Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Jakub Jelinek
On Mon, Jan 23, 2012 at 12:03:27PM +0100, Richard Guenther wrote:
 On Mon, Jan 23, 2012 at 12:23 AM, Gerald Pfeifer ger...@pfeifer.com wrote:
  On Sat, 21 Jan 2012, Tijl Coosemans wrote:
  I've been using this patch now. It's similar to the above url, but
  conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
  versions.
 
  Gerald volunteered to commit. Gerald, just trunk for now or older
  branches too?
 
  If Richi agries, I'd apply this on trunk and the GCC 4.6 branch,
  since that is the stable release our users employ.
 
 Sure, go ahead.
 
 Richard.
 
  Gerald
 
  PS: We also need to update the copyright date at the top, and I'll
  take care of that when committing.
 
  2011-01-20  Tijl Coosemans  t...@coosemans.org
 
        * gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] 
  (LINK_SSP_SPEC): Define.

This change unfortunately broke all non-freebsd powerpc* targets.
For some weird reason freebsd-spec.h is included for all powerpc* targets
(to support -mcall-freebsd), which means that e.g. on powerpc64-linux
the above results in -fstack-protector being broken.

So, if this mess is really needed (does anybody actually use -mcall-freebsd
on non-freebsd targets?), IMHO freebsd-spec.h must avoid defining non-FBSD_
prefixed macros, as the following (completely untested) patch.  Don't have
access to FreeBSD to test it there though, can test on powerpc64-linux.

2012-02-07  Jakub Jelinek  ja...@redhat.com

* config/freebsd-spec.h (LINK_EH_SPEC, LINK_SSP_SPEC,
USE_LD_AS_NEEDED): Don't define.
(FBSD_LINK_EH_SPEC, FBSD_LINK_SSP_SPEC, FBSD_USE_LD_AS_NEEDED):
Define these instead.
* config/freebsd.h (LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED):
Redefine to FBSD_* macros if those are defined.

--- gcc/config/freebsd-spec.h.jj2012-01-30 00:10:01.0 +0100
+++ gcc/config/freebsd-spec.h   2012-02-07 09:46:05.031256945 +0100
@@ -135,14 +135,15 @@ is built with the --enable-threads confi
 #endif
 
 #if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
+#define FBSD_LINK_EH_SPEC %{!static:--eh-frame-hdr} 
 #endif
 
 #ifdef TARGET_LIBC_PROVIDES_SSP
-#define LINK_SSP_SPEC 
%{fstack-protector|fstack-protector-all:-lssp_nonshared}
+#define FBSD_LINK_SSP_SPEC \
+  %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 #endif
 
 /* Use --as-needed -lgcc_s for eh support.  */
 #ifdef HAVE_LD_AS_NEEDED
-#define USE_LD_AS_NEEDED 1
+#define FBSD_USE_LD_AS_NEEDED 1
 #endif
--- gcc/config/freebsd.h.jj 2010-11-26 18:39:09.0 +0100
+++ gcc/config/freebsd.h2012-02-07 09:48:50.872294367 +0100
@@ -1,6 +1,6 @@
 /* Base configuration file for all FreeBSD targets.
Copyright (C) 1999, 2000, 2001, 2007, 2008, 2009,
-   2010 Free Software Foundation, Inc.
+   2010, 2011, 2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -45,6 +45,21 @@ along with GCC; see the file COPYING3.
 #undef  LIB_SPEC
 #define LIB_SPEC FBSD_LIB_SPEC
 
+#ifdef FBSD_LINK_EH_SPEC
+#undef LINK_EH_SPEC
+#defineLINK_EH_SPEC FBSD_LINK_EH_SPEC
+#endif
+
+#ifdef FBSD_LINK_SSP_SPEC
+#undef LINK_SSP_SPEC
+#defineLINK_SSP_SPEC FBSD_LINK_SSP_SPEC
+#endif
+ 
+#ifdef FBSD_USE_LD_AS_NEEDED
+#undef USE_LD_AS_NEEDED
+#defineUSE_LD_AS_NEEDED FBSD_USE_LD_AS_NEEDED
+#endif
+
 /[  Target stuff  ]***/
 
 /* All FreeBSD Architectures support the ELF object file format.  */

