loongson-community / discussions

Cross-community issue tracker & discussions / 跨社区工单追踪 & 讨论场所
11 stars 0 forks source link

[英雄贴] Binutils: Remove orphan GOT entries in relaxation #58

Open xry111 opened 4 months ago

xry111 commented 4 months ago

For

.p2align 2
f:
  la.got $a0, x
  ret

.data
.p2align 2
.globl x
.hidden x
x: .4byte 114514

The linker is able to relax la.got to la.pcrel or even pcaddi, but the GOT entry for x still exists.

Note that x86 BFD linker is able to remove the orphan GOT entry when relaxing movq to leaq in this example:

.data
x: .4byte 114514

.text
f:
movq x@GOTPCREL(%rip), %rax
ret
xry111 commented 4 months ago

Also note that if we remove

.globl x
.hidden x

from the test case, the relaxation still should happen but in reality it doesn't. It seems better to resolve both issues at once.

xen0n commented 1 week ago

More info: https://sourceware.org/pipermail/binutils/2024-November/137658.html