elf: Pass need_layout to _bfd_elf_map_sections_to_segments
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Jan 2022 16:45:16 +0000 (08:45 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 12 Jan 2022 13:15:18 +0000 (05:15 -0800)
On some targets, the DT_RELR section size can be computed only after all
symbols addresses can be determined.  Update ldelf_map_segments to pass
need_layout to _bfd_elf_map_sections_to_segments which will size DT_RELR
section and set need_layout to true if the DT_RELR section size is changed.

bfd/

* elf-bfd.h (_bfd_elf_map_sections_to_segments): Add a bool
pointer argument.
* elf.c (_bfd_elf_map_sections_to_segments): Add a bool pointer
argument to indicate if section layout needs update.
(assign_file_positions_for_load_sections): Pass NULL to
_bfd_elf_map_sections_to_segments.
* elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Pass
NULL to _bfd_elf_map_sections_to_segments.

ld/

* ldelfgen.c (ldelf_map_segments): Pass &need_layout to
_bfd_elf_map_sections_to_segments.

bfd/elf-bfd.h
bfd/elf.c
bfd/elflink.c
ld/ldelfgen.c

index 81f8fd47db7b3cadcb96bcd222187867dd38ba9c..0d9c76444857a9b6db05ae92dc1a9431b0799464 100644 (file)
@@ -2716,7 +2716,7 @@ extern struct elf_segment_map * _bfd_elf_make_dynamic_segment
   (bfd *, asection *);
 
 extern bool _bfd_elf_map_sections_to_segments
-  (bfd *, struct bfd_link_info *);
+  (bfd *, struct bfd_link_info *, bool *);
 
 extern bool _bfd_elf_is_function_type (unsigned int);
 
index ef0d18105babb5276d5de4d7eab7df5a054ab103..8b866b63e1858b2ebf1781efe7051579dbcfcf5d 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4609,10 +4609,13 @@ elf_modify_segment_map (bfd *abfd,
 #define IS_TBSS(s) \
   ((s->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) == SEC_THREAD_LOCAL)
 
-/* Set up a mapping from BFD sections to program segments.  */
+/* Set up a mapping from BFD sections to program segments.  Update
+   NEED_LAYOUT if the section layout is changed.  */
 
 bool
-_bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
+_bfd_elf_map_sections_to_segments (bfd *abfd,
+                                  struct bfd_link_info *info,
+                                  bool *need_layout ATTRIBUTE_UNUSED)
 {
   unsigned int count;
   struct elf_segment_map *m;
@@ -5416,7 +5419,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
   unsigned int opb = bfd_octets_per_byte (abfd, NULL);
 
   if (link_info == NULL
-      && !_bfd_elf_map_sections_to_segments (abfd, link_info))
+      && !_bfd_elf_map_sections_to_segments (abfd, link_info, NULL))
     return false;
 
   alloc = 0;
index f5e3fd53c5d3147920bf9bc19d718e5e6f92f319..46bff2771498d807f092c93ccb60ff453c07f26b 100644 (file)
@@ -3676,7 +3676,8 @@ _bfd_elf_strip_zero_sized_dynamic_sections (struct bfd_link_info *info)
     {
       /* Regenerate program headers.  */
       elf_seg_map (info->output_bfd) = NULL;
-      return _bfd_elf_map_sections_to_segments (info->output_bfd, info);
+      return _bfd_elf_map_sections_to_segments (info->output_bfd, info,
+                                               NULL);
     }
 
   return true;
index 5c033bbfbe0ef8691f24f54b3bf6ca37220dd050..58b37c65bc92bcb765570436a7893d04908bf40c 100644 (file)
@@ -304,7 +304,8 @@ ldelf_map_segments (bool need_layout)
          if (lang_phdr_list == NULL)
            elf_seg_map (link_info.output_bfd) = NULL;
          if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd,
-                                                 &link_info))
+                                                 &link_info,
+                                                 &need_layout))
            einfo (_("%F%P: map sections to segments failed: %E\n"));
 
          if (phdr_size != elf_program_header_size (link_info.output_bfd))