Jakub


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Richard Guenther
On Tue, Feb 7, 2012 at 9:54 AM, Jakub Jelinek ja...@redhat.com wrote:
 On Mon, Jan 23, 2012 at 12:03:27PM +0100, Richard Guenther wrote:
 On Mon, Jan 23, 2012 at 12:23 AM, Gerald Pfeifer ger...@pfeifer.com wrote:
  On Sat, 21 Jan 2012, Tijl Coosemans wrote:
  I've been using this patch now. It's similar to the above url, but
  conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
  versions.
 
  Gerald volunteered to commit. Gerald, just trunk for now or older
  branches too?
 
  If Richi agries, I'd apply this on trunk and the GCC 4.6 branch,
  since that is the stable release our users employ.

 Sure, go ahead.

 Richard.

  Gerald
 
  PS: We also need to update the copyright date at the top, and I'll
  take care of that when committing.
 
  2011-01-20  Tijl Coosemans  t...@coosemans.org
 
        * gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] 
  (LINK_SSP_SPEC): Define.

 This change unfortunately broke all non-freebsd powerpc* targets.
 For some weird reason freebsd-spec.h is included for all powerpc* targets
 (to support -mcall-freebsd), which means that e.g. on powerpc64-linux
 the above results in -fstack-protector being broken.

 So, if this mess is really needed (does anybody actually use -mcall-freebsd
 on non-freebsd targets?), IMHO freebsd-spec.h must avoid defining non-FBSD_
 prefixed macros, as the following (completely untested) patch.  Don't have
 access to FreeBSD to test it there though, can test on powerpc64-linux.

Ugh.

I propose to revert the original patch for now.

Richard.

 2012-02-07  Jakub Jelinek  ja...@redhat.com

        * config/freebsd-spec.h (LINK_EH_SPEC, LINK_SSP_SPEC,
        USE_LD_AS_NEEDED): Don't define.
        (FBSD_LINK_EH_SPEC, FBSD_LINK_SSP_SPEC, FBSD_USE_LD_AS_NEEDED):
        Define these instead.
        * config/freebsd.h (LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED):
        Redefine to FBSD_* macros if those are defined.

 --- gcc/config/freebsd-spec.h.jj        2012-01-30 00:10:01.0 +0100
 +++ gcc/config/freebsd-spec.h   2012-02-07 09:46:05.031256945 +0100
 @@ -135,14 +135,15 @@ is built with the --enable-threads confi
  #endif

  #if defined(HAVE_LD_EH_FRAME_HDR)
 -#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
 +#define FBSD_LINK_EH_SPEC %{!static:--eh-frame-hdr} 
  #endif

  #ifdef TARGET_LIBC_PROVIDES_SSP
 -#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 +#define FBSD_LINK_SSP_SPEC \
 +  %{fstack-protector|fstack-protector-all:-lssp_nonshared}
  #endif

  /* Use --as-needed -lgcc_s for eh support.  */
  #ifdef HAVE_LD_AS_NEEDED
 -#define USE_LD_AS_NEEDED 1
 +#define FBSD_USE_LD_AS_NEEDED 1
  #endif
 --- gcc/config/freebsd.h.jj     2010-11-26 18:39:09.0 +0100
 +++ gcc/config/freebsd.h        2012-02-07 09:48:50.872294367 +0100
 @@ -1,6 +1,6 @@
  /* Base configuration file for all FreeBSD targets.
    Copyright (C) 1999, 2000, 2001, 2007, 2008, 2009,
 -   2010 Free Software Foundation, Inc.
 +   2010, 2011, 2012 Free Software Foundation, Inc.

  This file is part of GCC.

 @@ -45,6 +45,21 @@ along with GCC; see the file COPYING3.
  #undef  LIB_SPEC
  #define LIB_SPEC FBSD_LIB_SPEC

 +#ifdef FBSD_LINK_EH_SPEC
 +#undef LINK_EH_SPEC
 +#define        LINK_EH_SPEC FBSD_LINK_EH_SPEC
 +#endif
 +
 +#ifdef FBSD_LINK_SSP_SPEC
 +#undef LINK_SSP_SPEC
 +#define        LINK_SSP_SPEC FBSD_LINK_SSP_SPEC
 +#endif
 +
 +#ifdef FBSD_USE_LD_AS_NEEDED
 +#undef USE_LD_AS_NEEDED
 +#define        USE_LD_AS_NEEDED FBSD_USE_LD_AS_NEEDED
 +#endif
 +
  /[  Target stuff  
 ]***/

  /* All FreeBSD Architectures support the ELF object file format.  */

        Jakub


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Tijl Coosemans
On Tuesday 07 February 2012 09:54:43 Jakub Jelinek wrote:
 On Mon, Jan 23, 2012 at 12:03:27PM +0100, Richard Guenther wrote:
 On Mon, Jan 23, 2012 at 12:23 AM, Gerald Pfeifer ger...@pfeifer.com wrote:
 On Sat, 21 Jan 2012, Tijl Coosemans wrote:
 I've been using this patch now. It's similar to the above url, but
 conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
 versions.

 Gerald volunteered to commit. Gerald, just trunk for now or older
 branches too?

 If Richi agries, I'd apply this on trunk and the GCC 4.6 branch,
 since that is the stable release our users employ.
 
 Sure, go ahead.
 
 Richard.
 
 Gerald

 PS: We also need to update the copyright date at the top, and I'll
 take care of that when committing.

 2011-01-20  Tijl Coosemans  t...@coosemans.org

   * gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] 
 (LINK_SSP_SPEC): Define.
 
 This change unfortunately broke all non-freebsd powerpc* targets.
 For some weird reason freebsd-spec.h is included for all powerpc* targets
 (to support -mcall-freebsd), which means that e.g. on powerpc64-linux
 the above results in -fstack-protector being broken.
 
 So, if this mess is really needed (does anybody actually use -mcall-freebsd
 on non-freebsd targets?), IMHO freebsd-spec.h must avoid defining non-FBSD_
 prefixed macros, as the following (completely untested) patch.  Don't have
 access to FreeBSD to test it there though, can test on powerpc64-linux.

