Bug 25551 - R_X86_64_PLT32 referencing .L should not emit an outstanding relocation
Summary: R_X86_64_PLT32 referencing .L should not emit an outstanding relocation
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-13 19:29 UTC by Fangrui Song
Modified: 2020-02-14 12:13 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-02-13 19:29:26 UTC
Context: https://github.com/ClangBuiltLinux/linux/issues/872

	.section	.init.text,"ax",@progbits
	call	.Lprintk$local
                                        # -- End function
	.text
	.globl	printk                  # -- Begin function printk
	.type	printk,@function
printk:                                 # @printk
.Lprintk$local:
 ret


% as a.s -o a.o
% readelf -Wrs a.o

Relocation section '.rela.init.text' at offset 0x108 contains 1 entry:
     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
     0000000000000001  0000000500000004 R_X86_64_PLT32     0000000000000000 .Lprintk$local - 4
...
      5: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT    1 .Lprintk$local


Delete `.section	.init.text,"ax",@progbits`, and there will be no relocation.



R_X86_64_PC32 does not emit the relocation. call .Lprintk$local emits an R_X86_64_PC32 before:

    commit bd7ab16b4537788ad53521c45469a1bdae84ad4a
    Author: H.J. Lu <hjl.tools@gmail.com>
    Date:   Tue Feb 13 07:34:22 2018 -0800
    
        x86-64: Generate branch with PLT32 relocation



https://sourceware.org/ml/binutils/2020-02/msg00243.html should fix the bug.
Comment 1 Sourceware Commits 2020-02-13 22:09:15 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=292676c15a615b5a95bede9ee91004d3f7ee7dfd

commit 292676c15a615b5a95bede9ee91004d3f7ee7dfd
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Feb 13 13:44:17 2020 -0800

    x86: Resolve PLT32 reloc aganst local symbol to section
    
    Since PLT entry isn't needed for branch to local symbol, we can resolve
    R_386_PLT32/R_X86_64_PLT32 relocation aganst local symbol to section,
    similar to R_386_PC32/R_X86_64_PC32.
    
    2020-02-13  Fangrui Song   <maskray@google.com>
    	    H.J. Lu  <hongjiu.lu@intel.com>
    
    	PR gas/25551
    	* config/tc-i386.c (tc_i386_fix_adjustable): Don't check
    	BFD_RELOC_386_PLT32 nor BFD_RELOC_X86_64_PLT32.
    	* testsuite/gas/i386/i386.exp: Run relax-5 and x86-64-relax-4.
    	* testsuite/gas/i386/relax-5.d: New file.
    	* testsuite/gas/i386/relax-5.s: Likewise.
    	* testsuite/gas/i386/x86-64-relax-4.d: Likewise.
    	* testsuite/gas/i386/x86-64-relax-4.s: Likewise.
Comment 2 H.J. Lu 2020-02-14 12:13:39 UTC
Fixed for 2.35.