From owner-freebsd-amd64@FreeBSD.ORG Sat Apr 28 21:40:06 2007 Return-Path: X-Original-To: freebsd-amd64@hub.freebsd.org Delivered-To: freebsd-amd64@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5600616A40D for ; Sat, 28 Apr 2007 21:40:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 0AA9C13C469 for ; Sat, 28 Apr 2007 21:40:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l3SLe5ek060859 for ; Sat, 28 Apr 2007 21:40:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l3SLe5e9060858; Sat, 28 Apr 2007 21:40:05 GMT (envelope-from gnats) Resent-Date: Sat, 28 Apr 2007 21:40:05 GMT Resent-Message-Id: <200704282140.l3SLe5e9060858@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-amd64@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Peter Jeremy Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3321916A402 for ; 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 ; 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: amd64/112215: [patch] "gcc -m32" attempts to link against 64-bit libs X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Peter Jeremy List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Apr 2007 21:40:06 -0000 >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@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: