public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] i386: Load external function address via GOT slot
@ 2019-01-22 13:41 H.J. Lu
  2019-01-22 13:57 ` Uros Bizjak
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2019-01-22 13:41 UTC (permalink / raw)
  To: gcc-patches; +Cc: Uros Bizjak

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.
---
 gcc/config/i386/i386.c                    |  6 +++++-
 gcc/testsuite/gcc.target/i386/pr88954-1.c | 15 +++++++++++++++
 gcc/testsuite/gcc.target/i386/pr88954-2.c | 16 ++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88954-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr88954-2.c

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8abff99cc62..9ca5596c4af 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -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));
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/pr88954-1.c b/gcc/testsuite/gcc.target/i386/pr88954-1.c
new file mode 100644
index 00000000000..69cb940ae4f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88954-1.c
@@ -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
index 00000000000..3bc4ee47bae
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88954-2.c
@@ -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 } } } } */
-- 
2.20.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] i386: Load external function address via GOT slot
  2019-01-22 13:41 [PATCH] i386: Load external function address via GOT slot H.J. Lu
@ 2019-01-22 13:57 ` Uros Bizjak
  0 siblings, 0 replies; 2+ messages in thread
From: Uros Bizjak @ 2019-01-22 13:57 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

On Tue, Jan 22, 2019 at 2:41 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> 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.

LGTM.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.c                    |  6 +++++-
>  gcc/testsuite/gcc.target/i386/pr88954-1.c | 15 +++++++++++++++
>  gcc/testsuite/gcc.target/i386/pr88954-2.c | 16 ++++++++++++++++
>  3 files changed, 36 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr88954-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr88954-2.c
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 8abff99cc62..9ca5596c4af 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -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));
>  }
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr88954-1.c b/gcc/testsuite/gcc.target/i386/pr88954-1.c
> new file mode 100644
> index 00000000000..69cb940ae4f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr88954-1.c
> @@ -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
> index 00000000000..3bc4ee47bae
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr88954-2.c
> @@ -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 } } } } */
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-22 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-22 13:41 [PATCH] i386: Load external function address via GOT slot H.J. Lu
2019-01-22 13:57 ` Uros Bizjak

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).