Everything still works on FreeBSD.

 --- gcc/config/freebsd.h.jj   2010-11-26 18:39:09.0 +0100
 +++ gcc/config/freebsd.h  2012-02-07 09:48:50.872294367 +0100
 @@ -45,6 +45,21 @@ along with GCC; see the file COPYING3.
  #undef  LIB_SPEC
  #define LIB_SPEC FBSD_LIB_SPEC
  
 +#ifdef   FBSD_LINK_EH_SPEC
 +#undef   LINK_EH_SPEC
 +#define  LINK_EH_SPEC FBSD_LINK_EH_SPEC
 +#endif
 +
 +#ifdef   FBSD_LINK_SSP_SPEC
 +#undef   LINK_SSP_SPEC
 +#define  LINK_SSP_SPEC FBSD_LINK_SSP_SPEC
 +#endif
 + 

FYI, there are extra spaces on this line.


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Jakub Jelinek
On Tue, Feb 07, 2012 at 12:17:59PM +0100, Tijl Coosemans wrote:
 Everything still works on FreeBSD.

After discussion about this on IRC Richard expressed his preference
for the following variant instead:

2012-02-07  Jakub Jelinek  ja...@redhat.com

* config/freebsd-spec.h: Add comment about what macros can be defined
in this header.
(LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED): Don't define here.
* config/freebsd.h (LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED): But
here instead.

--- gcc/config/freebsd-spec.h.jj2012-01-30 00:10:01.0 +0100
+++ gcc/config/freebsd-spec.h   2012-02-07 12:44:47.0 +0100
@@ -134,15 +134,6 @@ is built with the --enable-threads confi
 #define FBSD_DYNAMIC_LINKER /libexec/ld-elf.so.1
 #endif
 
-#if defined(HAVE_LD_EH_FRAME_HDR)
-#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
-#endif
-
-#ifdef TARGET_LIBC_PROVIDES_SSP
-#define LINK_SSP_SPEC 
%{fstack-protector|fstack-protector-all:-lssp_nonshared}
-#endif
-
-/* Use --as-needed -lgcc_s for eh support.  */
-#ifdef HAVE_LD_AS_NEEDED
-#define USE_LD_AS_NEEDED 1
-#endif
+/* NOTE: The freebsd-spec.h header is included also for various
+   non-FreeBSD powerpc targets, thus it should never define macros
+   other than FBSD_* prefixed ones, or USING_CONFIG_FREEBSD_SPEC.  */
--- gcc/config/freebsd.h.jj 2010-11-26 18:39:09.0 +0100
+++ gcc/config/freebsd.h2012-02-07 12:45:34.497798123 +0100
@@ -1,6 +1,6 @@
 /* Base configuration file for all FreeBSD targets.
Copyright (C) 1999, 2000, 2001, 2007, 2008, 2009,
-   2010 Free Software Foundation, Inc.
+   2010, 2011, 2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -45,6 +45,19 @@ along with GCC; see the file COPYING3.
 #undef  LIB_SPEC
 #define LIB_SPEC FBSD_LIB_SPEC
 
+#if defined(HAVE_LD_EH_FRAME_HDR)
+#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
+#endif
+
+#ifdef TARGET_LIBC_PROVIDES_SSP
+#define LINK_SSP_SPEC 
%{fstack-protector|fstack-protector-all:-lssp_nonshared}
+#endif
+
+/* Use --as-needed -lgcc_s for eh support.  */
+#ifdef HAVE_LD_AS_NEEDED
+#define USE_LD_AS_NEEDED 1
+#endif
+
 /[  Target stuff  ]***/
 
 /* All FreeBSD Architectures support the ELF object file format.  */


