This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

3.4 PATCH: Handle non-GNU nm in mklibgcc.in


When bootstrapping mainline on IRIX 5 or IRIX 6 with GNU as/ld, but
otherwise with the native tools, I initially got link failures:

e.g. on IRIX 5.3

stage2/xgcc -Bstage2/ -B/home/ro/mips-sgi-irix5.3/bin/   -g -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Werror -fno-common   -DHAVE_CONFIG_H -DGENERATOR_FILE  -o genpreds \
 genpreds.o ../libiberty/libiberty.a
/home/ro/bin/gld-2.14.90: genpreds: hidden symbol `_fpadd_parts' isn't defined
collect2: ld returned 1 exit status
make[2]: *** [genpreds] Error 1

or Solaris 10 with the native tools (where both as and ld support hidden
symbols):

Undefined			first referenced
 symbol  			    in file
mprotect                            stage1/libgcc.a(_trampoline.oS)  (symbol scope specifies local binding)
sysconf                             stage1/libgcc.a(_trampoline.oS)  (symbol scope specifies local binding)
getpagesize                         ada/init.o  (symbol scope specifies local binding)
perror                              stage1/libgcc.a(_trampoline.oS)  (symbol scope specifies local binding)
ld: fatal: Symbol referencing errors. No output written to gnatbind
collect2: ld returned 1 exit status

It turns out that all those undefined symbols are marked hidden in
libgcc.a, which is wrong because it doesn't provide their definitions.
This happens because currently mklibgcc.in (where this symbol hiding takes
place) assumes a GNU nm-only behavior, namely that only defined symbols
show up with three columns in nm -pg output.  Investigating
libgcc/_trampoline.o on Solaris 10, this is not true for the native nm:

% nm -pg libgcc/_trampoline.o
libgcc/_trampoline.o:
0000000000 U _GLOBAL_OFFSET_TABLE_
0000000068 T __enable_execute_stack
0000000000 U getpagesize
0000000000 U mprotect
0000000000 U perror
0000000000 U sysconf

while GNU nm does this:

% gnm -pg libgcc/_trampoline.o
         U mprotect
00000044 T __enable_execute_stack
         U perror
         U sysconf
         U getpagesize
         U _GLOBAL_OFFSET_TABLE_

This seems to be consistent across non-GNU vendor nm's, and POSIX
1003.1-2003 contains no indication for this behavior either:

	http://www.opengroup.org/onlinepubs/007904975/utilities/nm.html

To cope with this, we need to filter out undefined (U) and typeless
(N) symbols.  The following patch does this and allowed bootstrap on
mips-sgi-irix5.3 and mips-sgi-irix6.5 to finish successfully.

Ok for mainline?

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University


Thu Sep 25 19:09:04 2003  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* mklibgcc.in: Don't hide undefined or typeless symbols.

Index: gcc/mklibgcc.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/mklibgcc.in,v
retrieving revision 1.65
diff -u -p -r1.65 mklibgcc.in
--- gcc/mklibgcc.in	8 Sep 2003 23:48:58 -0000	1.65
+++ gcc/mklibgcc.in	23 Sep 2003 20:37:55 -0000
@@ -347,7 +347,9 @@ EOF
       # .oS objects will have all non-local symbol definitions .hidden
       oS=`echo ${o} | sed s~${objext}'$~.oS~g'`
       echo "${oS}: stmp-dirs libgcc/${dir}/stacknote.s ${o}"
-      echo '	( $(NM_FOR_TARGET) '${SHLIB_NM_FLAGS} ${o}' | $(AWK) '\''NF == 3 { print "\t.hidden", $$3 }'\''; cat libgcc/${dir}/stacknote.s ) | $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) '${flags}' -r -nostdinc -nostdlib -o $@ '${o}' -xassembler -'
+      # non-GNU nm emits three fields even for undefined and typeless symbols,
+      # so explicitly omit them
+      echo '	( $(NM_FOR_TARGET) '${SHLIB_NM_FLAGS} ${o}' | $(AWK) '\''NF == 3 && $$2 !~ /^[UN]$$/ { print "\t.hidden", $$3 }'\''; cat libgcc/${dir}/stacknote.s ) | $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) '${flags}' -r -nostdinc -nostdlib -o $@ '${o}' -xassembler -'
       libgcc_a_objs="${libgcc_a_objs} ${oS}"
     done
   fi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]