public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Support multiple .eh_frame sections
@ 2022-07-29  7:48 Jojo R
  2022-08-01 11:10 ` Nick Clifton
  2022-11-02  8:01 ` [PATCH v2] " Jojo R
  0 siblings, 2 replies; 10+ messages in thread
From: Jojo R @ 2022-07-29  7:48 UTC (permalink / raw)
  To: rjiejie, binutils

	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      |  3 +++
 bfd/elflink.c      |  7 +++++++
 bfd/elfxx-target.h |  4 ++++
 gas/dw2gencfi.c    | 27 +++++++++++++++++++++++++--
 gas/dw2gencfi.h    |  7 ++++++-
 5 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 65bd1128263..f9b64faa080 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 2b1450fa4e1..395718d72a6 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10924,6 +10924,13 @@ 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 (bed->elf_backend_can_make_multiple_eh_frame
+      && strncmp (sec->name, ".eh_frame.", 10) == 0)
+    return 0;
+
   if (sec->flags & SEC_DEBUGGING)
     return PRETEND;
 
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 0579f64d1a0..3927a377a0e 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -654,6 +654,9 @@
 #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
@@ -887,6 +890,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,
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 6be8cb50495..461ab601321 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -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, 0, frch->frch_root);;
+	  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
     {
diff --git a/gas/dw2gencfi.h b/gas/dw2gencfi.h
index d570cdb8db3..0f5ae77d800 100644
--- a/gas/dw2gencfi.h
+++ b/gas/dw2gencfi.h
@@ -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
 {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Support multiple .eh_frame sections
  2022-07-29  7:48 [PATCH] Support multiple .eh_frame sections Jojo R
@ 2022-08-01 11:10 ` Nick Clifton
  2022-08-02  7:23   ` Jojo R
  2022-11-02  8:01 ` [PATCH v2] " Jojo R
  1 sibling, 1 reply; 10+ messages in thread
From: Nick Clifton @ 2022-08-01 11:10 UTC (permalink / raw)
  To: Jojo R, binutils

Hi Jojo,

> 	This patch is based on MULTIPLE_FRAME_SECTIONS and EH_FRAME_LINKONCE, > 	it allows backend to enable this feature and use '--gc-sections' simply.
This patch looks good to me.  But there are two issues, one small, one major:

* The small issue is that you need to add an entry to the gas/doc/internals.texi
describing the new TARGET_MULTIPLE_EH_FRAME_SECTIONS macro.  (I know that the
name is basically self-describing, but it is nice to keep the documentation
accurate).

* The bigger issue is that I could not find a FSF copyright assignment under
your name, or for Alibaba.  We would need such an assignment before we could
accept your patch.  (Note - I did find an assignment for Alibaba contributions
to gcc, so I would assume that obtaining a similar assignment for the binutils
should not be too difficult).

Cheers
   Nick


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Support multiple .eh_frame sections
  2022-08-01 11:10 ` Nick Clifton
@ 2022-08-02  7:23   ` Jojo R
  0 siblings, 0 replies; 10+ messages in thread
From: Jojo R @ 2022-08-02  7:23 UTC (permalink / raw)
  To: Nick Clifton, binutils


在 2022/8/1 下午7:10, Nick Clifton 写道:
> Hi Jojo,
>
>>     This patch is based on MULTIPLE_FRAME_SECTIONS and 
>> EH_FRAME_LINKONCE, >     it allows backend to enable this feature and 
>> use '--gc-sections' simply.
> This patch looks good to me.  But there are two issues, one small, one 
> major:
>
> * The small issue is that you need to add an entry to the 
> gas/doc/internals.texi
> describing the new TARGET_MULTIPLE_EH_FRAME_SECTIONS macro.  (I know 
> that the
> name is basically self-describing, but it is nice to keep the 
> documentation
> accurate).
>
> * The bigger issue is that I could not find a FSF copyright assignment 
> under
> your name, or for Alibaba.  We would need such an assignment before we 
> could
> accept your patch.  (Note - I did find an assignment for Alibaba 
> contributions
> to gcc, so I would assume that obtaining a similar assignment for the 
> binutils
> should not be too difficult).
>
> Cheers
>   Nick

Hi Nick,

     Thanks for your review :)

     i will update documentation and check the FSF copyright assignment.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2] Support multiple .eh_frame sections
  2022-07-29  7:48 [PATCH] Support multiple .eh_frame sections Jojo R
  2022-08-01 11:10 ` Nick Clifton
@ 2022-11-02  8:01 ` Jojo R
  2022-11-02 12:21   ` Nick Clifton
  2022-11-03  2:04   ` [PATCH v3] " Jojo R
  1 sibling, 2 replies; 10+ messages in thread
From: Jojo R @ 2022-11-02  8:01 UTC (permalink / raw)
  To: nickc, rjiejie, binutils

	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          |  3 +++
 bfd/elflink.c          |  7 +++++++
 bfd/elfxx-target.h     |  4 ++++
 gas/doc/internals.texi |  4 ++++
 gas/dw2gencfi.c        | 27 +++++++++++++++++++++++++--
 gas/dw2gencfi.h        |  7 ++++++-
 6 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index f00f87b2779..fa4b9bcf193 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 89dcf26108c..b2ad374c85d 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10924,6 +10924,13 @@ 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 (bed->elf_backend_can_make_multiple_eh_frame
+      && strncmp (sec->name, ".eh_frame.", 10) == 0)
+    return 0;
+
   if (sec->flags & SEC_DEBUGGING)
     return PRETEND;
 
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index ca600bb5ddf..f39244e7f52 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -658,6 +658,9 @@
 #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,
diff --git a/gas/doc/internals.texi b/gas/doc/internals.texi
index a91d2ab9c1e..f0288746d78 100644
--- a/gas/doc/internals.texi
+++ b/gas/doc/internals.texi
@@ -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
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 6be8cb50495..461ab601321 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -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, 0, frch->frch_root);;
+	  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
     {
diff --git a/gas/dw2gencfi.h b/gas/dw2gencfi.h
index d570cdb8db3..0f5ae77d800 100644
--- a/gas/dw2gencfi.h
+++ b/gas/dw2gencfi.h
@@ -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
 {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] Support multiple .eh_frame sections
  2022-11-02  8:01 ` [PATCH v2] " Jojo R
@ 2022-11-02 12:21   ` Nick Clifton
  2022-11-03  2:11     ` Jojo R
  2022-11-03  2:04   ` [PATCH v3] " Jojo R
  1 sibling, 1 reply; 10+ messages in thread
From: Nick Clifton @ 2022-11-02 12:21 UTC (permalink / raw)
  To: Jojo R, binutils

Hi Jojo,

> 	This patch is based on MULTIPLE_FRAME_SECTIONS and EH_FRAME_LINKONCE,
> 	it allows backend to enable this feature and use '--gc-sections' simply.

Do you (or your employer) have a copyright assignment on file with the FSF for
contributions to the GNU Binutils project ?  If not, are you willing to contribute
the patch with a DCO attached ?   https://developercertificate.org/


>   _bfd_elf_default_action_discarded (asection *sec)
>   {
> +  const struct elf_backend_data *bed;
> +  bed = get_elf_backend_data (sec->owner);
> +
> +  if (bed->elf_backend_can_make_multiple_eh_frame
> +      && strncmp (sec->name, ".eh_frame.", 10) == 0)
> +    return 0;
> +
>     if (sec->flags & SEC_DEBUGGING)
>       return PRETEND;

I think that this test would be better if it was moved down a few lines,
until it was just after this test:

   if (strcmp (".eh_frame", sec->name) == 0)
     return 0;


> +	  exp.X_op = O_symbol;
> +	  exp.X_add_symbol = (symbolS *) local_symbol_make (cseg->name, cseg, 0, frch->frch_root);;
> +	  exp.X_add_number = 0;

The arguments to local_symbol_make() are in the wrong order:

   struct local_symbol *local_symbol_make (const char *, segT, fragS *, valueT);

Ie the frag should come before the value.

Also there is a double semi-colon at the end of the line.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3] Support multiple .eh_frame sections
  2022-11-02  8:01 ` [PATCH v2] " Jojo R
  2022-11-02 12:21   ` Nick Clifton
@ 2022-11-03  2:04   ` Jojo R
  2022-11-03 10:26     ` Nick Clifton
  1 sibling, 1 reply; 10+ messages in thread
From: Jojo R @ 2022-11-03  2:04 UTC (permalink / raw)
  To: nickc, rjiejie, binutils

	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          |  3 +++
 bfd/elflink.c          |  7 +++++++
 bfd/elfxx-target.h     |  4 ++++
 gas/doc/internals.texi |  4 ++++
 gas/dw2gencfi.c        | 27 +++++++++++++++++++++++++--
 gas/dw2gencfi.h        |  7 ++++++-
 6 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index f00f87b2779..fa4b9bcf193 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 89dcf26108c..019ac302905 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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;
 
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index ca600bb5ddf..f39244e7f52 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -658,6 +658,9 @@
 #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,
diff --git a/gas/doc/internals.texi b/gas/doc/internals.texi
index a91d2ab9c1e..f0288746d78 100644
--- a/gas/doc/internals.texi
+++ b/gas/doc/internals.texi
@@ -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
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index 6be8cb50495..80b26289289 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -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
     {
diff --git a/gas/dw2gencfi.h b/gas/dw2gencfi.h
index d570cdb8db3..0f5ae77d800 100644
--- a/gas/dw2gencfi.h
+++ b/gas/dw2gencfi.h
@@ -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
 {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] Support multiple .eh_frame sections
  2022-11-02 12:21   ` Nick Clifton
@ 2022-11-03  2:11     ` Jojo R
  0 siblings, 0 replies; 10+ messages in thread
From: Jojo R @ 2022-11-03  2:11 UTC (permalink / raw)
  To: Nick Clifton, binutils


在 2022/11/2 20:21, Nick Clifton 写道:
> Hi Jojo,
>
>>     This patch is based on MULTIPLE_FRAME_SECTIONS and 
>> EH_FRAME_LINKONCE,
>>     it allows backend to enable this feature and use '--gc-sections' 
>> simply.
>
> Do you (or your employer) have a copyright assignment on file with the 
> FSF for
> contributions to the GNU Binutils project ?  If not, are you willing 
> to contribute
> the patch with a DCO attached ? https://developercertificate.org/
>
Yes, we have signed the assignment of FSF :)
>
>>   _bfd_elf_default_action_discarded (asection *sec)
>>   {
>> +  const struct elf_backend_data *bed;
>> +  bed = get_elf_backend_data (sec->owner);
>> +
>> +  if (bed->elf_backend_can_make_multiple_eh_frame
>> +      && strncmp (sec->name, ".eh_frame.", 10) == 0)
>> +    return 0;
>> +
>>     if (sec->flags & SEC_DEBUGGING)
>>       return PRETEND;
>
> I think that this test would be better if it was moved down a few lines,
> until it was just after this test:
>
>   if (strcmp (".eh_frame", sec->name) == 0)
>     return 0;
>
Fixed.
>
>> +      exp.X_op = O_symbol;
>> +      exp.X_add_symbol = (symbolS *) local_symbol_make (cseg->name, 
>> cseg, 0, frch->frch_root);;
>> +      exp.X_add_number = 0;
>
> The arguments to local_symbol_make() are in the wrong order:
>
>   struct local_symbol *local_symbol_make (const char *, segT, fragS *, 
> valueT);
>
> Ie the frag should come before the value.
>
> Also there is a double semi-colon at the end of the line.
Fixed.
>
> Cheers
>   Nick

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] Support multiple .eh_frame sections
  2022-11-03  2:04   ` [PATCH v3] " Jojo R
@ 2022-11-03 10:26     ` Nick Clifton
  2022-11-03 19:34       ` Fangrui Song
       [not found]       ` <DS7PR12MB57653A2E86C6779B24889E51CB389@DS7PR12MB5765.namprd12.prod.outlook.com>
  0 siblings, 2 replies; 10+ messages in thread
From: Nick Clifton @ 2022-11-03 10:26 UTC (permalink / raw)
  To: Jojo R, binutils

Hi Jojo,

> 	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.


Approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] Support multiple .eh_frame sections
  2022-11-03 10:26     ` Nick Clifton
@ 2022-11-03 19:34       ` Fangrui Song
       [not found]       ` <DS7PR12MB57653A2E86C6779B24889E51CB389@DS7PR12MB5765.namprd12.prod.outlook.com>
  1 sibling, 0 replies; 10+ messages in thread
From: Fangrui Song @ 2022-11-03 19:34 UTC (permalink / raw)
  To: Jojo R; +Cc: Nick Clifton, binutils

On Thu, Nov 3, 2022 at 3:26 AM Nick Clifton via Binutils
<binutils@sourceware.org> wrote:
>
> Hi Jojo,
>
> >       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.
>
>
> Approved - please apply.
>
> Cheers
>    Nick
>

Hi Jojo, is there a test demonstrating the handling of multiple
.eh_frame? Input .eh_frame or output .eh_frame?

.eh_frame handling is known to be weird with --gc-sections but linkers
have gained support:
https://maskray.me/blog/2020-11-08-stack-unwinding#linker-perspective

Since monolithic .eh_frame has been around for so long, some tools may
gain reliance on it and they will need to be fixed.
Also, it'd be nice to verify that .eh_frame_hdr and PT_GNU_EH_FRAME
creation is still correct.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] Support multiple .eh_frame sections
       [not found]       ` <DS7PR12MB57653A2E86C6779B24889E51CB389@DS7PR12MB5765.namprd12.prod.outlook.com>
@ 2022-11-04  1:50         ` Jojo R
  0 siblings, 0 replies; 10+ messages in thread
From: Jojo R @ 2022-11-04  1:50 UTC (permalink / raw)
  To: Fangrui Song; +Cc: Nick Clifton, binutils


在 2022/11/4 03:34, Fangrui Song 写道:
> On Thu, Nov 3, 2022 at 3:26 AM Nick Clifton via Binutils
> <binutils@sourceware.org> wrote:
>> Hi Jojo,
>>
>>>        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.
>>
>> Approved - please apply.
>>
>> Cheers
>>     Nick
>>
> Hi Jojo, is there a test demonstrating the handling of multiple
> .eh_frame? Input .eh_frame or output .eh_frame?
>
> .eh_frame handling is known to be weird with --gc-sections but linkers
> have gained support:
> https://maskray.me/blog/2020-11-08-stack-unwinding#linker-perspective

We want to encode another eh_frame format like arm, and based on 
seprated eh_frame sections :)

> Since monolithic .eh_frame has been around for so long, some tools may
> gain reliance on it and they will need to be fixed.
> Also, it'd be nice to verify that .eh_frame_hdr and PT_GNU_EH_FRAME
> creation is still correct.

Thanks for your mention, it looks good for baremetal.

.eh_frame_hdr or shared libs system like linux is not supported by now,

we will append another patch later if we finished that.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-04  1:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29  7:48 [PATCH] Support multiple .eh_frame sections Jojo R
2022-08-01 11:10 ` Nick Clifton
2022-08-02  7:23   ` Jojo R
2022-11-02  8:01 ` [PATCH v2] " Jojo R
2022-11-02 12:21   ` Nick Clifton
2022-11-03  2:11     ` Jojo R
2022-11-03  2:04   ` [PATCH v3] " Jojo R
2022-11-03 10:26     ` Nick Clifton
2022-11-03 19:34       ` Fangrui Song
     [not found]       ` <DS7PR12MB57653A2E86C6779B24889E51CB389@DS7PR12MB5765.namprd12.prod.outlook.com>
2022-11-04  1:50         ` Jojo R

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).