Re: PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-06-03 Thread Robert Millan
Actually, please consider this patch instead.  It's the same but fixes a
mistake in ld.so pathname.

2011/6/2 Robert Millan :
> Hi,
>
> 2011/5/21 Joseph S. Myers :
>> Please send a patch against *current trunk* and CC *relevant target
>> architecture maintainers*.  linux*.h headers are no longer used on
>> non-Linux targets (since my 2011-04-28 patch - on which I CC:ed you) so
>> this patch version is no longer appropriate.  I think you'll want to make
>> gnu-user64.h use GNU_USER_LINK_EMULATION32 and GNU_USER_LINK_EMULATION64
>> similarly to how gnu-user.h uses GNU_USER_LINK_EMULATION.
>
> Thanks for the tip.  Here's an update to current trunk.
>
> --
> Robert Millan
>



-- 
Robert Millan
2011-06-02  Robert Millan  

* config/i386/kfreebsd-gnu.h: Resync with `config/i386/linux.h'.
* config/kfreebsd-gnu.h (GNU_USER_DYNAMIC_LINKER): Resync with
`config/linux.h'.

* config/i386/kfreebsd-gnu64.h: New file.
* config.gcc (x86_64-*-kfreebsd*-gnu): Replace `i386/kfreebsd-gnu.h'
with `i386/kfreebsd-gnu64.h'.

* config/i386/linux64.h (GNU_USER_LINK_EMULATION32)
(GNU_USER_LINK_EMULATION64): New macros.
* config/i386/gnu-user64.h (LINK_SPEC): Rely on
`GNU_USER_LINK_EMULATION32' and `GNU_USER_LINK_EMULATION64' instead
of hardcoding `elf_i386' and `elf_x86_64'.

