amd64/112215: [patch] "gcc -m32" attempts to link against 64-bit libs

Peter Jeremy peterjeremy at optushome.com.au
Sat Apr 28 21:40:06 UTC 2007


>Number:         112215
>Category:       amd64
>Synopsis:       [patch] "gcc -m32" attempts to link against 64-bit libs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-amd64
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 28 21:40:05 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Peter Jeremy
>Release:        FreeBSD 6.2-STABLE amd64
>Organization:
n/a
>Environment:
System: FreeBSD turion.vk2pj.dyndns.org 6.2-STABLE FreeBSD 6.2-STABLE #25: Tue Jan 30 05:01:57 EST 2007 root at turion.vk2pj.dyndns.org:/usr/obj/usr/src/sys/turion amd64

>Description:
	"gcc -m32" correctly builds 32-bit objects but attempts to use
	64-bit libraries and the 64-bit dynamic loader when linking.

>How-To-Repeat:
	echo 'main(){printf("Hello world\\n");}' > x.c
	gcc -v -m32 x.c

	Note that whilst it correctly passes "-m elf_i386_fbsd" to ld,
	it specifies /libexec/ld-elf.so.1 instead of /libexec/ld-elf32.so.1
	and /usr/lib/... instead of /usr/lib32/...

>Fix:
	A work-around is to install /usr/libdata/gcc/specs which is
	"gcc -dumpspecs" with the following patch:
--- -	Sun Apr 29 07:17:26 2007
+++ specs	Sat Apr 28 22:25:15 2007
@@ -99,7 +99,7 @@
 
 
 *startfile_prefix_spec:
-/usr/lib/
+%{m32:/usr/lib32/; :/usr/lib/}
 
 *sysroot_suffix_spec:
 
@@ -120,7 +120,7 @@
 }
 
 *fbsd_dynamic_linker:
-/libexec/ld-elf.so.1
+%{m32:/libexec/ld-elf32.so.1; :/libexec/ld-elf.so.1}
 
 *link_command:
 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:    %(linker) %l %{pie:} %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}    %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}    %{static:} %{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate:-lgcov}    %{!nostdlib:%{!nodefaultlibs:%(link_gcc_c_sequence)}}    %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}


	A complete fix is less clear.  *fbsd_dynamic_linker is derived from
	FBSD_DYNAMIC_LINKER - which is currently common across all FreeBSD
	platforms.  (Note that the code for FBSD_MAJOR<5 is obsolete now).
	Likewise *startfile_prefix_spec is common.  The following (untested)
	patch should work:
Index: /usr/src/contrib/gcc/config/freebsd-spec.h
===================================================================
RCS file: /usr/ncvs/src/contrib/gcc/config/freebsd-spec.h,v
retrieving revision 1.19.2.1
diff -u -r1.19.2.1 freebsd-spec.h
--- /usr/src/contrib/gcc/config/freebsd-spec.h	11 Jul 2006 19:13:04 -0000	1.19.2.1
+++ /usr/src/contrib/gcc/config/freebsd-spec.h	28 Apr 2007 21:25:27 -0000
@@ -166,6 +166,9 @@
 
 #if FBSD_MAJOR < 5
 #define FBSD_DYNAMIC_LINKER "/usr/libexec/ld-elf.so.1"
+#elif defined(__amd64)
+#define FBSD_DYNAMIC_LINKER \
+		"%{m32:/libexec/ld-elf32.so.1; :/libexec/ld-elf.so.1}"
 #else
 #define FBSD_DYNAMIC_LINKER "/libexec/ld-elf.so.1"
 #endif
Index: /usr/src/gnu/usr.bin/cc/cc_tools/freebsd-native.h
===================================================================
RCS file: /usr/ncvs/src/gnu/usr.bin/cc/cc_tools/freebsd-native.h,v
retrieving revision 1.24.8.2
diff -u -r1.24.8.2 freebsd-native.h
--- /usr/src/gnu/usr.bin/cc/cc_tools/freebsd-native.h	11 Jul 2006 20:02:39 -0000	1.24.8.2
+++ /usr/src/gnu/usr.bin/cc/cc_tools/freebsd-native.h	28 Apr 2007 21:33:24 -0000
@@ -44,7 +44,11 @@
 
 #undef  MD_STARTFILE_PREFIX		/* We don't need one for now. */
 #define STANDARD_STARTFILE_PREFIX	PREFIX"/lib/"
+#if defined(__amd64)
+#define STARTFILE_PREFIX_SPEC	"%{m32:"PREFIX"/lib32/; :"PREFIX"/lib/}"
+#else
 #define STARTFILE_PREFIX_SPEC		PREFIX"/lib/"
+#endif
 
 /* For the native system compiler, we actually build libgcc in a profiled
    version.  So we should use it with -pg.  */
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-amd64 mailing list