Bug 30788 - gas aarch64: GOT relocations referencing a local symbol should not be changed to reference STT_SECTION
Summary: gas aarch64: GOT relocations referencing a local symbol should not be changed...
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-23 03:33 UTC by Fangrui Song
Modified: 2024-02-21 04:27 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2023-08-23 03:33:47 UTC
Extracted from https://github.com/llvm/llvm-project/issues/63418

```
cat > a.s <<EOF
ldr     x1, [x1, :got_lo12:x]  // converted to .data+0
ldr     x1, [x1, :got_lo12:y]  // converted to .data+4

.data
// .globl x, y  would suppress STT_SECTION conversion
x:
.zero 4
y:
.long 42
aarch64-linux-gnu-gcc -c a.s
```

The two R_AARCH64_LD64_GOT_LO12_NC relocations are converted to reference the STT_SECTION symbol .data .
After linking, they will share the same GOT entry (GNU ld and ld.lld use just the symbol to decide an entry, not symbol plus addend), which is not expected.

I think this is a neglection for AArch64. For most targets (including AArch32,
x86, PowerPC, and RISC-V) local symbol to STT_SECTION conversion is suppressed
for GOT-generating relocations.

https://github.com/ARM-software/abi-aa/issues/217 is created to decide how we should create GOT entries, GDAT(S+A) vs GDAT(S).
If the decision is to respect existing linker behaviors and allow the same GOT entry for :got_lo12:(.data+0) and :got_lo12:(.data+4),
this assembler change is IMO a prerequisite.