Index: gcc/config/i386/kfreebsd-gnu64.h
===
--- gcc/config/i386/kfreebsd-gnu64.h(revision 0)
+++ gcc/config/i386/kfreebsd-gnu64.h(revision 0)
@@ -0,0 +1,26 @@
+/* Definitions for AMD x86-64 running kFreeBSD-based GNU systems with ELF 
format
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+   Contributed by Robert Millan.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+
+#define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
Index: gcc/config/i386/kfreebsd-gnu.h
===
--- gcc/config/i386/kfreebsd-gnu.h  (revision 174566)
+++ gcc/config/i386/kfreebsd-gnu.h  (working copy)
@@ -1,5 +1,5 @@
 /* Definitions for Intel 386 running kFreeBSD-based GNU systems with ELF format
-   Copyright (C) 2004, 2007, 2011
+   Copyright (C) 2011
Free Software Foundation, Inc.
Contributed by Robert Millan.
 
@@ -19,11 +19,5 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef GNU_USER_LINK_EMULATION
 #define GNU_USER_LINK_EMULATION "elf_i386_fbsd"
-
-#undef GNU_USER_DYNAMIC_LINKER32
-#define GNU_USER_DYNAMIC_LINKER32 "/lib/ld.so.1"
-
-#undef GNU_USER_DYNAMIC_LINKER64
-#define GNU_USER_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
Index: gcc/config/i386/linux64.h
===
--- gcc/config/i386/linux64.h   (revision 174566)
+++ gcc/config/i386/linux64.h   (working copy)
@@ -24,6 +24,9 @@
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
+#define GNU_USER_LINK_EMULATION32 "elf_i386"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
 
Index: gcc/config/i386/gnu-user64.h
===
--- gcc/config/i386/gnu-user64.h(revision 174566)
+++ gcc/config/i386/gnu-user64.h(working copy)
@@ -69,7 +69,8 @@
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef LINK_SPEC
-#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
+#define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
+   %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
   %{shared:-shared} \
   %{!shared: \
 %{!static: \
Index: gcc/config/kfreebsd-gnu.h
===
--- gcc/config/kfreebsd-gnu.h   (revision 174566)
+++ gcc/config/kfreebsd-gnu.h   (working copy)
@@ -19,7 +19,6 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef GNU_USER_TARGET_OS_CPP_BUILTINS
 #define GNU_USER_T

Re: PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-06-02 Thread Robert Millan
Hi,

2011/5/21 Joseph S. Myers :
> Please send a patch against *current trunk* and CC *relevant target
> architecture maintainers*.  linux*.h headers are no longer used on
> non-Linux targets (since my 2011-04-28 patch - on which I CC:ed you) so
> this patch version is no longer appropriate.  I think you'll want to make
> gnu-user64.h use GNU_USER_LINK_EMULATION32 and GNU_USER_LINK_EMULATION64
> similarly to how gnu-user.h uses GNU_USER_LINK_EMULATION.

Thanks for the tip.  Here's an update to current trunk.

-- 
Robert Millan
2011-06-02  Robert Millan  

* config/i386/kfreebsd-gnu.h: Resync with `config/i386/linux.h'.
* config/kfreebsd-gnu.h (GNU_USER_DYNAMIC_LINKER): Resync with
`config/linux.h'.

* config/i386/kfreebsd-gnu64.h: New file.
* config.gcc (x86_64-*-kfreebsd*-gnu): Replace `i386/kfreebsd-gnu.h'
with `i386/kfreebsd-gnu64.h'.

* config/i386/linux64.h (GNU_USER_LINK_EMULATION32)
(GNU_USER_LINK_EMULATION64): New macros.
* config/i386/gnu-user64.h (LINK_SPEC): Rely on
`GNU_USER_LINK_EMULATION32' and `GNU_USER_LINK_EMULATION64' instead
of hardcoding `elf_i386' and `elf_x86_64'.

Index: gcc/config/i386/kfreebsd-gnu64.h
===
--- gcc/config/i386/kfreebsd-gnu64.h(revision 0)
+++ gcc/config/i386/kfreebsd-gnu64.h(revision 0)
@@ -0,0 +1,26 @@
+/* Definitions for AMD x86-64 running kFreeBSD-based GNU systems with ELF 
format
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+   Contributed by Robert Millan.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#define GNU_USER_LINK_EMULATION32 "elf_i386_fbsd"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64_fbsd"
+
+#define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-kfreebsd-x86-64.so.1"
Index: gcc/config/i386/kfreebsd-gnu.h
===
--- gcc/config/i386/kfreebsd-gnu.h  (revision 174566)
+++ gcc/config/i386/kfreebsd-gnu.h  (working copy)
@@ -1,5 +1,5 @@
 /* Definitions for Intel 386 running kFreeBSD-based GNU systems with ELF format
-   Copyright (C) 2004, 2007, 2011
+   Copyright (C) 2011
Free Software Foundation, Inc.
Contributed by Robert Millan.
 
@@ -19,11 +19,5 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef GNU_USER_LINK_EMULATION
 #define GNU_USER_LINK_EMULATION "elf_i386_fbsd"
-
-#undef GNU_USER_DYNAMIC_LINKER32
-#define GNU_USER_DYNAMIC_LINKER32 "/lib/ld.so.1"
-
-#undef GNU_USER_DYNAMIC_LINKER64
-#define GNU_USER_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
Index: gcc/config/i386/linux64.h
===
--- gcc/config/i386/linux64.h   (revision 174566)
+++ gcc/config/i386/linux64.h   (working copy)
@@ -24,6 +24,9 @@
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 .  */
 
+#define GNU_USER_LINK_EMULATION32 "elf_i386"
+#define GNU_USER_LINK_EMULATION64 "elf_x86_64"
+
 #define GLIBC_DYNAMIC_LINKER32 "/lib/ld-linux.so.2"
 #define GLIBC_DYNAMIC_LINKER64 "/lib64/ld-linux-x86-64.so.2"
 
