From patchwork Mon Apr 4 18:17:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 89674 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 02EFAB6F86 for ; Tue, 5 Apr 2011 04:17:51 +1000 (EST) Received: (qmail 12383 invoked by alias); 4 Apr 2011 18:17:49 -0000 Received: (qmail 12370 invoked by uid 22791); 4 Apr 2011 18:17:48 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Apr 2011 18:17:42 +0000 Received: from hpaq6.eem.corp.google.com (hpaq6.eem.corp.google.com [172.25.149.6]) by smtp-out.google.com with ESMTP id p34IHftU019899 for ; Mon, 4 Apr 2011 11:17:42 -0700 Received: from elbrus2.mtv.corp.google.com (elbrus2.mtv.corp.google.com [172.18.116.96]) by hpaq6.eem.corp.google.com with ESMTP id p34IHc7j026856; Mon, 4 Apr 2011 11:17:39 -0700 Received: by elbrus2.mtv.corp.google.com (Postfix, from userid 74925) id 52D661909EB; Mon, 4 Apr 2011 11:17:38 -0700 (PDT) To: gcc-patches@sourceware.org Cc: satorux@google.com, iant@google.com, ppluzhnikov@google.com Subject: [patch] make default linker --hash-style configurable option Message-Id: <20110404181738.52D661909EB@elbrus2.mtv.corp.google.com> Date: Mon, 4 Apr 2011 11:17:38 -0700 (PDT) From: ppluzhnikov@google.com (Paul Pluzhnikov) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Greetings, Several Linux distributions (e.g. Fedora) carry local patches that turn on --hash-style=gnu for all links. Attached is a proposed patch (originally by Satoru Takabayashi) that makes default hash style a configure option. Tested by doing native bootstrap and verifying that no --hash-style is passed to the linker, and also configuring with --with-linker-hash-style=gnu and verifying that --hash-style=gnu is then passed to the linker. Ok for trunk? Thanks, P.S. Google has a blanket copyright assignment to FSF. --- Paul Pluzhnikov 2011-04-04 Satoru Takabayashi Paul Pluzhnikov * gcc/doc/install.texi (Configuration): Document --with-linker-hash-style. * gcc/gcc.c (init_spec): Handle LINKER_HASH_STYLE. * gcc/config.in: Add LINKER_HASH_STYLE. * gcc/configure.ac: Add --with-linker-hash-style. * gcc/configure: Regenerate. Index: gcc/doc/install.texi =================================================================== --- gcc/doc/install.texi (revision 171942) +++ gcc/doc/install.texi (working copy) @@ -1657,6 +1657,11 @@ support @option{--build-id} option, a warning is issued and the @option{--enable-linker-build-id} option is ignored. The default is off. +@item --with-linker-hash-style=@var{choice} +Tells GCC to pass @option{--hash-style=@var{choice}} option to the +linker for all final links. @var{choice} can be one of +@samp{sysv}, @samp{gnu}, and @samp{both} where @samp{sysv} is the default. + @item --enable-gnu-unique-object @itemx --disable-gnu-unique-object Tells GCC to use the gnu_unique_object relocation for C++ template Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 171942) +++ gcc/gcc.c (working copy) @@ -1438,7 +1438,8 @@ } #endif -#if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC +#if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \ + defined LINKER_HASH_STYLE # ifdef LINK_BUILDID_SPEC /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof(LINK_BUILDID_SPEC) - 1); @@ -1447,6 +1448,16 @@ /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ obstack_grow (&obstack, LINK_EH_SPEC, sizeof(LINK_EH_SPEC) - 1); # endif +# ifdef LINKER_HASH_STYLE + /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had + before. */ + { + static const char hash_style[] = "--hash-style="; + obstack_grow (&obstack, hash_style, sizeof(hash_style) - 1); + obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof(LINKER_HASH_STYLE) - 1); + obstack_1grow (&obstack, ' '); + } +# endif obstack_grow0 (&obstack, link_spec, strlen (link_spec)); link_spec = XOBFINISH (&obstack, const char *); #endif Index: gcc/config.in =================================================================== --- gcc/config.in (revision 171942) +++ gcc/config.in (working copy) @@ -1580,6 +1580,12 @@ #endif +/* The linker hash style */ +#ifndef USED_FOR_TARGET +#undef LINKER_HASH_STYLE +#endif + + /* Define to the name of the LTO plugin DSO that must be passed to the linker's -plugin=LIB option. */ #ifndef USED_FOR_TARGET Index: gcc/configure.ac =================================================================== --- gcc/configure.ac (revision 171942) +++ gcc/configure.ac (working copy) @@ -4936,6 +4936,30 @@ fi +# Specify what hash style to use by default. +AC_ARG_WITH([linker-hash-style], +[AC_HELP_STRING([--with-linker-hash-style={sysv,gnu,both}], + [specify the linker hash style])], +[case x"$withval" in + xsysv) + LINKER_HASH_STYLE=sysv + ;; + xgnu) + LINKER_HASH_STYLE=gnu + ;; + xboth) + LINKER_HASH_STYLE=both + ;; + *) + AC_MSG_ERROR([$withval is an invalid option to --with-linker-hash-style]) + ;; + esac], +[LINKER_HASH_STYLE='']) +if test x"${LINKER_HASH_STYLE}" != x; then + AC_DEFINE_UNQUOTED(LINKER_HASH_STYLE, "$LINKER_HASH_STYLE", + [The linker hash style]) +fi + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs) Index: gcc/configure =================================================================== --- gcc/configure (revision 171942) +++ gcc/configure (working copy) @@ -913,6 +913,7 @@ with_slibdir enable_plugin enable_libquadmath_support +with_linker_hash_style ' ac_precious_vars='build_alias host_alias @@ -1663,6 +1664,8 @@ with the compiler --with-system-zlib use installed libz --with-slibdir=DIR shared libraries in DIR [LIBDIR] + --with-linker-hash-style={sysv,gnu,both} + specify the linker hash style Some influential environment variables: CC C compiler command @@ -17505,7 +17508,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17508 "configure" +#line 17511 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -17611,7 +17614,7 @@ lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 17614 "configure" +#line 17617 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -26461,6 +26464,36 @@ fi +# Specify what hash style to use by default. + +# Check whether --with-linker-hash-style was given. +if test "${with_linker_hash_style+set}" = set; then : + withval=$with_linker_hash_style; case x"$withval" in + xsysv) + LINKER_HASH_STYLE=sysv + ;; + xgnu) + LINKER_HASH_STYLE=gnu + ;; + xboth) + LINKER_HASH_STYLE=both + ;; + *) + as_fn_error "$withval is an invalid option to --with-linker-hash-style" "$LINENO" 5 + ;; + esac +else + LINKER_HASH_STYLE='' +fi + +if test x"${LINKER_HASH_STYLE}" != x; then + +cat >>confdefs.h <<_ACEOF +#define LINKER_HASH_STYLE "$LINKER_HASH_STYLE" +_ACEOF + +fi + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs)