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