aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfnn-loongarch.c
diff options
context:
space:
mode:
authorLulu Cai <cailulu@loongson.cn>2024-03-19 17:51:19 +0800
committerliuzhensong <liuzhensong@loongson.cn>2024-04-25 09:21:26 +0800
commit66156bae7a0581879763514382d112716464db8a (patch)
tree41141ce7665dab0e3478cd7b4467156d1ab739a9 /bfd/elfnn-loongarch.c
parentb221bff7c7ca20d961a7e6b663a545384054a5be (diff)
downloadgdb-66156bae7a0581879763514382d112716464db8a.zip
gdb-66156bae7a0581879763514382d112716464db8a.tar.gz
gdb-66156bae7a0581879763514382d112716464db8a.tar.bz2
LoongArch: Add bad static relocation check and output more information to user
Absolute address symbols cannot be used with -shared. We output more information to the user than just BFD_ASSETR.
Diffstat (limited to 'bfd/elfnn-loongarch.c')
-rw-r--r--bfd/elfnn-loongarch.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index fe780e3..4761ee1 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -761,6 +761,33 @@ loongarch_tls_transition (bfd *input_bfd,
table. */
static bool
+bad_static_reloc (bfd *abfd, const Elf_Internal_Rela *rel, asection *sec,
+ unsigned r_type, struct elf_link_hash_entry *h,
+ Elf_Internal_Sym *isym)
+{
+ /* We propably can improve the information to tell users that they should
+ be recompile the code with -fPIC or -fPIE, just like what x86 does. */
+ reloc_howto_type * r = loongarch_elf_rtype_to_howto (abfd, r_type);
+ const char *name = NULL;
+
+ if (h)
+ name = h->root.root.string;
+ else if (isym)
+ name = bfd_elf_string_from_elf_section (abfd,
+ elf_symtab_hdr (abfd).sh_link,
+ isym->st_name);
+ if (name == NULL || *name == '\0')
+ name ="<nameless>";
+
+ (*_bfd_error_handler)
+ (_("%pB:(%pA+%#lx): relocation %s against `%s` can not be used when making "
+ "a shared object; recompile with -fPIC"),
+ abfd, sec, rel->r_offset, r ? r->name : _("<unknown>"), name);
+ bfd_set_error (bfd_error_bad_value);
+ return false;
+}
+
+static bool
loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
asection *sec, const Elf_Internal_Rela *relocs)
{
@@ -904,7 +931,7 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
case R_LARCH_TLS_LE_HI20_R:
case R_LARCH_SOP_PUSH_TLS_TPREL:
if (!bfd_link_executable (info))
- return false;
+ return bad_static_reloc (abfd, rel, sec, r_type, h, isym);
if (!loongarch_elf_record_tls_and_got_reference (abfd, info, h,
r_symndx,
@@ -922,6 +949,9 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
case R_LARCH_ABS_HI20:
case R_LARCH_SOP_PUSH_ABSOLUTE:
+ if (bfd_link_pic (info))
+ return bad_static_reloc (abfd, rel, sec, r_type, h, isym);
+
if (h != NULL)
/* If this reloc is in a read-only section, we might
need a copy reloc. We can't check reliably at this
@@ -3398,7 +3428,6 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
case R_LARCH_ABS_LO12:
case R_LARCH_ABS64_LO20:
case R_LARCH_ABS64_HI12:
- BFD_ASSERT (!is_pic);
if (is_undefweak)
{