llvm.org GIT mirror llvm / 4a6ca8d
This is my script for narrowing down miscompilations to a single file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10890 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gaeke 15 years ago
1 changed file(s) with 147 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/sh
1 # check-each-file
2 # Used to narrow down a miscompilation to one .o file from a list. Please read
3 # the usage procedure, below, for command-line syntax (or run it with --help).
4 # This script depends on the llvm-native-gcc script.
5
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 -s $program CC=llvm-native-gcc
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
45 checkfiles="$1"
46 program="$2"
47 linker="$3"
48 checker="$4"
49
50 usage () {
51 myname=`basename $0`
52 echo "$myname --make-linker-script PROGRAM"
53 echo "$myname OBJECTS-FILE PROGRAM LINKER CHECKER"
54 echo ""
55 echo "OBJECTS-FILE is a text file containing the names of all the .o files"
56 echo "PROGRAM is the name of the executable under test"
57 echo "(there must also exist a Makefile in the current directory which
58 echo "has PROGRAM as a target)"
59 echo "LINKER is the script that builds PROGRAM; try --make-linker-script"
60 echo "to automatically generate it"
61 echo "CHECKER is the script that exits 0 if PROGRAM is ok, 1 if it is not OK"
62 echo "(LINKER and CHECKER must be in your PATH, or you should specify ./)"
63 echo ""
64 echo "Bugs to ."
65 exit 1
66 }
67
68 if [ x$1 = x--help ]
69 then
70 usage
71 fi
72
73 if [ -z "$checkfiles" ]
74 then
75 echo "ERROR: Must specify name of file w/ list of objects as 1st arg."
76 echo "(got \"$checkfiles\")"
77 usage
78 fi
79 if [ ! -f "$checkfiles" ]
80 then
81 echo "ERROR: $checkfiles not found"
82 usage
83 fi
84 if [ -z "$program" ]
85 then
86 echo "ERROR: Must specify name of program as 2nd arg."
87 usage
88 fi
89 if [ -z "$linker" ]
90 then
91 echo "ERROR: Must specify name of link script as 3rd arg."
92 usage
93 fi
94 if [ ! -x "$linker" ]
95 then
96 echo "ERROR: $linker not found or not executable"
97 echo "You may wish to try: $0 --make-linker-script $program"
98 usage
99 fi
100 if [ -z "$checker" ]
101 then
102 echo "ERROR: Must specify name of $program check script as 3rd arg."
103 usage
104 fi
105 if [ ! -x "$checker" ]
106 then
107 echo "ERROR: $checker not found or not executable"
108 usage
109 fi
110
111 files=`cat $checkfiles`
112 echo "Recompiling everything with llvm-native-gcc"
113 for f in $files
114 do
115 rm -f $f && gmake $f CC=llvm-native-gcc
116 done
117 if $checker
118 then
119 echo "Sorry, I can't help you, $program is OK when compiled with llvm-native-gcc"
120 exit 1
121 fi
122 for f in $files
123 do
124 echo Trying to compile $f with native gcc and rebuild $program
125 mv ${f} ${f}__OLD__
126 gmake ${f} CC=gcc > /dev/null 2>&1
127 $linker
128 echo Checking validity of new $program
129 if $checker
130 then
131 echo Program is OK
132 okfiles="$okfiles $f"
133 else
134 echo Program is not OK
135 notokfiles="$notokfiles $f"
136 fi
137 mv ${f}__OLD__ ${f}
138 done
139 echo ""
140 echo "Program is OK when these files are recompiled with native gcc: "
141 echo "$okfiles"
142 echo ""
143 echo "Program is not OK when these files are recompiled with native gcc: "
144 echo "$notokfiles"
145 echo ""
146 exit 0