PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
Alan Modra
amodra@gmail.com
Tue Apr 2 08:55:18 GMT 2024
This is HJ's patch fixing a mips bug, tidied a little.
PR 31458
bfd/
* elf-bfd.h (_bfd_elf_link_read_relocs),
(_bfd_elf_link_info_read_relocs): Constify section.
* elflink.c: Likewise.
* elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read
relocs again in case --no-keep-memory.
ld/
* testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory
version of eh-frame3 test.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 7ad171d5000..29283f24895 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2592,9 +2592,9 @@ extern char *_bfd_elfcore_strndup
(bfd *, char *, size_t);
extern Elf_Internal_Rela *_bfd_elf_link_read_relocs
- (bfd *, asection *, void *, Elf_Internal_Rela *, bool);
+ (bfd *, const asection *, void *, Elf_Internal_Rela *, bool);
extern Elf_Internal_Rela *_bfd_elf_link_info_read_relocs
- (bfd *, struct bfd_link_info *, asection *, void *, Elf_Internal_Rela *,
+ (bfd *, struct bfd_link_info *, const asection *, void *, Elf_Internal_Rela *,
bool);
extern bool _bfd_elf_link_output_relocs
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 37a61b7cd31..e9cef470333 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2649,7 +2649,7 @@ _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data)
static bool
elf_link_read_relocs_from_section (bfd *abfd,
- asection *sec,
+ const asection *sec,
Elf_Internal_Shdr *shdr,
void *external_relocs,
Elf_Internal_Rela *internal_relocs)
@@ -2746,7 +2746,7 @@ elf_link_read_relocs_from_section (bfd *abfd,
Elf_Internal_Rela *
_bfd_elf_link_info_read_relocs (bfd *abfd,
struct bfd_link_info *info,
- asection *o,
+ const asection *o,
void *external_relocs,
Elf_Internal_Rela *internal_relocs,
bool keep_memory)
@@ -2843,7 +2843,7 @@ _bfd_elf_link_info_read_relocs (bfd *abfd,
Elf_Internal_Rela *
_bfd_elf_link_read_relocs (bfd *abfd,
- asection *o,
+ const asection *o,
void *external_relocs,
Elf_Internal_Rela *internal_relocs,
bool keep_memory)
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index f2a1441fdf7..59444b063a4 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -7298,11 +7298,23 @@ _bfd_mips_elf_eh_frame_address_size (bfd *abfd, const asection *sec)
if (long64_p)
return 8;
- if (sec->reloc_count > 0
- && elf_section_data (sec)->relocs != NULL
- && (ELF32_R_TYPE (elf_section_data (sec)->relocs[0].r_info)
- == R_MIPS_64))
- return 8;
+ if (sec->reloc_count > 0)
+ {
+ /* Load the relocations for this section. */
+ Elf_Internal_Rela *internal_relocs =
+ _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, true);
+ if (internal_relocs == NULL)
+ return 0;
+
+ unsigned int size = 0;
+ if (ELF32_R_TYPE (internal_relocs[0].r_info) == R_MIPS_64)
+ size = 8;
+
+ if (elf_section_data (sec)->relocs != internal_relocs)
+ free (internal_relocs);
+
+ return size;
+ }
return 0;
}
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index 50af78d1430..818238d0d58 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -771,6 +771,7 @@ if {$linux_gnu} {
run_dump_test_n64 "eh-frame2-n64"
}
run_dump_test_eabi "eh-frame3"
+run_dump_test_eabi "eh-frame3" {{ld --no-keep-memory} {name --no-keep-memory}}
run_dump_test_eabi "eh-frame4"
if {$linux_gnu} {
set eh_frame5_test {
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list