[PATCH] Not append rela for abs_symbol
Xin Wang
yw987194828@gmail.com
Thu Aug 15 06:12:42 GMT 2024
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 got 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.
Signed-off-by: Xin Wang <wangxin03@loongson.cn>
---
bfd/elfnn-loongarch.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 0d3a3919038..857826a58d0 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -4132,6 +4132,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (is_dyn,
bfd_link_pic (info),
h)
+ && !bfd_is_abs_section(h->root.u.def.section)
&& bfd_link_pic (info)
&& LARCH_REF_LOCAL (info, h))
{
@@ -4153,7 +4154,8 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
&& local_got_offsets[r_symndx] != MINUS_ONE);
got_off = local_got_offsets[r_symndx] & (~(bfd_vma)1);
- if ((local_got_offsets[r_symndx] & 1) == 0)
+ if (sym->st_shndx != SHN_ABS
+ && (local_got_offsets[r_symndx] & 1) == 0)
{
if (bfd_link_pic (info) && !info->enable_dt_relr)
{
@@ -5301,6 +5303,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
bfd_vma symval;
asection *sym_sec;
bool local_got = false;
+ bool is_abs_symbol = false;
Elf_Internal_Rela *rel = relocs + i;
struct elf_link_hash_entry *h = NULL;
unsigned long r_type = ELFNN_R_TYPE (rel->r_info);
@@ -5482,7 +5485,18 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
break;
case R_LARCH_GOT_PC_HI20:
+ if (h)
+ is_abs_symbol = bfd_is_abs_section(h->root.u.def.section);
+ else
+ {
+ Elf_Internal_Sym *sym = (Elf_Internal_Sym *)symtab_hdr->contents
+ + ELFNN_R_SYM (rel->r_info);
+ is_abs_symbol = sym->st_shndx == SHN_ABS;
+ }
if (local_got && 0 == info->relax_pass
+ // We can not change the r_type which will be
+ // needed when relocate for absolute symbol.
+ && !is_abs_symbol
&& (i + 4) <= sec->reloc_count)
{
if (loongarch_relax_pcala_ld (abfd, sec, rel))
--
2.33.0
More information about the Binutils
mailing list