x86: Don't generate GOT_symbol for PLT relocations
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 13 Jan 2021 13:42:11 +0000 (05:42 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 13 Jan 2021 13:42:27 +0000 (05:42 -0800)
Don't generate the _GLOBAL_OFFSET_TABLE_ symbol for PLT relocations
since it isn't needed.

PR gas/27178
* config/tc-i386.c (lex_got::gotrel): Add need_GOT_symbol.
Don't generate GOT_symbol for PLT relocations.
* testsuite/gas/i386/i386.exp: Run PR gas/27178 tests.
* testsuite/gas/i386/no-got.d: New file.
* testsuite/gas/i386/no-got.s: Likewise.
* testsuite/gas/i386/x86-64-no-got.d: Likewise.
* testsuite/gas/i386/x86-64-no-got.s: Likewise.

gas/ChangeLog
gas/config/tc-i386.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/no-got.d [new file with mode: 0644]
gas/testsuite/gas/i386/no-got.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-no-got.d [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-no-got.s [new file with mode: 0644]

index 15374feda62b337e7833477e847d541f45ee7412..bad8473bf6699c616460ce64327023c9681e6f2d 100644 (file)
@@ -1,3 +1,14 @@
+2021-01-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR gas/27178
+       * config/tc-i386.c (lex_got::gotrel): Add need_GOT_symbol.
+       Don't generate GOT_symbol for PLT relocations.
+       * testsuite/gas/i386/i386.exp: Run PR gas/27178 tests.
+       * testsuite/gas/i386/no-got.d: New file.
+       * testsuite/gas/i386/no-got.s: Likewise.
+       * testsuite/gas/i386/x86-64-no-got.d: Likewise.
+       * testsuite/gas/i386/x86-64-no-got.s: Likewise.
+
 2021-01-13  Alan Modra  <amodra@gmail.com>
 
        * Makefile.in: Regenerate.
index 9a2dfc92281127df460d3dc4d3f1bca8e1db30dd..a7d2ff1c1f91d0be837ed7dc9715d39e1ca8aa04 100644 (file)
@@ -10018,63 +10018,64 @@ lex_got (enum bfd_reloc_code_real *rel,
     int len;
     const enum bfd_reloc_code_real rel[2];
     const i386_operand_type types64;
+    bfd_boolean need_GOT_symbol;
   } gotrel[] = {
 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
     { STRING_COMMA_LEN ("SIZE"),      { BFD_RELOC_SIZE32,
                                        BFD_RELOC_SIZE32 },
-      OPERAND_TYPE_IMM32_64 },
+      OPERAND_TYPE_IMM32_64, FALSE },
 #endif
     { STRING_COMMA_LEN ("PLTOFF"),   { _dummy_first_bfd_reloc_code_real,
                                       BFD_RELOC_X86_64_PLTOFF64 },
-      OPERAND_TYPE_IMM64 },
+      OPERAND_TYPE_IMM64, TRUE },
     { STRING_COMMA_LEN ("PLT"),      { BFD_RELOC_386_PLT32,
                                       BFD_RELOC_X86_64_PLT32    },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, FALSE },
     { STRING_COMMA_LEN ("GOTPLT"),   { _dummy_first_bfd_reloc_code_real,
                                       BFD_RELOC_X86_64_GOTPLT64 },
-      OPERAND_TYPE_IMM64_DISP64 },
+      OPERAND_TYPE_IMM64_DISP64, TRUE },
     { STRING_COMMA_LEN ("GOTOFF"),   { BFD_RELOC_386_GOTOFF,
                                       BFD_RELOC_X86_64_GOTOFF64 },
-      OPERAND_TYPE_IMM64_DISP64 },
+      OPERAND_TYPE_IMM64_DISP64, TRUE },
     { STRING_COMMA_LEN ("GOTPCREL"), { _dummy_first_bfd_reloc_code_real,
                                       BFD_RELOC_X86_64_GOTPCREL },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
     { STRING_COMMA_LEN ("TLSGD"),    { BFD_RELOC_386_TLS_GD,
                                       BFD_RELOC_X86_64_TLSGD    },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
     { STRING_COMMA_LEN ("TLSLDM"),   { BFD_RELOC_386_TLS_LDM,
                                       _dummy_first_bfd_reloc_code_real },
-      OPERAND_TYPE_NONE },
+      OPERAND_TYPE_NONE, TRUE },
     { STRING_COMMA_LEN ("TLSLD"),    { _dummy_first_bfd_reloc_code_real,
                                       BFD_RELOC_X86_64_TLSLD    },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
     { STRING_COMMA_LEN ("GOTTPOFF"), { BFD_RELOC_386_TLS_IE_32,
                                       BFD_RELOC_X86_64_GOTTPOFF },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
     { STRING_COMMA_LEN ("TPOFF"),    { BFD_RELOC_386_TLS_LE_32,
                                       BFD_RELOC_X86_64_TPOFF32  },
-      OPERAND_TYPE_IMM32_32S_64_DISP32_64 },
+      OPERAND_TYPE_IMM32_32S_64_DISP32_64, TRUE },
     { STRING_COMMA_LEN ("NTPOFF"),   { BFD_RELOC_386_TLS_LE,
                                       _dummy_first_bfd_reloc_code_real },
-      OPERAND_TYPE_NONE },
+      OPERAND_TYPE_NONE, TRUE },
     { STRING_COMMA_LEN ("DTPOFF"),   { BFD_RELOC_386_TLS_LDO_32,
                                       BFD_RELOC_X86_64_DTPOFF32 },
-      OPERAND_TYPE_IMM32_32S_64_DISP32_64 },
+      OPERAND_TYPE_IMM32_32S_64_DISP32_64, TRUE },
     { STRING_COMMA_LEN ("GOTNTPOFF"),{ BFD_RELOC_386_TLS_GOTIE,
                                       _dummy_first_bfd_reloc_code_real },
-      OPERAND_TYPE_NONE },
+      OPERAND_TYPE_NONE, TRUE },
     { STRING_COMMA_LEN ("INDNTPOFF"),{ BFD_RELOC_386_TLS_IE,
                                       _dummy_first_bfd_reloc_code_real },
-      OPERAND_TYPE_NONE },
+      OPERAND_TYPE_NONE, TRUE },
     { STRING_COMMA_LEN ("GOT"),      { BFD_RELOC_386_GOT32,
                                       BFD_RELOC_X86_64_GOT32    },
-      OPERAND_TYPE_IMM32_32S_64_DISP32 },
+      OPERAND_TYPE_IMM32_32S_64_DISP32, TRUE },
     { STRING_COMMA_LEN ("TLSDESC"),  { BFD_RELOC_386_TLS_GOTDESC,
                                       BFD_RELOC_X86_64_GOTPC32_TLSDESC },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
     { STRING_COMMA_LEN ("TLSCALL"),  { BFD_RELOC_386_TLS_DESC_CALL,
                                       BFD_RELOC_X86_64_TLSDESC_CALL },
-      OPERAND_TYPE_IMM32_32S_DISP32 },
+      OPERAND_TYPE_IMM32_32S_DISP32, TRUE },
   };
   char *cp;
   unsigned int j;
