public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bfd_section_from_shdr: Support SHT_RELR sections
@ 2021-12-08  2:24 Fangrui Song
  2021-12-08 10:08 ` Alan Modra
  2021-12-08 14:04 ` Nick Clifton
  0 siblings, 2 replies; 3+ messages in thread
From: Fangrui Song @ 2021-12-08  2:24 UTC (permalink / raw)
  To: binutils, Alan Modra, Nick Clifton; +Cc: Fangrui Song

If a.so contains an SHT_RELR section, objcopy a.so will fail with:

    a.so: unknown type [0x13] section `.relr.dyn'

This change allows objcopy to work.

bfd/
    * elf.c (bfd_section_from_shdr): Support SHT_RELR.
---
 bfd/elf.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/bfd/elf.c b/bfd/elf.c
index cfdb94922f3..1d873b9d01e 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2359,16 +2359,22 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 
     case SHT_REL:
     case SHT_RELA:
+    case SHT_RELR:
       /* *These* do a lot of work -- but build no sections!  */
       {
 	asection *target_sect;
 	Elf_Internal_Shdr *hdr2, **p_hdr;
 	unsigned int num_sec = elf_numsections (abfd);
 	struct bfd_elf_section_data *esdt;
+	bfd_size_type size;
 
-	if (hdr->sh_entsize
-	    != (bfd_size_type) (hdr->sh_type == SHT_REL
-				? bed->s->sizeof_rel : bed->s->sizeof_rela))
+	if (hdr->sh_type == SHT_REL)
+	  size = (bfd_size_type) bed->s->sizeof_rel;
+	else if (hdr->sh_type == SHT_RELA)
+	  size = (bfd_size_type) bed->s->sizeof_rela;
+	else
+	  size = (bfd_size_type) bed->s->arch_size / 8;
+	if (hdr->sh_entsize != size)
 	  goto fail;
 
 	/* Check for a bogus link to avoid crashing.  */
-- 
2.34.1.400.ga245620fadb-goog


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

* Re: [PATCH] bfd_section_from_shdr: Support SHT_RELR sections
  2021-12-08  2:24 [PATCH] bfd_section_from_shdr: Support SHT_RELR sections Fangrui Song
@ 2021-12-08 10:08 ` Alan Modra
  2021-12-08 14:04 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Modra @ 2021-12-08 10:08 UTC (permalink / raw)
  To: Fangrui Song; +Cc: binutils, Nick Clifton

On Tue, Dec 07, 2021 at 06:24:14PM -0800, Fangrui Song wrote:
> If a.so contains an SHT_RELR section, objcopy a.so will fail with:
> 
>     a.so: unknown type [0x13] section `.relr.dyn'
> 
> This change allows objcopy to work.
> 
> bfd/
>     * elf.c (bfd_section_from_shdr): Support SHT_RELR.

Thanks!  Committed.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [PATCH] bfd_section_from_shdr: Support SHT_RELR sections
  2021-12-08  2:24 [PATCH] bfd_section_from_shdr: Support SHT_RELR sections Fangrui Song
  2021-12-08 10:08 ` Alan Modra
@ 2021-12-08 14:04 ` Nick Clifton
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Clifton @ 2021-12-08 14:04 UTC (permalink / raw)
  To: Fangrui Song, binutils, Alan Modra

Hi Fangrui,

> If a.so contains an SHT_RELR section, objcopy a.so will fail with:
> 
>      a.so: unknown type [0x13] section `.relr.dyn'
> 
> This change allows objcopy to work.
> 
> bfd/
>      * elf.c (bfd_section_from_shdr): Support SHT_RELR.

Approved - please apply.

Cheers
   Nick

PS. I wonder if this particular code:

+	if (hdr->sh_type == SHT_REL)
+	  size = (bfd_size_type) bed->s->sizeof_rel;
+	else if (hdr->sh_type == SHT_RELA)
+	  size = (bfd_size_type) bed->s->sizeof_rela;
+	else
+	  size = (bfd_size_type) bed->s->arch_size / 8;

Should be extracted into its own function.  I imagine that
is going to be needed in other locations in the BFD library....




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

end of thread, other threads:[~2021-12-08 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08  2:24 [PATCH] bfd_section_from_shdr: Support SHT_RELR sections Fangrui Song
2021-12-08 10:08 ` Alan Modra
2021-12-08 14:04 ` Nick Clifton

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