initfini.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/perl
  2. use strict;
  3. use Getopt::Long;
  4. my($initfini) = "initfini.s";
  5. my($crti) = "crti.S";
  6. my($crtn) = "crtn.S";
  7. my($alignval) = "";
  8. my($endp) = 0;
  9. my($end) = 0;
  10. my($omitcrti) = 0;
  11. my($omitcrtn) = 0;
  12. my($line);
  13. # Get commandline parameters
  14. Getopt::Long::Configure("no_ignore_case", "bundling");
  15. &GetOptions( "initfini=s" => \$initfini,
  16. "crti=s" => \$crti,
  17. "crtn=s" => \$crtn,
  18. );
  19. chomp($initfini);
  20. chomp($crti);
  21. chomp($crtn);
  22. if ($initfini) {
  23. open(INITFINI,"<$initfini") or
  24. die "(fatal) Can't open $initfini$!";
  25. } else {
  26. die "(fatal) Please give me an --initfini argument$!";
  27. }
  28. while($line = <INITFINI>) {
  29. if ($line =~ /^\w\.endp/) {
  30. $endp=1;
  31. next;
  32. }
  33. if ($line =~ /^\w\.end/) {
  34. $end=1;
  35. next;
  36. }
  37. if ($line =~ /\w\.align\(.*\)/) {
  38. $alignval=$1;
  39. next;
  40. }
  41. }
  42. close(INITFINI);
  43. if ($initfini) {
  44. open(INITFINI,"<$initfini") or
  45. die "(fatal) Can't open $initfini$!";
  46. } else {
  47. die "(fatal) Please give me an --initfini argument$!";
  48. }
  49. if ($crti) {
  50. open(CRTI,">$crti") or
  51. die "(fatal) Can't open $crti$!";
  52. } else {
  53. die "(fatal) Please give me a --asm argument$!";
  54. }
  55. if ($crtn) {
  56. open(CRTN,">$crtn") or
  57. die "(fatal) Can't open $crtn$!";
  58. } else {
  59. die "(fatal) Please give me a --asm argument$!";
  60. }
  61. while(<INITFINI>) {
  62. if (/HEADER_ENDS/) {
  63. $omitcrti = 1;
  64. $omitcrtn = 1;
  65. next;
  66. }
  67. if (/PROLOG_BEGINS/) {
  68. $omitcrti = 0;
  69. next;
  70. }
  71. if (/PROLOG_ENDS/) {
  72. $omitcrti = 1;
  73. next;
  74. }
  75. if (/EPILOG_BEGINS/) {
  76. $omitcrtn = 0;
  77. next;
  78. }
  79. if (/EPILOG_ENDS/) {
  80. $omitcrtn = 1;
  81. next;
  82. }
  83. if (/TRAILER_BEGINS/) {
  84. $omitcrti = 0;
  85. $omitcrtn = 0;
  86. next;
  87. }
  88. if (/END_INIT/) {
  89. if ($endp) {
  90. s/END_INIT/.endp _init/;
  91. } else {
  92. if($end) {
  93. s/END_INIT/.end _init/;
  94. } else {
  95. s/END_INIT//;
  96. }
  97. }
  98. }
  99. if (/END_FINI/) {
  100. if ($endp) {
  101. s/END_FINI/.endp _fini/;
  102. } else {
  103. if($end) {
  104. s/END_FINI/.end _fini/;
  105. } else {
  106. s/END_FINI//;
  107. }
  108. }
  109. }
  110. if (/ALIGN/) {
  111. if($alignval) {
  112. s/ALIGN/.align $alignval/;
  113. } else {
  114. s/ALIGN//;
  115. }
  116. }
  117. if (!$omitcrti) {
  118. print CRTI;
  119. }
  120. if (!$omitcrtn) {
  121. print CRTN;
  122. }
  123. }
  124. close(INITFINI);
  125. close(CRTI);
  126. close(CRTN);