Jakub


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Richard Guenther
On Tue, Feb 7, 2012 at 12:53 PM, Jakub Jelinek ja...@redhat.com wrote:
 On Tue, Feb 07, 2012 at 12:17:59PM +0100, Tijl Coosemans wrote:
 Everything still works on FreeBSD.

 After discussion about this on IRC Richard expressed his preference
 for the following variant instead:

Ok.

Thanks,
Richard.

 2012-02-07  Jakub Jelinek  ja...@redhat.com

        * config/freebsd-spec.h: Add comment about what macros can be defined
        in this header.
        (LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED): Don't define here.
        * config/freebsd.h (LINK_EH_SPEC, LINK_SSP_SPEC, USE_LD_AS_NEEDED): But
        here instead.

 --- gcc/config/freebsd-spec.h.jj        2012-01-30 00:10:01.0 +0100
 +++ gcc/config/freebsd-spec.h   2012-02-07 12:44:47.0 +0100
 @@ -134,15 +134,6 @@ is built with the --enable-threads confi
  #define FBSD_DYNAMIC_LINKER /libexec/ld-elf.so.1
  #endif

 -#if defined(HAVE_LD_EH_FRAME_HDR)
 -#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
 -#endif
 -
 -#ifdef TARGET_LIBC_PROVIDES_SSP
 -#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 -#endif
 -
 -/* Use --as-needed -lgcc_s for eh support.  */
 -#ifdef HAVE_LD_AS_NEEDED
 -#define USE_LD_AS_NEEDED 1
 -#endif
 +/* NOTE: The freebsd-spec.h header is included also for various
 +   non-FreeBSD powerpc targets, thus it should never define macros
 +   other than FBSD_* prefixed ones, or USING_CONFIG_FREEBSD_SPEC.  */
 --- gcc/config/freebsd.h.jj     2010-11-26 18:39:09.0 +0100
 +++ gcc/config/freebsd.h        2012-02-07 12:45:34.497798123 +0100
 @@ -1,6 +1,6 @@
  /* Base configuration file for all FreeBSD targets.
    Copyright (C) 1999, 2000, 2001, 2007, 2008, 2009,
 -   2010 Free Software Foundation, Inc.
 +   2010, 2011, 2012 Free Software Foundation, Inc.

  This file is part of GCC.

 @@ -45,6 +45,19 @@ along with GCC; see the file COPYING3.
  #undef  LIB_SPEC
  #define LIB_SPEC FBSD_LIB_SPEC

 +#if defined(HAVE_LD_EH_FRAME_HDR)
 +#define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
 +#endif
 +
 +#ifdef TARGET_LIBC_PROVIDES_SSP
 +#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 +#endif
 +
 +/* Use --as-needed -lgcc_s for eh support.  */
 +#ifdef HAVE_LD_AS_NEEDED
 +#define USE_LD_AS_NEEDED 1
 +#endif
 +
  /[  Target stuff  
 ]***/

  /* All FreeBSD Architectures support the ELF object file format.  */


        Jakub


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Joseph S. Myers
On Tue, 7 Feb 2012, Jakub Jelinek wrote:

 So, if this mess is really needed (does anybody actually use -mcall-freebsd
 on non-freebsd targets?), IMHO freebsd-spec.h must avoid defining non-FBSD_

