Solaris7/Intel, gcc 2.95.2 problem.

Tristram E. H. Mabbs tehm@gateway.firstgrade.co.uk
Thu Apr 13 08:59:00 GMT 2000


	Folks,

	I don't believe it - I've found a couple of problems (let's not call
them bugs) in "gcc"!  They're platform specific.
	The first relates to the way "gcc" calls the native Solaris assembler.
I didn't compile "gcc" myself, but downloaded the "Solaris7/Intel" packaged
version from SunFreeWare:

Script started on Thu 13 Apr 2000 03:44:19 PM BST
%gcc -v
Reading specs from /usr/local/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
%cat c.c
main()
{
	printf ("Hello, world!\n");

	exit (0);
}
%gcc -pipe c.c -o c
Usage: as [options] file
c.c:7: output pipe has been closed
%exit
script done on Thu 13 Apr 2000 03:44:40 PM BST

	The problem only occurs when using "-pipe", and would seem to be
because you pass "-" as a filename as the last argument - "as" recognises
this as an option (rather than an instruction to use "stdin" as the source
file) and dies with a syntax error.

	The second is also platform specific, and showed up when compiling
a GNU package ("gmp").  You pass in, for example "udiv_fp.S", to compile
to a temporary ".s" file for subsequent assembly.  However, the original
".S" file contains comments, which are passed through.  The trouble is
that the Intel Solaris "as" doesn't accept comments (it doesn't take "!" as
a comment; the manual page doesn't go into any such detail, and I've never
actually found any other way of getting comments into assembly source in
such a way that the compiler doesn't barf).  Unfortunately, therefore, the
only thing that can be done on the platform is to strip out comments when
building a ".s" file.

	So, I consider these to be Sun bugs rather than "gcc" ones, but I
thought you might be interested.  Meanwhile, a trivial "as" replacement
script gets around them - I've attached my quick hack below (if anyone is
feeling bored, I'm sure you can knock up a more elegant one!).

	Tris Mabbs.

------->Cut here:
#!/bin/sh
#	as:
#		Replacement for the system "as" command, that:
#
#	Strips out lines starting "!" (comment lines, not understood by "as"),
#	Groks a trailing "-" as "please use 'stdin' for the source file".
#
#		We also gather flags and files together, as the system "as" com-
#	mand strictly enforces "as [flags] files" syntax. This could potentially
#	be problematic, as we don't actually try to parse the actual assembler's
#	flags, but in practice it works OK.
#
#	History:
#	12/04/2000	1.0	Tris Mabbs	Lost my last version of this di-
#						rty hack (how careless), so kno-
#						cked this one up ....
#
#	Notes:
#	You only need this if you are using Sun's assembler on Solaris/Intel.
#	You need to rename the existing system "as" command to "as.SunOS_5.7" so
#	that "gcc" picks it up instead of "/usr/ccs/bin/as".  You can then eith-
#	er install this as "/usr/ccs/bin/as" (recommended), or dump it somewhere
#	more appropriate to your system.
#	To be "general purpose", we shouldn't rely on the ".SunOS_5.7" suffix to
#	the system "as" command, but should extract this from "uname".  However,
#	that would add an otherwise completely unecessary command to the execut-
#	ion of the script.
#	This script is ludicrously over-commented (over-caffinated fingers....).
#
progname="`basename \"$0\"`"
:
tmpdir="${TMPDIR:-${TEMPDIR:-/var/tmp}}"
eval pid="$$"
tmpfil="$tmpdir/$progname.tf.$pid"		# Replacement for "stdin".
tmpwrk="$tmpdir/$progname.tw.$pid"		# Concatenated source less "!"s.
:
trap 'rm -f "$tmpfil" "$tmpwrk"; exit 2' 1 2 3 15
						# Clean up on interruptions.
:
#
#	Tweakables start here:
#
system_as="/usr/ccs/bin/as.SunOS_5.7"		# System "as" command.
#
#	Tweakables end here.
#
:
#
#	Quick sanity check.
#
if [ ! -x "$system_as" ]
then
	echo "$progname: ERROR: Cannot find system assembler (\"$system_as\")." >&2
	i="`echo \"$system_as\" | sed -e 's/^\([^\.][^\.]*\)\.*$/\1/'`"
	if [ -x "$i" ]
	then
		echo "$progname: ERROR: However, can find \"$i\" - Please rename it!" >&2
	fi
	echo "$progname: ERROR: Aborting." >&2

	exit 1
fi
:
#
#	Pull apart our arguments to get flags and source files.
#
flags=""					# No arguments yet.
srces=""					# No source file(s) yet.
while [ "$#" -gt 0 ]
do
	case "$1" in
		-)
			#
			#	"stdin" marker (we hope!).
			#
			if [ "$#" -eq 1 ]
			then
				#
				#	Last argument: Assume "stdin" as a sour-
				#	ce file.
				#
				cat > "$tmpfil"

				if [ "$srces" = "" ]
				then
					srces="\"$tmpfil\""
				else
					srces="$srces \"$tmpfil\""
				fi
			else
				#
				#	This isn't going to work, but we will j-
				#	ust let the system "as" worry about that
				#	for us.
				#
				if [ "$flags" = "" ]
				then
					flags="\"$1\""
				else
					flags="$flags \"$1\""
				fi
			fi ;;
		*.s|*.S)
			#
			#	Source file
			#	
			if [ "$srces" = "" ]
			then
				srces="\"$1\""
			else
				srces="$srces \"$1\""
			fi ;;
		*)
			#
			#	Flag argument (or flag argument argument).
			#
			if [ "$flags" = "" ]
			then
				flags="$1"
			else
				flags="$flags \"$1\""
			fi ;;
	esac

	shift
done

#
#	Strip comment lines out of the source code.
#
if [ "$srces" != "" ]
then
	#
	#	Strip lines starting with "<optional whitespace>!".
	#
	( eval cat "$srces" ) | grep -v '^[ 	]*!' > "$tmpwrk"
else
	#
	#	Again, this isn't going to work, but we let "as" worry about it.
	#
	rm -f "$tmpwrk"

	tmpwrk=""
fi

#
#	Whatever we've got, pass it to the system "as".
#
eval "$system_as" $flags $tmpwrk
exstat="$?"
if [ "$tmpwrk" != "" ]
then
	rm -f "$tmpfil" "$tmpwrk"
else
	rm -f "$tmpfil"
fi
exit $exstat


More information about the Gcc-bugs mailing list