brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · bd76333 Raw
151 lines · plain
1#!/bin/sh2# check-each-file3# Used to narrow down a miscompilation to one .o file from a list. Please read4# 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 ]8then9	program=$210	linker=./link-$program11	echo "Building $program with llvm-native-gcc"12	rm -f $program13	gmake -e $program CC=llvm-native-gcc CXX=llvm-native-gxx14	echo "Erasing $program and re-linking it" 15	rm -f $program16	echo "rm -f $program" > $linker17	gmake -n $program >> $linker18	chmod 755 $linker19	echo "Linker script created in $linker; testing it out"20	output=`./$linker 2>&1`21	case "$output" in22		*undefined*reference*__main*) 23			echo "$program appears to need a dummy __main function; adding one"24			echo "void __main () { }" > __main.c25			gcc -c __main.c26			echo "Done; rebuilding $linker"27			echo "rm -f $program" > $linker28			gmake -n $program 2>&1 | sed '/gcc/s/$/__main.o/' >> $linker29			./$linker > /dev/null 2>&130			if [ ! -x $program ]31			then32				echo "WARNING: linker script didn't work"33			fi34			;;35		*)36			if [ ! -x $program ]37			then38				echo "WARNING: linker script didn't work"39			fi40			;;41	esac42	echo "Linker script created in $linker; please check it manually"43	exit 044fi45 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"58	echo "(there must also exist a Makefile in the current directory which"59	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 167}68 69if [ x$1 = x--help ]70then71	usage72fi73 74if [ -z "$checkfiles" ]75then76	echo "ERROR: Must specify name of file w/ list of objects as 1st arg."77	echo "(got \"$checkfiles\")"78	usage79fi80if [ ! -f "$checkfiles" ]81then82	echo "ERROR: $checkfiles not found"83	usage84fi85if [ -z "$program" ]86then87	echo "ERROR: Must specify name of program as 2nd arg."88	usage89fi90if [ -z "$linker" ]91then92	echo "ERROR: Must specify name of link script as 3rd arg."93	usage94fi95if [ ! -x "$linker" ]96then97	echo "ERROR: $linker not found or not executable"98	echo "You may wish to try: $0 --make-linker-script $program"99	usage100fi101if [ -z "$checker" ]102then103	echo "ERROR: Must specify name of $program check script as 3rd arg."104	usage105fi106if [ ! -x "$checker" ]107then108	echo "ERROR: $checker not found or not executable"109	usage110fi111 112files=`cat $checkfiles`113echo "Recompiling everything with llvm-native-gcc"114for f in $files115do116	rm -f $f117	gmake $f CC=llvm-native-gcc CXX=llvm-native-gxx118done119rm -f $program120$linker121if $checker122then123	echo "Sorry, I can't help you, $program is OK when compiled with llvm-native-gcc"124	exit 1125fi126for f in $files127do128	echo Trying to compile $f with native gcc and rebuild $program129	mv ${f} ${f}__OLD__130	gmake ${f} CC=gcc > /dev/null 2>&1131	$linker132	echo Checking validity of new $program133	if $checker134	then135		echo Program is OK136		okfiles="$okfiles $f"137	else138		echo Program is not OK139		notokfiles="$notokfiles $f"140	fi141	mv ${f}__OLD__ ${f}142done143echo ""144echo "Program is OK when these files are recompiled with native gcc: "145echo "$okfiles"146echo ""147echo "Program is not OK when these files are recompiled with native gcc: "148echo "$notokfiles"149echo ""150exit 0151