I've argued for a long time that the -mcall-* support should be removed 
and targets using rs6000/sysv4.h should move to the standard approach of 
each configuration defining and using its own specs where the specs differ 
between targets (in particular, making powerpc*-linux* use linux.h and 
gnu-user.h like most other targets using the Linux kernel do).  There's a 
point about this in the development conventions document at 
https://docs.google.com/document/pub?id=10LO8y0YhjlKHya_PKM3jEGrJu0rllv-Nc9qP5LXqH_I.
  
I don't think -mcall-* will form any useful part of proper multi-target 
support.

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


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Jakub Jelinek
On Tue, Feb 07, 2012 at 01:13:35PM +, Joseph S. Myers wrote:
 On Tue, 7 Feb 2012, Jakub Jelinek wrote:
 
  So, if this mess is really needed (does anybody actually use -mcall-freebsd
  on non-freebsd targets?), IMHO freebsd-spec.h must avoid defining non-FBSD_
 
 I've argued for a long time that the -mcall-* support should be removed 
 and targets using rs6000/sysv4.h should move to the standard approach of 
 each configuration defining and using its own specs where the specs differ 
 between targets (in particular, making powerpc*-linux* use linux.h and 
 gnu-user.h like most other targets using the Linux kernel do).  There's a 
 point about this in the development conventions document at 
 https://docs.google.com/document/pub?id=10LO8y0YhjlKHya_PKM3jEGrJu0rllv-Nc9qP5LXqH_I.
   
 I don't think -mcall-* will form any useful part of proper multi-target 
 support.

I agree, not sure if I'll have time for that though.  Not a stage4 material
though IMHO.

Jakub


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-02-07 Thread Tijl Coosemans
On Tuesday 07 February 2012 12:53:24 Jakub Jelinek wrote:
 On Tue, Feb 07, 2012 at 12:17:59PM +0100, Tijl Coosemans wrote:
 Everything still works on FreeBSD.
 
 After discussion about this on IRC Richard expressed his preference
 for the following variant instead:

Works too.


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-23 Thread Richard Guenther
On Mon, Jan 23, 2012 at 12:23 AM, Gerald Pfeifer ger...@pfeifer.com wrote:
 On Sat, 21 Jan 2012, Tijl Coosemans wrote:
 I've been using this patch now. It's similar to the above url, but
 conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
 versions.

 Gerald volunteered to commit. Gerald, just trunk for now or older
 branches too?

 If Richi agries, I'd apply this on trunk and the GCC 4.6 branch,
 since that is the stable release our users employ.

Sure, go ahead.

Richard.

 Gerald

 PS: We also need to update the copyright date at the top, and I'll
 take care of that when committing.

 2011-01-20  Tijl Coosemans  t...@coosemans.org

       * gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] 
 (LINK_SSP_SPEC): Define.

 --- gcc/config/freebsd-spec.h
 +++ gcc/config/freebsd-spec.h
 @@ -138,6 +138,10 @@ is built with the --enable-threads confi
  #define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
  #endif

 +#ifdef TARGET_LIBC_PROVIDES_SSP
 +#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 +#endif
 +
  /* Use --as-needed -lgcc_s for eh support.  */
  #ifdef HAVE_LD_AS_NEEDED
  #define USE_LD_AS_NEEDED 1



Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-22 Thread Gerald Pfeifer
On Sat, 21 Jan 2012, Tijl Coosemans wrote:
 I've been using this patch now. It's similar to the above url, but
 conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
 versions.
 
 Gerald volunteered to commit. Gerald, just trunk for now or older
 branches too?

If Richi agries, I'd apply this on trunk and the GCC 4.6 branch,
since that is the stable release our users employ.

Gerald

