Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Apr 2023 14:15:58 GMT
From:      Cy Schubert <cy@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 898053f91002 - main - devel/binutils: Setting sh_link for SHT_REL/SHT_RELA
Message-ID:  <202304251415.33PEFwS4010506@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=898053f9100240f305a2bc6d49998a13728d3a71

commit 898053f9100240f305a2bc6d49998a13728d3a71
Author:     Emanuel Haupt <ehaupt@FreeBSD.org>
AuthorDate: 2023-04-25 14:05:48 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-04-25 14:15:25 +0000

    devel/binutils: Setting sh_link for SHT_REL/SHT_RELA
    
    Import upstream commit 6b958fe36b7:
    
    It's wrong to have an alloc reloc section trying to use a non-alloc
    symbol table.
    
            * elf.c (assign_section_numbers <SHT_REL, SHT_RELA>): Correct
            comment.  Always set sh_link to .dynsym for alloc reloc
            sections and to .symtab for non-alloc.
    
    This also fixes strip when using llvm-strip, i.e. when base built with
    WITH_LLVM_BINUTILS.
    
    PR:             271061, see also: 270961, 270960
    Reported by:    Emanuel Haupt <ehaupt@FreeBSD.org>
    Approved by:    cy
    Obtained from:  Upstream commit 6b958fe36b7
    MFH:            2022Q2
---
 devel/binutils/Makefile              |  2 +-
 devel/binutils/files/patch-bfd_elf.c | 39 ++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/devel/binutils/Makefile b/devel/binutils/Makefile
index a468d736263d..f33baaa17357 100644
--- a/devel/binutils/Makefile
+++ b/devel/binutils/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	binutils
 DISTVERSION=	2.40
-PORTREVISION=	2
+PORTREVISION=	3
 PORTEPOCH?=	1
 CATEGORIES?=	devel
 MASTER_SITES=	SOURCEWARE/binutils/releases
diff --git a/devel/binutils/files/patch-bfd_elf.c b/devel/binutils/files/patch-bfd_elf.c
new file mode 100644
index 000000000000..7f27ebb80a10
--- /dev/null
+++ b/devel/binutils/files/patch-bfd_elf.c
@@ -0,0 +1,39 @@
+--- bfd/elf.c.orig	2023-01-14 00:00:00 UTC
++++ bfd/elf.c
+@@ -3870,21 +3870,23 @@ assign_section_numbers (bfd *abfd, struct bfd_link_inf
+ 	{
+ 	case SHT_REL:
+ 	case SHT_RELA:
+-	  /* A reloc section which we are treating as a normal BFD
+-	     section.  sh_link is the section index of the symbol
+-	     table.  sh_info is the section index of the section to
+-	     which the relocation entries apply.  We assume that an
+-	     allocated reloc section uses the dynamic symbol table
+-	     if there is one.  Otherwise we guess the normal symbol
+-	     table.  FIXME: How can we be sure?  */
+-	  if (d->this_hdr.sh_link == 0 && (sec->flags & SEC_ALLOC) != 0)
++	  /* sh_link is the section index of the symbol table.
++	     sh_info is the section index of the section to which the
++	     relocation entries apply.  */
++	  if (d->this_hdr.sh_link == 0)
+ 	    {
+-	      s = bfd_get_section_by_name (abfd, ".dynsym");
+-	      if (s != NULL)
+-		d->this_hdr.sh_link = elf_section_data (s)->this_idx;
++	      /* FIXME maybe: If this is a reloc section which we are
++		 treating as a normal section then we likely should
++		 not be assuming its sh_link is .dynsym or .symtab.  */
++	      if ((sec->flags & SEC_ALLOC) != 0)
++		{
++		  s = bfd_get_section_by_name (abfd, ".dynsym");
++		  if (s != NULL)
++		    d->this_hdr.sh_link = elf_section_data (s)->this_idx;
++		}
++	      else
++		d->this_hdr.sh_link = elf_onesymtab (abfd);
+ 	    }
+-	  if (d->this_hdr.sh_link == 0)
+-	    d->this_hdr.sh_link = elf_onesymtab (abfd);
+ 
+ 	  s = elf_get_reloc_section (sec);
+ 	  if (s != NULL)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304251415.33PEFwS4010506>