https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120002
Bug ID: 120002
Summary: R_AARCH64_ABS64 emitted against hidden symbol
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Relocations against involving hidden symbols should be PC-relative.
However on aarch64 with -mcmodel=tiny an absolute relocation may be emitted if
the offset to the symbol exceeds 64KiB.
Reproducer:
$ cat test.c
extern char hidden_symbol[] __attribute__((visibility("hidden")));
void *function(void)
{
void *ptr;
ptr = &hidden_symbol;
/* Works until 64 * 1024 */
ptr += 64 * 1024 + 1;
return ptr;
}
$ aarch64-linux-gnu-gcc test.c -c -o test.o -mcmodel=tiny -O2
$ aarch64-linux-gnu-objdump --section .text --disassemble-all
--disassemble-zeroes --reloc test.o
test.o: file format elf64-littleaarch64
Disassembly of section .text:
0000000000000000 <function>:
0: 58000040 ldr x0, 8 <function+0x8>
4: d65f03c0 ret
8: 00000000 udf #0
8: R_AARCH64_ABS64 hidden_symbol+0x10001
c: 00000000 udf #0
Background:
This setup is used in the Linux vDSO to achieve completely position independent
code. Some recent refactors triggered this bug.
https://lore.kernel.org/lkml/aApGPAoctq_eoE2g@t14ultra/