Index: gcc/config/i386/gnu-user64.h
===
--- gcc/config/i386/gnu-user64.h(revision 174566)
+++ gcc/config/i386/gnu-user64.h(working copy)
@@ -69,7 +69,8 @@
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef LINK_SPEC
-#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
+#define LINK_SPEC "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \
+   %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \
   %{shared:-shared} \
   %{!shared: \
 %{!static: \
Index: gcc/config/kfreebsd-gnu.h
===
--- gcc/config/kfreebsd-gnu.h   (revision 174566)
+++ gcc/config/kfreebsd-gnu.h   (working copy)
@@ -19,7 +19,6 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef GNU_USER_TARGET_OS_CPP_BUILTINS
 #define GNU_USER_TARGET_OS_CPP_BUILTINS()  \
   do   \
 {  \
@@ -31,5 +30,6 @@
 }  

Re: PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-05-21 Thread Joseph S. Myers
On Sat, 21 May 2011, Robert Millan wrote:

> Please can this patch be considered? It's several months old (sent in
> Jan 2011), and it is critical to use of GCC on GNU/kFreeBSD.

Please send a patch against *current trunk* and CC *relevant target 
architecture maintainers*.  linux*.h headers are no longer used on 
non-Linux targets (since my 2011-04-28 patch - on which I CC:ed you) so 
this patch version is no longer appropriate.  I think you'll want to make 
gnu-user64.h use GNU_USER_LINK_EMULATION32 and GNU_USER_LINK_EMULATION64 
similarly to how gnu-user.h uses GNU_USER_LINK_EMULATION.

-- 
Joseph S. Myers
jos...@codesourcery.com


PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-05-21 Thread Robert Millan
Please can this patch be considered? It's several months old (sent in
Jan 2011), and it is critical to use of GCC on GNU/kFreeBSD.

2011/1/26 Robert Millan :
> Ping!
>
> 2011/1/18 Robert Millan :
>> 2011/1/14 Robert Millan :
>>> 2011/1/12 Robert Millan :
> * The headers config/kfreebsd-gnu.h etc. override
>  GLIBC_DYNAMIC_LINKER.  But the 64-bit configurations
>  x86_64-*-kfreebsd*-gnu and x86_64-*-knetbsd*-gnu do not appear to
>  use any header that would override GLIBC_DYNAMIC_LINKER32 and
>  GLIBC_DYNAMIC_LINKER64, which are what LINK_SPEC in linux64.h
>  actually uses.  Thus those configurations would use Linux-specific
>  dynamic linker settings, which seems unlikely to be as intended.

 It's not as intended. On amd64 we use /lib/ld.so.1 and
 /lib/ld-kfreebsd-x86-64.so.1.
>>>
>>> It seems x86_64-kfreebsd-gnu has been broken for a while.  I
>>> just realized that I wrote a patch to fix this in 2006 [1], but
>>> somehow it was never merged in GCC (actually I'm not even
>>> sure I submitted it).
>>>
>>> In the meantime Debian GNU/kFreeBSD has been using this
>>> patch to build GCC on their "kfreebsd-amd64" port.
>>>
>>> I can prepare an updated version of this patch (relative to
>>> trunk + your linux.h overhaul [2]).
>>
>> Here is it.
>>
>> --
>> Robert Millan
>>
>
>
>
> --
> Robert Millan
>



-- 
Robert Millan
2011-01-18  Robert Millan  

Support for AMD64 targets running GNU/kFreeBSD.

