diff options
author | Lulu Cai <cailulu@loongson.cn> | 2024-02-23 16:28:22 +0800 |
---|---|---|
committer | liuzhensong <liuzhensong@loongson.cn> | 2024-03-06 14:47:03 +0800 |
commit | d5de762be734940049f1fc77d7b7bad2ee5f06f7 (patch) | |
tree | 2751d66407e51e23b1f601db0502d2d592568c12 /bfd/elfnn-loongarch.c | |
parent | 0e45942b2cad90e32c13b4c8c2c1aea9ba08c497 (diff) | |
download | binutils-d5de762be734940049f1fc77d7b7bad2ee5f06f7.zip binutils-d5de762be734940049f1fc77d7b7bad2ee5f06f7.tar.gz binutils-d5de762be734940049f1fc77d7b7bad2ee5f06f7.tar.bz2 |
LoongArch: Add dtpoff calculation function
When tls_sec is NULL, we should not access the virtual address
of tls_sec.
Diffstat (limited to 'bfd/elfnn-loongarch.c')
-rw-r--r-- | bfd/elfnn-loongarch.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 3cec041..ee99fd7 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -2550,6 +2550,16 @@ loongarch_reloc_is_fatal (struct bfd_link_info *info, }) +static bfd_vma +tls_dtpoff_base (struct bfd_link_info *info) +{ + /* If tls_sec is NULL, we should have signalled an error already. */ + if (elf_hash_table (info)->tls_sec == NULL) + return 0; + return elf_hash_table (info)->tls_sec->vma; +} + + static int loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, bfd *input_bfd, asection *input_section, @@ -3708,7 +3718,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, rela.r_offset = sec_addr (got) + got_off + desc_off; rela.r_addend = 0; if (indx == 0) - rela.r_addend = relocation - elf_hash_table (info)->tls_sec->vma; + rela.r_addend = relocation - tls_dtpoff_base (info); rela.r_info = ELFNN_R_INFO (indx, R_LARCH_TLS_DESCNN); loongarch_elf_append_rela (output_bfd, relgot, &rela); |