From 9a33a0b9c65e587c3142600571f59efb25c973f9 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Fri, 16 Aug 2024 11:28:10 +0800 Subject: Not append rela for absolute symbol LoongArch: Not append rela for absolute symbol Use la.global to get absolute symbol like la.abs. la.global put address of a global symbol into a got entry and append a rela for it, which will be used to relocate by dynamic linker. Dynamic linker should not relocate for got entry of absolute symbol as it stores symval not symbol's address. --- ld/testsuite/ld-loongarch-elf/abs-global.out | 1 + ld/testsuite/ld-loongarch-elf/abs-global.s | 5 +++++ ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c | 7 +++++++ ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 12 ++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 ld/testsuite/ld-loongarch-elf/abs-global.out create mode 100644 ld/testsuite/ld-loongarch-elf/abs-global.s create mode 100644 ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c (limited to 'ld') diff --git a/ld/testsuite/ld-loongarch-elf/abs-global.out b/ld/testsuite/ld-loongarch-elf/abs-global.out new file mode 100644 index 0000000..3656652 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abs-global.out @@ -0,0 +1 @@ +abba diff --git a/ld/testsuite/ld-loongarch-elf/abs-global.s b/ld/testsuite/ld-loongarch-elf/abs-global.s new file mode 100644 index 0000000..93a5da6 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/abs-global.s @@ -0,0 +1,5 @@ +.text +.globl get_sym +get_sym: + la.global $a0, sym + ret diff --git a/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c b/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c new file mode 100644 index 0000000..29781ad --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/get_abs_global_sym.c @@ -0,0 +1,7 @@ +#include + +extern int get_sym(); +int main() { + printf("%x\n", get_sym()); + return 0; +} diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp index 4328f6e..6bef97c2 100644 --- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp @@ -130,6 +130,18 @@ if [istarget "loongarch64-*-*"] { "a.binary" \ ] \ ] + + + run_ld_link_exec_tests [list \ + [list \ + "get global abs symbol test" \ + "-Wl,-z norelro -Wl,--defsym sym=0xabba" \ + "" \ + { abs-global.s get_abs_global_sym.c} \ + "abs-global" \ + "abs-global.out" \ + ] \ + ] } if [istarget "loongarch64-*-*"] { -- cgit v1.1