Hide __cpu_indicator_init/__cpu_model from linker
authorH.J. Lu <hongjiu.lu@intel.com>
Fri, 17 Apr 2015 12:58:07 +0000 (12:58 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Fri, 17 Apr 2015 12:58:07 +0000 (05:58 -0700)
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.

From-SVN: r222178

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/mv18.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/mv19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/mv20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/mv21.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/mv22.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/mv23.C [new file with mode: 0644]
libgcc/ChangeLog
libgcc/config.host
libgcc/config/i386/cpuinfo.c
libgcc/config/i386/t-linux

index 1f9f1d4e03cc1cc34ca8affec0d625ec49fe25ea..e7b30489c7f2a912025e2df849c2c80fdbfe49d8 100644 (file)
@@ -1,3 +1,13 @@
+2015-04-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2015-04-17  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/64527
diff --git a/gcc/testsuite/g++.dg/ext/mv18.C b/gcc/testsuite/g++.dg/ext/mv18.C
new file mode 100644 (file)
index 0000000..1f024de
--- /dev/null
@@ -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 (file)
index 0000000..d1ea788
--- /dev/null
@@ -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 (file)
index 0000000..98f7408
--- /dev/null
@@ -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 (file)
index 0000000..9708ad9
--- /dev/null
@@ -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 (file)
index 0000000..2550136
--- /dev/null
@@ -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 (file)
index 0000000..f00afb0
--- /dev/null
@@ -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"
index a21afe86fc51c118c22779f8cb930ca4081bb366..862608f6380a47e290d457bd337b7e93b5aa95a4 100644 (file)
@@ -1,3 +1,13 @@
+2015-04-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2015-04-16  Nick Clifton  <nickc@redhat.com>
 
        * config/rl78/divmodhi.S: Add G14 and G13 versions of the __divhi3
index 4b158958fafcf3c0439a00ec6461e2cfd020b874..ce14b9ee6254a9b77c664f8d93824e6d9f22fb50 100644 (file)
@@ -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
index eaf2f100d59c050db91700e0e9f5e78761bd0782..f6f91ddce6a3704097cd0a0b3b4ebc52b0a8abab 100644 (file)
@@ -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
index 4f47f7bfa59cfbe99372aa349c340c7b07c96b14..11bb46e0ee4f8e5555c69c6cd6b31b51ce7345f2 100644 (file)
@@ -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