public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Jack Howarth <howarth.at.gcc@gmail.com>
Cc: Ian Lance Taylor <ian@airs.com>, Jakub Jelinek <jakub@redhat.com>,
		GCC Patches <gcc-patches@gcc.gnu.org>,
	Uros Bizjak <ubizjak@gmail.com>,
		Iain Sandoe <iain@codesourcery.com>,
	Mike Stump <mikestump@comcast.net>
Subject: Re: PATCH] PR target/65612: Multiversioning doesn't work with DSO nor PIE
Date: Tue, 14 Apr 2015 15:07:00 -0000	[thread overview]
Message-ID: <CAMe9rOpj-nx=eYzLD9gjy4tVuUbbii8nx0pzM8ynWEvK+WLPLA@mail.gmail.com> (raw)
In-Reply-To: <CAJMcOU9hcqopdDfpYbP5d=JLVVLUMnvqZWPQt14kH3T6DgVB8w@mail.gmail.com>

[-- 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


  reply	other threads:[~2015-04-14 15:07 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30  2:25 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOpj-nx=eYzLD9gjy4tVuUbbii8nx0pzM8ynWEvK+WLPLA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=howarth.at.gcc@gmail.com \
    --cc=iain@codesourcery.com \
    --cc=ian@airs.com \
    --cc=jakub@redhat.com \
    --cc=mikestump@comcast.net \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).