]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Support multiple .eh_frame sections
authorJojo R <rjiejie@linux.alibaba.com>
Wed, 13 Jul 2022 16:28:09 +0000 (00:28 +0800)
committerJojo R <rjiejie@linux.alibaba.com>
Fri, 4 Nov 2022 02:30:18 +0000 (10:30 +0800)
This patch is based on MULTIPLE_FRAME_SECTIONS and EH_FRAME_LINKONCE,
it allows backend to enable this feature and use '--gc-sections' simply.

* gas/dw2gencfi.h (TARGET_MULTIPLE_EH_FRAME_SECTIONS): New.
(MULTIPLE_FRAME_SECTIONS): Add TARGET_MULTIPLE_EH_FRAME_SECTIONS.
* gas/dw2gencfi.c (EH_FRAME_LINKONCE): Add TARGET_MULTIPLE_EH_FRAME_SECTIONS.
(is_now_linkonce_segment): Likewise.
(get_cfi_seg): Create relocation info between .eh_frame.* and .text.* section.

* bfd/elf-bfd.h (elf_backend_can_make_multiple_eh_frame): New.
* bfd/elfxx-target.h (elf_backend_can_make_multiple_eh_frame): Likewise.
* bfd/elflink.c (_bfd_elf_default_action_discarded): Add checking for
elf_backend_can_make_multiple_eh_frame.

bfd/elf-bfd.h
bfd/elflink.c
bfd/elfxx-target.h
gas/doc/internals.texi
gas/dw2gencfi.c
gas/dw2gencfi.h

index f00f87b2779493bd4842767c6a0919afd79ad1ec..fa4b9bcf193c176c5b0e904bdcda34619dbabc45 100644 (file)
@@ -1432,6 +1432,9 @@ struct elf_backend_data
   bool (*elf_backend_can_make_lsda_relative_eh_frame)
      (bfd *, struct bfd_link_info *, asection *);
 
+  /* Tell linker to support multiple eh_frame sections.  */
+  bool elf_backend_can_make_multiple_eh_frame;
+
   /* This function returns an encoding after computing the encoded
      value (and storing it in ENCODED) for the given OFFSET into OSEC,
      to be stored in at LOC_OFFSET into the LOC_SEC input section.
index 89dcf26108c55a4a1b04af0fb5387bfdecac8dc1..019ac302905a2dbd0acd64d70080c101da633cbd 100644 (file)
@@ -10924,12 +10924,19 @@ elf_section_ignore_discarded_relocs (asection *sec)
 unsigned int
 _bfd_elf_default_action_discarded (asection *sec)
 {
+  const struct elf_backend_data *bed;
+  bed = get_elf_backend_data (sec->owner);
+
   if (sec->flags & SEC_DEBUGGING)
     return PRETEND;
 
   if (strcmp (".eh_frame", sec->name) == 0)
     return 0;
 
+  if (bed->elf_backend_can_make_multiple_eh_frame
+      && strncmp (sec->name, ".eh_frame.", 10) == 0)
+    return 0;
+
   if (strcmp (".gcc_except_table", sec->name) == 0)
     return 0;
 
index ca600bb5ddf891886d1c43c3e2c9fe3691685b72..f39244e7f523102fa6ea59e2be62dcdffed12e31 100644 (file)
 #ifndef elf_backend_can_make_lsda_relative_eh_frame
 #define elf_backend_can_make_lsda_relative_eh_frame    _bfd_elf_can_make_relative
 #endif
+#ifndef elf_backend_can_make_multiple_eh_frame
+#define elf_backend_can_make_multiple_eh_frame 0
+#endif
 #ifndef elf_backend_encode_eh_address
 #define elf_backend_encode_eh_address          _bfd_elf_encode_eh_address
 #endif
@@ -891,6 +894,7 @@ static const struct elf_backend_data elfNN_bed =
   elf_backend_eh_frame_address_size,
   elf_backend_can_make_relative_eh_frame,
   elf_backend_can_make_lsda_relative_eh_frame,
+  elf_backend_can_make_multiple_eh_frame,
   elf_backend_encode_eh_address,
   elf_backend_write_section,
   elf_backend_elfsym_local_is_section,
index a91d2ab9c1ec3f36db34a2ab92ca9868ce8a8f97..f0288746d78b81a8835aa14acfdc19a48db2ecd1 100644 (file)
@@ -1581,6 +1581,10 @@ If defined, GAS will check this macro before performing any optimizations on
 the DWARF call frame debug information that is emitted.  Targets which
 implement link time relaxation may need to define this macro and set it to zero
 if it is possible to change the size of a function's prologue.
+
+@item TARGET_MULTIPLE_EH_FRAME_SECTIONS
+If defined, GAS will create multiple .eh_frame.* sections according to
+the name of owner's function sections.
 @end table
 
 @node Object format backend
index 6be8cb50495d249d200a47ae60792fa99c8d6e90..80b2628928967a7624ae22038aeefe9ec689a643 100644 (file)
@@ -75,7 +75,8 @@
 # define tc_cfi_endproc(fde) ((void) (fde))
 #endif
 
-#define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh)
+#define EH_FRAME_LINKONCE (SUPPORT_FRAME_LINKONCE || compact_eh \
+                          || TARGET_MULTIPLE_EH_FRAME_SECTIONS)
 
 #ifndef DWARF2_FORMAT
 #define DWARF2_FORMAT(SEC) dwarf2_format_32bit
@@ -277,6 +278,9 @@ is_now_linkonce_segment (void)
   if (compact_eh)
     return now_seg;
 
+  if (TARGET_MULTIPLE_EH_FRAME_SECTIONS)
+    return now_seg;
+
   if ((bfd_section_flags (now_seg)
        & (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
          | SEC_LINK_DUPLICATES_ONE_ONLY | SEC_LINK_DUPLICATES_SAME_SIZE
@@ -1333,14 +1337,33 @@ static segT
 get_cfi_seg (segT cseg, const char *base, flagword flags, int align)
 {
   /* Exclude .debug_frame sections for Compact EH.  */
