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

Peter Jeremy peterjeremy at
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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 28 21:40:05 GMT 2007
>Originator:     Peter Jeremy
>Release:        FreeBSD 6.2-STABLE amd64
System: FreeBSD 6.2-STABLE FreeBSD 6.2-STABLE #25: Tue Jan 30 05:01:57 EST 2007 root at amd64

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

	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/ instead of /libexec/
	and /usr/lib/... instead of /usr/lib32/...

	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 @@
+%{m32:/usr/lib32/; :/usr/lib/}
@@ -120,7 +120,7 @@
+%{m32:/libexec/; :/libexec/}
 %{!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
diff -u -r1.19.2.1 freebsd-spec.h
--- /usr/src/contrib/gcc/config/freebsd-spec.h	11 Jul 2006 19:13:04 -0000
+++ /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/"
+#elif defined(__amd64)
+		"%{m32:/libexec/; :/libexec/}"
 #define FBSD_DYNAMIC_LINKER "/libexec/"
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
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
+++ /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. */
+#if defined(__amd64)
+#define STARTFILE_PREFIX_SPEC	"%{m32:"PREFIX"/lib32/; :"PREFIX"/lib/}"
 /* For the native system compiler, we actually build libgcc in a profiled
    version.  So we should use it with -pg.  */

More information about the freebsd-amd64 mailing list