Bug 27178 - x86-64: Omit _GLOBAL_OFFSET_TABLE_ for call foo@PLT
Summary: x86-64: Omit _GLOBAL_OFFSET_TABLE_ for call foo@PLT
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: 2.37
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-13 04:19 UTC by Fangrui Song
Modified: 2021-04-19 12:24 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-*
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-01-13 04:19:29 UTC
echo 'call foo' > ./a.s
echo 'call foo@PLT' > ./b.s

gcc -c a.s b.s
% readelf -Ws a.o b.o

File: a.o

Symbol table '.symtab' contains 5 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo

File: b.o

Symbol table '.symtab' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
     4: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND _GLOBAL_OFFSET_TABLE_
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo


_GLOBAL_OFFSET_TABLE_ is not needed.
Comment 1 Sourceware Commits 2021-01-13 13:52:42 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=844bf810cf9feebe50772c29d72256ec3c872270

commit 844bf810cf9feebe50772c29d72256ec3c872270
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jan 13 05:42:11 2021 -0800

    x86: Don't generate GOT_symbol for PLT relocations
    
    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.
Comment 2 H.J. Lu 2021-01-13 14:06:14 UTC
Fixed for 2.37.
Comment 3 Jan Beulich 2021-04-18 14:51:36 UTC
Shouldn't some of the TLS relocs be similarly marked as not requiring GOT_symbol?
Comment 4 H.J. Lu 2021-04-19 12:24:08 UTC
(In reply to Jan Beulich from comment #3)
> Shouldn't some of the TLS relocs be similarly marked as not requiring
> GOT_symbol?

Maybe.