From patchwork Tue Mar 31 15:58:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 456664 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3745E14018C for ; Wed, 1 Apr 2015 02:58:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vrkGYobb; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=Zz9y/2RTiycCFXslE2 tEvM3VG5j8/VG1q9fSPpfpQnK787tODPmppBgDXzyyQUG/diM57pjU42+FGQKiIu zUWsjbg3xydreBaoaOegi7PhnYx/1GZfm4MHL6Y8JGCoUldB1UMMCJUteKq9e0wU zBSNloY/6rQ+sgePz73x17fag= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=H2Anhmz8la/80XrEVElKhHTb yvg=; b=vrkGYobbtbivnM9uLgtmpgTgFkTkmoSk6J+yYjtUgoqn5QYbnGQGqG/J GgAfxR8Ih3BllA6Hr8tt21QU01j0qK5va76LeGwe3JhDDZ/D6BVqav4tsh+tfR2y F2u+S4abJFcac5q0Y+WjNqHvrJdm+SwYSmoe3BUox/2unFKBVOI= Received: (qmail 9203 invoked by alias); 31 Mar 2015 15:58:28 -0000 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 Received: (qmail 9175 invoked by uid 89); 31 Mar 2015 15:58:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: Yes, score=5.6 required=5.0 tests=AWL, BAYES_99, BAYES_999, FREEMAIL_FROM, KAM_FROM_URIBL_PCCC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ob0-f169.google.com Received: from mail-ob0-f169.google.com (HELO mail-ob0-f169.google.com) (209.85.214.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 31 Mar 2015 15:58:25 +0000 Received: by obvd1 with SMTP id d1so33368565obv.0 for ; Tue, 31 Mar 2015 08:58:23 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.28.39 with SMTP id y7mr33583755obg.11.1427817503835; Tue, 31 Mar 2015 08:58:23 -0700 (PDT) Received: by 10.76.134.102 with HTTP; Tue, 31 Mar 2015 08:58:23 -0700 (PDT) In-Reply-To: References: <20150330022527.GA4148@gmail.com> <20150331053855.GB2121@tucnak.redhat.com> Date: Tue, 31 Mar 2015 08:58:23 -0700 Message-ID: Subject: Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE From: "H.J. Lu" To: Jack Howarth , Ian Lance Taylor Cc: Jakub Jelinek , GCC Patches , Uros Bizjak , Iain Sandoe , Mike Stump X-IsSubscribed: yes On Tue, Mar 31, 2015 at 7:25 AM, Jack Howarth wrote: > H.J., > While the latest patch fails to bootstrap on x86_64-apple-darwin14... > > _restore_x86_fp_state in os-unix-sysdep.o > _sysdep_save_fp_ctrl_state in os-unix-sysdep.o > ld: symbol(s) not found for architecture x86_64 > collect2: error: ld returned 1 exit status > Makefile:540: recipe for target 'libcilkrts.la' failed > make[2]: *** [libcilkrts.la] Error 1 > make[2]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libcilkrts' > Makefile:13569: recipe for target 'all-target-libcilkrts' failed > make[1]: *** [all-target-libcilkrts] Error 2 > make[1]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' > Makefile:21064: recipe for target 'bootstrap' failed > make: *** [bootstrap] Error 2 > > as darwin will require the new usage of libgcc_nonshared.a to be added > to the spec handling with... Here is the updated patch to make libgcc_nonshared.a optional so that it is only needed on Linux. > Index: gcc/config/darwin.h > =================================================================== > --- gcc/config/darwin.h (revision 221794) > +++ gcc/config/darwin.h (working copy) > @@ -325,7 +325,7 @@ extern GTY(()) int darwin_ms_struct; > need symbols from -lgcc. */ > #undef REAL_LIBGCC_SPEC > #define REAL_LIBGCC_SPEC \ > - "%{static-libgcc|static: -lgcc_eh -lgcc; \ > + "%{static-libgcc|static: -lgcc_eh -lgcc_nonshared -lgcc; \ > shared-libgcc|fexceptions|fgnu-runtime: \ > %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4) \ > %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \ > @@ -336,7 +336,7 @@ extern GTY(()) int darwin_ms_struct; > %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \ > %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_ext.10.4) \ > %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_ext.10.5) \ > - -lgcc }" > + -lgcc_nonshared -lgcc }" > > /* We specify crt0.o as -lcrt0.o so that ld will search the library path. > > Jack > ps One minor nit... > > Index: gcc/gcc.c > =================================================================== > --- gcc/gcc.c (revision 221794) > +++ gcc/gcc.c (working copy) > @@ -1566,11 +1566,13 @@ init_spec (void) > if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) > { > init_gcc_specs (&obstack, > + "-lgcc_nonshared " > "-lgcc_s" > #ifdef USE_LIBUNWIND_EXCEPTIONS > " -lunwind" > #endif > , > + "-lgcc_nonshared " > "-lgcc", > "-lgcc_eh" > #ifdef USE_LIBUNWIND_EXCEPTIONS > @@ -1591,7 +1593,9 @@ init_spec (void) > /* Ug. We don't know shared library extensions. Hope that > systems that use this form don't do shared libraries. */ > init_gcc_specs (&obstack, > + "libgcc_nonshared.a%s " > "-lgcc_s", > + "libgcc_nonshared.a%s " > "libgcc.a%s", > "libgcc_eh.a%s" > > You seem to have unnecessary trailing whitespace at the end of these flags. > The white space is needed to avoid -lgcc_nonshared-lgcc_s. From 760b79124482860b4317f4d39fbe898cfbe8e47b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 29 Mar 2015 18:03:49 -0700 Subject: [PATCH] Hide __cpu_indicator_init/__cpu_model from linker We shouldn't call external function, __cpu_indicator_init, while an object is being relocated since its .got.plt section hasn't been updated. It works for non-PIE since no update on .got.plt section is required. This patch hides __cpu_indicator_init/__cpu_model from linker to force linker to resolve __cpu_indicator_init/__cpu_model to their hidden definitions in libgcc_nonshared.a while providing backward binary compatibility. The new libgcc_nonshared.a is always linked togther with -lgcc_s and -lgcc. gcc/ PR target/65612 * gcc.c (init_spec): Add -lgcc_nonshared/libgcc_nonshared.a%s to -lgcc_s. gcc/testsuite/ PR target/65612 * g++.dg/ext/mv18.C: New test. * g++.dg/ext/mv19.C: Likewise. * g++.dg/ext/mv20.C: Likewise. * g++.dg/ext/mv21.C: Likewise. * g++.dg/ext/mv22.C: Likewise. * g++.dg/ext/mv23.C: Likewise. libgcc/ PR target/65612 * Makefile.in (LIB2ADDNONSHARED): New. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. Check unsupported files in LIB2ADDNONSHARED. (iter-items): Add $(LIB2ADDNONSHARED). (all): Depend on libgcc_nonshared.a. ($(libgcc-nonshared-objects)): Depend on libgcc_tm.h. (install-leaf): Install libgcc_nonshared.a. * shared-object.mk: Check empty $o. * config/i386/cpuinfo.c (__cpu_model): Initialize. (__cpu_indicator_init@GCC_4.8.0): New. (__cpu_model@GCC_4.8.0): Likewise. * config/i386/t-cpuinfo (LIB2ADDNONSHARED): New. * config/i386/t-linux (HOST_LIBGCC2_CFLAGS): Add -DUSE_ELF_SYMVER. --- gcc/gcc.c | 2 ++ gcc/testsuite/g++.dg/ext/mv18.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv19.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv20.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv21.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv22.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv23.C | 7 +++++++ libgcc/Makefile.in | 22 +++++++++++++++++++--- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-cpuinfo | 1 + libgcc/config/i386/t-linux | 2 +- libgcc/shared-object.mk | 2 ++ 12 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/mv18.C create mode 100644 gcc/testsuite/g++.dg/ext/mv19.C create mode 100644 gcc/testsuite/g++.dg/ext/mv20.C create mode 100644 gcc/testsuite/g++.dg/ext/mv21.C create mode 100644 gcc/testsuite/g++.dg/ext/mv22.C create mode 100644 gcc/testsuite/g++.dg/ext/mv23.C diff --git a/gcc/gcc.c b/gcc/gcc.c index d956c36..3fbd549 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1566,6 +1566,7 @@ init_spec (void) if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0) { init_gcc_specs (&obstack, + "-lgcc_nonshared " "-lgcc_s" #ifdef USE_LIBUNWIND_EXCEPTIONS " -lunwind" @@ -1591,6 +1592,7 @@ init_spec (void) /* Ug. We don't know shared library extensions. Hope that systems that use this form don't do shared libraries. */ init_gcc_specs (&obstack, + "libgcc_nonshared.a%s " "-lgcc_s", "libgcc.a%s", "libgcc_eh.a%s" diff --git a/gcc/testsuite/g++.dg/ext/mv18.C b/gcc/testsuite/g++.dg/ext/mv18.C new file mode 100644 index 0000000..1f024de --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv18.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target pie } */ +/* { dg-options "-O2 -fPIE -pie" } */ + +#include "mv1.C" diff --git a/gcc/testsuite/g++.dg/ext/mv19.C b/gcc/testsuite/g++.dg/ext/mv19.C new file mode 100644 index 0000000..d1ea788 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv19.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target pie } */ +/* { dg-options "-O2 -fPIE -pie -march=x86-64" } */ + +#include "mv14.C" diff --git a/gcc/testsuite/g++.dg/ext/mv20.C b/gcc/testsuite/g++.dg/ext/mv20.C new file mode 100644 index 0000000..98f7408 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv20.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target pie } */ +/* { dg-options "-O2 -fPIE -pie -march=x86-64" } */ + +#include "mv15.C" diff --git a/gcc/testsuite/g++.dg/ext/mv21.C b/gcc/testsuite/g++.dg/ext/mv21.C new file mode 100644 index 0000000..9708ad9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv21.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target static } */ +/* { dg-options "-O2 -static" } */ + +#include "mv1.C" diff --git a/gcc/testsuite/g++.dg/ext/mv22.C b/gcc/testsuite/g++.dg/ext/mv22.C new file mode 100644 index 0000000..2550136 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv22.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target static } */ +/* { dg-options "-O2 -static -march=x86-64" } */ + +#include "mv14.C" diff --git a/gcc/testsuite/g++.dg/ext/mv23.C b/gcc/testsuite/g++.dg/ext/mv23.C new file mode 100644 index 0000000..f00afb0 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/mv23.C @@ -0,0 +1,7 @@ +/* Test case to check if Multiversioning works. */ +/* { dg-do run { target i?86-*-* x86_64-*-* } } */ +/* { dg-require-ifunc "" } */ +/* { dg-require-effective-target static } */ +/* { dg-options "-O2 -static -march=x86-64" } */ + +#include "mv15.C" diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 88ddfea..f78b1ac 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,10 @@ LIB2ADD = # Assembler files should have names ending in `.S'. LIB2ADD_ST = +# List of extra C and assembler files to add to libgcc_nonshared.a. +# Assembler files should have names ending in `.S'. +LIB2ADDNONSHARED = + # Specify the directories to be searched for header files. # Both . and srcdir are used, in that order, # so that *config.h will be found in the compilation @@ -807,8 +811,15 @@ endif libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD)))) libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD_ST)))) +# Build LIB2ADDNONSHARED. +ifneq ($(filter-out %.c %.S %.asm,$(LIB2ADDNONSHARED)),) +$(error Unsupported files in LIB2ADDNONSHARED.) +endif + +libgcc-nonshared-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADDNONSHARED)))) + c_flags := -iter-items := $(LIB2ADD) $(LIB2ADD_ST) +iter-items := $(LIB2ADD) $(LIB2ADD_ST) $(LIB2ADDNONSHARED) include $(iterator) ifeq ($(enable_shared),yes) @@ -890,8 +901,9 @@ libgcc.a: $(libgcc-objects) libgcov.a: $(libgcov-objects) libunwind.a: $(libunwind-objects) libgcc_eh.a: $(libgcc-eh-objects) +libgcc_nonshared.a: $(libgcc-nonshared-objects) -libgcc.a libgcov.a libunwind.a libgcc_eh.a: +libgcc.a libgcov.a libunwind.a libgcc_eh.a libgcc_nonshared.a: -rm -f $@ objects="$(objects)"; \ @@ -905,7 +917,7 @@ libgcc.a libgcov.a libunwind.a libgcc_eh.a: $(RANLIB) $@ -all: libgcc.a libgcov.a +all: libgcc.a libgcc_nonshared.a libgcov.a ifneq ($(LIBUNWIND),) all: libunwind.a @@ -1051,6 +1063,7 @@ libgcc-extra-parts: $(EXTRA_PARTS) all: $(extra-parts) $(libgcc-objects) $(libgcc-s-objects) $(libgcc-eh-objects) \ + $(libgcc-nonshared-objects) \ $(libgcov-objects) \ $(libunwind-objects) $(libunwind-s-objects) \ $(EXTRA_PARTS): libgcc_tm.h @@ -1118,6 +1131,9 @@ install-leaf: $(install-shared) $(install-libunwind) $(INSTALL_DATA) libgcc.a $(DESTDIR)$(inst_libdir)/ chmod 644 $(DESTDIR)$(inst_libdir)/libgcc.a $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc.a + $(INSTALL_DATA) libgcc_nonshared.a $(DESTDIR)$(inst_libdir)/ + chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_nonshared.a + $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_nonshared.a $(INSTALL_DATA) libgcov.a $(DESTDIR)$(inst_libdir)/ chmod 644 $(DESTDIR)$(inst_libdir)/libgcov.a $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcov.a diff --git a/libgcc/config/i386/cpuinfo.c b/libgcc/config/i386/cpuinfo.c index eaf2f10..f6f91dd 100644 --- a/libgcc/config/i386/cpuinfo.c +++ b/libgcc/config/i386/cpuinfo.c @@ -109,7 +109,7 @@ struct __processor_model unsigned int __cpu_type; unsigned int __cpu_subtype; unsigned int __cpu_features[1]; -} __cpu_model; +} __cpu_model = { }; /* Get the specific type of AMD CPU. */ @@ -424,3 +424,8 @@ __cpu_indicator_init (void) return 0; } + +#if defined SHARED && defined USE_ELF_SYMVER +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); +#endif diff --git a/libgcc/config/i386/t-cpuinfo b/libgcc/config/i386/t-cpuinfo index 31c8db9..b20ef30 100644 --- a/libgcc/config/i386/t-cpuinfo +++ b/libgcc/config/i386/t-cpuinfo @@ -1 +1,2 @@ LIB2ADD += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDNONSHARED += $(srcdir)/config/i386/cpuinfo.c diff --git a/libgcc/config/i386/t-linux b/libgcc/config/i386/t-linux index 4f47f7b..11bb46e 100644 --- a/libgcc/config/i386/t-linux +++ b/libgcc/config/i386/t-linux @@ -3,4 +3,4 @@ # t-slibgcc-elf-ver and t-linux SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/i386/libgcc-glibc.ver -HOST_LIBGCC2_CFLAGS += -mlong-double-80 +HOST_LIBGCC2_CFLAGS += -mlong-double-80 -DUSE_ELF_SYMVER diff --git a/libgcc/shared-object.mk b/libgcc/shared-object.mk index efac797..306176d 100644 --- a/libgcc/shared-object.mk +++ b/libgcc/shared-object.mk @@ -4,6 +4,7 @@ o := $(firstword $(iter-items)) iter-items := $(filter-out $o,$(iter-items)) +ifneq ($o,) base := $(basename $(notdir $o)) c_flags-$o := $(c_flags) @@ -36,3 +37,4 @@ $(base)_s$(objext): $o $(gcc_s_compile) -c $(as_flags-$<) $< endif +endif -- 1.9.3