PS: We also need to update the copyright date at the top, and I'll
take care of that when committing.

 2011-01-20  Tijl Coosemans  t...@coosemans.org
 
   * gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] (LINK_SSP_SPEC): 
 Define.
 
 --- gcc/config/freebsd-spec.h
 +++ gcc/config/freebsd-spec.h
 @@ -138,6 +138,10 @@ is built with the --enable-threads confi
  #define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
  #endif
  
 +#ifdef TARGET_LIBC_PROVIDES_SSP
 +#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
 +#endif
 +
  /* Use --as-needed -lgcc_s for eh support.  */
  #ifdef HAVE_LD_AS_NEEDED
  #define USE_LD_AS_NEEDED 1
 


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-20 Thread Tijl Coosemans
On Wednesday 11 January 2012 10:06:42 Richard Guenther wrote:
 On Tue, Jan 10, 2012 at 8:50 PM, Tijl Coosemans t...@freebsd.org wrote:
 On Tuesday 10 January 2012 15:40:15 Richard Guenther wrote:
 On Tue, Jan 10, 2012 at 3:38 PM, Richard Guenther
 richard.guent...@gmail.com wrote:
 On Tue, Jan 10, 2012 at 3:14 PM, Tijl Coosemans t...@coosemans.org wrote:
 On targets where libc implements stack protector functions (GNU libc,
 FreeBSD libc), and where gcc (as an optimisation) generates calls to
 a locally defined __stack_chk_fail_local instead of directly calling
 the global function __stack_chk_fail (e.g. -fpic code on i386), one
 must explicitly specify -lssp_nonshared or -lc -lc_nonshared on the
 command line to statically link in __stack_chk_fail_local.

 It would be more convenient if the compiler kept the details of this
 target specific optimisation hidden by passing -lssp_nonshared to the
 linker internally.

 Here's a simple test case that shows the problem on i386-freebsd, but
 works just fine on e.g. x86_64 targets:

 % cat test.c
 int
 main( void ) {
return( 0 );
 }
 % gcc46 -o test test.c -fstack-protector-all -fPIE
 /var/tmp//ccjYQxKu.o: In function `main':
 test.c:(.text+0x37): undefined reference to `__stack_chk_fail_local'
 /usr/local/bin/ld: test: hidden symbol `__stack_chk_fail_local' isn't 
 defined
 /usr/local/bin/ld: final link failed: Bad value
 collect2: ld returned 1 exit status


 I don't have commit access, so please commit when approved.

 Works fine for me on i?86-linux without -lssp_nonshared (which I do not
 have, so linking would fail).

 So my patch would actually break Linux?
 
 Yes.
 
 Probably because libc.so is a linker script:

 /* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily.  */
 OUTPUT_FORMAT(elf64-x86-64)
 GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED (
 /lib64/ld-linux-x86-64.so.2 ) )

 and /usr/lib64/libc_nonshared.a provides the symbol.  Why not fix it that
 way on *BSD?

 I'll discuss it with some FreeBSD developers. Currently FreeBSD doesn't
 use linker scripts anywhere. Would a FreeBSD specific version of the
 patch be acceptable? For instance, the version of GCC shipped with
 FreeBSD has been patched like this:
 http://svnweb.freebsd.org/base/head/contrib/gcc/config/freebsd-spec.h?r1=195697r2=195696
 
 That looks better to me.

I've been using this patch now. It's similar to the above url, but
conditional on TARGET_LIBC_PROVIDES_SSP to support older FreeBSD
versions.

Gerald volunteered to commit. Gerald, just trunk for now or older
branches too?


2011-01-20  Tijl Coosemans  t...@coosemans.org

* gcc/config/freebsd-spec.h [TARGET_LIBC_PROVIDES_SSP] (LINK_SSP_SPEC): 
Define.

--- gcc/config/freebsd-spec.h
+++ gcc/config/freebsd-spec.h
@@ -138,6 +138,10 @@ is built with the --enable-threads confi
 #define LINK_EH_SPEC %{!static:--eh-frame-hdr} 
 #endif
 
+#ifdef TARGET_LIBC_PROVIDES_SSP
+#define LINK_SSP_SPEC 
%{fstack-protector|fstack-protector-all:-lssp_nonshared}
+#endif
+
 /* Use --as-needed -lgcc_s for eh support.  */
 #ifdef HAVE_LD_AS_NEEDED
 #define USE_LD_AS_NEEDED 1


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-11 Thread Richard Guenther
On Tue, Jan 10, 2012 at 8:50 PM, Tijl Coosemans t...@freebsd.org wrote:
 On Tuesday 10 January 2012 15:40:15 Richard Guenther wrote:
 On Tue, Jan 10, 2012 at 3:38 PM, Richard Guenther
 richard.guent...@gmail.com wrote:
 On Tue, Jan 10, 2012 at 3:14 PM, Tijl Coosemans t...@coosemans.org wrote:
 On targets where libc implements stack protector functions (GNU libc,
 FreeBSD libc), and where gcc (as an optimisation) generates calls to
 a locally defined __stack_chk_fail_local instead of directly calling
 the global function __stack_chk_fail (e.g. -fpic code on i386), one
 must explicitly specify -lssp_nonshared or -lc -lc_nonshared on the
 command line to statically link in __stack_chk_fail_local.

 It would be more convenient if the compiler kept the details of this
 target specific optimisation hidden by passing -lssp_nonshared to the
 linker internally.

 Here's a simple test case that shows the problem on i386-freebsd, but
 works just fine on e.g. x86_64 targets:

 % cat test.c
 int
 main( void ) {
    return( 0 );
 }
 % gcc46 -o test test.c -fstack-protector-all -fPIE
 /var/tmp//ccjYQxKu.o: In function `main':
 test.c:(.text+0x37): undefined reference to `__stack_chk_fail_local'
 /usr/local/bin/ld: test: hidden symbol `__stack_chk_fail_local' isn't 
 defined
 /usr/local/bin/ld: final link failed: Bad value
 collect2: ld returned 1 exit status


 I don't have commit access, so please commit when approved.

 Works fine for me on i?86-linux without -lssp_nonshared (which I do not
 have, so linking would fail).

 So my patch would actually break Linux?