* config.gcc (tm_file): Include `i386/kfreebsd-gnu.h' on
x86_64-*-kfreebsd*-gnu.
* config/i386/kfreebsd-gnu.h
(GLIBC_DYNAMIC_LINKER32): If defined, redefine to "/lib/ld.so.1".
(GLIBC_DYNAMIC_LINKER64): If defined, redefine to
"/lib/ld-kfreebsd-x86-64.so.1".

* config/i386/linux.h (LINK_EMULATION): Redefine this macro
to a noop filter, which can be overriden by other headers.
* config/i386/linux64.h (LINK_SPEC): Process emulation names
through LINK_EMULATION().
* config/kfreebsd-gnu.h (LINK_EMULATION): Redefine to append
a "_fbsd" suffix.
* config/i386/kfreebsd-gnu.h (LINK_EMULATION): Remove macro
(superceded by the definition in config/kfreebsd-gnu.h).

Index: gcc/config.gcc
===
--- gcc/config.gcc  (revision 168952)
+++ gcc/config.gcc  (working copy)
@@ -1267,7 +1267,7 @@
case ${target} in
x86_64-*-linux*)
  default_gnu_indirect_function=glibc-2011 ;;
-   x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h" ;;
+   x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h 
i386/kfreebsd-gnu.h" ;;
x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
esac
tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc 
i386/t-crtfm t-dfprules"
Index: gcc/config/i386/linux.h
===
--- gcc/config/i386/linux.h (revision 168952)
+++ gcc/config/i386/linux.h (working copy)
@@ -91,7 +91,7 @@
done.  */
 
 /* These macros may be overridden in k*bsd-gnu.h and i386/k*bsd-gnu.h. */
-#define LINK_EMULATION "elf_i386"
+#define LINK_EMULATION(em) em
 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
 
 #undef  ASM_SPEC
@@ -100,7 +100,7 @@
 
 #undef  SUBTARGET_EXTRA_SPECS
 #define SUBTARGET_EXTRA_SPECS \
-  { "link_emulation", LINK_EMULATION },\
+  { "link_emulation", LINK_EMULATION("elf_i386") },\
   { "dynamic_linker", LINUX_DYNAMIC_LINKER }
 
 #undef LINK_SPEC
Index: gcc/config/i386/kfreebsd-gnu.h
===
--- gcc/config/i386/kfreebsd-gnu.h  (revision 168952)
+++ gcc/config/i386/kfreebsd-gnu.h  (working copy)
@@ -19,7 +19,15 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef LINK_EMULATION
-#define LINK_EMULATION "elf_i386_fbsd"
+#ifdef GLIBC_DYNAMIC_LINKER32
+#undef GLIBC_DYNAMIC_LINKER32
+#define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#endif
+
+#ifdef GLIBC_DYNAMIC_LINKER64
+#undef GLIBC_DYNAMIC_LINKER64
+#define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#endif
+
 #undef REG_NAME
 #define REG_NAME(reg) sc_ ## reg
Index: gcc/config/i386/linux64.h
===
--- gcc/config/i386/linux64.h   (revision 168952)
+++ gcc/config/i386/linux64.h   (working copy)
@@ -75,7 +75,8 @@
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef LINK_SPEC
-#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
+#define LINK_SPEC "%{" SPEC_64 ":-m " LINK_EMULATION("elf_x86_64") "} \
+  %{" SPEC_32 ":-m " LINK_EMULATION("elf_i386") "} \
   %{shared:-shared} \
   %{!shared: \
 %{!static: \
Index: gcc/config/kfreebsd-gnu.h
===
--- gcc/config/kfreebsd-gnu.h   (revision 168952)
+++ gcc

Re: PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-03-31 Thread Joseph S. Myers
I advise CC:ing the relevant target maintainers on such patch submissions.  
Since there is no *-kfreebsd-gnu maintainer (you might wish to volunteer 
to be such), and no *-linux* maintainer for the linux*.h changes, this 
means the people listed as maintainers of the i386 port.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: PING^2 [PATCH] Support for AMD64 targets running GNU/kFreeBSD

2011-03-31 Thread Robert Millan
Ping^2

2011/1/26 Robert Millan :
> Ping!
>
> 2011/1/18 Robert Millan :
>> 2011/1/14 Robert Millan :
>>> 2011/1/12 Robert Millan :
> * The headers config/kfreebsd-gnu.h etc. override
>  GLIBC_DYNAMIC_LINKER.  But the 64-bit configurations
>  x86_64-*-kfreebsd*-gnu and x86_64-*-knetbsd*-gnu do not appear to
>  use any header that would override GLIBC_DYNAMIC_LINKER32 and
>  GLIBC_DYNAMIC_LINKER64, which are what LINK_SPEC in linux64.h
>  actually uses.  Thus those configurations would use Linux-specific
>  dynamic linker settings, which seems unlikely to be as intended.

 It's not as intended. On amd64 we use /lib/ld.so.1 and
 /lib/ld-kfreebsd-x86-64.so.1.
>>>
>>> It seems x86_64-kfreebsd-gnu has been broken for a while.  I
>>> just realized that I wrote a patch to fix this in 2006 [1], but
>>> somehow it was never merged in GCC (actually I'm not even
>>> sure I submitted it).
>>>
>>> In the meantime Debian GNU/kFreeBSD has been using this
>>> patch to build GCC on their "kfreebsd-amd64" port.
>>>
>>> I can prepare an updated version of this patch (relative to
>>> trunk + your linux.h overhaul [2]).
>>
>> Here is it.
>>
>> --
>> Robert Millan
>>
>
>
>
> --
> Robert Millan
>



-- 
Robert Millan
2011-01-18  Robert Millan  

Support for AMD64 targets running GNU/kFreeBSD.

* config.gcc (tm_file): Include `i386/kfreebsd-gnu.h' on
x86_64-*-kfreebsd*-gnu.
* config/i386/kfreebsd-gnu.h
(GLIBC_DYNAMIC_LINKER32): If defined, redefine to "/lib/ld.so.1".
(GLIBC_DYNAMIC_LINKER64): If defined, redefine to
"/lib/ld-kfreebsd-x86-64.so.1".

