* PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE @ 2015-03-30 2:25 H.J. Lu 2015-03-30 2:34 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-30 2:25 UTC (permalink / raw) To: gcc-patches; +Cc: Uros Bizjak 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.a while providing backward binary compatibility. OK for trunk, 4.9 and 4.9 branches? Thanks. H.J. --- libgcc/ PR target/65612 * config/i386/cpuinfo.c (__cpu_model): Initialize. (__cpu_indicator_init@GCC_4.8.0): New. (__cpu_model@GCC_4.8.0): Likewise. gcc/testsuite/ PR target/65612 * g++.dg/ext/mv18.C: New test. * g++.dg/ext/mv19.C: Likewise. * g++.dg/ext/mv20.C: Likewise. --- gcc/testsuite/g++.dg/ext/mv18.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv19.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv20.C | 7 +++++++ libgcc/config/i386/cpuinfo.c | 7 ++++++- 4 files changed, 27 insertions(+), 1 deletion(-) 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 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/libgcc/config/i386/cpuinfo.c b/libgcc/config/i386/cpuinfo.c index eaf2f10..9639c8d 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 _WIN32 +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); +#endif -- 2.1.0 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-30 2:25 PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE H.J. Lu @ 2015-03-30 2:34 ` H.J. Lu 2015-03-30 2:40 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-30 2:34 UTC (permalink / raw) To: GCC Patches; +Cc: Uros Bizjak On Sun, Mar 29, 2015 at 7:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > 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.a while providing backward binary compatibility. > > OK for trunk, 4.9 and 4.9 branches? > > Thanks. > > > H.J. > --- > libgcc/ > > PR target/65612 > * config/i386/cpuinfo.c (__cpu_model): Initialize. > (__cpu_indicator_init@GCC_4.8.0): New. > (__cpu_model@GCC_4.8.0): Likewise. > > gcc/testsuite/ > > PR target/65612 > * g++.dg/ext/mv18.C: New test. > * g++.dg/ext/mv19.C: Likewise. > * g++.dg/ext/mv20.C: Likewise. It doesn' work for shared C++ library: /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -c -o main.o main.cc /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -shared -fPIC -O2 -o libmv20.so mv20.cc /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -o x main.o libmv20.so -Wl,-R,. /usr/local/bin/ld: x: hidden symbol `__cpu_model' in /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.0.0/libgcc.a(cpuinfo.o) is referenced by DSO /usr/local/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status Makefile:12: recipe for target 'x' failed make: *** [x] Error 1 [hjl@gnu-tools-1 pr65612]$ -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-30 2:34 ` H.J. Lu @ 2015-03-30 2:40 ` H.J. Lu 2015-03-30 22:26 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-30 2:40 UTC (permalink / raw) To: GCC Patches; +Cc: Uros Bizjak On Sun, Mar 29, 2015 at 7:34 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Sun, Mar 29, 2015 at 7:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> 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.a while providing backward binary compatibility. >> >> OK for trunk, 4.9 and 4.9 branches? >> >> Thanks. >> >> >> H.J. >> --- >> libgcc/ >> >> PR target/65612 >> * config/i386/cpuinfo.c (__cpu_model): Initialize. >> (__cpu_indicator_init@GCC_4.8.0): New. >> (__cpu_model@GCC_4.8.0): Likewise. >> >> gcc/testsuite/ >> >> PR target/65612 >> * g++.dg/ext/mv18.C: New test. >> * g++.dg/ext/mv19.C: Likewise. >> * g++.dg/ext/mv20.C: Likewise. > > It doesn' work for shared C++ library: > > /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -c > -o main.o main.cc > /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -shared > -fPIC -O2 -o libmv20.so mv20.cc > /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -o x > main.o libmv20.so -Wl,-R,. > /usr/local/bin/ld: x: hidden symbol `__cpu_model' in > /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.0.0/libgcc.a(cpuinfo.o) > is referenced by DSO > /usr/local/bin/ld: final link failed: Bad value > collect2: error: ld returned 1 exit status > Makefile:12: recipe for target 'x' failed > make: *** [x] Error 1 > [hjl@gnu-tools-1 pr65612]$ > > -- > H.J. We need something like libgcc_nonshared.a, which contains cpuinfo.o, and link together with -lgcc_s when creating executable or DSO. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-30 2:40 ` H.J. Lu @ 2015-03-30 22:26 ` H.J. Lu 2015-03-31 0:54 ` Jack Howarth 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-30 22:26 UTC (permalink / raw) To: GCC Patches; +Cc: Uros Bizjak [-- Attachment #1: Type: text/plain, Size: 3420 bytes --] On Sun, Mar 29, 2015 at 7:40 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Sun, Mar 29, 2015 at 7:34 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Sun, Mar 29, 2015 at 7:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>> 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.a while providing backward binary compatibility. >>> >>> OK for trunk, 4.9 and 4.9 branches? >>> >>> Thanks. >>> >>> >>> H.J. >>> --- >>> libgcc/ >>> >>> PR target/65612 >>> * config/i386/cpuinfo.c (__cpu_model): Initialize. >>> (__cpu_indicator_init@GCC_4.8.0): New. >>> (__cpu_model@GCC_4.8.0): Likewise. >>> >>> gcc/testsuite/ >>> >>> PR target/65612 >>> * g++.dg/ext/mv18.C: New test. >>> * g++.dg/ext/mv19.C: Likewise. >>> * g++.dg/ext/mv20.C: Likewise. >> >> It doesn' work for shared C++ library: >> >> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -c >> -o main.o main.cc >> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -shared >> -fPIC -O2 -o libmv20.so mv20.cc >> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -o x >> main.o libmv20.so -Wl,-R,. >> /usr/local/bin/ld: x: hidden symbol `__cpu_model' in >> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.0.0/libgcc.a(cpuinfo.o) >> is referenced by DSO >> /usr/local/bin/ld: final link failed: Bad value >> collect2: error: ld returned 1 exit status >> Makefile:12: recipe for target 'x' failed >> make: *** [x] Error 1 >> [hjl@gnu-tools-1 pr65612]$ >> >> -- >> H.J. > > We need something like libgcc_nonshared.a, which contains cpuinfo.o, and > link together with -lgcc_s when creating executable or DSO. > I am testing it on Linux/x86-64. OK for master if regression test passes? -- H.J. -- 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/-lgcc/libgcc.a%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. libgcc/ PR target/65612 * Makefile.in (LIB2ADDSHARED): New. (LIB2ADDNONSHARED): Likewise. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. (libgcc-s-objects): Add $(LIB2ADDSHARED). (all): Depend on libgcc_nonshared.a. ($(libgcc-nonshared-objects)): Depend on libgcc_tm.h. (install-leaf): Install libgcc_nonshared.a. * 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 (LIB2ADD): Renamed to ... (LIB2ADDSHARED): This. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 7893 bytes --] From 2dc6879c0c33069a02ae52d494f05603de9fe317 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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/-lgcc/libgcc.a%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. libgcc/ PR target/65612 * Makefile.in (LIB2ADDSHARED): New. (LIB2ADDNONSHARED): Likewise. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. (libgcc-s-objects): Add $(LIB2ADDSHARED). (all): Depend on libgcc_nonshared.a. ($(libgcc-nonshared-objects)): Depend on libgcc_tm.h. (install-leaf): Install libgcc_nonshared.a. * 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 (LIB2ADD): Renamed to ... (LIB2ADDSHARED): This. (LIB2ADDNONSHARED): New. --- gcc/gcc.c | 4 ++++ gcc/testsuite/g++.dg/ext/mv18.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv19.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv20.C | 7 +++++++ libgcc/Makefile.in | 20 +++++++++++++++++--- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-cpuinfo | 3 ++- 7 files changed, 50 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 diff --git a/gcc/gcc.c b/gcc/gcc.c index d956c36..88a8dac 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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" #ifdef USE_LIBUNWIND_EXCEPTIONS 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/libgcc/Makefile.in b/libgcc/Makefile.in index 88ddfea..cec4ae0 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,14 @@ LIB2ADD = # Assembler files should have names ending in `.S'. LIB2ADD_ST = +# List of extra C and assembler files to add to shared libgcc2. +# Assembler files should have names ending in `.S'. +LIB2ADDSHARED = + +# 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 @@ -806,13 +814,14 @@ endif libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD)))) libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD_ST)))) +libgcc-nonshared-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADDNONSHARED)))) c_flags := iter-items := $(LIB2ADD) $(LIB2ADD_ST) include $(iterator) ifeq ($(enable_shared),yes) -libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD)))) +libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD) $(LIB2ADDSHARED)))) endif # Build LIB2ADDEH, LIB2ADDEHSTATIC, and LIB2ADDEHSHARED. If we don't have @@ -890,8 +899,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 +915,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 +1061,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 +1129,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..9639c8d 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 _WIN32 +__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..8dbe9e6 100644 --- a/libgcc/config/i386/t-cpuinfo +++ b/libgcc/config/i386/t-cpuinfo @@ -1 +1,2 @@ -LIB2ADD += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDSHARED += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDNONSHARED += $(srcdir)/config/i386/cpuinfo.c -- 1.9.3 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-30 22:26 ` H.J. Lu @ 2015-03-31 0:54 ` Jack Howarth 2015-03-31 2:08 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 0:54 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches, Uros Bizjak HJ, This patch breaks the bootstrap on targets like darwin which don't build libgcc_nonshared.a... if test -z "$objects"; then \ echo 'int __libgcc_eh_dummy;' > eh_dummy.c; \ /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -pipe -fno-common -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe -fno-common -I. -I. -I../../.././gcc -I../../../../gcc-5-20150330/libgcc -I../../../../gcc-5-20150330/libgcc/. -I../../../../gcc-5-20150330/libgcc/../gcc -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS -DUSE_EMUTLS -fvisibility=hidden -DHIDE_EXPORTS -c eh_dummy.c \ -o eh_dummy.o; \ objects=eh_dummy.o; \ fi; \ ar rc libgcc_nonshared.a $objects ar: cpuinfo.o: No such file or directory Makefile:905: recipe for target 'libgcc_nonshared.a' failed make[5]: *** [libgcc_nonshared.a] Error 1 make[5]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' Makefile:1168: recipe for target 'multi-do' failed make[4]: *** [multi-do] Error 1 make[4]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' Makefile:117: recipe for target 'all-multi' failed make[3]: *** [all-multi] Error 2 make[3]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed make[2]: *** [all-stage1-target-libgcc] Error 2 make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' Makefile:20760: recipe for target 'stage1-bubble' failed make[1]: *** [stage1-bubble] 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 Jack On Mon, Mar 30, 2015 at 6:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Sun, Mar 29, 2015 at 7:40 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Sun, Mar 29, 2015 at 7:34 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>> On Sun, Mar 29, 2015 at 7:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>>> 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.a while providing backward binary compatibility. >>>> >>>> OK for trunk, 4.9 and 4.9 branches? >>>> >>>> Thanks. >>>> >>>> >>>> H.J. >>>> --- >>>> libgcc/ >>>> >>>> PR target/65612 >>>> * config/i386/cpuinfo.c (__cpu_model): Initialize. >>>> (__cpu_indicator_init@GCC_4.8.0): New. >>>> (__cpu_model@GCC_4.8.0): Likewise. >>>> >>>> gcc/testsuite/ >>>> >>>> PR target/65612 >>>> * g++.dg/ext/mv18.C: New test. >>>> * g++.dg/ext/mv19.C: Likewise. >>>> * g++.dg/ext/mv20.C: Likewise. >>> >>> It doesn' work for shared C++ library: >>> >>> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -c >>> -o main.o main.cc >>> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -shared >>> -fPIC -O2 -o libmv20.so mv20.cc >>> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/g++ -O2 -o x >>> main.o libmv20.so -Wl,-R,. >>> /usr/local/bin/ld: x: hidden symbol `__cpu_model' in >>> /export/build/gnu/gcc-x32/release/usr/gcc-5.0.0-x32/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.0.0/libgcc.a(cpuinfo.o) >>> is referenced by DSO >>> /usr/local/bin/ld: final link failed: Bad value >>> collect2: error: ld returned 1 exit status >>> Makefile:12: recipe for target 'x' failed >>> make: *** [x] Error 1 >>> [hjl@gnu-tools-1 pr65612]$ >>> >>> -- >>> H.J. >> >> We need something like libgcc_nonshared.a, which contains cpuinfo.o, and >> link together with -lgcc_s when creating executable or DSO. >> > > I am testing it on Linux/x86-64. OK for master if regression test > passes? > > -- > H.J. > -- > 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/-lgcc/libgcc.a%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. > > libgcc/ > > PR target/65612 > * Makefile.in (LIB2ADDSHARED): New. > (LIB2ADDNONSHARED): Likewise. > (libgcc-nonshared-objects): Likewise. > (libgcc_nonshared.a): Likewise. > (libgcc-s-objects): Add $(LIB2ADDSHARED). > (all): Depend on libgcc_nonshared.a. > ($(libgcc-nonshared-objects)): Depend on libgcc_tm.h. > (install-leaf): Install libgcc_nonshared.a. > * 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 (LIB2ADD): Renamed to ... > (LIB2ADDSHARED): This. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 0:54 ` Jack Howarth @ 2015-03-31 2:08 ` H.J. Lu 2015-03-31 2:42 ` H.J. Lu ` (2 more replies) 0 siblings, 3 replies; 46+ messages in thread From: H.J. Lu @ 2015-03-31 2:08 UTC (permalink / raw) To: Jack Howarth; +Cc: GCC Patches, Uros Bizjak [-- Attachment #1: Type: text/plain, Size: 2547 bytes --] On Mon, Mar 30, 2015 at 5:53 PM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: > HJ, > This patch breaks the bootstrap on targets like darwin which > don't build libgcc_nonshared.a... > > if test -z "$objects"; then \ > echo 'int __libgcc_eh_dummy;' > eh_dummy.c; \ > /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc > -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ > -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ > -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem > /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem > /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 > -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual > -Wno-format -Wstrict-prototypes -Wmissing-prototypes > -Wold-style-definition -isystem ./include -pipe -fno-common -g > -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe > -fno-common -I. -I. -I../../.././gcc > -I../../../../gcc-5-20150330/libgcc > -I../../../../gcc-5-20150330/libgcc/. > -I../../../../gcc-5-20150330/libgcc/../gcc > -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS > -DUSE_EMUTLS -fvisibility=hidden -DHIDE_EXPORTS -c eh_dummy.c \ > -o eh_dummy.o; \ > objects=eh_dummy.o; \ > fi; \ > ar rc libgcc_nonshared.a $objects > ar: cpuinfo.o: No such file or directory > Makefile:905: recipe for target 'libgcc_nonshared.a' failed > make[5]: *** [libgcc_nonshared.a] Error 1 > make[5]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' > Makefile:1168: recipe for target 'multi-do' failed > make[4]: *** [multi-do] Error 1 > make[4]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' > Makefile:117: recipe for target 'all-multi' failed > make[3]: *** [all-multi] Error 2 > make[3]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' > Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed > make[2]: *** [all-stage1-target-libgcc] Error 2 > make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' > Makefile:20760: recipe for target 'stage1-bubble' failed > make[1]: *** [stage1-bubble] 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 > > Jack > This one works. I need to add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) to iter-items and handle duplicated items in them. -- H.J. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 8793 bytes --] From ba83e7d541929204cb07a3f2d9de34b4f28264b7 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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/-lgcc/libgcc.a%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. libgcc/ PR target/65612 * Makefile.in (LIB2ADDSHARED): New. (LIB2ADDNONSHARED): Likewise. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. Check unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED. (iter-items): Add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED). (libgcc-s-objects): Add $(LIB2ADDSHARED). (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 (LIB2ADD): Renamed to ... (LIB2ADDSHARED): This. (LIB2ADDNONSHARED): New. --- gcc/gcc.c | 4 ++++ gcc/testsuite/g++.dg/ext/mv18.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv19.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv20.C | 7 +++++++ libgcc/Makefile.in | 28 ++++++++++++++++++++++++---- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-cpuinfo | 3 ++- libgcc/shared-object.mk | 2 ++ 8 files changed, 59 insertions(+), 6 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 diff --git a/gcc/gcc.c b/gcc/gcc.c index d956c36..88a8dac 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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" #ifdef USE_LIBUNWIND_EXCEPTIONS 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/libgcc/Makefile.in b/libgcc/Makefile.in index 88ddfea..f6eb047 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,14 @@ LIB2ADD = # Assembler files should have names ending in `.S'. LIB2ADD_ST = +# List of extra C and assembler files to add to shared libgcc2. +# Assembler files should have names ending in `.S'. +LIB2ADDSHARED = + +# 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,12 +815,19 @@ endif libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD)))) libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD_ST)))) +# Build LIB2ADDNONSHARED and LIB2ADDSHARED. +ifneq ($(filter-out %.c %.S %.asm,$(LIB2ADDNONSHARED) $(LIB2ADDSHARED)),) +$(error Unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED.) +endif + +libgcc-nonshared-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADDNONSHARED)))) + c_flags := -iter-items := $(LIB2ADD) $(LIB2ADD_ST) +iter-items := $(LIB2ADD) $(LIB2ADD_ST) $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) include $(iterator) ifeq ($(enable_shared),yes) -libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD)))) +libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD) $(LIB2ADDSHARED)))) endif # Build LIB2ADDEH, LIB2ADDEHSTATIC, and LIB2ADDEHSHARED. If we don't have @@ -890,8 +905,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 +921,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 +1067,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 +1135,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..9639c8d 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 _WIN32 +__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..8dbe9e6 100644 --- a/libgcc/config/i386/t-cpuinfo +++ b/libgcc/config/i386/t-cpuinfo @@ -1 +1,2 @@ -LIB2ADD += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDSHARED += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDNONSHARED += $(srcdir)/config/i386/cpuinfo.c 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 -- 2.1.0 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 2:08 ` H.J. Lu @ 2015-03-31 2:42 ` H.J. Lu 2015-03-31 3:14 ` Jack Howarth 2015-03-31 3:09 ` Jack Howarth 2015-03-31 5:39 ` Jakub Jelinek 2 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-31 2:42 UTC (permalink / raw) To: Jack Howarth; +Cc: GCC Patches, Uros Bizjak On Mon, Mar 30, 2015 at 7:08 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Mar 30, 2015 at 5:53 PM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >> HJ, >> This patch breaks the bootstrap on targets like darwin which >> don't build libgcc_nonshared.a... >> >> if test -z "$objects"; then \ >> echo 'int __libgcc_eh_dummy;' > eh_dummy.c; \ >> /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc >> -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ >> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ >> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem >> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem >> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 >> -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual >> -Wno-format -Wstrict-prototypes -Wmissing-prototypes >> -Wold-style-definition -isystem ./include -pipe -fno-common -g >> -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe >> -fno-common -I. -I. -I../../.././gcc >> -I../../../../gcc-5-20150330/libgcc >> -I../../../../gcc-5-20150330/libgcc/. >> -I../../../../gcc-5-20150330/libgcc/../gcc >> -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS >> -DUSE_EMUTLS -fvisibility=hidden -DHIDE_EXPORTS -c eh_dummy.c \ >> -o eh_dummy.o; \ >> objects=eh_dummy.o; \ >> fi; \ >> ar rc libgcc_nonshared.a $objects >> ar: cpuinfo.o: No such file or directory >> Makefile:905: recipe for target 'libgcc_nonshared.a' failed >> make[5]: *** [libgcc_nonshared.a] Error 1 >> make[5]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' >> Makefile:1168: recipe for target 'multi-do' failed >> make[4]: *** [multi-do] Error 1 >> make[4]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >> Makefile:117: recipe for target 'all-multi' failed >> make[3]: *** [all-multi] Error 2 >> make[3]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >> Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed >> make[2]: *** [all-stage1-target-libgcc] Error 2 >> make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' >> Makefile:20760: recipe for target 'stage1-bubble' failed >> make[1]: *** [stage1-bubble] 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 >> >> Jack >> > > This one works. I need to add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) > to iter-items and handle duplicated items in them. > There is no regression on Linux/x86-64. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 2:42 ` H.J. Lu @ 2015-03-31 3:14 ` Jack Howarth 0 siblings, 0 replies; 46+ messages in thread From: Jack Howarth @ 2015-03-31 3:14 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches, Uros Bizjak On Mon, Mar 30, 2015 at 10:42 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Mar 30, 2015 at 7:08 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Mon, Mar 30, 2015 at 5:53 PM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >>> HJ, >>> This patch breaks the bootstrap on targets like darwin which >>> don't build libgcc_nonshared.a... >>> >>> if test -z "$objects"; then \ >>> echo 'int __libgcc_eh_dummy;' > eh_dummy.c; \ >>> /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc >>> -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ >>> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ >>> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem >>> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem >>> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 >>> -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual >>> -Wno-format -Wstrict-prototypes -Wmissing-prototypes >>> -Wold-style-definition -isystem ./include -pipe -fno-common -g >>> -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe >>> -fno-common -I. -I. -I../../.././gcc >>> -I../../../../gcc-5-20150330/libgcc >>> -I../../../../gcc-5-20150330/libgcc/. >>> -I../../../../gcc-5-20150330/libgcc/../gcc >>> -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS >>> -DUSE_EMUTLS -fvisibility=hidden -DHIDE_EXPORTS -c eh_dummy.c \ >>> -o eh_dummy.o; \ >>> objects=eh_dummy.o; \ >>> fi; \ >>> ar rc libgcc_nonshared.a $objects >>> ar: cpuinfo.o: No such file or directory >>> Makefile:905: recipe for target 'libgcc_nonshared.a' failed >>> make[5]: *** [libgcc_nonshared.a] Error 1 >>> make[5]: Leaving directory >>> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' >>> Makefile:1168: recipe for target 'multi-do' failed >>> make[4]: *** [multi-do] Error 1 >>> make[4]: Leaving directory >>> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >>> Makefile:117: recipe for target 'all-multi' failed >>> make[3]: *** [all-multi] Error 2 >>> make[3]: Leaving directory >>> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >>> Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed >>> make[2]: *** [all-stage1-target-libgcc] Error 2 >>> make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' >>> Makefile:20760: recipe for target 'stage1-bubble' failed >>> make[1]: *** [stage1-bubble] 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 >>> >>> Jack >>> >> >> This one works. I need to add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) >> to iter-items and handle duplicated items in them. >> > > There is no regression on Linux/x86-64. > > -- > H.J. Can this wait for 5.2? Creating new libgcc libraries seems really invasive for stage4. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 2:08 ` H.J. Lu 2015-03-31 2:42 ` H.J. Lu @ 2015-03-31 3:09 ` Jack Howarth 2015-03-31 4:04 ` H.J. Lu 2015-03-31 5:39 ` Jakub Jelinek 2 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 3:09 UTC (permalink / raw) To: H.J. Lu; +Cc: GCC Patches, Uros Bizjak H.J., This still breaks the darwin bootstrap but differently. ar rc libgcc_eh.a $objects /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libgcc_eh.a(unwind-sjlj.o) has no symbols ranlib libgcc_eh.a /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libgcc_eh.a(unwind-sjlj.o) has no symbols /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -pipe -fno-common -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe -fno-common -I. -I. -I../../.././gcc -I../../../../gcc-5-20150330/libgcc -I../../../../gcc-5-20150330/libgcc/. -I../../../../gcc-5-20150330/libgcc/../gcc -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS -DUSE_EMUTLS -o cpuinfo_s.o -MT cpuinfo_s.o -MD -MP -MF cpuinfo_s.dep -DSHARED -c ../../../../gcc-5-20150330/libgcc/config/i386/cpuinfo.c {standard input}:3:Unknown pseudo-op: .symver {standard input}:3:Rest of line ignored. 1st junk character valued 95 (_). {standard input}:4:Unknown pseudo-op: .symver {standard input}:4:Rest of line ignored. 1st junk character valued 95 (_). ../../../../gcc-5-20150330/libgcc/shared-object.mk:18: recipe for target 'cpuinfo_s.o' failed make[5]: *** [cpuinfo_s.o] Error 1 make[5]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' Makefile:1174: recipe for target 'multi-do' failed make[4]: *** [multi-do] Error 1 make[4]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' Makefile:117: recipe for target 'all-multi' failed make[3]: *** [all-multi] Error 2 make[3]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed make[2]: *** [all-stage1-target-libgcc] Error 2 make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' Makefile:20760: recipe for target 'stage1-bubble' failed make[1]: *** [stage1-bubble] 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 Jack On Mon, Mar 30, 2015 at 10:08 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Mar 30, 2015 at 5:53 PM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >> HJ, >> This patch breaks the bootstrap on targets like darwin which >> don't build libgcc_nonshared.a... >> >> if test -z "$objects"; then \ >> echo 'int __libgcc_eh_dummy;' > eh_dummy.c; \ >> /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc >> -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ >> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ >> -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem >> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem >> /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 >> -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual >> -Wno-format -Wstrict-prototypes -Wmissing-prototypes >> -Wold-style-definition -isystem ./include -pipe -fno-common -g >> -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe >> -fno-common -I. -I. -I../../.././gcc >> -I../../../../gcc-5-20150330/libgcc >> -I../../../../gcc-5-20150330/libgcc/. >> -I../../../../gcc-5-20150330/libgcc/../gcc >> -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS >> -DUSE_EMUTLS -fvisibility=hidden -DHIDE_EXPORTS -c eh_dummy.c \ >> -o eh_dummy.o; \ >> objects=eh_dummy.o; \ >> fi; \ >> ar rc libgcc_nonshared.a $objects >> ar: cpuinfo.o: No such file or directory >> Makefile:905: recipe for target 'libgcc_nonshared.a' failed >> make[5]: *** [libgcc_nonshared.a] Error 1 >> make[5]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' >> Makefile:1168: recipe for target 'multi-do' failed >> make[4]: *** [multi-do] Error 1 >> make[4]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >> Makefile:117: recipe for target 'all-multi' failed >> make[3]: *** [all-multi] Error 2 >> make[3]: Leaving directory >> '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' >> Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed >> make[2]: *** [all-stage1-target-libgcc] Error 2 >> make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' >> Makefile:20760: recipe for target 'stage1-bubble' failed >> make[1]: *** [stage1-bubble] 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 >> >> Jack >> > > This one works. I need to add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) > to iter-items and handle duplicated items in them. > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 3:09 ` Jack Howarth @ 2015-03-31 4:04 ` H.J. Lu 0 siblings, 0 replies; 46+ messages in thread From: H.J. Lu @ 2015-03-31 4:04 UTC (permalink / raw) To: Jack Howarth; +Cc: GCC Patches, Uros Bizjak [-- Attachment #1: Type: text/plain, Size: 2957 bytes --] On Mon, Mar 30, 2015 at 8:09 PM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: > H.J., > This still breaks the darwin bootstrap but differently. > > ar rc libgcc_eh.a $objects > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: > file: libgcc_eh.a(unwind-sjlj.o) has no symbols > ranlib libgcc_eh.a > /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: > file: libgcc_eh.a(unwind-sjlj.o) has no symbols > /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xgcc > -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ > -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ > -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem > /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem > /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -m32 -O2 > -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual > -Wno-format -Wstrict-prototypes -Wmissing-prototypes > -Wold-style-definition -isystem ./include -pipe -fno-common -g > -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -pipe > -fno-common -I. -I. -I../../.././gcc > -I../../../../gcc-5-20150330/libgcc > -I../../../../gcc-5-20150330/libgcc/. > -I../../../../gcc-5-20150330/libgcc/../gcc > -I../../../../gcc-5-20150330/libgcc/../include -DHAVE_CC_TLS > -DUSE_EMUTLS -o cpuinfo_s.o -MT cpuinfo_s.o -MD -MP -MF cpuinfo_s.dep > -DSHARED -c ../../../../gcc-5-20150330/libgcc/config/i386/cpuinfo.c > {standard input}:3:Unknown pseudo-op: .symver > {standard input}:3:Rest of line ignored. 1st junk character valued 95 (_). > {standard input}:4:Unknown pseudo-op: .symver > {standard input}:4:Rest of line ignored. 1st junk character valued 95 (_). > ../../../../gcc-5-20150330/libgcc/shared-object.mk:18: recipe for > target 'cpuinfo_s.o' failed > make[5]: *** [cpuinfo_s.o] Error 1 > make[5]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/i386/libgcc' > Makefile:1174: recipe for target 'multi-do' failed > make[4]: *** [multi-do] Error 1 > make[4]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' > Makefile:117: recipe for target 'all-multi' failed > make[3]: *** [all-multi] Error 2 > make[3]: Leaving directory > '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libgcc' > Makefile:14820: recipe for target 'all-stage1-target-libgcc' failed > make[2]: *** [all-stage1-target-libgcc] Error 2 > make[2]: Leaving directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir' > Makefile:20760: recipe for target 'stage1-bubble' failed > make[1]: *** [stage1-bubble] 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 > Here is the updated patch. I added HOST_LIBGCC2_CFLAGS += -DUSE_ELF_SYMVER when mkmap-symver.awk is used. -- H.J. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 9237 bytes --] From 00e6d397103e2acae8261e5e691704b4f4be3b2b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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/-lgcc/libgcc.a%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. libgcc/ PR target/65612 * Makefile.in (LIB2ADDSHARED): New. (LIB2ADDNONSHARED): Likewise. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. Check unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED. (iter-items): Add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED). (libgcc-s-objects): Add $(LIB2ADDSHARED). (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/t-slibgcc-elf-ver (HOST_LIBGCC2_CFLAGS ): Add -DUSE_ELF_SYMVER. * config/i386/t-cpuinfo (LIB2ADD): Renamed to ... (LIB2ADDSHARED): This. (LIB2ADDNONSHARED): New. --- gcc/gcc.c | 4 ++++ gcc/testsuite/g++.dg/ext/mv18.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv19.C | 7 +++++++ gcc/testsuite/g++.dg/ext/mv20.C | 7 +++++++ libgcc/Makefile.in | 28 ++++++++++++++++++++++++---- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-cpuinfo | 3 ++- libgcc/config/t-slibgcc-elf-ver | 2 ++ libgcc/shared-object.mk | 2 ++ 9 files changed, 61 insertions(+), 6 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 diff --git a/gcc/gcc.c b/gcc/gcc.c index d956c36..88a8dac 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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" #ifdef USE_LIBUNWIND_EXCEPTIONS 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/libgcc/Makefile.in b/libgcc/Makefile.in index 88ddfea..f6eb047 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,14 @@ LIB2ADD = # Assembler files should have names ending in `.S'. LIB2ADD_ST = +# List of extra C and assembler files to add to shared libgcc2. +# Assembler files should have names ending in `.S'. +LIB2ADDSHARED = + +# 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,12 +815,19 @@ endif libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD)))) libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD_ST)))) +# Build LIB2ADDNONSHARED and LIB2ADDSHARED. +ifneq ($(filter-out %.c %.S %.asm,$(LIB2ADDNONSHARED) $(LIB2ADDSHARED)),) +$(error Unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED.) +endif + +libgcc-nonshared-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADDNONSHARED)))) + c_flags := -iter-items := $(LIB2ADD) $(LIB2ADD_ST) +iter-items := $(LIB2ADD) $(LIB2ADD_ST) $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) include $(iterator) ifeq ($(enable_shared),yes) -libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD)))) +libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD) $(LIB2ADDSHARED)))) endif # Build LIB2ADDEH, LIB2ADDEHSTATIC, and LIB2ADDEHSHARED. If we don't have @@ -890,8 +905,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 +921,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 +1067,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 +1135,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..8dbe9e6 100644 --- a/libgcc/config/i386/t-cpuinfo +++ b/libgcc/config/i386/t-cpuinfo @@ -1 +1,2 @@ -LIB2ADD += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDSHARED += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDNONSHARED += $(srcdir)/config/i386/cpuinfo.c diff --git a/libgcc/config/t-slibgcc-elf-ver b/libgcc/config/t-slibgcc-elf-ver index 4a00edc..a17659e 100644 --- a/libgcc/config/t-slibgcc-elf-ver +++ b/libgcc/config/t-slibgcc-elf-ver @@ -2,3 +2,5 @@ SHLIB_MKMAP = $(srcdir)/mkmap-symver.awk SHLIB_MAPFILES = libgcc-std.ver + +HOST_LIBGCC2_CFLAGS += -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 -- 2.1.0 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 2:08 ` H.J. Lu 2015-03-31 2:42 ` H.J. Lu 2015-03-31 3:09 ` Jack Howarth @ 2015-03-31 5:39 ` Jakub Jelinek 2015-03-31 6:20 ` Rainer Orth 2015-03-31 10:39 ` H.J. Lu 2 siblings, 2 replies; 46+ messages in thread From: Jakub Jelinek @ 2015-03-31 5:39 UTC (permalink / raw) To: H.J. Lu; +Cc: Jack Howarth, GCC Patches, Uros Bizjak On Mon, Mar 30, 2015 at 07:08:00PM -0700, H.J. Lu wrote: > --- a/gcc/gcc.c > +++ b/gcc/gcc.c > @@ -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" Why do you need to link libgcc_nonshared.a twice here? -lgcc_s surely won't add any new __cpu* undefined references. > @@ -424,3 +424,8 @@ __cpu_indicator_init (void) > > return 0; > } > + > +#if defined SHARED && !defined _WIN32 > +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); > +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); > +#endif Will this work on Solaris? I'd say you at least want to also guard with some configure check if .symver is supported by assembler. Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 5:39 ` Jakub Jelinek @ 2015-03-31 6:20 ` Rainer Orth 2015-03-31 10:39 ` H.J. Lu 1 sibling, 0 replies; 46+ messages in thread From: Rainer Orth @ 2015-03-31 6:20 UTC (permalink / raw) To: Jakub Jelinek; +Cc: H.J. Lu, Jack Howarth, GCC Patches, Uros Bizjak Jakub Jelinek <jakub@redhat.com> writes: >> @@ -424,3 +424,8 @@ __cpu_indicator_init (void) >> >> return 0; >> } >> + >> +#if defined SHARED && !defined _WIN32 >> +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); >> +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); >> +#endif > > Will this work on Solaris? > I'd say you at least want to also guard with some configure check if > .symver is supported by assembler. This will never work on Solaris: even if the assembler supports .symver, ld.so.1 never will. Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 5:39 ` Jakub Jelinek 2015-03-31 6:20 ` Rainer Orth @ 2015-03-31 10:39 ` H.J. Lu 2015-03-31 14:25 ` Jack Howarth 1 sibling, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-31 10:39 UTC (permalink / raw) To: Jakub Jelinek; +Cc: Jack Howarth, GCC Patches, Uros Bizjak [-- Attachment #1: Type: text/plain, Size: 3496 bytes --] On Mon, Mar 30, 2015 at 10:38 PM, Jakub Jelinek <jakub@redhat.com> wrote: > On Mon, Mar 30, 2015 at 07:08:00PM -0700, H.J. Lu wrote: >> --- a/gcc/gcc.c >> +++ b/gcc/gcc.c >> @@ -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" > > Why do you need to link libgcc_nonshared.a twice here? -lgcc_s surely won't > add any new __cpu* undefined references. The one added for -lgcc_s is for building shared C++ library since -lgcc isn't used and only -lgcc_s is used. The one added for -lgcc is for static linking since -lgcc_s isn't used. I updated the patch to add some testcases for -static. I couldn't find a way to add tests for: export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -c -o main.o main.cc /export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -shared -fPIC -O2 -o libmv20.so mv20.cc -L/export/build/gnu/gcc/build-x86_64-linux/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs /export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -o x main.o libmv20.so -Wl,-R,. -L/export/build/gnu/gcc/build-x86_64-linux/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs /usr/local/bin/ld: x: hidden symbol `__cpu_model' in /export/build/gnu/gcc/build-x86_64-linux/gcc/libgcc_nonshared.a(cpuinfo.o) is referenced by DSO /usr/local/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status >> @@ -424,3 +424,8 @@ __cpu_indicator_init (void) >> >> return 0; >> } >> + >> +#if defined SHARED && !defined _WIN32 >> +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); >> +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); >> +#endif > > Will this work on Solaris? > I'd say you at least want to also guard with some configure check if > .symver is supported by assembler. > I updated my patch with: @@ -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-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 OK for master? -- H.J. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 11008 bytes --] From 259457afe0add56064ed49da1954d0770b1e1975 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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/-lgcc/libgcc.a%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 (LIB2ADDSHARED): New. (LIB2ADDNONSHARED): Likewise. (libgcc-nonshared-objects): Likewise. (libgcc_nonshared.a): Likewise. Check unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED. (iter-items): Add $(LIB2ADDNONSHARED) $(LIB2ADDSHARED). (libgcc-s-objects): Add $(LIB2ADDSHARED). (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 (LIB2ADD): Renamed to ... (LIB2ADDSHARED): This. (LIB2ADDNONSHARED): New. * config/i386/t-linux (HOST_LIBGCC2_CFLAGS): Add -DUSE_ELF_SYMVER. --- gcc/gcc.c | 4 ++++ 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 | 28 ++++++++++++++++++++++++---- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-cpuinfo | 3 ++- libgcc/config/i386/t-linux | 2 +- libgcc/shared-object.mk | 2 ++ 12 files changed, 81 insertions(+), 7 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..88a8dac 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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" #ifdef USE_LIBUNWIND_EXCEPTIONS 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..f6eb047 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -261,6 +261,14 @@ LIB2ADD = # Assembler files should have names ending in `.S'. LIB2ADD_ST = +# List of extra C and assembler files to add to shared libgcc2. +# Assembler files should have names ending in `.S'. +LIB2ADDSHARED = + +# 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,12 +815,19 @@ endif libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD)))) libgcc-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADD_ST)))) +# Build LIB2ADDNONSHARED and LIB2ADDSHARED. +ifneq ($(filter-out %.c %.S %.asm,$(LIB2ADDNONSHARED) $(LIB2ADDSHARED)),) +$(error Unsupported files in LIB2ADDNONSHARED or LIB2ADDSHARED.) +endif + +libgcc-nonshared-objects += $(addsuffix $(objext),$(basename $(notdir $(LIB2ADDNONSHARED)))) + c_flags := -iter-items := $(LIB2ADD) $(LIB2ADD_ST) +iter-items := $(LIB2ADD) $(LIB2ADD_ST) $(LIB2ADDNONSHARED) $(LIB2ADDSHARED) include $(iterator) ifeq ($(enable_shared),yes) -libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD)))) +libgcc-s-objects += $(addsuffix _s$(objext),$(basename $(notdir $(LIB2ADD) $(LIB2ADDSHARED)))) endif # Build LIB2ADDEH, LIB2ADDEHSTATIC, and LIB2ADDEHSHARED. If we don't have @@ -890,8 +905,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 +921,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 +1067,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 +1135,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..8dbe9e6 100644 --- a/libgcc/config/i386/t-cpuinfo +++ b/libgcc/config/i386/t-cpuinfo @@ -1 +1,2 @@ -LIB2ADD += $(srcdir)/config/i386/cpuinfo.c +LIB2ADDSHARED += $(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 -- 2.1.0 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 10:39 ` H.J. Lu @ 2015-03-31 14:25 ` Jack Howarth 2015-03-31 15:58 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 14:25 UTC (permalink / raw) To: H.J. Lu; +Cc: Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump H.J., While the latest patch fails to bootstrap on x86_64-apple-darwin14... make[2]: Entering directory '/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libcilkrts' /bin/sh ./libtool --tag=CXX --mode=link /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xg++ -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ -nostdinc++ -nostdinc++ -I/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/include/x86_64-apple-darwin14.3.0 -I/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/include -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/testsuite/util -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src/.libs -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/libsupc++/.libs -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src/.libs -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/libsupc++/.libs -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -g -O2 -version-info 5:0:0 -ldl -lpthread -no-undefined -o libcilkrts.la -rpath /sw/lib/gcc5/lib cilk-abi-vla.lo os-unix-sysdep.lo bug.lo cilk-abi.lo cilk-abi-cilk-for.lo cilk-abi-vla-internal.lo cilk_api.lo cilk_fiber.lo cilk_fiber-unix.lo cilk_malloc.lo c_reducers.lo except-gcc.lo frame_malloc.lo full_frame.lo global_state.lo jmpbuf.lo local_state.lo metacall_impl.lo os_mutex-unix.lo os-unix.lo pedigrees.lo record-replay.lo reducer_impl.lo scheduler.lo signal_node.lo spin_mutex.lo stats.lo symbol_test.lo sysdep-unix.lo worker_mutex.lo libtool: link: /sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/xg++ -B/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/./gcc/ -nostdinc++ -nostdinc++ -I/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/include/x86_64-apple-darwin14.3.0 -I/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/include -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/libsupc++ -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/include/backward -I/sw/src/fink.build/gcc5-5.0.0-1/gcc-5-20150331/libstdc++-v3/testsuite/util -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src/.libs -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/libsupc++/.libs -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/bin/ -B/sw/lib/gcc5/x86_64-apple-darwin14.3.0/lib/ -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/include -isystem /sw/lib/gcc5/x86_64-apple-darwin14.3.0/sys-include -dynamiclib -o .libs/libcilkrts.5.dylib .libs/cilk-abi-vla.o .libs/os-unix-sysdep.o .libs/bug.o .libs/cilk-abi.o .libs/cilk-abi-cilk-for.o .libs/cilk-abi-vla-internal.o .libs/cilk_api.o .libs/cilk_fiber.o .libs/cilk_fiber-unix.o .libs/cilk_malloc.o .libs/c_reducers.o .libs/except-gcc.o .libs/frame_malloc.o .libs/full_frame.o .libs/global_state.o .libs/jmpbuf.o .libs/local_state.o .libs/metacall_impl.o .libs/os_mutex-unix.o .libs/os-unix.o .libs/pedigrees.o .libs/record-replay.o .libs/reducer_impl.o .libs/scheduler.o .libs/signal_node.o .libs/spin_mutex.o .libs/stats.o .libs/symbol_test.o .libs/sysdep-unix.o .libs/worker_mutex.o -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/src/.libs -L/sw/src/fink.build/gcc5-5.0.0-1/darwin_objdir/x86_64-apple-darwin14.3.0/libstdc++-v3/libsupc++/.libs -ldl -lpthread -install_name /sw/lib/gcc5/lib/libcilkrts.5.dylib -compatibility_version 6 -current_version 6.0 -Wl,-single_module Undefined symbols for architecture x86_64: "___cpu_model", referenced from: _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... 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. On Tue, Mar 31, 2015 at 6:38 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Mar 30, 2015 at 10:38 PM, Jakub Jelinek <jakub@redhat.com> wrote: >> On Mon, Mar 30, 2015 at 07:08:00PM -0700, H.J. Lu wrote: >>> --- a/gcc/gcc.c >>> +++ b/gcc/gcc.c >>> @@ -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" >> >> Why do you need to link libgcc_nonshared.a twice here? -lgcc_s surely won't >> add any new __cpu* undefined references. > > The one added for -lgcc_s is for building shared C++ library since -lgcc isn't > used and only -lgcc_s is used. The one added for -lgcc is for static linking > since -lgcc_s isn't used. I updated the patch to add some testcases > for -static. > I couldn't find a way to add tests for: > > export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ > -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -c -o main.o > main.cc > /export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ > -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -shared -fPIC -O2 -o > libmv20.so mv20.cc > -L/export/build/gnu/gcc/build-x86_64-linux/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs > /export/build/gnu/gcc/build-x86_64-linux/gcc/xg++ > -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -o x main.o > libmv20.so -Wl,-R,. > -L/export/build/gnu/gcc/build-x86_64-linux/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs > /usr/local/bin/ld: x: hidden symbol `__cpu_model' in > /export/build/gnu/gcc/build-x86_64-linux/gcc/libgcc_nonshared.a(cpuinfo.o) > is referenced by DSO > /usr/local/bin/ld: final link failed: Bad value > collect2: error: ld returned 1 exit status > >>> @@ -424,3 +424,8 @@ __cpu_indicator_init (void) >>> >>> return 0; >>> } >>> + >>> +#if defined SHARED && !defined _WIN32 >>> +__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); >>> +__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); >>> +#endif >> >> Will this work on Solaris? >> I'd say you at least want to also guard with some configure check if >> .symver is supported by assembler. >> > > I updated my patch with: > > @@ -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-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 > > OK for master? > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 14:25 ` Jack Howarth @ 2015-03-31 15:58 ` H.J. Lu 2015-03-31 16:10 ` Jack Howarth 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-31 15:58 UTC (permalink / raw) To: Jack Howarth, Ian Lance Taylor Cc: Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump [-- Attachment #1: Type: text/plain, Size: 4659 bytes --] On Tue, Mar 31, 2015 at 7:25 AM, Jack Howarth <howarth.at.gcc@gmail.com> 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. -- H.J. --- 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. --- [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 10127 bytes --] From 760b79124482860b4317f4d39fbe898cfbe8e47b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 15:58 ` H.J. Lu @ 2015-03-31 16:10 ` Jack Howarth 2015-03-31 16:15 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 16:10 UTC (permalink / raw) To: H.J. Lu Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump H.J., Did you attach the correct version of the patch? I don't see anything conditional on linux. Jack On Tue, Mar 31, 2015 at 11:58 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Tue, Mar 31, 2015 at 7:25 AM, Jack Howarth <howarth.at.gcc@gmail.com> 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. > > > -- > H.J. > --- > > 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. > --- ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 16:10 ` Jack Howarth @ 2015-03-31 16:15 ` H.J. Lu 2015-03-31 16:39 ` Jack Howarth 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-31 16:15 UTC (permalink / raw) To: Jack Howarth Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump On Tue, Mar 31, 2015 at 9:09 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: > H.J., > Did you attach the correct version of the patch? I don't see > anything conditional on linux. > Jack My patch will build and install libgcc_nonshared.a for all targets. If you don't link against it, nothing is changed. On Linux, it is used via the init_spec change. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 16:15 ` H.J. Lu @ 2015-03-31 16:39 ` Jack Howarth 2015-03-31 17:00 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 16:39 UTC (permalink / raw) To: H.J. Lu Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump On Tue, Mar 31, 2015 at 12:14 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Tue, Mar 31, 2015 at 9:09 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >> H.J., >> Did you attach the correct version of the patch? I don't see >> anything conditional on linux. >> Jack > > My patch will build and install libgcc_nonshared.a for all targets. If you > don't link against it, nothing is changed. On Linux, it is used via the > init_spec change. Isn't... 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" problematic for Solaris? I am unfamiliar with the Solaris spec handling but sol2.h doesn't seem to have any instances of -lgcc which might imply they use the stock compiler invocation which will now have a non-existent libgcc_nonshared static library. Also, are you leaving the cpu symbols in libgcc.a on non-linux targets? If not, the linkage failure reported in https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01668.html will occur, no? Jack > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 16:39 ` Jack Howarth @ 2015-03-31 17:00 ` H.J. Lu 2015-03-31 18:33 ` Jack Howarth 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-03-31 17:00 UTC (permalink / raw) To: Jack Howarth Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump On Tue, Mar 31, 2015 at 9:39 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: > On Tue, Mar 31, 2015 at 12:14 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Tue, Mar 31, 2015 at 9:09 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >>> H.J., >>> Did you attach the correct version of the patch? I don't see >>> anything conditional on linux. >>> Jack >> >> My patch will build and install libgcc_nonshared.a for all targets. If you >> don't link against it, nothing is changed. On Linux, it is used via the >> init_spec change. > > Isn't... > > 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" > > problematic for Solaris? I am unfamiliar with the Solaris spec > handling but sol2.h doesn't seem to have any instances of -lgcc which > might imply they use the stock compiler invocation which will now have > a non-existent libgcc_nonshared static library. libgcc_nonshared.a is built and installed for all targets. > Also, are you leaving the cpu symbols in libgcc.a on non-linux > targets? If not, the linkage failure reported in > https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01668.html will occur, > no? My current patch doesn't change what are in libgcc.a. It adds libgcc_nonshared.a for all targets, which contains the same cpuinfo.o as in libgcc.a or a dummy .o if libgcc.a doesn't have cpuinfo.o. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 17:00 ` H.J. Lu @ 2015-03-31 18:33 ` Jack Howarth 2015-04-14 15:07 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jack Howarth @ 2015-03-31 18:33 UTC (permalink / raw) To: H.J. Lu Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump On Tue, Mar 31, 2015 at 1:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Tue, Mar 31, 2015 at 9:39 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >> On Tue, Mar 31, 2015 at 12:14 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>> On Tue, Mar 31, 2015 at 9:09 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >>>> H.J., >>>> Did you attach the correct version of the patch? I don't see >>>> anything conditional on linux. >>>> Jack >>> >>> My patch will build and install libgcc_nonshared.a for all targets. If you >>> don't link against it, nothing is changed. On Linux, it is used via the >>> init_spec change. >> >> Isn't... >> >> 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" >> >> problematic for Solaris? I am unfamiliar with the Solaris spec >> handling but sol2.h doesn't seem to have any instances of -lgcc which >> might imply they use the stock compiler invocation which will now have >> a non-existent libgcc_nonshared static library. > > libgcc_nonshared.a is built and installed for all targets. > >> Also, are you leaving the cpu symbols in libgcc.a on non-linux >> targets? If not, the linkage failure reported in >> https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01668.html will occur, >> no? > > My current patch doesn't change what are in libgcc.a. It > adds libgcc_nonshared.a for all targets, which contains > the same cpuinfo.o as in libgcc.a or a dummy .o if libgcc.a > doesn't have cpuinfo.o. I can confirm that the most current patch bootstraps on x86_64-apple-darwin14 and that all of the new tests show up as unsupported in the test suite. Jack > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-03-31 18:33 ` Jack Howarth @ 2015-04-14 15:07 ` H.J. Lu 2015-04-16 16:29 ` Mike Stump 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-04-14 15:07 UTC (permalink / raw) To: Jack Howarth Cc: Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe, Mike Stump [-- Attachment #1: Type: text/plain, Size: 2634 bytes --] On Tue, Mar 31, 2015 at 11:33 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: > On Tue, Mar 31, 2015 at 1:00 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Tue, Mar 31, 2015 at 9:39 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >>> On Tue, Mar 31, 2015 at 12:14 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>>> On Tue, Mar 31, 2015 at 9:09 AM, Jack Howarth <howarth.at.gcc@gmail.com> wrote: >>>>> H.J., >>>>> Did you attach the correct version of the patch? I don't see >>>>> anything conditional on linux. >>>>> Jack >>>> >>>> My patch will build and install libgcc_nonshared.a for all targets. If you >>>> don't link against it, nothing is changed. On Linux, it is used via the >>>> init_spec change. >>> >>> Isn't... >>> >>> 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" >>> >>> problematic for Solaris? I am unfamiliar with the Solaris spec >>> handling but sol2.h doesn't seem to have any instances of -lgcc which >>> might imply they use the stock compiler invocation which will now have >>> a non-existent libgcc_nonshared static library. >> >> libgcc_nonshared.a is built and installed for all targets. >> >>> Also, are you leaving the cpu symbols in libgcc.a on non-linux >>> targets? If not, the linkage failure reported in >>> https://gcc.gnu.org/ml/gcc-patches/2015-03/msg01668.html will occur, >>> no? >> >> My current patch doesn't change what are in libgcc.a. It >> adds libgcc_nonshared.a for all targets, which contains >> the same cpuinfo.o as in libgcc.a or a dummy .o if libgcc.a >> doesn't have cpuinfo.o. > > > I can confirm that the most current patch bootstraps on > x86_64-apple-darwin14 and that all of the new tests show up as > unsupported in the test suite. > Jack I am re-posting this patch. OK for trunk? Thanks. -- H.J. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: text/x-patch, Size: 10127 bytes --] From 9ddf859ba7112c3459f709fbb7aaaf9eabf485b6 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-14 15:07 ` H.J. Lu @ 2015-04-16 16:29 ` Mike Stump 2015-04-17 8:05 ` Uros Bizjak 0 siblings, 1 reply; 46+ messages in thread From: Mike Stump @ 2015-04-16 16:29 UTC (permalink / raw) To: H.J. Lu Cc: Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Uros Bizjak, Iain Sandoe On Apr 14, 2015, at 8:07 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >> I can confirm that the most current patch bootstraps on >> x86_64-apple-darwin14 and that all of the new tests show up as >> unsupported in the test suite. >> Jack > > I am re-posting this patch. OK for trunk? If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-16 16:29 ` Mike Stump @ 2015-04-17 8:05 ` Uros Bizjak 2015-04-17 10:36 ` H.J. Lu 2015-04-17 12:23 ` Mike Stump 0 siblings, 2 replies; 46+ messages in thread From: Uros Bizjak @ 2015-04-17 8:05 UTC (permalink / raw) To: Mike Stump Cc: H.J. Lu, Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Iain Sandoe, Rainer Orth On Thu, Apr 16, 2015 at 6:28 PM, Mike Stump <mikestump@comcast.net> wrote: > On Apr 14, 2015, at 8:07 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >>> I can confirm that the most current patch bootstraps on >>> x86_64-apple-darwin14 and that all of the new tests show up as >>> unsupported in the test suite. >>> Jack >> >> I am re-posting this patch. OK for trunk? > > If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. What about Solaris? Uros. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 8:05 ` Uros Bizjak @ 2015-04-17 10:36 ` H.J. Lu 2015-04-17 11:04 ` Uros Bizjak 2015-04-17 12:23 ` Mike Stump 1 sibling, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-04-17 10:36 UTC (permalink / raw) To: Uros Bizjak Cc: Mike Stump, Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 1:05 AM, Uros Bizjak <ubizjak@gmail.com> wrote: > On Thu, Apr 16, 2015 at 6:28 PM, Mike Stump <mikestump@comcast.net> wrote: >> On Apr 14, 2015, at 8:07 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >>>> I can confirm that the most current patch bootstraps on >>>> x86_64-apple-darwin14 and that all of the new tests show up as >>>> unsupported in the test suite. >>>> Jack >>> >>> I am re-posting this patch. OK for trunk? >> >> If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. > > What about Solaris? > > Uros. There are 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-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 USE_ELF_SYMVER is only defined for Linux. This patch won't break Solaris. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 10:36 ` H.J. Lu @ 2015-04-17 11:04 ` Uros Bizjak 2015-04-17 11:12 ` Uros Bizjak 2015-04-17 11:38 ` Jakub Jelinek 0 siblings, 2 replies; 46+ messages in thread From: Uros Bizjak @ 2015-04-17 11:04 UTC (permalink / raw) To: H.J. Lu Cc: Mike Stump, Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 12:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >>>>> I can confirm that the most current patch bootstraps on >>>>> x86_64-apple-darwin14 and that all of the new tests show up as >>>>> unsupported in the test suite. >>>>> Jack >>>> >>>> I am re-posting this patch. OK for trunk? >>> >>> If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. >> >> What about Solaris? >> >> Uros. > > There are [...] Assuming Jakub is OK with the patch, let's go ahead with it. OK for mainline. Thanks, Uros. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 11:04 ` Uros Bizjak @ 2015-04-17 11:12 ` Uros Bizjak 2015-04-17 11:38 ` Jakub Jelinek 1 sibling, 0 replies; 46+ messages in thread From: Uros Bizjak @ 2015-04-17 11:12 UTC (permalink / raw) To: H.J. Lu Cc: Mike Stump, Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 1:04 PM, Uros Bizjak <ubizjak@gmail.com> wrote: > On Fri, Apr 17, 2015 at 12:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > >>>>>> I can confirm that the most current patch bootstraps on >>>>>> x86_64-apple-darwin14 and that all of the new tests show up as >>>>>> unsupported in the test suite. >>>>>> Jack >>>>> >>>>> I am re-posting this patch. OK for trunk? >>>> >>>> If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. >>> >>> What about Solaris? >>> >>> Uros. >> >> There are > > [...] > > Assuming Jakub is OK with the patch, let's go ahead with it. > > OK for mainline. Ehm, the approval is for x86 part, you still need approval from libgcc maintainer. Uros. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 11:04 ` Uros Bizjak 2015-04-17 11:12 ` Uros Bizjak @ 2015-04-17 11:38 ` Jakub Jelinek 2015-04-17 11:48 ` H.J. Lu 1 sibling, 1 reply; 46+ messages in thread From: Jakub Jelinek @ 2015-04-17 11:38 UTC (permalink / raw) To: Uros Bizjak Cc: H.J. Lu, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 01:04:20PM +0200, Uros Bizjak wrote: > On Fri, Apr 17, 2015 at 12:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > > >>>>> I can confirm that the most current patch bootstraps on > >>>>> x86_64-apple-darwin14 and that all of the new tests show up as > >>>>> unsupported in the test suite. > >>>>> Jack > >>>> > >>>> I am re-posting this patch. OK for trunk? > >>> > >>> If Jack is happy, Iâm happy. :-) That leaves the x86 people to comment on it. > >> > >> What about Solaris? > >> > >> Uros. > > > > There are > > [...] > > Assuming Jakub is OK with the patch, let's go ahead with it. > > OK for mainline. I don't like it. Nonshared libgcc is libgcc.a, period. No sense in creating yet another library for that. So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that static_name is always linked in, in the switch combinations that it isn't right now of course after shared_name rather than before that. I thought we've fixed that years ago... Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 11:38 ` Jakub Jelinek @ 2015-04-17 11:48 ` H.J. Lu 2015-04-17 12:00 ` Jakub Jelinek 0 siblings, 1 reply; 46+ messages in thread From: H.J. Lu @ 2015-04-17 11:48 UTC (permalink / raw) To: Jakub Jelinek Cc: Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 4:37 AM, Jakub Jelinek <jakub@redhat.com> wrote: > On Fri, Apr 17, 2015 at 01:04:20PM +0200, Uros Bizjak wrote: >> On Fri, Apr 17, 2015 at 12:36 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> >> >>>>> I can confirm that the most current patch bootstraps on >> >>>>> x86_64-apple-darwin14 and that all of the new tests show up as >> >>>>> unsupported in the test suite. >> >>>>> Jack >> >>>> >> >>>> I am re-posting this patch. OK for trunk? >> >>> >> >>> If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. >> >> >> >> What about Solaris? >> >> >> >> Uros. >> > >> > There are >> >> [...] >> >> Assuming Jakub is OK with the patch, let's go ahead with it. >> >> OK for mainline. > > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in > creating yet another library for that. > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that > static_name is always linked in, in the switch combinations that it isn't > right now of course after shared_name rather than before that. > I thought we've fixed that years ago... > We never pass -lgcc to linker when building C++ DSO: /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper -plugin-opt=-fresolution=/tmp/ccZC7iqy.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o [hjl@gnu-32 tmp]$ That is why libgcc_nonshared.a is needed. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 11:48 ` H.J. Lu @ 2015-04-17 12:00 ` Jakub Jelinek 2015-04-17 12:36 ` H.J. Lu 0 siblings, 1 reply; 46+ messages in thread From: Jakub Jelinek @ 2015-04-17 12:00 UTC (permalink / raw) To: H.J. Lu Cc: Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: > > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in > > creating yet another library for that. > > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead > > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that > > static_name is always linked in, in the switch combinations that it isn't > > right now of course after shared_name rather than before that. > > I thought we've fixed that years ago... > > > > We never pass -lgcc to linker when building C++ DSO: > > /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin > /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so > -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper > -plugin-opt=-fresolution=/tmp/ccZC7iqy.res > -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc > -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed > --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared > /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o > /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o > -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 > -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 > -L/lib/../lib64 -L/usr/lib/../lib64 > -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm > -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o > /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o > [hjl@gnu-32 tmp]$ > > That is why libgcc_nonshared.a is needed. See what I wrote. I think it is a bug that we don't do that, in your case we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. Or, if you don't want to change that, as the multi-versioning change is i386/x86_64 only change, just ensure that those targets have t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux targets where -lgcc is linked in always after -lgcc_s. Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 12:00 ` Jakub Jelinek @ 2015-04-17 12:36 ` H.J. Lu 2015-04-17 12:40 ` Jakub Jelinek ` (3 more replies) 0 siblings, 4 replies; 46+ messages in thread From: H.J. Lu @ 2015-04-17 12:36 UTC (permalink / raw) To: Jakub Jelinek Cc: Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth [-- Attachment #1: Type: text/plain, Size: 2628 bytes --] On Fri, Apr 17, 2015 at 4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in >> > creating yet another library for that. >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that >> > static_name is always linked in, in the switch combinations that it isn't >> > right now of course after shared_name rather than before that. >> > I thought we've fixed that years ago... >> > >> >> We never pass -lgcc to linker when building C++ DSO: >> >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so >> -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper >> -plugin-opt=-fresolution=/tmp/ccZC7iqy.res >> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc >> -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed >> --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 >> -L/lib/../lib64 -L/usr/lib/../lib64 >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm >> -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o >> [hjl@gnu-32 tmp]$ >> >> That is why libgcc_nonshared.a is needed. > > See what I wrote. I think it is a bug that we don't do that, in your case > we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. > Or, if you don't want to change that, as the multi-versioning change is > i386/x86_64 only change, just ensure that those targets have > t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux > targets where -lgcc is linked in always after -lgcc_s. > > Jakub This patch works for me. OK for trunk? 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 * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. * 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-linux (HOST_LIBGCC2_CFLAGS): Add -DUSE_ELF_SYMVER. Thanks. -- H.J. [-- Attachment #2: 0001-Hide-__cpu_indicator_init-__cpu_model-from-linker.patch --] [-- Type: application/octet-stream, Size: 6190 bytes --] From ea6a6f31551b6cb96d27db4388499a259aaceeda Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> 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 creates libgcc.so as a linker script, hides __cpu_indicator_init and __cpu_model in libgcc.so.1 from linker, forces linker to resolve __cpu_indicator_init and __cpu_model to their hidden definitions in libgcc.a while providing backward binary compatibility. 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 * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. * 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-linux (HOST_LIBGCC2_CFLAGS): Add -DUSE_ELF_SYMVER. --- 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/config.host | 2 +- libgcc/config/i386/cpuinfo.c | 7 ++++++- libgcc/config/i386/t-linux | 2 +- 9 files changed, 50 insertions(+), 3 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/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/config.host b/libgcc/config.host index 4b15895..ce14b9e 100644 --- a/libgcc/config.host +++ b/libgcc/config.host @@ -1306,7 +1306,7 @@ i[34567]86-*-linux* | x86_64-*-linux* | \ i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \ i[34567]86-*-knetbsd*-gnu | \ i[34567]86-*-gnu*) - tmake_file="${tmake_file} t-tls i386/t-linux" + tmake_file="${tmake_file} t-tls i386/t-linux t-slibgcc-libgcc" if test "$libgcc_cv_cfi" = "yes"; then tmake_file="${tmake_file} t-stack i386/t-stack-i386" fi 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-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 -- 2.1.0 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 12:36 ` H.J. Lu @ 2015-04-17 12:40 ` Jakub Jelinek 2015-05-08 23:00 ` Rich Felker ` (2 subsequent siblings) 3 siblings, 0 replies; 46+ messages in thread From: Jakub Jelinek @ 2015-04-17 12:40 UTC (permalink / raw) To: H.J. Lu Cc: Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 05:36:30AM -0700, H.J. Lu wrote: > This patch works for me. OK for trunk? > > 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 > * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. > * 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-linux (HOST_LIBGCC2_CFLAGS): Add > -DUSE_ELF_SYMVER. LGTM. Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 12:36 ` H.J. Lu 2015-04-17 12:40 ` Jakub Jelinek @ 2015-05-08 23:00 ` Rich Felker 2015-05-08 23:59 ` H.J. Lu 2015-05-09 14:31 ` Szabolcs Nagy 2015-07-22 21:14 ` Sriraman Tallam 3 siblings, 1 reply; 46+ messages in thread From: Rich Felker @ 2015-05-08 23:00 UTC (permalink / raw) To: H.J. Lu Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 05:36:30AM -0700, H.J. Lu wrote: > On Fri, Apr 17, 2015@4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: > > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: > >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in > >> > creating yet another library for that. > >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead > >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that > >> > static_name is always linked in, in the switch combinations that it isn't > >> > right now of course after shared_name rather than before that. > >> > I thought we've fixed that years ago... > >> > > >> > >> We never pass -lgcc to linker when building C++ DSO: > >> > >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin > >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so > >> -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper > >> -plugin-opt=-fresolution=/tmp/ccZC7iqy.res > >> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc > >> -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed > >> --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 > >> -L/lib/../lib64 -L/usr/lib/../lib64 > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm > >> -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o > >> [hjl@gnu-32 tmp]$ > >> > >> That is why libgcc_nonshared.a is needed. > > > > See what I wrote. I think it is a bug that we don't do that, in your case > > we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. > > Or, if you don't want to change that, as the multi-versioning change is > > i386/x86_64 only change, just ensure that those targets have > > t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux > > targets where -lgcc is linked in always after -lgcc_s. > > > > Jakub > > This patch works for me. OK for trunk? > > 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 > * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. > * 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-linux (HOST_LIBGCC2_CFLAGS): Add > -DUSE_ELF_SYMVER. > > Thanks. This patch seems to be making some trouble for musl's dynamic linker, which I could go into details on if necessary, but I'm wondering if there's any reason why simple visibility wasn't used if you want to hide the symbols from the linker. Could you explain the motivation for doing it this way? Is the intent for libgcc_s.so to refer to its own internal copy of __cpu_model and __cpu_indicator_init? If so, it seems wrong to have a relocation referring to them symbolically at all; this should just be a relative relocation. Rich ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-08 23:00 ` Rich Felker @ 2015-05-08 23:59 ` H.J. Lu 0 siblings, 0 replies; 46+ messages in thread From: H.J. Lu @ 2015-05-08 23:59 UTC (permalink / raw) To: Rich Felker Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, May 8, 2015 at 4:00 PM, Rich Felker <dalias@libc.org> wrote: > On Fri, Apr 17, 2015 at 05:36:30AM -0700, H.J. Lu wrote: >> On Fri, Apr 17, 2015@4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: >> > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: >> >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in >> >> > creating yet another library for that. >> >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead >> >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that >> >> > static_name is always linked in, in the switch combinations that it isn't >> >> > right now of course after shared_name rather than before that. >> >> > I thought we've fixed that years ago... >> >> > >> >> >> >> We never pass -lgcc to linker when building C++ DSO: >> >> >> >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin >> >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so >> >> -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper >> >> -plugin-opt=-fresolution=/tmp/ccZC7iqy.res >> >> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc >> >> -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed >> >> --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared >> >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o >> >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o >> >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 >> >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 >> >> -L/lib/../lib64 -L/usr/lib/../lib64 >> >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm >> >> -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o >> >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o >> >> [hjl@gnu-32 tmp]$ >> >> >> >> That is why libgcc_nonshared.a is needed. >> > >> > See what I wrote. I think it is a bug that we don't do that, in your case >> > we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. >> > Or, if you don't want to change that, as the multi-versioning change is >> > i386/x86_64 only change, just ensure that those targets have >> > t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux >> > targets where -lgcc is linked in always after -lgcc_s. >> > >> > Jakub >> >> This patch works for me. OK for trunk? >> >> 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 >> * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. >> * 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-linux (HOST_LIBGCC2_CFLAGS): Add >> -DUSE_ELF_SYMVER. >> >> Thanks. > > This patch seems to be making some trouble for musl's dynamic linker, > which I could go into details on if necessary, but I'm wondering if It sounds like a bug in musl's dynamic linker. foo@VERSION is visible to ld.so, but invisible to ld. > there's any reason why simple visibility wasn't used if you want to > hide the symbols from the linker. Could you explain the motivation for > doing it this way? Is the intent for libgcc_s.so to refer to its own > internal copy of __cpu_model and __cpu_indicator_init? If so, it seems > wrong to have a relocation referring to them symbolically at all; this > should just be a relative relocation. It is for backward binary compatibility so that the old binaries which have references to libgcc_s.so.1 work with the new libgcc_s.so.1. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 12:36 ` H.J. Lu 2015-04-17 12:40 ` Jakub Jelinek 2015-05-08 23:00 ` Rich Felker @ 2015-05-09 14:31 ` Szabolcs Nagy 2015-05-09 17:41 ` H.J. Lu 2015-07-22 21:14 ` Sriraman Tallam 3 siblings, 1 reply; 46+ messages in thread From: Szabolcs Nagy @ 2015-05-09 14:31 UTC (permalink / raw) To: H.J. Lu Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker * H.J. Lu <hjl.tools@gmail.com> [2015-04-17 05:36:30 -0700]: > On Fri, Apr 17, 2015 at 4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: > > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: > >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in > >> > creating yet another library for that. > >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead > >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that > >> > static_name is always linked in, in the switch combinations that it isn't > >> > right now of course after shared_name rather than before that. > >> > I thought we've fixed that years ago... > >> > I think the patch committed for this is suboptimal. (it breaks with musl libc on x86 if libgcc_s is linked into a binary) the patch: http://gcc.gnu.org/ml/gcc-patches/2015-04/msg00878.html original thread: http://gcc.gnu.org/ml/gcc-patches/2015-03/msg01520.html The symbol versioning hack for __cpu_model and __cpu_indicator_init makes them invisible to the musl dynamic linker so their relocation fails with 'symbol not found' error. (affects anything linked with -lgcc_s) I don't yet understand all the constraints, what I gathered is * x86 multi-versioning was broken with libgcc_s because ifunc resolution tried to use a libgcc_s function before it was relocated. (mv dispatch uses ifunc before relocation is finished, that calls __builtin_cpu_init that turns into a call to __cpu_indicator_init that is a constructor in libgcc_s.so to initialize __cpu_model). * old binaries that happened to work still have to work with new libgcc_s.so so __cpu_* must have a definition there. * new binaries must get their own definition of __cpu_* (ie statically linked from libgcc.a) to avoid the ifunc issue. I would rename the __cpu_* symbols and put those only in libgcc.a while keeping the old __cpu_* symbols still available in libgcc_s.so: old binaries work with new gcc, new binaries get the right definitions (so they work on old systems and new systems too, and yes -lgcc should be passed to c++ dso linking). Did i miss something? (This is not in the gcc-5 branch so I assume It is OK to work on a less intrusive fix.) PS.: It would be nice if there was a specification for the ifunc interface contract before any ifunc/multiversioned interface gets into the compiler runtime (see libatomic.so) to avoid similar bugs and incompatibilities between the dynamic linker/loader and compiler, the dynamic linker cannot guarantee arbitrary ifunc calls to work. > >> > >> We never pass -lgcc to linker when building C++ DSO: > >> > >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin > >> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so > >> -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper > >> -plugin-opt=-fresolution=/tmp/ccZC7iqy.res > >> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc > >> -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed > >> --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 > >> -L/lib/../lib64 -L/usr/lib/../lib64 > >> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm > >> -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o > >> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o > >> [hjl@gnu-32 tmp]$ > >> > >> That is why libgcc_nonshared.a is needed. > > > > See what I wrote. I think it is a bug that we don't do that, in your case > > we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. > > Or, if you don't want to change that, as the multi-versioning change is > > i386/x86_64 only change, just ensure that those targets have > > t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux > > targets where -lgcc is linked in always after -lgcc_s. > > > > Jakub > > This patch works for me. OK for trunk? > > 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 > * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. > * 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-linux (HOST_LIBGCC2_CFLAGS): Add > -DUSE_ELF_SYMVER. > > Thanks. > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-09 14:31 ` Szabolcs Nagy @ 2015-05-09 17:41 ` H.J. Lu 2015-05-09 18:57 ` Szabolcs Nagy 2015-05-09 19:36 ` Rich Felker 0 siblings, 2 replies; 46+ messages in thread From: H.J. Lu @ 2015-05-09 17:41 UTC (permalink / raw) To: Szabolcs Nagy Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker On Sat, May 9, 2015 at 7:31 AM, Szabolcs Nagy <nsz@port70.net> wrote: > * H.J. Lu <hjl.tools@gmail.com> [2015-04-17 05:36:30 -0700]: >> On Fri, Apr 17, 2015 at 4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: >> > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: >> >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in >> >> > creating yet another library for that. >> >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead >> >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that >> >> > static_name is always linked in, in the switch combinations that it isn't >> >> > right now of course after shared_name rather than before that. >> >> > I thought we've fixed that years ago... >> >> > > > I think the patch committed for this is suboptimal. > (it breaks with musl libc on x86 if libgcc_s is linked into a binary) > > the patch: > http://gcc.gnu.org/ml/gcc-patches/2015-04/msg00878.html > original thread: > http://gcc.gnu.org/ml/gcc-patches/2015-03/msg01520.html > > The symbol versioning hack for __cpu_model and __cpu_indicator_init > makes them invisible to the musl dynamic linker so their relocation > fails with 'symbol not found' error. > (affects anything linked with -lgcc_s) There are 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 __cpu_indicator_init@GCC_4.8.0 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 and 000000000215000 0000000400000001 R_X86_64_64 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 in libgcc_s.so.1. Musl ld.so must be fixed to handle it. -- H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-09 17:41 ` H.J. Lu @ 2015-05-09 18:57 ` Szabolcs Nagy 2015-05-11 10:20 ` Szabolcs Nagy 2015-05-09 19:36 ` Rich Felker 1 sibling, 1 reply; 46+ messages in thread From: Szabolcs Nagy @ 2015-05-09 18:57 UTC (permalink / raw) To: H.J. Lu Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker * H.J. Lu <hjl.tools@gmail.com> [2015-05-09 10:41:41 -0700]: > On Sat, May 9, 2015 at 7:31 AM, Szabolcs Nagy <nsz@port70.net> wrote: > > > > The symbol versioning hack for __cpu_model and __cpu_indicator_init > > makes them invisible to the musl dynamic linker so their relocation > > fails with 'symbol not found' error. > > (affects anything linked with -lgcc_s) > > There are > > 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 > __cpu_indicator_init@GCC_4.8.0 > 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 > > and > > 000000000215000 0000000400000001 R_X86_64_64 > 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 > 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT > 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 > > in libgcc_s.so.1. Musl ld.so must be fixed to handle it. > (sorry, i missed the other discussion about the same issue) i still think a solution that avoids depending on symbol versioning in the dynamic linker would be preferable. (versioning is a sun/gnu elf extension as far as i understand, eg. not supported by posix dlsym). i think it might be enough to add __cpu_indicator_init_local as an alias to __cpu_indicator_init in libgcc.a and then use the *_local symbol from the ifunc resolver, that way no new dependency is added to libgcc_s.so handling. (adding versioning support to musl is problematic with the current code, a simpler workaround for musl is to provide its own weak definition of __cpu_indicator_init, but that's ugly.) ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-09 18:57 ` Szabolcs Nagy @ 2015-05-11 10:20 ` Szabolcs Nagy 2015-05-11 10:32 ` Jakub Jelinek 0 siblings, 1 reply; 46+ messages in thread From: Szabolcs Nagy @ 2015-05-11 10:20 UTC (permalink / raw) To: Szabolcs Nagy, H.J. Lu Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker [-- Attachment #1: Type: text/plain, Size: 1681 bytes --] On 09/05/15 19:57, Szabolcs Nagy wrote: > * H.J. Lu <hjl.tools@gmail.com> [2015-05-09 10:41:41 -0700]: >> There are >> >> 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 >> __cpu_indicator_init@GCC_4.8.0 >> 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 >> >> and >> >> 000000000215000 0000000400000001 R_X86_64_64 >> 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 >> 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT >> 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 >> >> in libgcc_s.so.1. Musl ld.so must be fixed to handle it. >> Rich is looking at how to do this non-intrusively, but it seems non-trivial (some users of musl prefer not to resolve such versioned symbols). > > i think it might be enough to add __cpu_indicator_init_local > as an alias to __cpu_indicator_init in libgcc.a and then use > the *_local symbol from the ifunc resolver, that way no new > dependency is added to libgcc_s.so handling. i tried this approach and it seems to work: passes all multiversioning tests on x86_64. i think it's no worse than the symver approach. is it ok to change the current fix to this? libgcc/Changelog: 2015-05-11 Szabolcs Nagy <szabolcs.nagy@arm.com> * config/i386/cpuinfo.c (__cpu_indicator_init_local): Add. (__cpu_indicator_init@GCC_4.8.0, __cpu_model@GCC_4.8.0): Remove. * config/i386/t-linux (HOST_LIBGCC2_CFLAGS): Remove -DUSE_ELF_SYMVER. gcc/Changelog: 2015-05-11 Szabolcs Nagy <szabolcs.nagy@arm.com> * config/i386/i386.c (ix86_expand_builtin): Make __builtin_cpu_init call __cpu_indicator_init_local instead of __cpu_indicator_init. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: libgcc.diff --] [-- Type: text/x-patch; name=libgcc.diff, Size: 1706 bytes --] diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 7bd9ff3..7327cf3 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -38398,10 +38398,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget, { case IX86_BUILTIN_CPU_INIT: { - /* Make it call __cpu_indicator_init in libgcc. */ + /* Make it call __cpu_indicator_init_local in libgcc.a. */ tree call_expr, fndecl, type; type = build_function_type_list (integer_type_node, NULL_TREE); - fndecl = build_fn_decl ("__cpu_indicator_init", type); + fndecl = build_fn_decl ("__cpu_indicator_init_local", type); call_expr = build_call_expr (fndecl, 0); return expand_expr (call_expr, target, mode, EXPAND_NORMAL); } diff --git a/libgcc/config/i386/cpuinfo.c b/libgcc/config/i386/cpuinfo.c index f6f91dd..86b6d21 100644 --- a/libgcc/config/i386/cpuinfo.c +++ b/libgcc/config/i386/cpuinfo.c @@ -425,7 +425,7 @@ __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"); +#ifndef SHARED +int __cpu_indicator_init_local (void) + __attribute__ ((weak, alias ("__cpu_indicator_init"))); #endif diff --git a/libgcc/config/i386/t-linux b/libgcc/config/i386/t-linux index 11bb46e..4f47f7b 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 -DUSE_ELF_SYMVER +HOST_LIBGCC2_CFLAGS += -mlong-double-80 ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-11 10:20 ` Szabolcs Nagy @ 2015-05-11 10:32 ` Jakub Jelinek 2015-05-11 12:39 ` Szabolcs Nagy 2015-05-11 14:12 ` Rich Felker 0 siblings, 2 replies; 46+ messages in thread From: Jakub Jelinek @ 2015-05-11 10:32 UTC (permalink / raw) To: Szabolcs Nagy Cc: Szabolcs Nagy, H.J. Lu, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker On Mon, May 11, 2015 at 11:20:15AM +0100, Szabolcs Nagy wrote: > > > On 09/05/15 19:57, Szabolcs Nagy wrote: > > * H.J. Lu <hjl.tools@gmail.com> [2015-05-09 10:41:41 -0700]: > >> There are > >> > >> 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 > >> __cpu_indicator_init@GCC_4.8.0 > >> 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 > >> > >> and > >> > >> 000000000215000 0000000400000001 R_X86_64_64 > >> 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 > >> 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT > >> 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 > >> > >> in libgcc_s.so.1. Musl ld.so must be fixed to handle it. > >> > > Rich is looking at how to do this non-intrusively, but > it seems non-trivial (some users of musl prefer not to > resolve such versioned symbols). > > > > > i think it might be enough to add __cpu_indicator_init_local > > as an alias to __cpu_indicator_init in libgcc.a and then use > > the *_local symbol from the ifunc resolver, that way no new > > dependency is added to libgcc_s.so handling. > > i tried this approach and it seems to work: passes all > multiversioning tests on x86_64. > > i think it's no worse than the symver approach. > > is it ok to change the current fix to this? No. Instead of piling hacks like this just fix it in musl. libgcc certainly isn't the only library that uses @ symbol versions, e.g. libstdc++ does as well, as well as many other shared libraries. Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-11 10:32 ` Jakub Jelinek @ 2015-05-11 12:39 ` Szabolcs Nagy 2015-05-11 13:05 ` Jakub Jelinek 2015-05-11 14:12 ` Rich Felker 1 sibling, 1 reply; 46+ messages in thread From: Szabolcs Nagy @ 2015-05-11 12:39 UTC (permalink / raw) To: Jakub Jelinek Cc: Szabolcs Nagy, H.J. Lu, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker On 11/05/15 11:31, Jakub Jelinek wrote: > On Mon, May 11, 2015 at 11:20:15AM +0100, Szabolcs Nagy wrote: >>> i think it might be enough to add __cpu_indicator_init_local >>> as an alias to __cpu_indicator_init in libgcc.a and then use >>> the *_local symbol from the ifunc resolver, that way no new >>> dependency is added to libgcc_s.so handling. >> >> i tried this approach and it seems to work: passes all >> multiversioning tests on x86_64. >> >> i think it's no worse than the symver approach. >> >> is it ok to change the current fix to this? > > No. Instead of piling hacks like this just fix it in musl. > libgcc certainly isn't the only library that uses @ symbol versions, > e.g. libstdc++ does as well, as well as many other shared libraries. > can you explain how using a standard elf feature is a hack, but the current symver asm directive is not? fyi, musl loader loads libstdc++ just fine because it has no relocations for symbols which only has sym@version definition (libgcc_s.so.1 has because __cpu_indicator_init is a ctor). musl may end up supporting @version but that's an independent quest. (the one big pile of hacks here is multiversioning: each function with mv has its own ifunc resolver repeating the same logic, then the >1.5K cpuinfo.o is static linked into every single dso that uses mv and the separate __cpu_model structs all have to be initialized.. including the unused one in libgcc_s.so.1 because of the ctor.. adding more startup overhead. i'd gladly propose a patch to remove this feature if getting rid of piling hacks has priority.. the current design seems problematic to me for other archs that may need to call libc functions to do the dispatch anyway.) ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-11 12:39 ` Szabolcs Nagy @ 2015-05-11 13:05 ` Jakub Jelinek 2015-05-11 15:30 ` Szabolcs Nagy 0 siblings, 1 reply; 46+ messages in thread From: Jakub Jelinek @ 2015-05-11 13:05 UTC (permalink / raw) To: Szabolcs Nagy Cc: Szabolcs Nagy, H.J. Lu, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker On Mon, May 11, 2015 at 01:39:17PM +0100, Szabolcs Nagy wrote: > fyi, musl loader loads libstdc++ just fine because it has no But will it load any shared library that uses any of the 26 (if I count well on x86_64) @ symbols from libstdc++.so.6? readelf -Ws /lib64/libstdc++.so.6 | grep '@' | grep -v 'UND\|@@' For libstdc++ that is primarily C++ apps and shared libraries compiled/linked with GCC 4.0.0. > musl may end up supporting @version but that's an independent > quest. It is not independent. If musl claims to support symbol versioning, it should support it properly, if not, then supposedly gcc configured for musl can't be compatible with gcc configured for other linux C libraries, and should force symbol versioning off. Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-11 13:05 ` Jakub Jelinek @ 2015-05-11 15:30 ` Szabolcs Nagy 0 siblings, 0 replies; 46+ messages in thread From: Szabolcs Nagy @ 2015-05-11 15:30 UTC (permalink / raw) To: Jakub Jelinek Cc: Szabolcs Nagy, H.J. Lu, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth, Rich Felker On 11/05/15 14:05, Jakub Jelinek wrote: > On Mon, May 11, 2015 at 01:39:17PM +0100, Szabolcs Nagy wrote: >> fyi, musl loader loads libstdc++ just fine because it has no > > But will it load any shared library that uses any of the 26 (if I count well > on x86_64) @ symbols from libstdc++.so.6? i looked, but all of those symbols have @@ variant too so at least the libraries would load with musl. >> musl may end up supporting @version but that's an independent >> quest. > > It is not independent. If musl claims to support symbol versioning, it > should support it properly, if not, then supposedly gcc configured for musl > can't be compatible with gcc configured for other linux C libraries, and > should force symbol versioning off. ok, but the current solution does not make that easy: configuring gcc with --disable-gnu-indirect-function --disable-symvers has no effect on libgcc_s.so.1 on linux. (i can try to create a patch that removes the new -DUSE_ELF_SYMVER from the libgcc cflags for musl, but that seems a worse solution than the weak alias one). (note that previously a simple spec file was enough to use an existing gcc on linux to build things against musl... this didnt work for c++ code that used libstdc++ headers, but now it also fails for any build using -lgcc_s). ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-11 10:32 ` Jakub Jelinek 2015-05-11 12:39 ` Szabolcs Nagy @ 2015-05-11 14:12 ` Rich Felker 1 sibling, 0 replies; 46+ messages in thread From: Rich Felker @ 2015-05-11 14:12 UTC (permalink / raw) To: Jakub Jelinek Cc: Szabolcs Nagy, Szabolcs Nagy, H.J. Lu, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Mon, May 11, 2015 at 12:31:51PM +0200, Jakub Jelinek wrote: > On Mon, May 11, 2015 at 11:20:15AM +0100, Szabolcs Nagy wrote: > > > > > > On 09/05/15 19:57, Szabolcs Nagy wrote: > > > * H.J. Lu <hjl.tools@gmail.com> [2015-05-09 10:41:41 -0700]: > > >> There are > > >> > > >> 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 > > >> __cpu_indicator_init@GCC_4.8.0 > > >> 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 > > >> > > >> and > > >> > > >> 000000000215000 0000000400000001 R_X86_64_64 > > >> 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 > > >> 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT > > >> 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 > > >> > > >> in libgcc_s.so.1. Musl ld.so must be fixed to handle it. > > >> > > > > Rich is looking at how to do this non-intrusively, but > > it seems non-trivial (some users of musl prefer not to > > resolve such versioned symbols). > > > > > > > > i think it might be enough to add __cpu_indicator_init_local > > > as an alias to __cpu_indicator_init in libgcc.a and then use > > > the *_local symbol from the ifunc resolver, that way no new > > > dependency is added to libgcc_s.so handling. > > > > i tried this approach and it seems to work: passes all > > multiversioning tests on x86_64. > > > > i think it's no worse than the symver approach. > > > > is it ok to change the current fix to this? > > No. Instead of piling hacks like this just fix it in musl. I wouldn't call it piling hacks; it's an improvement as far as I can tell since it remove symbolic relocations and replaces them with relative ones. > libgcc certainly isn't the only library that uses @ symbol versions, > e.g. libstdc++ does as well, as well as many other shared libraries. We haven't encountered such issues there. Rich ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-09 17:41 ` H.J. Lu 2015-05-09 18:57 ` Szabolcs Nagy @ 2015-05-09 19:36 ` Rich Felker 2015-05-09 19:54 ` Jakub Jelinek 1 sibling, 1 reply; 46+ messages in thread From: Rich Felker @ 2015-05-09 19:36 UTC (permalink / raw) To: H.J. Lu Cc: Szabolcs Nagy, Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Sat, May 09, 2015 at 10:41:41AM -0700, H.J. Lu wrote: > On Sat, May 9, 2015 at 7:31 AM, Szabolcs Nagy <nsz@port70.net> wrote: > > * H.J. Lu <hjl.tools@gmail.com> [2015-04-17 05:36:30 -0700]: > >> On Fri, Apr 17, 2015 at 4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: > >> > On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: > >> >> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in > >> >> > creating yet another library for that. > >> >> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead > >> >> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that > >> >> > static_name is always linked in, in the switch combinations that it isn't > >> >> > right now of course after shared_name rather than before that. > >> >> > I thought we've fixed that years ago... > >> >> > > > > > I think the patch committed for this is suboptimal. > > (it breaks with musl libc on x86 if libgcc_s is linked into a binary) > > > > the patch: > > http://gcc.gnu.org/ml/gcc-patches/2015-04/msg00878.html > > original thread: > > http://gcc.gnu.org/ml/gcc-patches/2015-03/msg01520.html > > > > The symbol versioning hack for __cpu_model and __cpu_indicator_init > > makes them invisible to the musl dynamic linker so their relocation > > fails with 'symbol not found' error. > > (affects anything linked with -lgcc_s) > > There are > > 4: 0000000000002b70 806 FUNC GLOBAL DEFAULT 12 > __cpu_indicator_init@GCC_4.8.0 > 38: 00000000002153d0 16 OBJECT GLOBAL DEFAULT 25 __cpu_model@GCC_4.8.0 > > and > > 000000000215000 0000000400000001 R_X86_64_64 > 0000000000002b70 __cpu_indicator_init@GCC_4.8.0 + 0 > 0000000000215220 0000002600000006 R_X86_64_GLOB_DAT > 00000000002153d0 __cpu_model@GCC_4.8.0 + 0 > > in libgcc_s.so.1. Musl ld.so must be fixed to handle it. The intent in musl was always not to support symbol versioning. There are various reasons for this, which I could go into, but I'd rather not turn this thread into an argument about the merits of symbol versioning. Originally, musl ignored the version data completely, and would happily have resolved the above symbol, but this also led to problems where third-party libraries used symbol versioning and at runtime we got the oldest-versioned symbol instead of the desired current one. So I changed the lookup to use the same logic as ld, rejecting all symbols with the hidden bit set, and getting us the newest one (which is the only one we intended to support). We can't just do the same version processing as glibc because we want symbols in libc itself to resolve regardless of the version in the reference (this is needed for the glibc ABI compat we provide). It might work to honor symbol versions only when the library being searched has versions, and otherwise allow symbols to match any version requested, but I haven't thought this through entirely yet. In any case I'd like the decision for what musl does about symbol versions (which are not intended to be supported, anyway) to be independent of libgcc's solution of this problem. We can solve it with a hack on our side (just providing dummy symbols by those names) but that's ugly too and I'd rather not do it. Could you clarify the reasoning for why libgcc is using this hack with a reference to an 'obsolete' symbol version rather than just visibility? Rich ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-05-09 19:36 ` Rich Felker @ 2015-05-09 19:54 ` Jakub Jelinek 0 siblings, 0 replies; 46+ messages in thread From: Jakub Jelinek @ 2015-05-09 19:54 UTC (permalink / raw) To: Rich Felker Cc: H.J. Lu, Szabolcs Nagy, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Sat, May 09, 2015 at 03:36:01PM -0400, Rich Felker wrote: > Could you clarify the reasoning for why libgcc is using this hack with > a reference to an 'obsolete' symbol version rather than just > visibility? Obviously for ABI compatibility reasons. Older programs could be relying on the symbols exported from libgcc_s.so.1 in the past. We need to keep those working, just don't want to allow linking new programs against this symbol (because new programs should get their copy from libgcc.a now). Jakub ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 12:36 ` H.J. Lu ` (2 preceding siblings ...) 2015-05-09 14:31 ` Szabolcs Nagy @ 2015-07-22 21:14 ` Sriraman Tallam 3 siblings, 0 replies; 46+ messages in thread From: Sriraman Tallam @ 2015-07-22 21:14 UTC (permalink / raw) To: H.J. Lu Cc: Jakub Jelinek, Uros Bizjak, Mike Stump, Jack Howarth, Ian Lance Taylor, GCC Patches, Iain Sandoe, Rainer Orth On Fri, Apr 17, 2015 at 5:36 AM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Fri, Apr 17, 2015 at 4:59 AM, Jakub Jelinek <jakub@redhat.com> wrote: >> On Fri, Apr 17, 2015 at 04:48:48AM -0700, H.J. Lu wrote: >>> > I don't like it. Nonshared libgcc is libgcc.a, period. No sense in >>> > creating yet another library for that. >>> > So, IMHO beyond making the __cpu* entrypoints compat symbols only (@ instead >>> > of @@ symbol versions) the right fix is simply tweak init_gcc_spec, so that >>> > static_name is always linked in, in the switch combinations that it isn't >>> > right now of course after shared_name rather than before that. >>> > I thought we've fixed that years ago... >>> > >>> >>> We never pass -lgcc to linker when building C++ DSO: >>> >>> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/collect2 -plugin >>> /usr/libexec/gcc/x86_64-redhat-linux/4.9.2/liblto_plugin.so >>> -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper >>> -plugin-opt=-fresolution=/tmp/ccZC7iqy.res >>> -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc >>> -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed >>> --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -shared >>> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crti.o >>> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtbeginS.o >>> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2 >>> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64 >>> -L/lib/../lib64 -L/usr/lib/../lib64 >>> -L/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../.. x.o -lstdc++ -lm >>> -lgcc_s -lc -lgcc_s /usr/lib/gcc/x86_64-redhat-linux/4.9.2/crtendS.o >>> /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../lib64/crtn.o >>> [hjl@gnu-32 tmp]$ >>> >>> That is why libgcc_nonshared.a is needed. >> >> See what I wrote. I think it is a bug that we don't do that, in your case >> we should pass -lgcc_s -lgcc -lc -lgcc_s -lgcc. >> Or, if you don't want to change that, as the multi-versioning change is >> i386/x86_64 only change, just ensure that those targets have >> t-slibgcc-libgcc in libgcc/config.host and thus behave like most other linux >> targets where -lgcc is linked in always after -lgcc_s. >> >> Jakub > > This patch works for me. OK for trunk? H.J: This patch assumes that libgcc.a is built with -fvisibility=hidden and __cpu_indicator_init is LOCAL to libgcc.a. We have a config where libgcc.a is not built with hidden visibility. Can we consider this additional patch to make this explicit, mark __cpu_indicator_init with hidden visiblity explicitly when not building shared object. --- config/i386/cpuinfo.c (revision 225800) +++ config/i386/cpuinfo.c (working copy) @@ -34,6 +34,9 @@ #endif int __cpu_indicator_init (void) +#if !defined(SHARED) +__attribute__ ((visibility("hidden"))) +#endif __attribute__ ((constructor CONSTRUCTOR_PRIORITY)); /* Get the specific type of AMD CPU. */ @@ -321,6 +324,9 @@ needs to be called explicitly there. */ int __attribute__ ((constructor CONSTRUCTOR_PRIORITY)) +#if !defined(SHARED) +__attribute__ ((visibility("hidden"))) +#endif __cpu_indicator_init (void) Also, gold and ld have an incompatibility with symbol versioning as discussed here: https://sourceware.org/bugzilla/show_bug.cgi?id=18703 H.J. suggested this nice fix to solve this problem where BFD ld is always used to build libgcc_s.so.1: You can pass -fuse-ld=bfd to build libgcc_s.so.1 on Linux: diff --git a/libgcc/config/i386/t-linux b/libgcc/config/i386/t-linux index 11bb46e..12aab16 100644 --- a/libgcc/config/i386/t-linux +++ b/libgcc/config/i386/t-linux @@ -3,4 +3,8 @@ # t-slibgcc-elf-ver and t-linux SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/i386/libgcc-glibc.ver +# Work around gold bug: +# https://sourceware.org/bugzilla/show_bug.cgi?id=18703 +SHLIB_LDFLAGS += -fuse-ld=bfd + HOST_LIBGCC2_CFLAGS += -mlong-double-80 -DUSE_ELF_SYMVER Thanks Sri > > 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 > * config.host (tmake_file): Add t-slibgcc-libgcc for Linux/x86. > * 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-linux (HOST_LIBGCC2_CFLAGS): Add > -DUSE_ELF_SYMVER. > > Thanks. > > -- > H.J. ^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE 2015-04-17 8:05 ` Uros Bizjak 2015-04-17 10:36 ` H.J. Lu @ 2015-04-17 12:23 ` Mike Stump 1 sibling, 0 replies; 46+ messages in thread From: Mike Stump @ 2015-04-17 12:23 UTC (permalink / raw) To: Uros Bizjak Cc: H.J. Lu, Jack Howarth, Ian Lance Taylor, Jakub Jelinek, GCC Patches, Iain Sandoe, Rainer Orth On Apr 17, 2015, at 1:05 AM, Uros Bizjak <ubizjak@gmail.com> wrote: > On Thu, Apr 16, 2015 at 6:28 PM, Mike Stump <mikestump@comcast.net> wrote: >> On Apr 14, 2015, at 8:07 AM, H.J. Lu <hjl.tools@gmail.com> wrote: >>>> I can confirm that the most current patch bootstraps on >>>> x86_64-apple-darwin14 and that all of the new tests show up as >>>> unsupported in the test suite. >>>> Jack >>> >>> I am re-posting this patch. OK for trunk? >> >> If Jack is happy, I’m happy. :-) That leaves the x86 people to comment on it. > > What about Solaris? To be clear, I didn’t want to give the impression that my note was approval for the entire patch. If I said, darwin parts ok, I think that would have been clearer... ^ permalink raw reply [flat|nested] 46+ messages in thread
end of thread, other threads:[~2015-07-22 20:56 UTC | newest] Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-03-30 2:25 PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE H.J. Lu 2015-03-30 2:34 ` H.J. Lu 2015-03-30 2:40 ` H.J. Lu 2015-03-30 22:26 ` H.J. Lu 2015-03-31 0:54 ` Jack Howarth 2015-03-31 2:08 ` H.J. Lu 2015-03-31 2:42 ` H.J. Lu 2015-03-31 3:14 ` Jack Howarth 2015-03-31 3:09 ` Jack Howarth 2015-03-31 4:04 ` H.J. Lu 2015-03-31 5:39 ` Jakub Jelinek 2015-03-31 6:20 ` Rainer Orth 2015-03-31 10:39 ` H.J. Lu 2015-03-31 14:25 ` Jack Howarth 2015-03-31 15:58 ` H.J. Lu 2015-03-31 16:10 ` Jack Howarth 2015-03-31 16:15 ` H.J. Lu 2015-03-31 16:39 ` Jack Howarth 2015-03-31 17:00 ` H.J. Lu 2015-03-31 18:33 ` Jack Howarth 2015-04-14 15:07 ` H.J. Lu 2015-04-16 16:29 ` Mike Stump 2015-04-17 8:05 ` Uros Bizjak 2015-04-17 10:36 ` H.J. Lu 2015-04-17 11:04 ` Uros Bizjak 2015-04-17 11:12 ` Uros Bizjak 2015-04-17 11:38 ` Jakub Jelinek 2015-04-17 11:48 ` H.J. Lu 2015-04-17 12:00 ` Jakub Jelinek 2015-04-17 12:36 ` H.J. Lu 2015-04-17 12:40 ` Jakub Jelinek 2015-05-08 23:00 ` Rich Felker 2015-05-08 23:59 ` H.J. Lu 2015-05-09 14:31 ` Szabolcs Nagy 2015-05-09 17:41 ` H.J. Lu 2015-05-09 18:57 ` Szabolcs Nagy 2015-05-11 10:20 ` Szabolcs Nagy 2015-05-11 10:32 ` Jakub Jelinek 2015-05-11 12:39 ` Szabolcs Nagy 2015-05-11 13:05 ` Jakub Jelinek 2015-05-11 15:30 ` Szabolcs Nagy 2015-05-11 14:12 ` Rich Felker 2015-05-09 19:36 ` Rich Felker 2015-05-09 19:54 ` Jakub Jelinek 2015-07-22 21:14 ` Sriraman Tallam 2015-04-17 12:23 ` Mike Stump
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).