]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 7 Mar 2024 16:28:29 +0000 (08:28 -0800)
committerAlan Modra <amodra@gmail.com>
Tue, 2 Apr 2024 06:59:58 +0000 (17:29 +1030)
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.

bfd/elf-bfd.h
bfd/elflink.c
bfd/elfxx-mips.c
ld/testsuite/ld-mips-elf/mips-elf.exp

index 7ad171d50001a5755ef040ff98434e9048416055..29283f24895cc32d17d3db7f0aeb1643c21c1e71 100644 (file)
@@ -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
index 37a61b7cd3158b4b09e9de4a3b61fec45b189c48..e9cef470333d3b0e9aa096c09bef6ca0435840e4 100644 (file)
@@ -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)
index f2a1441fdf72330e8ba9ab91d93b8f0741019585..59444b063a440b457e67e35d9640d830cc276f9d 100644 (file)
@@ -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;
     }
index 50af78d143017357d12eb82537eb38cf658050b1..818238d0d5854ad540c9a3a5788fa58fb1725c11 100644 (file)
@@ -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 {