-  if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh))
+  if (SUPPORT_FRAME_LINKONCE || ((flags & SEC_DEBUGGING) == 0 && compact_eh)
+      || ((flags & SEC_DEBUGGING) == 0 && TARGET_MULTIPLE_EH_FRAME_SECTIONS))
     {
+      segT iseg = cseg;
       struct dwcfi_seg_list *l;
 
       l = dwcfi_hash_find_or_make (cseg, base, flags);
 
       cseg = l->seg;
       subseg_set (cseg, l->subseg);
+
+      if (TARGET_MULTIPLE_EH_FRAME_SECTIONS
+         && (flags & DWARF2_EH_FRAME_READ_ONLY))
+       {
+         const frchainS *ifrch = seg_info (iseg)->frchainP;
+         const frchainS *frch = seg_info (cseg)->frchainP;
+         expressionS exp;
+
+         exp.X_op = O_symbol;
+         exp.X_add_symbol = (symbolS *) local_symbol_make (cseg->name, cseg, frch->frch_root, 0);
+         exp.X_add_number = 0;
+         subseg_set (iseg, ifrch->frch_subseg);
+         fix_new_exp (ifrch->frch_root, 0, 0, &exp, 0, BFD_RELOC_NONE);
+
+         /* Restore the original segment info.  */
+         subseg_set (cseg, l->subseg);
+       }
     }
   else
     {
index d570cdb8db31fd48bd8d8df52ee1bd1f08b129e4..0f5ae77d8004e369baff5de1577c8856ec1814cb 100644 (file)
@@ -66,7 +66,12 @@ extern void cfi_add_CFA_restore_state (void);
 #define SUPPORT_COMPACT_EH 0
 #endif
 
-#define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH)
+#ifndef TARGET_MULTIPLE_EH_FRAME_SECTIONS
+#define TARGET_MULTIPLE_EH_FRAME_SECTIONS 0
+#endif
+
+#define MULTIPLE_FRAME_SECTIONS (SUPPORT_FRAME_LINKONCE || SUPPORT_COMPACT_EH \
+                                || TARGET_MULTIPLE_EH_FRAME_SECTIONS)
 
 struct cfi_insn_data
 {