@@ -10111,7 +10112,7 @@ lex_got (enum bfd_reloc_code_real *rel,
                    *types = gotrel[j].types64;
                }
 
-             if (j != 0 && GOT_symbol == NULL)
+             if (gotrel[j].need_GOT_symbol && GOT_symbol == NULL)
                GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
 
              /* The length of the first part of our input line.  */
index 3b8a734e7b62d7e5a20023c4635b40d049c59e5b..c9bca8ab215bca65e0be3c917ee5423f69d2c6ef 100644 (file)
@@ -645,6 +645,8 @@ if [gas_32_check] then {
        run_dump_test "got"
        run_dump_test "got-no-relax"
 
+       run_dump_test "no-got"
+
        run_dump_test "addend"
        run_dump_test "nop-3"
        run_dump_test "nop-4"
@@ -1262,6 +1264,8 @@ if [gas_64_check] then {
        run_dump_test "x86-64-gotpcrel-no-relax"
        run_dump_test "x86-64-gotpcrel-2"
 
+       run_dump_test "x86-64-no-got"
+
        run_dump_test "x86-64-addend"
        run_dump_test "x86-64-nop-3"
        run_dump_test "x86-64-nop-4"
diff --git a/gas/testsuite/gas/i386/no-got.d b/gas/testsuite/gas/i386/no-got.d
new file mode 100644 (file)
index 0000000..3dac832
--- /dev/null
@@ -0,0 +1,17 @@
+#objdump: -drwt
+#name: i386 no-GOT
+
+.*: +file format .*
+
+SYMBOL TABLE:
+0+ g     F .text       00000000 foo
+0+         \*UND\*     00000000 bar
+
+
+
+Disassembly of section .text:
+
+0+ <foo>:
+ +[a-f0-9]+:   e9 fc ff ff ff          jmp    1 <foo\+0x1>     1: R_386_PLT32  bar
+ +[a-f0-9]+:   e8 fc ff ff ff          call   6 <foo\+0x6>     6: R_386_PLT32  bar
+#pass
diff --git a/gas/testsuite/gas/i386/no-got.s b/gas/testsuite/gas/i386/no-got.s
new file mode 100644 (file)
index 0000000..9ffad27
--- /dev/null
@@ -0,0 +1,5 @@
+       .global foo
+       .type foo, @function
+foo:
+       jmp bar@PLT
+       call bar@PLT
diff --git a/gas/testsuite/gas/i386/x86-64-no-got.d b/gas/testsuite/gas/i386/x86-64-no-got.d
new file mode 100644 (file)
index 0000000..f09f3b1
--- /dev/null
@@ -0,0 +1,17 @@
+#objdump: -drwt
+#name: x86-64 no-GOT
+
+.*: +file format .*
+
+SYMBOL TABLE:
+0+ g     F .text       0000000000000000 foo
+0+         \*UND\*     0000000000000000 bar
+
+
+
+Disassembly of section .text:
+
+0+ <foo>:
+ +[a-f0-9]+:   e9 00 00 00 00          jmp    5 <foo\+0x5>     1: R_X86_64_PLT32       bar-0x4
+ +[a-f0-9]+:   e8 00 00 00 00          call   a <foo\+0xa>     6: R_X86_64_PLT32       bar-0x4
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-no-got.s b/gas/testsuite/gas/i386/x86-64-no-got.s
new file mode 100644 (file)
index 0000000..9ffad27
--- /dev/null
@@ -0,0 +1,5 @@
+       .global foo
+       .type foo, @function
+foo:
+       jmp bar@PLT
+       call bar@PLT