* config/i386/linux.h (LINK_EMULATION): Redefine this macro
to a noop filter, which can be overriden by other headers.
* config/i386/linux64.h (LINK_SPEC): Process emulation names
through LINK_EMULATION().
* config/kfreebsd-gnu.h (LINK_EMULATION): Redefine to append
a "_fbsd" suffix.
* config/i386/kfreebsd-gnu.h (LINK_EMULATION): Remove macro
(superceded by the definition in config/kfreebsd-gnu.h).

Index: gcc/config.gcc
===
--- gcc/config.gcc  (revision 168952)
+++ gcc/config.gcc  (working copy)
@@ -1267,7 +1267,7 @@
case ${target} in
x86_64-*-linux*)
  default_gnu_indirect_function=glibc-2011 ;;
-   x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h" ;;
+   x86_64-*-kfreebsd*-gnu) tm_file="${tm_file} kfreebsd-gnu.h 
i386/kfreebsd-gnu.h" ;;
x86_64-*-knetbsd*-gnu) tm_file="${tm_file} knetbsd-gnu.h" ;;
esac
tmake_file="${tmake_file} i386/t-linux64 i386/t-crtstuff i386/t-crtpc 
i386/t-crtfm t-dfprules"
Index: gcc/config/i386/linux.h
===
--- gcc/config/i386/linux.h (revision 168952)
+++ gcc/config/i386/linux.h (working copy)
@@ -91,7 +91,7 @@
done.  */
 
 /* These macros may be overridden in k*bsd-gnu.h and i386/k*bsd-gnu.h. */
-#define LINK_EMULATION "elf_i386"
+#define LINK_EMULATION(em) em
 #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
 
 #undef  ASM_SPEC
@@ -100,7 +100,7 @@
 
 #undef  SUBTARGET_EXTRA_SPECS
 #define SUBTARGET_EXTRA_SPECS \
-  { "link_emulation", LINK_EMULATION },\
+  { "link_emulation", LINK_EMULATION("elf_i386") },\
   { "dynamic_linker", LINUX_DYNAMIC_LINKER }
 
 #undef LINK_SPEC
Index: gcc/config/i386/kfreebsd-gnu.h
===
--- gcc/config/i386/kfreebsd-gnu.h  (revision 168952)
+++ gcc/config/i386/kfreebsd-gnu.h  (working copy)
@@ -19,7 +19,15 @@
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-#undef LINK_EMULATION
-#define LINK_EMULATION "elf_i386_fbsd"
+#ifdef GLIBC_DYNAMIC_LINKER32
+#undef GLIBC_DYNAMIC_LINKER32
+#define GLIBC_DYNAMIC_LINKER32 "/lib/ld.so.1"
+#endif
+
+#ifdef GLIBC_DYNAMIC_LINKER64
+#undef GLIBC_DYNAMIC_LINKER64
+#define GLIBC_DYNAMIC_LINKER64 "/lib/ld-kfreebsd-x86-64.so.1"
+#endif
+
 #undef REG_NAME
 #define REG_NAME(reg) sc_ ## reg
Index: gcc/config/i386/linux64.h
===
--- gcc/config/i386/linux64.h   (revision 168952)
+++ gcc/config/i386/linux64.h   (working copy)
@@ -75,7 +75,8 @@
  %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
 
 #undef LINK_SPEC
-#define LINK_SPEC "%{" SPEC_64 ":-m elf_x86_64} %{" SPEC_32 ":-m elf_i386} \
+#define LINK_SPEC "%{" SPEC_64 ":-m " LINK_EMULATION("elf_x86_64") "} \
+  %{" SPEC_32 ":-m " LINK_EMULATION("elf_i386") "} \
   %{shared:-shared} \
   %{!shared: \
 %{!static: \
Index: gcc/config/kfreebsd-gnu.h
===
--- gcc/config/kfreebsd-gnu.h   (revision 168952)
+++ gcc/config/kfreebsd-gnu.h   (working copy)
@@ -35,3 +35,6 @@
 #undef GLIBC_DYNAMIC_LINKER
 #define GLIBC_DYNAMIC_LINKER "/lib/l