Yes.

 Probably because libc.so is a linker script:

 /* GNU ld script
    Use the shared library, but some functions are only in
    the static library, so try that secondarily.  */
 OUTPUT_FORMAT(elf64-x86-64)
 GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED (
 /lib64/ld-linux-x86-64.so.2 ) )

 and /usr/lib64/libc_nonshared.a provides the symbol.  Why not fix it that
 way on *BSD?

 I'll discuss it with some FreeBSD developers. Currently FreeBSD doesn't
 use linker scripts anywhere. Would a FreeBSD specific version of the
 patch be acceptable? For instance, the version of GCC shipped with
 FreeBSD has been patched like this:
 http://svnweb.freebsd.org/base/head/contrib/gcc/config/freebsd-spec.h?r1=195697r2=195696

That looks better to me.

Richard.


Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-10 Thread Tijl Coosemans
On targets where libc implements stack protector functions (GNU libc,
FreeBSD libc), and where gcc (as an optimisation) generates calls to
a locally defined __stack_chk_fail_local instead of directly calling
the global function __stack_chk_fail (e.g. -fpic code on i386), one
must explicitly specify -lssp_nonshared or -lc -lc_nonshared on the
command line to statically link in __stack_chk_fail_local.

It would be more convenient if the compiler kept the details of this
target specific optimisation hidden by passing -lssp_nonshared to the
linker internally.

Here's a simple test case that shows the problem on i386-freebsd, but
works just fine on e.g. x86_64 targets:

% cat test.c
int
main( void ) {
return( 0 );
}
% gcc46 -o test test.c -fstack-protector-all -fPIE
/var/tmp//ccjYQxKu.o: In function `main':
test.c:(.text+0x37): undefined reference to `__stack_chk_fail_local'
/usr/local/bin/ld: test: hidden symbol `__stack_chk_fail_local' isn't defined
/usr/local/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status


I don't have commit access, so please commit when approved.

2011-01-10  Tijl Coosemans  t...@coosemans.org

* gcc.c [TARGET_LIBC_PROVIDES_SSP] (LINK_SSP_SPEC): Add -lssp_nonshared.

--- gcc/gcc.c.orig
+++ gcc/gcc.c
@@ -602,7 +602,7 @@ proper position among the other output f
 
 #ifndef LINK_SSP_SPEC
 #ifdef TARGET_LIBC_PROVIDES_SSP
-#define LINK_SSP_SPEC %{fstack-protector:}
+#define LINK_SSP_SPEC 
%{fstack-protector|fstack-protector-all:-lssp_nonshared}
 #else
 #define LINK_SSP_SPEC %{fstack-protector|fstack-protector-all:-lssp_nonshared 
-lssp}
 #endif


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-10 Thread Richard Guenther
On Tue, Jan 10, 2012 at 3:14 PM, Tijl Coosemans t...@coosemans.org wrote:
 On targets where libc implements stack protector functions (GNU libc,
 FreeBSD libc), and where gcc (as an optimisation) generates calls to
 a locally defined __stack_chk_fail_local instead of directly calling
 the global function __stack_chk_fail (e.g. -fpic code on i386), one
 must explicitly specify -lssp_nonshared or -lc -lc_nonshared on the
 command line to statically link in __stack_chk_fail_local.

 It would be more convenient if the compiler kept the details of this
 target specific optimisation hidden by passing -lssp_nonshared to the
 linker internally.

 Here's a simple test case that shows the problem on i386-freebsd, but
 works just fine on e.g. x86_64 targets:

 % cat test.c
 int
 main( void ) {
    return( 0 );
 }
 % gcc46 -o test test.c -fstack-protector-all -fPIE
 /var/tmp//ccjYQxKu.o: In function `main':
 test.c:(.text+0x37): undefined reference to `__stack_chk_fail_local'
 /usr/local/bin/ld: test: hidden symbol `__stack_chk_fail_local' isn't defined
 /usr/local/bin/ld: final link failed: Bad value
 collect2: ld returned 1 exit status


 I don't have commit access, so please commit when approved.

