Bug 31047 - relocation R_X86_64_NONE against absolute symbol `__dtrace_test_prov___place' in section `.text.startup' is disallowed
Summary: relocation R_X86_64_NONE against absolute symbol `__dtrace_test_prov___place'...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.42
: P2 normal
Target Milestone: 2.42
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-08 15:06 UTC by Kris Van Hees
Modified: 2024-01-09 14:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2024-01-08 00:00:00
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kris Van Hees 2023-11-08 15:06:41 UTC
We ran into a problem with how DTrace processes relocations to determine the
location of probe points in an ELF object.  USDT probe points are just calls
to (undefined) functions of a specific name, and when we process the ELF object
we look for relocations to such symbols.  We patch the text for the function
at the call site with NOPs, and generate meta-data for this probe in a
separate ELF object.  We then change the type of the reloc to be R_X86_64_NONE,
so that it will be ignored when the ELF object is linked into its target (so
the linker won't overwrite our carefully placed NOPs).

The reason why we don't just remove the reloc is that sometimes builds end
up re-processing the ELF object and we want it to be able to regenerate the
meta-data for the probes in that case.

This does not work on x86 with PIC/PIE because the relocation validation in
382aae063227 ("x86: Only allow S + A relocations against absolute symbol") is
not allowing R_X86_64_NONE relocations even though they have no functional
purpose, i.e. they should be ignored.

I realize that the use of the relocation type R_X86_64_NONE is perhaps a bit
unusual but it does support the need here in a quite elegant manner.

It would seem that allowing R_X86_64_NONE (and R_386_NONE) relocations in bfd_elf_x86_valid_reloc_p() would be the correct action?
Comment 1 H.J. Lu 2024-01-08 15:17:36 UTC
Is it possible to create a testcase? A binary object is OK.
Comment 2 H.J. Lu 2024-01-08 15:42:14 UTC
(In reply to H.J. Lu from comment #1)
> Is it possible to create a testcase? A binary object is OK.

If R_386_NONE is also impacted, please also provide such a testcase.
Comment 3 H.J. Lu 2024-01-09 14:12:03 UTC
[hjl@gnu-cfl-3 pr31047]$ cat x.s 
	.text
	.globl _start
_start:
	.nop
	.reloc 0, BFD_RELOC_NONE, foo
	.section .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-3 pr31047]$ cat y.s
	.globl foo
	foo = 0x1000
	.section .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-3 pr31047]$ make
as   -o y.o y.s
as   -o x.o x.s
./ld -pie -o x y.o x.o
./ld: x.o: relocation R_X86_64_NONE against absolute symbol `foo' in section `.text' is disallowed
make: *** [Makefile:13: x] Error 1
Comment 4 Sourceware Commits 2024-01-09 14:43:22 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=2e93abb858ae4ff2b8605b4a94988068869c0ff1

commit 2e93abb858ae4ff2b8605b4a94988068869c0ff1
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jan 9 06:30:28 2024 -0800

    x86: Don't check R_386_NONE nor R_X86_64_NONE
    
    Update x86 ELF linker to skip R_386_NONE/R_X86_64_NONE when scanning
    relocations.
    
    bfd/
    
            * PR ld/31047
            * elf32-i386.c (elf_i386_scan_relocs): Don't check R_386_NONE.
            * elf64-x86-64.c (elf_x86_64_scan_relocs): Don't check
            R_X86_64_NONE.
    
    ld/
    
            * PR ld/31047
            * testsuite/ld-i386/i386.exp: Run PR ld/31047 test.
            * testsuite/ld-x86-64/x86-64.exp: Likewise.
            * testsuite/ld-i386/pr31047.d: New file.
            * testsuite/ld-x86-64/pr31047-x32.d: Likewise.
            * testsuite/ld-x86-64/pr31047.d: Likewise.
            * testsuite/ld-x86-64/pr31047a.s: Likewise.
            * testsuite/ld-x86-64/pr31047b.s: Likewise.
Comment 5 H.J. Lu 2024-01-09 14:44:36 UTC
Fixed for 2.42.