diff options
author | Lulu Cai <cailulu@loongson.cn> | 2024-10-17 15:08:47 +0800 |
---|---|---|
committer | liuzhensong <liuzhensong@loongson.cn> | 2024-10-22 12:01:41 +0800 |
commit | 3790b9f7ff23857e44b58d4b710b1f014d956ef3 (patch) | |
tree | c4b4e813964b80d64ed31f6f0d2b371f614bb109 /gas/testsuite | |
parent | Automatic date update in version.in (diff) | |
download | binutils-gdb-3790b9f7ff23857e44b58d4b710b1f014d956ef3.tar.gz binutils-gdb-3790b9f7ff23857e44b58d4b710b1f014d956ef3.tar.bz2 binutils-gdb-3790b9f7ff23857e44b58d4b710b1f014d956ef3.zip |
LoongArch: Force relocation for every reference to the global offset table
Local absolute symbols are resolved at assembly stage and the symbol
value is placed in the relocation addend. But non-zero addend will
cause an assertion failure during linking.
Forces emission of relocations to defer resolution of local abs symbols
until link time.
bfd/
* elfnn-loongarch.c (loongarch_elf_relax_section): Determine
absolute symbols in advance to avoid ld crash.
gas/
* config/tc-loongarch.c (loongarch_force_relocation): New
function to force relocation.
* config/tc-loongarch.h (TC_FORCE_RELOCATION): New macros
to force relocation.
(loongarch_force_relocation): Function declaration.
* testsuite/gas/loongarch/localpic.d: New test.
* testsuite/gas/loongarch/localpic.s: New test.
Diffstat (limited to 'gas/testsuite')
-rw-r--r-- | gas/testsuite/gas/loongarch/localpic.d | 22 | ||||
-rw-r--r-- | gas/testsuite/gas/loongarch/localpic.s | 26 |
2 files changed, 48 insertions, 0 deletions
diff --git a/gas/testsuite/gas/loongarch/localpic.d b/gas/testsuite/gas/loongarch/localpic.d new file mode 100644 index 00000000000..bea1957818b --- /dev/null +++ b/gas/testsuite/gas/loongarch/localpic.d @@ -0,0 +1,22 @@ +#as: +#readelf: -rWs +#name: loongarch64 local PIC + +Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 12 entries: + Offset Info Type Symbol's Value Symbol's Name \+ Addend +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_PC_HI20 [0-9a-f]+ sym \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_PC_LO12 [0-9a-f]+ sym \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_PC_HI20 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_PC_LO12 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT64_PC_LO20 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT64_PC_HI12 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_HI20 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_LO12 [0-9a-f]+ foo \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_HI20 [0-9a-f]+ sym \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT_LO12 [0-9a-f]+ sym \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT64_LO20 [0-9a-f]+ sym \+ 0 +[0-9a-f]+ [0-9a-f]+ R_LARCH_GOT64_HI12 [0-9a-f]+ sym \+ 0 +#... + +[0-9a-f]+: +[0-9a-f]+ 0 NOTYPE LOCAL DEFAULT +[0-9a-f]+ foo + +[0-9a-f]+: 0+abba 0 NOTYPE LOCAL DEFAULT ABS sym +#pass diff --git a/gas/testsuite/gas/loongarch/localpic.s b/gas/testsuite/gas/loongarch/localpic.s new file mode 100644 index 00000000000..55548e4b62d --- /dev/null +++ b/gas/testsuite/gas/loongarch/localpic.s @@ -0,0 +1,26 @@ +.text +foo: + .quad 0 + # 32-bit PC-relative + pcalau12i $a0,%got_pc_hi20(sym) + ld.d $a0,$a0,%got_pc_lo12(sym) + # 64-bit PC-relative + pcalau12i $a0,%got_pc_hi20(foo) + addi.d $a1,$zero,%got_pc_lo12(foo) + lu32i.d $a1,%got64_pc_lo20(foo) + lu52i.d $a1,$a1,%got64_pc_hi12(foo) + ldx.d $a0,$a0,$a1 + + # 32-bit absolute + lu12i.w $a0,%got_hi20(foo) + ori $a0,$a0,%got_lo12(foo) + ld.w $a0,$a0,0 + + #64-bit absolute + lu12i.w $a0,%got_hi20(sym) + ori $a0,$a0,%got_lo12(sym) + lu32i.d $a0,%got64_lo20(sym) + lu52i.d $a0,$a0,%got64_hi12(sym) + ld.d $a0,$a0,0 + +.set sym,0xabba |