initfini.awk 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #! /usr/bin/awk -f
  2. # Contributed by Christian MICHON <christian_michon@yahoo.fr> to
  3. # eliminate the compile time dependancy on perl introduced by
  4. # Erik's older initfini.pl
  5. # vim:ai:sw=2:
  6. BEGIN \
  7. { alignval="";
  8. endp=0;
  9. end=0;
  10. system("touch crt[in].S");
  11. system("/bin/rm -f crt[in].S");
  12. omitcrti=0;
  13. omitcrtn=0;
  14. do_sh_specials = 0;
  15. glb_idx = 0;
  16. while(getline < "initfini.S")
  17. { if(/\.endp/) {endp=1}
  18. if(/\.end/) {end=1}
  19. if(/\.align/) {alignval=$2}
  20. # here comes some special stuff for the SuperH targets
  21. # We search for all labels, which uses the _GLOBAL_OFFSET_TABLE_
  22. # definition, and store them in the glb_label array.
  23. if(/_GLOBAL_OFFSET_TABLE_/) {
  24. glb_label[glb_idx] = last;
  25. glb_idx += 1;
  26. glb = $0;
  27. }
  28. last = $1;
  29. }
  30. close("initfini.S");
  31. }
  32. # special rules for the SuperH targets (They do nothing on other targets)
  33. /SH_GLB_BEGINS/ && glb_idx==0 {omitcrti +=1;do_sh_specials++}
  34. /_init_SH_GLB/ && glb_idx>=1 {print glb_label[0] glb >> "crti.S"}
  35. /_fini_SH_GLB/ && glb_idx>=2 {print glb_label[1] glb >> "crti.S"}
  36. /SH_GLB_ENDS/ && glb_idx==0 {omitcrti -=1}
  37. /SH_GLB/ || /_GLOBAL_OFFSET_TABLE_/ && do_sh_specials>=1 {getline}
  38. # special rules for H8/300 (sorry quick hack)
  39. /.h8300h/ {end=0}
  40. # rules for all targets
  41. /HEADER_ENDS/{omitcrti=1;omitcrtn=1;getline}
  42. /PROLOG_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  43. /i_am_not_a_leaf/{getline}
  44. /_init:/||/_fini:/{omitcrtn=1}
  45. /PROLOG_PAUSES/{omitcrti=1;getline}
  46. /PROLOG_UNPAUSES/{omitcrti=0;getline}
  47. /PROLOG_ENDS/{omitcrti=1;getline}
  48. /EPILOG_BEGINS/{omitcrtn=0;getline}
  49. /EPILOG_ENDS/{omitcrtn=1;getline}
  50. /TRAILER_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  51. /GMON_STUFF_BEGINS/{omitcrtn=1;getline}
  52. /GMON_STUFF_PAUSES/{omitcrtn=0;getline}
  53. /GMON_STUFF_UNPAUSES/{omitcrtn=1;getline}
  54. /GMON_STUFF_ENDS/{omitcrtn=0;getline}
  55. /END_INIT/ \
  56. { if(endp)
  57. { gsub("END_INIT",".endp _init",$0)
  58. }
  59. else
  60. { if(end)
  61. { gsub("END_INIT",".end _init",$0)
  62. }
  63. else
  64. { gsub("END_INIT","",$0)
  65. }
  66. }
  67. }
  68. /END_FINI/ \
  69. { if(endp)
  70. { gsub("END_FINI",".endp _fini",$0)
  71. }
  72. else
  73. { if(end)
  74. { gsub("END_FINI",".end _fini",$0)
  75. }
  76. else
  77. { gsub("END_FINI","",$0)
  78. }
  79. }
  80. }
  81. /ALIGN/ \
  82. { if(alignval!="")
  83. { gsub("ALIGN",sprintf(".align %s",alignval),$0)
  84. }
  85. else
  86. { gsub("ALIGN","",$0)
  87. }
  88. }
  89. omitcrti==0 {print >> "crti.S"}
  90. omitcrtn==0 {print >> "crtn.S"}
  91. END \
  92. { close("crti.S");
  93. close("crtn.S");
  94. }