From peterjeremy@optushome.com.au  Sat Apr 28 21:35:43 2007
Return-Path: <peterjeremy@optushome.com.au>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 3321916A402
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 28 Apr 2007 21:35:43 +0000 (UTC)
	(envelope-from peterjeremy@optushome.com.au)
Received: from turion.vk2pj.dyndns.org (c220-239-3-125.belrs4.nsw.optusnet.com.au [220.239.3.125])
	by mx1.freebsd.org (Postfix) with ESMTP id 9ED8B13C468
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 28 Apr 2007 21:35:42 +0000 (UTC)
	(envelope-from peterjeremy@optushome.com.au)
Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1])
	by turion.vk2pj.dyndns.org (8.13.8/8.13.8) with ESMTP id l3SLZeI2001723;
	Sun, 29 Apr 2007 07:35:40 +1000 (EST)
	(envelope-from peter@turion.vk2pj.dyndns.org)
Received: (from peter@localhost)
	by turion.vk2pj.dyndns.org (8.13.8/8.13.8/Submit) id l3SLZesi001722;
	Sun, 29 Apr 2007 07:35:40 +1000 (EST)
	(envelope-from peter)
Message-Id: <200704282135.l3SLZesi001722@turion.vk2pj.dyndns.org>
Date: Sun, 29 Apr 2007 07:35:40 +1000 (EST)
From: Peter Jeremy <peterjeremy@optushome.com.au>
Reply-To: Peter Jeremy <peterjeremy@optushome.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] "gcc -m32" attempts to link against 64-bit libs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         112215
>Category:       gnu
>Synopsis:       [patch] [amd64] gcc(1): "gcc -m32" attempts to link against 64-bit libs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 28 21:40:05 GMT 2007
>Closed-Date:    Mon May 07 04:00:50 UTC 2012
>Last-Modified:  Mon May 07 04:02:10 UTC 2012
>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@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:
Responsible-Changed-From-To: freebsd-amd64->kan 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Apr 28 23:04:06 UTC 2007 
Responsible-Changed-Why:  
kan, can you take a look at this one please? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112215 

From: Peter Jeremy <peterjeremy@optushome.com.au>
To: FreeBSD-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: amd64/112215: [patch] "gcc -m32" attempts to link against
	64-bit libs
Date: Sun, 29 Apr 2007 20:55:23 +1000

 --ZwgA9U+XZDXt4+m+
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On 2007-Apr-29 07:35:40 +1000, Peter Jeremy <peterjeremy@optushome.com.au> =
 wrote:
 >	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:
 
 Note that one disadvantage of the patches I proposed is that i386
 executables built on amd64 won't run on i386.  This is because the
 executables reference /libexec/ld-elf32.so.1 and /usr/lib32/*.so -
 which don't exist on an i386 install.  The solutions here would seem
 to be:
 a) link /libexec/ld-elf.so.1 to /libexec/ld-elf32.so.1 and /usr/lib to
    /usr/lib32 on i386 (though this doesn't work for libc.so.N which is
    in /lib)
 b) Use a different fix to amd64/112215 that links the executables in
    "compatibility" mode (in much the same way as i386 executables can
    point to /libexec/ld-elf.so.1 and /usr/lib but still run on amd64).
 
 The second approach would seem cleaner (ie an i386 executable looks
 identical whether it was built natively on i386 or using -m32 on
 amd64) but I'm not sure how easy it is to implement.  The first
 approach is basically implementing "i386 emulation" mode on i386.
 
 --=20
 Peter Jeremy
 
 --ZwgA9U+XZDXt4+m+
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.7 (FreeBSD)
 
 iD8DBQFGNHmb/opHv/APuIcRAvndAJ94sbKYlnsTakzGIlLx2i72nXm2ZgCgk3S5
 QEYoaGp17I4VRi6D0rrKjGQ=
 =01gi
 -----END PGP SIGNATURE-----
 
 --ZwgA9U+XZDXt4+m+--
State-Changed-From-To: open->suspended 
State-Changed-By: kan 
State-Changed-When: Sun Apr 29 15:44:38 UTC 2007 
State-Changed-Why:  
Cross build for 32 bit is plan not supported on amd64 due to many reasons, 
gcc specs being the least serious of them. 

We do not not install correct machine/ headers anywhere, so any binary 
compiled with -m32 still refers to amd64's machine/*.h headers. 

Ther patch makes no sense until we have cross-environment to speak of 
in the first place. 



Responsible-Changed-From-To: kan->freebsd-amd64 
Responsible-Changed-By: kan 
Responsible-Changed-When: Sun Apr 29 15:44:38 UTC 2007 
Responsible-Changed-Why:  
Cross build for 32 bit is plan not supported on amd64 due to many reasons, 
gcc specs being the least serious of them. 

We do not not install correct machine/ headers anywhere, so any binary 
compiled with -m32 still refers to amd64's machine/*.h headers. 

Ther patch makes no sense until we have cross-environment to speak of 
in the first place. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=112215 
Responsible-Changed-From-To: freebsd-amd64->obrien 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Tue Feb 5 17:57:51 UTC 2008 
Responsible-Changed-Why:  
I'll keep an eye on this -but I think we're going to close it as 
simply not supported at this time. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112215 

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/112215: [patch] [amd64] gcc(1): "gcc -m32" attempts to
 link against 64-bit libs (-m32 on amd64)?
Date: Wed, 9 Mar 2011 14:54:04 -0600

 ----- Forwarded message from Thomas David Rivers <rivers@dignus.com> -----
 
 Date: Wed, 09 Mar 2011 15:15:39 -0500
 From: Thomas David Rivers <rivers@dignus.com>
 To: freebsd-stable@freebsd.org
 Subject: bin/139146 still not right in FreeBSD 8.2 (-m32 on amd64)?
 User-Agent: Heirloom mailx 12.4 7/29/08
 
 Just installed a fresh 8.2-stable on a brand-spanking-new 64-bit
 machine...
 
 But, when I try to build 32-bit programs I get problems linking,
 and I stumbled onto PR bin/139146.  [bugmeister note: closed as
 a duplicate of 112215, so followup redirected there.]
 
 The PR mentions this quick test:
 
   uname -sr && echo "int main () { }" > t.c && gcc -v --help 2>&1 | grep m32 && gcc -m32 t.c
 
 which I try to get this output:
 
 FreeBSD 8.2-RELEASE
   -m32                        Generate 32bit i386 code
 /usr/bin/ld: skipping incompatible /usr/lib/libgcc.a when searching for -lgcc
 /usr/bin/ld: skipping incompatible /usr/lib/libgcc.a when searching for -lgcc
 /usr/bin/ld: cannot find -lgcc
 
 
 So - I'm wondering what the proper approach is on amd64 to build 
 32-bit applications?
 
 	- Thanks! -
 	- Dave Rivers -
 
 --
 rivers@dignus.com                        Work: (919) 676-0847
 Get your mainframe programming tools at http://www.dignus.com
 
 
 
 _______________________________________________
 freebsd-stable@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-stable
 To unsubscribe, send any mail to "freebsd-stable-unsubscribe@freebsd.org"
 
 
 ----- End forwarded message -----
State-Changed-From-To: suspended->closed 
State-Changed-By: eadler 
State-Changed-When: Mon May 7 04:00:48 UTC 2012 
State-Changed-Why:  
quick test works for me 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112215 
Responsible-Changed-From-To: obrien->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Mon May 7 04:02:08 UTC 2012 
Responsible-Changed-Why:  
I closed it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112215 
>Unformatted:
