i386: Load external function address via GOT slot
authorH.J. Lu <hongjiu.lu@intel.com>
Tue, 22 Jan 2019 14:53:41 +0000 (14:53 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Tue, 22 Jan 2019 14:53:41 +0000 (06:53 -0800)
With noplt attribute, we load the external function address via the GOT
slot so that linker won't create an PLT entry for extern function address.

gcc/

PR target/88954
* config/i386/i386.c (ix86_force_load_from_GOT_p): Also check
noplt attribute.

gcc/testsuite/

PR target/88954
* gcc.target/i386/pr88954-1.c: New test.
* gcc.target/i386/pr88954-2.c: Likewise.

From-SVN: r268152

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr88954-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr88954-2.c [new file with mode: 0644]

index 2409e7f59a138916741065262f8d716822a84e7c..88c2e149f228ced90371ff79ff3d9211003fc6c4 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/88954
+       * config/i386/i386.c (ix86_force_load_from_GOT_p): Also check
+       noplt attribute.
+
 2019-01-22  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/88469
index 88557f26c44ca5b9036e6f098efc72313345d75b..7485a86d7d5cfd4a55c0d2bf6b5480d94a41576c 100644 (file)
@@ -15189,10 +15189,14 @@ ix86_force_load_from_GOT_p (rtx x)
 {
   return ((TARGET_64BIT || HAVE_AS_IX86_GOT32X)
          && !TARGET_PECOFF && !TARGET_MACHO
-         && !flag_plt && !flag_pic
+         && !flag_pic
          && ix86_cmodel != CM_LARGE
          && GET_CODE (x) == SYMBOL_REF
          && SYMBOL_REF_FUNCTION_P (x)
+         && (!flag_plt
+             || (SYMBOL_REF_DECL (x)
+                 && lookup_attribute ("noplt",
+                                      DECL_ATTRIBUTES (SYMBOL_REF_DECL (x)))))
          && !SYMBOL_REF_LOCAL_P (x));
 }
 
index 50705fe6bb08358bc91fc39d4fefab7d04647501..5fb19c473e18887ba131ff3a8e1e852c259eff32 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-22  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/88954
+       * gcc.target/i386/pr88954-1.c: New test.
+       * gcc.target/i386/pr88954-2.c: Likewise.
+
 2019-01-22  Richard Earnshaw  <rearnsha@arm.com>
 
        PR target/88469
diff --git a/gcc/testsuite/gcc.target/i386/pr88954-1.c b/gcc/testsuite/gcc.target/i386/pr88954-1.c
new file mode 100644 (file)
index 0000000..69cb940
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fno-pic -fplt" } */
+
+extern void bar (void) __attribute__((noplt));
+
+void *
+foo (void)
+{
+  return &bar;
+}
+
+/* { dg-final { scan-assembler "mov\(l|q\)\[ \t\]*bar@GOTPCREL" { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler "movl\[ \t\]*bar@GOT," { target { ia32 && got32x_reloc } } } } */
+/* { dg-final { scan-assembler-not "\(mov|lea\)\(l|q\)\[ \t\]*\(\\\$|\)bar," { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-not "\(mov|lea\)l\[ \t\]*\(\\\$|\)bar," { target { ia32 && got32x_reloc } } } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr88954-2.c b/gcc/testsuite/gcc.target/i386/pr88954-2.c
new file mode 100644 (file)
index 0000000..3bc4ee4
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fno-pic -fplt" } */
+
+extern void bar (void) __attribute__((noplt));
+extern void *p;
+
+void
+foo (void)
+{
+  p = &bar;
+}
+
+/* { dg-final { scan-assembler "mov\(l|q\)\[ \t\]*bar@GOTPCREL" { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler "movl\[ \t\]*bar@GOT," { target { ia32 && got32x_reloc } } } } */
+/* { dg-final { scan-assembler-not "mov\(l|q\)\[ \t\]*\\\$bar," { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-not "mov\(l|q\)\[ \t\]*\\\$bar," { target { ia32 && got32x_reloc } } } } */