initfini.awk 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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("/bin/touch crt[in].S");
  11. system("/bin/rm -f crt[in].S");
  12. omitcrti=0;
  13. omitcrtn=0;
  14. glb_idx = 0;
  15. while(getline < "initfini.s")
  16. { if(/\.endp/) {endp=1}
  17. if(/\.end/) {end=1}
  18. if(/\.align/) {alignval=$2}
  19. # here comes some special stuff for the SuperH targets
  20. # Search for all labels
  21. # if(/_GLOBAL_OFFSET_TABLE_/) {
  22. # sub (":","",last);
  23. # glb_label[glb_idx] = last;
  24. # glb_idx += 1;
  25. # glb = $0;
  26. # }
  27. last = $1;
  28. }
  29. close("initfini.s");
  30. }
  31. /^_init:/{omitcrtn=1;if (glb_idx>0) print glb_label[0] ":" glb >> "crti.S";}
  32. /^_fini:/{omitcrtn=1;if (glb_idx>1) print glb_label[1] ":" glb >> "crti.S";}
  33. /HEADER_ENDS/{omitcrti=1;omitcrtn=1;getline}
  34. /PROLOG_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  35. /i_am_not_a_leaf/{getline}
  36. /PROLOG_PAUSES/{omitcrti=1;getline}
  37. /PROLOG_UNPAUSES/{omitcrti=0;getline}
  38. /PROLOG_ENDS/{omitcrti=1;getline}
  39. /EPILOG_BEGINS/{omitcrtn=0;getline}
  40. /EPILOG_ENDS/{omitcrtn=1;getline}
  41. /TRAILER_BEGINS/{omitcrti=0;omitcrtn=0;getline}
  42. /END_INIT/ \
  43. { if(endp)
  44. { gsub("END_INIT",".endp _init",$0)
  45. }
  46. else
  47. { if(end)
  48. { gsub("END_INIT",".end _init",$0)
  49. }
  50. else
  51. { gsub("END_INIT","",$0)
  52. }
  53. }
  54. }
  55. /END_FINI/ \
  56. { if(endp)
  57. { gsub("END_FINI",".endp _fini",$0)
  58. }
  59. else
  60. { if(end)
  61. { gsub("END_FINI",".end _fini",$0)
  62. }
  63. else
  64. { gsub("END_FINI","",$0)
  65. }
  66. }
  67. }
  68. /ALIGN/ \
  69. { if(alignval!="")
  70. { gsub("ALIGN",sprintf(".align %s",alignval),$0)
  71. }
  72. else
  73. { gsub("ALIGN","",$0)
  74. }
  75. }
  76. # substitude all label references of the _GLOBAL_OFFSET_TABLE_
  77. # .L10 ==> .L10b etc.
  78. glb_idx>0 { gsub (glb_label[0],sprintf("%sb",glb_label[0]),$0)}
  79. glb_idx>1 { gsub (glb_label[1],sprintf("%sb",glb_label[1]),$0)}
  80. omitcrti==0 {print >> "crti.S"}
  81. omitcrtn==0 {print >> "crtn.S"}
  82. END \
  83. { close("crti.S");
  84. close("crtn.S");
  85. }