check-each-file 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh
  2. # check-each-file
  3. # Used to narrow down a miscompilation to one .o file from a list. Please read
  4. # the usage procedure, below, for command-line syntax (or run it with --help).
  5. # This script depends on the llvm-native-gcc script.
  6. if [ x$1 = x--make-linker-script ]
  7. then
  8. program=$2
  9. linker=./link-$program
  10. echo "Building $program with llvm-native-gcc"
  11. rm -f $program
  12. gmake -e $program CC=llvm-native-gcc CXX=llvm-native-gxx
  13. echo "Erasing $program and re-linking it"
  14. rm -f $program
  15. echo "rm -f $program" > $linker
  16. gmake -n $program >> $linker
  17. chmod 755 $linker
  18. echo "Linker script created in $linker; testing it out"
  19. output=`./$linker 2>&1`
  20. case "$output" in
  21. *undefined*reference*__main*)
  22. echo "$program appears to need a dummy __main function; adding one"
  23. echo "void __main () { }" > __main.c
  24. gcc -c __main.c
  25. echo "Done; rebuilding $linker"
  26. echo "rm -f $program" > $linker
  27. gmake -n $program 2>&1 | sed '/gcc/s/$/__main.o/' >> $linker
  28. ./$linker > /dev/null 2>&1
  29. if [ ! -x $program ]
  30. then
  31. echo "WARNING: linker script didn't work"
  32. fi
  33. ;;
  34. *)
  35. if [ ! -x $program ]
  36. then
  37. echo "WARNING: linker script didn't work"
  38. fi
  39. ;;
  40. esac
  41. echo "Linker script created in $linker; please check it manually"
  42. exit 0
  43. fi
  44. checkfiles="$1"
  45. program="$2"
  46. linker="$3"
  47. checker="$4"
  48. usage () {
  49. myname=`basename $0`
  50. echo "$myname --make-linker-script PROGRAM"
  51. echo "$myname OBJECTS-FILE PROGRAM LINKER CHECKER"
  52. echo ""
  53. echo "OBJECTS-FILE is a text file containing the names of all the .o files"
  54. echo "PROGRAM is the name of the executable under test"
  55. echo "(there must also exist a Makefile in the current directory which"
  56. echo "has PROGRAM as a target)"
  57. echo "LINKER is the script that builds PROGRAM; try --make-linker-script"
  58. echo "to automatically generate it"
  59. echo "CHECKER is the script that exits 0 if PROGRAM is ok, 1 if it is not OK"
  60. echo "(LINKER and CHECKER must be in your PATH, or you should specify ./)"
  61. echo ""
  62. echo "Bugs to <[email protected]>."
  63. exit 1
  64. }
  65. if [ x$1 = x--help ]
  66. then
  67. usage
  68. fi
  69. if [ -z "$checkfiles" ]
  70. then
  71. echo "ERROR: Must specify name of file w/ list of objects as 1st arg."
  72. echo "(got \"$checkfiles\")"
  73. usage
  74. fi
  75. if [ ! -f "$checkfiles" ]
  76. then
  77. echo "ERROR: $checkfiles not found"
  78. usage
  79. fi
  80. if [ -z "$program" ]
  81. then
  82. echo "ERROR: Must specify name of program as 2nd arg."
  83. usage
  84. fi
  85. if [ -z "$linker" ]
  86. then
  87. echo "ERROR: Must specify name of link script as 3rd arg."
  88. usage
  89. fi
  90. if [ ! -x "$linker" ]
  91. then
  92. echo "ERROR: $linker not found or not executable"
  93. echo "You may wish to try: $0 --make-linker-script $program"
  94. usage
  95. fi
  96. if [ -z "$checker" ]
  97. then
  98. echo "ERROR: Must specify name of $program check script as 3rd arg."
  99. usage
  100. fi
  101. if [ ! -x "$checker" ]
  102. then
  103. echo "ERROR: $checker not found or not executable"
  104. usage
  105. fi
  106. files=`cat $checkfiles`
  107. echo "Recompiling everything with llvm-native-gcc"
  108. for f in $files
  109. do
  110. rm -f $f
  111. gmake $f CC=llvm-native-gcc CXX=llvm-native-gxx
  112. done
  113. rm -f $program
  114. $linker
  115. if $checker
  116. then
  117. echo "Sorry, I can't help you, $program is OK when compiled with llvm-native-gcc"
  118. exit 1
  119. fi
  120. for f in $files
  121. do
  122. echo Trying to compile $f with native gcc and rebuild $program
  123. mv ${f} ${f}__OLD__
  124. gmake ${f} CC=gcc > /dev/null 2>&1
  125. $linker
  126. echo Checking validity of new $program
  127. if $checker
  128. then
  129. echo Program is OK
  130. okfiles="$okfiles $f"
  131. else
  132. echo Program is not OK
  133. notokfiles="$notokfiles $f"
  134. fi
  135. mv ${f}__OLD__ ${f}
  136. done
  137. echo ""
  138. echo "Program is OK when these files are recompiled with native gcc: "
  139. echo "$okfiles"
  140. echo ""
  141. echo "Program is not OK when these files are recompiled with native gcc: "
  142. echo "$notokfiles"
  143. echo ""
  144. exit 0