Works fine for me on i?86-linux without -lssp_nonshared (which I do not
have, so linking would fail).

Richard.

 2011-01-10  Tijl Coosemans  t...@coosemans.org

        * gcc.c [TARGET_LIBC_PROVIDES_SSP] (LINK_SSP_SPEC): Add 
 -lssp_nonshared.

 --- gcc/gcc.c.orig
 +++ gcc/gcc.c
 @@ -602,7 +602,7 @@ proper position among the other output f

  #ifndef LINK_SSP_SPEC
  #ifdef TARGET_LIBC_PROVIDES_SSP
 -#define LINK_SSP_SPEC %{fstack-protector:}
 +#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
  #else
  #define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}
  #endif


Re: Add -lssp_nonshared to LINK_SSP_SPEC

2012-01-10 Thread Tijl Coosemans
On Tuesday 10 January 2012 15:40:15 Richard Guenther wrote:
 On Tue, Jan 10, 2012 at 3:38 PM, Richard Guenther
 richard.guent...@gmail.com wrote:
 On Tue, Jan 10, 2012 at 3:14 PM, Tijl Coosemans t...@coosemans.org wrote:
 On targets where libc implements stack protector functions (GNU libc,
 FreeBSD libc), and where gcc (as an optimisation) generates calls to
 a locally defined __stack_chk_fail_local instead of directly calling
 the global function __stack_chk_fail (e.g. -fpic code on i386), one
 must explicitly specify -lssp_nonshared or -lc -lc_nonshared on the
 command line to statically link in __stack_chk_fail_local.

 It would be more convenient if the compiler kept the details of this
 target specific optimisation hidden by passing -lssp_nonshared to the
 linker internally.

 Here's a simple test case that shows the problem on i386-freebsd, but
 works just fine on e.g. x86_64 targets:

 % cat test.c
 int
 main( void ) {
return( 0 );
 }
 % gcc46 -o test test.c -fstack-protector-all -fPIE
 /var/tmp//ccjYQxKu.o: In function `main':
 test.c:(.text+0x37): undefined reference to `__stack_chk_fail_local'
 /usr/local/bin/ld: test: hidden symbol `__stack_chk_fail_local' isn't 
 defined
 /usr/local/bin/ld: final link failed: Bad value
 collect2: ld returned 1 exit status


 I don't have commit access, so please commit when approved.

 Works fine for me on i?86-linux without -lssp_nonshared (which I do not
 have, so linking would fail).

So my patch would actually break Linux?

 Probably because libc.so is a linker script:
 
 /* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily.  */
 OUTPUT_FORMAT(elf64-x86-64)
 GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED (
 /lib64/ld-linux-x86-64.so.2 ) )
 
 and /usr/lib64/libc_nonshared.a provides the symbol.  Why not fix it that
 way on *BSD?

I'll discuss it with some FreeBSD developers. Currently FreeBSD doesn't
use linker scripts anywhere. Would a FreeBSD specific version of the
patch be acceptable? For instance, the version of GCC shipped with
FreeBSD has been patched like this:
http://svnweb.freebsd.org/base/head/contrib/gcc/config/freebsd-spec.h?r1=195697r2=195696

 2011-01-10  Tijl Coosemans  t...@coosemans.org

* gcc.c [TARGET_LIBC_PROVIDES_SSP] (LINK_SSP_SPEC): Add 
 -lssp_nonshared.

 --- gcc/gcc.c.orig
 +++ gcc/gcc.c
 @@ -602,7 +602,7 @@ proper position among the other output f

  #ifndef LINK_SSP_SPEC
  #ifdef TARGET_LIBC_PROVIDES_SSP
 -#define LINK_SSP_SPEC %{fstack-protector:}
 +#define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared}
  #else
  #define LINK_SSP_SPEC 
 %{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}
  #endif