Bug 30788

Summary: gas aarch64: GOT relocations referencing a local symbol should not be changed to reference STT_SECTION
Product: binutils Reporter: Fangrui Song <i>
Component: gasAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: nsz
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target: aarch64*-*
Build: Last reconfirmed:

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.