public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-08-17 20:07 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2021-08-17 20:07 UTC (permalink / raw
  To: gentoo-commits

commit:     8699e74a960289b51ace04e4fffde22d5344171b
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 17 20:01:35 2021 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Tue Aug 17 20:01:35 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=8699e74a

Enable new dtags via configure, not broken patch

Bug: https://bugs.gentoo.org/808787
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...nable-new-dtags-by-default-for-linux-gnu-.patch | 49 ----------------------
 1 file changed, 49 deletions(-)

diff --git a/9999/0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
deleted file mode 100644
index c6e5299..0000000
--- a/9999/0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
+++ /dev/null
@@ -1,49 +0,0 @@
-From f4ecba77ec1eb0576b8731c749336ea3889eba73 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 13 Oct 2019 05:25:28 +0200
-Subject: [PATCH 5/6] Gentoo: ld: enable new dtags by default for linux/gnu
- targets
-
-Original author: Mike Frysinger <vapier@gentoo.org>
-
-The "new" dtags options have been around for 14+ years now, so for Linux
-and GNU targets, enable them by default.
-
-2012-01-21  Mike Frysinger  <vapier@gentoo.org>
-
-        * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
-        link_info.new_dtags to TRUE for linux/gnu targets.
-        * NEWS: Mention new dtags default.
-
-2013-01-22  Roland McGrath  <mcgrathr@google.com>
-
-        * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
-        new_dtags to TRUE for *-*-nacl* targets.
----
- ld/emultempl/elf.em | 10 ++++++++++
- 1 file changed, 10 insertions(+)
-
-diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
-index bfaf8130a3e..c4c42b7371a 100644
---- a/ld/emultempl/elf.em
-+++ b/ld/emultempl/elf.em
-@@ -81,6 +81,16 @@ gld${EMULATION_NAME}_before_parse (void)
-   input_flags.dynamic = ${DYNAMIC_LINK-true};
-   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
-   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
-+EOF
-+
-+case ${target} in
-+  *-*-linux-* | *-*-k*bsd*-* | *-*-gnu* | *-*-nacl*)
-+    fragment <<EOF
-+  link_info.new_dtags = true;
-+EOF
-+    ;;
-+esac
-+fragment <<EOF
-   link_info.check_relocs_after_open_input = true;
- EOF
- if test -n "$COMMONPAGESIZE"; then
--- 
-2.31.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-11  6:40 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-11  6:40 UTC (permalink / raw
  To: gentoo-commits

commit:     570749321a435ac8368e6344034f00b0be92e7bc
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 11 06:40:33 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Oct 11 06:40:33 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=57074932

9999: update to v2 cache patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1277 +++-----------------
 1 file changed, 165 insertions(+), 1112 deletions(-)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
index f829ffc..3aebf29 100644
--- a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -1,8 +1,8 @@
-From 6081e4356a0e4f9932a05af0871490fc54e15113 Mon Sep 17 00:00:00 2001
-Message-ID: <6081e4356a0e4f9932a05af0871490fc54e15113.1760143572.git.sam@gentoo.org>
+From 9cf16688a03d54c4788398d9481d798935a71d40 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sat, 11 Oct 2025 07:18:50 +0800
-Subject: [PATCH] elf: Cache full internal symbol table for relocatable input
+Date: Thu, 9 Oct 2025 13:16:19 +0800
+Subject: [PATCH v2] elf: Cache full internal symbol table for relocatable
+ input
 
 Add bfd_elf_get_elf_syms_cached to cache internal symbol table for
 relocatable input and use the internal symbol table cache for both local
@@ -10,8 +10,10 @@ and global symbols to avoid swapping in the same symbol table repeatedly
 for --gc-sections.  This improves linker --gc-sections speed by ~2x for
 PR ld/33530.
 
-elf_link_input_bfd is updated to not to pass preallocated buffers to
-bfd_elf_get_elf_syms_cache.
+Pass non-NULL pointers for internal/external symbol tables and symbol
+section indices to bfd_elf_get_elf_syms_cache only if caller uses them
+since since it can be very expensive to copy from internal cache to them.
+It should be avoided.
 
 Data to link the 3.1GB clang executable in LLVM 21 debug build on
 Linux/x86-64 with 32GB RAM is:
@@ -26,111 +28,44 @@ page faults	2535779		2509896		0.1%
 and data to link the 308M cc1plus executable in GCC 16 stage 1 build is:
 
 		before		after		improvement
-user		3.56 		3.49		0.2%
-system		0.66		0.58		12%
-total		4.22 		4.07		0.3%
-maximum set(MB)	969		992		-2.4%
-page faults	992692		1016732		0.1%
+user		3.56 		3.39		4.8%
+system		0.66		0.53		20%
+total		4.22 		3.94		6.6%
+maximum set(MB)	946		970		-2.5%
+page faults	236737		243509		-0.3%
 
 bfd/
 
 	PR ld/33530
 	* elf-bfd.h (elf_obj_tdata): Add symtab.
-	(bfd_elf_get_elf_syms): Remove the Elf_External_Sym_Shndx pointer
-	argument.
 	(bfd_elf_get_elf_syms_cached): New function.
 	(bfd_elf_free_symtab): Likewise.
 	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
 	return void.
 	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
 	internal symbol table in symtab_hdr.
-	* elf-m10200.c (mn10200_elf_relax_section): Drop the last argument
-	to bfd_elf_get_elf_syms.
-	(mn10200_elf_get_relocated_section_contents): Likewise.
-	* elf-m10300.c (mn10300_elf_check_relocs): Likewise.
-	(mn10300_elf_relax_section): Likewise.
-	(mn10300_elf_get_relocated_section_contents): Likewise.
-	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
-	pointer argument.  Renamed to ...
+	* elf.c (bfd_elf_get_elf_syms): Renamed to ...
 	(bfd_elf_get_elf_syms_cached):  This.  Cache internal symbol
 	table.
 	(bfd_elf_get_elf_syms): Call bfd_elf_get_elf_syms_cached.
 	(group_signature): Call bfd_elf_get_elf_syms_cached instead of
-	bfd_elf_get_elf_syms.
+	bfd_elf_get_elf_syms and pass NULL for external symbol table
+	and symbol section indices.
 	(bfd_sym_from_r_symndx): Likewise.
 	(_bfd_elf_free_cached_info): Free internal symbol table cache.
-	* elf32-arc.c (arc_elf_relax_section): Likewise.
-	* elf32-arm.c (cmse_scan): Likewise.
-	(elf32_arm_size_stubs): Likewise.
-	(bfd_elf32_arm_init_maps): Likewise.
-	* elf32-avr.c (elf32_avr_relax_delete_bytes): Likewise.
-	(retrieve_local_syms): Likewise.
-	(elf32_avr_relax_section): Likewise.
-	(elf32_avr_get_relocated_section_contents): Likewise.
-	(get_local_syms): Likewise.
-	* elf32-bfin.c (bfd_bfin_elf32_create_embedded_relocs): Likewise.
-	* elf32-cr16.c (elf32_cr16_get_relocated_section_contents):
-	Likewise.
-	(elf32_cr16_relax_section): Likewise.
-	(bfd_cr16_elf32_create_embedded_relocs): Likewise.
-	* elf32-crx.c (elf32_crx_get_relocated_section_contents):
-	Likewise.
-	(elf32_crx_relax_section): Likewise.
-	* elf32-csky.c (elf32_csky_size_stubs): Likewise.
-	* elf32-epiphany.c (epiphany_elf_relax_section): Likewise.
-	* elf32-ft32.c (elf32_ft32_relax_delete_bytes): Likewise.
-	(elf32_ft32_relax_is_branch_target): Likewise.
-	(ft32_elf_relax_section): Likewise.
-	* elf32-h8300.c (elf32_h8_relax_section): Likewise.
-	(elf32_h8_get_relocated_section_contents): Likewise.
-	* elf32-hppa.c (get_local_syms): Likewise.
-	* elf32-ip2k.c (ip2k_elf_relax_section): Likewise.
-	* elf32-m32c.c (dump_symtab): Likewise.
-	(m32c_elf_relax_plt_section): Likewise.
-	(m32c_elf_relax_section): Likewise.
-	* elf32-m68hc11.c (m68hc11_elf_relax_section): Likewise.
-	* elf32-m68hc1x.c (elf32_m68hc11_size_stubs): Likewise.
-	* elf32-m68k.c (bfd_m68k_elf32_create_embedded_relocs): Likewise.
-	* elf32-metag.c (get_local_syms): Likewise.
-	* elf32-microblaze.c (microblaze_elf_relax_section): Likewise.
-	* elf32-msp430.c (msp430_elf_relax_section): Likewise.
-	* elf32-nds32.c (nds32_elf_relax_delete_blanks): Likewise.
-	(nds32_get_local_syms): Likewise.
-	* elf32-ppc.c (get_sym_h): Likewise.
-	(ppc_elf_late_size_sections): Likewise.
-	* elf32-pru.c (pru_elf_relax_delete_bytes): Likewise.
-	(pru_elf32_relax_section): Likewise.
-	* elf32-rl78.c (rl78_elf_relax_plt_section): Likewise.
-	(rl78_elf_relax_section): Likewise.
-	* elf32-rx.c (elf32_rx_relax_section): Likewise.
-	(rx_dump_symtab): Likewise.
-	* elf32-sh.c (sh_elf_relax_section): Likewise.
-	(sh_elf_get_relocated_section_contents): Likewise.
-	* elf32-spu.c (get_sym_h): Likewise.
-	(discover_functions): Likewise.
-	* elf32-v850.c (v850_elf_relax_section): Likewise.
-	* elf32-xstormy16.c (xstormy16_elf_relax_section): Likewise.
-	* elf32-xtensa.c (retrieve_local_syms): Likewise.
-	* elf64-alpha.c (elf64_alpha_relax_section): Likewise.
-	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
-	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
-	(elf64_vms_link_add_object_symbols): Likewise.
-	* elf64-mmix.c (mmix_elf_relax_section): Likewise.
-	* elf64-ppc.c (opd_entry_value): Likewise.
-	(get_sym_h): Likewise.
-	(ppc64_elf_late_size_sections): Likewise.
-	(ppc64_elf_layout_multitoc): Likewise.
-	(got_and_plt_relr_for_local_syms): Likewise.
 	* elfcode.h (elf_slurp_symbol_table): Call
 	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
 	Don't free internal symbol buffer.
 	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms
+	and pass NULL for external symbol table and symbol section
+	indices.
+	(elf_link_is_defined_archive_symbol): Call
 	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
-	(elf_link_is_defined_archive_symbol): Likewise.  Free internal
-	symbol table cache.
+	Free internal symbol table cache.
 	(elf_link_add_object_symbols): Call bfd_elf_get_elf_syms_cached
 	instead of bfd_elf_get_elf_syms.  Free internal symbol table
-	cache if it has been changed.
+	cache if it has been changed or there is an error.
 	(bfd_elf_match_symbols_in_sections): Call
 	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
 	Don't free the internal symbol table.
@@ -138,10 +73,12 @@ bfd/
 	internal_syms.
 	(elf_link_check_versioned_symbol): Call
 	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
-	(elf_link_input_bfd): Likewise.  Don't pass pre-allocated
-	buffer to bfd_elf_get_elf_syms_cached.
+	(elf_link_input_bfd): Likewise.  Pass NULL as pointers to
+	internal/external symbol tables and symbol section indices to
+	bfd_elf_get_elf_syms_cached.
 	(elf_final_link_free): Updated.
-	(bfd_elf_final_link): Don't set flinfo.external_syms,
+	(bfd_elf_final_link): Don't clear flinfo fields after cleared
+	with memset.  Don't set flinfo.external_syms,
 	flinfo.internal_syms nor flinfo.locsym_shndx.
 	(init_reloc_cookie): Remove the keep_memory argument.  Don't
 	cache internal symbol table in symtab_hdr.
@@ -155,15 +92,10 @@ bfd/
 	(bfd_elf_discard_info): Replace fini_reloc_cookie_for_section with
 	fini_reloc_cookie_rels.  Don't call fini_reloc_cookie.
 	(bfd_elf_parse_eh_frame_entries): Updated.
-	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
-	(bfd_elfNN_aarch64_init_maps): Likewise.
-	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
-	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
-	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
-	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
-	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
-	use symtab_hdr->contents for internal symbol table.  Set
-	keep_symtab if the symbol table has been updated.
+	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	Cache internal symbol table in symtab_hdr->contents if it has
+	been changed.
 
 libctf/
 
@@ -174,59 +106,17 @@ libctf/
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
- bfd/elf-bfd.h          |  19 ++++-
- bfd/elf-eh-frame.c     |  17 +----
- bfd/elf-m10200.c       |   4 +-
- bfd/elf-m10300.c       |  10 +--
- bfd/elf.c              | 167 +++++++++++++++++++++++++++++++----------
- bfd/elf32-arc.c        |   2 +-
- bfd/elf32-arm.c        |   7 +-
- bfd/elf32-avr.c        |  12 +--
- bfd/elf32-bfin.c       |   2 +-
- bfd/elf32-cr16.c       |   6 +-
- bfd/elf32-crx.c        |   4 +-
- bfd/elf32-csky.c       |   2 +-
- bfd/elf32-epiphany.c   |   2 +-
- bfd/elf32-ft32.c       |   6 +-
- bfd/elf32-h8300.c      |   4 +-
- bfd/elf32-hppa.c       |   2 +-
- bfd/elf32-ip2k.c       |   2 +-
- bfd/elf32-m32c.c       |   8 +-
- bfd/elf32-m68hc11.c    |   2 +-
- bfd/elf32-m68hc1x.c    |   2 +-
- bfd/elf32-m68k.c       |   2 +-
- bfd/elf32-metag.c      |   2 +-
- bfd/elf32-microblaze.c |   2 +-
- bfd/elf32-msp430.c     |   4 +-
- bfd/elf32-nds32.c      |   4 +-
- bfd/elf32-ppc.c        |   4 +-
- bfd/elf32-pru.c        |   4 +-
- bfd/elf32-rl78.c       |   4 +-
- bfd/elf32-rx.c         |   4 +-
- bfd/elf32-sh.c         |   4 +-
- bfd/elf32-spu.c        |   4 +-
- bfd/elf32-v850.c       |   2 +-
- bfd/elf32-xstormy16.c  |   2 +-
- bfd/elf32-xtensa.c     |   2 +-
- bfd/elf64-alpha.c      |   2 +-
- bfd/elf64-hppa.c       |   2 +-
- bfd/elf64-ia64-vms.c   |   4 +-
- bfd/elf64-mmix.c       |   2 +-
- bfd/elf64-ppc.c        |  12 +--
- bfd/elfcode.h          |  10 +--
- bfd/elflink.c          | 162 +++++++++++----------------------------
- bfd/elfnn-aarch64.c    |   4 +-
- bfd/elfnn-ia64.c       |   2 +-
- bfd/elfnn-kvx.c        |   2 +-
- bfd/elfnn-loongarch.c  |   2 +-
- bfd/elfnn-riscv.c      |   2 +-
- bfd/elfxx-mips.c       |   2 +-
- bfd/elfxx-x86.c        |  22 ++++--
- libctf/ctf-open-bfd.c  |   6 +-
- 49 files changed, 293 insertions(+), 267 deletions(-)
+ bfd/elf-bfd.h         |  17 ++++
+ bfd/elf-eh-frame.c    |  17 +---
+ bfd/elf.c             | 189 +++++++++++++++++++++++++++++++++---------
+ bfd/elfcode.h         |  10 +--
+ bfd/elflink.c         | 172 +++++++++++---------------------------
+ bfd/elfxx-x86.c       |  22 +++--
+ libctf/ctf-open-bfd.c |   6 +-
+ 7 files changed, 239 insertions(+), 194 deletions(-)
 
 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index 5d19529d972..b0bd8f4d589 100644
+index 5d19529d972..28179647e9d 100644
 --- a/bfd/elf-bfd.h
 +++ b/bfd/elf-bfd.h
 @@ -2165,6 +2165,11 @@ struct elf_obj_tdata
@@ -234,26 +124,24 @@ index 5d19529d972..b0bd8f4d589 100644
    void *symbuf;
  
 +  /* A pointer to the full internal symbol table of input relocatable
-+     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
-+     all backends use it to only cache local symbols.  */
++     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since it
++     is used by backends to cache local symbols.  */
 +  Elf_Internal_Sym *symtab;
 +
    /* List of GNU properties.  Will be updated by setup_gnu_properties
       after all input GNU properties are merged for output.  */
    elf_property_list *properties;
-@@ -2297,8 +2302,9 @@ extern unsigned int _bfd_elf_section_from_bfd_section
- extern char *bfd_elf_string_from_elf_section
-   (bfd *, unsigned, unsigned);
+@@ -2299,6 +2304,9 @@ extern char *bfd_elf_string_from_elf_section
  extern Elf_Internal_Sym *bfd_elf_get_elf_syms
--  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
--   Elf_External_Sym_Shndx *);
-+  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
+   (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
+    Elf_External_Sym_Shndx *);
 +extern Elf_Internal_Sym *bfd_elf_get_elf_syms_cached
-+  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
++  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
++   Elf_External_Sym_Shndx *);
  extern char * bfd_elf_get_str_section (bfd *, unsigned int);
  extern const char *bfd_elf_sym_name
    (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
-@@ -3333,6 +3339,15 @@ bfd_section_is_ctf (const asection *sec)
+@@ -3333,6 +3341,15 @@ bfd_section_is_ctf (const asection *sec)
    return startswith (name, ".ctf") && (name[4] == 0 || name[4] == '.');
  }
  
@@ -316,96 +204,33 @@ index 4eda3c991bb..bd2c85291fb 100644
    return changed;
  }
  
-diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
-index ca9a92e1221..4da86774ee2 100644
---- a/bfd/elf-m10200.c
-+++ b/bfd/elf-m10200.c
-@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
-index b381bb9037c..373290cbe4a 100644
---- a/bfd/elf-m10300.c
-+++ b/bfd/elf-m10300.c
-@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
- 		  if (isymbuf == NULL)
- 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						    symtab_hdr->sh_info, 0,
--						    NULL, NULL, NULL);
-+						    NULL, NULL);
- 		  if (isymbuf)
- 		    {
- 		      isym = isymbuf + r_symndx;
-@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
 diff --git a/bfd/elf.c b/bfd/elf.c
-index bde7414ee21..472fb5da55e 100644
+index bde7414ee21..134c3664f85 100644
 --- a/bfd/elf.c
 +++ b/bfd/elf.c
-@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
+@@ -427,22 +427,27 @@ bfd_elf_string_from_elf_section (bfd *abfd,
+   return ((char *) hdr->contents) + strindex;
  }
  
- /* Read and convert symbols to internal format.
+-/* Read and convert symbols to internal format.
 -   SYMCOUNT specifies the number of symbols to read, starting from
 -   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
-+   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
-+   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
-    are non-NULL, they are used to store the internal symbols, external
+-   are non-NULL, they are used to store the internal symbols, external
 -   symbols, and symbol section index extensions, respectively.
 -   Returns a pointer to the internal symbol buffer (malloced if necessary)
 -   or NULL if there were no symbols or some kind of problem.  */
-+   symbols, and symbol section index extensions, respectively.  Returns
-+   a pointer to the internal symbol cache or NULL if there were no
-+   symbols or some kind of problem.  */
++/* Read and convert symbols to internal format.  PARTIAL_SYMCOUNT
++   specifies the number of symbols to read, starting from symbol
++   PARTIAL_SYMOFFSET.  If any of INTSYM_BUF, PARTIAL_EXTSYM_BUF or
++   PARTIAL_EXTSHNDX_BUF are non-NULL, they are used to store the
++   internal symbols, external symbols, and symbol section index
++   extensions, respectively.  Returns a pointer to the internal
++   symbol buffer or NULL if there were no symbols or some kind of
++   problem.
++
++   NB: Pass non-NULL for INTSYM_BUF, PARTIAL_EXTSYM_BUF or
++   PARTIAL_EXTSHNDX_BUF only if they will be used since it can be
++   very expensive to copy from internal cache to them.  */
  
  Elf_Internal_Sym *
 -bfd_elf_get_elf_syms (bfd *ibfd,
@@ -420,11 +245,12 @@ index bde7414ee21..472fb5da55e 100644
 +			     size_t partial_symcount,
 +			     size_t partial_symoffset,
 +			     Elf_Internal_Sym *intsym_buf,
-+			     void *partial_extsym_buf)
++			     void *partial_extsym_buf,
++			     Elf_External_Sym_Shndx *partial_extshndx_buf)
  {
    Elf_Internal_Shdr *shndx_hdr;
    void *alloc_ext;
-@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -455,7 +460,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
    const struct elf_backend_data *bed;
    size_t extsym_size;
    size_t amt;
@@ -432,21 +258,21 @@ index bde7414ee21..472fb5da55e 100644
 +  file_ptr pos = 0;
 +  size_t symcount = partial_symcount;
 +  size_t symoffset = partial_symoffset;
-+  void *extsym_buf = NULL;
 +  Elf_External_Sym_Shndx *extshndx_buf = NULL;
++  void *extsym_buf = NULL;
 +  bool cache_symtab = false;
  
    if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
      abort ();
-@@ -474,6 +478,25 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -474,6 +484,25 @@ bfd_elf_get_elf_syms (bfd *ibfd,
        return elf_tdata (ibfd)->dt_symtab + symoffset;
      }
  
 +  if (elf_tdata (ibfd)->symtab != NULL)
 +    {
-+      /* Since extsym_buf isn't cached, free the symbol table cache and
-+	 re-read the symbol table.  */
-+      if (partial_extsym_buf != NULL)
++      /* Since extsym_buf and extshndx_buf aren't cached, free the
++	 symbol table cache and re-read the symbol table.  */
++      if (partial_extsym_buf != NULL || partial_extshndx_buf != NULL)
 +	bfd_elf_free_symtab (ibfd);
 +      else
 +	{
@@ -464,7 +290,7 @@ index bde7414ee21..472fb5da55e 100644
    /* Normal syms might have section extension entries.  */
    shndx_hdr = NULL;
    if (elf_symtab_shndx_list (ibfd) != NULL)
-@@ -506,19 +529,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -506,19 +535,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	}
      }
  
@@ -499,7 +325,7 @@ index bde7414ee21..472fb5da55e 100644
    if (bfd_seek (ibfd, pos, SEEK_SET) != 0
        || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
  				    &alloc_ext, ibfd, false))
-@@ -551,22 +586,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -551,22 +592,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	}
      }
  
@@ -536,7 +362,7 @@ index bde7414ee21..472fb5da55e 100644
  	   shndx = extshndx_buf;
         isym < isymend;
         esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
-@@ -590,7 +627,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -590,7 +633,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	{	
  	  /* xgettext:c-format */
  	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
@@ -547,7 +373,7 @@ index bde7414ee21..472fb5da55e 100644
  	  free (alloc_intsym);
  	  intsym_buf = NULL;
  	  goto out1;
-@@ -602,18 +641,72 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -602,18 +647,83 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	{
  	  /* xgettext:c-format */
  	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
@@ -563,10 +389,18 @@ index bde7414ee21..472fb5da55e 100644
  
 +  /* Copy external symbol table before external symbol table buffer
 +     is released by _bfd_munmap_temporary.  */
-+  if (intsym_buf != NULL && partial_extsym_buf != NULL)
-+    memcpy (partial_extsym_buf,
-+	    extsym_buf + partial_symoffset * extsym_size,
-+	    partial_symcount * extsym_size);
++  if (intsym_buf != NULL)
++    {
++      if (partial_extsym_buf != NULL)
++	memcpy (partial_extsym_buf,
++		extsym_buf + partial_symoffset * extsym_size,
++		partial_symcount * extsym_size);
++      if (extshndx_buf != NULL && partial_extshndx_buf != NULL)
++	memcpy (partial_extshndx_buf,
++		(extshndx_buf
++		 + partial_symoffset * sizeof (Elf_External_Sym_Shndx)),
++		partial_symcount * sizeof (Elf_External_Sym_Shndx));
++    }
 +
   out1:
    _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
@@ -587,13 +421,14 @@ index bde7414ee21..472fb5da55e 100644
 +    return alloc_intsym + partial_symoffset;
 +}
 +
-+/* Read and convert symbols to internal format.
-+   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
-+   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
-+   are non-NULL, they are used to store the internal symbols, external
-+   symbols, and symbol section index extensions, respectively.  Returns
-+   a pointer to the internal symbol buffer (malloced if necessary) or
-+   NULL if there were no symbols or some kind of problem.  */
++/* Read and convert symbols to internal format.  PARTIAL_SYMCOUNT
++   specifies the number of symbols to read, starting from symbol
++   PARTIAL_SYMOFFSET.  If any of INTSYM_BUF, PARTIAL_EXTSYM_BUF
++   or PARTIAL_EXTSHNDX_BUF are non-NULL, they are used to store the
++   internal symbols, external symbols, and symbol section index
++   extensions, respectively.  Returns a pointer to the internal
++   symbol buffer (malloced if necessary) or NULL if there were no
++   symbols or some kind of problem.  */
 +
 +Elf_Internal_Sym *
 +bfd_elf_get_elf_syms (bfd *ibfd,
@@ -601,12 +436,14 @@ index bde7414ee21..472fb5da55e 100644
 +		      size_t partial_symcount,
 +		      size_t partial_symoffset,
 +		      Elf_Internal_Sym *intsym_buf,
-+		      void *partial_extsym_buf)
++		      void *partial_extsym_buf,
++		      Elf_External_Sym_Shndx *partial_extshndx_buf)
 +{
 +  Elf_Internal_Sym *isym
 +    = bfd_elf_get_elf_syms_cached (ibfd, symtab_hdr, partial_symcount,
 +				   partial_symoffset, intsym_buf,
-+				   partial_extsym_buf);
++				   partial_extsym_buf,
++				   partial_extshndx_buf);
 +  if (isym == NULL
 +      || intsym_buf != NULL
 +      || partial_symcount == 0
@@ -621,7 +458,7 @@ index bde7414ee21..472fb5da55e 100644
    return intsym_buf;
  }
  
-@@ -659,8 +752,6 @@ static const char *
+@@ -659,8 +769,6 @@ static const char *
  group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
  {
    Elf_Internal_Shdr *hdr;
@@ -630,18 +467,18 @@ index bde7414ee21..472fb5da55e 100644
    Elf_Internal_Sym isym;
  
    /* First we need to ensure the symbol table is available.  Make sure
-@@ -674,8 +765,8 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+@@ -674,8 +782,8 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
  
    /* Go read the symbol.  */
    hdr = &elf_tdata (abfd)->symtab_hdr;
 -  if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
 -			    &isym, esym, &eshndx) == NULL)
 +  if (bfd_elf_get_elf_syms_cached (abfd, hdr, 1, ghdr->sh_info,
-+				   &isym, NULL) == NULL)
++				   &isym, NULL, NULL) == NULL)
      return NULL;
  
    return bfd_elf_sym_name_raw (abfd, hdr, &isym);
-@@ -3029,12 +3120,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
+@@ -3029,12 +3137,11 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
    if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
      {
        Elf_Internal_Shdr *symtab_hdr;
@@ -652,11 +489,12 @@ index bde7414ee21..472fb5da55e 100644
 -      if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
 -				&cache->sym[ent], esym, &eshndx) == NULL)
 +      if (bfd_elf_get_elf_syms_cached (abfd, symtab_hdr, 1, r_symndx,
-+				       &cache->sym[ent], NULL) == NULL)
++				       &cache->sym[ent], NULL, NULL)
++	  == NULL)
  	return NULL;
  
        if (cache->abfd != abfd)
-@@ -10241,6 +10330,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
+@@ -10241,6 +10348,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
  	}
        free (tdata->symtab_hdr.contents);
        tdata->symtab_hdr.contents = NULL;
@@ -665,714 +503,8 @@ index bde7414ee21..472fb5da55e 100644
      }
  
    return _bfd_generic_bfd_free_cached_info (abfd);
-diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
-index ebfe4dcc26a..ed1dd56a59f 100644
---- a/bfd/elf32-arc.c
-+++ b/bfd/elf32-arc.c
-@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
-           if (isymbuf == NULL)
-             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-                                             symtab_hdr->sh_info, 0,
--                                            NULL, NULL, NULL);
-+					    NULL, NULL);
-           if (isymbuf == NULL)
-             goto error_return;
-         }
-diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
-index ae3dc246be0..627c03eb507 100644
---- a/bfd/elf32-arm.c
-+++ b/bfd/elf32-arm.c
-@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
-   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (local_syms == NULL)
-     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
--				       symtab_hdr->sh_info, 0, NULL, NULL,
-+				       symtab_hdr->sh_info, 0, NULL,
- 				       NULL);
-   if (symtab_hdr->sh_info && local_syms == NULL)
-     return false;
-@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
--				  NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
-index 6653e4d72f6..28e41914bd0 100644
---- a/bfd/elf32-avr.c
-+++ b/bfd/elf32-avr.c
-@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
- 					(abfd,
- 					 symtab_hdr,
- 					 symtab_hdr->sh_info, 0,
--					 NULL, NULL, NULL);
-+					 NULL, NULL);
- 				    if (isymbuf == NULL)
- 				      break;
- 				  }
-@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
-index 7ed1285f4c2..8b74a9f3039 100644
---- a/bfd/elf32-bfin.c
-+++ b/bfd/elf32-bfin.c
-@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
-index 31d1ba41c17..3fc4b4adfa1 100644
---- a/bfd/elf32-cr16.c
-+++ b/bfd/elf32-cr16.c
-@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
-index d2bc1f7ba72..03c20aab6cb 100644
---- a/bfd/elf32-crx.c
-+++ b/bfd/elf32-crx.c
-@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
-index 40781a0e1bb..cc93602f5b0 100644
---- a/bfd/elf32-csky.c
-+++ b/bfd/elf32-csky.c
-@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
- 			    bfd_elf_get_elf_syms (input_bfd,
- 						  symtab_hdr,
- 						  symtab_hdr->sh_info,
--						  0, NULL, NULL, NULL);
-+						  0, NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
-index ea60ce4dc72..bace4943dea 100644
---- a/bfd/elf32-epiphany.c
-+++ b/bfd/elf32-epiphany.c
-@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
-index 6ca175533da..ee9294def64 100644
---- a/bfd/elf32-ft32.c
-+++ b/bfd/elf32-ft32.c
-@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
- 		if (isymbuf == NULL)
- 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		if (isymbuf == NULL)
- 		  return false;
- 	      }
-@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		return false;
- 	    }
-@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-       symtab_hdr->contents = (unsigned char *) isymbuf;
-diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
-index e183577fca4..4bd20f9c433 100644
---- a/bfd/elf32-h8300.c
-+++ b/bfd/elf32-h8300.c
-@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
-index 2f463e12829..085b10b8ea9 100644
---- a/bfd/elf32-hppa.c
-+++ b/bfd/elf32-hppa.c
-@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
-index 5c28a06f318..71de071e1ec 100644
---- a/bfd/elf32-ip2k.c
-+++ b/bfd/elf32-ip2k.c
-@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
-index 8f6881bcb0b..bf24f487c44 100644
---- a/bfd/elf32-m32c.c
-+++ b/bfd/elf32-m32c.c
-@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
-   if (free_internal)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
-     }
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+				      symtab_hdr->sh_info, 0, NULL,
-+				      NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
-index f70716d66a2..b4e0a3220ac 100644
---- a/bfd/elf32-m68hc11.c
-+++ b/bfd/elf32-m68hc11.c
-@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
-index 7e8e0383717..9c1bac23549 100644
---- a/bfd/elf32-m68hc1x.c
-+++ b/bfd/elf32-m68hc1x.c
-@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
-index 44ef102ea60..728da0754ab 100644
---- a/bfd/elf32-m68k.c
-+++ b/bfd/elf32-m68k.c
-@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
-index 916f3e15c72..f754af6e3be 100644
---- a/bfd/elf32-metag.c
-+++ b/bfd/elf32-metag.c
-@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
-index db7ed465779..3a526391676 100644
---- a/bfd/elf32-microblaze.c
-+++ b/bfd/elf32-microblaze.c
-@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
-   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
-   if (isymbuf == NULL)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
--				    0, NULL, NULL, NULL);
-+				    0, NULL, NULL);
-   BFD_ASSERT (isymbuf != NULL);
- 
-   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
-diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
-index 3b356bfe4e2..5250f13a8b9 100644
---- a/bfd/elf32-msp430.c
-+++ b/bfd/elf32-msp430.c
-@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	    if (isymbuf == NULL)
- 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      symtab_hdr->sh_info, 0,
--					      NULL, NULL, NULL);
-+					      NULL, NULL);
- 	    if (isymbuf == NULL)
- 	      goto error_return;
- 	  }
-diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
-index e22b58c4ea8..b15626349a8 100644
---- a/bfd/elf32-nds32.c
-+++ b/bfd/elf32-nds32.c
-@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
-   if (isym == NULL)
-     {
-       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
--				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+				   symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) isym;
-     }
- 
-@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
- 	{
- 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  if (*isymbuf_p == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
-index a3adcf8430e..e77e77fd687 100644
---- a/bfd/elf32-ppc.c
-+++ b/bfd/elf32-ppc.c
-@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
-index 45a86be3ccf..e0d9eb507e2 100644
---- a/bfd/elf32-pru.c
-+++ b/bfd/elf32-pru.c
-@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
-index e2ea6b1d15f..3608008c977 100644
---- a/bfd/elf32-rl78.c
-+++ b/bfd/elf32-rl78.c
-@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
-index d8a2236a233..e18eab7bbda 100644
---- a/bfd/elf32-rx.c
-+++ b/bfd/elf32-rx.c
-@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
-   if (!internal_syms)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
-index e078e41b675..022799f389b 100644
---- a/bfd/elf32-sh.c
-+++ b/bfd/elf32-sh.c
-@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
-index de051e48185..eb1ce1c9a12 100644
---- a/bfd/elf32-spu.c
-+++ b/bfd/elf32-spu.c
-@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
-       free (symtab_hdr->contents);
-       symtab_hdr->contents = NULL;
-       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
--				   NULL, NULL, NULL);
-+				   NULL, NULL);
-       symtab_hdr->contents = (void *) syms;
-       if (syms == NULL)
- 	return false;
-diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
-index 27744814691..4d96cf9fbce 100644
---- a/bfd/elf32-v850.c
-+++ b/bfd/elf32-v850.c
-@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
-index 5cee2f389eb..ae043319206 100644
---- a/bfd/elf32-xstormy16.c
-+++ b/bfd/elf32-xstormy16.c
-@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
-index b21676df36a..c554740f357 100644
---- a/bfd/elf32-xtensa.c
-+++ b/bfd/elf32-xtensa.c
-@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
-index b13c99e4958..2b9eede314d 100644
---- a/bfd/elf64-alpha.c
-+++ b/bfd/elf64-alpha.c
-@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
-index 05bb7f125b7..8cd2d918d8b 100644
---- a/bfd/elf64-hppa.c
-+++ b/bfd/elf64-hppa.c
-@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
- 	  if (local_syms == NULL)
- 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					       symtab_hdr->sh_info, 0,
--					       NULL, NULL, NULL);
-+					       NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
-index 822b263ae2c..f6d00fc1826 100644
---- a/bfd/elf64-ia64-vms.c
-+++ b/bfd/elf64-ia64-vms.c
-@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   if (extsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
- 
-diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
-index bb8350718a2..642b2cdb9bb 100644
---- a/bfd/elf64-mmix.c
-+++ b/bfd/elf64-mmix.c
-@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
-index fdda9e0bbb3..ee15d6f0639 100644
---- a/bfd/elf64-ppc.c
-+++ b/bfd/elf64-ppc.c
-@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
- 			  size_t symcnt = symtab_hdr->sh_info;
- 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						      symcnt, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (sym == NULL)
- 			    break;
- 			  symtab_hdr->contents = (bfd_byte *) sym;
-@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
- 		    {
- 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						  1, symndx,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (sym == NULL)
- 			break;
- 		    }
-@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
 diff --git a/bfd/elfcode.h b/bfd/elfcode.h
-index 5224a1abee6..f8176294bc9 100644
+index 5224a1abee6..ae5e814cdcc 100644
 --- a/bfd/elfcode.h
 +++ b/bfd/elfcode.h
 @@ -1302,8 +1302,8 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
@@ -1382,7 +514,7 @@ index 5224a1abee6..f8176294bc9 100644
 -      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
 -				      NULL, NULL, NULL);
 +      isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, symcount, 0,
-+					     NULL, NULL);
++					     NULL, NULL, NULL);
        if (isymbuf == NULL)
  	return -1;
  
@@ -1404,7 +536,7 @@ index 5224a1abee6..f8176294bc9 100644
  }
  
 diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 3f3ea2cce51..0ab843a4924 100644
+index 3f3ea2cce51..1566dcbb677 100644
 --- a/bfd/elflink.c
 +++ b/bfd/elflink.c
 @@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
@@ -1416,7 +548,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  
    if (! is_elf_hash_table (info->hash))
      return 0;
-@@ -868,8 +866,9 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+@@ -868,8 +866,10 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
      return 0;
  
    /* Go find the symbol, so that we can find it's name.  */
@@ -1424,22 +556,23 @@ index 3f3ea2cce51..0ab843a4924 100644
 -			     1, input_indx, &entry->isym, esym, &eshndx))
 +  if (!bfd_elf_get_elf_syms_cached (input_bfd,
 +				    &elf_tdata (input_bfd)->symtab_hdr,
-+				    1, input_indx, &entry->isym, NULL))
++				    1, input_indx, &entry->isym, NULL,
++				    NULL))
      {
        bfd_release (input_bfd, entry);
        return 0;
-@@ -3744,8 +3743,8 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+@@ -3744,8 +3744,8 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
      return false;
  
    /* Read in the symbol table.  */
 -  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
 -				  NULL, NULL, NULL);
 +  isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, extsymcount,
-+					 extsymoff, NULL, NULL);
++					 extsymoff, NULL, NULL, NULL);
    if (isymbuf == NULL)
      return false;
  
-@@ -3767,7 +3766,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+@@ -3767,7 +3767,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
  	}
      }
  
@@ -1448,18 +581,19 @@ index 3f3ea2cce51..0ab843a4924 100644
  
    return result;
  }
-@@ -4829,8 +4828,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -4829,8 +4829,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
    sym_hash = elf_sym_hashes (abfd);
    if (extsymcount != 0)
      {
 -      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
 -				      NULL, NULL, NULL);
 +      isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, extsymcount,
-+					     extsymoff, NULL, NULL);
++					     extsymoff, NULL, NULL,
++					     NULL);
        if (isymbuf == NULL)
  	goto error_return;
  
-@@ -4977,6 +4976,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -4977,6 +4978,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  	(_("%pB: plugin needed to handle lto object"), abfd);
      }
  
@@ -1468,7 +602,7 @@ index 3f3ea2cce51..0ab843a4924 100644
    for (isym = isymbuf, isymend = PTR_ADD (isymbuf, extsymcount);
         isym < isymend;
         isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL))
-@@ -5013,6 +5014,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -5013,6 +5016,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  	{
  	  /* Treat common symbol as undefined for --no-define-common.  */
  	  isym->st_shndx = SHN_UNDEF;
@@ -1476,7 +610,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  	  common = false;
  	}
        discarded = false;
-@@ -5086,6 +5088,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -5086,6 +5090,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  	      sec = bfd_und_section_ptr;
  	      discarded = true;
  	      isym->st_shndx = SHN_UNDEF;
@@ -1484,7 +618,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  	    }
  	  else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
  	    value -= sec->vma;
-@@ -5814,8 +5817,10 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -5814,8 +5819,10 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  
    free (extversym);
    extversym = NULL;
@@ -1497,7 +631,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  
    if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
      {
-@@ -6167,7 +6172,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -6167,7 +6174,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
    free (nondeflt_vers);
    free (extversym);
   error_free_sym:
@@ -1506,29 +640,29 @@ index 3f3ea2cce51..0ab843a4924 100644
   error_return:
    return false;
  }
-@@ -8808,8 +8813,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -8808,8 +8815,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
  
    if (ssymbuf1 == NULL)
      {
 -      isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
 -				       NULL, NULL, NULL);
 +      isymbuf1 = bfd_elf_get_elf_syms_cached (bfd1, hdr1, symcount1,
-+					      0, NULL, NULL);
++					      0, NULL, NULL, NULL);
        if (isymbuf1 == NULL)
  	goto done;
  
-@@ -8822,8 +8827,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -8822,8 +8829,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
  
    if (ssymbuf1 == NULL || ssymbuf2 == NULL)
      {
 -      isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
 -				       NULL, NULL, NULL);
 +      isymbuf2 = bfd_elf_get_elf_syms_cached (bfd2, hdr2, symcount2,
-+					      0, NULL, NULL);
++					      0, NULL, NULL, NULL);
        if (isymbuf2 == NULL)
  	goto done;
  
-@@ -9013,8 +9018,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -9013,8 +9020,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
   done:
    free (symtable1);
    free (symtable2);
@@ -1537,7 +671,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  
    return result;
  }
-@@ -9056,14 +9059,6 @@ struct elf_final_link_info
+@@ -9056,14 +9061,6 @@ struct elf_final_link_info
    void *external_relocs;
    /* Buffer large enough to hold internal relocs of any section.  */
    Elf_Internal_Rela *internal_relocs;
@@ -1552,27 +686,19 @@ index 3f3ea2cce51..0ab843a4924 100644
    /* Array large enough to hold a symbol index for each local symbol
       of any input BFD.  */
    long *indices;
-@@ -10665,8 +10660,8 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+@@ -10665,8 +10662,9 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
        if (extsymcount == 0)
  	continue;
  
 -      isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
 -				      NULL, NULL, NULL);
 +      isymbuf = bfd_elf_get_elf_syms_cached (input, hdr, extsymcount,
-+					     extsymoff, NULL, NULL);
++					     extsymoff, NULL, NULL,
++					     NULL);
        if (isymbuf == NULL)
  	return false;
  
-@@ -11410,7 +11405,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
-   Elf_Internal_Shdr *symtab_hdr;
-   size_t locsymcount;
-   size_t extsymoff;
--  Elf_Internal_Sym *isymbuf;
-+  Elf_Internal_Sym *isymbuf = NULL;
-   Elf_Internal_Sym *isym;
-   Elf_Internal_Sym *isymend;
-   long *pindex;
-@@ -11459,10 +11454,8 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+@@ -11459,10 +11457,9 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
    isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
    if (isymbuf == NULL && locsymcount != 0)
      {
@@ -1581,11 +707,12 @@ index 3f3ea2cce51..0ab843a4924 100644
 -				      flinfo->external_syms,
 -				      flinfo->locsym_shndx);
 +      isymbuf = bfd_elf_get_elf_syms_cached (input_bfd, symtab_hdr,
-+					     locsymcount, 0, NULL, NULL);
++					     locsymcount, 0, NULL, NULL,
++					     NULL);
        if (isymbuf == NULL)
  	return false;
      }
-@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
+@@ -12632,9 +12629,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
    free (flinfo->contents);
    free (flinfo->external_relocs);
    free (flinfo->internal_relocs);
@@ -1595,7 +722,7 @@ index 3f3ea2cce51..0ab843a4924 100644
    free (flinfo->indices);
    free (flinfo->sections);
    if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
-@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -12663,7 +12657,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
    bfd_size_type max_external_reloc_size;
    bfd_size_type max_internal_reloc_count;
    bfd_size_type max_sym_count;
@@ -1603,7 +730,21 @@ index 3f3ea2cce51..0ab843a4924 100644
    Elf_Internal_Sym elfsym;
    unsigned int i;
    Elf_Internal_Shdr *symtab_hdr;
-@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -12697,12 +12690,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+   if (flinfo.symstrtab == NULL)
+     return false;
+ 
+-  if (! dynamic)
+-    {
+-      flinfo.hash_sec = NULL;
+-      flinfo.symver_sec = NULL;
+-    }
+-  else
++  if (dynamic)
+     {
+       flinfo.hash_sec = bfd_get_linker_section (dynobj, ".hash");
+       /* Note that dynsym_sec can be NULL (on VMS).  */
+@@ -12792,7 +12780,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
      }
    max_internal_reloc_count = 0;
    max_sym_count = 0;
@@ -1611,7 +752,7 @@ index 3f3ea2cce51..0ab843a4924 100644
    merged = false;
    for (o = abfd->sections; o != NULL; o = o->next)
      {
-@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -12854,10 +12841,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
  		  if (sym_count > max_sym_count)
  		    max_sym_count = sym_count;
  
@@ -1622,7 +763,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  		  esdi = elf_section_data (sec);
  
  		  if (esdi->this_hdr.sh_type == SHT_REL
-@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -13118,16 +13101,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
  
    if (max_sym_count != 0)
      {
@@ -1639,7 +780,7 @@ index 3f3ea2cce51..0ab843a4924 100644
        amt = max_sym_count * sizeof (long);
        flinfo.indices = (long int *) bfd_malloc (amt);
        if (flinfo.indices == NULL)
-@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -13139,14 +13112,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
  	goto error_return;
      }
  
@@ -1654,7 +795,7 @@ index 3f3ea2cce51..0ab843a4924 100644
    if (htab->tls_sec)
      {
        bfd_vma base, end = 0;  /* Both bytes.  */
-@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+@@ -13890,8 +13855,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
  
  static bool
  init_reloc_cookie (struct elf_reloc_cookie *cookie,
@@ -1664,7 +805,7 @@ index 3f3ea2cce51..0ab843a4924 100644
  {
    Elf_Internal_Shdr *symtab_hdr;
    const struct elf_backend_data *bed;
-@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+@@ -13918,39 +13882,21 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
    else
      cookie->r_sym_shift = 32;
  
@@ -1677,7 +818,8 @@ index 3f3ea2cce51..0ab843a4924 100644
 -					      NULL, NULL, NULL);
 +      cookie->locsyms = bfd_elf_get_elf_syms_cached (abfd, symtab_hdr,
 +						     cookie->locsymcount,
-+						     0, NULL, NULL);
++						     0, NULL, NULL,
++						     NULL);
        if (cookie->locsyms == NULL)
  	{
  	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
@@ -1828,95 +970,8 @@ index 3f3ea2cce51..0ab843a4924 100644
  	}
      }
  
-diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
-index 3c3c2899674..553ba27b604 100644
---- a/bfd/elfnn-aarch64.c
-+++ b/bfd/elfnn-aarch64.c
-@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
- 			local_syms
- 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (local_syms == NULL)
- 			goto error_ret_free_internal;
- 		    }
-@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
-index 528b1dcdcc3..48fce2380cd 100644
---- a/bfd/elfnn-ia64.c
-+++ b/bfd/elfnn-ia64.c
-@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
-index 3b44db57421..8e75b400570 100644
---- a/bfd/elfnn-kvx.c
-+++ b/bfd/elfnn-kvx.c
-@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
-index 53cdb783859..10a4f99add7 100644
---- a/bfd/elfnn-loongarch.c
-+++ b/bfd/elfnn-loongarch.c
-@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
-       && !(symtab_hdr->contents =
- 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						   symtab_hdr->sh_info,
--						   0, NULL, NULL, NULL)))
-+						   0, NULL, NULL)))
-     return true;
- 
-   /* Estimate the maximum alignment for all output sections once time
-diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
-index 09cf7076733..d1ab410a94f 100644
---- a/bfd/elfnn-riscv.c
-+++ b/bfd/elfnn-riscv.c
-@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
- 	  && !(symtab_hdr->contents =
- 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						       symtab_hdr->sh_info,
--						       0, NULL, NULL, NULL)))
-+						       0, NULL, NULL)))
- 	goto fail;
- 
-       /* Get the value of the symbol referred to by the reloc.  */
-diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
-index 00ef0663728..44c58362dda 100644
---- a/bfd/elfxx-mips.c
-+++ b/bfd/elfxx-mips.c
-@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
 diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index 140e86888a6..3f397f5cf70 100644
+index 140e86888a6..a44b0bb9124 100644
 --- a/bfd/elfxx-x86.c
 +++ b/bfd/elfxx-x86.c
 @@ -1157,9 +1157,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
@@ -1929,7 +984,7 @@ index 140e86888a6..3f397f5cf70 100644
 +		  isymbuf
 +		    = bfd_elf_get_elf_syms_cached (abfd, symtab_hdr,
 +						   symtab_hdr->sh_info,
-+						   0, NULL, NULL);
++						   0, NULL, NULL, NULL);
  		  if (isymbuf == NULL)
  		    goto error_return;
  		}
@@ -1958,7 +1013,7 @@ index 140e86888a6..3f397f5cf70 100644
    if (elf_section_data (input_section)->relocs != internal_relocs)
      free (internal_relocs);
 diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
-index 7241de70709..2ec91ffb0bf 100644
+index 7241de70709..0cabab8dc1f 100644
 --- a/libctf/ctf-open-bfd.c
 +++ b/libctf/ctf-open-bfd.c
 @@ -145,9 +145,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
@@ -1969,13 +1024,11 @@ index 7241de70709..2ec91ffb0bf 100644
 -				      NULL, symtab, NULL);
 -      free (isymbuf);
 +      isymbuf = bfd_elf_get_elf_syms_cached (abfd, symhdr, symcount, 0,
-+					     NULL, symtab);
++					     NULL, symtab, NULL);
 +      bfd_elf_free_symtab (abfd);
        if (isymbuf == NULL)
  	{
  	  bfderrstr = N_("cannot read symbol table");
-
-base-commit: 552ddbabb5d28b301c660ddeecae19510ed4aa30
 -- 
 2.51.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-11  0:46 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-11  0:46 UTC (permalink / raw
  To: gentoo-commits

commit:     4abaf649adf4919486a0db9fa8d49a5e449315bc
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 11 00:45:23 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Oct 11 00:46:48 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=4abaf649

Revert "9999: patch still fails tests"

This reverts commit 279ad384a8d621f9a25985f2bf67803123940e4c.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1885 ++++++++++++++++++++
 1 file changed, 1885 insertions(+)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
new file mode 100644
index 0000000..acae3cf
--- /dev/null
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -0,0 +1,1885 @@
+From 13058a8b8feb26ddafb62995f164d81dce02979c Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Thu, 9 Oct 2025 13:16:19 +0800
+Subject: [PATCH] elf: Cache full internal symbol table for relocatable input
+
+Cache internal symbol table for relocatable input and use the internal
+symbol table cache for both local and global symbols to avoid swapping in
+the same symbol table repeatedly for --gc-sections.  This improves linker
+--gc-sections speed by ~20x.
+
+Most backends cache the local symbol table in symtab_hdr->contents. But
+some backends cache something else in it.  Since symtab_hdr->contents may
+point to the middle of the internal symbol table cache, we can release
+symtab_hdr->contents only when no backends cache the local symbol table
+in it.
+
+bfd/
+
+	PR ld/33530
+	* elf-bfd.h (elf_obj_tdata): Add symtab and keep_symtab.
+	(bfd_elf_get_elf_syms): Remove the Elf_External_Sym_Shndx pointer
+	argument.
+	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
+	return void.
+	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
+	internal symbol table in symtab_hdr.
+	* elf-m10200.c (mn10200_elf_relax_section): Drop the last argument
+	to bfd_elf_get_elf_syms.
+	(mn10200_elf_get_relocated_section_contents): Likewise.
+	* elf-m10300.c (mn10300_elf_check_relocs): Likewise.
+	(mn10300_elf_relax_section): Likewise.
+	(mn10300_elf_get_relocated_section_contents): Likewise.
+	* elf32-arc.c (arc_elf_relax_section): Likewise.
+	* elf32-arm.c (cmse_scan): Likewise.
+	(elf32_arm_size_stubs): Likewise.
+	(bfd_elf32_arm_init_maps): Likewise.
+	* elf32-avr.c (elf32_avr_relax_delete_bytes): Likewise.
+	(retrieve_local_syms): Likewise.
+	(elf32_avr_relax_section): Likewise.
+	(elf32_avr_get_relocated_section_contents): Likewise.
+	(get_local_syms): Likewise.
+	* elf32-bfin.c (bfd_bfin_elf32_create_embedded_relocs): Likewise.
+	* elf32-cr16.c (elf32_cr16_get_relocated_section_contents):
+	Likewise.
+	(elf32_cr16_relax_section): Likewise.
+	(bfd_cr16_elf32_create_embedded_relocs): Likewise.
+	* elf32-crx.c (elf32_crx_get_relocated_section_contents):
+	Likewise.
+	(elf32_crx_relax_section): Likewise.
+	* elf32-csky.c (elf32_csky_size_stubs): Likewise.
+	* elf32-epiphany.c (epiphany_elf_relax_section): Likewise.
+	* elf32-ft32.c (elf32_ft32_relax_delete_bytes): Likewise.
+	(elf32_ft32_relax_is_branch_target): Likewise.
+	(ft32_elf_relax_section): Likewise.
+	* elf32-h8300.c (elf32_h8_relax_section): Likewise.
+	(elf32_h8_get_relocated_section_contents): Likewise.
+	* elf32-hppa.c (get_local_syms): Likewise.
+	* elf32-ip2k.c (ip2k_elf_relax_section): Likewise.
+	* elf32-m32c.c (dump_symtab): Likewise.
+	(m32c_elf_relax_plt_section): Likewise.
+	(m32c_elf_relax_section): Likewise.
+	* elf32-m68hc11.c (m68hc11_elf_relax_section): Likewise.
+	* elf32-m68hc1x.c (elf32_m68hc11_size_stubs): Likewise.
+	* elf32-m68k.c (bfd_m68k_elf32_create_embedded_relocs): Likewise.
+	* elf32-metag.c (get_local_syms): Likewise.
+	* elf32-microblaze.c (microblaze_elf_relax_section): Likewise.
+	* elf32-msp430.c (msp430_elf_relax_section): Likewise.
+	* elf32-nds32.c (nds32_elf_relax_delete_blanks): Likewise.
+	(nds32_get_local_syms): Likewise.
+	* elf32-ppc.c (get_sym_h): Likewise.
+	(ppc_elf_late_size_sections): Likewise.
+	* elf32-pru.c (pru_elf_relax_delete_bytes): Likewise.
+	(pru_elf32_relax_section): Likewise.
+	* elf32-rl78.c (rl78_elf_relax_plt_section): Likewise.
+	(rl78_elf_relax_section): Likewise.
+	* elf32-rx.c (elf32_rx_relax_section): Likewise.
+	(rx_dump_symtab): Likewise.
+	* elf32-sh.c (sh_elf_relax_section): Likewise.
+	(sh_elf_get_relocated_section_contents): Likewise.
+	* elf32-spu.c (get_sym_h): Likewise.
+	(discover_functions): Likewise.
+	* elf32-v850.c (v850_elf_relax_section): Likewise.
+	* elf32-xstormy16.c (xstormy16_elf_relax_section): Likewise.
+	* elf32-xtensa.c (retrieve_local_syms): Likewise.
+	* elf64-alpha.c (elf64_alpha_relax_section): Likewise.
+	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
+	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
+	(elf64_vms_link_add_object_symbols): Likewise.
+	* elf64-mmix.c (mmix_elf_relax_section): Likewise.
+	* elf64-ppc.c (opd_entry_value): Likewise.
+	(get_sym_h): Likewise.
+	(ppc64_elf_late_size_sections): Likewise.
+	(ppc64_elf_layout_multitoc): Likewise.
+	(got_and_plt_relr_for_local_syms): Likewise.
+	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
+	(bfd_elfNN_aarch64_init_maps): Likewise.
+	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
+	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
+	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
+	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
+	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
+	pointer argument.  Only allow the full external symbol table.
+	Cache internal symbol table.
+	(group_signature): Update the bfd_elf_get_elf_syms call.
+	(bfd_sym_from_r_symndx): Likewise.
+	(_bfd_elf_free_cached_info): Free internal symbol table cache.
+	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
+	buffer.
+	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Update
+	the bfd_elf_get_elf_syms call.
+	(elf_link_is_defined_archive_symbol): Likewise.  Free cached
+	internal symbol buffer unless it should be kept.
+	(elf_link_add_object_symbols): Update the bfd_elf_get_elf_syms
+	call.  Free cached internal symbol buffer.
+	(bfd_elf_match_symbols_in_sections): Update the
+	bfd_elf_get_elf_syms call.  Don't free the internal symbol table.
+	(elf_final_link_info): Remove external_syms, locsym_shndx and
+	internal_syms.
+	(elf_link_check_versioned_symbol): Update the bfd_elf_get_elf_syms
+	call.
+	(elf_link_input_bfd): Likewise.  Don't use symtab_hdr->contents
+	for internal symbol table.
+	(elf_final_link_free): Updated.
+	(bfd_elf_final_link): Don't set flinfo.external_syms,
+	flinfo.internal_syms nor flinfo.locsym_shndx.
+	(init_reloc_cookie): Remove the keep_memory argument.  Don't
+	cache internal symbol table in symtab_hdr.
+	(fini_reloc_cookie): Removed.
+	(init_reloc_cookie_for_section): Don't call fini_reloc_cookie on
+	error.
+	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
+	fini_reloc_cookie_rels.
+	(bfd_elf_gc_sections): Likewise.  Free the internal symbol table
+	cache.
+	(bfd_elf_discard_info): Replace fini_reloc_cookie_for_section with
+	fini_reloc_cookie_rels.  Don't call fini_reloc_cookie.
+	(bfd_elf_parse_eh_frame_entries): Updated.
+	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
+	use symtab_hdr->contents for internal symbol table.  Set
+	keep_symtab if the symbol table has been updated.
+
+libctf/
+
+	PR ld/33530
+	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
+	table cache.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-bfd.h          |  11 ++-
+ bfd/elf-eh-frame.c     |  17 ++---
+ bfd/elf-m10200.c       |   4 +-
+ bfd/elf-m10300.c       |  10 +--
+ bfd/elf.c              | 131 ++++++++++++++++++++++++++---------
+ bfd/elf32-arc.c        |   2 +-
+ bfd/elf32-arm.c        |   7 +-
+ bfd/elf32-avr.c        |  12 ++--
+ bfd/elf32-bfin.c       |   2 +-
+ bfd/elf32-cr16.c       |   6 +-
+ bfd/elf32-crx.c        |   4 +-
+ bfd/elf32-csky.c       |   2 +-
+ bfd/elf32-epiphany.c   |   2 +-
+ bfd/elf32-ft32.c       |   6 +-
+ bfd/elf32-h8300.c      |   4 +-
+ bfd/elf32-hppa.c       |   2 +-
+ bfd/elf32-ip2k.c       |   2 +-
+ bfd/elf32-m32c.c       |   8 ++-
+ bfd/elf32-m68hc11.c    |   2 +-
+ bfd/elf32-m68hc1x.c    |   2 +-
+ bfd/elf32-m68k.c       |   2 +-
+ bfd/elf32-metag.c      |   2 +-
+ bfd/elf32-microblaze.c |   2 +-
+ bfd/elf32-msp430.c     |   4 +-
+ bfd/elf32-nds32.c      |   4 +-
+ bfd/elf32-ppc.c        |   4 +-
+ bfd/elf32-pru.c        |   4 +-
+ bfd/elf32-rl78.c       |   4 +-
+ bfd/elf32-rx.c         |   4 +-
+ bfd/elf32-sh.c         |   4 +-
+ bfd/elf32-spu.c        |   4 +-
+ bfd/elf32-v850.c       |   2 +-
+ bfd/elf32-xstormy16.c  |   2 +-
+ bfd/elf32-xtensa.c     |   2 +-
+ bfd/elf64-alpha.c      |   2 +-
+ bfd/elf64-hppa.c       |   2 +-
+ bfd/elf64-ia64-vms.c   |   4 +-
+ bfd/elf64-mmix.c       |   2 +-
+ bfd/elf64-ppc.c        |  12 ++--
+ bfd/elfcode.h          |   8 +--
+ bfd/elflink.c          | 152 ++++++++++++-----------------------------
+ bfd/elfnn-aarch64.c    |   4 +-
+ bfd/elfnn-ia64.c       |   2 +-
+ bfd/elfnn-kvx.c        |   2 +-
+ bfd/elfnn-loongarch.c  |   2 +-
+ bfd/elfnn-riscv.c      |   2 +-
+ bfd/elfxx-mips.c       |   2 +-
+ bfd/elfxx-x86.c        |  24 +++----
+ libctf/ctf-open-bfd.c  |   5 +-
+ 49 files changed, 243 insertions(+), 262 deletions(-)
+
+diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
+index 5d19529d972..b7061e55b59 100644
+--- a/bfd/elf-bfd.h
++++ b/bfd/elf-bfd.h
+@@ -2165,6 +2165,11 @@ struct elf_obj_tdata
+   /* Symbol buffer.  */
+   void *symbuf;
+ 
++  /* A pointer to the full internal symbol table of input relocatable
++     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
++     all backends use it to only cache local symbols.  */
++  Elf_Internal_Sym *symtab;
++
+   /* List of GNU properties.  Will be updated by setup_gnu_properties
+      after all input GNU properties are merged for output.  */
+   elf_property_list *properties;
+@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
+      symbols.  */
+   unsigned int bad_symtab : 1;
+ 
++  /* Set if the symbol table cache should be kept.  */
++  unsigned int keep_symtab : 1;
++
+   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
+   unsigned int is_pie : 1;
+ 
+@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
+ extern char *bfd_elf_string_from_elf_section
+   (bfd *, unsigned, unsigned);
+ extern Elf_Internal_Sym *bfd_elf_get_elf_syms
+-  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
+-   Elf_External_Sym_Shndx *);
++  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
+ extern char * bfd_elf_get_str_section (bfd *, unsigned int);
+ extern const char *bfd_elf_sym_name
+   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
+diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
+index 4eda3c991bb..bd2c85291fb 100644
+--- a/bfd/elf-eh-frame.c
++++ b/bfd/elf-eh-frame.c
+@@ -1448,12 +1448,10 @@ _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *h,
+ /* The same for all local symbols defined in .eh_frame.  Returns true
+    if any symbol was changed.  */
+ 
+-static int
++static void
+ adjust_eh_frame_local_symbols (const asection *sec,
+ 			       struct elf_reloc_cookie *cookie)
+ {
+-  int adjusted = 0;
+-
+   if (cookie->locsymcount > 1)
+     {
+       unsigned int shndx = elf_section_data (sec)->this_idx;
+@@ -1467,13 +1465,9 @@ adjust_eh_frame_local_symbols (const asection *sec,
+ 	    bfd_signed_vma delta = offset_adjust (sym->st_value, sec);
+ 
+ 	    if (delta != 0)
+-	      {
+-		adjusted = 1;
+-		sym->st_value += delta;
+-	      }
++	      sym->st_value += delta;
+ 	  }
+     }
+-  return adjusted;
+ }
+ 
+ /* This function is called for each input file before the .eh_frame
+@@ -1611,11 +1605,8 @@ _bfd_elf_discard_section_eh_frame
+   if (sec->size != sec->rawsize)
+     changed = 1;
+ 
+-  if (changed && adjust_eh_frame_local_symbols (sec, cookie))
+-    {
+-      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-      symtab_hdr->contents = (unsigned char *) cookie->locsyms;
+-    }
++  if (changed)
++    adjust_eh_frame_local_symbols (sec, cookie);
+   return changed;
+ }
+ 
+diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
+index ca9a92e1221..4da86774ee2 100644
+--- a/bfd/elf-m10200.c
++++ b/bfd/elf-m10200.c
+@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
+index b381bb9037c..373290cbe4a 100644
+--- a/bfd/elf-m10300.c
++++ b/bfd/elf-m10300.c
+@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
+ 		  if (isymbuf == NULL)
+ 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						    symtab_hdr->sh_info, 0,
+-						    NULL, NULL, NULL);
++						    NULL, NULL);
+ 		  if (isymbuf)
+ 		    {
+ 		      isym = isymbuf + r_symndx;
+@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf.c b/bfd/elf.c
+index bde7414ee21..9e220f0a0d7 100644
+--- a/bfd/elf.c
++++ b/bfd/elf.c
+@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
+ }
+ 
+ /* Read and convert symbols to internal format.
+-   SYMCOUNT specifies the number of symbols to read, starting from
+-   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
++   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
++   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
+    are non-NULL, they are used to store the internal symbols, external
+-   symbols, and symbol section index extensions, respectively.
+-   Returns a pointer to the internal symbol buffer (malloced if necessary)
+-   or NULL if there were no symbols or some kind of problem.  */
++   symbols, and symbol section index extensions, respectively.  Returns
++   a pointer to the internal symbol buffer (malloced if necessary) or
++   NULL if there were no symbols or some kind of problem.  */
+ 
+ Elf_Internal_Sym *
+ bfd_elf_get_elf_syms (bfd *ibfd,
+ 		      Elf_Internal_Shdr *symtab_hdr,
+-		      size_t symcount,
+-		      size_t symoffset,
++		      size_t partial_symcount,
++		      size_t partial_symoffset,
+ 		      Elf_Internal_Sym *intsym_buf,
+-		      void *extsym_buf,
+-		      Elf_External_Sym_Shndx *extshndx_buf)
++		      void *partial_extsym_buf)
+ {
+   Elf_Internal_Shdr *shndx_hdr;
+   void *alloc_ext;
+@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+   const struct elf_backend_data *bed;
+   size_t extsym_size;
+   size_t amt;
+-  file_ptr pos;
++  file_ptr pos = 0;
++  size_t symcount = partial_symcount;
++  size_t symoffset = partial_symoffset;
++  void *extsym_buf = NULL;
++  Elf_External_Sym_Shndx *extshndx_buf = NULL;
++  bool cache_symtab = false;
+ 
+   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+     abort ();
+@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+       return elf_tdata (ibfd)->dt_symtab + symoffset;
+     }
+ 
++  if (elf_tdata (ibfd)->symtab != NULL)
++    {
++      /* NB: Should extsym_buf be cached?  */
++      if (partial_extsym_buf != NULL)
++	abort ();
++
++      if (intsym_buf != NULL)
++	{
++	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
++		  symcount * sizeof (*intsym_buf));
++	  return intsym_buf;
++	}
++      else
++	return elf_tdata (ibfd)->symtab + symoffset;
++    }
++
+   /* Normal syms might have section extension entries.  */
+   shndx_hdr = NULL;
+   if (elf_symtab_shndx_list (ibfd) != NULL)
+@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
++  if (elf_elfheader (ibfd)->e_type == ET_REL
++      && symtab_hdr->sh_entsize != 0)
++    {
++      symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
++      symoffset = 0;
++      cache_symtab = true;
++    }
++
+   /* Read the symbols.  */
+   alloc_ext = NULL;
+   alloc_extshndx = NULL;
+   alloc_intsym = NULL;
+   bed = get_elf_backend_data (ibfd);
+   extsym_size = bed->s->sizeof_sym;
+-  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
++  size_t extsym_buf_size;
++  if (_bfd_mul_overflow (symcount, extsym_size, &extsym_buf_size))
+     {
+       bfd_set_error (bfd_error_file_too_big);
+       return NULL;
+     }
+-  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
+-  size_t alloc_ext_size = amt;
++  if (cache_symtab)
++    pos = symtab_hdr->sh_offset;
++  else
++    pos = symtab_hdr->sh_offset + symoffset * extsym_size;
++  size_t alloc_ext_size = extsym_buf_size;
+   if (bfd_seek (ibfd, pos, SEEK_SET) != 0
+       || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
+ 				    &alloc_ext, ibfd, false))
+@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
+-  if (intsym_buf == NULL)
++  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+     {
+-      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+-	{
+-	  bfd_set_error (bfd_error_file_too_big);
+-	  goto out1;
+-	}
+-      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      intsym_buf = alloc_intsym;
+-      if (intsym_buf == NULL)
+-	goto out1;
++      bfd_set_error (bfd_error_file_too_big);
++      goto out1;
+     }
++  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
++  if (alloc_intsym == NULL)
++    {
++      intsym_buf = NULL;
++      goto out1;
++    }
++
++  if (intsym_buf == NULL)
++    intsym_buf = alloc_intsym;
+ 
+   /* Convert the symbols to internal form.  */
+-  isymend = intsym_buf + symcount;
+-  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
++  isymend = alloc_intsym + symcount;
++  for (esym = (const bfd_byte *) extsym_buf, isym = alloc_intsym,
+ 	   shndx = extshndx_buf;
+        isym < isymend;
+        esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
+@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{	
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), bind);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      bind);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), t);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      t);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+ 	}
+     }
+ 
++  if (intsym_buf != NULL && partial_extsym_buf != NULL)
++    {
++      if (partial_symcount != symcount)
++	abort ();
++      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
++    }
++
+  out1:
+   _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
+  out2:
+   _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
+ 
+-  return intsym_buf;
++  if (intsym_buf == NULL)
++    return intsym_buf;
++
++  if (!cache_symtab)
++    return intsym_buf;
++
++  elf_tdata (ibfd)->symtab = alloc_intsym;
++  if (intsym_buf != alloc_intsym)
++    {
++      memcpy (intsym_buf, alloc_intsym + partial_symoffset,
++	      partial_symcount * sizeof (*intsym_buf));
++      return intsym_buf;
++    }
++  else
++    return alloc_intsym + partial_symoffset;
+ }
+ 
+ /* Look up a symbol name.  */
+@@ -659,8 +718,6 @@ static const char *
+ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+ {
+   Elf_Internal_Shdr *hdr;
+-  unsigned char esym[sizeof (Elf64_External_Sym)];
+-  Elf_External_Sym_Shndx eshndx;
+   Elf_Internal_Sym isym;
+ 
+   /* First we need to ensure the symbol table is available.  Make sure
+@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+   /* Go read the symbol.  */
+   hdr = &elf_tdata (abfd)->symtab_hdr;
+   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
+-			    &isym, esym, &eshndx) == NULL)
++			    &isym, NULL) == NULL)
+     return NULL;
+ 
+   return bfd_elf_sym_name_raw (abfd, hdr, &isym);
+@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
+   if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
+     {
+       Elf_Internal_Shdr *symtab_hdr;
+-      unsigned char esym[sizeof (Elf64_External_Sym)];
+-      Elf_External_Sym_Shndx eshndx;
+ 
+       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
+-				&cache->sym[ent], esym, &eshndx) == NULL)
++				&cache->sym[ent], NULL) == NULL)
+ 	return NULL;
+ 
+       if (cache->abfd != abfd)
+@@ -10239,8 +10294,16 @@ _bfd_elf_free_cached_info (bfd *abfd)
+ 	      free (sec_info->cies);
+ 	    }
+ 	}
++#if 0
++      /* NB: tdata->symtab_hdr.contents may point to the middle of
++	 tdata->symtab.  Need to update all backends only to cache
++	 the malloced memory in tdata->symtab_hdr.contents before
++	 tdata->symtab_hdr.contents can be freed.  */
+       free (tdata->symtab_hdr.contents);
+       tdata->symtab_hdr.contents = NULL;
++#endif
++      free (tdata->symtab);
++      tdata->symtab = NULL;
+     }
+ 
+   return _bfd_generic_bfd_free_cached_info (abfd);
+diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
+index ebfe4dcc26a..ed1dd56a59f 100644
+--- a/bfd/elf32-arc.c
++++ b/bfd/elf32-arc.c
+@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
+           if (isymbuf == NULL)
+             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+                                             symtab_hdr->sh_info, 0,
+-                                            NULL, NULL, NULL);
++					    NULL, NULL);
+           if (isymbuf == NULL)
+             goto error_return;
+         }
+diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
+index ae3dc246be0..627c03eb507 100644
+--- a/bfd/elf32-arm.c
++++ b/bfd/elf32-arm.c
+@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
+   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (local_syms == NULL)
+     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+-				       symtab_hdr->sh_info, 0, NULL, NULL,
++				       symtab_hdr->sh_info, 0, NULL,
+ 				       NULL);
+   if (symtab_hdr->sh_info && local_syms == NULL)
+     return false;
+@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
+-				  NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
+index 6653e4d72f6..28e41914bd0 100644
+--- a/bfd/elf32-avr.c
++++ b/bfd/elf32-avr.c
+@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 					(abfd,
+ 					 symtab_hdr,
+ 					 symtab_hdr->sh_info, 0,
+-					 NULL, NULL, NULL);
++					 NULL, NULL);
+ 				    if (isymbuf == NULL)
+ 				      break;
+ 				  }
+@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
+index 7ed1285f4c2..8b74a9f3039 100644
+--- a/bfd/elf32-bfin.c
++++ b/bfd/elf32-bfin.c
+@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
+index 31d1ba41c17..3fc4b4adfa1 100644
+--- a/bfd/elf32-cr16.c
++++ b/bfd/elf32-cr16.c
+@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
+index d2bc1f7ba72..03c20aab6cb 100644
+--- a/bfd/elf32-crx.c
++++ b/bfd/elf32-crx.c
+@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
+index 40781a0e1bb..cc93602f5b0 100644
+--- a/bfd/elf32-csky.c
++++ b/bfd/elf32-csky.c
+@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
+ 			    bfd_elf_get_elf_syms (input_bfd,
+ 						  symtab_hdr,
+ 						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
++						  0, NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
+index ea60ce4dc72..bace4943dea 100644
+--- a/bfd/elf32-epiphany.c
++++ b/bfd/elf32-epiphany.c
+@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
+index 6ca175533da..ee9294def64 100644
+--- a/bfd/elf32-ft32.c
++++ b/bfd/elf32-ft32.c
+@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
+ 		if (isymbuf == NULL)
+ 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		if (isymbuf == NULL)
+ 		  return false;
+ 	      }
+@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		return false;
+ 	    }
+@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+       symtab_hdr->contents = (unsigned char *) isymbuf;
+diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
+index e183577fca4..4bd20f9c433 100644
+--- a/bfd/elf32-h8300.c
++++ b/bfd/elf32-h8300.c
+@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
+index 2f463e12829..085b10b8ea9 100644
+--- a/bfd/elf32-hppa.c
++++ b/bfd/elf32-hppa.c
+@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
+index 5c28a06f318..71de071e1ec 100644
+--- a/bfd/elf32-ip2k.c
++++ b/bfd/elf32-ip2k.c
+@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
+index 8f6881bcb0b..bf24f487c44 100644
+--- a/bfd/elf32-m32c.c
++++ b/bfd/elf32-m32c.c
+@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
+   if (free_internal)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
+     }
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++				      symtab_hdr->sh_info, 0, NULL,
++				      NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
+index f70716d66a2..b4e0a3220ac 100644
+--- a/bfd/elf32-m68hc11.c
++++ b/bfd/elf32-m68hc11.c
+@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
+index 7e8e0383717..9c1bac23549 100644
+--- a/bfd/elf32-m68hc1x.c
++++ b/bfd/elf32-m68hc1x.c
+@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
+index 44ef102ea60..728da0754ab 100644
+--- a/bfd/elf32-m68k.c
++++ b/bfd/elf32-m68k.c
+@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
+index 916f3e15c72..f754af6e3be 100644
+--- a/bfd/elf32-metag.c
++++ b/bfd/elf32-metag.c
+@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
+index db7ed465779..3a526391676 100644
+--- a/bfd/elf32-microblaze.c
++++ b/bfd/elf32-microblaze.c
+@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
+   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
+   if (isymbuf == NULL)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
+-				    0, NULL, NULL, NULL);
++				    0, NULL, NULL);
+   BFD_ASSERT (isymbuf != NULL);
+ 
+   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
+diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
+index 3b356bfe4e2..5250f13a8b9 100644
+--- a/bfd/elf32-msp430.c
++++ b/bfd/elf32-msp430.c
+@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	    if (isymbuf == NULL)
+ 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      symtab_hdr->sh_info, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+ 	    if (isymbuf == NULL)
+ 	      goto error_return;
+ 	  }
+diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
+index e22b58c4ea8..b15626349a8 100644
+--- a/bfd/elf32-nds32.c
++++ b/bfd/elf32-nds32.c
+@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
+   if (isym == NULL)
+     {
+       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++				   symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) isym;
+     }
+ 
+@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
+ 	{
+ 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  if (*isymbuf_p == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
+index a3adcf8430e..e77e77fd687 100644
+--- a/bfd/elf32-ppc.c
++++ b/bfd/elf32-ppc.c
+@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
+index 45a86be3ccf..e0d9eb507e2 100644
+--- a/bfd/elf32-pru.c
++++ b/bfd/elf32-pru.c
+@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
+index e2ea6b1d15f..3608008c977 100644
+--- a/bfd/elf32-rl78.c
++++ b/bfd/elf32-rl78.c
+@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
+index d8a2236a233..e18eab7bbda 100644
+--- a/bfd/elf32-rx.c
++++ b/bfd/elf32-rx.c
+@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
+   if (!internal_syms)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
+index e078e41b675..022799f389b 100644
+--- a/bfd/elf32-sh.c
++++ b/bfd/elf32-sh.c
+@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
+index de051e48185..eb1ce1c9a12 100644
+--- a/bfd/elf32-spu.c
++++ b/bfd/elf32-spu.c
+@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
+       free (symtab_hdr->contents);
+       symtab_hdr->contents = NULL;
+       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
+-				   NULL, NULL, NULL);
++				   NULL, NULL);
+       symtab_hdr->contents = (void *) syms;
+       if (syms == NULL)
+ 	return false;
+diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
+index 27744814691..4d96cf9fbce 100644
+--- a/bfd/elf32-v850.c
++++ b/bfd/elf32-v850.c
+@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
+index 5cee2f389eb..ae043319206 100644
+--- a/bfd/elf32-xstormy16.c
++++ b/bfd/elf32-xstormy16.c
+@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
+index b21676df36a..c554740f357 100644
+--- a/bfd/elf32-xtensa.c
++++ b/bfd/elf32-xtensa.c
+@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
+index b13c99e4958..2b9eede314d 100644
+--- a/bfd/elf64-alpha.c
++++ b/bfd/elf64-alpha.c
+@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
+index 05bb7f125b7..8cd2d918d8b 100644
+--- a/bfd/elf64-hppa.c
++++ b/bfd/elf64-hppa.c
+@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
+ 	  if (local_syms == NULL)
+ 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					       symtab_hdr->sh_info, 0,
+-					       NULL, NULL, NULL);
++					       NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
+index 822b263ae2c..f6d00fc1826 100644
+--- a/bfd/elf64-ia64-vms.c
++++ b/bfd/elf64-ia64-vms.c
+@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
+index bb8350718a2..642b2cdb9bb 100644
+--- a/bfd/elf64-mmix.c
++++ b/bfd/elf64-mmix.c
+@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
+index fdda9e0bbb3..ee15d6f0639 100644
+--- a/bfd/elf64-ppc.c
++++ b/bfd/elf64-ppc.c
+@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
+ 			  size_t symcnt = symtab_hdr->sh_info;
+ 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						      symcnt, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (sym == NULL)
+ 			    break;
+ 			  symtab_hdr->contents = (bfd_byte *) sym;
+@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
+ 		    {
+ 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						  1, symndx,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (sym == NULL)
+ 			break;
+ 		    }
+@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elfcode.h b/bfd/elfcode.h
+index 5224a1abee6..8777a08a77a 100644
+--- a/bfd/elfcode.h
++++ b/bfd/elfcode.h
+@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+       size_t i;
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return -1;
+ 
+@@ -1523,16 +1523,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+     }
+ 
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return symcount;
+ 
+  error_return:
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return -1;
+ }
+ 
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index 3f3ea2cce51..da4da5c453a 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+   struct elf_strtab_hash *dynstr;
+   size_t dynstr_index;
+   char *name;
+-  Elf_External_Sym_Shndx eshndx;
+-  char esym[sizeof (Elf64_External_Sym)];
+ 
+   if (! is_elf_hash_table (info->hash))
+     return 0;
+@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+ 
+   /* Go find the symbol, so that we can find it's name.  */
+   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
+-			     1, input_indx, &entry->isym, esym, &eshndx))
++			     1, input_indx, &entry->isym, NULL))
+     {
+       bfd_release (input_bfd, entry);
+       return 0;
+@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 
+   /* Read in the symbol table.  */
+   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				  NULL, NULL, NULL);
++				  NULL, NULL);
+   if (isymbuf == NULL)
+     return false;
+ 
+@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 	}
+     }
+ 
+-  free (isymbuf);
++  if (!elf_tdata (abfd)->keep_symtab)
++    {
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
++    }
+ 
+   return result;
+ }
+@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 
+   free (extversym);
+   extversym = NULL;
+-  free (isymbuf);
+-  isymbuf = NULL;
++
++  /* NB: Since st_shndx of symbol from discarded section is changed to
++     SHN_UNDEF, free the cached symbol table.  */
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+ 
+   if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
+     {
+@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   free (nondeflt_vers);
+   free (extversym);
+  error_free_sym:
+-  free (isymbuf);
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+  error_return:
+   return false;
+ }
+@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL)
+     {
+       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf1 == NULL)
+ 	goto done;
+ 
+@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL || ssymbuf2 == NULL)
+     {
+       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf2 == NULL)
+ 	goto done;
+ 
+@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+  done:
+   free (symtable1);
+   free (symtable2);
+-  free (isymbuf1);
+-  free (isymbuf2);
+ 
+   return result;
+ }
+@@ -9056,14 +9060,6 @@ struct elf_final_link_info
+   void *external_relocs;
+   /* Buffer large enough to hold internal relocs of any section.  */
+   Elf_Internal_Rela *internal_relocs;
+-  /* Buffer large enough to hold external local symbols of any input
+-     BFD.  */
+-  bfd_byte *external_syms;
+-  /* And a buffer for symbol section indices.  */
+-  Elf_External_Sym_Shndx *locsym_shndx;
+-  /* Buffer large enough to hold internal local symbols of any input
+-     BFD.  */
+-  Elf_Internal_Sym *internal_syms;
+   /* Array large enough to hold a symbol index for each local symbol
+      of any input BFD.  */
+   long *indices;
+@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+ 	continue;
+ 
+       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+ 
+@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+   Elf_Internal_Shdr *symtab_hdr;
+   size_t locsymcount;
+   size_t extsymoff;
+-  Elf_Internal_Sym *isymbuf;
++  Elf_Internal_Sym *isymbuf = NULL;
+   Elf_Internal_Sym *isym;
+   Elf_Internal_Sym *isymend;
+   long *pindex;
+@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+ 	     ? -1 : ~elf_gnu_osabi_retain));
+ 
+   /* Read the local symbols.  */
+-  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (isymbuf == NULL && locsymcount != 0)
++  if (locsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				      flinfo->internal_syms,
+-				      flinfo->external_syms,
+-				      flinfo->locsym_shndx);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+     }
+@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
+   free (flinfo->contents);
+   free (flinfo->external_relocs);
+   free (flinfo->internal_relocs);
+-  free (flinfo->external_syms);
+-  free (flinfo->locsym_shndx);
+-  free (flinfo->internal_syms);
+   free (flinfo->indices);
+   free (flinfo->sections);
+   if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
+@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+   bfd_size_type max_external_reloc_size;
+   bfd_size_type max_internal_reloc_count;
+   bfd_size_type max_sym_count;
+-  bfd_size_type max_sym_shndx_count;
+   Elf_Internal_Sym elfsym;
+   unsigned int i;
+   Elf_Internal_Shdr *symtab_hdr;
+@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+     }
+   max_internal_reloc_count = 0;
+   max_sym_count = 0;
+-  max_sym_shndx_count = 0;
+   merged = false;
+   for (o = abfd->sections; o != NULL; o = o->next)
+     {
+@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 		  if (sym_count > max_sym_count)
+ 		    max_sym_count = sym_count;
+ 
+-		  if (sym_count > max_sym_shndx_count
+-		      && elf_symtab_shndx_list (sec->owner) != NULL)
+-		    max_sym_shndx_count = sym_count;
+-
+ 		  esdi = elf_section_data (sec);
+ 
+ 		  if (esdi->this_hdr.sh_type == SHT_REL
+@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+   if (max_sym_count != 0)
+     {
+-      amt = max_sym_count * bed->s->sizeof_sym;
+-      flinfo.external_syms = (bfd_byte *) bfd_malloc (amt);
+-      if (flinfo.external_syms == NULL)
+-	goto error_return;
+-
+-      amt = max_sym_count * sizeof (Elf_Internal_Sym);
+-      flinfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      if (flinfo.internal_syms == NULL)
+-	goto error_return;
+-
+       amt = max_sym_count * sizeof (long);
+       flinfo.indices = (long int *) bfd_malloc (amt);
+       if (flinfo.indices == NULL)
+@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 	goto error_return;
+     }
+ 
+-  if (max_sym_shndx_count != 0)
+-    {
+-      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
+-      flinfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
+-      if (flinfo.locsym_shndx == NULL)
+-	goto error_return;
+-    }
+-
+   if (htab->tls_sec)
+     {
+       bfd_vma base, end = 0;  /* Both bytes.  */
+@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+ static bool
+ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+-		   struct bfd_link_info *info, bfd *abfd,
+-		   bool keep_memory)
++		   struct bfd_link_info *info, bfd *abfd)
+ {
+   Elf_Internal_Shdr *symtab_hdr;
+   const struct elf_backend_data *bed;
+@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+   else
+     cookie->r_sym_shift = 32;
+ 
+-  cookie->locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
++  if (cookie->locsymcount != 0)
+     {
+       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      cookie->locsymcount, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+       if (cookie->locsyms == NULL)
+ 	{
+ 	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
+ 	  return false;
+ 	}
+-      if (keep_memory || _bfd_elf_link_keep_memory (info))
+-	{
+-	  symtab_hdr->contents = (bfd_byte *) cookie->locsyms;
+-	  info->cache_size += (cookie->locsymcount
+-			       * sizeof (Elf_Internal_Sym));
+-	}
+     }
+   return true;
+ }
+ 
+-/* Free the memory allocated by init_reloc_cookie, if appropriate.  */
+-
+-static void
+-fini_reloc_cookie (struct elf_reloc_cookie *cookie, bfd *abfd)
+-{
+-  Elf_Internal_Shdr *symtab_hdr;
+-
+-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-  if (symtab_hdr->contents != (unsigned char *) cookie->locsyms)
+-    free (cookie->locsyms);
+-}
+-
+ /* Initialize the relocation information in COOKIE for input section SEC
+    of input bfd ABFD.  */
+ 
+@@ -13996,28 +13942,9 @@ init_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+ 			       struct bfd_link_info *info,
+ 			       asection *sec, bool keep_memory)
+ {
+-  if (!init_reloc_cookie (cookie, info, sec->owner, keep_memory))
+-    goto error1;
+-  if (!init_reloc_cookie_rels (cookie, info, sec->owner, sec,
+-			       keep_memory))
+-    goto error2;
+-  return true;
+-
+- error2:
+-  fini_reloc_cookie (cookie, sec->owner);
+- error1:
+-  return false;
+-}
+-
+-/* Free the memory allocated by init_reloc_cookie_for_section,
+-   if appropriate.  */
+-
+-static void
+-fini_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+-			       asection *sec)
+-{
+-  fini_reloc_cookie_rels (cookie, sec);
+-  fini_reloc_cookie (cookie, sec->owner);
++  return (init_reloc_cookie (cookie, info, sec->owner)
++	  && init_reloc_cookie_rels (cookie, info, sec->owner, sec,
++				     keep_memory));
+ }
+ \f
+ /* Garbage collect unused sections.  */
+@@ -14209,7 +14136,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 		ret = false;
+ 		break;
+ 	      }
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	}
+     }
+ 
+@@ -14231,7 +14158,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 	  if (!_bfd_elf_gc_mark_fdes (info, sec, eh_frame,
+ 				      gc_mark_hook, &cookie))
+ 	    ret = false;
+-	  fini_reloc_cookie_for_section (&cookie, eh_frame);
++	  fini_reloc_cookie_rels (&cookie, eh_frame);
+ 	}
+     }
+ 
+@@ -14665,7 +14592,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
+       if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+ 	continue;
+ 
+-      if (!init_reloc_cookie (&cookie, info, ibfd, false))
++      if (!init_reloc_cookie (&cookie, info, ibfd))
+ 	return false;
+ 
+       for (sec = ibfd->sections; sec; sec = sec->next)
+@@ -14724,7 +14651,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	  if (elf_section_data (sec)->sec_info
+ 	      && (sec->flags & SEC_LINKER_CREATED) == 0)
+ 	    elf_eh_frame_section (sub) = sec;
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	  sec = bfd_get_next_section_by_name (NULL, sec);
+ 	}
+     }
+@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
+ 	      return false;
+ 	  }
++
++      if (!elf_tdata (sub)->keep_symtab
++	  && !_bfd_elf_link_keep_memory (info))
++	{
++	  free (elf_tdata (sub)->symtab);
++	  elf_tdata (sub)->symtab = NULL;
++	}
+     }
+ 
+   /* Allow the backend to mark additional target specific sections.  */
+@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 					  &cookie))
+ 	    changed = 1;
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+     }
+ 
+@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		changed = 1;
+ 	    }
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+ 
+       eh_alignment = ((1 << o->alignment_power)
+@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		    changed = 1;
+ 		}
+ 	    }
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+       /* Update the reference to the output .sframe section.  Used to
+ 	 determine later if PT_GNU_SFRAME segment is to be generated.  */
+@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 
+       if (bed->elf_backend_discard_info != NULL)
+ 	{
+-	  if (!init_reloc_cookie (&cookie, info, abfd, false))
++	  if (!init_reloc_cookie (&cookie, info, abfd))
+ 	    return -1;
+ 
+ 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
+ 	    changed = 1;
+-
+-	  fini_reloc_cookie (&cookie, abfd);
+ 	}
+     }
+ 
+diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
+index 3c3c2899674..553ba27b604 100644
+--- a/bfd/elfnn-aarch64.c
++++ b/bfd/elfnn-aarch64.c
+@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
+ 			local_syms
+ 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (local_syms == NULL)
+ 			goto error_ret_free_internal;
+ 		    }
+@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
+index 528b1dcdcc3..48fce2380cd 100644
+--- a/bfd/elfnn-ia64.c
++++ b/bfd/elfnn-ia64.c
+@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
+index 3b44db57421..8e75b400570 100644
+--- a/bfd/elfnn-kvx.c
++++ b/bfd/elfnn-kvx.c
+@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
+index 53cdb783859..10a4f99add7 100644
+--- a/bfd/elfnn-loongarch.c
++++ b/bfd/elfnn-loongarch.c
+@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
+       && !(symtab_hdr->contents =
+ 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						   symtab_hdr->sh_info,
+-						   0, NULL, NULL, NULL)))
++						   0, NULL, NULL)))
+     return true;
+ 
+   /* Estimate the maximum alignment for all output sections once time
+diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
+index 09cf7076733..d1ab410a94f 100644
+--- a/bfd/elfnn-riscv.c
++++ b/bfd/elfnn-riscv.c
+@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
+ 	  && !(symtab_hdr->contents =
+ 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						       symtab_hdr->sh_info,
+-						       0, NULL, NULL, NULL)))
++						       0, NULL, NULL)))
+ 	goto fail;
+ 
+       /* Get the value of the symbol referred to by the reloc.  */
+diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
+index 00ef0663728..44c58362dda 100644
+--- a/bfd/elfxx-mips.c
++++ b/bfd/elfxx-mips.c
+@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index 140e86888a6..53083e0b54c 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+ 	  /* Read this BFD's local symbols.  */
+ 	  if (isymbuf == NULL)
+ 	    {
+-	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
++	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++					      symtab_hdr->sh_info,
++					      0, NULL, NULL);
+ 	      if (isymbuf == NULL)
+-		{
+-		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
+-		  if (isymbuf == NULL)
+-		    goto error_return;
+-		}
++		goto error_return;
+ 	    }
+ 
+ 	  isym = isymbuf + r_symndx;
+@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+   return_status = true;
+ 
+ error_return:
+-  if ((unsigned char *) isymbuf != symtab_hdr->contents)
+-    {
+-      /* Cache the symbol buffer if it must be kept.  */
+-      if (keep_symbuf)
+-	symtab_hdr->contents = (unsigned char *) isymbuf;
+-      else
+-	free (isymbuf);
+-    }
++  /* If the symbol table has been updated, it must be kept since it will
++     be used later.  */
++  if (keep_symbuf)
++    elf_tdata (abfd)->keep_symtab = 1;
+   if (elf_section_data (input_section)->relocs != internal_relocs)
+     free (internal_relocs);
+   return return_status;
+diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
+index 7241de70709..205347c4e22 100644
+--- a/libctf/ctf-open-bfd.c
++++ b/libctf/ctf-open-bfd.c
+@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+ 	}
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
+-				      NULL, symtab, NULL);
+-      free (isymbuf);
++				      NULL, symtab);
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
+       if (isymbuf == NULL)
+ 	{
+ 	  bfderrstr = N_("cannot read symbol table");
+-- 
+GitLab
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-11  0:46 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-11  0:46 UTC (permalink / raw
  To: gentoo-commits

commit:     56cd194bbf2a0a211d1818b4b42ab0c74893bb18
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 11 00:46:39 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Oct 11 00:46:48 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=56cd194b

9999: update patch from ML

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 522 ++++++++++++---------
 1 file changed, 309 insertions(+), 213 deletions(-)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
index acae3cf..f829ffc 100644
--- a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -1,25 +1,45 @@
-From 13058a8b8feb26ddafb62995f164d81dce02979c Mon Sep 17 00:00:00 2001
+From 6081e4356a0e4f9932a05af0871490fc54e15113 Mon Sep 17 00:00:00 2001
+Message-ID: <6081e4356a0e4f9932a05af0871490fc54e15113.1760143572.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Thu, 9 Oct 2025 13:16:19 +0800
+Date: Sat, 11 Oct 2025 07:18:50 +0800
 Subject: [PATCH] elf: Cache full internal symbol table for relocatable input
 
-Cache internal symbol table for relocatable input and use the internal
-symbol table cache for both local and global symbols to avoid swapping in
-the same symbol table repeatedly for --gc-sections.  This improves linker
---gc-sections speed by ~20x.
+Add bfd_elf_get_elf_syms_cached to cache internal symbol table for
+relocatable input and use the internal symbol table cache for both local
+and global symbols to avoid swapping in the same symbol table repeatedly
+for --gc-sections.  This improves linker --gc-sections speed by ~2x for
+PR ld/33530.
 
-Most backends cache the local symbol table in symtab_hdr->contents. But
-some backends cache something else in it.  Since symtab_hdr->contents may
-point to the middle of the internal symbol table cache, we can release
-symtab_hdr->contents only when no backends cache the local symbol table
-in it.
+elf_link_input_bfd is updated to not to pass preallocated buffers to
+bfd_elf_get_elf_syms_cache.
+
+Data to link the 3.1GB clang executable in LLVM 21 debug build on
+Linux/x86-64 with 32GB RAM is:
+
+		before		after		improvement
+user		48.29		46.45		3.8%
+system		7.82		5.47		30%
+total		56.1 		51.92		7%
+maximum set(GB)	10.5		10.7		-0.2%
+page faults	2535779		2509896		0.1%
+
+and data to link the 308M cc1plus executable in GCC 16 stage 1 build is:
+
+		before		after		improvement
+user		3.56 		3.49		0.2%
+system		0.66		0.58		12%
+total		4.22 		4.07		0.3%
+maximum set(MB)	969		992		-2.4%
+page faults	992692		1016732		0.1%
 
 bfd/
 
 	PR ld/33530
-	* elf-bfd.h (elf_obj_tdata): Add symtab and keep_symtab.
+	* elf-bfd.h (elf_obj_tdata): Add symtab.
 	(bfd_elf_get_elf_syms): Remove the Elf_External_Sym_Shndx pointer
 	argument.
+	(bfd_elf_get_elf_syms_cached): New function.
+	(bfd_elf_free_symtab): Likewise.
 	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
 	return void.
 	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
@@ -30,6 +50,15 @@ bfd/
 	* elf-m10300.c (mn10300_elf_check_relocs): Likewise.
 	(mn10300_elf_relax_section): Likewise.
 	(mn10300_elf_get_relocated_section_contents): Likewise.
+	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
+	pointer argument.  Renamed to ...
+	(bfd_elf_get_elf_syms_cached):  This.  Cache internal symbol
+	table.
+	(bfd_elf_get_elf_syms): Call bfd_elf_get_elf_syms_cached.
+	(group_signature): Call bfd_elf_get_elf_syms_cached instead of
+	bfd_elf_get_elf_syms.
+	(bfd_sym_from_r_symndx): Likewise.
+	(_bfd_elf_free_cached_info): Free internal symbol table cache.
 	* elf32-arc.c (arc_elf_relax_section): Likewise.
 	* elf32-arm.c (cmse_scan): Likewise.
 	(elf32_arm_size_stubs): Likewise.
@@ -92,34 +121,25 @@ bfd/
 	(ppc64_elf_late_size_sections): Likewise.
 	(ppc64_elf_layout_multitoc): Likewise.
 	(got_and_plt_relr_for_local_syms): Likewise.
-	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
-	(bfd_elfNN_aarch64_init_maps): Likewise.
-	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
-	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
-	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
-	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
-	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
-	pointer argument.  Only allow the full external symbol table.
-	Cache internal symbol table.
-	(group_signature): Update the bfd_elf_get_elf_syms call.
-	(bfd_sym_from_r_symndx): Likewise.
-	(_bfd_elf_free_cached_info): Free internal symbol table cache.
-	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
-	buffer.
-	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Update
-	the bfd_elf_get_elf_syms call.
-	(elf_link_is_defined_archive_symbol): Likewise.  Free cached
-	internal symbol buffer unless it should be kept.
-	(elf_link_add_object_symbols): Update the bfd_elf_get_elf_syms
-	call.  Free cached internal symbol buffer.
-	(bfd_elf_match_symbols_in_sections): Update the
-	bfd_elf_get_elf_syms call.  Don't free the internal symbol table.
+	* elfcode.h (elf_slurp_symbol_table): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	Don't free internal symbol buffer.
+	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	(elf_link_is_defined_archive_symbol): Likewise.  Free internal
+	symbol table cache.
+	(elf_link_add_object_symbols): Call bfd_elf_get_elf_syms_cached
+	instead of bfd_elf_get_elf_syms.  Free internal symbol table
+	cache if it has been changed.
+	(bfd_elf_match_symbols_in_sections): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	Don't free the internal symbol table.
 	(elf_final_link_info): Remove external_syms, locsym_shndx and
 	internal_syms.
-	(elf_link_check_versioned_symbol): Update the bfd_elf_get_elf_syms
-	call.
-	(elf_link_input_bfd): Likewise.  Don't use symtab_hdr->contents
-	for internal symbol table.
+	(elf_link_check_versioned_symbol): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	(elf_link_input_bfd): Likewise.  Don't pass pre-allocated
+	buffer to bfd_elf_get_elf_syms_cached.
 	(elf_final_link_free): Updated.
 	(bfd_elf_final_link): Don't set flinfo.external_syms,
 	flinfo.internal_syms nor flinfo.locsym_shndx.
@@ -135,6 +155,12 @@ bfd/
 	(bfd_elf_discard_info): Replace fini_reloc_cookie_for_section with
 	fini_reloc_cookie_rels.  Don't call fini_reloc_cookie.
 	(bfd_elf_parse_eh_frame_entries): Updated.
+	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
+	(bfd_elfNN_aarch64_init_maps): Likewise.
+	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
+	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
+	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
+	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
 	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
 	use symtab_hdr->contents for internal symbol table.  Set
 	keep_symtab if the symbol table has been updated.
@@ -142,19 +168,20 @@ bfd/
 libctf/
 
 	PR ld/33530
-	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
-	table cache.
+	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Call
+	bfd_elf_get_elf_syms_cached instead of bfd_elf_get_elf_syms.
+	Free internal symbol table cache.
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
- bfd/elf-bfd.h          |  11 ++-
- bfd/elf-eh-frame.c     |  17 ++---
+ bfd/elf-bfd.h          |  19 ++++-
+ bfd/elf-eh-frame.c     |  17 +----
  bfd/elf-m10200.c       |   4 +-
  bfd/elf-m10300.c       |  10 +--
- bfd/elf.c              | 131 ++++++++++++++++++++++++++---------
+ bfd/elf.c              | 167 +++++++++++++++++++++++++++++++----------
  bfd/elf32-arc.c        |   2 +-
  bfd/elf32-arm.c        |   7 +-
- bfd/elf32-avr.c        |  12 ++--
+ bfd/elf32-avr.c        |  12 +--
  bfd/elf32-bfin.c       |   2 +-
  bfd/elf32-cr16.c       |   6 +-
  bfd/elf32-crx.c        |   4 +-
@@ -164,7 +191,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  bfd/elf32-h8300.c      |   4 +-
  bfd/elf32-hppa.c       |   2 +-
  bfd/elf32-ip2k.c       |   2 +-
- bfd/elf32-m32c.c       |   8 ++-
+ bfd/elf32-m32c.c       |   8 +-
  bfd/elf32-m68hc11.c    |   2 +-
  bfd/elf32-m68hc1x.c    |   2 +-
  bfd/elf32-m68k.c       |   2 +-
@@ -185,21 +212,21 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  bfd/elf64-hppa.c       |   2 +-
  bfd/elf64-ia64-vms.c   |   4 +-
  bfd/elf64-mmix.c       |   2 +-
- bfd/elf64-ppc.c        |  12 ++--
- bfd/elfcode.h          |   8 +--
- bfd/elflink.c          | 152 ++++++++++++-----------------------------
+ bfd/elf64-ppc.c        |  12 +--
+ bfd/elfcode.h          |  10 +--
+ bfd/elflink.c          | 162 +++++++++++----------------------------
  bfd/elfnn-aarch64.c    |   4 +-
  bfd/elfnn-ia64.c       |   2 +-
  bfd/elfnn-kvx.c        |   2 +-
  bfd/elfnn-loongarch.c  |   2 +-
  bfd/elfnn-riscv.c      |   2 +-
  bfd/elfxx-mips.c       |   2 +-
- bfd/elfxx-x86.c        |  24 +++----
- libctf/ctf-open-bfd.c  |   5 +-
- 49 files changed, 243 insertions(+), 262 deletions(-)
+ bfd/elfxx-x86.c        |  22 ++++--
+ libctf/ctf-open-bfd.c  |   6 +-
+ 49 files changed, 293 insertions(+), 267 deletions(-)
 
 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index 5d19529d972..b7061e55b59 100644
+index 5d19529d972..b0bd8f4d589 100644
 --- a/bfd/elf-bfd.h
 +++ b/bfd/elf-bfd.h
 @@ -2165,6 +2165,11 @@ struct elf_obj_tdata
@@ -214,26 +241,34 @@ index 5d19529d972..b7061e55b59 100644
    /* List of GNU properties.  Will be updated by setup_gnu_properties
       after all input GNU properties are merged for output.  */
    elf_property_list *properties;
-@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
-      symbols.  */
-   unsigned int bad_symtab : 1;
- 
-+  /* Set if the symbol table cache should be kept.  */
-+  unsigned int keep_symtab : 1;
-+
-   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
-   unsigned int is_pie : 1;
- 
-@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
+@@ -2297,8 +2302,9 @@ extern unsigned int _bfd_elf_section_from_bfd_section
  extern char *bfd_elf_string_from_elf_section
    (bfd *, unsigned, unsigned);
  extern Elf_Internal_Sym *bfd_elf_get_elf_syms
 -  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
 -   Elf_External_Sym_Shndx *);
++  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
++extern Elf_Internal_Sym *bfd_elf_get_elf_syms_cached
 +  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
  extern char * bfd_elf_get_str_section (bfd *, unsigned int);
  extern const char *bfd_elf_sym_name
    (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
+@@ -3333,6 +3339,15 @@ bfd_section_is_ctf (const asection *sec)
+   return startswith (name, ".ctf") && (name[4] == 0 || name[4] == '.');
+ }
+ 
++/* Free ELF symbol table cache.  */
++
++static inline void
++bfd_elf_free_symtab (bfd *abfd)
++{
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
++}
++
+ #ifdef __cplusplus
+ }
+ #endif
 diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
 index 4eda3c991bb..bd2c85291fb 100644
 --- a/bfd/elf-eh-frame.c
@@ -353,7 +388,7 @@ index b381bb9037c..373290cbe4a 100644
  	    goto error_return;
  	}
 diff --git a/bfd/elf.c b/bfd/elf.c
-index bde7414ee21..9e220f0a0d7 100644
+index bde7414ee21..472fb5da55e 100644
 --- a/bfd/elf.c
 +++ b/bfd/elf.c
 @@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
@@ -369,20 +404,23 @@ index bde7414ee21..9e220f0a0d7 100644
 -   Returns a pointer to the internal symbol buffer (malloced if necessary)
 -   or NULL if there were no symbols or some kind of problem.  */
 +   symbols, and symbol section index extensions, respectively.  Returns
-+   a pointer to the internal symbol buffer (malloced if necessary) or
-+   NULL if there were no symbols or some kind of problem.  */
++   a pointer to the internal symbol cache or NULL if there were no
++   symbols or some kind of problem.  */
  
  Elf_Internal_Sym *
- bfd_elf_get_elf_syms (bfd *ibfd,
- 		      Elf_Internal_Shdr *symtab_hdr,
+-bfd_elf_get_elf_syms (bfd *ibfd,
+-		      Elf_Internal_Shdr *symtab_hdr,
 -		      size_t symcount,
 -		      size_t symoffset,
-+		      size_t partial_symcount,
-+		      size_t partial_symoffset,
- 		      Elf_Internal_Sym *intsym_buf,
+-		      Elf_Internal_Sym *intsym_buf,
 -		      void *extsym_buf,
 -		      Elf_External_Sym_Shndx *extshndx_buf)
-+		      void *partial_extsym_buf)
++bfd_elf_get_elf_syms_cached (bfd *ibfd,
++			     Elf_Internal_Shdr *symtab_hdr,
++			     size_t partial_symcount,
++			     size_t partial_symoffset,
++			     Elf_Internal_Sym *intsym_buf,
++			     void *partial_extsym_buf)
  {
    Elf_Internal_Shdr *shndx_hdr;
    void *alloc_ext;
@@ -400,30 +438,33 @@ index bde7414ee21..9e220f0a0d7 100644
  
    if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
      abort ();
-@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -474,6 +478,25 @@ bfd_elf_get_elf_syms (bfd *ibfd,
        return elf_tdata (ibfd)->dt_symtab + symoffset;
      }
  
 +  if (elf_tdata (ibfd)->symtab != NULL)
 +    {
-+      /* NB: Should extsym_buf be cached?  */
++      /* Since extsym_buf isn't cached, free the symbol table cache and
++	 re-read the symbol table.  */
 +      if (partial_extsym_buf != NULL)
-+	abort ();
-+
-+      if (intsym_buf != NULL)
++	bfd_elf_free_symtab (ibfd);
++      else
 +	{
-+	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
-+		  symcount * sizeof (*intsym_buf));
-+	  return intsym_buf;
++	  if (intsym_buf != NULL)
++	    {
++	      memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
++		      symcount * sizeof (*intsym_buf));
++	      return intsym_buf;
++	    }
++	  else
++	    return elf_tdata (ibfd)->symtab + symoffset;
 +	}
-+      else
-+	return elf_tdata (ibfd)->symtab + symoffset;
 +    }
 +
    /* Normal syms might have section extension entries.  */
    shndx_hdr = NULL;
    if (elf_symtab_shndx_list (ibfd) != NULL)
-@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -506,19 +529,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	}
      }
  
@@ -458,7 +499,7 @@ index bde7414ee21..9e220f0a0d7 100644
    if (bfd_seek (ibfd, pos, SEEK_SET) != 0
        || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
  				    &alloc_ext, ibfd, false))
-@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -551,22 +586,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	}
      }
  
@@ -476,17 +517,17 @@ index bde7414ee21..9e220f0a0d7 100644
 -	goto out1;
 +      bfd_set_error (bfd_error_file_too_big);
 +      goto out1;
-     }
++    }
 +  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
 +  if (alloc_intsym == NULL)
 +    {
 +      intsym_buf = NULL;
 +      goto out1;
-+    }
-+
+     }
+ 
 +  if (intsym_buf == NULL)
 +    intsym_buf = alloc_intsym;
- 
++
    /* Convert the symbols to internal form.  */
 -  isymend = intsym_buf + symcount;
 -  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
@@ -495,7 +536,7 @@ index bde7414ee21..9e220f0a0d7 100644
  	   shndx = extshndx_buf;
         isym < isymend;
         esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
-@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -590,7 +627,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	{	
  	  /* xgettext:c-format */
  	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
@@ -506,7 +547,7 @@ index bde7414ee21..9e220f0a0d7 100644
  	  free (alloc_intsym);
  	  intsym_buf = NULL;
  	  goto out1;
-@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+@@ -602,18 +641,72 @@ bfd_elf_get_elf_syms (bfd *ibfd,
  	{
  	  /* xgettext:c-format */
  	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
@@ -520,23 +561,19 @@ index bde7414ee21..9e220f0a0d7 100644
  	}
      }
  
++  /* Copy external symbol table before external symbol table buffer
++     is released by _bfd_munmap_temporary.  */
 +  if (intsym_buf != NULL && partial_extsym_buf != NULL)
-+    {
-+      if (partial_symcount != symcount)
-+	abort ();
-+      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
-+    }
++    memcpy (partial_extsym_buf,
++	    extsym_buf + partial_symoffset * extsym_size,
++	    partial_symcount * extsym_size);
 +
   out1:
    _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
   out2:
    _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
  
--  return intsym_buf;
-+  if (intsym_buf == NULL)
-+    return intsym_buf;
-+
-+  if (!cache_symtab)
++  if (intsym_buf == NULL || !cache_symtab)
 +    return intsym_buf;
 +
 +  elf_tdata (ibfd)->symtab = alloc_intsym;
@@ -548,10 +585,43 @@ index bde7414ee21..9e220f0a0d7 100644
 +    }
 +  else
 +    return alloc_intsym + partial_symoffset;
++}
++
++/* Read and convert symbols to internal format.
++   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
++   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
++   are non-NULL, they are used to store the internal symbols, external
++   symbols, and symbol section index extensions, respectively.  Returns
++   a pointer to the internal symbol buffer (malloced if necessary) or
++   NULL if there were no symbols or some kind of problem.  */
++
++Elf_Internal_Sym *
++bfd_elf_get_elf_syms (bfd *ibfd,
++		      Elf_Internal_Shdr *symtab_hdr,
++		      size_t partial_symcount,
++		      size_t partial_symoffset,
++		      Elf_Internal_Sym *intsym_buf,
++		      void *partial_extsym_buf)
++{
++  Elf_Internal_Sym *isym
++    = bfd_elf_get_elf_syms_cached (ibfd, symtab_hdr, partial_symcount,
++				   partial_symoffset, intsym_buf,
++				   partial_extsym_buf);
++  if (isym == NULL
++      || intsym_buf != NULL
++      || partial_symcount == 0
++      || elf_use_dt_symtab_p (ibfd))
++    return isym;
++
++  size_t amt = partial_symcount * sizeof (*intsym_buf);
++  intsym_buf = bfd_malloc (amt);
++  if (intsym_buf != NULL)
++    memcpy (intsym_buf, isym, amt);
++  bfd_elf_free_symtab (ibfd);
+   return intsym_buf;
  }
  
- /* Look up a symbol name.  */
-@@ -659,8 +718,6 @@ static const char *
+@@ -659,8 +752,6 @@ static const char *
  group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
  {
    Elf_Internal_Shdr *hdr;
@@ -560,16 +630,18 @@ index bde7414ee21..9e220f0a0d7 100644
    Elf_Internal_Sym isym;
  
    /* First we need to ensure the symbol table is available.  Make sure
-@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+@@ -674,8 +765,8 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+ 
    /* Go read the symbol.  */
    hdr = &elf_tdata (abfd)->symtab_hdr;
-   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
+-  if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
 -			    &isym, esym, &eshndx) == NULL)
-+			    &isym, NULL) == NULL)
++  if (bfd_elf_get_elf_syms_cached (abfd, hdr, 1, ghdr->sh_info,
++				   &isym, NULL) == NULL)
      return NULL;
  
    return bfd_elf_sym_name_raw (abfd, hdr, &isym);
-@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
+@@ -3029,12 +3120,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
    if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
      {
        Elf_Internal_Shdr *symtab_hdr;
@@ -577,24 +649,17 @@ index bde7414ee21..9e220f0a0d7 100644
 -      Elf_External_Sym_Shndx eshndx;
  
        symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
+-      if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
 -				&cache->sym[ent], esym, &eshndx) == NULL)
-+				&cache->sym[ent], NULL) == NULL)
++      if (bfd_elf_get_elf_syms_cached (abfd, symtab_hdr, 1, r_symndx,
++				       &cache->sym[ent], NULL) == NULL)
  	return NULL;
  
        if (cache->abfd != abfd)
-@@ -10239,8 +10294,16 @@ _bfd_elf_free_cached_info (bfd *abfd)
- 	      free (sec_info->cies);
- 	    }
+@@ -10241,6 +10330,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
  	}
-+#if 0
-+      /* NB: tdata->symtab_hdr.contents may point to the middle of
-+	 tdata->symtab.  Need to update all backends only to cache
-+	 the malloced memory in tdata->symtab_hdr.contents before
-+	 tdata->symtab_hdr.contents can be freed.  */
        free (tdata->symtab_hdr.contents);
        tdata->symtab_hdr.contents = NULL;
-+#endif
 +      free (tdata->symtab);
 +      tdata->symtab = NULL;
      }
@@ -1307,15 +1372,17 @@ index fdda9e0bbb3..ee15d6f0639 100644
  	    return false;
  	}
 diff --git a/bfd/elfcode.h b/bfd/elfcode.h
-index 5224a1abee6..8777a08a77a 100644
+index 5224a1abee6..f8176294bc9 100644
 --- a/bfd/elfcode.h
 +++ b/bfd/elfcode.h
-@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+@@ -1302,8 +1302,8 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+     {
        size_t i;
  
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
+-      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
 -				      NULL, NULL, NULL);
-+				      NULL, NULL);
++      isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, symcount, 0,
++					     NULL, NULL);
        if (isymbuf == NULL)
  	return -1;
  
@@ -1337,7 +1404,7 @@ index 5224a1abee6..8777a08a77a 100644
  }
  
 diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 3f3ea2cce51..da4da5c453a 100644
+index 3f3ea2cce51..0ab843a4924 100644
 --- a/bfd/elflink.c
 +++ b/bfd/elflink.c
 @@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
@@ -1349,89 +1416,119 @@ index 3f3ea2cce51..da4da5c453a 100644
  
    if (! is_elf_hash_table (info->hash))
      return 0;
-@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+@@ -868,8 +866,9 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+     return 0;
  
    /* Go find the symbol, so that we can find it's name.  */
-   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
+-  if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
 -			     1, input_indx, &entry->isym, esym, &eshndx))
-+			     1, input_indx, &entry->isym, NULL))
++  if (!bfd_elf_get_elf_syms_cached (input_bfd,
++				    &elf_tdata (input_bfd)->symtab_hdr,
++				    1, input_indx, &entry->isym, NULL))
      {
        bfd_release (input_bfd, entry);
        return 0;
-@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+@@ -3744,8 +3743,8 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+     return false;
  
    /* Read in the symbol table.  */
-   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
 -				  NULL, NULL, NULL);
-+				  NULL, NULL);
++  isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, extsymcount,
++					 extsymoff, NULL, NULL);
    if (isymbuf == NULL)
      return false;
  
-@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+@@ -3767,7 +3766,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
  	}
      }
  
 -  free (isymbuf);
-+  if (!elf_tdata (abfd)->keep_symtab)
-+    {
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-+    }
++  bfd_elf_free_symtab (abfd);
  
    return result;
  }
-@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -4829,8 +4828,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   sym_hash = elf_sym_hashes (abfd);
    if (extsymcount != 0)
      {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
 -				      NULL, NULL, NULL);
-+				      NULL, NULL);
++      isymbuf = bfd_elf_get_elf_syms_cached (abfd, hdr, extsymcount,
++					     extsymoff, NULL, NULL);
        if (isymbuf == NULL)
  	goto error_return;
  
-@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -4977,6 +4976,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 	(_("%pB: plugin needed to handle lto object"), abfd);
+     }
+ 
++  bool symtab_changed = false;
++
+   for (isym = isymbuf, isymend = PTR_ADD (isymbuf, extsymcount);
+        isym < isymend;
+        isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL))
+@@ -5013,6 +5014,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 	{
+ 	  /* Treat common symbol as undefined for --no-define-common.  */
+ 	  isym->st_shndx = SHN_UNDEF;
++	  symtab_changed = true;
+ 	  common = false;
+ 	}
+       discarded = false;
+@@ -5086,6 +5088,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 	      sec = bfd_und_section_ptr;
+ 	      discarded = true;
+ 	      isym->st_shndx = SHN_UNDEF;
++	      symtab_changed = true;
+ 	    }
+ 	  else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
+ 	    value -= sec->vma;
+@@ -5814,8 +5817,10 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
  
    free (extversym);
    extversym = NULL;
 -  free (isymbuf);
 -  isymbuf = NULL;
 +
-+  /* NB: Since st_shndx of symbol from discarded section is changed to
-+     SHN_UNDEF, free the cached symbol table.  */
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
++  /* Free internal symbol table cache if it has been changed.  */
++  if (symtab_changed)
++    bfd_elf_free_symtab (abfd);
  
    if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
      {
-@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+@@ -6167,7 +6172,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
    free (nondeflt_vers);
    free (extversym);
   error_free_sym:
 -  free (isymbuf);
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
++  bfd_elf_free_symtab (abfd);
   error_return:
    return false;
  }
-@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -8808,8 +8813,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+ 
    if (ssymbuf1 == NULL)
      {
-       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
+-      isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
 -				       NULL, NULL, NULL);
-+				       NULL, NULL);
++      isymbuf1 = bfd_elf_get_elf_syms_cached (bfd1, hdr1, symcount1,
++					      0, NULL, NULL);
        if (isymbuf1 == NULL)
  	goto done;
  
-@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -8822,8 +8827,8 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+ 
    if (ssymbuf1 == NULL || ssymbuf2 == NULL)
      {
-       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
+-      isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
 -				       NULL, NULL, NULL);
-+				       NULL, NULL);
++      isymbuf2 = bfd_elf_get_elf_syms_cached (bfd2, hdr2, symcount2,
++					      0, NULL, NULL);
        if (isymbuf2 == NULL)
  	goto done;
  
-@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+@@ -9013,8 +9018,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
   done:
    free (symtable1);
    free (symtable2);
@@ -1440,7 +1537,7 @@ index 3f3ea2cce51..da4da5c453a 100644
  
    return result;
  }
-@@ -9056,14 +9060,6 @@ struct elf_final_link_info
+@@ -9056,14 +9059,6 @@ struct elf_final_link_info
    void *external_relocs;
    /* Buffer large enough to hold internal relocs of any section.  */
    Elf_Internal_Rela *internal_relocs;
@@ -1455,16 +1552,18 @@ index 3f3ea2cce51..da4da5c453a 100644
    /* Array large enough to hold a symbol index for each local symbol
       of any input BFD.  */
    long *indices;
-@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+@@ -10665,8 +10660,8 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+       if (extsymcount == 0)
  	continue;
  
-       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
+-      isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
 -				      NULL, NULL, NULL);
-+				      NULL, NULL);
++      isymbuf = bfd_elf_get_elf_syms_cached (input, hdr, extsymcount,
++					     extsymoff, NULL, NULL);
        if (isymbuf == NULL)
  	return false;
  
-@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+@@ -11410,7 +11405,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
    Elf_Internal_Shdr *symtab_hdr;
    size_t locsymcount;
    size_t extsymoff;
@@ -1473,19 +1572,16 @@ index 3f3ea2cce51..da4da5c453a 100644
    Elf_Internal_Sym *isym;
    Elf_Internal_Sym *isymend;
    long *pindex;
-@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
- 	     ? -1 : ~elf_gnu_osabi_retain));
- 
-   /* Read the local symbols.  */
--  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
--  if (isymbuf == NULL && locsymcount != 0)
-+  if (locsymcount != 0)
+@@ -11459,10 +11454,8 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
      {
-       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-      isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
 -				      flinfo->internal_syms,
 -				      flinfo->external_syms,
 -				      flinfo->locsym_shndx);
-+				      NULL, NULL);
++      isymbuf = bfd_elf_get_elf_syms_cached (input_bfd, symtab_hdr,
++					     locsymcount, 0, NULL, NULL);
        if (isymbuf == NULL)
  	return false;
      }
@@ -1576,10 +1672,12 @@ index 3f3ea2cce51..da4da5c453a 100644
 -  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
 +  if (cookie->locsymcount != 0)
      {
-       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      cookie->locsymcount, 0,
+-      cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-					      cookie->locsymcount, 0,
 -					      NULL, NULL, NULL);
-+					      NULL, NULL);
++      cookie->locsyms = bfd_elf_get_elf_syms_cached (abfd, symtab_hdr,
++						     cookie->locsymcount,
++						     0, NULL, NULL);
        if (cookie->locsyms == NULL)
  	{
  	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
@@ -1678,21 +1776,17 @@ index 3f3ea2cce51..da4da5c453a 100644
  	  sec = bfd_get_next_section_by_name (NULL, sec);
  	}
      }
-@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+@@ -14784,6 +14711,9 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
  	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
  	      return false;
  	  }
 +
-+      if (!elf_tdata (sub)->keep_symtab
-+	  && !_bfd_elf_link_keep_memory (info))
-+	{
-+	  free (elf_tdata (sub)->symtab);
-+	  elf_tdata (sub)->symtab = NULL;
-+	}
++      if (!_bfd_elf_link_keep_memory (info))
++	bfd_elf_free_symtab (sub);
      }
  
    /* Allow the backend to mark additional target specific sections.  */
-@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+@@ -15239,7 +15169,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
  					  &cookie))
  	    changed = 1;
  
@@ -1701,7 +1795,7 @@ index 3f3ea2cce51..da4da5c453a 100644
  	}
      }
  
-@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+@@ -15274,7 +15204,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
  		changed = 1;
  	    }
  
@@ -1710,7 +1804,7 @@ index 3f3ea2cce51..da4da5c453a 100644
  	}
  
        eh_alignment = ((1 << o->alignment_power)
-@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+@@ -15339,7 +15269,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
  		    changed = 1;
  		}
  	    }
@@ -1719,7 +1813,7 @@ index 3f3ea2cce51..da4da5c453a 100644
  	}
        /* Update the reference to the output .sframe section.  Used to
  	 determine later if PT_GNU_SFRAME segment is to be generated.  */
-@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+@@ -15362,13 +15292,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
  
        if (bed->elf_backend_discard_info != NULL)
  	{
@@ -1822,64 +1916,66 @@ index 00ef0663728..44c58362dda 100644
  	    goto error_return;
  	}
 diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index 140e86888a6..53083e0b54c 100644
+index 140e86888a6..3f397f5cf70 100644
 --- a/bfd/elfxx-x86.c
 +++ b/bfd/elfxx-x86.c
-@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
- 	  /* Read this BFD's local symbols.  */
- 	  if (isymbuf == NULL)
- 	    {
--	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-+	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+					      symtab_hdr->sh_info,
-+					      0, NULL, NULL);
+@@ -1157,9 +1157,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+ 	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  	      if (isymbuf == NULL)
--		{
+ 		{
 -		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
 -						  symtab_hdr->sh_info,
 -						  0, NULL, NULL, NULL);
--		  if (isymbuf == NULL)
--		    goto error_return;
--		}
-+		goto error_return;
- 	    }
- 
- 	  isym = isymbuf + r_symndx;
-@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
++		  isymbuf
++		    = bfd_elf_get_elf_syms_cached (abfd, symtab_hdr,
++						   symtab_hdr->sh_info,
++						   0, NULL, NULL);
+ 		  if (isymbuf == NULL)
+ 		    goto error_return;
+ 		}
+@@ -1345,13 +1346,18 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
    return_status = true;
  
  error_return:
 -  if ((unsigned char *) isymbuf != symtab_hdr->contents)
--    {
++  if (keep_symbuf && (unsigned char *) isymbuf != symtab_hdr->contents)
+     {
 -      /* Cache the symbol buffer if it must be kept.  */
 -      if (keep_symbuf)
 -	symtab_hdr->contents = (unsigned char *) isymbuf;
--      else
++      /* Cache the symbol buffer if it has been changed.  */
++      size_t amt = symtab_hdr->sh_info * sizeof (*isymbuf);
++      void *buffer = bfd_malloc (amt);
++      if (buffer == NULL)
++	return_status = false;
+       else
 -	free (isymbuf);
--    }
-+  /* If the symbol table has been updated, it must be kept since it will
-+     be used later.  */
-+  if (keep_symbuf)
-+    elf_tdata (abfd)->keep_symtab = 1;
++	{
++	  memcpy (buffer, isymbuf, amt);
++	  symtab_hdr->contents = buffer;
++	}
+     }
    if (elf_section_data (input_section)->relocs != internal_relocs)
      free (internal_relocs);
-   return return_status;
 diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
-index 7241de70709..205347c4e22 100644
+index 7241de70709..2ec91ffb0bf 100644
 --- a/libctf/ctf-open-bfd.c
 +++ b/libctf/ctf-open-bfd.c
-@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+@@ -145,9 +145,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+ 	  goto err;
  	}
  
-       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
+-      isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
 -				      NULL, symtab, NULL);
 -      free (isymbuf);
-+				      NULL, symtab);
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
++      isymbuf = bfd_elf_get_elf_syms_cached (abfd, symhdr, symcount, 0,
++					     NULL, symtab);
++      bfd_elf_free_symtab (abfd);
        if (isymbuf == NULL)
  	{
  	  bfderrstr = N_("cannot read symbol table");
+
+base-commit: 552ddbabb5d28b301c660ddeecae19510ed4aa30
 -- 
-GitLab
+2.51.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-10  5:41 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-10  5:41 UTC (permalink / raw
  To: gentoo-commits

commit:     279ad384a8d621f9a25985f2bf67803123940e4c
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 10 05:41:15 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 10 05:41:15 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=279ad384

9999: patch still fails tests

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1885 --------------------
 1 file changed, 1885 deletions(-)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
deleted file mode 100644
index acae3cf..0000000
--- a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
+++ /dev/null
@@ -1,1885 +0,0 @@
-From 13058a8b8feb26ddafb62995f164d81dce02979c Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Thu, 9 Oct 2025 13:16:19 +0800
-Subject: [PATCH] elf: Cache full internal symbol table for relocatable input
-
-Cache internal symbol table for relocatable input and use the internal
-symbol table cache for both local and global symbols to avoid swapping in
-the same symbol table repeatedly for --gc-sections.  This improves linker
---gc-sections speed by ~20x.
-
-Most backends cache the local symbol table in symtab_hdr->contents. But
-some backends cache something else in it.  Since symtab_hdr->contents may
-point to the middle of the internal symbol table cache, we can release
-symtab_hdr->contents only when no backends cache the local symbol table
-in it.
-
-bfd/
-
-	PR ld/33530
-	* elf-bfd.h (elf_obj_tdata): Add symtab and keep_symtab.
-	(bfd_elf_get_elf_syms): Remove the Elf_External_Sym_Shndx pointer
-	argument.
-	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
-	return void.
-	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
-	internal symbol table in symtab_hdr.
-	* elf-m10200.c (mn10200_elf_relax_section): Drop the last argument
-	to bfd_elf_get_elf_syms.
-	(mn10200_elf_get_relocated_section_contents): Likewise.
-	* elf-m10300.c (mn10300_elf_check_relocs): Likewise.
-	(mn10300_elf_relax_section): Likewise.
-	(mn10300_elf_get_relocated_section_contents): Likewise.
-	* elf32-arc.c (arc_elf_relax_section): Likewise.
-	* elf32-arm.c (cmse_scan): Likewise.
-	(elf32_arm_size_stubs): Likewise.
-	(bfd_elf32_arm_init_maps): Likewise.
-	* elf32-avr.c (elf32_avr_relax_delete_bytes): Likewise.
-	(retrieve_local_syms): Likewise.
-	(elf32_avr_relax_section): Likewise.
-	(elf32_avr_get_relocated_section_contents): Likewise.
-	(get_local_syms): Likewise.
-	* elf32-bfin.c (bfd_bfin_elf32_create_embedded_relocs): Likewise.
-	* elf32-cr16.c (elf32_cr16_get_relocated_section_contents):
-	Likewise.
-	(elf32_cr16_relax_section): Likewise.
-	(bfd_cr16_elf32_create_embedded_relocs): Likewise.
-	* elf32-crx.c (elf32_crx_get_relocated_section_contents):
-	Likewise.
-	(elf32_crx_relax_section): Likewise.
-	* elf32-csky.c (elf32_csky_size_stubs): Likewise.
-	* elf32-epiphany.c (epiphany_elf_relax_section): Likewise.
-	* elf32-ft32.c (elf32_ft32_relax_delete_bytes): Likewise.
-	(elf32_ft32_relax_is_branch_target): Likewise.
-	(ft32_elf_relax_section): Likewise.
-	* elf32-h8300.c (elf32_h8_relax_section): Likewise.
-	(elf32_h8_get_relocated_section_contents): Likewise.
-	* elf32-hppa.c (get_local_syms): Likewise.
-	* elf32-ip2k.c (ip2k_elf_relax_section): Likewise.
-	* elf32-m32c.c (dump_symtab): Likewise.
-	(m32c_elf_relax_plt_section): Likewise.
-	(m32c_elf_relax_section): Likewise.
-	* elf32-m68hc11.c (m68hc11_elf_relax_section): Likewise.
-	* elf32-m68hc1x.c (elf32_m68hc11_size_stubs): Likewise.
-	* elf32-m68k.c (bfd_m68k_elf32_create_embedded_relocs): Likewise.
-	* elf32-metag.c (get_local_syms): Likewise.
-	* elf32-microblaze.c (microblaze_elf_relax_section): Likewise.
-	* elf32-msp430.c (msp430_elf_relax_section): Likewise.
-	* elf32-nds32.c (nds32_elf_relax_delete_blanks): Likewise.
-	(nds32_get_local_syms): Likewise.
-	* elf32-ppc.c (get_sym_h): Likewise.
-	(ppc_elf_late_size_sections): Likewise.
-	* elf32-pru.c (pru_elf_relax_delete_bytes): Likewise.
-	(pru_elf32_relax_section): Likewise.
-	* elf32-rl78.c (rl78_elf_relax_plt_section): Likewise.
-	(rl78_elf_relax_section): Likewise.
-	* elf32-rx.c (elf32_rx_relax_section): Likewise.
-	(rx_dump_symtab): Likewise.
-	* elf32-sh.c (sh_elf_relax_section): Likewise.
-	(sh_elf_get_relocated_section_contents): Likewise.
-	* elf32-spu.c (get_sym_h): Likewise.
-	(discover_functions): Likewise.
-	* elf32-v850.c (v850_elf_relax_section): Likewise.
-	* elf32-xstormy16.c (xstormy16_elf_relax_section): Likewise.
-	* elf32-xtensa.c (retrieve_local_syms): Likewise.
-	* elf64-alpha.c (elf64_alpha_relax_section): Likewise.
-	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
-	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
-	(elf64_vms_link_add_object_symbols): Likewise.
-	* elf64-mmix.c (mmix_elf_relax_section): Likewise.
-	* elf64-ppc.c (opd_entry_value): Likewise.
-	(get_sym_h): Likewise.
-	(ppc64_elf_late_size_sections): Likewise.
-	(ppc64_elf_layout_multitoc): Likewise.
-	(got_and_plt_relr_for_local_syms): Likewise.
-	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
-	(bfd_elfNN_aarch64_init_maps): Likewise.
-	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
-	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
-	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
-	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
-	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
-	pointer argument.  Only allow the full external symbol table.
-	Cache internal symbol table.
-	(group_signature): Update the bfd_elf_get_elf_syms call.
-	(bfd_sym_from_r_symndx): Likewise.
-	(_bfd_elf_free_cached_info): Free internal symbol table cache.
-	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
-	buffer.
-	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Update
-	the bfd_elf_get_elf_syms call.
-	(elf_link_is_defined_archive_symbol): Likewise.  Free cached
-	internal symbol buffer unless it should be kept.
-	(elf_link_add_object_symbols): Update the bfd_elf_get_elf_syms
-	call.  Free cached internal symbol buffer.
-	(bfd_elf_match_symbols_in_sections): Update the
-	bfd_elf_get_elf_syms call.  Don't free the internal symbol table.
-	(elf_final_link_info): Remove external_syms, locsym_shndx and
-	internal_syms.
-	(elf_link_check_versioned_symbol): Update the bfd_elf_get_elf_syms
-	call.
-	(elf_link_input_bfd): Likewise.  Don't use symtab_hdr->contents
-	for internal symbol table.
-	(elf_final_link_free): Updated.
-	(bfd_elf_final_link): Don't set flinfo.external_syms,
-	flinfo.internal_syms nor flinfo.locsym_shndx.
-	(init_reloc_cookie): Remove the keep_memory argument.  Don't
-	cache internal symbol table in symtab_hdr.
-	(fini_reloc_cookie): Removed.
-	(init_reloc_cookie_for_section): Don't call fini_reloc_cookie on
-	error.
-	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
-	fini_reloc_cookie_rels.
-	(bfd_elf_gc_sections): Likewise.  Free the internal symbol table
-	cache.
-	(bfd_elf_discard_info): Replace fini_reloc_cookie_for_section with
-	fini_reloc_cookie_rels.  Don't call fini_reloc_cookie.
-	(bfd_elf_parse_eh_frame_entries): Updated.
-	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
-	use symtab_hdr->contents for internal symbol table.  Set
-	keep_symtab if the symbol table has been updated.
-
-libctf/
-
-	PR ld/33530
-	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
-	table cache.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-bfd.h          |  11 ++-
- bfd/elf-eh-frame.c     |  17 ++---
- bfd/elf-m10200.c       |   4 +-
- bfd/elf-m10300.c       |  10 +--
- bfd/elf.c              | 131 ++++++++++++++++++++++++++---------
- bfd/elf32-arc.c        |   2 +-
- bfd/elf32-arm.c        |   7 +-
- bfd/elf32-avr.c        |  12 ++--
- bfd/elf32-bfin.c       |   2 +-
- bfd/elf32-cr16.c       |   6 +-
- bfd/elf32-crx.c        |   4 +-
- bfd/elf32-csky.c       |   2 +-
- bfd/elf32-epiphany.c   |   2 +-
- bfd/elf32-ft32.c       |   6 +-
- bfd/elf32-h8300.c      |   4 +-
- bfd/elf32-hppa.c       |   2 +-
- bfd/elf32-ip2k.c       |   2 +-
- bfd/elf32-m32c.c       |   8 ++-
- bfd/elf32-m68hc11.c    |   2 +-
- bfd/elf32-m68hc1x.c    |   2 +-
- bfd/elf32-m68k.c       |   2 +-
- bfd/elf32-metag.c      |   2 +-
- bfd/elf32-microblaze.c |   2 +-
- bfd/elf32-msp430.c     |   4 +-
- bfd/elf32-nds32.c      |   4 +-
- bfd/elf32-ppc.c        |   4 +-
- bfd/elf32-pru.c        |   4 +-
- bfd/elf32-rl78.c       |   4 +-
- bfd/elf32-rx.c         |   4 +-
- bfd/elf32-sh.c         |   4 +-
- bfd/elf32-spu.c        |   4 +-
- bfd/elf32-v850.c       |   2 +-
- bfd/elf32-xstormy16.c  |   2 +-
- bfd/elf32-xtensa.c     |   2 +-
- bfd/elf64-alpha.c      |   2 +-
- bfd/elf64-hppa.c       |   2 +-
- bfd/elf64-ia64-vms.c   |   4 +-
- bfd/elf64-mmix.c       |   2 +-
- bfd/elf64-ppc.c        |  12 ++--
- bfd/elfcode.h          |   8 +--
- bfd/elflink.c          | 152 ++++++++++++-----------------------------
- bfd/elfnn-aarch64.c    |   4 +-
- bfd/elfnn-ia64.c       |   2 +-
- bfd/elfnn-kvx.c        |   2 +-
- bfd/elfnn-loongarch.c  |   2 +-
- bfd/elfnn-riscv.c      |   2 +-
- bfd/elfxx-mips.c       |   2 +-
- bfd/elfxx-x86.c        |  24 +++----
- libctf/ctf-open-bfd.c  |   5 +-
- 49 files changed, 243 insertions(+), 262 deletions(-)
-
-diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index 5d19529d972..b7061e55b59 100644
---- a/bfd/elf-bfd.h
-+++ b/bfd/elf-bfd.h
-@@ -2165,6 +2165,11 @@ struct elf_obj_tdata
-   /* Symbol buffer.  */
-   void *symbuf;
- 
-+  /* A pointer to the full internal symbol table of input relocatable
-+     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
-+     all backends use it to only cache local symbols.  */
-+  Elf_Internal_Sym *symtab;
-+
-   /* List of GNU properties.  Will be updated by setup_gnu_properties
-      after all input GNU properties are merged for output.  */
-   elf_property_list *properties;
-@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
-      symbols.  */
-   unsigned int bad_symtab : 1;
- 
-+  /* Set if the symbol table cache should be kept.  */
-+  unsigned int keep_symtab : 1;
-+
-   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
-   unsigned int is_pie : 1;
- 
-@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
- extern char *bfd_elf_string_from_elf_section
-   (bfd *, unsigned, unsigned);
- extern Elf_Internal_Sym *bfd_elf_get_elf_syms
--  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
--   Elf_External_Sym_Shndx *);
-+  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
- extern char * bfd_elf_get_str_section (bfd *, unsigned int);
- extern const char *bfd_elf_sym_name
-   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
-diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
-index 4eda3c991bb..bd2c85291fb 100644
---- a/bfd/elf-eh-frame.c
-+++ b/bfd/elf-eh-frame.c
-@@ -1448,12 +1448,10 @@ _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *h,
- /* The same for all local symbols defined in .eh_frame.  Returns true
-    if any symbol was changed.  */
- 
--static int
-+static void
- adjust_eh_frame_local_symbols (const asection *sec,
- 			       struct elf_reloc_cookie *cookie)
- {
--  int adjusted = 0;
--
-   if (cookie->locsymcount > 1)
-     {
-       unsigned int shndx = elf_section_data (sec)->this_idx;
-@@ -1467,13 +1465,9 @@ adjust_eh_frame_local_symbols (const asection *sec,
- 	    bfd_signed_vma delta = offset_adjust (sym->st_value, sec);
- 
- 	    if (delta != 0)
--	      {
--		adjusted = 1;
--		sym->st_value += delta;
--	      }
-+	      sym->st_value += delta;
- 	  }
-     }
--  return adjusted;
- }
- 
- /* This function is called for each input file before the .eh_frame
-@@ -1611,11 +1605,8 @@ _bfd_elf_discard_section_eh_frame
-   if (sec->size != sec->rawsize)
-     changed = 1;
- 
--  if (changed && adjust_eh_frame_local_symbols (sec, cookie))
--    {
--      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
--      symtab_hdr->contents = (unsigned char *) cookie->locsyms;
--    }
-+  if (changed)
-+    adjust_eh_frame_local_symbols (sec, cookie);
-   return changed;
- }
- 
-diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
-index ca9a92e1221..4da86774ee2 100644
---- a/bfd/elf-m10200.c
-+++ b/bfd/elf-m10200.c
-@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
-index b381bb9037c..373290cbe4a 100644
---- a/bfd/elf-m10300.c
-+++ b/bfd/elf-m10300.c
-@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
- 		  if (isymbuf == NULL)
- 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						    symtab_hdr->sh_info, 0,
--						    NULL, NULL, NULL);
-+						    NULL, NULL);
- 		  if (isymbuf)
- 		    {
- 		      isym = isymbuf + r_symndx;
-@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf.c b/bfd/elf.c
-index bde7414ee21..9e220f0a0d7 100644
---- a/bfd/elf.c
-+++ b/bfd/elf.c
-@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
- }
- 
- /* Read and convert symbols to internal format.
--   SYMCOUNT specifies the number of symbols to read, starting from
--   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
-+   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
-+   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
-    are non-NULL, they are used to store the internal symbols, external
--   symbols, and symbol section index extensions, respectively.
--   Returns a pointer to the internal symbol buffer (malloced if necessary)
--   or NULL if there were no symbols or some kind of problem.  */
-+   symbols, and symbol section index extensions, respectively.  Returns
-+   a pointer to the internal symbol buffer (malloced if necessary) or
-+   NULL if there were no symbols or some kind of problem.  */
- 
- Elf_Internal_Sym *
- bfd_elf_get_elf_syms (bfd *ibfd,
- 		      Elf_Internal_Shdr *symtab_hdr,
--		      size_t symcount,
--		      size_t symoffset,
-+		      size_t partial_symcount,
-+		      size_t partial_symoffset,
- 		      Elf_Internal_Sym *intsym_buf,
--		      void *extsym_buf,
--		      Elf_External_Sym_Shndx *extshndx_buf)
-+		      void *partial_extsym_buf)
- {
-   Elf_Internal_Shdr *shndx_hdr;
-   void *alloc_ext;
-@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
-   const struct elf_backend_data *bed;
-   size_t extsym_size;
-   size_t amt;
--  file_ptr pos;
-+  file_ptr pos = 0;
-+  size_t symcount = partial_symcount;
-+  size_t symoffset = partial_symoffset;
-+  void *extsym_buf = NULL;
-+  Elf_External_Sym_Shndx *extshndx_buf = NULL;
-+  bool cache_symtab = false;
- 
-   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
-     abort ();
-@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
-       return elf_tdata (ibfd)->dt_symtab + symoffset;
-     }
- 
-+  if (elf_tdata (ibfd)->symtab != NULL)
-+    {
-+      /* NB: Should extsym_buf be cached?  */
-+      if (partial_extsym_buf != NULL)
-+	abort ();
-+
-+      if (intsym_buf != NULL)
-+	{
-+	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
-+		  symcount * sizeof (*intsym_buf));
-+	  return intsym_buf;
-+	}
-+      else
-+	return elf_tdata (ibfd)->symtab + symoffset;
-+    }
-+
-   /* Normal syms might have section extension entries.  */
-   shndx_hdr = NULL;
-   if (elf_symtab_shndx_list (ibfd) != NULL)
-@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	}
-     }
- 
-+  if (elf_elfheader (ibfd)->e_type == ET_REL
-+      && symtab_hdr->sh_entsize != 0)
-+    {
-+      symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
-+      symoffset = 0;
-+      cache_symtab = true;
-+    }
-+
-   /* Read the symbols.  */
-   alloc_ext = NULL;
-   alloc_extshndx = NULL;
-   alloc_intsym = NULL;
-   bed = get_elf_backend_data (ibfd);
-   extsym_size = bed->s->sizeof_sym;
--  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
-+  size_t extsym_buf_size;
-+  if (_bfd_mul_overflow (symcount, extsym_size, &extsym_buf_size))
-     {
-       bfd_set_error (bfd_error_file_too_big);
-       return NULL;
-     }
--  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
--  size_t alloc_ext_size = amt;
-+  if (cache_symtab)
-+    pos = symtab_hdr->sh_offset;
-+  else
-+    pos = symtab_hdr->sh_offset + symoffset * extsym_size;
-+  size_t alloc_ext_size = extsym_buf_size;
-   if (bfd_seek (ibfd, pos, SEEK_SET) != 0
-       || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
- 				    &alloc_ext, ibfd, false))
-@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	}
-     }
- 
--  if (intsym_buf == NULL)
-+  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
-     {
--      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
--	{
--	  bfd_set_error (bfd_error_file_too_big);
--	  goto out1;
--	}
--      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
--      intsym_buf = alloc_intsym;
--      if (intsym_buf == NULL)
--	goto out1;
-+      bfd_set_error (bfd_error_file_too_big);
-+      goto out1;
-     }
-+  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
-+  if (alloc_intsym == NULL)
-+    {
-+      intsym_buf = NULL;
-+      goto out1;
-+    }
-+
-+  if (intsym_buf == NULL)
-+    intsym_buf = alloc_intsym;
- 
-   /* Convert the symbols to internal form.  */
--  isymend = intsym_buf + symcount;
--  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
-+  isymend = alloc_intsym + symcount;
-+  for (esym = (const bfd_byte *) extsym_buf, isym = alloc_intsym,
- 	   shndx = extshndx_buf;
-        isym < isymend;
-        esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
-@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	{	
- 	  /* xgettext:c-format */
- 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
--			      ibfd, (unsigned long) (isym - intsym_buf), bind);
-+			      ibfd,
-+			      (unsigned long) (isym - alloc_intsym),
-+			      bind);
- 	  free (alloc_intsym);
- 	  intsym_buf = NULL;
- 	  goto out1;
-@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	{
- 	  /* xgettext:c-format */
- 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
--			      ibfd, (unsigned long) (isym - intsym_buf), t);
-+			      ibfd,
-+			      (unsigned long) (isym - alloc_intsym),
-+			      t);
- 	  free (alloc_intsym);
- 	  intsym_buf = NULL;
- 	  goto out1;
- 	}
-     }
- 
-+  if (intsym_buf != NULL && partial_extsym_buf != NULL)
-+    {
-+      if (partial_symcount != symcount)
-+	abort ();
-+      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
-+    }
-+
-  out1:
-   _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
-  out2:
-   _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
- 
--  return intsym_buf;
-+  if (intsym_buf == NULL)
-+    return intsym_buf;
-+
-+  if (!cache_symtab)
-+    return intsym_buf;
-+
-+  elf_tdata (ibfd)->symtab = alloc_intsym;
-+  if (intsym_buf != alloc_intsym)
-+    {
-+      memcpy (intsym_buf, alloc_intsym + partial_symoffset,
-+	      partial_symcount * sizeof (*intsym_buf));
-+      return intsym_buf;
-+    }
-+  else
-+    return alloc_intsym + partial_symoffset;
- }
- 
- /* Look up a symbol name.  */
-@@ -659,8 +718,6 @@ static const char *
- group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
- {
-   Elf_Internal_Shdr *hdr;
--  unsigned char esym[sizeof (Elf64_External_Sym)];
--  Elf_External_Sym_Shndx eshndx;
-   Elf_Internal_Sym isym;
- 
-   /* First we need to ensure the symbol table is available.  Make sure
-@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
-   /* Go read the symbol.  */
-   hdr = &elf_tdata (abfd)->symtab_hdr;
-   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
--			    &isym, esym, &eshndx) == NULL)
-+			    &isym, NULL) == NULL)
-     return NULL;
- 
-   return bfd_elf_sym_name_raw (abfd, hdr, &isym);
-@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
-   if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
-     {
-       Elf_Internal_Shdr *symtab_hdr;
--      unsigned char esym[sizeof (Elf64_External_Sym)];
--      Elf_External_Sym_Shndx eshndx;
- 
-       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
--				&cache->sym[ent], esym, &eshndx) == NULL)
-+				&cache->sym[ent], NULL) == NULL)
- 	return NULL;
- 
-       if (cache->abfd != abfd)
-@@ -10239,8 +10294,16 @@ _bfd_elf_free_cached_info (bfd *abfd)
- 	      free (sec_info->cies);
- 	    }
- 	}
-+#if 0
-+      /* NB: tdata->symtab_hdr.contents may point to the middle of
-+	 tdata->symtab.  Need to update all backends only to cache
-+	 the malloced memory in tdata->symtab_hdr.contents before
-+	 tdata->symtab_hdr.contents can be freed.  */
-       free (tdata->symtab_hdr.contents);
-       tdata->symtab_hdr.contents = NULL;
-+#endif
-+      free (tdata->symtab);
-+      tdata->symtab = NULL;
-     }
- 
-   return _bfd_generic_bfd_free_cached_info (abfd);
-diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
-index ebfe4dcc26a..ed1dd56a59f 100644
---- a/bfd/elf32-arc.c
-+++ b/bfd/elf32-arc.c
-@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
-           if (isymbuf == NULL)
-             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-                                             symtab_hdr->sh_info, 0,
--                                            NULL, NULL, NULL);
-+					    NULL, NULL);
-           if (isymbuf == NULL)
-             goto error_return;
-         }
-diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
-index ae3dc246be0..627c03eb507 100644
---- a/bfd/elf32-arm.c
-+++ b/bfd/elf32-arm.c
-@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
-   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (local_syms == NULL)
-     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
--				       symtab_hdr->sh_info, 0, NULL, NULL,
-+				       symtab_hdr->sh_info, 0, NULL,
- 				       NULL);
-   if (symtab_hdr->sh_info && local_syms == NULL)
-     return false;
-@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
--				  NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
-index 6653e4d72f6..28e41914bd0 100644
---- a/bfd/elf32-avr.c
-+++ b/bfd/elf32-avr.c
-@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
- 					(abfd,
- 					 symtab_hdr,
- 					 symtab_hdr->sh_info, 0,
--					 NULL, NULL, NULL);
-+					 NULL, NULL);
- 				    if (isymbuf == NULL)
- 				      break;
- 				  }
-@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
-index 7ed1285f4c2..8b74a9f3039 100644
---- a/bfd/elf32-bfin.c
-+++ b/bfd/elf32-bfin.c
-@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
-index 31d1ba41c17..3fc4b4adfa1 100644
---- a/bfd/elf32-cr16.c
-+++ b/bfd/elf32-cr16.c
-@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
-index d2bc1f7ba72..03c20aab6cb 100644
---- a/bfd/elf32-crx.c
-+++ b/bfd/elf32-crx.c
-@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
-index 40781a0e1bb..cc93602f5b0 100644
---- a/bfd/elf32-csky.c
-+++ b/bfd/elf32-csky.c
-@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
- 			    bfd_elf_get_elf_syms (input_bfd,
- 						  symtab_hdr,
- 						  symtab_hdr->sh_info,
--						  0, NULL, NULL, NULL);
-+						  0, NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
-index ea60ce4dc72..bace4943dea 100644
---- a/bfd/elf32-epiphany.c
-+++ b/bfd/elf32-epiphany.c
-@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
-index 6ca175533da..ee9294def64 100644
---- a/bfd/elf32-ft32.c
-+++ b/bfd/elf32-ft32.c
-@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
- 		if (isymbuf == NULL)
- 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		if (isymbuf == NULL)
- 		  return false;
- 	      }
-@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		return false;
- 	    }
-@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-       symtab_hdr->contents = (unsigned char *) isymbuf;
-diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
-index e183577fca4..4bd20f9c433 100644
---- a/bfd/elf32-h8300.c
-+++ b/bfd/elf32-h8300.c
-@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
-index 2f463e12829..085b10b8ea9 100644
---- a/bfd/elf32-hppa.c
-+++ b/bfd/elf32-hppa.c
-@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
-index 5c28a06f318..71de071e1ec 100644
---- a/bfd/elf32-ip2k.c
-+++ b/bfd/elf32-ip2k.c
-@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
-index 8f6881bcb0b..bf24f487c44 100644
---- a/bfd/elf32-m32c.c
-+++ b/bfd/elf32-m32c.c
-@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
-   if (free_internal)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
-     }
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+				      symtab_hdr->sh_info, 0, NULL,
-+				      NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
-index f70716d66a2..b4e0a3220ac 100644
---- a/bfd/elf32-m68hc11.c
-+++ b/bfd/elf32-m68hc11.c
-@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
-index 7e8e0383717..9c1bac23549 100644
---- a/bfd/elf32-m68hc1x.c
-+++ b/bfd/elf32-m68hc1x.c
-@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
-index 44ef102ea60..728da0754ab 100644
---- a/bfd/elf32-m68k.c
-+++ b/bfd/elf32-m68k.c
-@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
-index 916f3e15c72..f754af6e3be 100644
---- a/bfd/elf32-metag.c
-+++ b/bfd/elf32-metag.c
-@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
-index db7ed465779..3a526391676 100644
---- a/bfd/elf32-microblaze.c
-+++ b/bfd/elf32-microblaze.c
-@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
-   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
-   if (isymbuf == NULL)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
--				    0, NULL, NULL, NULL);
-+				    0, NULL, NULL);
-   BFD_ASSERT (isymbuf != NULL);
- 
-   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
-diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
-index 3b356bfe4e2..5250f13a8b9 100644
---- a/bfd/elf32-msp430.c
-+++ b/bfd/elf32-msp430.c
-@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	    if (isymbuf == NULL)
- 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      symtab_hdr->sh_info, 0,
--					      NULL, NULL, NULL);
-+					      NULL, NULL);
- 	    if (isymbuf == NULL)
- 	      goto error_return;
- 	  }
-diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
-index e22b58c4ea8..b15626349a8 100644
---- a/bfd/elf32-nds32.c
-+++ b/bfd/elf32-nds32.c
-@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
-   if (isym == NULL)
-     {
-       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
--				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+				   symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) isym;
-     }
- 
-@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
- 	{
- 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  if (*isymbuf_p == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
-index a3adcf8430e..e77e77fd687 100644
---- a/bfd/elf32-ppc.c
-+++ b/bfd/elf32-ppc.c
-@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
-index 45a86be3ccf..e0d9eb507e2 100644
---- a/bfd/elf32-pru.c
-+++ b/bfd/elf32-pru.c
-@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
-index e2ea6b1d15f..3608008c977 100644
---- a/bfd/elf32-rl78.c
-+++ b/bfd/elf32-rl78.c
-@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
-index d8a2236a233..e18eab7bbda 100644
---- a/bfd/elf32-rx.c
-+++ b/bfd/elf32-rx.c
-@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
-   if (!internal_syms)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
-index e078e41b675..022799f389b 100644
---- a/bfd/elf32-sh.c
-+++ b/bfd/elf32-sh.c
-@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
-index de051e48185..eb1ce1c9a12 100644
---- a/bfd/elf32-spu.c
-+++ b/bfd/elf32-spu.c
-@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
-       free (symtab_hdr->contents);
-       symtab_hdr->contents = NULL;
-       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
--				   NULL, NULL, NULL);
-+				   NULL, NULL);
-       symtab_hdr->contents = (void *) syms;
-       if (syms == NULL)
- 	return false;
-diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
-index 27744814691..4d96cf9fbce 100644
---- a/bfd/elf32-v850.c
-+++ b/bfd/elf32-v850.c
-@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
-index 5cee2f389eb..ae043319206 100644
---- a/bfd/elf32-xstormy16.c
-+++ b/bfd/elf32-xstormy16.c
-@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
-index b21676df36a..c554740f357 100644
---- a/bfd/elf32-xtensa.c
-+++ b/bfd/elf32-xtensa.c
-@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
-index b13c99e4958..2b9eede314d 100644
---- a/bfd/elf64-alpha.c
-+++ b/bfd/elf64-alpha.c
-@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
-index 05bb7f125b7..8cd2d918d8b 100644
---- a/bfd/elf64-hppa.c
-+++ b/bfd/elf64-hppa.c
-@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
- 	  if (local_syms == NULL)
- 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					       symtab_hdr->sh_info, 0,
--					       NULL, NULL, NULL);
-+					       NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
-index 822b263ae2c..f6d00fc1826 100644
---- a/bfd/elf64-ia64-vms.c
-+++ b/bfd/elf64-ia64-vms.c
-@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   if (extsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
- 
-diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
-index bb8350718a2..642b2cdb9bb 100644
---- a/bfd/elf64-mmix.c
-+++ b/bfd/elf64-mmix.c
-@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
-index fdda9e0bbb3..ee15d6f0639 100644
---- a/bfd/elf64-ppc.c
-+++ b/bfd/elf64-ppc.c
-@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
- 			  size_t symcnt = symtab_hdr->sh_info;
- 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						      symcnt, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (sym == NULL)
- 			    break;
- 			  symtab_hdr->contents = (bfd_byte *) sym;
-@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
- 		    {
- 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						  1, symndx,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (sym == NULL)
- 			break;
- 		    }
-@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elfcode.h b/bfd/elfcode.h
-index 5224a1abee6..8777a08a77a 100644
---- a/bfd/elfcode.h
-+++ b/bfd/elfcode.h
-@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
-       size_t i;
- 
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return -1;
- 
-@@ -1523,16 +1523,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
-     }
- 
-   free (xverbuf);
--  if (hdr->contents != (unsigned char *) isymbuf
--      && !elf_use_dt_symtab_p (abfd))
--    free (isymbuf);
-   return symcount;
- 
-  error_return:
-   free (xverbuf);
--  if (hdr->contents != (unsigned char *) isymbuf
--      && !elf_use_dt_symtab_p (abfd))
--    free (isymbuf);
-   return -1;
- }
- 
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 3f3ea2cce51..da4da5c453a 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
-   struct elf_strtab_hash *dynstr;
-   size_t dynstr_index;
-   char *name;
--  Elf_External_Sym_Shndx eshndx;
--  char esym[sizeof (Elf64_External_Sym)];
- 
-   if (! is_elf_hash_table (info->hash))
-     return 0;
-@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
- 
-   /* Go find the symbol, so that we can find it's name.  */
-   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
--			     1, input_indx, &entry->isym, esym, &eshndx))
-+			     1, input_indx, &entry->isym, NULL))
-     {
-       bfd_release (input_bfd, entry);
-       return 0;
-@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
- 
-   /* Read in the symbol table.  */
-   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				  NULL, NULL, NULL);
-+				  NULL, NULL);
-   if (isymbuf == NULL)
-     return false;
- 
-@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
- 	}
-     }
- 
--  free (isymbuf);
-+  if (!elf_tdata (abfd)->keep_symtab)
-+    {
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-+    }
- 
-   return result;
- }
-@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   if (extsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
- 
-@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
- 
-   free (extversym);
-   extversym = NULL;
--  free (isymbuf);
--  isymbuf = NULL;
-+
-+  /* NB: Since st_shndx of symbol from discarded section is changed to
-+     SHN_UNDEF, free the cached symbol table.  */
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
- 
-   if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
-     {
-@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   free (nondeflt_vers);
-   free (extversym);
-  error_free_sym:
--  free (isymbuf);
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
-  error_return:
-   return false;
- }
-@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-   if (ssymbuf1 == NULL)
-     {
-       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
--				       NULL, NULL, NULL);
-+				       NULL, NULL);
-       if (isymbuf1 == NULL)
- 	goto done;
- 
-@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-   if (ssymbuf1 == NULL || ssymbuf2 == NULL)
-     {
-       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
--				       NULL, NULL, NULL);
-+				       NULL, NULL);
-       if (isymbuf2 == NULL)
- 	goto done;
- 
-@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-  done:
-   free (symtable1);
-   free (symtable2);
--  free (isymbuf1);
--  free (isymbuf2);
- 
-   return result;
- }
-@@ -9056,14 +9060,6 @@ struct elf_final_link_info
-   void *external_relocs;
-   /* Buffer large enough to hold internal relocs of any section.  */
-   Elf_Internal_Rela *internal_relocs;
--  /* Buffer large enough to hold external local symbols of any input
--     BFD.  */
--  bfd_byte *external_syms;
--  /* And a buffer for symbol section indices.  */
--  Elf_External_Sym_Shndx *locsym_shndx;
--  /* Buffer large enough to hold internal local symbols of any input
--     BFD.  */
--  Elf_Internal_Sym *internal_syms;
-   /* Array large enough to hold a symbol index for each local symbol
-      of any input BFD.  */
-   long *indices;
-@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
- 	continue;
- 
-       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return false;
- 
-@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
-   Elf_Internal_Shdr *symtab_hdr;
-   size_t locsymcount;
-   size_t extsymoff;
--  Elf_Internal_Sym *isymbuf;
-+  Elf_Internal_Sym *isymbuf = NULL;
-   Elf_Internal_Sym *isym;
-   Elf_Internal_Sym *isymend;
-   long *pindex;
-@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
- 	     ? -1 : ~elf_gnu_osabi_retain));
- 
-   /* Read the local symbols.  */
--  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
--  if (isymbuf == NULL && locsymcount != 0)
-+  if (locsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				      flinfo->internal_syms,
--				      flinfo->external_syms,
--				      flinfo->locsym_shndx);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return false;
-     }
-@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
-   free (flinfo->contents);
-   free (flinfo->external_relocs);
-   free (flinfo->internal_relocs);
--  free (flinfo->external_syms);
--  free (flinfo->locsym_shndx);
--  free (flinfo->internal_syms);
-   free (flinfo->indices);
-   free (flinfo->sections);
-   if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
-@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
-   bfd_size_type max_external_reloc_size;
-   bfd_size_type max_internal_reloc_count;
-   bfd_size_type max_sym_count;
--  bfd_size_type max_sym_shndx_count;
-   Elf_Internal_Sym elfsym;
-   unsigned int i;
-   Elf_Internal_Shdr *symtab_hdr;
-@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
-     }
-   max_internal_reloc_count = 0;
-   max_sym_count = 0;
--  max_sym_shndx_count = 0;
-   merged = false;
-   for (o = abfd->sections; o != NULL; o = o->next)
-     {
-@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 		  if (sym_count > max_sym_count)
- 		    max_sym_count = sym_count;
- 
--		  if (sym_count > max_sym_shndx_count
--		      && elf_symtab_shndx_list (sec->owner) != NULL)
--		    max_sym_shndx_count = sym_count;
--
- 		  esdi = elf_section_data (sec);
- 
- 		  if (esdi->this_hdr.sh_type == SHT_REL
-@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 
-   if (max_sym_count != 0)
-     {
--      amt = max_sym_count * bed->s->sizeof_sym;
--      flinfo.external_syms = (bfd_byte *) bfd_malloc (amt);
--      if (flinfo.external_syms == NULL)
--	goto error_return;
--
--      amt = max_sym_count * sizeof (Elf_Internal_Sym);
--      flinfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
--      if (flinfo.internal_syms == NULL)
--	goto error_return;
--
-       amt = max_sym_count * sizeof (long);
-       flinfo.indices = (long int *) bfd_malloc (amt);
-       if (flinfo.indices == NULL)
-@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 	goto error_return;
-     }
- 
--  if (max_sym_shndx_count != 0)
--    {
--      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
--      flinfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
--      if (flinfo.locsym_shndx == NULL)
--	goto error_return;
--    }
--
-   if (htab->tls_sec)
-     {
-       bfd_vma base, end = 0;  /* Both bytes.  */
-@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 
- static bool
- init_reloc_cookie (struct elf_reloc_cookie *cookie,
--		   struct bfd_link_info *info, bfd *abfd,
--		   bool keep_memory)
-+		   struct bfd_link_info *info, bfd *abfd)
- {
-   Elf_Internal_Shdr *symtab_hdr;
-   const struct elf_backend_data *bed;
-@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
-   else
-     cookie->r_sym_shift = 32;
- 
--  cookie->locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
--  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
-+  if (cookie->locsymcount != 0)
-     {
-       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      cookie->locsymcount, 0,
--					      NULL, NULL, NULL);
-+					      NULL, NULL);
-       if (cookie->locsyms == NULL)
- 	{
- 	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
- 	  return false;
- 	}
--      if (keep_memory || _bfd_elf_link_keep_memory (info))
--	{
--	  symtab_hdr->contents = (bfd_byte *) cookie->locsyms;
--	  info->cache_size += (cookie->locsymcount
--			       * sizeof (Elf_Internal_Sym));
--	}
-     }
-   return true;
- }
- 
--/* Free the memory allocated by init_reloc_cookie, if appropriate.  */
--
--static void
--fini_reloc_cookie (struct elf_reloc_cookie *cookie, bfd *abfd)
--{
--  Elf_Internal_Shdr *symtab_hdr;
--
--  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
--  if (symtab_hdr->contents != (unsigned char *) cookie->locsyms)
--    free (cookie->locsyms);
--}
--
- /* Initialize the relocation information in COOKIE for input section SEC
-    of input bfd ABFD.  */
- 
-@@ -13996,28 +13942,9 @@ init_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
- 			       struct bfd_link_info *info,
- 			       asection *sec, bool keep_memory)
- {
--  if (!init_reloc_cookie (cookie, info, sec->owner, keep_memory))
--    goto error1;
--  if (!init_reloc_cookie_rels (cookie, info, sec->owner, sec,
--			       keep_memory))
--    goto error2;
--  return true;
--
-- error2:
--  fini_reloc_cookie (cookie, sec->owner);
-- error1:
--  return false;
--}
--
--/* Free the memory allocated by init_reloc_cookie_for_section,
--   if appropriate.  */
--
--static void
--fini_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
--			       asection *sec)
--{
--  fini_reloc_cookie_rels (cookie, sec);
--  fini_reloc_cookie (cookie, sec->owner);
-+  return (init_reloc_cookie (cookie, info, sec->owner)
-+	  && init_reloc_cookie_rels (cookie, info, sec->owner, sec,
-+				     keep_memory));
- }
- \f
- /* Garbage collect unused sections.  */
-@@ -14209,7 +14136,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
- 		ret = false;
- 		break;
- 	      }
--	  fini_reloc_cookie_for_section (&cookie, sec);
-+	  fini_reloc_cookie_rels (&cookie, sec);
- 	}
-     }
- 
-@@ -14231,7 +14158,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
- 	  if (!_bfd_elf_gc_mark_fdes (info, sec, eh_frame,
- 				      gc_mark_hook, &cookie))
- 	    ret = false;
--	  fini_reloc_cookie_for_section (&cookie, eh_frame);
-+	  fini_reloc_cookie_rels (&cookie, eh_frame);
- 	}
-     }
- 
-@@ -14665,7 +14592,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
-       if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
- 	continue;
- 
--      if (!init_reloc_cookie (&cookie, info, ibfd, false))
-+      if (!init_reloc_cookie (&cookie, info, ibfd))
- 	return false;
- 
-       for (sec = ibfd->sections; sec; sec = sec->next)
-@@ -14724,7 +14651,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
- 	  if (elf_section_data (sec)->sec_info
- 	      && (sec->flags & SEC_LINKER_CREATED) == 0)
- 	    elf_eh_frame_section (sub) = sec;
--	  fini_reloc_cookie_for_section (&cookie, sec);
-+	  fini_reloc_cookie_rels (&cookie, sec);
- 	  sec = bfd_get_next_section_by_name (NULL, sec);
- 	}
-     }
-@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
- 	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
- 	      return false;
- 	  }
-+
-+      if (!elf_tdata (sub)->keep_symtab
-+	  && !_bfd_elf_link_keep_memory (info))
-+	{
-+	  free (elf_tdata (sub)->symtab);
-+	  elf_tdata (sub)->symtab = NULL;
-+	}
-     }
- 
-   /* Allow the backend to mark additional target specific sections.  */
-@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 					  &cookie))
- 	    changed = 1;
- 
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
-     }
- 
-@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 		changed = 1;
- 	    }
- 
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
- 
-       eh_alignment = ((1 << o->alignment_power)
-@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 		    changed = 1;
- 		}
- 	    }
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
-       /* Update the reference to the output .sframe section.  Used to
- 	 determine later if PT_GNU_SFRAME segment is to be generated.  */
-@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 
-       if (bed->elf_backend_discard_info != NULL)
- 	{
--	  if (!init_reloc_cookie (&cookie, info, abfd, false))
-+	  if (!init_reloc_cookie (&cookie, info, abfd))
- 	    return -1;
- 
- 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
- 	    changed = 1;
--
--	  fini_reloc_cookie (&cookie, abfd);
- 	}
-     }
- 
-diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
-index 3c3c2899674..553ba27b604 100644
---- a/bfd/elfnn-aarch64.c
-+++ b/bfd/elfnn-aarch64.c
-@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
- 			local_syms
- 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (local_syms == NULL)
- 			goto error_ret_free_internal;
- 		    }
-@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
-index 528b1dcdcc3..48fce2380cd 100644
---- a/bfd/elfnn-ia64.c
-+++ b/bfd/elfnn-ia64.c
-@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
-index 3b44db57421..8e75b400570 100644
---- a/bfd/elfnn-kvx.c
-+++ b/bfd/elfnn-kvx.c
-@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
-index 53cdb783859..10a4f99add7 100644
---- a/bfd/elfnn-loongarch.c
-+++ b/bfd/elfnn-loongarch.c
-@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
-       && !(symtab_hdr->contents =
- 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						   symtab_hdr->sh_info,
--						   0, NULL, NULL, NULL)))
-+						   0, NULL, NULL)))
-     return true;
- 
-   /* Estimate the maximum alignment for all output sections once time
-diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
-index 09cf7076733..d1ab410a94f 100644
---- a/bfd/elfnn-riscv.c
-+++ b/bfd/elfnn-riscv.c
-@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
- 	  && !(symtab_hdr->contents =
- 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						       symtab_hdr->sh_info,
--						       0, NULL, NULL, NULL)))
-+						       0, NULL, NULL)))
- 	goto fail;
- 
-       /* Get the value of the symbol referred to by the reloc.  */
-diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
-index 00ef0663728..44c58362dda 100644
---- a/bfd/elfxx-mips.c
-+++ b/bfd/elfxx-mips.c
-@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index 140e86888a6..53083e0b54c 100644
---- a/bfd/elfxx-x86.c
-+++ b/bfd/elfxx-x86.c
-@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
- 	  /* Read this BFD's local symbols.  */
- 	  if (isymbuf == NULL)
- 	    {
--	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-+	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+					      symtab_hdr->sh_info,
-+					      0, NULL, NULL);
- 	      if (isymbuf == NULL)
--		{
--		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
--						  symtab_hdr->sh_info,
--						  0, NULL, NULL, NULL);
--		  if (isymbuf == NULL)
--		    goto error_return;
--		}
-+		goto error_return;
- 	    }
- 
- 	  isym = isymbuf + r_symndx;
-@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
-   return_status = true;
- 
- error_return:
--  if ((unsigned char *) isymbuf != symtab_hdr->contents)
--    {
--      /* Cache the symbol buffer if it must be kept.  */
--      if (keep_symbuf)
--	symtab_hdr->contents = (unsigned char *) isymbuf;
--      else
--	free (isymbuf);
--    }
-+  /* If the symbol table has been updated, it must be kept since it will
-+     be used later.  */
-+  if (keep_symbuf)
-+    elf_tdata (abfd)->keep_symtab = 1;
-   if (elf_section_data (input_section)->relocs != internal_relocs)
-     free (internal_relocs);
-   return return_status;
-diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
-index 7241de70709..205347c4e22 100644
---- a/libctf/ctf-open-bfd.c
-+++ b/libctf/ctf-open-bfd.c
-@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
- 	}
- 
-       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
--				      NULL, symtab, NULL);
--      free (isymbuf);
-+				      NULL, symtab);
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-       if (isymbuf == NULL)
- 	{
- 	  bfderrstr = N_("cannot read symbol table");
--- 
-GitLab
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-10  5:28 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-10  5:28 UTC (permalink / raw
  To: gentoo-commits

commit:     380d983472c3292f2276aecee685768a12fd92e9
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 10 05:27:54 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 10 05:28:14 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=380d9834

9999: try patch from branch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 166 +++++++++++++++++----
 1 file changed, 138 insertions(+), 28 deletions(-)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
index dbf42d5..acae3cf 100644
--- a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -1,27 +1,128 @@
-From a724f5c582f8df93eee54d43cf7766bc47d30f44 Mon Sep 17 00:00:00 2001
+From 13058a8b8feb26ddafb62995f164d81dce02979c Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Thu, 9 Oct 2025 13:16:19 +0800
-Subject: [PATCH] elf: Cache internal symbol table in relocatable BFD
+Subject: [PATCH] elf: Cache full internal symbol table for relocatable input
 
-Don't cache internal symbol table in symtab_hdr->contents.
+Cache internal symbol table for relocatable input and use the internal
+symbol table cache for both local and global symbols to avoid swapping in
+the same symbol table repeatedly for --gc-sections.  This improves linker
+--gc-sections speed by ~20x.
+
+Most backends cache the local symbol table in symtab_hdr->contents. But
+some backends cache something else in it.  Since symtab_hdr->contents may
+point to the middle of the internal symbol table cache, we can release
+symtab_hdr->contents only when no backends cache the local symbol table
+in it.
 
 bfd/
 
 	PR ld/33530
-	* elf-bfd.h (elf_obj_tdata): Add symtab.
+	* elf-bfd.h (elf_obj_tdata): Add symtab and keep_symtab.
+	(bfd_elf_get_elf_syms): Remove the Elf_External_Sym_Shndx pointer
+	argument.
 	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
 	return void.
 	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
 	internal symbol table in symtab_hdr.
-	* elf.c (bfd_elf_get_elf_syms): Cache internal symbol table in
-	BFD.
-	(_bfd_elf_free_cached_info): Free internal symbol table in BFD.
+	* elf-m10200.c (mn10200_elf_relax_section): Drop the last argument
+	to bfd_elf_get_elf_syms.
+	(mn10200_elf_get_relocated_section_contents): Likewise.
+	* elf-m10300.c (mn10300_elf_check_relocs): Likewise.
+	(mn10300_elf_relax_section): Likewise.
+	(mn10300_elf_get_relocated_section_contents): Likewise.
+	* elf32-arc.c (arc_elf_relax_section): Likewise.
+	* elf32-arm.c (cmse_scan): Likewise.
+	(elf32_arm_size_stubs): Likewise.
+	(bfd_elf32_arm_init_maps): Likewise.
+	* elf32-avr.c (elf32_avr_relax_delete_bytes): Likewise.
+	(retrieve_local_syms): Likewise.
+	(elf32_avr_relax_section): Likewise.
+	(elf32_avr_get_relocated_section_contents): Likewise.
+	(get_local_syms): Likewise.
+	* elf32-bfin.c (bfd_bfin_elf32_create_embedded_relocs): Likewise.
+	* elf32-cr16.c (elf32_cr16_get_relocated_section_contents):
+	Likewise.
+	(elf32_cr16_relax_section): Likewise.
+	(bfd_cr16_elf32_create_embedded_relocs): Likewise.
+	* elf32-crx.c (elf32_crx_get_relocated_section_contents):
+	Likewise.
+	(elf32_crx_relax_section): Likewise.
+	* elf32-csky.c (elf32_csky_size_stubs): Likewise.
+	* elf32-epiphany.c (epiphany_elf_relax_section): Likewise.
+	* elf32-ft32.c (elf32_ft32_relax_delete_bytes): Likewise.
+	(elf32_ft32_relax_is_branch_target): Likewise.
+	(ft32_elf_relax_section): Likewise.
+	* elf32-h8300.c (elf32_h8_relax_section): Likewise.
+	(elf32_h8_get_relocated_section_contents): Likewise.
+	* elf32-hppa.c (get_local_syms): Likewise.
+	* elf32-ip2k.c (ip2k_elf_relax_section): Likewise.
+	* elf32-m32c.c (dump_symtab): Likewise.
+	(m32c_elf_relax_plt_section): Likewise.
+	(m32c_elf_relax_section): Likewise.
+	* elf32-m68hc11.c (m68hc11_elf_relax_section): Likewise.
+	* elf32-m68hc1x.c (elf32_m68hc11_size_stubs): Likewise.
+	* elf32-m68k.c (bfd_m68k_elf32_create_embedded_relocs): Likewise.
+	* elf32-metag.c (get_local_syms): Likewise.
+	* elf32-microblaze.c (microblaze_elf_relax_section): Likewise.
+	* elf32-msp430.c (msp430_elf_relax_section): Likewise.
+	* elf32-nds32.c (nds32_elf_relax_delete_blanks): Likewise.
+	(nds32_get_local_syms): Likewise.
+	* elf32-ppc.c (get_sym_h): Likewise.
+	(ppc_elf_late_size_sections): Likewise.
+	* elf32-pru.c (pru_elf_relax_delete_bytes): Likewise.
+	(pru_elf32_relax_section): Likewise.
+	* elf32-rl78.c (rl78_elf_relax_plt_section): Likewise.
+	(rl78_elf_relax_section): Likewise.
+	* elf32-rx.c (elf32_rx_relax_section): Likewise.
+	(rx_dump_symtab): Likewise.
+	* elf32-sh.c (sh_elf_relax_section): Likewise.
+	(sh_elf_get_relocated_section_contents): Likewise.
+	* elf32-spu.c (get_sym_h): Likewise.
+	(discover_functions): Likewise.
+	* elf32-v850.c (v850_elf_relax_section): Likewise.
+	* elf32-xstormy16.c (xstormy16_elf_relax_section): Likewise.
+	* elf32-xtensa.c (retrieve_local_syms): Likewise.
+	* elf64-alpha.c (elf64_alpha_relax_section): Likewise.
+	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
+	* elf64-ia64-vms.c (elf64_ia64_relax_section): Likewise.
+	(elf64_vms_link_add_object_symbols): Likewise.
+	* elf64-mmix.c (mmix_elf_relax_section): Likewise.
+	* elf64-ppc.c (opd_entry_value): Likewise.
+	(get_sym_h): Likewise.
+	(ppc64_elf_late_size_sections): Likewise.
+	(ppc64_elf_layout_multitoc): Likewise.
+	(got_and_plt_relr_for_local_syms): Likewise.
+	* elfnn-aarch64.c (_bfd_aarch64_add_call_stub_entries): Likewise.
+	(bfd_elfNN_aarch64_init_maps): Likewise.
+	* elfnn-ia64.c (elfNN_ia64_relax_section): Likewise.
+	* elfnn-kvx.c (elfNN_kvx_size_stubs): Likewise.
+	* elfnn-loongarch.c (_bfd_riscv_relax_section): Likewise.
+	* elfxx-mips.c (_bfd_mips_elf_relax_section): Likewise.
+	* elf.c (bfd_elf_get_elf_syms): Drop the Elf_External_Sym_Shndx
+	pointer argument.  Only allow the full external symbol table.
+	Cache internal symbol table.
+	(group_signature): Update the bfd_elf_get_elf_syms call.
+	(bfd_sym_from_r_symndx): Likewise.
+	(_bfd_elf_free_cached_info): Free internal symbol table cache.
 	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
 	buffer.
-	* elflink.c (elf_link_is_defined_archive_symbol): Likewise.
-	(elf_link_add_object_symbols): Free cached internal symbol buffer.
-	(elf_link_input_bfd): Don't use symtab_hdr->contents for internal
-	symbol table.
+	* elflink.c (bfd_elf_link_record_local_dynamic_symbol): Update
+	the bfd_elf_get_elf_syms call.
+	(elf_link_is_defined_archive_symbol): Likewise.  Free cached
+	internal symbol buffer unless it should be kept.
+	(elf_link_add_object_symbols): Update the bfd_elf_get_elf_syms
+	call.  Free cached internal symbol buffer.
+	(bfd_elf_match_symbols_in_sections): Update the
+	bfd_elf_get_elf_syms call.  Don't free the internal symbol table.
+	(elf_final_link_info): Remove external_syms, locsym_shndx and
+	internal_syms.
+	(elf_link_check_versioned_symbol): Update the bfd_elf_get_elf_syms
+	call.
+	(elf_link_input_bfd): Likewise.  Don't use symtab_hdr->contents
+	for internal symbol table.
+	(elf_final_link_free): Updated.
+	(bfd_elf_final_link): Don't set flinfo.external_syms,
+	flinfo.internal_syms nor flinfo.locsym_shndx.
 	(init_reloc_cookie): Remove the keep_memory argument.  Don't
 	cache internal symbol table in symtab_hdr.
 	(fini_reloc_cookie): Removed.
@@ -29,17 +130,20 @@ bfd/
 	error.
 	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
 	fini_reloc_cookie_rels.
-	(bfd_elf_gc_sections): Likewise.
-	(bfd_elf_discard_info): Likewise.  Don't call fini_reloc_cookie.
+	(bfd_elf_gc_sections): Likewise.  Free the internal symbol table
+	cache.
+	(bfd_elf_discard_info): Replace fini_reloc_cookie_for_section with
+	fini_reloc_cookie_rels.  Don't call fini_reloc_cookie.
 	(bfd_elf_parse_eh_frame_entries): Updated.
 	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
-	use symtab_hdr->contents for internal symbol table.
+	use symtab_hdr->contents for internal symbol table.  Set
+	keep_symtab if the symbol table has been updated.
 
 libctf/
 
 	PR ld/33530
 	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
-	table in BFD.
+	table cache.
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
@@ -47,7 +151,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  bfd/elf-eh-frame.c     |  17 ++---
  bfd/elf-m10200.c       |   4 +-
  bfd/elf-m10300.c       |  10 +--
- bfd/elf.c              | 127 ++++++++++++++++++++++++----------
+ bfd/elf.c              | 131 ++++++++++++++++++++++++++---------
  bfd/elf32-arc.c        |   2 +-
  bfd/elf32-arm.c        |   7 +-
  bfd/elf32-avr.c        |  12 ++--
@@ -92,7 +196,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  bfd/elfxx-mips.c       |   2 +-
  bfd/elfxx-x86.c        |  24 +++----
  libctf/ctf-open-bfd.c  |   5 +-
- 49 files changed, 237 insertions(+), 264 deletions(-)
+ 49 files changed, 243 insertions(+), 262 deletions(-)
 
 diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
 index 5d19529d972..b7061e55b59 100644
@@ -249,7 +353,7 @@ index b381bb9037c..373290cbe4a 100644
  	    goto error_return;
  	}
 diff --git a/bfd/elf.c b/bfd/elf.c
-index bde7414ee21..edce3d3b95f 100644
+index bde7414ee21..9e220f0a0d7 100644
 --- a/bfd/elf.c
 +++ b/bfd/elf.c
 @@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
@@ -372,17 +476,17 @@ index bde7414ee21..edce3d3b95f 100644
 -	goto out1;
 +      bfd_set_error (bfd_error_file_too_big);
 +      goto out1;
-+    }
+     }
 +  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
 +  if (alloc_intsym == NULL)
 +    {
 +      intsym_buf = NULL;
 +      goto out1;
-     }
- 
++    }
++
 +  if (intsym_buf == NULL)
 +    intsym_buf = alloc_intsym;
-+
+ 
    /* Convert the symbols to internal form.  */
 -  isymend = intsym_buf + symcount;
 -  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
@@ -479,14 +583,20 @@ index bde7414ee21..edce3d3b95f 100644
  	return NULL;
  
        if (cache->abfd != abfd)
-@@ -10239,8 +10294,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
+@@ -10239,8 +10294,16 @@ _bfd_elf_free_cached_info (bfd *abfd)
  	      free (sec_info->cies);
  	    }
  	}
--      free (tdata->symtab_hdr.contents);
--      tdata->symtab_hdr.contents = NULL;
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
++#if 0
++      /* NB: tdata->symtab_hdr.contents may point to the middle of
++	 tdata->symtab.  Need to update all backends only to cache
++	 the malloced memory in tdata->symtab_hdr.contents before
++	 tdata->symtab_hdr.contents can be freed.  */
+       free (tdata->symtab_hdr.contents);
+       tdata->symtab_hdr.contents = NULL;
++#endif
++      free (tdata->symtab);
++      tdata->symtab = NULL;
      }
  
    return _bfd_generic_bfd_free_cached_info (abfd);
@@ -1771,5 +1881,5 @@ index 7241de70709..205347c4e22 100644
  	{
  	  bfderrstr = N_("cannot read symbol table");
 -- 
-2.51.0
+GitLab
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-10  5:28 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-10  5:28 UTC (permalink / raw
  To: gentoo-commits

commit:     cd3584bbe4b07a4e4f0220cdb41724ed4dc69007
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 10 05:27:21 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 10 05:28:13 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=cd3584bb

Reapply "9999: add H.J.'s patch for caching"

This reverts commit 556e1cf24506afead74ca345a3d00e517019b073.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1775 ++++++++++++++++++++
 1 file changed, 1775 insertions(+)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
new file mode 100644
index 0000000..dbf42d5
--- /dev/null
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -0,0 +1,1775 @@
+From a724f5c582f8df93eee54d43cf7766bc47d30f44 Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Thu, 9 Oct 2025 13:16:19 +0800
+Subject: [PATCH] elf: Cache internal symbol table in relocatable BFD
+
+Don't cache internal symbol table in symtab_hdr->contents.
+
+bfd/
+
+	PR ld/33530
+	* elf-bfd.h (elf_obj_tdata): Add symtab.
+	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
+	return void.
+	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
+	internal symbol table in symtab_hdr.
+	* elf.c (bfd_elf_get_elf_syms): Cache internal symbol table in
+	BFD.
+	(_bfd_elf_free_cached_info): Free internal symbol table in BFD.
+	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
+	buffer.
+	* elflink.c (elf_link_is_defined_archive_symbol): Likewise.
+	(elf_link_add_object_symbols): Free cached internal symbol buffer.
+	(elf_link_input_bfd): Don't use symtab_hdr->contents for internal
+	symbol table.
+	(init_reloc_cookie): Remove the keep_memory argument.  Don't
+	cache internal symbol table in symtab_hdr.
+	(fini_reloc_cookie): Removed.
+	(init_reloc_cookie_for_section): Don't call fini_reloc_cookie on
+	error.
+	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
+	fini_reloc_cookie_rels.
+	(bfd_elf_gc_sections): Likewise.
+	(bfd_elf_discard_info): Likewise.  Don't call fini_reloc_cookie.
+	(bfd_elf_parse_eh_frame_entries): Updated.
+	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
+	use symtab_hdr->contents for internal symbol table.
+
+libctf/
+
+	PR ld/33530
+	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
+	table in BFD.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-bfd.h          |  11 ++-
+ bfd/elf-eh-frame.c     |  17 ++---
+ bfd/elf-m10200.c       |   4 +-
+ bfd/elf-m10300.c       |  10 +--
+ bfd/elf.c              | 127 ++++++++++++++++++++++++----------
+ bfd/elf32-arc.c        |   2 +-
+ bfd/elf32-arm.c        |   7 +-
+ bfd/elf32-avr.c        |  12 ++--
+ bfd/elf32-bfin.c       |   2 +-
+ bfd/elf32-cr16.c       |   6 +-
+ bfd/elf32-crx.c        |   4 +-
+ bfd/elf32-csky.c       |   2 +-
+ bfd/elf32-epiphany.c   |   2 +-
+ bfd/elf32-ft32.c       |   6 +-
+ bfd/elf32-h8300.c      |   4 +-
+ bfd/elf32-hppa.c       |   2 +-
+ bfd/elf32-ip2k.c       |   2 +-
+ bfd/elf32-m32c.c       |   8 ++-
+ bfd/elf32-m68hc11.c    |   2 +-
+ bfd/elf32-m68hc1x.c    |   2 +-
+ bfd/elf32-m68k.c       |   2 +-
+ bfd/elf32-metag.c      |   2 +-
+ bfd/elf32-microblaze.c |   2 +-
+ bfd/elf32-msp430.c     |   4 +-
+ bfd/elf32-nds32.c      |   4 +-
+ bfd/elf32-ppc.c        |   4 +-
+ bfd/elf32-pru.c        |   4 +-
+ bfd/elf32-rl78.c       |   4 +-
+ bfd/elf32-rx.c         |   4 +-
+ bfd/elf32-sh.c         |   4 +-
+ bfd/elf32-spu.c        |   4 +-
+ bfd/elf32-v850.c       |   2 +-
+ bfd/elf32-xstormy16.c  |   2 +-
+ bfd/elf32-xtensa.c     |   2 +-
+ bfd/elf64-alpha.c      |   2 +-
+ bfd/elf64-hppa.c       |   2 +-
+ bfd/elf64-ia64-vms.c   |   4 +-
+ bfd/elf64-mmix.c       |   2 +-
+ bfd/elf64-ppc.c        |  12 ++--
+ bfd/elfcode.h          |   8 +--
+ bfd/elflink.c          | 152 ++++++++++++-----------------------------
+ bfd/elfnn-aarch64.c    |   4 +-
+ bfd/elfnn-ia64.c       |   2 +-
+ bfd/elfnn-kvx.c        |   2 +-
+ bfd/elfnn-loongarch.c  |   2 +-
+ bfd/elfnn-riscv.c      |   2 +-
+ bfd/elfxx-mips.c       |   2 +-
+ bfd/elfxx-x86.c        |  24 +++----
+ libctf/ctf-open-bfd.c  |   5 +-
+ 49 files changed, 237 insertions(+), 264 deletions(-)
+
+diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
+index 5d19529d972..b7061e55b59 100644
+--- a/bfd/elf-bfd.h
++++ b/bfd/elf-bfd.h
+@@ -2165,6 +2165,11 @@ struct elf_obj_tdata
+   /* Symbol buffer.  */
+   void *symbuf;
+ 
++  /* A pointer to the full internal symbol table of input relocatable
++     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
++     all backends use it to only cache local symbols.  */
++  Elf_Internal_Sym *symtab;
++
+   /* List of GNU properties.  Will be updated by setup_gnu_properties
+      after all input GNU properties are merged for output.  */
+   elf_property_list *properties;
+@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
+      symbols.  */
+   unsigned int bad_symtab : 1;
+ 
++  /* Set if the symbol table cache should be kept.  */
++  unsigned int keep_symtab : 1;
++
+   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
+   unsigned int is_pie : 1;
+ 
+@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
+ extern char *bfd_elf_string_from_elf_section
+   (bfd *, unsigned, unsigned);
+ extern Elf_Internal_Sym *bfd_elf_get_elf_syms
+-  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
+-   Elf_External_Sym_Shndx *);
++  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
+ extern char * bfd_elf_get_str_section (bfd *, unsigned int);
+ extern const char *bfd_elf_sym_name
+   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
+diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
+index 4eda3c991bb..bd2c85291fb 100644
+--- a/bfd/elf-eh-frame.c
++++ b/bfd/elf-eh-frame.c
+@@ -1448,12 +1448,10 @@ _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *h,
+ /* The same for all local symbols defined in .eh_frame.  Returns true
+    if any symbol was changed.  */
+ 
+-static int
++static void
+ adjust_eh_frame_local_symbols (const asection *sec,
+ 			       struct elf_reloc_cookie *cookie)
+ {
+-  int adjusted = 0;
+-
+   if (cookie->locsymcount > 1)
+     {
+       unsigned int shndx = elf_section_data (sec)->this_idx;
+@@ -1467,13 +1465,9 @@ adjust_eh_frame_local_symbols (const asection *sec,
+ 	    bfd_signed_vma delta = offset_adjust (sym->st_value, sec);
+ 
+ 	    if (delta != 0)
+-	      {
+-		adjusted = 1;
+-		sym->st_value += delta;
+-	      }
++	      sym->st_value += delta;
+ 	  }
+     }
+-  return adjusted;
+ }
+ 
+ /* This function is called for each input file before the .eh_frame
+@@ -1611,11 +1605,8 @@ _bfd_elf_discard_section_eh_frame
+   if (sec->size != sec->rawsize)
+     changed = 1;
+ 
+-  if (changed && adjust_eh_frame_local_symbols (sec, cookie))
+-    {
+-      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-      symtab_hdr->contents = (unsigned char *) cookie->locsyms;
+-    }
++  if (changed)
++    adjust_eh_frame_local_symbols (sec, cookie);
+   return changed;
+ }
+ 
+diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
+index ca9a92e1221..4da86774ee2 100644
+--- a/bfd/elf-m10200.c
++++ b/bfd/elf-m10200.c
+@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
+index b381bb9037c..373290cbe4a 100644
+--- a/bfd/elf-m10300.c
++++ b/bfd/elf-m10300.c
+@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
+ 		  if (isymbuf == NULL)
+ 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						    symtab_hdr->sh_info, 0,
+-						    NULL, NULL, NULL);
++						    NULL, NULL);
+ 		  if (isymbuf)
+ 		    {
+ 		      isym = isymbuf + r_symndx;
+@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf.c b/bfd/elf.c
+index bde7414ee21..edce3d3b95f 100644
+--- a/bfd/elf.c
++++ b/bfd/elf.c
+@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
+ }
+ 
+ /* Read and convert symbols to internal format.
+-   SYMCOUNT specifies the number of symbols to read, starting from
+-   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
++   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
++   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
+    are non-NULL, they are used to store the internal symbols, external
+-   symbols, and symbol section index extensions, respectively.
+-   Returns a pointer to the internal symbol buffer (malloced if necessary)
+-   or NULL if there were no symbols or some kind of problem.  */
++   symbols, and symbol section index extensions, respectively.  Returns
++   a pointer to the internal symbol buffer (malloced if necessary) or
++   NULL if there were no symbols or some kind of problem.  */
+ 
+ Elf_Internal_Sym *
+ bfd_elf_get_elf_syms (bfd *ibfd,
+ 		      Elf_Internal_Shdr *symtab_hdr,
+-		      size_t symcount,
+-		      size_t symoffset,
++		      size_t partial_symcount,
++		      size_t partial_symoffset,
+ 		      Elf_Internal_Sym *intsym_buf,
+-		      void *extsym_buf,
+-		      Elf_External_Sym_Shndx *extshndx_buf)
++		      void *partial_extsym_buf)
+ {
+   Elf_Internal_Shdr *shndx_hdr;
+   void *alloc_ext;
+@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+   const struct elf_backend_data *bed;
+   size_t extsym_size;
+   size_t amt;
+-  file_ptr pos;
++  file_ptr pos = 0;
++  size_t symcount = partial_symcount;
++  size_t symoffset = partial_symoffset;
++  void *extsym_buf = NULL;
++  Elf_External_Sym_Shndx *extshndx_buf = NULL;
++  bool cache_symtab = false;
+ 
+   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+     abort ();
+@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+       return elf_tdata (ibfd)->dt_symtab + symoffset;
+     }
+ 
++  if (elf_tdata (ibfd)->symtab != NULL)
++    {
++      /* NB: Should extsym_buf be cached?  */
++      if (partial_extsym_buf != NULL)
++	abort ();
++
++      if (intsym_buf != NULL)
++	{
++	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
++		  symcount * sizeof (*intsym_buf));
++	  return intsym_buf;
++	}
++      else
++	return elf_tdata (ibfd)->symtab + symoffset;
++    }
++
+   /* Normal syms might have section extension entries.  */
+   shndx_hdr = NULL;
+   if (elf_symtab_shndx_list (ibfd) != NULL)
+@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
++  if (elf_elfheader (ibfd)->e_type == ET_REL
++      && symtab_hdr->sh_entsize != 0)
++    {
++      symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
++      symoffset = 0;
++      cache_symtab = true;
++    }
++
+   /* Read the symbols.  */
+   alloc_ext = NULL;
+   alloc_extshndx = NULL;
+   alloc_intsym = NULL;
+   bed = get_elf_backend_data (ibfd);
+   extsym_size = bed->s->sizeof_sym;
+-  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
++  size_t extsym_buf_size;
++  if (_bfd_mul_overflow (symcount, extsym_size, &extsym_buf_size))
+     {
+       bfd_set_error (bfd_error_file_too_big);
+       return NULL;
+     }
+-  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
+-  size_t alloc_ext_size = amt;
++  if (cache_symtab)
++    pos = symtab_hdr->sh_offset;
++  else
++    pos = symtab_hdr->sh_offset + symoffset * extsym_size;
++  size_t alloc_ext_size = extsym_buf_size;
+   if (bfd_seek (ibfd, pos, SEEK_SET) != 0
+       || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
+ 				    &alloc_ext, ibfd, false))
+@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
+-  if (intsym_buf == NULL)
++  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+     {
+-      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+-	{
+-	  bfd_set_error (bfd_error_file_too_big);
+-	  goto out1;
+-	}
+-      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      intsym_buf = alloc_intsym;
+-      if (intsym_buf == NULL)
+-	goto out1;
++      bfd_set_error (bfd_error_file_too_big);
++      goto out1;
++    }
++  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
++  if (alloc_intsym == NULL)
++    {
++      intsym_buf = NULL;
++      goto out1;
+     }
+ 
++  if (intsym_buf == NULL)
++    intsym_buf = alloc_intsym;
++
+   /* Convert the symbols to internal form.  */
+-  isymend = intsym_buf + symcount;
+-  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
++  isymend = alloc_intsym + symcount;
++  for (esym = (const bfd_byte *) extsym_buf, isym = alloc_intsym,
+ 	   shndx = extshndx_buf;
+        isym < isymend;
+        esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
+@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{	
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), bind);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      bind);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), t);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      t);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+ 	}
+     }
+ 
++  if (intsym_buf != NULL && partial_extsym_buf != NULL)
++    {
++      if (partial_symcount != symcount)
++	abort ();
++      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
++    }
++
+  out1:
+   _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
+  out2:
+   _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
+ 
+-  return intsym_buf;
++  if (intsym_buf == NULL)
++    return intsym_buf;
++
++  if (!cache_symtab)
++    return intsym_buf;
++
++  elf_tdata (ibfd)->symtab = alloc_intsym;
++  if (intsym_buf != alloc_intsym)
++    {
++      memcpy (intsym_buf, alloc_intsym + partial_symoffset,
++	      partial_symcount * sizeof (*intsym_buf));
++      return intsym_buf;
++    }
++  else
++    return alloc_intsym + partial_symoffset;
+ }
+ 
+ /* Look up a symbol name.  */
+@@ -659,8 +718,6 @@ static const char *
+ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+ {
+   Elf_Internal_Shdr *hdr;
+-  unsigned char esym[sizeof (Elf64_External_Sym)];
+-  Elf_External_Sym_Shndx eshndx;
+   Elf_Internal_Sym isym;
+ 
+   /* First we need to ensure the symbol table is available.  Make sure
+@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+   /* Go read the symbol.  */
+   hdr = &elf_tdata (abfd)->symtab_hdr;
+   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
+-			    &isym, esym, &eshndx) == NULL)
++			    &isym, NULL) == NULL)
+     return NULL;
+ 
+   return bfd_elf_sym_name_raw (abfd, hdr, &isym);
+@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
+   if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
+     {
+       Elf_Internal_Shdr *symtab_hdr;
+-      unsigned char esym[sizeof (Elf64_External_Sym)];
+-      Elf_External_Sym_Shndx eshndx;
+ 
+       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
+-				&cache->sym[ent], esym, &eshndx) == NULL)
++				&cache->sym[ent], NULL) == NULL)
+ 	return NULL;
+ 
+       if (cache->abfd != abfd)
+@@ -10239,8 +10294,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
+ 	      free (sec_info->cies);
+ 	    }
+ 	}
+-      free (tdata->symtab_hdr.contents);
+-      tdata->symtab_hdr.contents = NULL;
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
+     }
+ 
+   return _bfd_generic_bfd_free_cached_info (abfd);
+diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
+index ebfe4dcc26a..ed1dd56a59f 100644
+--- a/bfd/elf32-arc.c
++++ b/bfd/elf32-arc.c
+@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
+           if (isymbuf == NULL)
+             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+                                             symtab_hdr->sh_info, 0,
+-                                            NULL, NULL, NULL);
++					    NULL, NULL);
+           if (isymbuf == NULL)
+             goto error_return;
+         }
+diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
+index ae3dc246be0..627c03eb507 100644
+--- a/bfd/elf32-arm.c
++++ b/bfd/elf32-arm.c
+@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
+   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (local_syms == NULL)
+     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+-				       symtab_hdr->sh_info, 0, NULL, NULL,
++				       symtab_hdr->sh_info, 0, NULL,
+ 				       NULL);
+   if (symtab_hdr->sh_info && local_syms == NULL)
+     return false;
+@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
+-				  NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
+index 6653e4d72f6..28e41914bd0 100644
+--- a/bfd/elf32-avr.c
++++ b/bfd/elf32-avr.c
+@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 					(abfd,
+ 					 symtab_hdr,
+ 					 symtab_hdr->sh_info, 0,
+-					 NULL, NULL, NULL);
++					 NULL, NULL);
+ 				    if (isymbuf == NULL)
+ 				      break;
+ 				  }
+@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
+index 7ed1285f4c2..8b74a9f3039 100644
+--- a/bfd/elf32-bfin.c
++++ b/bfd/elf32-bfin.c
+@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
+index 31d1ba41c17..3fc4b4adfa1 100644
+--- a/bfd/elf32-cr16.c
++++ b/bfd/elf32-cr16.c
+@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
+index d2bc1f7ba72..03c20aab6cb 100644
+--- a/bfd/elf32-crx.c
++++ b/bfd/elf32-crx.c
+@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
+index 40781a0e1bb..cc93602f5b0 100644
+--- a/bfd/elf32-csky.c
++++ b/bfd/elf32-csky.c
+@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
+ 			    bfd_elf_get_elf_syms (input_bfd,
+ 						  symtab_hdr,
+ 						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
++						  0, NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
+index ea60ce4dc72..bace4943dea 100644
+--- a/bfd/elf32-epiphany.c
++++ b/bfd/elf32-epiphany.c
+@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
+index 6ca175533da..ee9294def64 100644
+--- a/bfd/elf32-ft32.c
++++ b/bfd/elf32-ft32.c
+@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
+ 		if (isymbuf == NULL)
+ 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		if (isymbuf == NULL)
+ 		  return false;
+ 	      }
+@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		return false;
+ 	    }
+@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+       symtab_hdr->contents = (unsigned char *) isymbuf;
+diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
+index e183577fca4..4bd20f9c433 100644
+--- a/bfd/elf32-h8300.c
++++ b/bfd/elf32-h8300.c
+@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
+index 2f463e12829..085b10b8ea9 100644
+--- a/bfd/elf32-hppa.c
++++ b/bfd/elf32-hppa.c
+@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
+index 5c28a06f318..71de071e1ec 100644
+--- a/bfd/elf32-ip2k.c
++++ b/bfd/elf32-ip2k.c
+@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
+index 8f6881bcb0b..bf24f487c44 100644
+--- a/bfd/elf32-m32c.c
++++ b/bfd/elf32-m32c.c
+@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
+   if (free_internal)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
+     }
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++				      symtab_hdr->sh_info, 0, NULL,
++				      NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
+index f70716d66a2..b4e0a3220ac 100644
+--- a/bfd/elf32-m68hc11.c
++++ b/bfd/elf32-m68hc11.c
+@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
+index 7e8e0383717..9c1bac23549 100644
+--- a/bfd/elf32-m68hc1x.c
++++ b/bfd/elf32-m68hc1x.c
+@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
+index 44ef102ea60..728da0754ab 100644
+--- a/bfd/elf32-m68k.c
++++ b/bfd/elf32-m68k.c
+@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
+index 916f3e15c72..f754af6e3be 100644
+--- a/bfd/elf32-metag.c
++++ b/bfd/elf32-metag.c
+@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
+index db7ed465779..3a526391676 100644
+--- a/bfd/elf32-microblaze.c
++++ b/bfd/elf32-microblaze.c
+@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
+   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
+   if (isymbuf == NULL)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
+-				    0, NULL, NULL, NULL);
++				    0, NULL, NULL);
+   BFD_ASSERT (isymbuf != NULL);
+ 
+   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
+diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
+index 3b356bfe4e2..5250f13a8b9 100644
+--- a/bfd/elf32-msp430.c
++++ b/bfd/elf32-msp430.c
+@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	    if (isymbuf == NULL)
+ 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      symtab_hdr->sh_info, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+ 	    if (isymbuf == NULL)
+ 	      goto error_return;
+ 	  }
+diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
+index e22b58c4ea8..b15626349a8 100644
+--- a/bfd/elf32-nds32.c
++++ b/bfd/elf32-nds32.c
+@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
+   if (isym == NULL)
+     {
+       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++				   symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) isym;
+     }
+ 
+@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
+ 	{
+ 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  if (*isymbuf_p == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
+index a3adcf8430e..e77e77fd687 100644
+--- a/bfd/elf32-ppc.c
++++ b/bfd/elf32-ppc.c
+@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
+index 45a86be3ccf..e0d9eb507e2 100644
+--- a/bfd/elf32-pru.c
++++ b/bfd/elf32-pru.c
+@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
+index e2ea6b1d15f..3608008c977 100644
+--- a/bfd/elf32-rl78.c
++++ b/bfd/elf32-rl78.c
+@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
+index d8a2236a233..e18eab7bbda 100644
+--- a/bfd/elf32-rx.c
++++ b/bfd/elf32-rx.c
+@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
+   if (!internal_syms)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
+index e078e41b675..022799f389b 100644
+--- a/bfd/elf32-sh.c
++++ b/bfd/elf32-sh.c
+@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
+index de051e48185..eb1ce1c9a12 100644
+--- a/bfd/elf32-spu.c
++++ b/bfd/elf32-spu.c
+@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
+       free (symtab_hdr->contents);
+       symtab_hdr->contents = NULL;
+       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
+-				   NULL, NULL, NULL);
++				   NULL, NULL);
+       symtab_hdr->contents = (void *) syms;
+       if (syms == NULL)
+ 	return false;
+diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
+index 27744814691..4d96cf9fbce 100644
+--- a/bfd/elf32-v850.c
++++ b/bfd/elf32-v850.c
+@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
+index 5cee2f389eb..ae043319206 100644
+--- a/bfd/elf32-xstormy16.c
++++ b/bfd/elf32-xstormy16.c
+@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
+index b21676df36a..c554740f357 100644
+--- a/bfd/elf32-xtensa.c
++++ b/bfd/elf32-xtensa.c
+@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
+index b13c99e4958..2b9eede314d 100644
+--- a/bfd/elf64-alpha.c
++++ b/bfd/elf64-alpha.c
+@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
+index 05bb7f125b7..8cd2d918d8b 100644
+--- a/bfd/elf64-hppa.c
++++ b/bfd/elf64-hppa.c
+@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
+ 	  if (local_syms == NULL)
+ 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					       symtab_hdr->sh_info, 0,
+-					       NULL, NULL, NULL);
++					       NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
+index 822b263ae2c..f6d00fc1826 100644
+--- a/bfd/elf64-ia64-vms.c
++++ b/bfd/elf64-ia64-vms.c
+@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
+index bb8350718a2..642b2cdb9bb 100644
+--- a/bfd/elf64-mmix.c
++++ b/bfd/elf64-mmix.c
+@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
+index fdda9e0bbb3..ee15d6f0639 100644
+--- a/bfd/elf64-ppc.c
++++ b/bfd/elf64-ppc.c
+@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
+ 			  size_t symcnt = symtab_hdr->sh_info;
+ 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						      symcnt, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (sym == NULL)
+ 			    break;
+ 			  symtab_hdr->contents = (bfd_byte *) sym;
+@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
+ 		    {
+ 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						  1, symndx,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (sym == NULL)
+ 			break;
+ 		    }
+@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elfcode.h b/bfd/elfcode.h
+index 5224a1abee6..8777a08a77a 100644
+--- a/bfd/elfcode.h
++++ b/bfd/elfcode.h
+@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+       size_t i;
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return -1;
+ 
+@@ -1523,16 +1523,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+     }
+ 
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return symcount;
+ 
+  error_return:
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return -1;
+ }
+ 
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index 3f3ea2cce51..da4da5c453a 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+   struct elf_strtab_hash *dynstr;
+   size_t dynstr_index;
+   char *name;
+-  Elf_External_Sym_Shndx eshndx;
+-  char esym[sizeof (Elf64_External_Sym)];
+ 
+   if (! is_elf_hash_table (info->hash))
+     return 0;
+@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+ 
+   /* Go find the symbol, so that we can find it's name.  */
+   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
+-			     1, input_indx, &entry->isym, esym, &eshndx))
++			     1, input_indx, &entry->isym, NULL))
+     {
+       bfd_release (input_bfd, entry);
+       return 0;
+@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 
+   /* Read in the symbol table.  */
+   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				  NULL, NULL, NULL);
++				  NULL, NULL);
+   if (isymbuf == NULL)
+     return false;
+ 
+@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 	}
+     }
+ 
+-  free (isymbuf);
++  if (!elf_tdata (abfd)->keep_symtab)
++    {
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
++    }
+ 
+   return result;
+ }
+@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 
+   free (extversym);
+   extversym = NULL;
+-  free (isymbuf);
+-  isymbuf = NULL;
++
++  /* NB: Since st_shndx of symbol from discarded section is changed to
++     SHN_UNDEF, free the cached symbol table.  */
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+ 
+   if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
+     {
+@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   free (nondeflt_vers);
+   free (extversym);
+  error_free_sym:
+-  free (isymbuf);
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+  error_return:
+   return false;
+ }
+@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL)
+     {
+       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf1 == NULL)
+ 	goto done;
+ 
+@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL || ssymbuf2 == NULL)
+     {
+       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf2 == NULL)
+ 	goto done;
+ 
+@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+  done:
+   free (symtable1);
+   free (symtable2);
+-  free (isymbuf1);
+-  free (isymbuf2);
+ 
+   return result;
+ }
+@@ -9056,14 +9060,6 @@ struct elf_final_link_info
+   void *external_relocs;
+   /* Buffer large enough to hold internal relocs of any section.  */
+   Elf_Internal_Rela *internal_relocs;
+-  /* Buffer large enough to hold external local symbols of any input
+-     BFD.  */
+-  bfd_byte *external_syms;
+-  /* And a buffer for symbol section indices.  */
+-  Elf_External_Sym_Shndx *locsym_shndx;
+-  /* Buffer large enough to hold internal local symbols of any input
+-     BFD.  */
+-  Elf_Internal_Sym *internal_syms;
+   /* Array large enough to hold a symbol index for each local symbol
+      of any input BFD.  */
+   long *indices;
+@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+ 	continue;
+ 
+       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+ 
+@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+   Elf_Internal_Shdr *symtab_hdr;
+   size_t locsymcount;
+   size_t extsymoff;
+-  Elf_Internal_Sym *isymbuf;
++  Elf_Internal_Sym *isymbuf = NULL;
+   Elf_Internal_Sym *isym;
+   Elf_Internal_Sym *isymend;
+   long *pindex;
+@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+ 	     ? -1 : ~elf_gnu_osabi_retain));
+ 
+   /* Read the local symbols.  */
+-  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (isymbuf == NULL && locsymcount != 0)
++  if (locsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				      flinfo->internal_syms,
+-				      flinfo->external_syms,
+-				      flinfo->locsym_shndx);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+     }
+@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
+   free (flinfo->contents);
+   free (flinfo->external_relocs);
+   free (flinfo->internal_relocs);
+-  free (flinfo->external_syms);
+-  free (flinfo->locsym_shndx);
+-  free (flinfo->internal_syms);
+   free (flinfo->indices);
+   free (flinfo->sections);
+   if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
+@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+   bfd_size_type max_external_reloc_size;
+   bfd_size_type max_internal_reloc_count;
+   bfd_size_type max_sym_count;
+-  bfd_size_type max_sym_shndx_count;
+   Elf_Internal_Sym elfsym;
+   unsigned int i;
+   Elf_Internal_Shdr *symtab_hdr;
+@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+     }
+   max_internal_reloc_count = 0;
+   max_sym_count = 0;
+-  max_sym_shndx_count = 0;
+   merged = false;
+   for (o = abfd->sections; o != NULL; o = o->next)
+     {
+@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 		  if (sym_count > max_sym_count)
+ 		    max_sym_count = sym_count;
+ 
+-		  if (sym_count > max_sym_shndx_count
+-		      && elf_symtab_shndx_list (sec->owner) != NULL)
+-		    max_sym_shndx_count = sym_count;
+-
+ 		  esdi = elf_section_data (sec);
+ 
+ 		  if (esdi->this_hdr.sh_type == SHT_REL
+@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+   if (max_sym_count != 0)
+     {
+-      amt = max_sym_count * bed->s->sizeof_sym;
+-      flinfo.external_syms = (bfd_byte *) bfd_malloc (amt);
+-      if (flinfo.external_syms == NULL)
+-	goto error_return;
+-
+-      amt = max_sym_count * sizeof (Elf_Internal_Sym);
+-      flinfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      if (flinfo.internal_syms == NULL)
+-	goto error_return;
+-
+       amt = max_sym_count * sizeof (long);
+       flinfo.indices = (long int *) bfd_malloc (amt);
+       if (flinfo.indices == NULL)
+@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 	goto error_return;
+     }
+ 
+-  if (max_sym_shndx_count != 0)
+-    {
+-      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
+-      flinfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
+-      if (flinfo.locsym_shndx == NULL)
+-	goto error_return;
+-    }
+-
+   if (htab->tls_sec)
+     {
+       bfd_vma base, end = 0;  /* Both bytes.  */
+@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+ static bool
+ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+-		   struct bfd_link_info *info, bfd *abfd,
+-		   bool keep_memory)
++		   struct bfd_link_info *info, bfd *abfd)
+ {
+   Elf_Internal_Shdr *symtab_hdr;
+   const struct elf_backend_data *bed;
+@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+   else
+     cookie->r_sym_shift = 32;
+ 
+-  cookie->locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
++  if (cookie->locsymcount != 0)
+     {
+       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      cookie->locsymcount, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+       if (cookie->locsyms == NULL)
+ 	{
+ 	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
+ 	  return false;
+ 	}
+-      if (keep_memory || _bfd_elf_link_keep_memory (info))
+-	{
+-	  symtab_hdr->contents = (bfd_byte *) cookie->locsyms;
+-	  info->cache_size += (cookie->locsymcount
+-			       * sizeof (Elf_Internal_Sym));
+-	}
+     }
+   return true;
+ }
+ 
+-/* Free the memory allocated by init_reloc_cookie, if appropriate.  */
+-
+-static void
+-fini_reloc_cookie (struct elf_reloc_cookie *cookie, bfd *abfd)
+-{
+-  Elf_Internal_Shdr *symtab_hdr;
+-
+-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-  if (symtab_hdr->contents != (unsigned char *) cookie->locsyms)
+-    free (cookie->locsyms);
+-}
+-
+ /* Initialize the relocation information in COOKIE for input section SEC
+    of input bfd ABFD.  */
+ 
+@@ -13996,28 +13942,9 @@ init_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+ 			       struct bfd_link_info *info,
+ 			       asection *sec, bool keep_memory)
+ {
+-  if (!init_reloc_cookie (cookie, info, sec->owner, keep_memory))
+-    goto error1;
+-  if (!init_reloc_cookie_rels (cookie, info, sec->owner, sec,
+-			       keep_memory))
+-    goto error2;
+-  return true;
+-
+- error2:
+-  fini_reloc_cookie (cookie, sec->owner);
+- error1:
+-  return false;
+-}
+-
+-/* Free the memory allocated by init_reloc_cookie_for_section,
+-   if appropriate.  */
+-
+-static void
+-fini_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+-			       asection *sec)
+-{
+-  fini_reloc_cookie_rels (cookie, sec);
+-  fini_reloc_cookie (cookie, sec->owner);
++  return (init_reloc_cookie (cookie, info, sec->owner)
++	  && init_reloc_cookie_rels (cookie, info, sec->owner, sec,
++				     keep_memory));
+ }
+ \f
+ /* Garbage collect unused sections.  */
+@@ -14209,7 +14136,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 		ret = false;
+ 		break;
+ 	      }
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	}
+     }
+ 
+@@ -14231,7 +14158,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 	  if (!_bfd_elf_gc_mark_fdes (info, sec, eh_frame,
+ 				      gc_mark_hook, &cookie))
+ 	    ret = false;
+-	  fini_reloc_cookie_for_section (&cookie, eh_frame);
++	  fini_reloc_cookie_rels (&cookie, eh_frame);
+ 	}
+     }
+ 
+@@ -14665,7 +14592,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
+       if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+ 	continue;
+ 
+-      if (!init_reloc_cookie (&cookie, info, ibfd, false))
++      if (!init_reloc_cookie (&cookie, info, ibfd))
+ 	return false;
+ 
+       for (sec = ibfd->sections; sec; sec = sec->next)
+@@ -14724,7 +14651,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	  if (elf_section_data (sec)->sec_info
+ 	      && (sec->flags & SEC_LINKER_CREATED) == 0)
+ 	    elf_eh_frame_section (sub) = sec;
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	  sec = bfd_get_next_section_by_name (NULL, sec);
+ 	}
+     }
+@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
+ 	      return false;
+ 	  }
++
++      if (!elf_tdata (sub)->keep_symtab
++	  && !_bfd_elf_link_keep_memory (info))
++	{
++	  free (elf_tdata (sub)->symtab);
++	  elf_tdata (sub)->symtab = NULL;
++	}
+     }
+ 
+   /* Allow the backend to mark additional target specific sections.  */
+@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 					  &cookie))
+ 	    changed = 1;
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+     }
+ 
+@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		changed = 1;
+ 	    }
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+ 
+       eh_alignment = ((1 << o->alignment_power)
+@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		    changed = 1;
+ 		}
+ 	    }
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+       /* Update the reference to the output .sframe section.  Used to
+ 	 determine later if PT_GNU_SFRAME segment is to be generated.  */
+@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 
+       if (bed->elf_backend_discard_info != NULL)
+ 	{
+-	  if (!init_reloc_cookie (&cookie, info, abfd, false))
++	  if (!init_reloc_cookie (&cookie, info, abfd))
+ 	    return -1;
+ 
+ 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
+ 	    changed = 1;
+-
+-	  fini_reloc_cookie (&cookie, abfd);
+ 	}
+     }
+ 
+diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
+index 3c3c2899674..553ba27b604 100644
+--- a/bfd/elfnn-aarch64.c
++++ b/bfd/elfnn-aarch64.c
+@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
+ 			local_syms
+ 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (local_syms == NULL)
+ 			goto error_ret_free_internal;
+ 		    }
+@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
+index 528b1dcdcc3..48fce2380cd 100644
+--- a/bfd/elfnn-ia64.c
++++ b/bfd/elfnn-ia64.c
+@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
+index 3b44db57421..8e75b400570 100644
+--- a/bfd/elfnn-kvx.c
++++ b/bfd/elfnn-kvx.c
+@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
+index 53cdb783859..10a4f99add7 100644
+--- a/bfd/elfnn-loongarch.c
++++ b/bfd/elfnn-loongarch.c
+@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
+       && !(symtab_hdr->contents =
+ 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						   symtab_hdr->sh_info,
+-						   0, NULL, NULL, NULL)))
++						   0, NULL, NULL)))
+     return true;
+ 
+   /* Estimate the maximum alignment for all output sections once time
+diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
+index 09cf7076733..d1ab410a94f 100644
+--- a/bfd/elfnn-riscv.c
++++ b/bfd/elfnn-riscv.c
+@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
+ 	  && !(symtab_hdr->contents =
+ 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						       symtab_hdr->sh_info,
+-						       0, NULL, NULL, NULL)))
++						       0, NULL, NULL)))
+ 	goto fail;
+ 
+       /* Get the value of the symbol referred to by the reloc.  */
+diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
+index 00ef0663728..44c58362dda 100644
+--- a/bfd/elfxx-mips.c
++++ b/bfd/elfxx-mips.c
+@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index 140e86888a6..53083e0b54c 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+ 	  /* Read this BFD's local symbols.  */
+ 	  if (isymbuf == NULL)
+ 	    {
+-	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
++	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++					      symtab_hdr->sh_info,
++					      0, NULL, NULL);
+ 	      if (isymbuf == NULL)
+-		{
+-		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
+-		  if (isymbuf == NULL)
+-		    goto error_return;
+-		}
++		goto error_return;
+ 	    }
+ 
+ 	  isym = isymbuf + r_symndx;
+@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+   return_status = true;
+ 
+ error_return:
+-  if ((unsigned char *) isymbuf != symtab_hdr->contents)
+-    {
+-      /* Cache the symbol buffer if it must be kept.  */
+-      if (keep_symbuf)
+-	symtab_hdr->contents = (unsigned char *) isymbuf;
+-      else
+-	free (isymbuf);
+-    }
++  /* If the symbol table has been updated, it must be kept since it will
++     be used later.  */
++  if (keep_symbuf)
++    elf_tdata (abfd)->keep_symtab = 1;
+   if (elf_section_data (input_section)->relocs != internal_relocs)
+     free (internal_relocs);
+   return return_status;
+diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
+index 7241de70709..205347c4e22 100644
+--- a/libctf/ctf-open-bfd.c
++++ b/libctf/ctf-open-bfd.c
+@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+ 	}
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
+-				      NULL, symtab, NULL);
+-      free (isymbuf);
++				      NULL, symtab);
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
+       if (isymbuf == NULL)
+ 	{
+ 	  bfderrstr = N_("cannot read symbol table");
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-10  5:25 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-10  5:25 UTC (permalink / raw
  To: gentoo-commits

commit:     556e1cf24506afead74ca345a3d00e517019b073
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 10 05:25:05 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 10 05:25:17 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=556e1cf2

Revert "9999: add H.J.'s patch for caching"

This reverts commit a3c33571d7f0c64df3b509556b9a11388451070c.

I get some test failures.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1775 --------------------
 1 file changed, 1775 deletions(-)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
deleted file mode 100644
index dbf42d5..0000000
--- a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
+++ /dev/null
@@ -1,1775 +0,0 @@
-From a724f5c582f8df93eee54d43cf7766bc47d30f44 Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Thu, 9 Oct 2025 13:16:19 +0800
-Subject: [PATCH] elf: Cache internal symbol table in relocatable BFD
-
-Don't cache internal symbol table in symtab_hdr->contents.
-
-bfd/
-
-	PR ld/33530
-	* elf-bfd.h (elf_obj_tdata): Add symtab.
-	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
-	return void.
-	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
-	internal symbol table in symtab_hdr.
-	* elf.c (bfd_elf_get_elf_syms): Cache internal symbol table in
-	BFD.
-	(_bfd_elf_free_cached_info): Free internal symbol table in BFD.
-	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
-	buffer.
-	* elflink.c (elf_link_is_defined_archive_symbol): Likewise.
-	(elf_link_add_object_symbols): Free cached internal symbol buffer.
-	(elf_link_input_bfd): Don't use symtab_hdr->contents for internal
-	symbol table.
-	(init_reloc_cookie): Remove the keep_memory argument.  Don't
-	cache internal symbol table in symtab_hdr.
-	(fini_reloc_cookie): Removed.
-	(init_reloc_cookie_for_section): Don't call fini_reloc_cookie on
-	error.
-	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
-	fini_reloc_cookie_rels.
-	(bfd_elf_gc_sections): Likewise.
-	(bfd_elf_discard_info): Likewise.  Don't call fini_reloc_cookie.
-	(bfd_elf_parse_eh_frame_entries): Updated.
-	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
-	use symtab_hdr->contents for internal symbol table.
-
-libctf/
-
-	PR ld/33530
-	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
-	table in BFD.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-bfd.h          |  11 ++-
- bfd/elf-eh-frame.c     |  17 ++---
- bfd/elf-m10200.c       |   4 +-
- bfd/elf-m10300.c       |  10 +--
- bfd/elf.c              | 127 ++++++++++++++++++++++++----------
- bfd/elf32-arc.c        |   2 +-
- bfd/elf32-arm.c        |   7 +-
- bfd/elf32-avr.c        |  12 ++--
- bfd/elf32-bfin.c       |   2 +-
- bfd/elf32-cr16.c       |   6 +-
- bfd/elf32-crx.c        |   4 +-
- bfd/elf32-csky.c       |   2 +-
- bfd/elf32-epiphany.c   |   2 +-
- bfd/elf32-ft32.c       |   6 +-
- bfd/elf32-h8300.c      |   4 +-
- bfd/elf32-hppa.c       |   2 +-
- bfd/elf32-ip2k.c       |   2 +-
- bfd/elf32-m32c.c       |   8 ++-
- bfd/elf32-m68hc11.c    |   2 +-
- bfd/elf32-m68hc1x.c    |   2 +-
- bfd/elf32-m68k.c       |   2 +-
- bfd/elf32-metag.c      |   2 +-
- bfd/elf32-microblaze.c |   2 +-
- bfd/elf32-msp430.c     |   4 +-
- bfd/elf32-nds32.c      |   4 +-
- bfd/elf32-ppc.c        |   4 +-
- bfd/elf32-pru.c        |   4 +-
- bfd/elf32-rl78.c       |   4 +-
- bfd/elf32-rx.c         |   4 +-
- bfd/elf32-sh.c         |   4 +-
- bfd/elf32-spu.c        |   4 +-
- bfd/elf32-v850.c       |   2 +-
- bfd/elf32-xstormy16.c  |   2 +-
- bfd/elf32-xtensa.c     |   2 +-
- bfd/elf64-alpha.c      |   2 +-
- bfd/elf64-hppa.c       |   2 +-
- bfd/elf64-ia64-vms.c   |   4 +-
- bfd/elf64-mmix.c       |   2 +-
- bfd/elf64-ppc.c        |  12 ++--
- bfd/elfcode.h          |   8 +--
- bfd/elflink.c          | 152 ++++++++++++-----------------------------
- bfd/elfnn-aarch64.c    |   4 +-
- bfd/elfnn-ia64.c       |   2 +-
- bfd/elfnn-kvx.c        |   2 +-
- bfd/elfnn-loongarch.c  |   2 +-
- bfd/elfnn-riscv.c      |   2 +-
- bfd/elfxx-mips.c       |   2 +-
- bfd/elfxx-x86.c        |  24 +++----
- libctf/ctf-open-bfd.c  |   5 +-
- 49 files changed, 237 insertions(+), 264 deletions(-)
-
-diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index 5d19529d972..b7061e55b59 100644
---- a/bfd/elf-bfd.h
-+++ b/bfd/elf-bfd.h
-@@ -2165,6 +2165,11 @@ struct elf_obj_tdata
-   /* Symbol buffer.  */
-   void *symbuf;
- 
-+  /* A pointer to the full internal symbol table of input relocatable
-+     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
-+     all backends use it to only cache local symbols.  */
-+  Elf_Internal_Sym *symtab;
-+
-   /* List of GNU properties.  Will be updated by setup_gnu_properties
-      after all input GNU properties are merged for output.  */
-   elf_property_list *properties;
-@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
-      symbols.  */
-   unsigned int bad_symtab : 1;
- 
-+  /* Set if the symbol table cache should be kept.  */
-+  unsigned int keep_symtab : 1;
-+
-   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
-   unsigned int is_pie : 1;
- 
-@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
- extern char *bfd_elf_string_from_elf_section
-   (bfd *, unsigned, unsigned);
- extern Elf_Internal_Sym *bfd_elf_get_elf_syms
--  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
--   Elf_External_Sym_Shndx *);
-+  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
- extern char * bfd_elf_get_str_section (bfd *, unsigned int);
- extern const char *bfd_elf_sym_name
-   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
-diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
-index 4eda3c991bb..bd2c85291fb 100644
---- a/bfd/elf-eh-frame.c
-+++ b/bfd/elf-eh-frame.c
-@@ -1448,12 +1448,10 @@ _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *h,
- /* The same for all local symbols defined in .eh_frame.  Returns true
-    if any symbol was changed.  */
- 
--static int
-+static void
- adjust_eh_frame_local_symbols (const asection *sec,
- 			       struct elf_reloc_cookie *cookie)
- {
--  int adjusted = 0;
--
-   if (cookie->locsymcount > 1)
-     {
-       unsigned int shndx = elf_section_data (sec)->this_idx;
-@@ -1467,13 +1465,9 @@ adjust_eh_frame_local_symbols (const asection *sec,
- 	    bfd_signed_vma delta = offset_adjust (sym->st_value, sec);
- 
- 	    if (delta != 0)
--	      {
--		adjusted = 1;
--		sym->st_value += delta;
--	      }
-+	      sym->st_value += delta;
- 	  }
-     }
--  return adjusted;
- }
- 
- /* This function is called for each input file before the .eh_frame
-@@ -1611,11 +1605,8 @@ _bfd_elf_discard_section_eh_frame
-   if (sec->size != sec->rawsize)
-     changed = 1;
- 
--  if (changed && adjust_eh_frame_local_symbols (sec, cookie))
--    {
--      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
--      symtab_hdr->contents = (unsigned char *) cookie->locsyms;
--    }
-+  if (changed)
-+    adjust_eh_frame_local_symbols (sec, cookie);
-   return changed;
- }
- 
-diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
-index ca9a92e1221..4da86774ee2 100644
---- a/bfd/elf-m10200.c
-+++ b/bfd/elf-m10200.c
-@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
-index b381bb9037c..373290cbe4a 100644
---- a/bfd/elf-m10300.c
-+++ b/bfd/elf-m10300.c
-@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
- 		  if (isymbuf == NULL)
- 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						    symtab_hdr->sh_info, 0,
--						    NULL, NULL, NULL);
-+						    NULL, NULL);
- 		  if (isymbuf)
- 		    {
- 		      isym = isymbuf + r_symndx;
-@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf.c b/bfd/elf.c
-index bde7414ee21..edce3d3b95f 100644
---- a/bfd/elf.c
-+++ b/bfd/elf.c
-@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
- }
- 
- /* Read and convert symbols to internal format.
--   SYMCOUNT specifies the number of symbols to read, starting from
--   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
-+   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
-+   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
-    are non-NULL, they are used to store the internal symbols, external
--   symbols, and symbol section index extensions, respectively.
--   Returns a pointer to the internal symbol buffer (malloced if necessary)
--   or NULL if there were no symbols or some kind of problem.  */
-+   symbols, and symbol section index extensions, respectively.  Returns
-+   a pointer to the internal symbol buffer (malloced if necessary) or
-+   NULL if there were no symbols or some kind of problem.  */
- 
- Elf_Internal_Sym *
- bfd_elf_get_elf_syms (bfd *ibfd,
- 		      Elf_Internal_Shdr *symtab_hdr,
--		      size_t symcount,
--		      size_t symoffset,
-+		      size_t partial_symcount,
-+		      size_t partial_symoffset,
- 		      Elf_Internal_Sym *intsym_buf,
--		      void *extsym_buf,
--		      Elf_External_Sym_Shndx *extshndx_buf)
-+		      void *partial_extsym_buf)
- {
-   Elf_Internal_Shdr *shndx_hdr;
-   void *alloc_ext;
-@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
-   const struct elf_backend_data *bed;
-   size_t extsym_size;
-   size_t amt;
--  file_ptr pos;
-+  file_ptr pos = 0;
-+  size_t symcount = partial_symcount;
-+  size_t symoffset = partial_symoffset;
-+  void *extsym_buf = NULL;
-+  Elf_External_Sym_Shndx *extshndx_buf = NULL;
-+  bool cache_symtab = false;
- 
-   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
-     abort ();
-@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
-       return elf_tdata (ibfd)->dt_symtab + symoffset;
-     }
- 
-+  if (elf_tdata (ibfd)->symtab != NULL)
-+    {
-+      /* NB: Should extsym_buf be cached?  */
-+      if (partial_extsym_buf != NULL)
-+	abort ();
-+
-+      if (intsym_buf != NULL)
-+	{
-+	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
-+		  symcount * sizeof (*intsym_buf));
-+	  return intsym_buf;
-+	}
-+      else
-+	return elf_tdata (ibfd)->symtab + symoffset;
-+    }
-+
-   /* Normal syms might have section extension entries.  */
-   shndx_hdr = NULL;
-   if (elf_symtab_shndx_list (ibfd) != NULL)
-@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	}
-     }
- 
-+  if (elf_elfheader (ibfd)->e_type == ET_REL
-+      && symtab_hdr->sh_entsize != 0)
-+    {
-+      symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
-+      symoffset = 0;
-+      cache_symtab = true;
-+    }
-+
-   /* Read the symbols.  */
-   alloc_ext = NULL;
-   alloc_extshndx = NULL;
-   alloc_intsym = NULL;
-   bed = get_elf_backend_data (ibfd);
-   extsym_size = bed->s->sizeof_sym;
--  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
-+  size_t extsym_buf_size;
-+  if (_bfd_mul_overflow (symcount, extsym_size, &extsym_buf_size))
-     {
-       bfd_set_error (bfd_error_file_too_big);
-       return NULL;
-     }
--  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
--  size_t alloc_ext_size = amt;
-+  if (cache_symtab)
-+    pos = symtab_hdr->sh_offset;
-+  else
-+    pos = symtab_hdr->sh_offset + symoffset * extsym_size;
-+  size_t alloc_ext_size = extsym_buf_size;
-   if (bfd_seek (ibfd, pos, SEEK_SET) != 0
-       || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
- 				    &alloc_ext, ibfd, false))
-@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	}
-     }
- 
--  if (intsym_buf == NULL)
-+  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
-     {
--      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
--	{
--	  bfd_set_error (bfd_error_file_too_big);
--	  goto out1;
--	}
--      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
--      intsym_buf = alloc_intsym;
--      if (intsym_buf == NULL)
--	goto out1;
-+      bfd_set_error (bfd_error_file_too_big);
-+      goto out1;
-+    }
-+  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
-+  if (alloc_intsym == NULL)
-+    {
-+      intsym_buf = NULL;
-+      goto out1;
-     }
- 
-+  if (intsym_buf == NULL)
-+    intsym_buf = alloc_intsym;
-+
-   /* Convert the symbols to internal form.  */
--  isymend = intsym_buf + symcount;
--  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
-+  isymend = alloc_intsym + symcount;
-+  for (esym = (const bfd_byte *) extsym_buf, isym = alloc_intsym,
- 	   shndx = extshndx_buf;
-        isym < isymend;
-        esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
-@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	{	
- 	  /* xgettext:c-format */
- 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
--			      ibfd, (unsigned long) (isym - intsym_buf), bind);
-+			      ibfd,
-+			      (unsigned long) (isym - alloc_intsym),
-+			      bind);
- 	  free (alloc_intsym);
- 	  intsym_buf = NULL;
- 	  goto out1;
-@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
- 	{
- 	  /* xgettext:c-format */
- 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
--			      ibfd, (unsigned long) (isym - intsym_buf), t);
-+			      ibfd,
-+			      (unsigned long) (isym - alloc_intsym),
-+			      t);
- 	  free (alloc_intsym);
- 	  intsym_buf = NULL;
- 	  goto out1;
- 	}
-     }
- 
-+  if (intsym_buf != NULL && partial_extsym_buf != NULL)
-+    {
-+      if (partial_symcount != symcount)
-+	abort ();
-+      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
-+    }
-+
-  out1:
-   _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
-  out2:
-   _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
- 
--  return intsym_buf;
-+  if (intsym_buf == NULL)
-+    return intsym_buf;
-+
-+  if (!cache_symtab)
-+    return intsym_buf;
-+
-+  elf_tdata (ibfd)->symtab = alloc_intsym;
-+  if (intsym_buf != alloc_intsym)
-+    {
-+      memcpy (intsym_buf, alloc_intsym + partial_symoffset,
-+	      partial_symcount * sizeof (*intsym_buf));
-+      return intsym_buf;
-+    }
-+  else
-+    return alloc_intsym + partial_symoffset;
- }
- 
- /* Look up a symbol name.  */
-@@ -659,8 +718,6 @@ static const char *
- group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
- {
-   Elf_Internal_Shdr *hdr;
--  unsigned char esym[sizeof (Elf64_External_Sym)];
--  Elf_External_Sym_Shndx eshndx;
-   Elf_Internal_Sym isym;
- 
-   /* First we need to ensure the symbol table is available.  Make sure
-@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
-   /* Go read the symbol.  */
-   hdr = &elf_tdata (abfd)->symtab_hdr;
-   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
--			    &isym, esym, &eshndx) == NULL)
-+			    &isym, NULL) == NULL)
-     return NULL;
- 
-   return bfd_elf_sym_name_raw (abfd, hdr, &isym);
-@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
-   if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
-     {
-       Elf_Internal_Shdr *symtab_hdr;
--      unsigned char esym[sizeof (Elf64_External_Sym)];
--      Elf_External_Sym_Shndx eshndx;
- 
-       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
--				&cache->sym[ent], esym, &eshndx) == NULL)
-+				&cache->sym[ent], NULL) == NULL)
- 	return NULL;
- 
-       if (cache->abfd != abfd)
-@@ -10239,8 +10294,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
- 	      free (sec_info->cies);
- 	    }
- 	}
--      free (tdata->symtab_hdr.contents);
--      tdata->symtab_hdr.contents = NULL;
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-     }
- 
-   return _bfd_generic_bfd_free_cached_info (abfd);
-diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
-index ebfe4dcc26a..ed1dd56a59f 100644
---- a/bfd/elf32-arc.c
-+++ b/bfd/elf32-arc.c
-@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
-           if (isymbuf == NULL)
-             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-                                             symtab_hdr->sh_info, 0,
--                                            NULL, NULL, NULL);
-+					    NULL, NULL);
-           if (isymbuf == NULL)
-             goto error_return;
-         }
-diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
-index ae3dc246be0..627c03eb507 100644
---- a/bfd/elf32-arm.c
-+++ b/bfd/elf32-arm.c
-@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
-   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (local_syms == NULL)
-     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
--				       symtab_hdr->sh_info, 0, NULL, NULL,
-+				       symtab_hdr->sh_info, 0, NULL,
- 				       NULL);
-   if (symtab_hdr->sh_info && local_syms == NULL)
-     return false;
-@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
--				  NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
-index 6653e4d72f6..28e41914bd0 100644
---- a/bfd/elf32-avr.c
-+++ b/bfd/elf32-avr.c
-@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
- 					(abfd,
- 					 symtab_hdr,
- 					 symtab_hdr->sh_info, 0,
--					 NULL, NULL, NULL);
-+					 NULL, NULL);
- 				    if (isymbuf == NULL)
- 				      break;
- 				  }
-@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
-index 7ed1285f4c2..8b74a9f3039 100644
---- a/bfd/elf32-bfin.c
-+++ b/bfd/elf32-bfin.c
-@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
-index 31d1ba41c17..3fc4b4adfa1 100644
---- a/bfd/elf32-cr16.c
-+++ b/bfd/elf32-cr16.c
-@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
-index d2bc1f7ba72..03c20aab6cb 100644
---- a/bfd/elf32-crx.c
-+++ b/bfd/elf32-crx.c
-@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
-index 40781a0e1bb..cc93602f5b0 100644
---- a/bfd/elf32-csky.c
-+++ b/bfd/elf32-csky.c
-@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
- 			    bfd_elf_get_elf_syms (input_bfd,
- 						  symtab_hdr,
- 						  symtab_hdr->sh_info,
--						  0, NULL, NULL, NULL);
-+						  0, NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
-index ea60ce4dc72..bace4943dea 100644
---- a/bfd/elf32-epiphany.c
-+++ b/bfd/elf32-epiphany.c
-@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
-index 6ca175533da..ee9294def64 100644
---- a/bfd/elf32-ft32.c
-+++ b/bfd/elf32-ft32.c
-@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
- 		if (isymbuf == NULL)
- 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		if (isymbuf == NULL)
- 		  return false;
- 	      }
-@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		return false;
- 	    }
-@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-       symtab_hdr->contents = (unsigned char *) isymbuf;
-diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
-index e183577fca4..4bd20f9c433 100644
---- a/bfd/elf32-h8300.c
-+++ b/bfd/elf32-h8300.c
-@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
-index 2f463e12829..085b10b8ea9 100644
---- a/bfd/elf32-hppa.c
-+++ b/bfd/elf32-hppa.c
-@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
-index 5c28a06f318..71de071e1ec 100644
---- a/bfd/elf32-ip2k.c
-+++ b/bfd/elf32-ip2k.c
-@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
-       if (isymbuf == NULL)
- 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					symtab_hdr->sh_info, 0,
--					NULL, NULL, NULL);
-+					NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
-     }
-diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
-index 8f6881bcb0b..bf24f487c44 100644
---- a/bfd/elf32-m32c.c
-+++ b/bfd/elf32-m32c.c
-@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
-   if (free_internal)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
-     }
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+				      symtab_hdr->sh_info, 0, NULL,
-+				      NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
-index f70716d66a2..b4e0a3220ac 100644
---- a/bfd/elf32-m68hc11.c
-+++ b/bfd/elf32-m68hc11.c
-@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
-index 7e8e0383717..9c1bac23549 100644
---- a/bfd/elf32-m68hc1x.c
-+++ b/bfd/elf32-m68hc1x.c
-@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
-index 44ef102ea60..728da0754ab 100644
---- a/bfd/elf32-m68k.c
-+++ b/bfd/elf32-m68k.c
-@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
-index 916f3e15c72..f754af6e3be 100644
---- a/bfd/elf32-metag.c
-+++ b/bfd/elf32-metag.c
-@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  /* Cache them for elf_link_input_bfd.  */
- 	  symtab_hdr->contents = (unsigned char *) local_syms;
- 	}
-diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
-index db7ed465779..3a526391676 100644
---- a/bfd/elf32-microblaze.c
-+++ b/bfd/elf32-microblaze.c
-@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
-   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
-   if (isymbuf == NULL)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
--				    0, NULL, NULL, NULL);
-+				    0, NULL, NULL);
-   BFD_ASSERT (isymbuf != NULL);
- 
-   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
-diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
-index 3b356bfe4e2..5250f13a8b9 100644
---- a/bfd/elf32-msp430.c
-+++ b/bfd/elf32-msp430.c
-@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
- 	    if (isymbuf == NULL)
- 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      symtab_hdr->sh_info, 0,
--					      NULL, NULL, NULL);
-+					      NULL, NULL);
- 	    if (isymbuf == NULL)
- 	      goto error_return;
- 	  }
-diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
-index e22b58c4ea8..b15626349a8 100644
---- a/bfd/elf32-nds32.c
-+++ b/bfd/elf32-nds32.c
-@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
-   if (isym == NULL)
-     {
-       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
--				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+				   symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) isym;
-     }
- 
-@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
- 	{
- 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					     symtab_hdr->sh_info, 0,
--					     NULL, NULL, NULL);
-+					     NULL, NULL);
- 	  if (*isymbuf_p == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
-index a3adcf8430e..e77e77fd687 100644
---- a/bfd/elf32-ppc.c
-+++ b/bfd/elf32-ppc.c
-@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
-index 45a86be3ccf..e0d9eb507e2 100644
---- a/bfd/elf32-pru.c
-+++ b/bfd/elf32-pru.c
-@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
- 	       if (isymbuf == NULL)
- 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						 symtab_hdr->sh_info, 0,
--						 NULL, NULL, NULL);
-+						 NULL, NULL);
- 	       if (isymbuf == NULL)
- 		 return false;
- 	     }
-@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
-index e2ea6b1d15f..3608008c977 100644
---- a/bfd/elf32-rl78.c
-+++ b/bfd/elf32-rl78.c
-@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
-index d8a2236a233..e18eab7bbda 100644
---- a/bfd/elf32-rx.c
-+++ b/bfd/elf32-rx.c
-@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
-     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
-   else
-     {
--      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
-+      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
-       symtab_hdr->contents = (bfd_byte *) intsyms;
-     }
- 
-@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
-   if (!internal_syms)
-     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 				    symtab_hdr->sh_info, 0,
--				    internal_syms, external_syms, NULL);
-+				    internal_syms, external_syms);
-   else
-     isymbuf = internal_syms;
-   isymend = isymbuf + locsymcount;
-diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
-index e078e41b675..022799f389b 100644
---- a/bfd/elf32-sh.c
-+++ b/bfd/elf32-sh.c
-@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
-index de051e48185..eb1ce1c9a12 100644
---- a/bfd/elf32-spu.c
-+++ b/bfd/elf32-spu.c
-@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
-       free (symtab_hdr->contents);
-       symtab_hdr->contents = NULL;
-       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
--				   NULL, NULL, NULL);
-+				   NULL, NULL);
-       symtab_hdr->contents = (void *) syms;
-       if (syms == NULL)
- 	return false;
-diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
-index 27744814691..4d96cf9fbce 100644
---- a/bfd/elf32-v850.c
-+++ b/bfd/elf32-v850.c
-@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
-index 5cee2f389eb..ae043319206 100644
---- a/bfd/elf32-xstormy16.c
-+++ b/bfd/elf32-xstormy16.c
-@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
-index b21676df36a..c554740f357 100644
---- a/bfd/elf32-xtensa.c
-+++ b/bfd/elf32-xtensa.c
-@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
-   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-   if (isymbuf == NULL && locsymcount != 0)
-     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				    NULL, NULL, NULL);
-+				    NULL, NULL);
- 
-   /* Save the symbols for this input file so they won't be read again.  */
-   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
-diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
-index b13c99e4958..2b9eede314d 100644
---- a/bfd/elf64-alpha.c
-+++ b/bfd/elf64-alpha.c
-@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == NULL)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
-index 05bb7f125b7..8cd2d918d8b 100644
---- a/bfd/elf64-hppa.c
-+++ b/bfd/elf64-hppa.c
-@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
- 	  if (local_syms == NULL)
- 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					       symtab_hdr->sh_info, 0,
--					       NULL, NULL, NULL);
-+					       NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
-index 822b263ae2c..f6d00fc1826 100644
---- a/bfd/elf64-ia64-vms.c
-+++ b/bfd/elf64-ia64-vms.c
-@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   if (extsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
- 
-diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
-index bb8350718a2..642b2cdb9bb 100644
---- a/bfd/elf64-mmix.c
-+++ b/bfd/elf64-mmix.c
-@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
-index fdda9e0bbb3..ee15d6f0639 100644
---- a/bfd/elf64-ppc.c
-+++ b/bfd/elf64-ppc.c
-@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
- 			  size_t symcnt = symtab_hdr->sh_info;
- 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						      symcnt, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (sym == NULL)
- 			    break;
- 			  symtab_hdr->contents = (bfd_byte *) sym;
-@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
- 		    {
- 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
- 						  1, symndx,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (sym == NULL)
- 			break;
- 		    }
-@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
- 	  if (locsyms == NULL)
- 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
- 					    symtab_hdr->sh_info,
--					    0, NULL, NULL, NULL);
-+					    0, NULL, NULL);
- 	  if (locsyms == NULL)
- 	    return false;
- 	  *locsymsp = locsyms;
-@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
-       if (local_syms == NULL && locsymcount != 0)
- 	{
- 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
--					     0, NULL, NULL, NULL);
-+					     0, NULL, NULL);
- 	  if (local_syms == NULL)
- 	    return false;
- 	}
-diff --git a/bfd/elfcode.h b/bfd/elfcode.h
-index 5224a1abee6..8777a08a77a 100644
---- a/bfd/elfcode.h
-+++ b/bfd/elfcode.h
-@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
-       size_t i;
- 
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return -1;
- 
-@@ -1523,16 +1523,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
-     }
- 
-   free (xverbuf);
--  if (hdr->contents != (unsigned char *) isymbuf
--      && !elf_use_dt_symtab_p (abfd))
--    free (isymbuf);
-   return symcount;
- 
-  error_return:
-   free (xverbuf);
--  if (hdr->contents != (unsigned char *) isymbuf
--      && !elf_use_dt_symtab_p (abfd))
--    free (isymbuf);
-   return -1;
- }
- 
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 3f3ea2cce51..da4da5c453a 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
-   struct elf_strtab_hash *dynstr;
-   size_t dynstr_index;
-   char *name;
--  Elf_External_Sym_Shndx eshndx;
--  char esym[sizeof (Elf64_External_Sym)];
- 
-   if (! is_elf_hash_table (info->hash))
-     return 0;
-@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
- 
-   /* Go find the symbol, so that we can find it's name.  */
-   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
--			     1, input_indx, &entry->isym, esym, &eshndx))
-+			     1, input_indx, &entry->isym, NULL))
-     {
-       bfd_release (input_bfd, entry);
-       return 0;
-@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
- 
-   /* Read in the symbol table.  */
-   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				  NULL, NULL, NULL);
-+				  NULL, NULL);
-   if (isymbuf == NULL)
-     return false;
- 
-@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
- 	}
-     }
- 
--  free (isymbuf);
-+  if (!elf_tdata (abfd)->keep_symtab)
-+    {
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-+    }
- 
-   return result;
- }
-@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   if (extsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	goto error_return;
- 
-@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
- 
-   free (extversym);
-   extversym = NULL;
--  free (isymbuf);
--  isymbuf = NULL;
-+
-+  /* NB: Since st_shndx of symbol from discarded section is changed to
-+     SHN_UNDEF, free the cached symbol table.  */
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
- 
-   if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
-     {
-@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-   free (nondeflt_vers);
-   free (extversym);
-  error_free_sym:
--  free (isymbuf);
-+  free (elf_tdata (abfd)->symtab);
-+  elf_tdata (abfd)->symtab = NULL;
-  error_return:
-   return false;
- }
-@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-   if (ssymbuf1 == NULL)
-     {
-       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
--				       NULL, NULL, NULL);
-+				       NULL, NULL);
-       if (isymbuf1 == NULL)
- 	goto done;
- 
-@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-   if (ssymbuf1 == NULL || ssymbuf2 == NULL)
-     {
-       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
--				       NULL, NULL, NULL);
-+				       NULL, NULL);
-       if (isymbuf2 == NULL)
- 	goto done;
- 
-@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
-  done:
-   free (symtable1);
-   free (symtable2);
--  free (isymbuf1);
--  free (isymbuf2);
- 
-   return result;
- }
-@@ -9056,14 +9060,6 @@ struct elf_final_link_info
-   void *external_relocs;
-   /* Buffer large enough to hold internal relocs of any section.  */
-   Elf_Internal_Rela *internal_relocs;
--  /* Buffer large enough to hold external local symbols of any input
--     BFD.  */
--  bfd_byte *external_syms;
--  /* And a buffer for symbol section indices.  */
--  Elf_External_Sym_Shndx *locsym_shndx;
--  /* Buffer large enough to hold internal local symbols of any input
--     BFD.  */
--  Elf_Internal_Sym *internal_syms;
-   /* Array large enough to hold a symbol index for each local symbol
-      of any input BFD.  */
-   long *indices;
-@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
- 	continue;
- 
-       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
--				      NULL, NULL, NULL);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return false;
- 
-@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
-   Elf_Internal_Shdr *symtab_hdr;
-   size_t locsymcount;
-   size_t extsymoff;
--  Elf_Internal_Sym *isymbuf;
-+  Elf_Internal_Sym *isymbuf = NULL;
-   Elf_Internal_Sym *isym;
-   Elf_Internal_Sym *isymend;
-   long *pindex;
-@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
- 	     ? -1 : ~elf_gnu_osabi_retain));
- 
-   /* Read the local symbols.  */
--  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
--  if (isymbuf == NULL && locsymcount != 0)
-+  if (locsymcount != 0)
-     {
-       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
--				      flinfo->internal_syms,
--				      flinfo->external_syms,
--				      flinfo->locsym_shndx);
-+				      NULL, NULL);
-       if (isymbuf == NULL)
- 	return false;
-     }
-@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
-   free (flinfo->contents);
-   free (flinfo->external_relocs);
-   free (flinfo->internal_relocs);
--  free (flinfo->external_syms);
--  free (flinfo->locsym_shndx);
--  free (flinfo->internal_syms);
-   free (flinfo->indices);
-   free (flinfo->sections);
-   if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
-@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
-   bfd_size_type max_external_reloc_size;
-   bfd_size_type max_internal_reloc_count;
-   bfd_size_type max_sym_count;
--  bfd_size_type max_sym_shndx_count;
-   Elf_Internal_Sym elfsym;
-   unsigned int i;
-   Elf_Internal_Shdr *symtab_hdr;
-@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
-     }
-   max_internal_reloc_count = 0;
-   max_sym_count = 0;
--  max_sym_shndx_count = 0;
-   merged = false;
-   for (o = abfd->sections; o != NULL; o = o->next)
-     {
-@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 		  if (sym_count > max_sym_count)
- 		    max_sym_count = sym_count;
- 
--		  if (sym_count > max_sym_shndx_count
--		      && elf_symtab_shndx_list (sec->owner) != NULL)
--		    max_sym_shndx_count = sym_count;
--
- 		  esdi = elf_section_data (sec);
- 
- 		  if (esdi->this_hdr.sh_type == SHT_REL
-@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 
-   if (max_sym_count != 0)
-     {
--      amt = max_sym_count * bed->s->sizeof_sym;
--      flinfo.external_syms = (bfd_byte *) bfd_malloc (amt);
--      if (flinfo.external_syms == NULL)
--	goto error_return;
--
--      amt = max_sym_count * sizeof (Elf_Internal_Sym);
--      flinfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
--      if (flinfo.internal_syms == NULL)
--	goto error_return;
--
-       amt = max_sym_count * sizeof (long);
-       flinfo.indices = (long int *) bfd_malloc (amt);
-       if (flinfo.indices == NULL)
-@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 	goto error_return;
-     }
- 
--  if (max_sym_shndx_count != 0)
--    {
--      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
--      flinfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
--      if (flinfo.locsym_shndx == NULL)
--	goto error_return;
--    }
--
-   if (htab->tls_sec)
-     {
-       bfd_vma base, end = 0;  /* Both bytes.  */
-@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 
- static bool
- init_reloc_cookie (struct elf_reloc_cookie *cookie,
--		   struct bfd_link_info *info, bfd *abfd,
--		   bool keep_memory)
-+		   struct bfd_link_info *info, bfd *abfd)
- {
-   Elf_Internal_Shdr *symtab_hdr;
-   const struct elf_backend_data *bed;
-@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
-   else
-     cookie->r_sym_shift = 32;
- 
--  cookie->locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
--  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
-+  if (cookie->locsymcount != 0)
-     {
-       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					      cookie->locsymcount, 0,
--					      NULL, NULL, NULL);
-+					      NULL, NULL);
-       if (cookie->locsyms == NULL)
- 	{
- 	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
- 	  return false;
- 	}
--      if (keep_memory || _bfd_elf_link_keep_memory (info))
--	{
--	  symtab_hdr->contents = (bfd_byte *) cookie->locsyms;
--	  info->cache_size += (cookie->locsymcount
--			       * sizeof (Elf_Internal_Sym));
--	}
-     }
-   return true;
- }
- 
--/* Free the memory allocated by init_reloc_cookie, if appropriate.  */
--
--static void
--fini_reloc_cookie (struct elf_reloc_cookie *cookie, bfd *abfd)
--{
--  Elf_Internal_Shdr *symtab_hdr;
--
--  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
--  if (symtab_hdr->contents != (unsigned char *) cookie->locsyms)
--    free (cookie->locsyms);
--}
--
- /* Initialize the relocation information in COOKIE for input section SEC
-    of input bfd ABFD.  */
- 
-@@ -13996,28 +13942,9 @@ init_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
- 			       struct bfd_link_info *info,
- 			       asection *sec, bool keep_memory)
- {
--  if (!init_reloc_cookie (cookie, info, sec->owner, keep_memory))
--    goto error1;
--  if (!init_reloc_cookie_rels (cookie, info, sec->owner, sec,
--			       keep_memory))
--    goto error2;
--  return true;
--
-- error2:
--  fini_reloc_cookie (cookie, sec->owner);
-- error1:
--  return false;
--}
--
--/* Free the memory allocated by init_reloc_cookie_for_section,
--   if appropriate.  */
--
--static void
--fini_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
--			       asection *sec)
--{
--  fini_reloc_cookie_rels (cookie, sec);
--  fini_reloc_cookie (cookie, sec->owner);
-+  return (init_reloc_cookie (cookie, info, sec->owner)
-+	  && init_reloc_cookie_rels (cookie, info, sec->owner, sec,
-+				     keep_memory));
- }
- \f
- /* Garbage collect unused sections.  */
-@@ -14209,7 +14136,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
- 		ret = false;
- 		break;
- 	      }
--	  fini_reloc_cookie_for_section (&cookie, sec);
-+	  fini_reloc_cookie_rels (&cookie, sec);
- 	}
-     }
- 
-@@ -14231,7 +14158,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
- 	  if (!_bfd_elf_gc_mark_fdes (info, sec, eh_frame,
- 				      gc_mark_hook, &cookie))
- 	    ret = false;
--	  fini_reloc_cookie_for_section (&cookie, eh_frame);
-+	  fini_reloc_cookie_rels (&cookie, eh_frame);
- 	}
-     }
- 
-@@ -14665,7 +14592,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
-       if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
- 	continue;
- 
--      if (!init_reloc_cookie (&cookie, info, ibfd, false))
-+      if (!init_reloc_cookie (&cookie, info, ibfd))
- 	return false;
- 
-       for (sec = ibfd->sections; sec; sec = sec->next)
-@@ -14724,7 +14651,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
- 	  if (elf_section_data (sec)->sec_info
- 	      && (sec->flags & SEC_LINKER_CREATED) == 0)
- 	    elf_eh_frame_section (sub) = sec;
--	  fini_reloc_cookie_for_section (&cookie, sec);
-+	  fini_reloc_cookie_rels (&cookie, sec);
- 	  sec = bfd_get_next_section_by_name (NULL, sec);
- 	}
-     }
-@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
- 	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
- 	      return false;
- 	  }
-+
-+      if (!elf_tdata (sub)->keep_symtab
-+	  && !_bfd_elf_link_keep_memory (info))
-+	{
-+	  free (elf_tdata (sub)->symtab);
-+	  elf_tdata (sub)->symtab = NULL;
-+	}
-     }
- 
-   /* Allow the backend to mark additional target specific sections.  */
-@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 					  &cookie))
- 	    changed = 1;
- 
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
-     }
- 
-@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 		changed = 1;
- 	    }
- 
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
- 
-       eh_alignment = ((1 << o->alignment_power)
-@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 		    changed = 1;
- 		}
- 	    }
--	  fini_reloc_cookie_for_section (&cookie, i);
-+	  fini_reloc_cookie_rels (&cookie, i);
- 	}
-       /* Update the reference to the output .sframe section.  Used to
- 	 determine later if PT_GNU_SFRAME segment is to be generated.  */
-@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
- 
-       if (bed->elf_backend_discard_info != NULL)
- 	{
--	  if (!init_reloc_cookie (&cookie, info, abfd, false))
-+	  if (!init_reloc_cookie (&cookie, info, abfd))
- 	    return -1;
- 
- 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
- 	    changed = 1;
--
--	  fini_reloc_cookie (&cookie, abfd);
- 	}
-     }
- 
-diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
-index 3c3c2899674..553ba27b604 100644
---- a/bfd/elfnn-aarch64.c
-+++ b/bfd/elfnn-aarch64.c
-@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
- 			local_syms
- 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						  symtab_hdr->sh_info, 0,
--						  NULL, NULL, NULL);
-+						  NULL, NULL);
- 		      if (local_syms == NULL)
- 			goto error_ret_free_internal;
- 		    }
-@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
-   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
-      should contain the number of local symbols, which should come before any
-      global symbols.  Mapping symbols are always local.  */
--  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
-+  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
- 
-   /* No internal symbols read?  Skip this BFD.  */
-   if (isymbuf == NULL)
-diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
-index 528b1dcdcc3..48fce2380cd 100644
---- a/bfd/elfnn-ia64.c
-+++ b/bfd/elfnn-ia64.c
-@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
- 	      if (isymbuf == NULL)
- 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						symtab_hdr->sh_info, 0,
--						NULL, NULL, NULL);
-+						NULL, NULL);
- 	      if (isymbuf == 0)
- 		goto error_return;
- 	    }
-diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
-index 3b44db57421..8e75b400570 100644
---- a/bfd/elfnn-kvx.c
-+++ b/bfd/elfnn-kvx.c
-@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
- 			    local_syms
- 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
- 						      symtab_hdr->sh_info, 0,
--						      NULL, NULL, NULL);
-+						      NULL, NULL);
- 			  if (local_syms == NULL)
- 			    goto error_ret_free_internal;
- 			}
-diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
-index 53cdb783859..10a4f99add7 100644
---- a/bfd/elfnn-loongarch.c
-+++ b/bfd/elfnn-loongarch.c
-@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
-       && !(symtab_hdr->contents =
- 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						   symtab_hdr->sh_info,
--						   0, NULL, NULL, NULL)))
-+						   0, NULL, NULL)))
-     return true;
- 
-   /* Estimate the maximum alignment for all output sections once time
-diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
-index 09cf7076733..d1ab410a94f 100644
---- a/bfd/elfnn-riscv.c
-+++ b/bfd/elfnn-riscv.c
-@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
- 	  && !(symtab_hdr->contents =
- 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 						       symtab_hdr->sh_info,
--						       0, NULL, NULL, NULL)))
-+						       0, NULL, NULL)))
- 	goto fail;
- 
-       /* Get the value of the symbol referred to by the reloc.  */
-diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
-index 00ef0663728..44c58362dda 100644
---- a/bfd/elfxx-mips.c
-+++ b/bfd/elfxx-mips.c
-@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
- 	  if (isymbuf == NULL)
- 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
- 					    symtab_hdr->sh_info, 0,
--					    NULL, NULL, NULL);
-+					    NULL, NULL);
- 	  if (isymbuf == NULL)
- 	    goto error_return;
- 	}
-diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index 140e86888a6..53083e0b54c 100644
---- a/bfd/elfxx-x86.c
-+++ b/bfd/elfxx-x86.c
-@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
- 	  /* Read this BFD's local symbols.  */
- 	  if (isymbuf == NULL)
- 	    {
--	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-+	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-+					      symtab_hdr->sh_info,
-+					      0, NULL, NULL);
- 	      if (isymbuf == NULL)
--		{
--		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
--						  symtab_hdr->sh_info,
--						  0, NULL, NULL, NULL);
--		  if (isymbuf == NULL)
--		    goto error_return;
--		}
-+		goto error_return;
- 	    }
- 
- 	  isym = isymbuf + r_symndx;
-@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
-   return_status = true;
- 
- error_return:
--  if ((unsigned char *) isymbuf != symtab_hdr->contents)
--    {
--      /* Cache the symbol buffer if it must be kept.  */
--      if (keep_symbuf)
--	symtab_hdr->contents = (unsigned char *) isymbuf;
--      else
--	free (isymbuf);
--    }
-+  /* If the symbol table has been updated, it must be kept since it will
-+     be used later.  */
-+  if (keep_symbuf)
-+    elf_tdata (abfd)->keep_symtab = 1;
-   if (elf_section_data (input_section)->relocs != internal_relocs)
-     free (internal_relocs);
-   return return_status;
-diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
-index 7241de70709..205347c4e22 100644
---- a/libctf/ctf-open-bfd.c
-+++ b/libctf/ctf-open-bfd.c
-@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
- 	}
- 
-       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
--				      NULL, symtab, NULL);
--      free (isymbuf);
-+				      NULL, symtab);
-+      free (elf_tdata (abfd)->symtab);
-+      elf_tdata (abfd)->symtab = NULL;
-       if (isymbuf == NULL)
- 	{
- 	  bfderrstr = N_("cannot read symbol table");
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-10-10  4:57 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-10-10  4:57 UTC (permalink / raw
  To: gentoo-commits

commit:     a3c33571d7f0c64df3b509556b9a11388451070c
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 10 04:57:00 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 10 04:57:00 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=a3c33571

9999: add H.J.'s patch for caching

Bug: https://sourceware.org/PR33530
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-internal-symbol-table-in-relocatable-BFD.patch | 1775 ++++++++++++++++++++
 1 file changed, 1775 insertions(+)

diff --git a/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
new file mode 100644
index 0000000..dbf42d5
--- /dev/null
+++ b/9999/0005-elf-Cache-internal-symbol-table-in-relocatable-BFD.patch
@@ -0,0 +1,1775 @@
+From a724f5c582f8df93eee54d43cf7766bc47d30f44 Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Thu, 9 Oct 2025 13:16:19 +0800
+Subject: [PATCH] elf: Cache internal symbol table in relocatable BFD
+
+Don't cache internal symbol table in symtab_hdr->contents.
+
+bfd/
+
+	PR ld/33530
+	* elf-bfd.h (elf_obj_tdata): Add symtab.
+	* elf-eh-frame.c (adjust_eh_frame_local_symbols): Changed to
+	return void.
+	(_bfd_elf_discard_section_eh_frame): Updated.  Don't cache
+	internal symbol table in symtab_hdr.
+	* elf.c (bfd_elf_get_elf_syms): Cache internal symbol table in
+	BFD.
+	(_bfd_elf_free_cached_info): Free internal symbol table in BFD.
+	* elfcode.h (elf_slurp_symbol_table): Don't free internal symbol
+	buffer.
+	* elflink.c (elf_link_is_defined_archive_symbol): Likewise.
+	(elf_link_add_object_symbols): Free cached internal symbol buffer.
+	(elf_link_input_bfd): Don't use symtab_hdr->contents for internal
+	symbol table.
+	(init_reloc_cookie): Remove the keep_memory argument.  Don't
+	cache internal symbol table in symtab_hdr.
+	(fini_reloc_cookie): Removed.
+	(init_reloc_cookie_for_section): Don't call fini_reloc_cookie on
+	error.
+	(_bfd_elf_gc_mark): Replace fini_reloc_cookie_for_section with
+	fini_reloc_cookie_rels.
+	(bfd_elf_gc_sections): Likewise.
+	(bfd_elf_discard_info): Likewise.  Don't call fini_reloc_cookie.
+	(bfd_elf_parse_eh_frame_entries): Updated.
+	* elfxx-x86.c (_bfd_x86_elf_link_relax_section): Don't use
+	use symtab_hdr->contents for internal symbol table.
+
+libctf/
+
+	PR ld/33530
+	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Free internal symbol
+	table in BFD.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-bfd.h          |  11 ++-
+ bfd/elf-eh-frame.c     |  17 ++---
+ bfd/elf-m10200.c       |   4 +-
+ bfd/elf-m10300.c       |  10 +--
+ bfd/elf.c              | 127 ++++++++++++++++++++++++----------
+ bfd/elf32-arc.c        |   2 +-
+ bfd/elf32-arm.c        |   7 +-
+ bfd/elf32-avr.c        |  12 ++--
+ bfd/elf32-bfin.c       |   2 +-
+ bfd/elf32-cr16.c       |   6 +-
+ bfd/elf32-crx.c        |   4 +-
+ bfd/elf32-csky.c       |   2 +-
+ bfd/elf32-epiphany.c   |   2 +-
+ bfd/elf32-ft32.c       |   6 +-
+ bfd/elf32-h8300.c      |   4 +-
+ bfd/elf32-hppa.c       |   2 +-
+ bfd/elf32-ip2k.c       |   2 +-
+ bfd/elf32-m32c.c       |   8 ++-
+ bfd/elf32-m68hc11.c    |   2 +-
+ bfd/elf32-m68hc1x.c    |   2 +-
+ bfd/elf32-m68k.c       |   2 +-
+ bfd/elf32-metag.c      |   2 +-
+ bfd/elf32-microblaze.c |   2 +-
+ bfd/elf32-msp430.c     |   4 +-
+ bfd/elf32-nds32.c      |   4 +-
+ bfd/elf32-ppc.c        |   4 +-
+ bfd/elf32-pru.c        |   4 +-
+ bfd/elf32-rl78.c       |   4 +-
+ bfd/elf32-rx.c         |   4 +-
+ bfd/elf32-sh.c         |   4 +-
+ bfd/elf32-spu.c        |   4 +-
+ bfd/elf32-v850.c       |   2 +-
+ bfd/elf32-xstormy16.c  |   2 +-
+ bfd/elf32-xtensa.c     |   2 +-
+ bfd/elf64-alpha.c      |   2 +-
+ bfd/elf64-hppa.c       |   2 +-
+ bfd/elf64-ia64-vms.c   |   4 +-
+ bfd/elf64-mmix.c       |   2 +-
+ bfd/elf64-ppc.c        |  12 ++--
+ bfd/elfcode.h          |   8 +--
+ bfd/elflink.c          | 152 ++++++++++++-----------------------------
+ bfd/elfnn-aarch64.c    |   4 +-
+ bfd/elfnn-ia64.c       |   2 +-
+ bfd/elfnn-kvx.c        |   2 +-
+ bfd/elfnn-loongarch.c  |   2 +-
+ bfd/elfnn-riscv.c      |   2 +-
+ bfd/elfxx-mips.c       |   2 +-
+ bfd/elfxx-x86.c        |  24 +++----
+ libctf/ctf-open-bfd.c  |   5 +-
+ 49 files changed, 237 insertions(+), 264 deletions(-)
+
+diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
+index 5d19529d972..b7061e55b59 100644
+--- a/bfd/elf-bfd.h
++++ b/bfd/elf-bfd.h
+@@ -2165,6 +2165,11 @@ struct elf_obj_tdata
+   /* Symbol buffer.  */
+   void *symbuf;
+ 
++  /* A pointer to the full internal symbol table of input relocatable
++     SHT_SYMTAB if not NULL.  Don't use symtab_hdr->contents since not
++     all backends use it to only cache local symbols.  */
++  Elf_Internal_Sym *symtab;
++
+   /* List of GNU properties.  Will be updated by setup_gnu_properties
+      after all input GNU properties are merged for output.  */
+   elf_property_list *properties;
+@@ -2207,6 +2212,9 @@ struct elf_obj_tdata
+      symbols.  */
+   unsigned int bad_symtab : 1;
+ 
++  /* Set if the symbol table cache should be kept.  */
++  unsigned int keep_symtab : 1;
++
+   /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
+   unsigned int is_pie : 1;
+ 
+@@ -2297,8 +2305,7 @@ extern unsigned int _bfd_elf_section_from_bfd_section
+ extern char *bfd_elf_string_from_elf_section
+   (bfd *, unsigned, unsigned);
+ extern Elf_Internal_Sym *bfd_elf_get_elf_syms
+-  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *,
+-   Elf_External_Sym_Shndx *);
++  (bfd *, Elf_Internal_Shdr *, size_t, size_t, Elf_Internal_Sym *, void *);
+ extern char * bfd_elf_get_str_section (bfd *, unsigned int);
+ extern const char *bfd_elf_sym_name
+   (bfd *, Elf_Internal_Shdr *, Elf_Internal_Sym *, asection *);
+diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
+index 4eda3c991bb..bd2c85291fb 100644
+--- a/bfd/elf-eh-frame.c
++++ b/bfd/elf-eh-frame.c
+@@ -1448,12 +1448,10 @@ _bfd_elf_adjust_eh_frame_global_symbol (struct elf_link_hash_entry *h,
+ /* The same for all local symbols defined in .eh_frame.  Returns true
+    if any symbol was changed.  */
+ 
+-static int
++static void
+ adjust_eh_frame_local_symbols (const asection *sec,
+ 			       struct elf_reloc_cookie *cookie)
+ {
+-  int adjusted = 0;
+-
+   if (cookie->locsymcount > 1)
+     {
+       unsigned int shndx = elf_section_data (sec)->this_idx;
+@@ -1467,13 +1465,9 @@ adjust_eh_frame_local_symbols (const asection *sec,
+ 	    bfd_signed_vma delta = offset_adjust (sym->st_value, sec);
+ 
+ 	    if (delta != 0)
+-	      {
+-		adjusted = 1;
+-		sym->st_value += delta;
+-	      }
++	      sym->st_value += delta;
+ 	  }
+     }
+-  return adjusted;
+ }
+ 
+ /* This function is called for each input file before the .eh_frame
+@@ -1611,11 +1605,8 @@ _bfd_elf_discard_section_eh_frame
+   if (sec->size != sec->rawsize)
+     changed = 1;
+ 
+-  if (changed && adjust_eh_frame_local_symbols (sec, cookie))
+-    {
+-      Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-      symtab_hdr->contents = (unsigned char *) cookie->locsyms;
+-    }
++  if (changed)
++    adjust_eh_frame_local_symbols (sec, cookie);
+   return changed;
+ }
+ 
+diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c
+index ca9a92e1221..4da86774ee2 100644
+--- a/bfd/elf-m10200.c
++++ b/bfd/elf-m10200.c
+@@ -627,7 +627,7 @@ mn10200_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1321,7 +1321,7 @@ mn10200_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
+index b381bb9037c..373290cbe4a 100644
+--- a/bfd/elf-m10300.c
++++ b/bfd/elf-m10300.c
+@@ -1328,7 +1328,7 @@ mn10300_elf_check_relocs (bfd *abfd,
+ 		  if (isymbuf == NULL)
+ 		    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						    symtab_hdr->sh_info, 0,
+-						    NULL, NULL, NULL);
++						    NULL, NULL);
+ 		  if (isymbuf)
+ 		    {
+ 		      isym = isymbuf + r_symndx;
+@@ -2676,7 +2676,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3019,7 +3019,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+@@ -3347,7 +3347,7 @@ mn10300_elf_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -4463,7 +4463,7 @@ mn10300_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf.c b/bfd/elf.c
+index bde7414ee21..edce3d3b95f 100644
+--- a/bfd/elf.c
++++ b/bfd/elf.c
+@@ -428,21 +428,20 @@ bfd_elf_string_from_elf_section (bfd *abfd,
+ }
+ 
+ /* Read and convert symbols to internal format.
+-   SYMCOUNT specifies the number of symbols to read, starting from
+-   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
++   PARTIAL_SYMCOUNT specifies the number of symbols to read, starting
++   from symbol PARTIAL_SYMOFFSET.  If INTSYM_BUF or PARTIAL_EXTSYM_BUF
+    are non-NULL, they are used to store the internal symbols, external
+-   symbols, and symbol section index extensions, respectively.
+-   Returns a pointer to the internal symbol buffer (malloced if necessary)
+-   or NULL if there were no symbols or some kind of problem.  */
++   symbols, and symbol section index extensions, respectively.  Returns
++   a pointer to the internal symbol buffer (malloced if necessary) or
++   NULL if there were no symbols or some kind of problem.  */
+ 
+ Elf_Internal_Sym *
+ bfd_elf_get_elf_syms (bfd *ibfd,
+ 		      Elf_Internal_Shdr *symtab_hdr,
+-		      size_t symcount,
+-		      size_t symoffset,
++		      size_t partial_symcount,
++		      size_t partial_symoffset,
+ 		      Elf_Internal_Sym *intsym_buf,
+-		      void *extsym_buf,
+-		      Elf_External_Sym_Shndx *extshndx_buf)
++		      void *partial_extsym_buf)
+ {
+   Elf_Internal_Shdr *shndx_hdr;
+   void *alloc_ext;
+@@ -455,7 +454,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+   const struct elf_backend_data *bed;
+   size_t extsym_size;
+   size_t amt;
+-  file_ptr pos;
++  file_ptr pos = 0;
++  size_t symcount = partial_symcount;
++  size_t symoffset = partial_symoffset;
++  void *extsym_buf = NULL;
++  Elf_External_Sym_Shndx *extshndx_buf = NULL;
++  bool cache_symtab = false;
+ 
+   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+     abort ();
+@@ -474,6 +478,22 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+       return elf_tdata (ibfd)->dt_symtab + symoffset;
+     }
+ 
++  if (elf_tdata (ibfd)->symtab != NULL)
++    {
++      /* NB: Should extsym_buf be cached?  */
++      if (partial_extsym_buf != NULL)
++	abort ();
++
++      if (intsym_buf != NULL)
++	{
++	  memcpy (intsym_buf, elf_tdata (ibfd)->symtab + symoffset,
++		  symcount * sizeof (*intsym_buf));
++	  return intsym_buf;
++	}
++      else
++	return elf_tdata (ibfd)->symtab + symoffset;
++    }
++
+   /* Normal syms might have section extension entries.  */
+   shndx_hdr = NULL;
+   if (elf_symtab_shndx_list (ibfd) != NULL)
+@@ -506,19 +526,31 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
++  if (elf_elfheader (ibfd)->e_type == ET_REL
++      && symtab_hdr->sh_entsize != 0)
++    {
++      symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
++      symoffset = 0;
++      cache_symtab = true;
++    }
++
+   /* Read the symbols.  */
+   alloc_ext = NULL;
+   alloc_extshndx = NULL;
+   alloc_intsym = NULL;
+   bed = get_elf_backend_data (ibfd);
+   extsym_size = bed->s->sizeof_sym;
+-  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
++  size_t extsym_buf_size;
++  if (_bfd_mul_overflow (symcount, extsym_size, &extsym_buf_size))
+     {
+       bfd_set_error (bfd_error_file_too_big);
+       return NULL;
+     }
+-  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
+-  size_t alloc_ext_size = amt;
++  if (cache_symtab)
++    pos = symtab_hdr->sh_offset;
++  else
++    pos = symtab_hdr->sh_offset + symoffset * extsym_size;
++  size_t alloc_ext_size = extsym_buf_size;
+   if (bfd_seek (ibfd, pos, SEEK_SET) != 0
+       || !_bfd_mmap_read_temporary (&extsym_buf, &alloc_ext_size,
+ 				    &alloc_ext, ibfd, false))
+@@ -551,22 +583,24 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	}
+     }
+ 
+-  if (intsym_buf == NULL)
++  if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+     {
+-      if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
+-	{
+-	  bfd_set_error (bfd_error_file_too_big);
+-	  goto out1;
+-	}
+-      alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      intsym_buf = alloc_intsym;
+-      if (intsym_buf == NULL)
+-	goto out1;
++      bfd_set_error (bfd_error_file_too_big);
++      goto out1;
++    }
++  alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
++  if (alloc_intsym == NULL)
++    {
++      intsym_buf = NULL;
++      goto out1;
+     }
+ 
++  if (intsym_buf == NULL)
++    intsym_buf = alloc_intsym;
++
+   /* Convert the symbols to internal form.  */
+-  isymend = intsym_buf + symcount;
+-  for (esym = (const bfd_byte *) extsym_buf, isym = intsym_buf,
++  isymend = alloc_intsym + symcount;
++  for (esym = (const bfd_byte *) extsym_buf, isym = alloc_intsym,
+ 	   shndx = extshndx_buf;
+        isym < isymend;
+        esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
+@@ -590,7 +624,9 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{	
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported binding of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), bind);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      bind);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+@@ -602,19 +638,42 @@ bfd_elf_get_elf_syms (bfd *ibfd,
+ 	{
+ 	  /* xgettext:c-format */
+ 	  _bfd_error_handler (_("%pB symbol number %lu uses unsupported type of %u"),
+-			      ibfd, (unsigned long) (isym - intsym_buf), t);
++			      ibfd,
++			      (unsigned long) (isym - alloc_intsym),
++			      t);
+ 	  free (alloc_intsym);
+ 	  intsym_buf = NULL;
+ 	  goto out1;
+ 	}
+     }
+ 
++  if (intsym_buf != NULL && partial_extsym_buf != NULL)
++    {
++      if (partial_symcount != symcount)
++	abort ();
++      memcpy (partial_extsym_buf, extsym_buf, extsym_buf_size);
++    }
++
+  out1:
+   _bfd_munmap_temporary (alloc_extshndx, alloc_extshndx_size);
+  out2:
+   _bfd_munmap_temporary (alloc_ext, alloc_ext_size);
+ 
+-  return intsym_buf;
++  if (intsym_buf == NULL)
++    return intsym_buf;
++
++  if (!cache_symtab)
++    return intsym_buf;
++
++  elf_tdata (ibfd)->symtab = alloc_intsym;
++  if (intsym_buf != alloc_intsym)
++    {
++      memcpy (intsym_buf, alloc_intsym + partial_symoffset,
++	      partial_symcount * sizeof (*intsym_buf));
++      return intsym_buf;
++    }
++  else
++    return alloc_intsym + partial_symoffset;
+ }
+ 
+ /* Look up a symbol name.  */
+@@ -659,8 +718,6 @@ static const char *
+ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+ {
+   Elf_Internal_Shdr *hdr;
+-  unsigned char esym[sizeof (Elf64_External_Sym)];
+-  Elf_External_Sym_Shndx eshndx;
+   Elf_Internal_Sym isym;
+ 
+   /* First we need to ensure the symbol table is available.  Make sure
+@@ -675,7 +732,7 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr)
+   /* Go read the symbol.  */
+   hdr = &elf_tdata (abfd)->symtab_hdr;
+   if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
+-			    &isym, esym, &eshndx) == NULL)
++			    &isym, NULL) == NULL)
+     return NULL;
+ 
+   return bfd_elf_sym_name_raw (abfd, hdr, &isym);
+@@ -3029,12 +3086,10 @@ bfd_sym_from_r_symndx (struct sym_cache *cache,
+   if (cache->abfd != abfd || cache->indx[ent] != r_symndx)
+     {
+       Elf_Internal_Shdr *symtab_hdr;
+-      unsigned char esym[sizeof (Elf64_External_Sym)];
+-      Elf_External_Sym_Shndx eshndx;
+ 
+       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+       if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
+-				&cache->sym[ent], esym, &eshndx) == NULL)
++				&cache->sym[ent], NULL) == NULL)
+ 	return NULL;
+ 
+       if (cache->abfd != abfd)
+@@ -10239,8 +10294,8 @@ _bfd_elf_free_cached_info (bfd *abfd)
+ 	      free (sec_info->cies);
+ 	    }
+ 	}
+-      free (tdata->symtab_hdr.contents);
+-      tdata->symtab_hdr.contents = NULL;
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
+     }
+ 
+   return _bfd_generic_bfd_free_cached_info (abfd);
+diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
+index ebfe4dcc26a..ed1dd56a59f 100644
+--- a/bfd/elf32-arc.c
++++ b/bfd/elf32-arc.c
+@@ -3037,7 +3037,7 @@ arc_elf_relax_section (bfd *abfd, asection *sec,
+           if (isymbuf == NULL)
+             isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+                                             symtab_hdr->sh_info, 0,
+-                                            NULL, NULL, NULL);
++					    NULL, NULL);
+           if (isymbuf == NULL)
+             goto error_return;
+         }
+diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
+index ae3dc246be0..627c03eb507 100644
+--- a/bfd/elf32-arm.c
++++ b/bfd/elf32-arm.c
+@@ -5928,7 +5928,7 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
+   local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (local_syms == NULL)
+     local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+-				       symtab_hdr->sh_info, 0, NULL, NULL,
++				       symtab_hdr->sh_info, 0, NULL,
+ 				       NULL);
+   if (symtab_hdr->sh_info && local_syms == NULL)
+     return false;
+@@ -6611,7 +6611,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+@@ -7966,8 +7966,7 @@ bfd_elf32_arm_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
+-				  NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
+index 6653e4d72f6..28e41914bd0 100644
+--- a/bfd/elf32-avr.c
++++ b/bfd/elf32-avr.c
+@@ -2064,7 +2064,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -2197,7 +2197,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+@@ -2569,7 +2569,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3008,7 +3008,7 @@ elf32_avr_relax_section (bfd *abfd,
+ 					(abfd,
+ 					 symtab_hdr,
+ 					 symtab_hdr->sh_info, 0,
+-					 NULL, NULL, NULL);
++					 NULL, NULL);
+ 				    if (isymbuf == NULL)
+ 				      break;
+ 				  }
+@@ -3241,7 +3241,7 @@ elf32_avr_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -3590,7 +3590,7 @@ get_local_syms (bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
+index 7ed1285f4c2..8b74a9f3039 100644
+--- a/bfd/elf32-bfin.c
++++ b/bfd/elf32-bfin.c
+@@ -5351,7 +5351,7 @@ bfd_bfin_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
+index 31d1ba41c17..3fc4b4adfa1 100644
+--- a/bfd/elf32-cr16.c
++++ b/bfd/elf32-cr16.c
+@@ -1511,7 +1511,7 @@ elf32_cr16_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1765,7 +1765,7 @@ elf32_cr16_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2739,7 +2739,7 @@ bfd_cr16_elf32_create_embedded_relocs (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-crx.c b/bfd/elf32-crx.c
+index d2bc1f7ba72..03c20aab6cb 100644
+--- a/bfd/elf32-crx.c
++++ b/bfd/elf32-crx.c
+@@ -772,7 +772,7 @@ elf32_crx_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1021,7 +1021,7 @@ elf32_crx_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-csky.c b/bfd/elf32-csky.c
+index 40781a0e1bb..cc93602f5b0 100644
+--- a/bfd/elf32-csky.c
++++ b/bfd/elf32-csky.c
+@@ -3543,7 +3543,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
+ 			    bfd_elf_get_elf_syms (input_bfd,
+ 						  symtab_hdr,
+ 						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
++						  0, NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elf32-epiphany.c b/bfd/elf32-epiphany.c
+index ea60ce4dc72..bace4943dea 100644
+--- a/bfd/elf32-epiphany.c
++++ b/bfd/elf32-epiphany.c
+@@ -259,7 +259,7 @@ epiphany_elf_relax_section (bfd *abfd, asection *sec,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-ft32.c b/bfd/elf32-ft32.c
+index 6ca175533da..ee9294def64 100644
+--- a/bfd/elf32-ft32.c
++++ b/bfd/elf32-ft32.c
+@@ -837,7 +837,7 @@ elf32_ft32_relax_delete_bytes (struct bfd_link_info *link_info, bfd * abfd,
+ 		if (isymbuf == NULL)
+ 		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		if (isymbuf == NULL)
+ 		  return false;
+ 	      }
+@@ -995,7 +995,7 @@ elf32_ft32_relax_is_branch_target (struct bfd_link_info *link_info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		return false;
+ 	    }
+@@ -1119,7 +1119,7 @@ ft32_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+       symtab_hdr->contents = (unsigned char *) isymbuf;
+diff --git a/bfd/elf32-h8300.c b/bfd/elf32-h8300.c
+index e183577fca4..4bd20f9c433 100644
+--- a/bfd/elf32-h8300.c
++++ b/bfd/elf32-h8300.c
+@@ -778,7 +778,7 @@ elf32_h8_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -1654,7 +1654,7 @@ elf32_h8_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
+index 2f463e12829..085b10b8ea9 100644
+--- a/bfd/elf32-hppa.c
++++ b/bfd/elf32-hppa.c
+@@ -2506,7 +2506,7 @@ get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-ip2k.c b/bfd/elf32-ip2k.c
+index 5c28a06f318..71de071e1ec 100644
+--- a/bfd/elf32-ip2k.c
++++ b/bfd/elf32-ip2k.c
+@@ -1130,7 +1130,7 @@ ip2k_elf_relax_section (bfd *abfd,
+       if (isymbuf == NULL)
+ 	isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					symtab_hdr->sh_info, 0,
+-					NULL, NULL, NULL);
++					NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+     }
+diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
+index 8f6881bcb0b..bf24f487c44 100644
+--- a/bfd/elf32-m32c.c
++++ b/bfd/elf32-m32c.c
+@@ -980,7 +980,7 @@ dump_symtab (bfd * abfd, void *internal_syms, void *external_syms)
+   if (free_internal)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+@@ -1191,7 +1191,7 @@ m32c_elf_relax_plt_section (asection *splt,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -1488,7 +1488,9 @@ m32c_elf_relax_section (bfd *abfd,
+     }
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++				      symtab_hdr->sh_info, 0, NULL,
++				      NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-m68hc11.c b/bfd/elf32-m68hc11.c
+index f70716d66a2..b4e0a3220ac 100644
+--- a/bfd/elf32-m68hc11.c
++++ b/bfd/elf32-m68hc11.c
+@@ -823,7 +823,7 @@ m68hc11_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
+index 7e8e0383717..9c1bac23549 100644
+--- a/bfd/elf32-m68hc1x.c
++++ b/bfd/elf32-m68hc1x.c
+@@ -375,7 +375,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
+index 44ef102ea60..728da0754ab 100644
+--- a/bfd/elf32-m68k.c
++++ b/bfd/elf32-m68k.c
+@@ -4439,7 +4439,7 @@ bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c
+index 916f3e15c72..f754af6e3be 100644
+--- a/bfd/elf32-metag.c
++++ b/bfd/elf32-metag.c
+@@ -3604,7 +3604,7 @@ get_local_syms (bfd *output_bfd ATTRIBUTE_UNUSED, bfd *input_bfd,
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  /* Cache them for elf_link_input_bfd.  */
+ 	  symtab_hdr->contents = (unsigned char *) local_syms;
+ 	}
+diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
+index db7ed465779..3a526391676 100644
+--- a/bfd/elf32-microblaze.c
++++ b/bfd/elf32-microblaze.c
+@@ -1801,7 +1801,7 @@ microblaze_elf_relax_section (bfd *abfd,
+   symcount =  symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
+   if (isymbuf == NULL)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
+-				    0, NULL, NULL, NULL);
++				    0, NULL, NULL);
+   BFD_ASSERT (isymbuf != NULL);
+ 
+   internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
+diff --git a/bfd/elf32-msp430.c b/bfd/elf32-msp430.c
+index 3b356bfe4e2..5250f13a8b9 100644
+--- a/bfd/elf32-msp430.c
++++ b/bfd/elf32-msp430.c
+@@ -2071,7 +2071,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -2295,7 +2295,7 @@ msp430_elf_relax_section (bfd * abfd, asection * sec,
+ 	    if (isymbuf == NULL)
+ 	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      symtab_hdr->sh_info, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+ 	    if (isymbuf == NULL)
+ 	      goto error_return;
+ 	  }
+diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
+index e22b58c4ea8..b15626349a8 100644
+--- a/bfd/elf32-nds32.c
++++ b/bfd/elf32-nds32.c
+@@ -9225,7 +9225,7 @@ nds32_elf_relax_delete_blanks (bfd *abfd, asection *sec,
+   if (isym == NULL)
+     {
+       isym = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-				   symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++				   symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) isym;
+     }
+ 
+@@ -9533,7 +9533,7 @@ nds32_get_local_syms (bfd *abfd, asection *sec ATTRIBUTE_UNUSED,
+ 	{
+ 	  *isymbuf_p = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					     symtab_hdr->sh_info, 0,
+-					     NULL, NULL, NULL);
++					     NULL, NULL);
+ 	  if (*isymbuf_p == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
+index a3adcf8430e..e77e77fd687 100644
+--- a/bfd/elf32-ppc.c
++++ b/bfd/elf32-ppc.c
+@@ -4114,7 +4114,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -5570,7 +5570,7 @@ ppc_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-pru.c b/bfd/elf32-pru.c
+index 45a86be3ccf..e0d9eb507e2 100644
+--- a/bfd/elf32-pru.c
++++ b/bfd/elf32-pru.c
+@@ -1215,7 +1215,7 @@ pru_elf_relax_delete_bytes (bfd *abfd,
+ 	       if (isymbuf == NULL)
+ 		 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						 symtab_hdr->sh_info, 0,
+-						 NULL, NULL, NULL);
++						 NULL, NULL);
+ 	       if (isymbuf == NULL)
+ 		 return false;
+ 	     }
+@@ -1393,7 +1393,7 @@ pru_elf32_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c
+index e2ea6b1d15f..3608008c977 100644
+--- a/bfd/elf32-rl78.c
++++ b/bfd/elf32-rl78.c
+@@ -1573,7 +1573,7 @@ rl78_elf_relax_plt_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+@@ -2137,7 +2137,7 @@ rl78_elf_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+diff --git a/bfd/elf32-rx.c b/bfd/elf32-rx.c
+index d8a2236a233..e18eab7bbda 100644
+--- a/bfd/elf32-rx.c
++++ b/bfd/elf32-rx.c
+@@ -2070,7 +2070,7 @@ elf32_rx_relax_section (bfd *abfd,
+     intsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+   else
+     {
+-      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL);
++      intsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL);
+       symtab_hdr->contents = (bfd_byte *) intsyms;
+     }
+ 
+@@ -3362,7 +3362,7 @@ rx_dump_symtab (bfd * abfd, void * internal_syms, void * external_syms)
+   if (!internal_syms)
+     isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 				    symtab_hdr->sh_info, 0,
+-				    internal_syms, external_syms, NULL);
++				    internal_syms, external_syms);
+   else
+     isymbuf = internal_syms;
+   isymend = isymbuf + locsymcount;
+diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
+index e078e41b675..022799f389b 100644
+--- a/bfd/elf32-sh.c
++++ b/bfd/elf32-sh.c
+@@ -577,7 +577,7 @@ sh_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+@@ -5118,7 +5118,7 @@ sh_elf_get_relocated_section_contents (bfd *output_bfd,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
+index de051e48185..eb1ce1c9a12 100644
+--- a/bfd/elf32-spu.c
++++ b/bfd/elf32-spu.c
+@@ -538,7 +538,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -3018,7 +3018,7 @@ discover_functions (struct bfd_link_info *info)
+       free (symtab_hdr->contents);
+       symtab_hdr->contents = NULL;
+       syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, 0,
+-				   NULL, NULL, NULL);
++				   NULL, NULL);
+       symtab_hdr->contents = (void *) syms;
+       if (syms == NULL)
+ 	return false;
+diff --git a/bfd/elf32-v850.c b/bfd/elf32-v850.c
+index 27744814691..4d96cf9fbce 100644
+--- a/bfd/elf32-v850.c
++++ b/bfd/elf32-v850.c
+@@ -3548,7 +3548,7 @@ v850_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c
+index 5cee2f389eb..ae043319206 100644
+--- a/bfd/elf32-xstormy16.c
++++ b/bfd/elf32-xstormy16.c
+@@ -627,7 +627,7 @@ xstormy16_elf_relax_section (bfd *dynobj,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
+index b21676df36a..c554740f357 100644
+--- a/bfd/elf32-xtensa.c
++++ b/bfd/elf32-xtensa.c
+@@ -6831,7 +6831,7 @@ retrieve_local_syms (bfd *input_bfd)
+   isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+   if (isymbuf == NULL && locsymcount != 0)
+     isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				    NULL, NULL, NULL);
++				    NULL, NULL);
+ 
+   /* Save the symbols for this input file so they won't be read again.  */
+   if (isymbuf && isymbuf != (Elf_Internal_Sym *) symtab_hdr->contents)
+diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
+index b13c99e4958..2b9eede314d 100644
+--- a/bfd/elf64-alpha.c
++++ b/bfd/elf64-alpha.c
+@@ -3814,7 +3814,7 @@ elf64_alpha_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == NULL)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
+index 05bb7f125b7..8cd2d918d8b 100644
+--- a/bfd/elf64-hppa.c
++++ b/bfd/elf64-hppa.c
+@@ -560,7 +560,7 @@ elf64_hppa_check_relocs (bfd *abfd,
+ 	  if (local_syms == NULL)
+ 	    local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					       symtab_hdr->sh_info, 0,
+-					       NULL, NULL, NULL);
++					       NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
+index 822b263ae2c..f6d00fc1826 100644
+--- a/bfd/elf64-ia64-vms.c
++++ b/bfd/elf64-ia64-vms.c
+@@ -467,7 +467,7 @@ elf64_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+@@ -4896,7 +4896,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
+index bb8350718a2..642b2cdb9bb 100644
+--- a/bfd/elf64-mmix.c
++++ b/bfd/elf64-mmix.c
+@@ -2640,7 +2640,7 @@ mmix_elf_relax_section (bfd *abfd,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
+index fdda9e0bbb3..ee15d6f0639 100644
+--- a/bfd/elf64-ppc.c
++++ b/bfd/elf64-ppc.c
+@@ -5666,7 +5666,7 @@ opd_entry_value (asection *opd_sec,
+ 			  size_t symcnt = symtab_hdr->sh_info;
+ 			  sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						      symcnt, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (sym == NULL)
+ 			    break;
+ 			  symtab_hdr->contents = (bfd_byte *) sym;
+@@ -5677,7 +5677,7 @@ opd_entry_value (asection *opd_sec,
+ 		    {
+ 		      sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 						  1, symndx,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (sym == NULL)
+ 			break;
+ 		    }
+@@ -6987,7 +6987,7 @@ get_sym_h (struct elf_link_hash_entry **hp,
+ 	  if (locsyms == NULL)
+ 	    locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
+ 					    symtab_hdr->sh_info,
+-					    0, NULL, NULL, NULL);
++					    0, NULL, NULL);
+ 	  if (locsyms == NULL)
+ 	    return false;
+ 	  *locsymsp = locsyms;
+@@ -10325,7 +10325,7 @@ ppc64_elf_late_size_sections (bfd *output_bfd,
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -12921,7 +12921,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+@@ -13591,7 +13591,7 @@ got_and_plt_relr_for_local_syms (struct bfd_link_info *info)
+       if (local_syms == NULL && locsymcount != 0)
+ 	{
+ 	  local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, locsymcount,
+-					     0, NULL, NULL, NULL);
++					     0, NULL, NULL);
+ 	  if (local_syms == NULL)
+ 	    return false;
+ 	}
+diff --git a/bfd/elfcode.h b/bfd/elfcode.h
+index 5224a1abee6..8777a08a77a 100644
+--- a/bfd/elfcode.h
++++ b/bfd/elfcode.h
+@@ -1303,7 +1303,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+       size_t i;
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return -1;
+ 
+@@ -1523,16 +1523,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bool dynamic)
+     }
+ 
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return symcount;
+ 
+  error_return:
+   free (xverbuf);
+-  if (hdr->contents != (unsigned char *) isymbuf
+-      && !elf_use_dt_symtab_p (abfd))
+-    free (isymbuf);
+   return -1;
+ }
+ 
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index 3f3ea2cce51..da4da5c453a 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -851,8 +851,6 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+   struct elf_strtab_hash *dynstr;
+   size_t dynstr_index;
+   char *name;
+-  Elf_External_Sym_Shndx eshndx;
+-  char esym[sizeof (Elf64_External_Sym)];
+ 
+   if (! is_elf_hash_table (info->hash))
+     return 0;
+@@ -869,7 +867,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
+ 
+   /* Go find the symbol, so that we can find it's name.  */
+   if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
+-			     1, input_indx, &entry->isym, esym, &eshndx))
++			     1, input_indx, &entry->isym, NULL))
+     {
+       bfd_release (input_bfd, entry);
+       return 0;
+@@ -3745,7 +3743,7 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 
+   /* Read in the symbol table.  */
+   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				  NULL, NULL, NULL);
++				  NULL, NULL);
+   if (isymbuf == NULL)
+     return false;
+ 
+@@ -3767,7 +3765,11 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
+ 	}
+     }
+ 
+-  free (isymbuf);
++  if (!elf_tdata (abfd)->keep_symtab)
++    {
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
++    }
+ 
+   return result;
+ }
+@@ -4830,7 +4832,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   if (extsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	goto error_return;
+ 
+@@ -5814,8 +5816,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 
+   free (extversym);
+   extversym = NULL;
+-  free (isymbuf);
+-  isymbuf = NULL;
++
++  /* NB: Since st_shndx of symbol from discarded section is changed to
++     SHN_UNDEF, free the cached symbol table.  */
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+ 
+   if ((elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0)
+     {
+@@ -6167,7 +6172,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+   free (nondeflt_vers);
+   free (extversym);
+  error_free_sym:
+-  free (isymbuf);
++  free (elf_tdata (abfd)->symtab);
++  elf_tdata (abfd)->symtab = NULL;
+  error_return:
+   return false;
+ }
+@@ -8809,7 +8815,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL)
+     {
+       isymbuf1 = bfd_elf_get_elf_syms (bfd1, hdr1, symcount1, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf1 == NULL)
+ 	goto done;
+ 
+@@ -8823,7 +8829,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+   if (ssymbuf1 == NULL || ssymbuf2 == NULL)
+     {
+       isymbuf2 = bfd_elf_get_elf_syms (bfd2, hdr2, symcount2, 0,
+-				       NULL, NULL, NULL);
++				       NULL, NULL);
+       if (isymbuf2 == NULL)
+ 	goto done;
+ 
+@@ -9013,8 +9019,6 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
+  done:
+   free (symtable1);
+   free (symtable2);
+-  free (isymbuf1);
+-  free (isymbuf2);
+ 
+   return result;
+ }
+@@ -9056,14 +9060,6 @@ struct elf_final_link_info
+   void *external_relocs;
+   /* Buffer large enough to hold internal relocs of any section.  */
+   Elf_Internal_Rela *internal_relocs;
+-  /* Buffer large enough to hold external local symbols of any input
+-     BFD.  */
+-  bfd_byte *external_syms;
+-  /* And a buffer for symbol section indices.  */
+-  Elf_External_Sym_Shndx *locsym_shndx;
+-  /* Buffer large enough to hold internal local symbols of any input
+-     BFD.  */
+-  Elf_Internal_Sym *internal_syms;
+   /* Array large enough to hold a symbol index for each local symbol
+      of any input BFD.  */
+   long *indices;
+@@ -10666,7 +10662,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
+ 	continue;
+ 
+       isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
+-				      NULL, NULL, NULL);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+ 
+@@ -11410,7 +11406,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+   Elf_Internal_Shdr *symtab_hdr;
+   size_t locsymcount;
+   size_t extsymoff;
+-  Elf_Internal_Sym *isymbuf;
++  Elf_Internal_Sym *isymbuf = NULL;
+   Elf_Internal_Sym *isym;
+   Elf_Internal_Sym *isymend;
+   long *pindex;
+@@ -11456,13 +11452,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
+ 	     ? -1 : ~elf_gnu_osabi_retain));
+ 
+   /* Read the local symbols.  */
+-  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (isymbuf == NULL && locsymcount != 0)
++  if (locsymcount != 0)
+     {
+       isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
+-				      flinfo->internal_syms,
+-				      flinfo->external_syms,
+-				      flinfo->locsym_shndx);
++				      NULL, NULL);
+       if (isymbuf == NULL)
+ 	return false;
+     }
+@@ -12632,9 +12625,6 @@ elf_final_link_free (bfd *obfd, struct elf_final_link_info *flinfo)
+   free (flinfo->contents);
+   free (flinfo->external_relocs);
+   free (flinfo->internal_relocs);
+-  free (flinfo->external_syms);
+-  free (flinfo->locsym_shndx);
+-  free (flinfo->internal_syms);
+   free (flinfo->indices);
+   free (flinfo->sections);
+   if (flinfo->symshndxbuf != (Elf_External_Sym_Shndx *) -1)
+@@ -12663,7 +12653,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+   bfd_size_type max_external_reloc_size;
+   bfd_size_type max_internal_reloc_count;
+   bfd_size_type max_sym_count;
+-  bfd_size_type max_sym_shndx_count;
+   Elf_Internal_Sym elfsym;
+   unsigned int i;
+   Elf_Internal_Shdr *symtab_hdr;
+@@ -12792,7 +12781,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+     }
+   max_internal_reloc_count = 0;
+   max_sym_count = 0;
+-  max_sym_shndx_count = 0;
+   merged = false;
+   for (o = abfd->sections; o != NULL; o = o->next)
+     {
+@@ -12854,10 +12842,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 		  if (sym_count > max_sym_count)
+ 		    max_sym_count = sym_count;
+ 
+-		  if (sym_count > max_sym_shndx_count
+-		      && elf_symtab_shndx_list (sec->owner) != NULL)
+-		    max_sym_shndx_count = sym_count;
+-
+ 		  esdi = elf_section_data (sec);
+ 
+ 		  if (esdi->this_hdr.sh_type == SHT_REL
+@@ -13118,16 +13102,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+   if (max_sym_count != 0)
+     {
+-      amt = max_sym_count * bed->s->sizeof_sym;
+-      flinfo.external_syms = (bfd_byte *) bfd_malloc (amt);
+-      if (flinfo.external_syms == NULL)
+-	goto error_return;
+-
+-      amt = max_sym_count * sizeof (Elf_Internal_Sym);
+-      flinfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
+-      if (flinfo.internal_syms == NULL)
+-	goto error_return;
+-
+       amt = max_sym_count * sizeof (long);
+       flinfo.indices = (long int *) bfd_malloc (amt);
+       if (flinfo.indices == NULL)
+@@ -13139,14 +13113,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 	goto error_return;
+     }
+ 
+-  if (max_sym_shndx_count != 0)
+-    {
+-      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
+-      flinfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
+-      if (flinfo.locsym_shndx == NULL)
+-	goto error_return;
+-    }
+-
+   if (htab->tls_sec)
+     {
+       bfd_vma base, end = 0;  /* Both bytes.  */
+@@ -13890,8 +13856,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
+ 
+ static bool
+ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+-		   struct bfd_link_info *info, bfd *abfd,
+-		   bool keep_memory)
++		   struct bfd_link_info *info, bfd *abfd)
+ {
+   Elf_Internal_Shdr *symtab_hdr;
+   const struct elf_backend_data *bed;
+@@ -13918,39 +13883,20 @@ init_reloc_cookie (struct elf_reloc_cookie *cookie,
+   else
+     cookie->r_sym_shift = 32;
+ 
+-  cookie->locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
+-  if (cookie->locsyms == NULL && cookie->locsymcount != 0)
++  if (cookie->locsymcount != 0)
+     {
+       cookie->locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					      cookie->locsymcount, 0,
+-					      NULL, NULL, NULL);
++					      NULL, NULL);
+       if (cookie->locsyms == NULL)
+ 	{
+ 	  info->callbacks->einfo (_("%P%X: can not read symbols: %E\n"));
+ 	  return false;
+ 	}
+-      if (keep_memory || _bfd_elf_link_keep_memory (info))
+-	{
+-	  symtab_hdr->contents = (bfd_byte *) cookie->locsyms;
+-	  info->cache_size += (cookie->locsymcount
+-			       * sizeof (Elf_Internal_Sym));
+-	}
+     }
+   return true;
+ }
+ 
+-/* Free the memory allocated by init_reloc_cookie, if appropriate.  */
+-
+-static void
+-fini_reloc_cookie (struct elf_reloc_cookie *cookie, bfd *abfd)
+-{
+-  Elf_Internal_Shdr *symtab_hdr;
+-
+-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+-  if (symtab_hdr->contents != (unsigned char *) cookie->locsyms)
+-    free (cookie->locsyms);
+-}
+-
+ /* Initialize the relocation information in COOKIE for input section SEC
+    of input bfd ABFD.  */
+ 
+@@ -13996,28 +13942,9 @@ init_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+ 			       struct bfd_link_info *info,
+ 			       asection *sec, bool keep_memory)
+ {
+-  if (!init_reloc_cookie (cookie, info, sec->owner, keep_memory))
+-    goto error1;
+-  if (!init_reloc_cookie_rels (cookie, info, sec->owner, sec,
+-			       keep_memory))
+-    goto error2;
+-  return true;
+-
+- error2:
+-  fini_reloc_cookie (cookie, sec->owner);
+- error1:
+-  return false;
+-}
+-
+-/* Free the memory allocated by init_reloc_cookie_for_section,
+-   if appropriate.  */
+-
+-static void
+-fini_reloc_cookie_for_section (struct elf_reloc_cookie *cookie,
+-			       asection *sec)
+-{
+-  fini_reloc_cookie_rels (cookie, sec);
+-  fini_reloc_cookie (cookie, sec->owner);
++  return (init_reloc_cookie (cookie, info, sec->owner)
++	  && init_reloc_cookie_rels (cookie, info, sec->owner, sec,
++				     keep_memory));
+ }
+ \f
+ /* Garbage collect unused sections.  */
+@@ -14209,7 +14136,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 		ret = false;
+ 		break;
+ 	      }
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	}
+     }
+ 
+@@ -14231,7 +14158,7 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
+ 	  if (!_bfd_elf_gc_mark_fdes (info, sec, eh_frame,
+ 				      gc_mark_hook, &cookie))
+ 	    ret = false;
+-	  fini_reloc_cookie_for_section (&cookie, eh_frame);
++	  fini_reloc_cookie_rels (&cookie, eh_frame);
+ 	}
+     }
+ 
+@@ -14665,7 +14592,7 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
+       if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+ 	continue;
+ 
+-      if (!init_reloc_cookie (&cookie, info, ibfd, false))
++      if (!init_reloc_cookie (&cookie, info, ibfd))
+ 	return false;
+ 
+       for (sec = ibfd->sections; sec; sec = sec->next)
+@@ -14724,7 +14651,7 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	  if (elf_section_data (sec)->sec_info
+ 	      && (sec->flags & SEC_LINKER_CREATED) == 0)
+ 	    elf_eh_frame_section (sub) = sec;
+-	  fini_reloc_cookie_for_section (&cookie, sec);
++	  fini_reloc_cookie_rels (&cookie, sec);
+ 	  sec = bfd_get_next_section_by_name (NULL, sec);
+ 	}
+     }
+@@ -14784,6 +14711,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
+ 	    if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
+ 	      return false;
+ 	  }
++
++      if (!elf_tdata (sub)->keep_symtab
++	  && !_bfd_elf_link_keep_memory (info))
++	{
++	  free (elf_tdata (sub)->symtab);
++	  elf_tdata (sub)->symtab = NULL;
++	}
+     }
+ 
+   /* Allow the backend to mark additional target specific sections.  */
+@@ -15239,7 +15173,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 					  &cookie))
+ 	    changed = 1;
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+     }
+ 
+@@ -15274,7 +15208,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		changed = 1;
+ 	    }
+ 
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+ 
+       eh_alignment = ((1 << o->alignment_power)
+@@ -15339,7 +15273,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 		    changed = 1;
+ 		}
+ 	    }
+-	  fini_reloc_cookie_for_section (&cookie, i);
++	  fini_reloc_cookie_rels (&cookie, i);
+ 	}
+       /* Update the reference to the output .sframe section.  Used to
+ 	 determine later if PT_GNU_SFRAME segment is to be generated.  */
+@@ -15362,13 +15296,11 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
+ 
+       if (bed->elf_backend_discard_info != NULL)
+ 	{
+-	  if (!init_reloc_cookie (&cookie, info, abfd, false))
++	  if (!init_reloc_cookie (&cookie, info, abfd))
+ 	    return -1;
+ 
+ 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
+ 	    changed = 1;
+-
+-	  fini_reloc_cookie (&cookie, abfd);
+ 	}
+     }
+ 
+diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
+index 3c3c2899674..553ba27b604 100644
+--- a/bfd/elfnn-aarch64.c
++++ b/bfd/elfnn-aarch64.c
+@@ -4471,7 +4471,7 @@ _bfd_aarch64_add_call_stub_entries (bool *stub_changed, bfd *output_bfd,
+ 			local_syms
+ 			  = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						  symtab_hdr->sh_info, 0,
+-						  NULL, NULL, NULL);
++						  NULL, NULL);
+ 		      if (local_syms == NULL)
+ 			goto error_ret_free_internal;
+ 		    }
+@@ -4934,7 +4934,7 @@ bfd_elfNN_aarch64_init_maps (bfd *abfd)
+   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
+      should contain the number of local symbols, which should come before any
+      global symbols.  Mapping symbols are always local.  */
+-  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
++  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL);
+ 
+   /* No internal symbols read?  Skip this BFD.  */
+   if (isymbuf == NULL)
+diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c
+index 528b1dcdcc3..48fce2380cd 100644
+--- a/bfd/elfnn-ia64.c
++++ b/bfd/elfnn-ia64.c
+@@ -468,7 +468,7 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec,
+ 	      if (isymbuf == NULL)
+ 		isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						symtab_hdr->sh_info, 0,
+-						NULL, NULL, NULL);
++						NULL, NULL);
+ 	      if (isymbuf == 0)
+ 		goto error_return;
+ 	    }
+diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
+index 3b44db57421..8e75b400570 100644
+--- a/bfd/elfnn-kvx.c
++++ b/bfd/elfnn-kvx.c
+@@ -1404,7 +1404,7 @@ elfNN_kvx_size_stubs (bfd *output_bfd,
+ 			    local_syms
+ 			      = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
+ 						      symtab_hdr->sh_info, 0,
+-						      NULL, NULL, NULL);
++						      NULL, NULL);
+ 			  if (local_syms == NULL)
+ 			    goto error_ret_free_internal;
+ 			}
+diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
+index 53cdb783859..10a4f99add7 100644
+--- a/bfd/elfnn-loongarch.c
++++ b/bfd/elfnn-loongarch.c
+@@ -5792,7 +5792,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
+       && !(symtab_hdr->contents =
+ 	   (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						   symtab_hdr->sh_info,
+-						   0, NULL, NULL, NULL)))
++						   0, NULL, NULL)))
+     return true;
+ 
+   /* Estimate the maximum alignment for all output sections once time
+diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
+index 09cf7076733..d1ab410a94f 100644
+--- a/bfd/elfnn-riscv.c
++++ b/bfd/elfnn-riscv.c
+@@ -5492,7 +5492,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
+ 	  && !(symtab_hdr->contents =
+ 	       (unsigned char *) bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 						       symtab_hdr->sh_info,
+-						       0, NULL, NULL, NULL)))
++						       0, NULL, NULL)))
+ 	goto fail;
+ 
+       /* Get the value of the symbol referred to by the reloc.  */
+diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
+index 00ef0663728..44c58362dda 100644
+--- a/bfd/elfxx-mips.c
++++ b/bfd/elfxx-mips.c
+@@ -14136,7 +14136,7 @@ _bfd_mips_elf_relax_section (bfd *abfd, asection *sec,
+ 	  if (isymbuf == NULL)
+ 	    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+ 					    symtab_hdr->sh_info, 0,
+-					    NULL, NULL, NULL);
++					    NULL, NULL);
+ 	  if (isymbuf == NULL)
+ 	    goto error_return;
+ 	}
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index 140e86888a6..53083e0b54c 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -1154,15 +1154,11 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+ 	  /* Read this BFD's local symbols.  */
+ 	  if (isymbuf == NULL)
+ 	    {
+-	      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
++	      isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
++					      symtab_hdr->sh_info,
++					      0, NULL, NULL);
+ 	      if (isymbuf == NULL)
+-		{
+-		  isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+-						  symtab_hdr->sh_info,
+-						  0, NULL, NULL, NULL);
+-		  if (isymbuf == NULL)
+-		    goto error_return;
+-		}
++		goto error_return;
+ 	    }
+ 
+ 	  isym = isymbuf + r_symndx;
+@@ -1345,14 +1341,10 @@ _bfd_x86_elf_link_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
+   return_status = true;
+ 
+ error_return:
+-  if ((unsigned char *) isymbuf != symtab_hdr->contents)
+-    {
+-      /* Cache the symbol buffer if it must be kept.  */
+-      if (keep_symbuf)
+-	symtab_hdr->contents = (unsigned char *) isymbuf;
+-      else
+-	free (isymbuf);
+-    }
++  /* If the symbol table has been updated, it must be kept since it will
++     be used later.  */
++  if (keep_symbuf)
++    elf_tdata (abfd)->keep_symtab = 1;
+   if (elf_section_data (input_section)->relocs != internal_relocs)
+     free (internal_relocs);
+   return return_status;
+diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
+index 7241de70709..205347c4e22 100644
+--- a/libctf/ctf-open-bfd.c
++++ b/libctf/ctf-open-bfd.c
+@@ -146,8 +146,9 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+ 	}
+ 
+       isymbuf = bfd_elf_get_elf_syms (abfd, symhdr, symcount, 0,
+-				      NULL, symtab, NULL);
+-      free (isymbuf);
++				      NULL, symtab);
++      free (elf_tdata (abfd)->symtab);
++      elf_tdata (abfd)->symtab = NULL;
+       if (isymbuf == NULL)
+ 	{
+ 	  bfderrstr = N_("cannot read symbol table");
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-29 13:40 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-29 13:40 UTC (permalink / raw
  To: gentoo-commits

commit:     66feb3705c419dfd965e099c2f167958ddf45be5
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 29 13:40:06 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 29 13:40:06 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=66feb370

9999: drop merged --got-sections patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0007-readelf-Add-got-contents-option.patch | 2245 -----------------------
 1 file changed, 2245 deletions(-)

diff --git a/9999/0007-readelf-Add-got-contents-option.patch b/9999/0007-readelf-Add-got-contents-option.patch
deleted file mode 100644
index 85fd491..0000000
--- a/9999/0007-readelf-Add-got-contents-option.patch
+++ /dev/null
@@ -1,2245 +0,0 @@
-From 59c754fcc3081053610842bdd288726fedc8c91b Mon Sep 17 00:00:00 2001
-Message-ID: <59c754fcc3081053610842bdd288726fedc8c91b.1756412415.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 25 Aug 2025 18:00:00 -0700
-Subject: [PATCH] readelf: Add --got-contents option
-
-Add --got-contents option to readelf, inspired by the -G option on Solaris,
-to display contents of GOT sections:
-
-$ readelf --got-contents libfoo.so
-
-Global Offset Table '.got' contains 1 entry:
- Index:    Address       Reloc         Sym. Name + Addend/Value
-     0: 000000200340 R_X86_64_GLOB_DAT foo + 0
-
-Global Offset Table '.got.plt' contains 4 entries:
- Index:    Address       Reloc         Sym. Name + Addend/Value
-     0: 000000200348                   200220
-     1: 000000200350                   0
-     2: 000000200358                   0
-     3: 000000200360 R_X86_64_JUMP_SLO bar + 0
-
-When --got-content options are used:
-
-1. Allocate an array, all_relocations, to hold all relocations.
-2. Update dump_relr_relocations and dump_relocations to scan relocations
-and cache them in all_relocations.  Don't display relocations if not
-requested.
-3. Add process_got_section_contents to display contents of GOT sections
-by matching the GOT entry offset against the cached relocations.
-4. Update process_mips_specific to only display the GOT related contents
-for --got-contents.
-
-binutils/
-
-	* NEWS: Mention "readelf --got-contents".
-	* readelf.c (do_got_section_contents): New.
-	(elf_relocation): Likewise.
-	(all_relocations_root): Likewise.
-	(all_relocations): Likewise.
-	(all_relocations_count): Likewise.
-	(update_all_relocations): Likewise.
-	(dump_relr_relocations): Add a bool argument to indicate if
-	relocations should be displayed.  Populate all_relocations if
-	do_got_section_contents is true.
-	(dump_relocations): Likewise.
-	(long_option_values): Add OPTION_GOT_CONTENTS.
-	(options): Add --got-contents.
-	(usage): Show --got-contents.
-	(parse_args): Support --got-contents.
-	(display_relocations): Add a bool argument, dump_reloc, to
-	indicate if relocations should be displayed.  Call
-	update_all_relocations.  Pass dump_reloc to dump_relr_relocations
-	and dump_relocations.
-	(process_relocs): Check do_got_section_contents.  Handle
-	do_got_section_contents for dynamic relocations.
-	(process_section_contents): Pass true to display_relocations.
-	(process_mips_specific): Add a bool argument, dump_got, to
-	indicate if only the GOT related contents should be displayed.
-	Display all MIPS specific information if dump_got is false.
-	(elf_relocation_cmp): New.
-	(display_elf_relocation_at): Likewise.
-	(process_got_section_contents): Likewise.
-	(process_object): Call process_got_section_contents.
-	* doc/binutils.texi: Document --got-contents.
-
-ld/
-
-	* testsuite/ld-i386/binutils.exp: New file.
-	* testsuite/ld-i386/got-1.s: Likewise.
-	* testsuite/ld-i386/libgot-1a.rd: Likewise.
-	* testsuite/ld-i386/libgot-1b.rd: Likewise.
-	* testsuite/ld-i386/libgot-1c.rd: Likewise.
-	* testsuite/ld-i386/libgot-1d.rd: Likewise.
-	* testsuite/ld-x86-64/binutils.exp: Likewise.
-	* testsuite/ld-x86-64/got-1.s: Likewise.
-	* testsuite/ld-x86-64/libgot-1a-x32.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1a.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1b-x32.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1b.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1c-x32.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1c.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1d-x32.rd: Likewise.
-	* testsuite/ld-x86-64/libgot-1d.rd: Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- binutils/NEWS                           |    3 +
- binutils/doc/binutils.texi              |   12 +-
- binutils/readelf.c                      | 1004 ++++++++++++++++++-----
- ld/testsuite/ld-i386/binutils.exp       |   45 +
- ld/testsuite/ld-i386/got-1.s            |    7 +
- ld/testsuite/ld-i386/libgot-1a.rd       |    9 +
- ld/testsuite/ld-i386/libgot-1b.rd       |  119 +++
- ld/testsuite/ld-i386/libgot-1c.rd       |   12 +
- ld/testsuite/ld-i386/libgot-1d.rd       |   12 +
- ld/testsuite/ld-x86-64/binutils.exp     |   59 ++
- ld/testsuite/ld-x86-64/got-1.s          |    7 +
- ld/testsuite/ld-x86-64/libgot-1a-x32.rd |    9 +
- ld/testsuite/ld-x86-64/libgot-1a.rd     |    9 +
- ld/testsuite/ld-x86-64/libgot-1b-x32.rd |  119 +++
- ld/testsuite/ld-x86-64/libgot-1b.rd     |  119 +++
- ld/testsuite/ld-x86-64/libgot-1c-x32.rd |   12 +
- ld/testsuite/ld-x86-64/libgot-1c.rd     |   12 +
- ld/testsuite/ld-x86-64/libgot-1d-x32.rd |   12 +
- ld/testsuite/ld-x86-64/libgot-1d.rd     |   12 +
- 19 files changed, 1378 insertions(+), 215 deletions(-)
- create mode 100644 ld/testsuite/ld-i386/binutils.exp
- create mode 100644 ld/testsuite/ld-i386/got-1.s
- create mode 100644 ld/testsuite/ld-i386/libgot-1a.rd
- create mode 100644 ld/testsuite/ld-i386/libgot-1b.rd
- create mode 100644 ld/testsuite/ld-i386/libgot-1c.rd
- create mode 100644 ld/testsuite/ld-i386/libgot-1d.rd
- create mode 100644 ld/testsuite/ld-x86-64/binutils.exp
- create mode 100644 ld/testsuite/ld-x86-64/got-1.s
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1a-x32.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1a.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1b-x32.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1b.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1c-x32.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1c.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1d-x32.rd
- create mode 100644 ld/testsuite/ld-x86-64/libgot-1d.rd
-
-diff --git a/binutils/NEWS b/binutils/NEWS
-index ccda8559897..0a4ed3bcc43 100644
---- a/binutils/NEWS
-+++ b/binutils/NEWS
-@@ -1,5 +1,8 @@
- -*- text -*-
- 
-+* Add --got-contents option to readelf to display the contents of
-+  Global Offset Table (GOT) sections.
-+
- * Internal changes to plugin support, and stricter target checking may result
-   in some errors being exposed in user options passed to the various binutils.
-   For example objcopy --target=TARGET now will only work if the input file is
-diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
-index 4543341e00c..89425b8a15b 100644
---- a/binutils/doc/binutils.texi
-+++ b/binutils/doc/binutils.texi
-@@ -5076,6 +5076,7 @@ readelf [@option{-a}|@option{--all}]
-         [@option{--ctf-strings=}@var{section}]
-         [@option{--sframe=}@var{section}]
-         [@option{-I}|@option{--histogram}]
-+        [@option{--got-contents}]
-         [@option{-v}|@option{--version}]
-         [@option{-W}|@option{--wide}]
-         [@option{-T}|@option{--silent-truncation}]
-@@ -5111,7 +5112,8 @@ given.
- Equivalent to specifying @option{--file-header},
- @option{--program-headers}, @option{--sections}, @option{--symbols},
- @option{--relocs}, @option{--dynamic}, @option{--notes},
--@option{--version-info}, @option{--arch-specific}, @option{--unwind},
-+@option{--got-contents}, @option{--version-info},
-+@option{--arch-specific}, @option{--unwind},
- @option{--section-groups} and @option{--histogram}.
- 
- Note - this option does not enable @option{--use-dynamic} itself, so
-@@ -5387,6 +5389,14 @@ string table are used.
- If either of @option{--ctf-symbols} or @option{--ctf-strings} is specified, the
- other must be specified as well.
- 
-+@item --got-contents
-+@cindex ELF section information
-+@cindex ELF reloc information
-+Displays the contents of the file's Global Offset Table (GOT) sections,
-+if it has any.  For MIPS, this option is similar to
-+@option{--arch-specific}, but it only displays the GOT related contents
-+and it is ignored when @option{--arch-specific} is used.
-+
- @item -I
- @itemx --histogram
- Display a histogram of bucket list lengths when displaying the contents
-diff --git a/binutils/readelf.c b/binutils/readelf.c
-index 68e193415f2..2affc713adb 100644
---- a/binutils/readelf.c
-+++ b/binutils/readelf.c
-@@ -229,6 +229,7 @@ static bool do_dyn_syms = false;
- static bool do_lto_syms = false;
- static bool do_reloc = false;
- static bool do_sections = false;
-+static bool do_got_section_contents = false;
- static bool do_section_groups = false;
- static bool do_section_details = false;
- static bool do_segments = false;
-@@ -372,6 +373,21 @@ enum versioned_symbol_info
-   symbol_public
- };
- 
-+/* Relocation entries */
-+
-+typedef struct elf_relocation
-+{
-+  bfd_vma r_offset;	/* Location at which to apply the action */
-+  bfd_vma r_addend;	/* Constant addend used to compute value */
-+  const char *r_name;	/* Relocation name.  */
-+  char *r_symbol;	/* Relocation symbol.  */
-+  relocation_type r_type; /* Relocation type.  */
-+} elf_relocation;
-+
-+static elf_relocation *all_relocations_root;
-+static elf_relocation *all_relocations;
-+static size_t all_relocations_count;
-+
- static int
- fseek64 (FILE *stream, int64_t offset, int whence)
- {
-@@ -1767,6 +1783,32 @@ symcmp (const void *p, const void *q)
-   return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
- }
- 
-+static void
-+update_all_relocations (size_t nentries)
-+{
-+  size_t sz;
-+
-+  if (!do_got_section_contents)
-+    return;
-+
-+  if (!all_relocations_root)
-+    {
-+      sz = nentries * sizeof (elf_relocation);
-+      all_relocations_root = (elf_relocation *) xmalloc (sz);
-+      all_relocations = all_relocations_root;
-+      all_relocations_count = nentries;
-+    }
-+  else
-+    {
-+      size_t orig_count = all_relocations_count;
-+      sz = (orig_count + nentries) * sizeof (elf_relocation);
-+      all_relocations_root = (elf_relocation *)
-+	xrealloc (all_relocations_root, sz);
-+      all_relocations = all_relocations_root + orig_count;
-+      all_relocations_count += nentries;
-+    }
-+}
-+
- static uint64_t
- count_relr_relocations (Filedata *          filedata,
- 			Elf_Internal_Shdr * section)
-@@ -1830,6 +1872,9 @@ count_relr_relocations (Filedata *          filedata,
-   return count;
- }
- 
-+/* If DUMP_RELOC is false, don't display RELR relocations, just collect
-+   RELR relocations for displaying GOT section contents later.  */
-+
- static bool
- dump_relr_relocations (Filedata *          filedata,
- 		       uint64_t            relr_size,
-@@ -1838,7 +1883,8 @@ dump_relr_relocations (Filedata *          filedata,
- 		       Elf_Internal_Sym *  symtab,
- 		       uint64_t            nsyms,
- 		       char *              strtab,
--		       uint64_t            strtablen)
-+		       uint64_t            strtablen,
-+		       bool                dump_reloc)
- {
-   uint64_t *  relrs;
-   uint64_t    nentries, i;
-@@ -1860,7 +1906,8 @@ dump_relr_relocations (Filedata *          filedata,
-     num_bits_in_entry = 63;
-   else
-     {
--      warn (_("Unexpected entsize for RELR section\n"));
-+      if (dump_reloc)
-+	warn (_("Unexpected entsize for RELR section\n"));
-       return false;
-     }
- 
-@@ -1874,6 +1921,161 @@ dump_relr_relocations (Filedata *          filedata,
-   if (symtab == NULL)
-     nsyms = 0;
- 
-+  const char *rtype = NULL;
-+  if (do_got_section_contents)
-+    switch (filedata->file_header.e_machine)
-+      {
-+      default:
-+	abort ();
-+
-+      case EM_386:
-+      case EM_IAMCU:
-+	rtype = "R_386_RELATIVE";
-+	break;
-+
-+      case EM_68K:
-+	rtype = "R_68K_RELATIVE";
-+	break;
-+
-+      case EM_860:
-+	rtype = "R_860_RELATIVE";
-+	break;
-+
-+      case EM_AARCH64:
-+	rtype = "R_AARCH64_RELATIVE";
-+	break;
-+
-+      case EM_AMDGPU:
-+	rtype = "R_AMDGPU_RELATIVE64";
-+	break;
-+
-+      case EM_ALPHA:
-+	rtype = "R_ALPHA_RELATIVE";
-+	break;
-+
-+      case EM_ALTERA_NIOS2:
-+	rtype = "R_NIOS2_RELATIVE";
-+	break;
-+
-+      case EM_ARM:
-+	rtype = "R_ARM_RELATIVE";
-+	break;
-+
-+      case EM_ARC:
-+      case EM_ARC_COMPACT:
-+      case EM_ARC_COMPACT2:
-+      case EM_ARC_COMPACT3:
-+      case EM_ARC_COMPACT3_64:
-+	rtype = "R_ARC_RELATIVE";
-+	break;
-+
-+      case EM_CRIS:
-+	rtype = "R_CRIS_RELATIVE";
-+	break;
-+
-+      case EM_CSKY:
-+	rtype = "R_CKCORE_RELATIVE";
-+	break;
-+
-+      case EM_KVX:
-+	rtype = "R_KVX_RELATIVE";
-+	break;
-+
-+      case EM_LATTICEMICO32:
-+	rtype = "R_LM32_RELATIVE";
-+	break;
-+
-+      case EM_LOONGARCH:
-+	rtype = "R_LARCH_RELATIVE";
-+	break;
-+
-+      case EM_M32R:
-+      case EM_CYGNUS_M32R:
-+	rtype = "R_M32R_RELATIVE";
-+	break;
-+
-+      case EM_MCORE:
-+	rtype = "R_MCORE_RELATIVE";
-+	break;
-+
-+      case EM_METAG:
-+	rtype = "R_METAG_RELATIVE";
-+	break;
-+
-+      case EM_MN10300:
-+      case EM_CYGNUS_MN10300:
-+	rtype = "R_MN10300_RELATIVE";
-+	break;
-+
-+      case EM_NDS32:
-+	rtype = "R_NDS32_RELATIVE";
-+	break;
-+
-+      case EM_OR1K:
-+	rtype = "R_OR1K_RELATIVE";
-+	break;
-+
-+      case EM_PPC:
-+	rtype = "R_PPC_RELATIVE";
-+	break;
-+
-+      case EM_PPC64:
-+	rtype = "R_PPC64_RELATIVE";
-+	break;
-+
-+      case EM_RISCV:
-+	rtype = "R_RISCV_RELATIVE";
-+	break;
-+
-+      case EM_S370:
-+	rtype = "R_I370_RELATIVE";
-+	break;
-+
-+      case EM_S390_OLD:
-+      case EM_S390:
-+	rtype = "R_390_RELATIVE";
-+	break;
-+
-+      case EM_SH:
-+	rtype = "R_SH_RELATIVE";
-+	break;
-+
-+      case EM_OLD_SPARCV9:
-+      case EM_SPARC32PLUS:
-+      case EM_SPARCV9:
-+      case EM_SPARC:
-+	rtype = "R_SPARC_RELATIVE";
-+	break;
-+
-+      case EM_TILEGX:
-+	rtype = "R_TILEGX_RELATIVE";
-+	break;
-+
-+      case EM_TILEPRO:
-+	rtype = "R_TILEPRO_RELATIVE";
-+	break;
-+
-+      case EM_V850:
-+      case EM_CYGNUS_V850:
-+	rtype = "R_V850_RELATIVE";
-+	break;
-+
-+      case EM_VAX:
-+	rtype = "R_VAX_RELATIVE";
-+	break;
-+
-+      case EM_X86_64:
-+      case EM_L1OM:
-+      case EM_K1OM:
-+	rtype = "R_X86_64_RELATIVE";
-+	break;
-+
-+      case EM_XTENSA_OLD:
-+      case EM_XTENSA:
-+	rtype = "R_XTENSA_RELATIVE";
-+	break;
-+      }
-+
-   if (symtab != NULL)
-     {
-       /* Symbol tables are not sorted on address, but we want a quick lookup
-@@ -1884,11 +2086,15 @@ dump_relr_relocations (Filedata *          filedata,
-       nsyms = filter_display_syms (filedata, symtab, nsyms, strtab, strtablen);
-     }
- 
--  if (relr_entsize == sizeof (Elf32_External_Relr))
--    printf (_ ("Index: Entry    Address   Symbolic Address\n"));
--  else
--    printf (_ ("Index: Entry            Address           Symbolic Address\n"));
-+  if (dump_reloc)
-+    {
-+      if (relr_entsize == sizeof (Elf32_External_Relr))
-+	printf (_ ("Index: Entry    Address   Symbolic Address\n"));
-+      else
-+	printf (_ ("Index: Entry            Address           Symbolic Address\n"));
-+    }
- 
-+  uint64_t r = 0;
-   for (i = 0; i < nentries; i++)
-     {
-       uint64_t entry;
-@@ -1898,16 +2104,34 @@ dump_relr_relocations (Filedata *          filedata,
-       else
- 	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
- 
--      /* We assume that there will never be more than 9999 entries.  */
--      printf (_("%04u:  "), (unsigned int) i);
--      print_vma (entry, ZERO_HEX);
--      printf (" ");
-+      if (dump_reloc)
-+	{
-+	  /* We assume that there will never be more than 9999
-+	     entries.  */
-+	  printf (_("%04u:  "), (unsigned int) i);
-+	  print_vma (entry, ZERO_HEX);
-+	  printf (" ");
-+	}
- 
-       if ((entry & 1) == 0)
- 	{
- 	  where = entry;
--	  print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, where);
--	  printf ("\n");
-+	  if (dump_reloc)
-+	    {
-+	      print_relr_addr_and_sym (filedata, symtab, nsyms, strtab,
-+				       where);
-+	      printf ("\n");
-+	    }
-+
-+	  if (do_got_section_contents)
-+	    {
-+	      all_relocations[r].r_offset = where;
-+	      all_relocations[r].r_name = rtype;
-+	      all_relocations[r].r_symbol = NULL;
-+	      all_relocations[r].r_type = reltype_relr;
-+	      r++;
-+	    }
-+
- 	  where += relr_entsize;
- 	}
-       else
-@@ -1920,7 +2144,7 @@ dump_relr_relocations (Filedata *          filedata,
- 	    /* This can actually happen when the linker is allowed to shrink
- 	       RELR sections.  For more details see: https://reviews.llvm.org/D67164. */
- 	    continue;
--	  else if (i == 0)
-+	  else if (dump_reloc && i == 0)
- 	    warn (_("Unusual RELR bitmap - no previous entry to set the base address\n"));
- 
- 	  for (j = 0; entry >>= 1; j++)
-@@ -1928,19 +2152,35 @@ dump_relr_relocations (Filedata *          filedata,
- 	      {
- 		uint64_t addr = where + (j * relr_entsize);
- 
--		if (first)
-+		if (dump_reloc)
- 		  {
--		    print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr);
--		    first = false;
-+		    if (first)
-+		      {
-+			print_relr_addr_and_sym (filedata, symtab, nsyms,
-+						 strtab, addr);
-+			first = false;
-+		      }
-+		    else
-+		      {
-+			printf (_("\n%*s "),
-+				relr_entsize == 4 ? 15 : 23, " ");
-+			print_relr_addr_and_sym (filedata, symtab, nsyms,
-+						 strtab, addr);
-+		      }
- 		  }
--		else
-+
-+		if (do_got_section_contents)
- 		  {
--		    printf (_("\n%*s "), relr_entsize == 4 ? 15 : 23, " ");
--		    print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr);
-+		    all_relocations[r].r_offset = addr;
-+		    all_relocations[r].r_name = rtype;
-+		    all_relocations[r].r_symbol = NULL;
-+		    all_relocations[r].r_type = reltype_relr;
-+		    r++;
- 		  }
- 	      }
- 
--	  printf ("\n");
-+	  if (dump_reloc)
-+	    printf ("\n");
- 	  where += num_bits_in_entry * relr_entsize;
- 	}
-     }
-@@ -1950,7 +2190,8 @@ dump_relr_relocations (Filedata *          filedata,
- }
- 
- /* Display the contents of the relocation data found at the specified
--   offset.  */
-+   offset.  If DUMP_RELOC is false, don't display relocations, just
-+   collect relocations for displaying GOT section contents later.  */
- 
- static bool
- dump_relocations (Filedata *          filedata,
-@@ -1961,7 +2202,8 @@ dump_relocations (Filedata *          filedata,
- 		  char *              strtab,
- 		  uint64_t            strtablen,
- 		  relocation_type     rel_type,
--		  bool                is_dynsym)
-+		  bool                is_dynsym,
-+		  bool                dump_reloc)
- {
-   size_t i;
-   Elf_Internal_Rela * rels;
-@@ -1986,26 +2228,26 @@ dump_relocations (Filedata *          filedata,
-       return false;
-     }
- 
--  if (is_32bit_elf)
-+  if (dump_reloc)
-     {
--      if (rel_type == reltype_rela)
--	{
--	  if (do_wide)
--	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
--	  else
--	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
--	}
--      else
-+      if (is_32bit_elf)
- 	{
--	  if (do_wide)
--	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
-+	  if (rel_type == reltype_rela)
-+	    {
-+	      if (do_wide)
-+		printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
-+	      else
-+		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
-+	    }
- 	  else
--	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
-+	    {
-+	      if (do_wide)
-+		printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
-+	      else
-+		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
-+	    }
- 	}
--    }
--  else
--    {
--      if (rel_type == reltype_rela)
-+      else if (rel_type == reltype_rela)
- 	{
- 	  if (do_wide)
- 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
-@@ -2035,18 +2277,16 @@ dump_relocations (Filedata *          filedata,
-       type = get_reloc_type (filedata, inf);
-       symtab_index = get_reloc_symindex  (inf);
- 
--      if (is_32bit_elf)
--	{
--	  printf ("%8.8lx  %8.8lx ",
--		  (unsigned long) offset & 0xffffffff,
--		  (unsigned long) inf & 0xffffffff);
--	}
--      else
-+      if (dump_reloc)
- 	{
--	  printf (do_wide
--		  ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
--		  : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
--		  offset, inf);
-+	  if (is_32bit_elf)
-+	    printf ("%8.8" PRIx32 "  %8.8" PRIx32 " ",
-+		    (uint32_t) offset, (uint32_t) inf);
-+	  else
-+	    printf (do_wide
-+		    ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
-+		    : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
-+		    offset, inf);
- 	}
- 
-       switch (filedata->file_header.e_machine)
-@@ -2396,10 +2636,15 @@ dump_relocations (Filedata *          filedata,
- 	  break;
- 	}
- 
--      if (rtype == NULL)
--	printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
--      else
--	printf (do_wide ? "%-22s" : "%-17.17s", rtype);
-+      char *symbol_name = NULL;
-+      if (dump_reloc)
-+	{
-+	  if (rtype == NULL)
-+	    printf (_("unrecognized: %-7lx"),
-+		    (unsigned long) type & 0xffffffff);
-+	  else
-+	    printf (do_wide ? "%-22s" : "%-17.17s", rtype);
-+	}
- 
-       if (filedata->file_header.e_machine == EM_ALPHA
- 	  && rtype != NULL
-@@ -2418,23 +2663,29 @@ dump_relocations (Filedata *          filedata,
- 	    default: rtype = NULL;
- 	    }
- 
--	  if (rtype)
--	    printf (" (%s)", rtype);
--	  else
-+	  if (dump_reloc)
- 	    {
--	      putchar (' ');
--	      printf (_("<unknown addend: %" PRIx64 ">"),
--		      rels[i].r_addend);
--	      res = false;
-+	      if (rtype)
-+		printf (" (%s)", rtype);
-+	      else
-+		{
-+		  putchar (' ');
-+		  printf (_("<unknown addend: %" PRIx64 ">"),
-+			  rels[i].r_addend);
-+		  res = false;
-+		}
- 	    }
- 	}
-       else if (symtab_index)
- 	{
- 	  if (symtab == NULL || symtab_index >= nsyms)
- 	    {
--	      error (_(" bad symbol index: %08lx in reloc\n"),
--		     (unsigned long) symtab_index);
--	      res = false;
-+	      if (dump_reloc)
-+		{
-+		  error (_(" bad symbol index: %08lx in reloc\n"),
-+			 (unsigned long) symtab_index);
-+		  res = false;
-+		}
- 	    }
- 	  else
- 	    {
-@@ -2453,7 +2704,8 @@ dump_relocations (Filedata *          filedata,
- 					     &sym_info,
- 					     &vna_other);
- 
--	      printf (" ");
-+	      if (dump_reloc)
-+		printf (" ");
- 
- 	      if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
- 		{
-@@ -2478,13 +2730,30 @@ dump_relocations (Filedata *          filedata,
- 		  else
- 		    name = strtab + psym->st_name;
- 
--		  len = print_symbol_name (width, name);
--		  if (version_string)
--		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
--			    version_string);
--		  printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
-+		  if (do_got_section_contents)
-+		    {
-+		      if (version_string)
-+			symbol_name = concat (name,
-+					      sym_info == symbol_public
-+					      ? "@@" : "@",
-+					      version_string, NULL);
-+		      else
-+			symbol_name = xstrdup (name);
-+		    }
-+
-+		  if (dump_reloc)
-+		    {
-+		      len = print_symbol_name (width, name);
-+		      if (version_string)
-+			printf (sym_info == symbol_public
-+				? "@@%s" : "@%s",
-+				version_string);
-+		      printf ("()%-*s",
-+			      len <= width ? (width + 1) - len : 1,
-+			      " ");
-+		    }
- 		}
--	      else
-+	      else if (dump_reloc)
- 		{
- 		  print_vma (psym->st_value, LONG_HEX);
- 
-@@ -2499,25 +2768,49 @@ dump_relocations (Filedata *          filedata,
- 		    sec_name = printable_section_name_from_index
- 		      (filedata, psym->st_shndx, NULL);
- 
--		  print_symbol_name (22, sec_name);
-+		  if (do_got_section_contents)
-+		    symbol_name = xstrdup (sec_name);
-+		  if (dump_reloc)
-+		    print_symbol_name (22, sec_name);
- 		}
- 	      else if (strtab == NULL)
--		printf (_("<string table index: %3ld>"), psym->st_name);
-+		{
-+		  if (dump_reloc)
-+		    printf (_("<string table index: %3ld>"),
-+			    psym->st_name);
-+		}
- 	      else if (psym->st_name >= strtablen)
- 		{
--		  error (_("<corrupt string table index: %3ld>\n"),
--			 psym->st_name);
--		  res = false;
-+		  if (dump_reloc)
-+		    {
-+		      error (_("<corrupt string table index: %3ld>\n"),
-+			     psym->st_name);
-+		      res = false;
-+		    }
- 		}
- 	      else
- 		{
--		  print_symbol_name (22, strtab + psym->st_name);
--		  if (version_string)
--		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
--			    version_string);
-+		  if (dump_reloc)
-+		    {
-+		      print_symbol_name (22, strtab + psym->st_name);
-+		      if (version_string)
-+			printf (sym_info == symbol_public
-+				? "@@%s" : "@%s",
-+				version_string);
-+		    }
-+		  if (do_got_section_contents)
-+		    {
-+		      if (version_string)
-+			symbol_name = concat (strtab + psym->st_name,
-+					      sym_info == symbol_public
-+					      ? "@@" : "@",
-+					      version_string, NULL);
-+		      else
-+			symbol_name = xstrdup (strtab + psym->st_name);
-+		    }
- 		}
- 
--	      if (rel_type == reltype_rela)
-+	      if (dump_reloc && rel_type == reltype_rela)
- 		{
- 		  uint64_t off = rels[i].r_addend;
- 
-@@ -2528,7 +2821,7 @@ dump_relocations (Filedata *          filedata,
- 		}
- 	    }
- 	}
--      else if (rel_type == reltype_rela)
-+      else if (dump_reloc && rel_type == reltype_rela)
- 	{
- 	  uint64_t off = rels[i].r_addend;
- 
-@@ -2539,37 +2832,50 @@ dump_relocations (Filedata *          filedata,
- 	    printf ("%" PRIx64, off);
- 	}
- 
--      if (filedata->file_header.e_machine == EM_SPARCV9
--	  && rtype != NULL
--	  && streq (rtype, "R_SPARC_OLO10"))
--	printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf));
--
--      putchar ('\n');
-+      if (do_got_section_contents)
-+	{
-+	  all_relocations[i].r_offset = offset;
-+	  all_relocations[i].r_name = rtype;
-+	  all_relocations[i].r_symbol = symbol_name;
-+	  all_relocations[i].r_addend = rels[i].r_addend;
-+	  all_relocations[i].r_type = rel_type;
-+	}
- 
--      if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
-+      if (dump_reloc)
- 	{
--	  uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf);
--	  uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf);
--	  const char * rtype2 = elf_mips_reloc_type (type2);
--	  const char * rtype3 = elf_mips_reloc_type (type3);
-+	  if (filedata->file_header.e_machine == EM_SPARCV9
-+	      && rtype != NULL
-+	      && streq (rtype, "R_SPARC_OLO10"))
-+	    printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf));
- 
--	  printf ("                    Type2: ");
-+	  putchar ('\n');
- 
--	  if (rtype2 == NULL)
--	    printf (_("unrecognized: %-7lx"),
--		    (unsigned long) type2 & 0xffffffff);
--	  else
--	    printf ("%-17.17s", rtype2);
-+	  if (! is_32bit_elf
-+	      && filedata->file_header.e_machine == EM_MIPS)
-+	    {
-+	      uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf);
-+	      uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf);
-+	      const char * rtype2 = elf_mips_reloc_type (type2);
-+	      const char * rtype3 = elf_mips_reloc_type (type3);
- 
--	  printf ("\n                    Type3: ");
-+	      printf ("                    Type2: ");
- 
--	  if (rtype3 == NULL)
--	    printf (_("unrecognized: %-7lx"),
--		    (unsigned long) type3 & 0xffffffff);
--	  else
--	    printf ("%-17.17s", rtype3);
-+	      if (rtype2 == NULL)
-+		printf (_("unrecognized: %-7lx"),
-+			(unsigned long) type2 & 0xffffffff);
-+	      else
-+		printf ("%-17.17s", rtype2);
- 
--	  putchar ('\n');
-+	      printf ("\n                    Type3: ");
-+
-+	      if (rtype3 == NULL)
-+		printf (_("unrecognized: %-7lx"),
-+			(unsigned long) type3 & 0xffffffff);
-+	      else
-+		printf ("%-17.17s", rtype3);
-+
-+	      putchar ('\n');
-+	    }
- 	}
-     }
- 
-@@ -6097,7 +6403,8 @@ enum long_option_values
-   OPTION_NO_RECURSE_LIMIT,
-   OPTION_NO_DEMANGLING,
-   OPTION_NO_EXTRA_SYM_INFO,
--  OPTION_SYM_BASE
-+  OPTION_SYM_BASE,
-+  OPTION_GOT_CONTENTS
- };
- 
- static struct option options[] =
-@@ -6160,6 +6467,7 @@ static struct option options[] =
- #endif
-   {"sframe",	       optional_argument, 0, OPTION_SFRAME_DUMP},
-   {"sym-base",	       optional_argument, 0, OPTION_SYM_BASE},
-+  {"got-contents",     no_argument, 0, OPTION_GOT_CONTENTS},
- 
-   {0,		       no_argument, 0, 0}
- };
-@@ -6171,7 +6479,7 @@ usage (FILE * stream)
-   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
-   fprintf (stream, _(" Options are:\n"));
-   fprintf (stream, _("\
--  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
-+  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I --got-contents\n"));
-   fprintf (stream, _("\
-   -h --file-header       Display the ELF file header\n"));
-   fprintf (stream, _("\
-@@ -6317,6 +6625,8 @@ usage (FILE * stream)
-   fprintf (stream, _("\
-   -I --histogram         Display histogram of bucket list lengths\n"));
-   fprintf (stream, _("\
-+  --got-contents         Display GOT section contents\n"));
-+  fprintf (stream, _("\
-   -W --wide              Allow output width to exceed 80 characters\n"));
-   fprintf (stream, _("\
-   -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
-@@ -6441,6 +6751,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
- 	  do_histogram = true;
- 	  do_arch = true;
- 	  do_notes = true;
-+	  do_got_section_contents = true;
- 	  break;
- 
- 	case 'g':
-@@ -6700,6 +7011,11 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
- 	    }
- 	  break;
- 
-+	case OPTION_GOT_CONTENTS:
-+	  do_got_section_contents = true;
-+	  do_dump = true;
-+	  break;
-+
- 	default:
- 	  /* xgettext:c-format */
- 	  error (_("Invalid option '-%c'\n"), c);
-@@ -9437,7 +9753,8 @@ rel_type_from_sh_type (unsigned int sh_type)
- 
- static bool
- display_relocations (Elf_Internal_Shdr *  section,
--		     Filedata *           filedata)
-+		     Filedata *           filedata,
-+		     bool                 dump_reloc)
- {
-   relocation_type rel_type = rel_type_from_sh_type (section->sh_type);
- 
-@@ -9449,19 +9766,23 @@ display_relocations (Elf_Internal_Shdr *  section,
-   if (rel_size == 0)
-     return false;
- 
--  if (filedata->is_separate)
--    printf (_("\nIn linked file '%s' relocation section "),
--	    printable_string (filedata->file_name, 0));
--  else
--    printf (_("\nRelocation section "));
-+  if (dump_reloc)
-+    {
-+      if (filedata->is_separate)
-+	printf (_("\nIn linked file '%s' relocation section "),
-+		printable_string (filedata->file_name, 0));
-+      else
-+	printf (_("\nRelocation section "));
- 
--  if (filedata->string_table == NULL)
--    printf ("%d", section->sh_name);
--  else
--    printf ("'%s'", printable_section_name (filedata, section));
-+      if (filedata->string_table == NULL)
-+	printf ("%d", section->sh_name);
-+      else
-+	printf ("'%s'", printable_section_name (filedata, section));
-+    }
- 
--  uint64_t num_rela = rel_size / section->sh_entsize;
-   uint64_t rel_offset = section->sh_offset;
-+  uint64_t num_rela = rel_size / section->sh_entsize;
-+  uint64_t num_reloc;
- 
-   if (rel_type == reltype_relr)
-     {
-@@ -9470,26 +9791,33 @@ display_relocations (Elf_Internal_Shdr *  section,
- 	 the number of words in the compressed RELR format.  So also provide
- 	 the number of locations affected.  */
- 
--      uint64_t num_reloc = count_relr_relocations (filedata, section);
-+      num_reloc = count_relr_relocations (filedata, section);
- 
--      printf (_(" at offset %#" PRIx64), rel_offset);
--      printf (ngettext (" contains %" PRIu64 " entry which relocates",
--			" contains %" PRIu64 " entries which relocate",
--			num_rela), num_rela);
--      printf (ngettext (" %" PRIu64 " location:\n",
--			" %" PRIu64 " locations:\n",
--			num_reloc), num_reloc);
-+      if (dump_reloc)
-+	{
-+	  printf (_(" at offset %#" PRIx64), rel_offset);
-+	  printf (ngettext (" contains %" PRIu64 " entry which relocates",
-+			    " contains %" PRIu64 " entries which relocate",
-+			    num_rela), num_rela);
-+	  printf (ngettext (" %" PRIu64 " location:\n",
-+			    " %" PRIu64 " locations:\n",
-+			    num_reloc), num_reloc);
-+	}
-     }
-   else
-     {
--      printf (ngettext (" at offset %#" PRIx64
--			" contains %" PRIu64 " entry:\n",
--			" at offset %#" PRIx64
--			" contains %" PRIu64 " entries:\n",
--			num_rela),
--	      rel_offset, num_rela);
-+      num_reloc = num_rela;
-+      if (dump_reloc)
-+	printf (ngettext (" at offset %#" PRIx64
-+			  " contains %" PRIu64 " entry:\n",
-+			  " at offset %#" PRIx64
-+			  " contains %" PRIu64 " entries:\n",
-+			  num_rela),
-+		rel_offset, num_rela);
-     }
- 
-+  update_all_relocations (num_reloc);
-+
-   Elf_Internal_Shdr * symsec;
-   Elf_Internal_Sym *  symtab = NULL;
-   uint64_t            nsyms = 0;
-@@ -9524,12 +9852,15 @@ display_relocations (Elf_Internal_Shdr *  section,
-     res = dump_relr_relocations (filedata, section->sh_size,
- 				 section->sh_entsize,
- 				 section->sh_offset,
--				 symtab, nsyms, strtab, strtablen);
-+				 symtab, nsyms, strtab, strtablen,
-+				 dump_reloc);
-   else
-     res = dump_relocations (filedata, rel_offset, rel_size,
- 			    symtab, nsyms, strtab, strtablen,
- 			    rel_type,
--			    symsec == NULL ? false : symsec->sh_type == SHT_DYNSYM);
-+			    symsec == NULL
-+			    ? false : symsec->sh_type == SHT_DYNSYM,
-+			    dump_reloc);
-   free (strtab);
-   free (symtab);
- 
-@@ -9543,14 +9874,16 @@ process_relocs (Filedata * filedata)
- {
-   uint64_t rel_size;
-   uint64_t rel_offset;
-+  unsigned int rel_entsz;
- 
--  if (!do_reloc)
-+  if (!do_reloc && !do_got_section_contents)
-     return true;
- 
-   if (do_using_dynamic)
-     {
-       relocation_type rel_type;
-       const char * name;
-+      const char * entsz_name;
-       bool  has_dynamic_reloc;
-       unsigned int i;
- 
-@@ -9584,16 +9917,37 @@ process_relocs (Filedata * filedata)
- 		}
- 	    }
- 
--	  if (filedata->is_separate)
--	    printf
--	      (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
--		 " contains %" PRId64 " bytes:\n"),
--	       filedata->file_name, name, rel_offset, rel_size);
--	  else
--	    printf
--	      (_("\n'%s' relocation section at offset %#" PRIx64
--		 " contains %" PRId64 " bytes:\n"),
--	       name, rel_offset, rel_size);
-+	  switch (rel_type)
-+	    {
-+	    default:
-+	      abort ();
-+	    case reltype_rel:
-+	      rel_entsz = filedata->dynamic_info[DT_RELENT];
-+	      entsz_name = "DT_RELENT";
-+	      break;
-+	    case reltype_rela:
-+	      rel_entsz = filedata->dynamic_info[DT_RELAENT];
-+	      entsz_name = "DT_RELAENT";
-+	      break;
-+	    case reltype_relr:
-+	      rel_entsz = filedata->dynamic_info[DT_RELRENT];
-+	      entsz_name = "DT_RELRENT";
-+	      break;
-+	    }
-+
-+	  if (do_reloc)
-+	    {
-+	      if (filedata->is_separate)
-+		printf
-+		  (_("\nIn linked file '%s' section '%s' at offset"
-+		     "%#" PRIx64 " contains %" PRId64 " bytes:\n"),
-+		   filedata->file_name, name, rel_offset, rel_size);
-+	      else
-+		printf
-+		  (_("\n'%s' relocation section at offset %#" PRIx64
-+		     " contains %" PRId64 " bytes:\n"),
-+		   name, rel_offset, rel_size);
-+	    }
- 
- 	  if (rel_type == reltype_relr)
- 	    dump_relr_relocations (filedata,
-@@ -9603,24 +9957,37 @@ process_relocs (Filedata * filedata)
- 				   filedata->dynamic_symbols,
- 				   filedata->num_dynamic_syms,
- 				   filedata->dynamic_strings,
--				   filedata->dynamic_strings_length);
-+				   filedata->dynamic_strings_length,
-+				   do_reloc);
- 	  else
--	    dump_relocations (filedata,
--			      offset_from_vma (filedata, rel_offset,
--					       rel_size),
--			      rel_size,
--			      filedata->dynamic_symbols,
--			      filedata->num_dynamic_syms,
--			      filedata->dynamic_strings,
--			      filedata->dynamic_strings_length,
--			      rel_type, true /* is_dynamic */);
-+	    {
-+	      if (rel_entsz == 0)
-+		{
-+		  printf (_("<missing or corrupt dynamic tag: %s>\n"),
-+			  entsz_name);
-+		  continue;
-+		}
-+
-+	      update_all_relocations (rel_size / rel_entsz);
-+
-+	      dump_relocations (filedata,
-+				offset_from_vma (filedata, rel_offset,
-+						 rel_size),
-+				rel_size,
-+				filedata->dynamic_symbols,
-+				filedata->num_dynamic_syms,
-+				filedata->dynamic_strings,
-+				filedata->dynamic_strings_length,
-+				rel_type, true /* is_dynamic */,
-+				do_reloc);
-+	    }
- 	}
- 
-       if (is_ia64_vms (filedata)
- 	  && process_ia64_vms_dynamic_relocs (filedata))
- 	has_dynamic_reloc = true;
- 
--      if (! has_dynamic_reloc)
-+      if (do_reloc && ! has_dynamic_reloc)
- 	{
- 	  if (filedata->is_separate)
- 	    printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
-@@ -9639,11 +10006,11 @@ process_relocs (Filedata * filedata)
- 	   i < filedata->file_header.e_shnum;
- 	   i++, section++)
- 	{
--	  if (display_relocations (section, filedata))
-+	  if (display_relocations (section, filedata, do_reloc))
- 	    found = true;
- 	}
- 
--      if (! found)
-+      if (do_reloc && ! found)
- 	{
- 	  /* Users sometimes forget the -D option, so try to be helpful.  */
- 	  for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
-@@ -17627,7 +17994,7 @@ process_section_contents (Filedata * filedata)
- 	    case SHT_RELA:
- 	    case SHT_REL:
- 	    case SHT_RELR:
--	      res &= display_relocations (section, filedata);
-+	      res &= display_relocations (section, filedata, true);
- 	      break;
- 
- 	    case SHT_NOTE:
-@@ -19644,8 +20011,11 @@ get_mips_reg_size (int reg_size)
- 	 : -1;
- }
- 
-+/* If DUMP_GOT is true, display only the GOT related contents.
-+   Otherwise, display all MIPS specific information.  */
-+
- static bool
--process_mips_specific (Filedata * filedata)
-+process_mips_specific (Filedata * filedata, bool dump_got)
- {
-   Elf_Internal_Dyn * entry;
-   Elf_Internal_Shdr *sect = NULL;
-@@ -19664,60 +20034,63 @@ process_mips_specific (Filedata * filedata)
-   uint64_t symtabno = 0;
-   bool res = true;
- 
--  if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
--			    display_mips_gnu_attribute))
--    res = false;
--
--  sect = find_section (filedata, ".MIPS.abiflags");
--
--  if (sect != NULL)
-+  if (!dump_got)
-     {
--      Elf_External_ABIFlags_v0 *abiflags_ext;
--      Elf_Internal_ABIFlags_v0 abiflags_in;
-+      if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
-+				display_mips_gnu_attribute))
-+	res = false;
- 
--      if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
--	{
--	  error (_("Corrupt MIPS ABI Flags section.\n"));
--	  res = false;
--	}
--      else
-+      sect = find_section (filedata, ".MIPS.abiflags");
-+
-+      if (sect != NULL)
- 	{
--	  abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
--				   sect->sh_size, _("MIPS ABI Flags section"));
--	  if (abiflags_ext)
-+	  Elf_External_ABIFlags_v0 *abiflags_ext;
-+	  Elf_Internal_ABIFlags_v0 abiflags_in;
-+
-+	  if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
- 	    {
--	      abiflags_in.version = BYTE_GET (abiflags_ext->version);
--	      abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
--	      abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
--	      abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
--	      abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
--	      abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
--	      abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
--	      abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
--	      abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
--	      abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
--	      abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
--
--	      printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
--	      printf ("\nISA: MIPS%d", abiflags_in.isa_level);
--	      if (abiflags_in.isa_rev > 1)
--		printf ("r%d", abiflags_in.isa_rev);
--	      printf ("\nGPR size: %d",
--		      get_mips_reg_size (abiflags_in.gpr_size));
--	      printf ("\nCPR1 size: %d",
--		      get_mips_reg_size (abiflags_in.cpr1_size));
--	      printf ("\nCPR2 size: %d",
--		      get_mips_reg_size (abiflags_in.cpr2_size));
--	      fputs ("\nFP ABI: ", stdout);
--	      print_mips_fp_abi_value (abiflags_in.fp_abi);
--	      fputs ("ISA Extension: ", stdout);
--	      print_mips_isa_ext (abiflags_in.isa_ext);
--	      fputs ("\nASEs:", stdout);
--	      print_mips_ases (abiflags_in.ases);
--	      printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
--	      printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
--	      fputc ('\n', stdout);
--	      free (abiflags_ext);
-+	      error (_("Corrupt MIPS ABI Flags section.\n"));
-+	      res = false;
-+	    }
-+	  else
-+	    {
-+	      abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
-+				       sect->sh_size, _("MIPS ABI Flags section"));
-+	      if (abiflags_ext)
-+		{
-+		  abiflags_in.version = BYTE_GET (abiflags_ext->version);
-+		  abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
-+		  abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
-+		  abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
-+		  abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
-+		  abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
-+		  abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
-+		  abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
-+		  abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
-+		  abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
-+		  abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
-+
-+		  printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
-+		  printf ("\nISA: MIPS%d", abiflags_in.isa_level);
-+		  if (abiflags_in.isa_rev > 1)
-+		    printf ("r%d", abiflags_in.isa_rev);
-+		  printf ("\nGPR size: %d",
-+			  get_mips_reg_size (abiflags_in.gpr_size));
-+		  printf ("\nCPR1 size: %d",
-+			  get_mips_reg_size (abiflags_in.cpr1_size));
-+		  printf ("\nCPR2 size: %d",
-+			  get_mips_reg_size (abiflags_in.cpr2_size));
-+		  fputs ("\nFP ABI: ", stdout);
-+		  print_mips_fp_abi_value (abiflags_in.fp_abi);
-+		  fputs ("ISA Extension: ", stdout);
-+		  print_mips_isa_ext (abiflags_in.isa_ext);
-+		  fputs ("\nASEs:", stdout);
-+		  print_mips_ases (abiflags_in.ases);
-+		  printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
-+		  printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
-+		  fputc ('\n', stdout);
-+		  free (abiflags_ext);
-+		}
- 	    }
- 	}
-     }
-@@ -19865,7 +20238,7 @@ process_mips_specific (Filedata * filedata)
- 	break;
-       }
- 
--  if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
-+  if (!dump_got && liblist_offset != 0 && liblistno != 0 && do_dynamic)
-     {
-       Elf32_External_Lib * elib;
-       size_t cnt;
-@@ -19950,7 +20323,7 @@ process_mips_specific (Filedata * filedata)
- 	res = false;
-     }
- 
--  if (options_offset != 0)
-+  if (!dump_got && options_offset != 0)
-     {
-       Elf_External_Options * eopt;
-       size_t offset;
-@@ -20199,7 +20572,7 @@ process_mips_specific (Filedata * filedata)
- 	res = false;
-     }
- 
--  if (conflicts_offset != 0 && conflictsno != 0)
-+  if (!dump_got && conflicts_offset != 0 && conflictsno != 0)
-     {
-       Elf32_Conflict * iconf;
-       size_t cnt;
-@@ -20558,6 +20931,206 @@ process_nds32_specific (Filedata * filedata)
-   return true;
- }
- 
-+static int
-+elf_relocation_cmp (const void *p, const void *q)
-+{
-+  const elf_relocation *rp = (const elf_relocation *) p;
-+  const elf_relocation *rq = (const elf_relocation *) q;
-+
-+  return (rp->r_offset > rq->r_offset
-+	  ? 1
-+	  : (rp->r_offset < rq->r_offset ? -1 : 0));
-+}
-+
-+static void
-+display_elf_relocation_at (uint64_t offset, uint64_t g)
-+{
-+  bool matched = false;
-+
-+  for (size_t i = 0; i < all_relocations_count; i++)
-+    if (all_relocations_root[i].r_offset == offset)
-+      {
-+	if (do_wide)
-+	  printf (" %-22s", all_relocations_root[i].r_name);
-+	else
-+	  printf (" %-17.17s", all_relocations_root[i].r_name);
-+
-+	uint64_t off;
-+	switch (all_relocations_root[i].r_type)
-+	  {
-+	  default:
-+	    abort ();
-+	  case reltype_rel:
-+	  case reltype_relr:
-+	    off = g;
-+	    break;
-+	  case reltype_rela:
-+	    off = all_relocations_root[i].r_addend;
-+	    break;
-+	  }
-+
-+	if (all_relocations_root[i].r_symbol)
-+	  {
-+	    printf (" %s", all_relocations_root[i].r_symbol);
-+	    if ((int64_t) off < 0)
-+	      printf (" - %" PRIx64, -off);
-+	    else
-+	      printf (" + %" PRIx64, off);
-+	  }
-+	else
-+	  {
-+	    if ((int64_t) off < 0)
-+	      printf (" -%" PRIx64, -off);
-+	    else
-+	      printf (" %" PRIx64, off);
-+	  }
-+
-+	matched = true;
-+	break;
-+      }
-+    else if (all_relocations_root[i].r_offset > offset)
-+      break;
-+
-+  if (!matched)
-+    {
-+      if (do_wide)
-+	printf ("%*c", 24, ' ');
-+      else
-+	printf ("%*c", 19, ' ');
-+      printf ("%" PRIx64, g);
-+    }
-+}
-+
-+static bool
-+process_got_section_contents (Filedata * filedata)
-+{
-+  Elf_Internal_Shdr * section;
-+  unsigned int i;
-+  uint64_t entries;
-+  unsigned char *data;
-+  bool res = true;
-+
-+  if (!do_got_section_contents)
-+    return res;
-+
-+  switch (filedata->file_header.e_machine)
-+    {
-+    case EM_MIPS:
-+    case EM_MIPS_RS3_LE:
-+      /* process_mips_specific also displays GOT related contents.  */
-+      if (!do_arch)
-+	res = process_mips_specific (filedata, true);
-+      goto out;
-+    }
-+
-+  qsort (all_relocations_root, all_relocations_count,
-+	 sizeof (elf_relocation), elf_relocation_cmp);
-+
-+  initialise_dumps_byname (filedata);
-+
-+  for (i = 0, section = filedata->section_headers;
-+       i < filedata->file_header.e_shnum;
-+       i++, section++)
-+    if (section->sh_type == SHT_PROGBITS
-+	&& section->sh_size != 0)
-+      {
-+	const char *name = printable_section_name (filedata, section);
-+
-+	if (!startswith (name, ".got"))
-+	  continue;
-+
-+	data = (unsigned char *) get_section_contents (section,
-+						       filedata);
-+	if (data == NULL)
-+	  {
-+	    res = false;
-+	    goto out;
-+	  }
-+
-+	uint32_t entsz = section->sh_entsize;
-+	entries = section->sh_size / entsz;
-+	if (entries == 1)
-+	  printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),
-+		  name);
-+	else
-+	  printf (_("\nGlobal Offset Table '%s' contains %" PRIu64
-+		    " entries:\n"), name, entries);
-+
-+	uint64_t g;
-+
-+	if (is_32bit_elf)
-+	  {
-+	    uint32_t j, n = entries;
-+	    uint32_t addr;
-+	    struct got32
-+	      {
-+		unsigned char bytes[4];
-+	      } *got;
-+
-+	    if (do_wide)
-+	      printf (_("   Index:  Address      Reloc             Sym. Name + Addend/Value\n"));
-+		      /* |---9---| |---8--| |---------22---------| |...........  */
-+	    else
-+	      printf (_(" Index:  Address      Reloc        Sym. Name + Addend/Value\n"));
-+		    /* |--7--| |---8--| |-------17------| |...........  */
-+
-+	    addr = section->sh_addr;
-+	    got = (struct got32 *) data;
-+	    for (j = 0; j < n; j++)
-+	      {
-+		g = BYTE_GET (got[j].bytes);
-+		if (do_wide)
-+		  printf ("%8" PRIu32 ": %8.8" PRIx32, j, addr);
-+		else
-+		  printf ("%6" PRIu32 ": %8.8" PRIx32, j, addr);
-+		display_elf_relocation_at (addr, g);
-+		putchar ('\n');
-+		addr += entsz;
-+	      }
-+	  }
-+	else
-+	  {
-+	    uint64_t j, addr;
-+	    struct got64
-+	      {
-+		unsigned char bytes[4];
-+	      } *got;
-+
-+	    if (do_wide)
-+	      printf (_("   Index:      Address          Reloc             Sym. Name + Addend/Value\n"));
-+		      /* |---9---| |------16------| |---------22---------| |...........  */
-+	    else
-+	      printf (_(" Index:    Address       Reloc         Sym. Name + Addend/Value\n"));
-+		      /* |--7--| |----12----| |------17-------| |...........  */
-+
-+	    addr = section->sh_addr;
-+	    got = (struct got64 *) data;
-+	    for (j = 0; j < entries; j++)
-+	      {
-+		g = BYTE_GET (got[j].bytes);
-+		if (do_wide)
-+		  printf ("%8" PRIu64 ": %16.16" PRIx64, j, addr);
-+		else
-+		  printf ("%6" PRIu64 ": %12.12" PRIx64, j, addr);
-+		display_elf_relocation_at (addr, g);
-+		putchar ('\n');
-+		addr += entsz;
-+	      }
-+	  }
-+
-+	free (data);
-+      }
-+
-+ out:
-+  for (size_t j = 0; j < all_relocations_count; j++)
-+    free (all_relocations_root[j].r_symbol);
-+  free (all_relocations_root);
-+  all_relocations_root = NULL;
-+  all_relocations = NULL;
-+  all_relocations_count = 0;
-+  return res;
-+}
-+
- static bool
- process_gnu_liblist (Filedata * filedata)
- {
-@@ -23469,7 +24042,7 @@ process_arch_specific (Filedata * filedata)
- 
-     case EM_MIPS:
-     case EM_MIPS_RS3_LE:
--      return process_mips_specific (filedata);
-+      return process_mips_specific (filedata, false);
- 
-     case EM_MSP430:
-      return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
-@@ -23833,6 +24406,9 @@ process_object (Filedata * filedata)
-   if (! process_section_contents (filedata))
-     res = false;
- 
-+  if (! process_got_section_contents (filedata))
-+    res = false;
-+
-   if (have_separate_files)
-     {
-       separate_info * d;
-diff --git a/ld/testsuite/ld-i386/binutils.exp b/ld/testsuite/ld-i386/binutils.exp
-new file mode 100644
-index 00000000000..5069c59ca9e
---- /dev/null
-+++ b/ld/testsuite/ld-i386/binutils.exp
-@@ -0,0 +1,45 @@
-+# Expect script for ELF/i386 binutils tests on linker outputs.
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-+# MA 02110-1301, USA.
-+#
-+
-+if ![is_elf_format] {
-+    return
-+}
-+
-+if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
-+    return
-+}
-+
-+run_ld_link_tests [list \
-+    [list \
-+	"Build libgot-1.so" \
-+	"-shared -melf_i386 --no-ld-generated-unwind-info \
-+	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
-+	 $NO_DT_RELR_LDFLAGS" \
-+	"" \
-+	"--32 -mx86-used-note=no --generate-missing-build-notes=no" \
-+	{got-1.s} \
-+	{{readelf -rW libgot-1a.rd} \
-+	 {readelf -aW libgot-1b.rd} \
-+	 {readelf --got-contents libgot-1c.rd} \
-+	 {readelf {--got-contents -W} libgot-1d.rd}} \
-+	"libgot-1.so" \
-+    ] \
-+]
-diff --git a/ld/testsuite/ld-i386/got-1.s b/ld/testsuite/ld-i386/got-1.s
-new file mode 100644
-index 00000000000..30e45f9be43
---- /dev/null
-+++ b/ld/testsuite/ld-i386/got-1.s
-@@ -0,0 +1,7 @@
-+	.text
-+	.globl	func
-+	.type	func, @function
-+func:
-+	call	*foo@GOT(%ebx)
-+	jmp	bar@PLT
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-i386/libgot-1a.rd b/ld/testsuite/ld-i386/libgot-1a.rd
-new file mode 100644
-index 00000000000..b8609b8fbe2
---- /dev/null
-+++ b/ld/testsuite/ld-i386/libgot-1a.rd
-@@ -0,0 +1,9 @@
-+
-+Relocation section '.rel.dyn' at offset 0x128 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name
-+0+2001fc  00000206 R_386_GLOB_DAT         00000000   foo
-+
-+Relocation section '.rel.plt' at offset 0x130 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name
-+0+20020c  00000307 R_386_JUMP_SLOT        00000000   bar
-+#pass
-diff --git a/ld/testsuite/ld-i386/libgot-1b.rd b/ld/testsuite/ld-i386/libgot-1b.rd
-new file mode 100644
-index 00000000000..faebdb49e0d
---- /dev/null
-+++ b/ld/testsuite/ld-i386/libgot-1b.rd
-@@ -0,0 +1,119 @@
-+ELF Header:
-+  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
-+  Class:                             ELF32
-+  Data:                              2's complement, little endian
-+  Version:                           1 \(current\)
-+  OS/ABI:                            UNIX - System V
-+  ABI Version:                       0
-+  Type:                              DYN \(Shared object file\)
-+  Machine:                           Intel 80386
-+  Version:                           0x1
-+  Entry point address:               0x0
-+  Start of program headers:          52 \(bytes into file\)
-+  Start of section headers:          768 \(bytes into file\)
-+  Flags:                             0x0
-+  Size of this header:               52 \(bytes\)
-+  Size of program headers:           32 \(bytes\)
-+  Number of program headers:         4
-+  Size of section headers:           40 \(bytes\)
-+  Number of section headers:         14
-+  Section header string table index: 13
-+
-+Section Headers:
-+  \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
-+  \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
-+  \[ 1\] .hash             HASH            000000b4 0000b4 000024 04   A  2   0  4
-+  \[ 2\] .dynsym           DYNSYM          000000d8 0000d8 000040 10   A  3   1  4
-+  \[ 3\] .dynstr           STRTAB          00000118 000118 00000e 00   A  0   0  1
-+  \[ 4\] .rel.dyn          REL             00000128 000128 000008 08   A  2   0  4
-+  \[ 5\] .rel.plt          REL             00000130 000130 000008 08  AI  2  10  4
-+  \[ 6\] .plt              PROGBITS        00000140 000140 000020 04  AX  0   0 16
-+  \[ 7\] .text             PROGBITS        00000160 000160 00000b 00  AX  0   0  1
-+  \[ 8\] .dynamic          DYNAMIC         0020016c 00016c 000090 08  WA  3   0  4
-+  \[ 9\] .got              PROGBITS        002001fc 0001fc 000004 04  WA  0   0  4
-+  \[10\] .got.plt          PROGBITS        00200200 000200 000010 04  WA  0   0  4
-+  \[11\] .symtab           SYMTAB          00000000 000210 000060 10     12   3  4
-+  \[12\] .strtab           STRTAB          00000000 000270 00002d 00      0   0  1
-+  \[13\] .shstrtab         STRTAB          00000000 00029d 000060 00      0   0  1
-+Key to Flags:
-+  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
-+  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
-+  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
-+  D \(mbind\), p \(processor specific\)
-+
-+There are no section groups in this file.
-+
-+Program Headers:
-+  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
-+  LOAD           0x000000 0x00000000 0x00000000 0x0016b 0x0016b R E 0x200000
-+  LOAD           0x00016c 0x0020016c 0x0020016c 0x000a4 0x000a4 RW  0x200000
-+  DYNAMIC        0x00016c 0x0020016c 0x0020016c 0x00090 0x00090 RW  0x4
-+  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
-+
-+ Section to Segment mapping:
-+  Segment Sections...
-+   00     .hash .dynsym .dynstr .rel.dyn .rel.plt .plt .text 
-+   01     .dynamic .got .got.plt 
-+   02     .dynamic 
-+   03     
-+
-+Dynamic section at offset 0x16c contains 13 entries:
-+  Tag        Type                         Name/Value
-+ 0x00000004 \(HASH\)                       0xb4
-+ 0x00000005 \(STRTAB\)                     0x118
-+ 0x00000006 \(SYMTAB\)                     0xd8
-+ 0x0000000a \(STRSZ\)                      14 \(bytes\)
-+ 0x0000000b \(SYMENT\)                     16 \(bytes\)
-+ 0x00000003 \(PLTGOT\)                     0x200200
-+ 0x00000002 \(PLTRELSZ\)                   8 \(bytes\)
-+ 0x00000014 \(PLTREL\)                     REL
-+ 0x00000017 \(JMPREL\)                     0x130
-+ 0x00000011 \(REL\)                        0x128
-+ 0x00000012 \(RELSZ\)                      8 \(bytes\)
-+ 0x00000013 \(RELENT\)                     8 \(bytes\)
-+ 0x00000000 \(NULL\)                       0x0
-+
-+Relocation section '.rel.dyn' at offset 0x128 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name
-+0+2001fc  00000206 R_386_GLOB_DAT         00000000   foo
-+
-+Relocation section '.rel.plt' at offset 0x130 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name
-+0+20020c  00000307 R_386_JUMP_SLOT        00000000   bar
-+No processor specific unwind information to decode
-+
-+Symbol table '.dynsym' contains 4 entries:
-+   Num:    Value  Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Symbol table '.symtab' contains 6 entries:
-+   Num:    Value  Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 0020016c     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
-+ +[a-f0-9]+: 00200200     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
-+ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Histogram for bucket list length \(total of 3 buckets\):
-+ Length  Number     % of total  Coverage
-+      0  1          \( 33.3%\)
-+      1  1          \( 33.3%\)     33.3%
-+      2  1          \( 33.3%\)    100.0%
-+
-+No version information found in this file.
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200                        20016c
-+ +[0-9]+: 00200204                        0
-+ +[0-9]+: 00200208                        0
-+ +[0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
-+#pass
-diff --git a/ld/testsuite/ld-i386/libgot-1c.rd b/ld/testsuite/ld-i386/libgot-1c.rd
-new file mode 100644
-index 00000000000..374b03f1658
---- /dev/null
-+++ b/ld/testsuite/ld-i386/libgot-1c.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+ Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[0-9]+: 002001fc R_386_GLOB_DAT    foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+ Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200                   20016c
-+ +[0-9]+: 00200204                   0
-+ +[0-9]+: 00200208                   0
-+ +[0-9]+: 0020020c R_386_JUMP_SLOT   bar \+ 156
-+#pass
-diff --git a/ld/testsuite/ld-i386/libgot-1d.rd b/ld/testsuite/ld-i386/libgot-1d.rd
-new file mode 100644
-index 00000000000..632b47be743
---- /dev/null
-+++ b/ld/testsuite/ld-i386/libgot-1d.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200                        20016c
-+ +[0-9]+: 00200204                        0
-+ +[0-9]+: 00200208                        0
-+ +[0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/binutils.exp b/ld/testsuite/ld-x86-64/binutils.exp
-new file mode 100644
-index 00000000000..fef997368db
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/binutils.exp
-@@ -0,0 +1,59 @@
-+# Expect script for ELF/x86-64 binutils tests on linker outputs.
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-+# MA 02110-1301, USA.
-+#
-+
-+if ![is_elf_format] {
-+    return
-+}
-+
-+if { ![istarget "x86_64-*-*"] } {
-+    return
-+}
-+
-+run_ld_link_tests [list \
-+    [list \
-+	"Build libgot-1.so" \
-+	"-shared -melf_x86_64 --no-ld-generated-unwind-info \
-+	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
-+	 -z nomark-plt $NO_DT_RELR_LDFLAGS" \
-+	"" \
-+	"--64 -mx86-used-note=no --generate-missing-build-notes=no" \
-+	{got-1.s} \
-+	{{readelf -rW libgot-1a.rd} \
-+	 {readelf -aW libgot-1b.rd} \
-+	 {readelf --got-contents libgot-1c.rd} \
-+	 {readelf {--got-contents -W} libgot-1d.rd}} \
-+	"libgot-1.so" \
-+    ] \
-+    [list \
-+	"Build libgot-1-x32.so" \
-+	"-shared -melf32_x86_64 --no-ld-generated-unwind-info \
-+	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
-+	 -z nomark-plt $NO_DT_RELR_LDFLAGS" \
-+	"" \
-+	"--x32 -mx86-used-note=no --generate-missing-build-notes=no" \
-+	{got-1.s} \
-+	{{readelf -rW libgot-1a-x32.rd} \
-+	 {readelf -aW libgot-1b-x32.rd} \
-+	 {readelf --got-contents libgot-1c-x32.rd} \
-+	 {readelf {--got-contents -W} libgot-1d-x32.rd}} \
-+	"libgot-1-x32.so" \
-+    ] \
-+]
-diff --git a/ld/testsuite/ld-x86-64/got-1.s b/ld/testsuite/ld-x86-64/got-1.s
-new file mode 100644
-index 00000000000..76370691f1d
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/got-1.s
-@@ -0,0 +1,7 @@
-+	.text
-+	.globl	func
-+	.type	func, @function
-+func:
-+	call	*foo@GOTPCREL(%rip)
-+	jmp	bar@PLT
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/libgot-1a-x32.rd b/ld/testsuite/ld-x86-64/libgot-1a-x32.rd
-new file mode 100644
-index 00000000000..6861d6588d6
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1a-x32.rd
-@@ -0,0 +1,9 @@
-+
-+Relocation section '.rela.dyn' at offset 0x128 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-+0+200200  00000206 R_X86_64_GLOB_DAT      00000000   foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x134 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-+0+200220  00000307 R_X86_64_JUMP_SLOT     00000000   bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1a.rd b/ld/testsuite/ld-x86-64/libgot-1a.rd
-new file mode 100644
-index 00000000000..8ed447003c7
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1a.rd
-@@ -0,0 +1,9 @@
-+
-+Relocation section '.rela.dyn' at offset 0x1b8 contains 1 entry:
-+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
-+0+200340  0000000200000006 R_X86_64_GLOB_DAT      0000000000000000 foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x1d0 contains 1 entry:
-+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
-+0+200360  0000000300000007 R_X86_64_JUMP_SLOT     0000000000000000 bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1b-x32.rd b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
-new file mode 100644
-index 00000000000..f900303fcce
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
-@@ -0,0 +1,119 @@
-+ELF Header:
-+  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
-+  Class:                             ELF32
-+  Data:                              2's complement, little endian
-+  Version:                           1 \(current\)
-+  OS/ABI:                            UNIX - System V
-+  ABI Version:                       0
-+  Type:                              DYN \(Shared object file\)
-+  Machine:                           Advanced Micro Devices X86-64
-+  Version:                           0x1
-+  Entry point address:               0x0
-+  Start of program headers:          52 \(bytes into file\)
-+  Start of section headers:          792 \(bytes into file\)
-+  Flags:                             0x0
-+  Size of this header:               52 \(bytes\)
-+  Size of program headers:           32 \(bytes\)
-+  Number of program headers:         4
-+  Size of section headers:           40 \(bytes\)
-+  Number of section headers:         14
-+  Section header string table index: 13
-+
-+Section Headers:
-+  \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
-+  \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
-+  \[ 1\] .hash             HASH            000000b4 0000b4 000024 04   A  2   0  4
-+  \[ 2\] .dynsym           DYNSYM          000000d8 0000d8 000040 10   A  3   1  4
-+  \[ 3\] .dynstr           STRTAB          00000118 000118 00000e 00   A  0   0  1
-+  \[ 4\] .rela.dyn         RELA            00000128 000128 00000c 0c   A  2   0  4
-+  \[ 5\] .rela.plt         RELA            00000134 000134 00000c 0c  AI  2  10  4
-+  \[ 6\] .plt              PROGBITS        00000140 000140 000020 10  AX  0   0 16
-+  \[ 7\] .text             PROGBITS        00000160 000160 00000b 00  AX  0   0  1
-+  \[ 8\] .dynamic          DYNAMIC         0020016c 00016c 000090 08  WA  3   0  4
-+  \[ 9\] .got              PROGBITS        00200200 000200 000008 08  WA  0   0  8
-+  \[10\] .got.plt          PROGBITS        00200208 000208 000020 08  WA  0   0  8
-+  \[11\] .symtab           SYMTAB          00000000 000228 000060 10     12   3  4
-+  \[12\] .strtab           STRTAB          00000000 000288 00002d 00      0   0  1
-+  \[13\] .shstrtab         STRTAB          00000000 0002b5 000062 00      0   0  1
-+Key to Flags:
-+  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
-+  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
-+  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
-+  D \(mbind\), l \(large\), p \(processor specific\)
-+
-+There are no section groups in this file.
-+
-+Program Headers:
-+  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
-+  LOAD           0x000000 0x00000000 0x00000000 0x0016b 0x0016b R E 0x200000
-+  LOAD           0x00016c 0x0020016c 0x0020016c 0x000bc 0x000bc RW  0x200000
-+  DYNAMIC        0x00016c 0x0020016c 0x0020016c 0x00090 0x00090 RW  0x4
-+  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
-+
-+ Section to Segment mapping:
-+  Segment Sections...
-+   00     .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text 
-+   01     .dynamic .got .got.plt 
-+   02     .dynamic 
-+   03     
-+
-+Dynamic section at offset 0x16c contains 13 entries:
-+  Tag        Type                         Name/Value
-+ 0x00000004 \(HASH\)                       0xb4
-+ 0x00000005 \(STRTAB\)                     0x118
-+ 0x00000006 \(SYMTAB\)                     0xd8
-+ 0x0000000a \(STRSZ\)                      14 \(bytes\)
-+ 0x0000000b \(SYMENT\)                     16 \(bytes\)
-+ 0x00000003 \(PLTGOT\)                     0x200208
-+ 0x00000002 \(PLTRELSZ\)                   12 \(bytes\)
-+ 0x00000014 \(PLTREL\)                     RELA
-+ 0x00000017 \(JMPREL\)                     0x134
-+ 0x00000007 \(RELA\)                       0x128
-+ 0x00000008 \(RELASZ\)                     12 \(bytes\)
-+ 0x00000009 \(RELAENT\)                    12 \(bytes\)
-+ 0x00000000 \(NULL\)                       0x0
-+
-+Relocation section '.rela.dyn' at offset 0x128 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-+0+200200  00000206 R_X86_64_GLOB_DAT      00000000   foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x134 contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
-+0+200220  00000307 R_X86_64_JUMP_SLOT     00000000   bar \+ 0
-+No processor specific unwind information to decode
-+
-+Symbol table '.dynsym' contains 4 entries:
-+   Num:    Value  Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Symbol table '.symtab' contains 6 entries:
-+   Num:    Value  Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 0020016c     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
-+ +[a-f0-9]+: 00200208     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
-+ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Histogram for bucket list length \(total of 3 buckets\):
-+ Length  Number     % of total  Coverage
-+      0  1          \( 33.3%\)
-+      1  1          \( 33.3%\)     33.3%
-+      2  1          \( 33.3%\)    100.0%
-+
-+No version information found in this file.
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200208                        20016c
-+ +[0-9]+: 00200210                        0
-+ +[0-9]+: 00200218                        0
-+ +[0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1b.rd b/ld/testsuite/ld-x86-64/libgot-1b.rd
-new file mode 100644
-index 00000000000..18e432475fc
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1b.rd
-@@ -0,0 +1,119 @@
-+ELF Header:
-+  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
-+  Class:                             ELF64
-+  Data:                              2's complement, little endian
-+  Version:                           1 \(current\)
-+  OS/ABI:                            UNIX - System V
-+  ABI Version:                       0
-+  Type:                              DYN \(Shared object file\)
-+  Machine:                           Advanced Micro Devices X86-64
-+  Version:                           0x1
-+  Entry point address:               0x0
-+  Start of program headers:          64 \(bytes into file\)
-+  Start of section headers:          1160 \(bytes into file\)
-+  Flags:                             0x0
-+  Size of this header:               64 \(bytes\)
-+  Size of program headers:           56 \(bytes\)
-+  Number of program headers:         4
-+  Size of section headers:           64 \(bytes\)
-+  Number of section headers:         14
-+  Section header string table index: 13
-+
-+Section Headers:
-+  \[Nr\] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
-+  \[ 0\]                   NULL            0000000000000000 000000 000000 00      0   0  0
-+  \[ 1\] .hash             HASH            0000000000000120 000120 000024 04   A  2   0  8
-+  \[ 2\] .dynsym           DYNSYM          0000000000000148 000148 000060 18   A  3   1  8
-+  \[ 3\] .dynstr           STRTAB          00000000000001a8 0001a8 00000e 00   A  0   0  1
-+  \[ 4\] .rela.dyn         RELA            00000000000001b8 0001b8 000018 18   A  2   0  8
-+  \[ 5\] .rela.plt         RELA            00000000000001d0 0001d0 000018 18  AI  2  10  8
-+  \[ 6\] .plt              PROGBITS        00000000000001f0 0001f0 000020 10  AX  0   0 16
-+  \[ 7\] .text             PROGBITS        0000000000000210 000210 00000b 00  AX  0   0  1
-+  \[ 8\] .dynamic          DYNAMIC         0000000000200220 000220 000120 10  WA  3   0  8
-+  \[ 9\] .got              PROGBITS        0000000000200340 000340 000008 08  WA  0   0  8
-+  \[10\] .got.plt          PROGBITS        0000000000200348 000348 000020 08  WA  0   0  8
-+  \[11\] .symtab           SYMTAB          0000000000000000 000368 000090 18     12   3  8
-+  \[12\] .strtab           STRTAB          0000000000000000 0003f8 00002d 00      0   0  1
-+  \[13\] .shstrtab         STRTAB          0000000000000000 000425 000062 00      0   0  1
-+Key to Flags:
-+  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
-+  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
-+  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
-+  D \(mbind\), l \(large\), p \(processor specific\)
-+
-+There are no section groups in this file.
-+
-+Program Headers:
-+  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
-+  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x00021b 0x00021b R E 0x200000
-+  LOAD           0x000220 0x0000000000200220 0x0000000000200220 0x000148 0x000148 RW  0x200000
-+  DYNAMIC        0x000220 0x0000000000200220 0x0000000000200220 0x000120 0x000120 RW  0x8
-+  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x10
-+
-+ Section to Segment mapping:
-+  Segment Sections...
-+   00     .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text 
-+   01     .dynamic .got .got.plt 
-+   02     .dynamic 
-+   03     
-+
-+Dynamic section at offset 0x220 contains 13 entries:
-+  Tag        Type                         Name/Value
-+ 0x0000000000000004 \(HASH\)               0x120
-+ 0x0000000000000005 \(STRTAB\)             0x1a8
-+ 0x0000000000000006 \(SYMTAB\)             0x148
-+ 0x000000000000000a \(STRSZ\)              14 \(bytes\)
-+ 0x000000000000000b \(SYMENT\)             24 \(bytes\)
-+ 0x0000000000000003 \(PLTGOT\)             0x200348
-+ 0x0000000000000002 \(PLTRELSZ\)           24 \(bytes\)
-+ 0x0000000000000014 \(PLTREL\)             RELA
-+ 0x0000000000000017 \(JMPREL\)             0x1d0
-+ 0x0000000000000007 \(RELA\)               0x1b8
-+ 0x0000000000000008 \(RELASZ\)             24 \(bytes\)
-+ 0x0000000000000009 \(RELAENT\)            24 \(bytes\)
-+ 0x0000000000000000 \(NULL\)               0x0
-+
-+Relocation section '.rela.dyn' at offset 0x1b8 contains 1 entry:
-+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
-+0+200340  0000000200000006 R_X86_64_GLOB_DAT      0000000000000000 foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x1d0 contains 1 entry:
-+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
-+0+200360  0000000300000007 R_X86_64_JUMP_SLOT     0000000000000000 bar \+ 0
-+No processor specific unwind information to decode
-+
-+Symbol table '.dynsym' contains 4 entries:
-+   Num:    Value          Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 0000000000000210     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Symbol table '.symtab' contains 6 entries:
-+   Num:    Value          Size Type    Bind   Vis      Ndx Name
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
-+ +[a-f0-9]+: 0000000000200220     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
-+ +[a-f0-9]+: 0000000000200348     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
-+ +[a-f0-9]+: 0000000000000210     0 FUNC    GLOBAL DEFAULT    7 func
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
-+ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
-+
-+Histogram for bucket list length \(total of 3 buckets\):
-+ Length  Number     % of total  Coverage
-+      0  1          \( 33.3%\)
-+      1  1          \( 33.3%\)     33.3%
-+      2  1          \( 33.3%\)    100.0%
-+
-+No version information found in this file.
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 0000000000200348                        200220
-+ +[0-9]+: 0000000000200350                        0
-+ +[0-9]+: 0000000000200358                        0
-+ +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1c-x32.rd b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
-new file mode 100644
-index 00000000000..a3bdacf1fa4
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+ Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200 R_X86_64_GLOB_DAT foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+ Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200208                   20016c
-+ +[0-9]+: 00200210                   0
-+ +[0-9]+: 00200218                   0
-+ +[0-9]+: 00200220 R_X86_64_JUMP_SLO bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1c.rd b/ld/testsuite/ld-x86-64/libgot-1c.rd
-new file mode 100644
-index 00000000000..fc1a2605848
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1c.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+ Index:    Address       Reloc         Sym. Name \+ Addend/Value
-+ +[0-9]+: 000000200340 R_X86_64_GLOB_DAT foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+ Index:    Address       Reloc         Sym. Name \+ Addend/Value
-+ +[0-9]+: 000000200348                   200220
-+ +[0-9]+: 000000200350                   0
-+ +[0-9]+: 000000200358                   0
-+ +[0-9]+: 000000200360 R_X86_64_JUMP_SLO bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1d-x32.rd b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
-new file mode 100644
-index 00000000000..3e2693e0f52
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 00200208                        20016c
-+ +[0-9]+: 00200210                        0
-+ +[0-9]+: 00200218                        0
-+ +[0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/libgot-1d.rd b/ld/testsuite/ld-x86-64/libgot-1d.rd
-new file mode 100644
-index 00000000000..341840e9081
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/libgot-1d.rd
-@@ -0,0 +1,12 @@
-+
-+Global Offset Table '.got' contains 1 entry:
-+   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
-+
-+Global Offset Table '.got.plt' contains 4 entries:
-+   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[0-9]+: 0000000000200348                        200220
-+ +[0-9]+: 0000000000200350                        0
-+ +[0-9]+: 0000000000200358                        0
-+ +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
-+#pass
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-28 20:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-28 20:21 UTC (permalink / raw
  To: gentoo-commits

commit:     31b49699ce7ab2b769f48bc9527ece5d2324b4e6
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 28 20:21:22 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 28 20:21:22 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=31b49699

9999: update readelf --got-contents patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0007-readelf-Add-got-contents-option.patch | 263 ++++++++++++++++++++----
 1 file changed, 223 insertions(+), 40 deletions(-)

diff --git a/9999/0007-readelf-Add-got-contents-option.patch b/9999/0007-readelf-Add-got-contents-option.patch
index fb4d0f2..85fd491 100644
--- a/9999/0007-readelf-Add-got-contents-option.patch
+++ b/9999/0007-readelf-Add-got-contents-option.patch
@@ -1,4 +1,5 @@
-From 68498caec29f2d1ae5302a5d462190f4b9d3e541 Mon Sep 17 00:00:00 2001
+From 59c754fcc3081053610842bdd288726fedc8c91b Mon Sep 17 00:00:00 2001
+Message-ID: <59c754fcc3081053610842bdd288726fedc8c91b.1756412415.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Mon, 25 Aug 2025 18:00:00 -0700
 Subject: [PATCH] readelf: Add --got-contents option
@@ -27,6 +28,8 @@ and cache them in all_relocations.  Don't display relocations if not
 requested.
 3. Add process_got_section_contents to display contents of GOT sections
 by matching the GOT entry offset against the cached relocations.
+4. Update process_mips_specific to only display the GOT related contents
+for --got-contents.
 
 binutils/
 
@@ -45,12 +48,16 @@ binutils/
 	(options): Add --got-contents.
 	(usage): Show --got-contents.
 	(parse_args): Support --got-contents.
-	(display_relocations): Add bool argument, dump_reloc, to indicate
-	if relocations should be displayed.  Call update_all_relocations.
-	Pass dump_reloc to dump_relr_relocations and dump_relocations.
+	(display_relocations): Add a bool argument, dump_reloc, to
+	indicate if relocations should be displayed.  Call
+	update_all_relocations.  Pass dump_reloc to dump_relr_relocations
+	and dump_relocations.
 	(process_relocs): Check do_got_section_contents.  Handle
 	do_got_section_contents for dynamic relocations.
 	(process_section_contents): Pass true to display_relocations.
+	(process_mips_specific): Add a bool argument, dump_got, to
+	indicate if only the GOT related contents should be displayed.
+	Display all MIPS specific information if dump_got is false.
 	(elf_relocation_cmp): New.
 	(display_elf_relocation_at): Likewise.
 	(process_got_section_contents): Likewise.
@@ -78,26 +85,26 @@ ld/
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
- binutils/NEWS                           |   3 +
- binutils/doc/binutils.texi              |  10 +-
- binutils/readelf.c                      | 878 +++++++++++++++++++-----
- ld/testsuite/ld-i386/binutils.exp       |  45 ++
- ld/testsuite/ld-i386/got-1.s            |   7 +
- ld/testsuite/ld-i386/libgot-1a.rd       |   9 +
- ld/testsuite/ld-i386/libgot-1b.rd       | 119 ++++
- ld/testsuite/ld-i386/libgot-1c.rd       |  12 +
- ld/testsuite/ld-i386/libgot-1d.rd       |  12 +
- ld/testsuite/ld-x86-64/binutils.exp     |  59 ++
- ld/testsuite/ld-x86-64/got-1.s          |   7 +
- ld/testsuite/ld-x86-64/libgot-1a-x32.rd |   9 +
- ld/testsuite/ld-x86-64/libgot-1a.rd     |   9 +
- ld/testsuite/ld-x86-64/libgot-1b-x32.rd | 119 ++++
- ld/testsuite/ld-x86-64/libgot-1b.rd     | 119 ++++
- ld/testsuite/ld-x86-64/libgot-1c-x32.rd |  12 +
- ld/testsuite/ld-x86-64/libgot-1c.rd     |  12 +
- ld/testsuite/ld-x86-64/libgot-1d-x32.rd |  12 +
- ld/testsuite/ld-x86-64/libgot-1d.rd     |  12 +
- 19 files changed, 1305 insertions(+), 160 deletions(-)
+ binutils/NEWS                           |    3 +
+ binutils/doc/binutils.texi              |   12 +-
+ binutils/readelf.c                      | 1004 ++++++++++++++++++-----
+ ld/testsuite/ld-i386/binutils.exp       |   45 +
+ ld/testsuite/ld-i386/got-1.s            |    7 +
+ ld/testsuite/ld-i386/libgot-1a.rd       |    9 +
+ ld/testsuite/ld-i386/libgot-1b.rd       |  119 +++
+ ld/testsuite/ld-i386/libgot-1c.rd       |   12 +
+ ld/testsuite/ld-i386/libgot-1d.rd       |   12 +
+ ld/testsuite/ld-x86-64/binutils.exp     |   59 ++
+ ld/testsuite/ld-x86-64/got-1.s          |    7 +
+ ld/testsuite/ld-x86-64/libgot-1a-x32.rd |    9 +
+ ld/testsuite/ld-x86-64/libgot-1a.rd     |    9 +
+ ld/testsuite/ld-x86-64/libgot-1b-x32.rd |  119 +++
+ ld/testsuite/ld-x86-64/libgot-1b.rd     |  119 +++
+ ld/testsuite/ld-x86-64/libgot-1c-x32.rd |   12 +
+ ld/testsuite/ld-x86-64/libgot-1c.rd     |   12 +
+ ld/testsuite/ld-x86-64/libgot-1d-x32.rd |   12 +
+ ld/testsuite/ld-x86-64/libgot-1d.rd     |   12 +
+ 19 files changed, 1378 insertions(+), 215 deletions(-)
  create mode 100644 ld/testsuite/ld-i386/binutils.exp
  create mode 100644 ld/testsuite/ld-i386/got-1.s
  create mode 100644 ld/testsuite/ld-i386/libgot-1a.rd
@@ -129,7 +136,7 @@ index ccda8559897..0a4ed3bcc43 100644
    in some errors being exposed in user options passed to the various binutils.
    For example objcopy --target=TARGET now will only work if the input file is
 diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
-index 4543341e00c..6217dd76d90 100644
+index 4543341e00c..89425b8a15b 100644
 --- a/binutils/doc/binutils.texi
 +++ b/binutils/doc/binutils.texi
 @@ -5076,6 +5076,7 @@ readelf [@option{-a}|@option{--all}]
@@ -150,7 +157,7 @@ index 4543341e00c..6217dd76d90 100644
  @option{--section-groups} and @option{--histogram}.
  
  Note - this option does not enable @option{--use-dynamic} itself, so
-@@ -5387,6 +5389,12 @@ string table are used.
+@@ -5387,6 +5389,14 @@ string table are used.
  If either of @option{--ctf-symbols} or @option{--ctf-strings} is specified, the
  other must be specified as well.
  
@@ -158,13 +165,15 @@ index 4543341e00c..6217dd76d90 100644
 +@cindex ELF section information
 +@cindex ELF reloc information
 +Displays the contents of the file's Global Offset Table (GOT) sections,
-+if it has any.
++if it has any.  For MIPS, this option is similar to
++@option{--arch-specific}, but it only displays the GOT related contents
++and it is ignored when @option{--arch-specific} is used.
 +
  @item -I
  @itemx --histogram
  Display a histogram of bucket list lengths when displaying the contents
 diff --git a/binutils/readelf.c b/binutils/readelf.c
-index 68e193415f2..a58ad8d116c 100644
+index 68e193415f2..2affc713adb 100644
 --- a/binutils/readelf.c
 +++ b/binutils/readelf.c
 @@ -229,6 +229,7 @@ static bool do_dyn_syms = false;
@@ -603,14 +612,14 @@ index 68e193415f2..a58ad8d116c 100644
        symtab_index = get_reloc_symindex  (inf);
  
 -      if (is_32bit_elf)
-+      if (dump_reloc)
- 	{
+-	{
 -	  printf ("%8.8lx  %8.8lx ",
 -		  (unsigned long) offset & 0xffffffff,
 -		  (unsigned long) inf & 0xffffffff);
 -	}
 -      else
--	{
++      if (dump_reloc)
+ 	{
 -	  printf (do_wide
 -		  ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
 -		  : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
@@ -1181,8 +1190,162 @@ index 68e193415f2..a58ad8d116c 100644
  	      break;
  
  	    case SHT_NOTE:
-@@ -17718,6 +18085,196 @@ process_section_contents (Filedata * filedata)
-   return res;
+@@ -19644,8 +20011,11 @@ get_mips_reg_size (int reg_size)
+ 	 : -1;
+ }
+ 
++/* If DUMP_GOT is true, display only the GOT related contents.
++   Otherwise, display all MIPS specific information.  */
++
+ static bool
+-process_mips_specific (Filedata * filedata)
++process_mips_specific (Filedata * filedata, bool dump_got)
+ {
+   Elf_Internal_Dyn * entry;
+   Elf_Internal_Shdr *sect = NULL;
+@@ -19664,60 +20034,63 @@ process_mips_specific (Filedata * filedata)
+   uint64_t symtabno = 0;
+   bool res = true;
+ 
+-  if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
+-			    display_mips_gnu_attribute))
+-    res = false;
+-
+-  sect = find_section (filedata, ".MIPS.abiflags");
+-
+-  if (sect != NULL)
++  if (!dump_got)
+     {
+-      Elf_External_ABIFlags_v0 *abiflags_ext;
+-      Elf_Internal_ABIFlags_v0 abiflags_in;
++      if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
++				display_mips_gnu_attribute))
++	res = false;
+ 
+-      if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
+-	{
+-	  error (_("Corrupt MIPS ABI Flags section.\n"));
+-	  res = false;
+-	}
+-      else
++      sect = find_section (filedata, ".MIPS.abiflags");
++
++      if (sect != NULL)
+ 	{
+-	  abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
+-				   sect->sh_size, _("MIPS ABI Flags section"));
+-	  if (abiflags_ext)
++	  Elf_External_ABIFlags_v0 *abiflags_ext;
++	  Elf_Internal_ABIFlags_v0 abiflags_in;
++
++	  if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
+ 	    {
+-	      abiflags_in.version = BYTE_GET (abiflags_ext->version);
+-	      abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
+-	      abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
+-	      abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
+-	      abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
+-	      abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
+-	      abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
+-	      abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
+-	      abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
+-	      abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
+-	      abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
+-
+-	      printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
+-	      printf ("\nISA: MIPS%d", abiflags_in.isa_level);
+-	      if (abiflags_in.isa_rev > 1)
+-		printf ("r%d", abiflags_in.isa_rev);
+-	      printf ("\nGPR size: %d",
+-		      get_mips_reg_size (abiflags_in.gpr_size));
+-	      printf ("\nCPR1 size: %d",
+-		      get_mips_reg_size (abiflags_in.cpr1_size));
+-	      printf ("\nCPR2 size: %d",
+-		      get_mips_reg_size (abiflags_in.cpr2_size));
+-	      fputs ("\nFP ABI: ", stdout);
+-	      print_mips_fp_abi_value (abiflags_in.fp_abi);
+-	      fputs ("ISA Extension: ", stdout);
+-	      print_mips_isa_ext (abiflags_in.isa_ext);
+-	      fputs ("\nASEs:", stdout);
+-	      print_mips_ases (abiflags_in.ases);
+-	      printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
+-	      printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
+-	      fputc ('\n', stdout);
+-	      free (abiflags_ext);
++	      error (_("Corrupt MIPS ABI Flags section.\n"));
++	      res = false;
++	    }
++	  else
++	    {
++	      abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
++				       sect->sh_size, _("MIPS ABI Flags section"));
++	      if (abiflags_ext)
++		{
++		  abiflags_in.version = BYTE_GET (abiflags_ext->version);
++		  abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
++		  abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
++		  abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
++		  abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
++		  abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
++		  abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
++		  abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
++		  abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
++		  abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
++		  abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
++
++		  printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
++		  printf ("\nISA: MIPS%d", abiflags_in.isa_level);
++		  if (abiflags_in.isa_rev > 1)
++		    printf ("r%d", abiflags_in.isa_rev);
++		  printf ("\nGPR size: %d",
++			  get_mips_reg_size (abiflags_in.gpr_size));
++		  printf ("\nCPR1 size: %d",
++			  get_mips_reg_size (abiflags_in.cpr1_size));
++		  printf ("\nCPR2 size: %d",
++			  get_mips_reg_size (abiflags_in.cpr2_size));
++		  fputs ("\nFP ABI: ", stdout);
++		  print_mips_fp_abi_value (abiflags_in.fp_abi);
++		  fputs ("ISA Extension: ", stdout);
++		  print_mips_isa_ext (abiflags_in.isa_ext);
++		  fputs ("\nASEs:", stdout);
++		  print_mips_ases (abiflags_in.ases);
++		  printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
++		  printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
++		  fputc ('\n', stdout);
++		  free (abiflags_ext);
++		}
+ 	    }
+ 	}
+     }
+@@ -19865,7 +20238,7 @@ process_mips_specific (Filedata * filedata)
+ 	break;
+       }
+ 
+-  if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
++  if (!dump_got && liblist_offset != 0 && liblistno != 0 && do_dynamic)
+     {
+       Elf32_External_Lib * elib;
+       size_t cnt;
+@@ -19950,7 +20323,7 @@ process_mips_specific (Filedata * filedata)
+ 	res = false;
+     }
+ 
+-  if (options_offset != 0)
++  if (!dump_got && options_offset != 0)
+     {
+       Elf_External_Options * eopt;
+       size_t offset;
+@@ -20199,7 +20572,7 @@ process_mips_specific (Filedata * filedata)
+ 	res = false;
+     }
+ 
+-  if (conflicts_offset != 0 && conflictsno != 0)
++  if (!dump_got && conflicts_offset != 0 && conflictsno != 0)
+     {
+       Elf32_Conflict * iconf;
+       size_t cnt;
+@@ -20558,6 +20931,206 @@ process_nds32_specific (Filedata * filedata)
+   return true;
  }
  
 +static int
@@ -1264,9 +1427,19 @@ index 68e193415f2..a58ad8d116c 100644
 +  unsigned char *data;
 +  bool res = true;
 +
-+  if (! do_got_section_contents)
++  if (!do_got_section_contents)
 +    return res;
 +
++  switch (filedata->file_header.e_machine)
++    {
++    case EM_MIPS:
++    case EM_MIPS_RS3_LE:
++      /* process_mips_specific also displays GOT related contents.  */
++      if (!do_arch)
++	res = process_mips_specific (filedata, true);
++      goto out;
++    }
++
 +  qsort (all_relocations_root, all_relocations_count,
 +	 sizeof (elf_relocation), elf_relocation_cmp);
 +
@@ -1316,10 +1489,10 @@ index 68e193415f2..a58ad8d116c 100644
 +		      /* |---9---| |---8--| |---------22---------| |...........  */
 +	    else
 +	      printf (_(" Index:  Address      Reloc        Sym. Name + Addend/Value\n"));
-+		      /* |--7--| |---8--| |-------17------| |...........  */
++		    /* |--7--| |---8--| |-------17------| |...........  */
++
 +	    addr = section->sh_addr;
 +	    got = (struct got32 *) data;
-+
 +	    for (j = 0; j < n; j++)
 +	      {
 +		g = BYTE_GET (got[j].bytes);
@@ -1375,10 +1548,19 @@ index 68e193415f2..a58ad8d116c 100644
 +  return res;
 +}
 +
- static void
- process_mips_fpe_exception (int mask)
+ static bool
+ process_gnu_liblist (Filedata * filedata)
  {
-@@ -23833,6 +24390,9 @@ process_object (Filedata * filedata)
+@@ -23469,7 +24042,7 @@ process_arch_specific (Filedata * filedata)
+ 
+     case EM_MIPS:
+     case EM_MIPS_RS3_LE:
+-      return process_mips_specific (filedata);
++      return process_mips_specific (filedata, false);
+ 
+     case EM_MSP430:
+      return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
+@@ -23833,6 +24406,9 @@ process_object (Filedata * filedata)
    if (! process_section_contents (filedata))
      res = false;
  
@@ -2059,4 +2241,5 @@ index 00000000000..341840e9081
 + +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
 -- 
-GitLab
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-28 13:51 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-28 13:51 UTC (permalink / raw
  To: gentoo-commits

commit:     045a21949cf0d9247209cb063abd8f456eeab9db
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 28 13:50:53 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 28 13:50:53 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=045a2194

9999: update readelf (-G, now --got-contents) patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ... => 0007-readelf-Add-got-contents-option.patch} | 186 +++++++++++----------
 1 file changed, 100 insertions(+), 86 deletions(-)

diff --git a/9999/0007-readelf-Add-G-got-contents-options.patch b/9999/0007-readelf-Add-got-contents-option.patch
similarity index 94%
rename from 9999/0007-readelf-Add-G-got-contents-options.patch
rename to 9999/0007-readelf-Add-got-contents-option.patch
index 3937e46..fb4d0f2 100644
--- a/9999/0007-readelf-Add-G-got-contents-options.patch
+++ b/9999/0007-readelf-Add-got-contents-option.patch
@@ -1,13 +1,12 @@
-From 2ff87965b30795687eeaa8cb7241d2d1e0a63e16 Mon Sep 17 00:00:00 2001
-Message-ID: <2ff87965b30795687eeaa8cb7241d2d1e0a63e16.1756359099.git.sam@gentoo.org>
+From 68498caec29f2d1ae5302a5d462190f4b9d3e541 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Mon, 25 Aug 2025 18:00:00 -0700
-Subject: [PATCH] readelf: Add -G/--got-contents options
+Subject: [PATCH] readelf: Add --got-contents option
 
-Add -G/--got-contents options to readelf, inspired by the similar option
-on Solaris, to display contents of GOT sections:
+Add --got-contents option to readelf, inspired by the -G option on Solaris,
+to display contents of GOT sections:
 
-$ readelf -G libfoo.so
+$ readelf --got-contents libfoo.so
 
 Global Offset Table '.got' contains 1 entry:
  Index:    Address       Reloc         Sym. Name + Addend/Value
@@ -20,7 +19,7 @@ Global Offset Table '.got.plt' contains 4 entries:
      2: 000000200358                   0
      3: 000000200360 R_X86_64_JUMP_SLO bar + 0
 
-When -G/--got-contents options are used:
+When --got-content options are used:
 
 1. Allocate an array, all_relocations, to hold all relocations.
 2. Update dump_relr_relocations and dump_relocations to scan relocations
@@ -31,7 +30,7 @@ by matching the GOT entry offset against the cached relocations.
 
 binutils/
 
-	* NEWS: Mention "readelf -G/--got-contents".
+	* NEWS: Mention "readelf --got-contents".
 	* readelf.c (do_got_section_contents): New.
 	(elf_relocation): Likewise.
 	(all_relocations_root): Likewise.
@@ -42,9 +41,10 @@ binutils/
 	relocations should be displayed.  Populate all_relocations if
 	do_got_section_contents is true.
 	(dump_relocations): Likewise.
-	(options): Add -G/--got-contents.
-	(usage): Show -G/--got-contents.
-	(parse_args): Support -G/--got-contents.
+	(long_option_values): Add OPTION_GOT_CONTENTS.
+	(options): Add --got-contents.
+	(usage): Show --got-contents.
+	(parse_args): Support --got-contents.
 	(display_relocations): Add bool argument, dump_reloc, to indicate
 	if relocations should be displayed.  Call update_all_relocations.
 	Pass dump_reloc to dump_relr_relocations and dump_relocations.
@@ -55,7 +55,7 @@ binutils/
 	(display_elf_relocation_at): Likewise.
 	(process_got_section_contents): Likewise.
 	(process_object): Call process_got_section_contents.
-	* doc/binutils.texi: Document -G/--got-contents.
+	* doc/binutils.texi: Document --got-contents.
 
 ld/
 
@@ -79,8 +79,8 @@ ld/
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  binutils/NEWS                           |   3 +
- binutils/doc/binutils.texi              |  11 +-
- binutils/readelf.c                      | 874 +++++++++++++++++++-----
+ binutils/doc/binutils.texi              |  10 +-
+ binutils/readelf.c                      | 878 +++++++++++++++++++-----
  ld/testsuite/ld-i386/binutils.exp       |  45 ++
  ld/testsuite/ld-i386/got-1.s            |   7 +
  ld/testsuite/ld-i386/libgot-1a.rd       |   9 +
@@ -97,7 +97,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/testsuite/ld-x86-64/libgot-1c.rd     |  12 +
  ld/testsuite/ld-x86-64/libgot-1d-x32.rd |  12 +
  ld/testsuite/ld-x86-64/libgot-1d.rd     |  12 +
- 19 files changed, 1303 insertions(+), 159 deletions(-)
+ 19 files changed, 1305 insertions(+), 160 deletions(-)
  create mode 100644 ld/testsuite/ld-i386/binutils.exp
  create mode 100644 ld/testsuite/ld-i386/got-1.s
  create mode 100644 ld/testsuite/ld-i386/libgot-1a.rd
@@ -116,30 +116,30 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  create mode 100644 ld/testsuite/ld-x86-64/libgot-1d.rd
 
 diff --git a/binutils/NEWS b/binutils/NEWS
-index ccda8559897..9af862a4735 100644
+index ccda8559897..0a4ed3bcc43 100644
 --- a/binutils/NEWS
 +++ b/binutils/NEWS
 @@ -1,5 +1,8 @@
  -*- text -*-
  
-+* Add -G/--got-contents options to readelf to display the contents of
++* Add --got-contents option to readelf to display the contents of
 +  Global Offset Table (GOT) sections.
 +
  * Internal changes to plugin support, and stricter target checking may result
    in some errors being exposed in user options passed to the various binutils.
    For example objcopy --target=TARGET now will only work if the input file is
 diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
-index 4543341e00c..15f31d1bcef 100644
+index 4543341e00c..6217dd76d90 100644
 --- a/binutils/doc/binutils.texi
 +++ b/binutils/doc/binutils.texi
-@@ -5036,6 +5036,7 @@ readelf [@option{-a}|@option{--all}]
-         [@option{-h}|@option{--file-header}]
-         [@option{-l}|@option{--program-headers}|@option{--segments}]
-         [@option{-S}|@option{--section-headers}|@option{--sections}]
-+        [@option{-G}|@option{--got-contents}]
-         [@option{-g}|@option{--section-groups}]
-         [@option{-t}|@option{--section-details}]
-         [@option{-e}|@option{--headers}]
+@@ -5076,6 +5076,7 @@ readelf [@option{-a}|@option{--all}]
+         [@option{--ctf-strings=}@var{section}]
+         [@option{--sframe=}@var{section}]
+         [@option{-I}|@option{--histogram}]
++        [@option{--got-contents}]
+         [@option{-v}|@option{--version}]
+         [@option{-W}|@option{--wide}]
+         [@option{-T}|@option{--silent-truncation}]
 @@ -5111,7 +5112,8 @@ given.
  Equivalent to specifying @option{--file-header},
  @option{--program-headers}, @option{--sections}, @option{--symbols},
@@ -150,22 +150,21 @@ index 4543341e00c..15f31d1bcef 100644
  @option{--section-groups} and @option{--histogram}.
  
  Note - this option does not enable @option{--use-dynamic} itself, so
-@@ -5143,6 +5145,13 @@ Suppress "no symbols" diagnostic.
- Displays the information contained in the file's section headers, if it
- has any.
+@@ -5387,6 +5389,12 @@ string table are used.
+ If either of @option{--ctf-symbols} or @option{--ctf-strings} is specified, the
+ other must be specified as well.
  
-+@item -G
-+@itemx --got-contents
++@item --got-contents
 +@cindex ELF section information
 +@cindex ELF reloc information
 +Displays the contents of the file's Global Offset Table (GOT) sections,
 +if it has any.
 +
- @item -g
- @itemx --section-groups
- @cindex ELF section group information
+ @item -I
+ @itemx --histogram
+ Display a histogram of bucket list lengths when displaying the contents
 diff --git a/binutils/readelf.c b/binutils/readelf.c
-index 68e193415f2..efd4221ef6f 100644
+index 68e193415f2..a58ad8d116c 100644
 --- a/binutils/readelf.c
 +++ b/binutils/readelf.c
 @@ -229,6 +229,7 @@ static bool do_dyn_syms = false;
@@ -604,14 +603,14 @@ index 68e193415f2..efd4221ef6f 100644
        symtab_index = get_reloc_symindex  (inf);
  
 -      if (is_32bit_elf)
--	{
++      if (dump_reloc)
+ 	{
 -	  printf ("%8.8lx  %8.8lx ",
 -		  (unsigned long) offset & 0xffffffff,
 -		  (unsigned long) inf & 0xffffffff);
 -	}
 -      else
-+      if (dump_reloc)
- 	{
+-	{
 -	  printf (do_wide
 -		  ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
 -		  : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
@@ -878,47 +877,63 @@ index 68e193415f2..efd4221ef6f 100644
  	}
      }
  
-@@ -6111,6 +6417,7 @@ static struct option options[] =
-   {"use-dynamic",      no_argument, 0, 'D'},
-   {"dynamic",	       no_argument, 0, 'd'},
-   {"headers",	       no_argument, 0, 'e'},
-+  {"got-contents",     no_argument, 0, 'G'},
-   {"section-groups",   no_argument, 0, 'g'},
-   {"help",	       no_argument, 0, 'H'},
-   {"file-header",      no_argument, 0, 'h'},
-@@ -6183,6 +6490,8 @@ usage (FILE * stream)
+@@ -6097,7 +6403,8 @@ enum long_option_values
+   OPTION_NO_RECURSE_LIMIT,
+   OPTION_NO_DEMANGLING,
+   OPTION_NO_EXTRA_SYM_INFO,
+-  OPTION_SYM_BASE
++  OPTION_SYM_BASE,
++  OPTION_GOT_CONTENTS
+ };
+ 
+ static struct option options[] =
+@@ -6160,6 +6467,7 @@ static struct option options[] =
+ #endif
+   {"sframe",	       optional_argument, 0, OPTION_SFRAME_DUMP},
+   {"sym-base",	       optional_argument, 0, OPTION_SYM_BASE},
++  {"got-contents",     no_argument, 0, OPTION_GOT_CONTENTS},
+ 
+   {0,		       no_argument, 0, 0}
+ };
+@@ -6171,7 +6479,7 @@ usage (FILE * stream)
+   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
+   fprintf (stream, _(" Options are:\n"));
+   fprintf (stream, _("\
+-  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
++  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I --got-contents\n"));
+   fprintf (stream, _("\
+   -h --file-header       Display the ELF file header\n"));
    fprintf (stream, _("\
-      --sections          An alias for --section-headers\n"));
+@@ -6317,6 +6625,8 @@ usage (FILE * stream)
    fprintf (stream, _("\
-+  -G --got               Display GOT section contents\n"));
+   -I --histogram         Display histogram of bucket list lengths\n"));
+   fprintf (stream, _("\
++  --got-contents         Display GOT section contents\n"));
 +  fprintf (stream, _("\
-   -g --section-groups    Display the section groups\n"));
+   -W --wide              Allow output width to exceed 80 characters\n"));
    fprintf (stream, _("\
-   -t --section-details   Display the section details\n"));
-@@ -6417,7 +6726,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
-     usage (stderr);
- 
-   while ((c = getopt_long
--	  (argc, argv, "ACDHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options, NULL)) != EOF)
-+	  (argc, argv, "ACDGHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options, NULL)) != EOF)
-     {
-       switch (c)
- 	{
-@@ -6441,8 +6750,13 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+   -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
+@@ -6441,6 +6751,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
  	  do_histogram = true;
  	  do_arch = true;
  	  do_notes = true;
 +	  do_got_section_contents = true;
  	  break;
  
-+	case 'G':
+ 	case 'g':
+@@ -6700,6 +7011,11 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+ 	    }
+ 	  break;
+ 
++	case OPTION_GOT_CONTENTS:
 +	  do_got_section_contents = true;
 +	  do_dump = true;
 +	  break;
- 	case 'g':
- 	  do_section_groups = true;
- 	  break;
-@@ -9437,7 +9751,8 @@ rel_type_from_sh_type (unsigned int sh_type)
++
+ 	default:
+ 	  /* xgettext:c-format */
+ 	  error (_("Invalid option '-%c'\n"), c);
+@@ -9437,7 +9753,8 @@ rel_type_from_sh_type (unsigned int sh_type)
  
  static bool
  display_relocations (Elf_Internal_Shdr *  section,
@@ -928,7 +943,7 @@ index 68e193415f2..efd4221ef6f 100644
  {
    relocation_type rel_type = rel_type_from_sh_type (section->sh_type);
  
-@@ -9449,19 +9764,23 @@ display_relocations (Elf_Internal_Shdr *  section,
+@@ -9449,19 +9766,23 @@ display_relocations (Elf_Internal_Shdr *  section,
    if (rel_size == 0)
      return false;
  
@@ -962,7 +977,7 @@ index 68e193415f2..efd4221ef6f 100644
  
    if (rel_type == reltype_relr)
      {
-@@ -9470,26 +9789,33 @@ display_relocations (Elf_Internal_Shdr *  section,
+@@ -9470,26 +9791,33 @@ display_relocations (Elf_Internal_Shdr *  section,
  	 the number of words in the compressed RELR format.  So also provide
  	 the number of locations affected.  */
  
@@ -1010,7 +1025,7 @@ index 68e193415f2..efd4221ef6f 100644
    Elf_Internal_Shdr * symsec;
    Elf_Internal_Sym *  symtab = NULL;
    uint64_t            nsyms = 0;
-@@ -9524,12 +9850,15 @@ display_relocations (Elf_Internal_Shdr *  section,
+@@ -9524,12 +9852,15 @@ display_relocations (Elf_Internal_Shdr *  section,
      res = dump_relr_relocations (filedata, section->sh_size,
  				 section->sh_entsize,
  				 section->sh_offset,
@@ -1028,7 +1043,7 @@ index 68e193415f2..efd4221ef6f 100644
    free (strtab);
    free (symtab);
  
-@@ -9543,14 +9872,16 @@ process_relocs (Filedata * filedata)
+@@ -9543,14 +9874,16 @@ process_relocs (Filedata * filedata)
  {
    uint64_t rel_size;
    uint64_t rel_offset;
@@ -1046,7 +1061,7 @@ index 68e193415f2..efd4221ef6f 100644
        bool  has_dynamic_reloc;
        unsigned int i;
  
-@@ -9584,16 +9915,37 @@ process_relocs (Filedata * filedata)
+@@ -9584,16 +9917,37 @@ process_relocs (Filedata * filedata)
  		}
  	    }
  
@@ -1094,7 +1109,7 @@ index 68e193415f2..efd4221ef6f 100644
  
  	  if (rel_type == reltype_relr)
  	    dump_relr_relocations (filedata,
-@@ -9603,24 +9955,37 @@ process_relocs (Filedata * filedata)
+@@ -9603,24 +9957,37 @@ process_relocs (Filedata * filedata)
  				   filedata->dynamic_symbols,
  				   filedata->num_dynamic_syms,
  				   filedata->dynamic_strings,
@@ -1143,7 +1158,7 @@ index 68e193415f2..efd4221ef6f 100644
  	{
  	  if (filedata->is_separate)
  	    printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
-@@ -9639,11 +10004,11 @@ process_relocs (Filedata * filedata)
+@@ -9639,11 +10006,11 @@ process_relocs (Filedata * filedata)
  	   i < filedata->file_header.e_shnum;
  	   i++, section++)
  	{
@@ -1157,7 +1172,7 @@ index 68e193415f2..efd4221ef6f 100644
  	{
  	  /* Users sometimes forget the -D option, so try to be helpful.  */
  	  for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
-@@ -17627,7 +17992,7 @@ process_section_contents (Filedata * filedata)
+@@ -17627,7 +17994,7 @@ process_section_contents (Filedata * filedata)
  	    case SHT_RELA:
  	    case SHT_REL:
  	    case SHT_RELR:
@@ -1166,7 +1181,7 @@ index 68e193415f2..efd4221ef6f 100644
  	      break;
  
  	    case SHT_NOTE:
-@@ -17718,6 +18083,196 @@ process_section_contents (Filedata * filedata)
+@@ -17718,6 +18085,196 @@ process_section_contents (Filedata * filedata)
    return res;
  }
  
@@ -1363,7 +1378,7 @@ index 68e193415f2..efd4221ef6f 100644
  static void
  process_mips_fpe_exception (int mask)
  {
-@@ -23833,6 +24388,9 @@ process_object (Filedata * filedata)
+@@ -23833,6 +24390,9 @@ process_object (Filedata * filedata)
    if (! process_section_contents (filedata))
      res = false;
  
@@ -1375,7 +1390,7 @@ index 68e193415f2..efd4221ef6f 100644
        separate_info * d;
 diff --git a/ld/testsuite/ld-i386/binutils.exp b/ld/testsuite/ld-i386/binutils.exp
 new file mode 100644
-index 00000000000..eb8c14215c3
+index 00000000000..5069c59ca9e
 --- /dev/null
 +++ b/ld/testsuite/ld-i386/binutils.exp
 @@ -0,0 +1,45 @@
@@ -1419,8 +1434,8 @@ index 00000000000..eb8c14215c3
 +	{got-1.s} \
 +	{{readelf -rW libgot-1a.rd} \
 +	 {readelf -aW libgot-1b.rd} \
-+	 {readelf -G libgot-1c.rd} \
-+	 {readelf -GW libgot-1d.rd}} \
++	 {readelf --got-contents libgot-1c.rd} \
++	 {readelf {--got-contents -W} libgot-1d.rd}} \
 +	"libgot-1.so" \
 +    ] \
 +]
@@ -1615,7 +1630,7 @@ index 00000000000..632b47be743
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/binutils.exp b/ld/testsuite/ld-x86-64/binutils.exp
 new file mode 100644
-index 00000000000..70609a8da12
+index 00000000000..fef997368db
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/binutils.exp
 @@ -0,0 +1,59 @@
@@ -1659,8 +1674,8 @@ index 00000000000..70609a8da12
 +	{got-1.s} \
 +	{{readelf -rW libgot-1a.rd} \
 +	 {readelf -aW libgot-1b.rd} \
-+	 {readelf -G libgot-1c.rd} \
-+	 {readelf -GW libgot-1d.rd}} \
++	 {readelf --got-contents libgot-1c.rd} \
++	 {readelf {--got-contents -W} libgot-1d.rd}} \
 +	"libgot-1.so" \
 +    ] \
 +    [list \
@@ -1673,8 +1688,8 @@ index 00000000000..70609a8da12
 +	{got-1.s} \
 +	{{readelf -rW libgot-1a-x32.rd} \
 +	 {readelf -aW libgot-1b-x32.rd} \
-+	 {readelf -G libgot-1c-x32.rd} \
-+	 {readelf -GW libgot-1d-x32.rd}} \
++	 {readelf --got-contents libgot-1c-x32.rd} \
++	 {readelf {--got-contents -W} libgot-1d-x32.rd}} \
 +	"libgot-1-x32.so" \
 +    ] \
 +]
@@ -2044,5 +2059,4 @@ index 00000000000..341840e9081
 + +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
 -- 
-2.51.0
-
+GitLab


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-28  5:32 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-28  5:32 UTC (permalink / raw
  To: gentoo-commits

commit:     63758a79dadc14ba8df635ff67370c4348ff7c31
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 28 05:31:59 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 28 05:31:59 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=63758a79

9999: update readelf -G patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0007-readelf-Add-G-got-contents-options.patch | 491 +++++++++++----------
 1 file changed, 254 insertions(+), 237 deletions(-)

diff --git a/9999/0007-readelf-Add-G-got-contents-options.patch b/9999/0007-readelf-Add-G-got-contents-options.patch
index 5cae8ee..3937e46 100644
--- a/9999/0007-readelf-Add-G-got-contents-options.patch
+++ b/9999/0007-readelf-Add-G-got-contents-options.patch
@@ -1,40 +1,86 @@
-From d10474f6defab5484fd8a9a79c3fa8588ca37396 Mon Sep 17 00:00:00 2001
-Message-ID: <d10474f6defab5484fd8a9a79c3fa8588ca37396.1756262897.git.sam@gentoo.org>
+From 2ff87965b30795687eeaa8cb7241d2d1e0a63e16 Mon Sep 17 00:00:00 2001
+Message-ID: <2ff87965b30795687eeaa8cb7241d2d1e0a63e16.1756359099.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 26 Aug 2025 19:45:44 -0700
+Date: Mon, 25 Aug 2025 18:00:00 -0700
 Subject: [PATCH] readelf: Add -G/--got-contents options
 
-On Tue, Aug 26, 2025 at 02:53:40PM -0700, H.J. Lu wrote:
-> Add -G/--got-contents options to readelf, inspired by the similar option
-> on Solaris, to display the contents of GOT sections:
->
-> $ readelf -G libfoo.so
->
-> Global Offset Table '.got' contains 5 entries:
->  Index:    Address       Reloc         Sym. Name + Addend/Value
->      0: 000000002fc8 R_X86_64_GLOB_DAT bar + 0
->      1: 000000002fd0 R_X86_64_GLOB_DAT __gmon_start__ + 0
->      2: 000000002fd8 R_X86_64_GLOB_DAT _ITM_registerTMCloneTable + 0
->      3: 000000002fe0 R_X86_64_GLOB_DAT __cxa_finalize@GLIBC_2.2.5 + 0
->      4: 000000002fe8                   0
->
-> Global Offset Table '.got.plt' contains 4 entries:
->  Index:    Address       Reloc         Sym. Name + Addend/Value
->      0: 000000002ff0                   2dd0
->      1: 000000002ff8                   0
->      2: 000000003000 R_X86_64_JUMP_SLO printf@GLIBC_2.2.5 + 2c0
->      3: 000000003008                   0
->
-> Any comments?
->
+Add -G/--got-contents options to readelf, inspired by the similar option
+on Solaris, to display contents of GOT sections:
 
-The updated patch with typo fix.
+$ readelf -G libfoo.so
 
-H.J.
+Global Offset Table '.got' contains 1 entry:
+ Index:    Address       Reloc         Sym. Name + Addend/Value
+     0: 000000200340 R_X86_64_GLOB_DAT foo + 0
+
+Global Offset Table '.got.plt' contains 4 entries:
+ Index:    Address       Reloc         Sym. Name + Addend/Value
+     0: 000000200348                   200220
+     1: 000000200350                   0
+     2: 000000200358                   0
+     3: 000000200360 R_X86_64_JUMP_SLO bar + 0
+
+When -G/--got-contents options are used:
+
+1. Allocate an array, all_relocations, to hold all relocations.
+2. Update dump_relr_relocations and dump_relocations to scan relocations
+and cache them in all_relocations.  Don't display relocations if not
+requested.
+3. Add process_got_section_contents to display contents of GOT sections
+by matching the GOT entry offset against the cached relocations.
+
+binutils/
+
+	* NEWS: Mention "readelf -G/--got-contents".
+	* readelf.c (do_got_section_contents): New.
+	(elf_relocation): Likewise.
+	(all_relocations_root): Likewise.
+	(all_relocations): Likewise.
+	(all_relocations_count): Likewise.
+	(update_all_relocations): Likewise.
+	(dump_relr_relocations): Add a bool argument to indicate if
+	relocations should be displayed.  Populate all_relocations if
+	do_got_section_contents is true.
+	(dump_relocations): Likewise.
+	(options): Add -G/--got-contents.
+	(usage): Show -G/--got-contents.
+	(parse_args): Support -G/--got-contents.
+	(display_relocations): Add bool argument, dump_reloc, to indicate
+	if relocations should be displayed.  Call update_all_relocations.
+	Pass dump_reloc to dump_relr_relocations and dump_relocations.
+	(process_relocs): Check do_got_section_contents.  Handle
+	do_got_section_contents for dynamic relocations.
+	(process_section_contents): Pass true to display_relocations.
+	(elf_relocation_cmp): New.
+	(display_elf_relocation_at): Likewise.
+	(process_got_section_contents): Likewise.
+	(process_object): Call process_got_section_contents.
+	* doc/binutils.texi: Document -G/--got-contents.
+
+ld/
+
+	* testsuite/ld-i386/binutils.exp: New file.
+	* testsuite/ld-i386/got-1.s: Likewise.
+	* testsuite/ld-i386/libgot-1a.rd: Likewise.
+	* testsuite/ld-i386/libgot-1b.rd: Likewise.
+	* testsuite/ld-i386/libgot-1c.rd: Likewise.
+	* testsuite/ld-i386/libgot-1d.rd: Likewise.
+	* testsuite/ld-x86-64/binutils.exp: Likewise.
+	* testsuite/ld-x86-64/got-1.s: Likewise.
+	* testsuite/ld-x86-64/libgot-1a-x32.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1a.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1b-x32.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1b.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1c-x32.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1c.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1d-x32.rd: Likewise.
+	* testsuite/ld-x86-64/libgot-1d.rd: Likewise.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  binutils/NEWS                           |   3 +
  binutils/doc/binutils.texi              |  11 +-
- binutils/readelf.c                      | 896 +++++++++++++++++++-----
+ binutils/readelf.c                      | 874 +++++++++++++++++++-----
  ld/testsuite/ld-i386/binutils.exp       |  45 ++
  ld/testsuite/ld-i386/got-1.s            |   7 +
  ld/testsuite/ld-i386/libgot-1a.rd       |   9 +
@@ -51,7 +97,7 @@ H.J.
  ld/testsuite/ld-x86-64/libgot-1c.rd     |  12 +
  ld/testsuite/ld-x86-64/libgot-1d-x32.rd |  12 +
  ld/testsuite/ld-x86-64/libgot-1d.rd     |  12 +
- 19 files changed, 1317 insertions(+), 167 deletions(-)
+ 19 files changed, 1303 insertions(+), 159 deletions(-)
  create mode 100644 ld/testsuite/ld-i386/binutils.exp
  create mode 100644 ld/testsuite/ld-i386/got-1.s
  create mode 100644 ld/testsuite/ld-i386/libgot-1a.rd
@@ -119,7 +165,7 @@ index 4543341e00c..15f31d1bcef 100644
  @itemx --section-groups
  @cindex ELF section group information
 diff --git a/binutils/readelf.c b/binutils/readelf.c
-index bb81c824ac3..15064daa969 100644
+index 68e193415f2..efd4221ef6f 100644
 --- a/binutils/readelf.c
 +++ b/binutils/readelf.c
 @@ -229,6 +229,7 @@ static bool do_dyn_syms = false;
@@ -185,7 +231,17 @@ index bb81c824ac3..15064daa969 100644
  static uint64_t
  count_relr_relocations (Filedata *          filedata,
  			Elf_Internal_Shdr * section)
-@@ -1836,7 +1878,8 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1830,6 +1872,9 @@ count_relr_relocations (Filedata *          filedata,
+   return count;
+ }
+ 
++/* If DUMP_RELOC is false, don't display RELR relocations, just collect
++   RELR relocations for displaying GOT section contents later.  */
++
+ static bool
+ dump_relr_relocations (Filedata *          filedata,
+ 		       uint64_t            relr_size,
+@@ -1838,7 +1883,8 @@ dump_relr_relocations (Filedata *          filedata,
  		       Elf_Internal_Sym *  symtab,
  		       uint64_t            nsyms,
  		       char *              strtab,
@@ -195,7 +251,7 @@ index bb81c824ac3..15064daa969 100644
  {
    uint64_t *  relrs;
    uint64_t    nentries, i;
-@@ -1861,7 +1904,8 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1860,7 +1906,8 @@ dump_relr_relocations (Filedata *          filedata,
      num_bits_in_entry = 63;
    else
      {
@@ -205,7 +261,7 @@ index bb81c824ac3..15064daa969 100644
        return false;
      }
  
-@@ -1875,6 +1919,161 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1874,6 +1921,161 @@ dump_relr_relocations (Filedata *          filedata,
    if (symtab == NULL)
      nsyms = 0;
  
@@ -214,7 +270,7 @@ index bb81c824ac3..15064daa969 100644
 +    switch (filedata->file_header.e_machine)
 +      {
 +      default:
-+	break;
++	abort ();
 +
 +      case EM_386:
 +      case EM_IAMCU:
@@ -367,7 +423,7 @@ index bb81c824ac3..15064daa969 100644
    if (symtab != NULL)
      {
        /* Symbol tables are not sorted on address, but we want a quick lookup
-@@ -1885,11 +2084,15 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1884,11 +2086,15 @@ dump_relr_relocations (Filedata *          filedata,
        nsyms = filter_display_syms (filedata, symtab, nsyms, strtab, strtablen);
      }
  
@@ -387,7 +443,7 @@ index bb81c824ac3..15064daa969 100644
    for (i = 0; i < nentries; i++)
      {
        uint64_t entry;
-@@ -1899,16 +2102,34 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1898,16 +2104,34 @@ dump_relr_relocations (Filedata *          filedata,
        else
  	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
  
@@ -428,7 +484,7 @@ index bb81c824ac3..15064daa969 100644
  	  where += relr_entsize;
  	}
        else
-@@ -1921,7 +2142,7 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1920,7 +2144,7 @@ dump_relr_relocations (Filedata *          filedata,
  	    /* This can actually happen when the linker is allowed to shrink
  	       RELR sections.  For more details see: https://reviews.llvm.org/D67164. */
  	    continue;
@@ -437,7 +493,7 @@ index bb81c824ac3..15064daa969 100644
  	    warn (_("Unusual RELR bitmap - no previous entry to set the base address\n"));
  
  	  for (j = 0; entry >>= 1; j++)
-@@ -1929,19 +2150,35 @@ dump_relr_relocations (Filedata *          filedata,
+@@ -1928,19 +2152,35 @@ dump_relr_relocations (Filedata *          filedata,
  	      {
  		uint64_t addr = where + (j * relr_entsize);
  
@@ -480,7 +536,17 @@ index bb81c824ac3..15064daa969 100644
  	  where += num_bits_in_entry * relr_entsize;
  	}
      }
-@@ -1962,7 +2199,8 @@ dump_relocations (Filedata *          filedata,
+@@ -1950,7 +2190,8 @@ dump_relr_relocations (Filedata *          filedata,
+ }
+ 
+ /* Display the contents of the relocation data found at the specified
+-   offset.  */
++   offset.  If DUMP_RELOC is false, don't display relocations, just
++   collect relocations for displaying GOT section contents later.  */
+ 
+ static bool
+ dump_relocations (Filedata *          filedata,
+@@ -1961,7 +2202,8 @@ dump_relocations (Filedata *          filedata,
  		  char *              strtab,
  		  uint64_t            strtablen,
  		  relocation_type     rel_type,
@@ -490,7 +556,7 @@ index bb81c824ac3..15064daa969 100644
  {
    size_t i;
    Elf_Internal_Rela * rels;
-@@ -1987,38 +2225,41 @@ dump_relocations (Filedata *          filedata,
+@@ -1986,26 +2228,26 @@ dump_relocations (Filedata *          filedata,
        return false;
      }
  
@@ -505,20 +571,10 @@ index bb81c824ac3..15064daa969 100644
 -	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
 -	}
 -      else
--	{
--	  if (do_wide)
--	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
--	  else
--	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
--	}
--    }
--  else
--    {
--      if (rel_type == reltype_rela)
 +      if (is_32bit_elf)
  	{
 -	  if (do_wide)
--	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
+-	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
 +	  if (rel_type == reltype_rela)
 +	    {
 +	      if (do_wide)
@@ -527,7 +583,7 @@ index bb81c824ac3..15064daa969 100644
 +		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
 +	    }
  	  else
--	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
+-	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
 +	    {
 +	      if (do_wide)
 +		printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
@@ -535,29 +591,15 @@ index bb81c824ac3..15064daa969 100644
 +		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
 +	    }
  	}
-       else
+-    }
+-  else
+-    {
+-      if (rel_type == reltype_rela)
++      else if (rel_type == reltype_rela)
  	{
--	  if (do_wide)
--	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
-+	  if (rel_type == reltype_rela)
-+	    {
-+	      if (do_wide)
-+		printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
-+	      else
-+		printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
-+	    }
- 	  else
--	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
-+	    {
-+	      if (do_wide)
-+		printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
-+	      else
-+		printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
-+	    }
- 	}
-     }
- 
-@@ -2036,18 +2277,17 @@ dump_relocations (Filedata *          filedata,
+ 	  if (do_wide)
+ 	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
+@@ -2035,18 +2277,16 @@ dump_relocations (Filedata *          filedata,
        type = get_reloc_type (filedata, inf);
        symtab_index = get_reloc_symindex  (inf);
  
@@ -575,9 +617,8 @@ index bb81c824ac3..15064daa969 100644
 -		  : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
 -		  offset, inf);
 +	  if (is_32bit_elf)
-+	    printf ("%8.8lx  %8.8lx ",
-+		    (unsigned long) offset & 0xffffffff,
-+		    (unsigned long) inf & 0xffffffff);
++	    printf ("%8.8" PRIx32 "  %8.8" PRIx32 " ",
++		    (uint32_t) offset, (uint32_t) inf);
 +	  else
 +	    printf (do_wide
 +		    ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
@@ -586,7 +627,7 @@ index bb81c824ac3..15064daa969 100644
  	}
  
        switch (filedata->file_header.e_machine)
-@@ -2397,10 +2637,15 @@ dump_relocations (Filedata *          filedata,
+@@ -2396,10 +2636,15 @@ dump_relocations (Filedata *          filedata,
  	  break;
  	}
  
@@ -606,7 +647,7 @@ index bb81c824ac3..15064daa969 100644
  
        if (filedata->file_header.e_machine == EM_ALPHA
  	  && rtype != NULL
-@@ -2419,23 +2664,29 @@ dump_relocations (Filedata *          filedata,
+@@ -2418,23 +2663,29 @@ dump_relocations (Filedata *          filedata,
  	    default: rtype = NULL;
  	    }
  
@@ -646,7 +687,7 @@ index bb81c824ac3..15064daa969 100644
  	    }
  	  else
  	    {
-@@ -2454,7 +2705,8 @@ dump_relocations (Filedata *          filedata,
+@@ -2453,7 +2704,8 @@ dump_relocations (Filedata *          filedata,
  					     &sym_info,
  					     &vna_other);
  
@@ -656,7 +697,7 @@ index bb81c824ac3..15064daa969 100644
  
  	      if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
  		{
-@@ -2479,13 +2731,30 @@ dump_relocations (Filedata *          filedata,
+@@ -2478,13 +2730,30 @@ dump_relocations (Filedata *          filedata,
  		  else
  		    name = strtab + psym->st_name;
  
@@ -693,7 +734,7 @@ index bb81c824ac3..15064daa969 100644
  		{
  		  print_vma (psym->st_value, LONG_HEX);
  
-@@ -2500,25 +2769,49 @@ dump_relocations (Filedata *          filedata,
+@@ -2499,25 +2768,49 @@ dump_relocations (Filedata *          filedata,
  		    sec_name = printable_section_name_from_index
  		      (filedata, psym->st_shndx, NULL);
  
@@ -736,7 +777,7 @@ index bb81c824ac3..15064daa969 100644
 +				? "@@%s" : "@%s",
 +				version_string);
 +		    }
-+		  if (all_relocations)
++		  if (do_got_section_contents)
 +		    {
 +		      if (version_string)
 +			symbol_name = concat (strtab + psym->st_name,
@@ -753,7 +794,7 @@ index bb81c824ac3..15064daa969 100644
  		{
  		  uint64_t off = rels[i].r_addend;
  
-@@ -2529,7 +2822,7 @@ dump_relocations (Filedata *          filedata,
+@@ -2528,7 +2821,7 @@ dump_relocations (Filedata *          filedata,
  		}
  	    }
  	}
@@ -762,7 +803,7 @@ index bb81c824ac3..15064daa969 100644
  	{
  	  uint64_t off = rels[i].r_addend;
  
-@@ -2540,37 +2833,50 @@ dump_relocations (Filedata *          filedata,
+@@ -2539,37 +2832,50 @@ dump_relocations (Filedata *          filedata,
  	    printf ("%" PRIx64, off);
  	}
  
@@ -837,7 +878,7 @@ index bb81c824ac3..15064daa969 100644
  	}
      }
  
-@@ -6112,6 +6418,7 @@ static struct option options[] =
+@@ -6111,6 +6417,7 @@ static struct option options[] =
    {"use-dynamic",      no_argument, 0, 'D'},
    {"dynamic",	       no_argument, 0, 'd'},
    {"headers",	       no_argument, 0, 'e'},
@@ -845,7 +886,7 @@ index bb81c824ac3..15064daa969 100644
    {"section-groups",   no_argument, 0, 'g'},
    {"help",	       no_argument, 0, 'H'},
    {"file-header",      no_argument, 0, 'h'},
-@@ -6184,6 +6491,8 @@ usage (FILE * stream)
+@@ -6183,6 +6490,8 @@ usage (FILE * stream)
    fprintf (stream, _("\
       --sections          An alias for --section-headers\n"));
    fprintf (stream, _("\
@@ -854,7 +895,7 @@ index bb81c824ac3..15064daa969 100644
    -g --section-groups    Display the section groups\n"));
    fprintf (stream, _("\
    -t --section-details   Display the section details\n"));
-@@ -6418,7 +6727,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+@@ -6417,7 +6726,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
      usage (stderr);
  
    while ((c = getopt_long
@@ -863,7 +904,7 @@ index bb81c824ac3..15064daa969 100644
      {
        switch (c)
  	{
-@@ -6442,8 +6751,13 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+@@ -6441,8 +6750,13 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
  	  do_histogram = true;
  	  do_arch = true;
  	  do_notes = true;
@@ -877,7 +918,7 @@ index bb81c824ac3..15064daa969 100644
  	case 'g':
  	  do_section_groups = true;
  	  break;
-@@ -9438,7 +9752,8 @@ rel_type_from_sh_type (unsigned int sh_type)
+@@ -9437,7 +9751,8 @@ rel_type_from_sh_type (unsigned int sh_type)
  
  static bool
  display_relocations (Elf_Internal_Shdr *  section,
@@ -887,7 +928,7 @@ index bb81c824ac3..15064daa969 100644
  {
    relocation_type rel_type = rel_type_from_sh_type (section->sh_type);
  
-@@ -9450,19 +9765,23 @@ display_relocations (Elf_Internal_Shdr *  section,
+@@ -9449,19 +9764,23 @@ display_relocations (Elf_Internal_Shdr *  section,
    if (rel_size == 0)
      return false;
  
@@ -921,7 +962,7 @@ index bb81c824ac3..15064daa969 100644
  
    if (rel_type == reltype_relr)
      {
-@@ -9471,26 +9790,33 @@ display_relocations (Elf_Internal_Shdr *  section,
+@@ -9470,26 +9789,33 @@ display_relocations (Elf_Internal_Shdr *  section,
  	 the number of words in the compressed RELR format.  So also provide
  	 the number of locations affected.  */
  
@@ -969,13 +1010,13 @@ index bb81c824ac3..15064daa969 100644
    Elf_Internal_Shdr * symsec;
    Elf_Internal_Sym *  symtab = NULL;
    uint64_t            nsyms = 0;
-@@ -9522,12 +9848,15 @@ display_relocations (Elf_Internal_Shdr *  section,
-   bool res;
- 
-   if (rel_type == reltype_relr)
--    res = dump_relr_relocations (filedata, section, symtab, nsyms, strtab, strtablen);
-+    res = dump_relr_relocations (filedata, section, symtab, nsyms,
-+				 strtab, strtablen, dump_reloc);
+@@ -9524,12 +9850,15 @@ display_relocations (Elf_Internal_Shdr *  section,
+     res = dump_relr_relocations (filedata, section->sh_size,
+ 				 section->sh_entsize,
+ 				 section->sh_offset,
+-				 symtab, nsyms, strtab, strtablen);
++				 symtab, nsyms, strtab, strtablen,
++				 dump_reloc);
    else
      res = dump_relocations (filedata, rel_offset, rel_size,
  			    symtab, nsyms, strtab, strtablen,
@@ -987,7 +1028,7 @@ index bb81c824ac3..15064daa969 100644
    free (strtab);
    free (symtab);
  
-@@ -9541,14 +9870,16 @@ process_relocs (Filedata * filedata)
+@@ -9543,14 +9872,16 @@ process_relocs (Filedata * filedata)
  {
    uint64_t rel_size;
    uint64_t rel_offset;
@@ -1005,55 +1046,20 @@ index bb81c824ac3..15064daa969 100644
        bool  has_dynamic_reloc;
        unsigned int i;
  
-@@ -9556,57 +9887,97 @@ process_relocs (Filedata * filedata)
- 
-       for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
- 	{
-+	  rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
-+
-+	  if (!rel_size)
-+	    continue;
-+
-+	  has_dynamic_reloc = true;
-+
- 	  rel_type = dynamic_relocations [i].rel_type;
- 	  name = dynamic_relocations [i].name;
--	  rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
- 	  rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc];
- 
--	  if (rel_size)
--	    has_dynamic_reloc = true;
--
- 	  if (rel_type == reltype_unknown)
- 	    {
--	      if (dynamic_relocations [i].reloc == DT_JMPREL)
--		switch (filedata->dynamic_info[DT_PLTREL])
--		  {
--		  case DT_REL:
--		    rel_type = reltype_rel;
--		    break;
--		  case DT_RELA:
--		    rel_type = reltype_rela;
--		    break;
--		  }
-+	      if (dynamic_relocations [i].reloc != DT_JMPREL)
-+		abort ();
-+
-+	      switch (filedata->dynamic_info[DT_PLTREL])
-+		{
-+		default:
-+		  printf (_("<missing dynamic or corrupt tag: DT_PLTREL>\n"));
-+		  continue;
-+		case DT_REL:
-+		  rel_type = reltype_rel;
-+		  break;
-+		case DT_RELA:
-+		  rel_type = reltype_rela;
-+		  break;
-+		}
+@@ -9584,16 +9915,37 @@ process_relocs (Filedata * filedata)
+ 		}
  	    }
  
--	  if (rel_size)
+-	  if (filedata->is_separate)
+-	    printf
+-	      (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
+-		 " contains %" PRId64 " bytes:\n"),
+-	       filedata->file_name, name, rel_offset, rel_size);
+-	  else
+-	    printf
+-	      (_("\n'%s' relocation section at offset %#" PRIx64
+-		 " contains %" PRId64 " bytes:\n"),
+-	       name, rel_offset, rel_size);
 +	  switch (rel_type)
 +	    {
 +	    default:
@@ -1073,22 +1079,38 @@ index bb81c824ac3..15064daa969 100644
 +	    }
 +
 +	  if (do_reloc)
- 	    {
- 	      if (filedata->is_separate)
- 		printf
--		  (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
--		     " contains %" PRId64 " bytes:\n"),
++	    {
++	      if (filedata->is_separate)
++		printf
 +		  (_("\nIn linked file '%s' section '%s' at offset"
 +		     "%#" PRIx64 " contains %" PRId64 " bytes:\n"),
- 		   filedata->file_name, name, rel_offset, rel_size);
- 	      else
- 		printf
- 		  (_("\n'%s' relocation section at offset %#" PRIx64
- 		     " contains %" PRId64 " bytes:\n"),
- 		   name, rel_offset, rel_size);
++		   filedata->file_name, name, rel_offset, rel_size);
++	      else
++		printf
++		  (_("\n'%s' relocation section at offset %#" PRIx64
++		     " contains %" PRId64 " bytes:\n"),
++		   name, rel_offset, rel_size);
 +	    }
-+
-+	  if (rel_type != reltype_relr)
+ 
+ 	  if (rel_type == reltype_relr)
+ 	    dump_relr_relocations (filedata,
+@@ -9603,24 +9955,37 @@ process_relocs (Filedata * filedata)
+ 				   filedata->dynamic_symbols,
+ 				   filedata->num_dynamic_syms,
+ 				   filedata->dynamic_strings,
+-				   filedata->dynamic_strings_length);
++				   filedata->dynamic_strings_length,
++				   do_reloc);
+ 	  else
+-	    dump_relocations (filedata,
+-			      offset_from_vma (filedata, rel_offset,
+-					       rel_size),
+-			      rel_size,
+-			      filedata->dynamic_symbols,
+-			      filedata->num_dynamic_syms,
+-			      filedata->dynamic_strings,
+-			      filedata->dynamic_strings_length,
+-			      rel_type, true /* is_dynamic */);
 +	    {
 +	      if (rel_entsz == 0)
 +		{
@@ -1098,33 +1120,30 @@ index bb81c824ac3..15064daa969 100644
 +		}
 +
 +	      update_all_relocations (rel_size / rel_entsz);
- 
- 	      dump_relocations (filedata,
--				offset_from_vma (filedata, rel_offset, rel_size),
++
++	      dump_relocations (filedata,
 +				offset_from_vma (filedata, rel_offset,
 +						 rel_size),
- 				rel_size,
- 				filedata->dynamic_symbols,
- 				filedata->num_dynamic_syms,
- 				filedata->dynamic_strings,
- 				filedata->dynamic_strings_length,
--				rel_type, true /* is_dynamic */);
++				rel_size,
++				filedata->dynamic_symbols,
++				filedata->num_dynamic_syms,
++				filedata->dynamic_strings,
++				filedata->dynamic_strings_length,
 +				rel_type, true /* is_dynamic */,
 +				do_reloc);
- 	    }
++	    }
  	}
  
-       if (is_ia64_vms (filedata))
--        if (process_ia64_vms_dynamic_relocs (filedata))
-+	if (process_ia64_vms_dynamic_relocs (filedata))
- 	  has_dynamic_reloc = true;
+       if (is_ia64_vms (filedata)
+ 	  && process_ia64_vms_dynamic_relocs (filedata))
+ 	has_dynamic_reloc = true;
  
 -      if (! has_dynamic_reloc)
 +      if (do_reloc && ! has_dynamic_reloc)
  	{
  	  if (filedata->is_separate)
  	    printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
-@@ -9625,11 +9996,11 @@ process_relocs (Filedata * filedata)
+@@ -9639,11 +10004,11 @@ process_relocs (Filedata * filedata)
  	   i < filedata->file_header.e_shnum;
  	   i++, section++)
  	{
@@ -1138,7 +1157,7 @@ index bb81c824ac3..15064daa969 100644
  	{
  	  /* Users sometimes forget the -D option, so try to be helpful.  */
  	  for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
-@@ -17613,7 +17984,7 @@ process_section_contents (Filedata * filedata)
+@@ -17627,7 +17992,7 @@ process_section_contents (Filedata * filedata)
  	    case SHT_RELA:
  	    case SHT_REL:
  	    case SHT_RELR:
@@ -1147,15 +1166,15 @@ index bb81c824ac3..15064daa969 100644
  	      break;
  
  	    case SHT_NOTE:
-@@ -17704,6 +18075,196 @@ process_section_contents (Filedata * filedata)
+@@ -17718,6 +18083,196 @@ process_section_contents (Filedata * filedata)
    return res;
  }
  
 +static int
 +elf_relocation_cmp (const void *p, const void *q)
 +{
-+  elf_relocation *rp = (elf_relocation *) p;
-+  elf_relocation *rq = (elf_relocation *) q;
++  const elf_relocation *rp = (const elf_relocation *) p;
++  const elf_relocation *rq = (const elf_relocation *) q;
 +
 +  return (rp->r_offset > rq->r_offset
 +	  ? 1
@@ -1344,7 +1363,7 @@ index bb81c824ac3..15064daa969 100644
  static void
  process_mips_fpe_exception (int mask)
  {
-@@ -23819,6 +24380,9 @@ process_object (Filedata * filedata)
+@@ -23833,6 +24388,9 @@ process_object (Filedata * filedata)
    if (! process_section_contents (filedata))
      res = false;
  
@@ -1435,7 +1454,7 @@ index 00000000000..b8609b8fbe2
 +#pass
 diff --git a/ld/testsuite/ld-i386/libgot-1b.rd b/ld/testsuite/ld-i386/libgot-1b.rd
 new file mode 100644
-index 00000000000..070fa424d4d
+index 00000000000..faebdb49e0d
 --- /dev/null
 +++ b/ld/testsuite/ld-i386/libgot-1b.rd
 @@ -0,0 +1,119 @@
@@ -1549,50 +1568,50 @@ index 00000000000..070fa424d4d
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
++ +[0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200                        20016c
-+ +[a-f0-9]+: 00200204                        0
-+ +[a-f0-9]+: 00200208                        0
-+ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
++ +[0-9]+: 00200200                        20016c
++ +[0-9]+: 00200204                        0
++ +[0-9]+: 00200208                        0
++ +[0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
 +#pass
 diff --git a/ld/testsuite/ld-i386/libgot-1c.rd b/ld/testsuite/ld-i386/libgot-1c.rd
 new file mode 100644
-index 00000000000..a69279ab8cc
+index 00000000000..374b03f1658
 --- /dev/null
 +++ b/ld/testsuite/ld-i386/libgot-1c.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 + Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 002001fc R_386_GLOB_DAT    foo \+ 0
++ +[0-9]+: 002001fc R_386_GLOB_DAT    foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 + Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200                   20016c
-+ +[a-f0-9]+: 00200204                   0
-+ +[a-f0-9]+: 00200208                   0
-+ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT   bar \+ 156
++ +[0-9]+: 00200200                   20016c
++ +[0-9]+: 00200204                   0
++ +[0-9]+: 00200208                   0
++ +[0-9]+: 0020020c R_386_JUMP_SLOT   bar \+ 156
 +#pass
 diff --git a/ld/testsuite/ld-i386/libgot-1d.rd b/ld/testsuite/ld-i386/libgot-1d.rd
 new file mode 100644
-index 00000000000..af5e3df0153
+index 00000000000..632b47be743
 --- /dev/null
 +++ b/ld/testsuite/ld-i386/libgot-1d.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
++ +[0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200                        20016c
-+ +[a-f0-9]+: 00200204                        0
-+ +[a-f0-9]+: 00200208                        0
-+ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
++ +[0-9]+: 00200200                        20016c
++ +[0-9]+: 00200204                        0
++ +[0-9]+: 00200208                        0
++ +[0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/binutils.exp b/ld/testsuite/ld-x86-64/binutils.exp
 new file mode 100644
@@ -1704,7 +1723,7 @@ index 00000000000..8ed447003c7
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1b-x32.rd b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
 new file mode 100644
-index 00000000000..2245275b980
+index 00000000000..f900303fcce
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
 @@ -0,0 +1,119 @@
@@ -1818,18 +1837,18 @@ index 00000000000..2245275b980
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
++ +[0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200208                        20016c
-+ +[a-f0-9]+: 00200210                        0
-+ +[a-f0-9]+: 00200218                        0
-+ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
++ +[0-9]+: 00200208                        20016c
++ +[0-9]+: 00200210                        0
++ +[0-9]+: 00200218                        0
++ +[0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1b.rd b/ld/testsuite/ld-x86-64/libgot-1b.rd
 new file mode 100644
-index 00000000000..9d5cc030f72
+index 00000000000..18e432475fc
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1b.rd
 @@ -0,0 +1,119 @@
@@ -1943,89 +1962,87 @@ index 00000000000..9d5cc030f72
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
++ +[0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 0000000000200348                        200220
-+ +[a-f0-9]+: 0000000000200350                        0
-+ +[a-f0-9]+: 0000000000200358                        0
-+ +[a-f0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
++ +[0-9]+: 0000000000200348                        200220
++ +[0-9]+: 0000000000200350                        0
++ +[0-9]+: 0000000000200358                        0
++ +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1c-x32.rd b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
 new file mode 100644
-index 00000000000..bec8ac79e07
+index 00000000000..a3bdacf1fa4
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 + Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT foo \+ 0
++ +[0-9]+: 00200200 R_X86_64_GLOB_DAT foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 + Index:  Address      Reloc        Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200208                   20016c
-+ +[a-f0-9]+: 00200210                   0
-+ +[a-f0-9]+: 00200218                   0
-+ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLO bar \+ 0
++ +[0-9]+: 00200208                   20016c
++ +[0-9]+: 00200210                   0
++ +[0-9]+: 00200218                   0
++ +[0-9]+: 00200220 R_X86_64_JUMP_SLO bar \+ 0
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1c.rd b/ld/testsuite/ld-x86-64/libgot-1c.rd
 new file mode 100644
-index 00000000000..4944b3111c3
+index 00000000000..fc1a2605848
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1c.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 + Index:    Address       Reloc         Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 000000200340 R_X86_64_GLOB_DAT foo \+ 0
++ +[0-9]+: 000000200340 R_X86_64_GLOB_DAT foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 + Index:    Address       Reloc         Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 000000200348                   200220
-+ +[a-f0-9]+: 000000200350                   0
-+ +[a-f0-9]+: 000000200358                   0
-+ +[a-f0-9]+: 000000200360 R_X86_64_JUMP_SLO bar \+ 0
++ +[0-9]+: 000000200348                   200220
++ +[0-9]+: 000000200350                   0
++ +[0-9]+: 000000200358                   0
++ +[0-9]+: 000000200360 R_X86_64_JUMP_SLO bar \+ 0
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1d-x32.rd b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
 new file mode 100644
-index 00000000000..fdad77aab84
+index 00000000000..3e2693e0f52
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
++ +[0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:  Address      Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 00200208                        20016c
-+ +[a-f0-9]+: 00200210                        0
-+ +[a-f0-9]+: 00200218                        0
-+ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
++ +[0-9]+: 00200208                        20016c
++ +[0-9]+: 00200210                        0
++ +[0-9]+: 00200218                        0
++ +[0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
 diff --git a/ld/testsuite/ld-x86-64/libgot-1d.rd b/ld/testsuite/ld-x86-64/libgot-1d.rd
 new file mode 100644
-index 00000000000..2e0a6c1e0db
+index 00000000000..341840e9081
 --- /dev/null
 +++ b/ld/testsuite/ld-x86-64/libgot-1d.rd
 @@ -0,0 +1,12 @@
 +
 +Global Offset Table '.got' contains 1 entry:
 +   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
++ +[0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
 +
 +Global Offset Table '.got.plt' contains 4 entries:
 +   Index:      Address          Reloc             Sym. Name \+ Addend/Value
-+ +[a-f0-9]+: 0000000000200348                        200220
-+ +[a-f0-9]+: 0000000000200350                        0
-+ +[a-f0-9]+: 0000000000200358                        0
-+ +[a-f0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
++ +[0-9]+: 0000000000200348                        200220
++ +[0-9]+: 0000000000200350                        0
++ +[0-9]+: 0000000000200358                        0
++ +[0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
 +#pass
-
-base-commit: f5493d6c96da9faf5f16d748cf6c899f0836b12d
 -- 
 2.51.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-27 16:26 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-27 16:26 UTC (permalink / raw
  To: gentoo-commits

commit:     868bc25b604fb6e99c05dfb5e871b6014dcf14f8
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 27 16:25:49 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 27 16:25:49 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=868bc25b

9999: drop conflicting test patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-Adjust-testsuites-for-flto-and-without-g.patch | 210 ---------------------
 1 file changed, 210 deletions(-)

diff --git a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
deleted file mode 100644
index e2735aa..0000000
--- a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
+++ /dev/null
@@ -1,210 +0,0 @@
-From 3d6a0b4a3f6b0582781979062cc6730e858997ae Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 10 Mar 2025 17:07:16 -0700
-Subject: [PATCH 5/5] Adjust testsuites for -flto and without -g
-
-Adjust testsuites for binutils built with -flto and without -g:
-
-1. Pass -fno-lto to objcopy tests which don't work with LTO.
-2. Update gprof testsuite to avoid LTO and compile with -g for line
-number info checked by tst-gmon-gprof-l.sh.
-3. Append $NOLTO_CFLAGS in ctf.exp.
-4. For libctf, filter out -flto in CFLAGS for "make check" and also
-prune lto-wrapper warnings.
-
-binutils/
-
-	PR binutils/32773
-	* testsuite/binutils-all/objcopy.exp (no_lto_flags): New.
-	(strip_test): Pass $no_lto_flags to target_compile.
-	(strip_test_with_saving_a_symbol): Likewise.
-	(objcopy_test_without_global_symbol): Likewise.
-
-gprof/
-
-	PR binutils/32773
-	PR gprof/32779
-	* testsuite/Makefile.am (GPROF_FLAGS): Add -g.
-	(COMPILE): Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS)".
-	(LINK) Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS)
-	$(LDFLAGS) -o $@".
-	* testsuite/Makefile.in: Regenerated.
-
-ld/
-
-	PR binutils/32773
-	* testsuite/ld-ctf/ctf.exp (old_CFLAGS): New.
-	(CFLAGS_FOR_TARGET): Append $NOLTO_CFLAGS.
-
-libctf/
-
-	PR binutils/32773
-	* Makefile.am (check-DEJAGNU): Filter out -flto in CFLAGS.
-	* Makefile.in: Regenerated.
-	* testsuite/lib/ctf-lib.exp (prune_warnings_lto): New.
-	(run_lookup_test): Replace prune_warnings with
-	prune_warnings_lto.
-	(run_lookup_test): Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- binutils/testsuite/binutils-all/objcopy.exp | 14 +++++++++++---
- ld/testsuite/ld-ctf/ctf.exp                 |  5 +++++
- libctf/Makefile.am                          |  3 ++-
- libctf/Makefile.in                          |  3 ++-
- libctf/testsuite/lib/ctf-lib.exp            | 14 ++++++++++++--
- 5 files changed, 32 insertions(+), 7 deletions(-)
-
-diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
-index 6aa6d2d9fe7..9371d928d60 100644
---- a/binutils/testsuite/binutils-all/objcopy.exp
-+++ b/binutils/testsuite/binutils-all/objcopy.exp
-@@ -36,6 +36,11 @@ if ![is_remote host] {
-     set copyfile copy
- }
- 
-+set no_lto_flags "additional_flags=-fno-lto"
-+if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object $no_lto_flags] != "" } {
-+    set no_lto_flags ""
-+}
-+
- # Test that objcopy does not modify a file when copying it.
- # "object" or "executable" values for type are supported.
- 
-@@ -516,10 +521,11 @@ proc strip_test { } {
-     global srcdir
-     global subdir
-     global READELF
-+    global no_lto_flags
- 
-     set test "strip"
- 
--    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
-+    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
- 	untested $test
- 	return
-     }
-@@ -628,10 +634,11 @@ proc strip_test_with_saving_a_symbol { } {
-     global NMFLAGS
-     global srcdir
-     global subdir
-+    global no_lto_flags
- 
-     set test "strip with saving a symbol"
- 
--    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
-+    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
- 	untested $test
- 	return
-     }
-@@ -1462,10 +1469,11 @@ proc objcopy_test_without_global_symbol { } {
-     global OBJDUMPFLAGS
-     global srcdir
-     global subdir
-+    global no_lto_flags
- 
-     set test "strip without global symbol "
- 
--    if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } {
-+    if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object "debug $no_lto_flags"] != "" } {
- 	untested $test
- 	return
-     }
-diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
-index c314f2995af..08b47d2db18 100644
---- a/ld/testsuite/ld-ctf/ctf.exp
-+++ b/ld/testsuite/ld-ctf/ctf.exp
-@@ -33,6 +33,9 @@ if ![check_shared_lib_support] {
-     return 0
- }
- 
-+set old_CFLAGS "$CFLAGS_FOR_TARGET"
-+append CFLAGS_FOR_TARGET " $NOLTO_CFLAGS"
-+
- if {[info exists env(LC_ALL)]} {
-     set old_lc_all $env(LC_ALL)
- }
-@@ -55,3 +58,5 @@ if {[info exists old_lc_all]} {
- } else {
-     unset env(LC_ALL)
- }
-+
-+set CFLAGS_FOR_TARGET "$old_CFLAGS"
-diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index 12301277275..26980667cc3 100644
---- a/libctf/Makefile.am
-+++ b/libctf/Makefile.am
-@@ -114,11 +114,12 @@ check-DEJAGNU: site.exp development.exp
- 	else \
- 	  TEST_CROSS=yes; \
- 	fi; \
-+	TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
- 	runtest=$(RUNTEST); \
- 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
- 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
- 		CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
--		CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
-+		CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
- 		LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
- 	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
- 	fi
-diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 639d7147b02..812134c70c9 100644
---- a/libctf/Makefile.in
-+++ b/libctf/Makefile.in
-@@ -1826,11 +1826,12 @@ check-DEJAGNU: site.exp development.exp
- 	else \
- 	  TEST_CROSS=yes; \
- 	fi; \
-+	TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
- 	runtest=$(RUNTEST); \
- 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
- 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
- 		CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
--		CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
-+		CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
- 		LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
- 	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
- 	fi
-diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp
-index 64d2a40ad9f..6d3b75e22a2 100644
---- a/libctf/testsuite/lib/ctf-lib.exp
-+++ b/libctf/testsuite/lib/ctf-lib.exp
-@@ -54,6 +54,16 @@ proc compile_link_one_host_cc { src output additional_args } {
-     return [run_native_host_cmd "./libtool --quiet --tag=CC --mode=link $CC $CFLAGS $src -o $output $additional_args" ]
- }
- 
-+# Also prune lto-wrapper warnings, like
-+# lto-wrapper: warning: using serial compilation of 16 LTRANS jobs
-+# lto-wrapper: note: see the '-flto' option documentation for more information
-+#
-+proc prune_warnings_lto { msg } {
-+    set msgx "lto-wrapper: (?:warning\:\[^\n\r\]+|note\:\[^\n\r\]+)"
-+    regsub -all "$msgx\[\n\r\]*" $msg {} msg
-+    return [prune_warnings $msg]
-+}
-+
- # run_lookup_test FILE
- #
- # Compile with the host compiler and link a .c file into a "lookup" binary, then
-@@ -208,7 +218,7 @@ proc run_lookup_test { name } {
-     set testname $file4log
- 
-     # Compile and link the lookup program.
--    set comp_output [prune_warnings [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
-+    set comp_output [prune_warnings_lto [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
- 
-     if { $comp_output != ""} {
- 	send_log "compilation of lookup program $opts(lookup) failed with <$comp_output>"
-@@ -244,7 +254,7 @@ proc run_lookup_test { name } {
- 	    }
- 	}
- 
--	set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
-+	set comp_output [prune_warnings_lto [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
- 
- 	if { $comp_output != ""} {
- 	    send_log "compilation of CTF program [concat $src] failed with <$comp_output>"
--- 
-2.49.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-27  4:05 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-27  4:05 UTC (permalink / raw
  To: gentoo-commits

commit:     bf81d5cb905f3a2b53b3f49e5397cd27e4ad5302
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 27 04:05:20 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 27 04:05:20 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=bf81d5cb

9999: drop TLSDESC patch merged upstream

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ut-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch | 931 ---------------------
 1 file changed, 931 deletions(-)

diff --git a/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch b/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch
deleted file mode 100644
index 1df59c2..0000000
--- a/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch
+++ /dev/null
@@ -1,931 +0,0 @@
-From 0b2d86d4c1c26b6e1d48a5dc7842b21698d80abc Mon Sep 17 00:00:00 2001
-Message-ID: <0b2d86d4c1c26b6e1d48a5dc7842b21698d80abc.1756090103.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 24 Aug 2025 14:43:44 -0700
-Subject: [PATCH] x86: Don't put R_386_TLS_DESC/R_X86_64_TLSDESC in
- .rel.plt/.rela.plt
-
-Since lazy tlsdesc relocation has data races:
-
-https://sourceware.org/bugzilla/show_bug.cgi?id=27137
-
-put R_386_TLS_DESC and R_X86_64_TLSDESC relocation in .rela.tls/.rel.tls
-section, instead of .rel.plt/.rela.plt section.
-
-Tested with glibc/i686 and glibc/x86-64 compiled with -mtls-dialect=gnu2
-as well as GCC 16 configured with --with-tls=gnu2.
-
-bfd/
-
-	PR ld/28387
-	* elf32-i386.c (elf_i386_relocate_section): Put R_386_TLS_DESC
-	in rel_tls_desc instead of elf.srelplt.
-	* elf64-x86-64.c (elf_x86_64_relocate_section): Put
-	R_X86_64_TLSDESC in rel_tls_desc instead of elf.srelplt.
-	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Use rel_tls_desc,
-	instead of elf.srelplt, for GOT_TLS_GDESC_P.
-	(_bfd_elf_x86_get_reloc_section): New function.
-	(_bfd_x86_elf_late_size_sections): Use rel_tls_desc, instead of
-	elf.srelplt, for GOT_TLS_GDESC_P.  Remove next_tls_desc_index.
-	(_bfd_x86_elf_link_setup_gnu_properties): Allocate
-	.rela.tls/.rel.tls section for rel_tls_desc.
-	* elfxx-x86.h (elf_x86_link_hash_table): Add rel_tls_desc.
-	Remove next_tls_desc_index.
-	(_bfd_elf_x86_get_reloc_section): New.
-	(elf_backend_get_reloc_section): Likewise.
-
-ld/
-
-	PR ld/28387
-	* emulparams/elf32_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): New.
-	* emulparams/elf_i386.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
-	* emulparams/elf_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
-	* testsuite/ld-i386/i386.exp: Run pr28387.
-	* testsuite/ld-i386/pr17057.d: Adjusted
-	* testsuite/ld-i386/tlsdesc.rd: Likewise.
-	* testsuite/ld-i386/tlsdesc2.d: Likewise.
-	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
-	* testsuite/ld-x86-64/tlsdesc.pd: Likewise.
-	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
-	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
-	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
-	* testsuite/ld-i386/pr28387.d: New file.
-	* testsuite/ld-i386/pr28387.s: Likewise.
-	* testsuite/ld-x86-64/pr28387-x32.d: Likewise.
-	* testsuite/ld-x86-64/pr28387.d: Likewise.
-	* testsuite/ld-x86-64/pr28387.s: Likewise.
-	* testsuite/ld-x86-64/x86-64.exp: Run pr28387 and pr28387-x32.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf32-i386.c                     |  10 +-
- bfd/elf64-x86-64.c                   |   2 +-
- bfd/elfxx-x86.c                      |  23 ++++-
- bfd/elfxx-x86.h                      |  13 ++-
- ld/emulparams/elf32_x86_64.sh        |   2 +
- ld/emulparams/elf_i386.sh            |   2 +
- ld/emulparams/elf_x86_64.sh          |   2 +
- ld/testsuite/ld-i386/i386.exp        |   1 +
- ld/testsuite/ld-i386/pr17057.d       |   7 +-
- ld/testsuite/ld-i386/pr28387.d       |  35 +++++++
- ld/testsuite/ld-i386/pr28387.s       |  12 +++
- ld/testsuite/ld-i386/tlsdesc.rd      | 106 ++++++++++----------
- ld/testsuite/ld-i386/tlsdesc2.d      |   3 +-
- ld/testsuite/ld-i386/tlsgdesc.rd     |   8 +-
- ld/testsuite/ld-x86-64/pr28387-x32.d |  36 +++++++
- ld/testsuite/ld-x86-64/pr28387.d     |  35 +++++++
- ld/testsuite/ld-x86-64/pr28387.s     |  11 +++
- ld/testsuite/ld-x86-64/tlsdesc.pd    |   8 +-
- ld/testsuite/ld-x86-64/tlsdesc.rd    | 141 +++++++++++++--------------
- ld/testsuite/ld-x86-64/tlsdesc2.d    |   4 +-
- ld/testsuite/ld-x86-64/tlsgdesc.rd   |   8 +-
- ld/testsuite/ld-x86-64/x86-64.exp    |   2 +
- 22 files changed, 309 insertions(+), 162 deletions(-)
- create mode 100644 ld/testsuite/ld-i386/pr28387.d
- create mode 100644 ld/testsuite/ld-i386/pr28387.s
- create mode 100644 ld/testsuite/ld-x86-64/pr28387-x32.d
- create mode 100644 ld/testsuite/ld-x86-64/pr28387.d
- create mode 100644 ld/testsuite/ld-x86-64/pr28387.s
-
-diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
-index 657563f2f4f..4b99b8e0202 100644
---- a/bfd/elf32-i386.c
-+++ b/bfd/elf32-i386.c
-@@ -3163,7 +3163,6 @@ elf_i386_relocate_section (bfd *output_bfd,
- 
- 	      if (GOT_TLS_GDESC_P (tls_type))
- 		{
--		  bfd_byte *loc;
- 		  outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
- 		  BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
- 			      <= htab->elf.sgotplt->size);
-@@ -3171,13 +3170,8 @@ elf_i386_relocate_section (bfd *output_bfd,
- 				     + htab->elf.sgotplt->output_offset
- 				     + offplt
- 				     + htab->sgotplt_jump_table_size);
--		  sreloc = htab->elf.srelplt;
--		  loc = sreloc->contents;
--		  loc += (htab->next_tls_desc_index++
--			  * sizeof (Elf32_External_Rel));
--		  BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
--			      <= sreloc->contents + sreloc->size);
--		  bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
-+		  sreloc = htab->rel_tls_desc;
-+		  elf_append_rel (output_bfd, sreloc, &outrel);
- 		  if (indx == 0)
- 		    {
- 		      BFD_ASSERT (! unresolved_reloc);
-diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index 580975b6d67..4f0e97c4a9a 100644
---- a/bfd/elf64-x86-64.c
-+++ b/bfd/elf64-x86-64.c
-@@ -4627,7 +4627,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
- 				     + htab->elf.sgotplt->output_offset
- 				     + offplt
- 				     + htab->sgotplt_jump_table_size);
--		  sreloc = htab->elf.srelplt;
-+		  sreloc = htab->rel_tls_desc;
- 		  if (indx == 0)
- 		    outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
- 		  else
-diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index 3de48397e78..6dc15864833 100644
---- a/bfd/elfxx-x86.c
-+++ b/bfd/elfxx-x86.c
-@@ -366,7 +366,7 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
- 	htab->elf.srelgot->size += htab->sizeof_reloc;
-       if (GOT_TLS_GDESC_P (tls_type))
- 	{
--	  htab->elf.srelplt->size += htab->sizeof_reloc;
-+	  htab->rel_tls_desc->size += htab->sizeof_reloc;
- 	  if (bed->target_id == X86_64_ELF_DATA)
- 	    htab->elf.tlsdesc_plt = (bfd_vma) -1;
- 	}
-@@ -2157,6 +2157,16 @@ _bfd_elf_x86_finish_relative_relocs (struct bfd_link_info *info)
-   return true;
- }
- 
-+asection *
-+_bfd_elf_x86_get_reloc_section (bfd *abfd, const char *name)
-+{
-+  /* Treat .rel.tls/.rela.tls section the same as .rel.plt/.rela.plt
-+     section.  */
-+  if (strcmp (name, ".tls") == 0)
-+    name = ".plt";
-+  return _bfd_elf_plt_get_reloc_section (abfd, name);
-+}
-+
- bool
- _bfd_elf_x86_valid_reloc_p (asection *input_section,
- 			    struct bfd_link_info *info,
-@@ -2376,7 +2386,7 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
- 		    srel->size += htab->sizeof_reloc;
- 		  if (GOT_TLS_GDESC_P (*local_tls_type))
- 		    {
--		      htab->elf.srelplt->size += htab->sizeof_reloc;
-+		      htab->rel_tls_desc->size += htab->sizeof_reloc;
- 		      if (bed->target_id == X86_64_ELF_DATA)
- 			htab->elf.tlsdesc_plt = (bfd_vma) -1;
- 		    }
-@@ -2417,7 +2427,6 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
-      so that R_{386,X86_64}_IRELATIVE entries come last.  */
-   if (htab->elf.srelplt)
-     {
--      htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
-       htab->sgotplt_jump_table_size
- 	= elf_x86_compute_jump_table_size (htab);
-       htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
-@@ -4742,6 +4751,14 @@ _bfd_x86_elf_link_setup_gnu_properties
- 	    }
- 	}
- 
-+      sec = bfd_make_section_anyway_with_flags
-+	(dynobj, bed->rela_plts_and_copies_p ? ".rela.tls" : ".rel.tls",
-+	 bed->dynamic_sec_flags | SEC_READONLY);
-+      if (sec == NULL
-+	  || !bfd_set_section_alignment (sec, bed->s->log_file_align))
-+	return false;
-+      htab->rel_tls_desc = sec;
-+
-       if (!info->no_ld_generated_unwind_info)
- 	{
- 	  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
-diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
-index 2a28987f208..5593203f9ec 100644
---- a/bfd/elfxx-x86.h
-+++ b/bfd/elfxx-x86.h
-@@ -650,14 +650,14 @@ struct elf_x86_link_hash_table
-   /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt.  */
-   bfd_vma next_irelative_index;
- 
-+  /* The .rela.tls/.rel.tls section for R_386_TLS_DESC or R_X86_64_TLSDESC
-+     relocation.  */
-+  asection *rel_tls_desc;
-+
-   /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.
-      This is used for i386 only.  */
-   asection *srelplt2;
- 
--  /* The index of the next unused R_386_TLS_DESC slot in .rel.plt.  This
--     is only used for i386.  */
--  bfd_vma next_tls_desc_index;
--
-   /* DT_RELR bitmap.  */
-   struct elf_dt_relr_bitmap dt_relr_bitmap;
- 
-@@ -871,6 +871,9 @@ extern bool _bfd_elf_x86_size_relative_relocs
- extern bool _bfd_elf_x86_finish_relative_relocs
-   (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
- 
-+extern asection * _bfd_elf_x86_get_reloc_section
-+  (bfd *, const char *) ATTRIBUTE_HIDDEN;
-+
- extern void _bfd_elf32_write_addend 
-   (bfd *, uint64_t, void *) ATTRIBUTE_HIDDEN;
- extern void _bfd_elf64_write_addend
-@@ -994,6 +997,8 @@ extern void _bfd_x86_elf_link_report_tls_transition_error
-   _bfd_elf_x86_size_relative_relocs
- #define elf_backend_finish_relative_relocs \
-   _bfd_elf_x86_finish_relative_relocs
-+#define elf_backend_get_reloc_section \
-+  _bfd_elf_x86_get_reloc_section
- #define elf_backend_use_mmap true
- 
- #define ELF_P_ALIGN ELF_MINPAGESIZE
-diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
-index 4db1a979058..8a07f50e47f 100644
---- a/ld/emulparams/elf32_x86_64.sh
-+++ b/ld/emulparams/elf32_x86_64.sh
-@@ -33,6 +33,8 @@ OTHER_PLT_SECTIONS="
- .plt.got      ${RELOCATING-0} : { *(.plt.got) }
- .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
- "
-+OTHER_GOT_RELOC_SECTIONS="
-+  .rela.tls	${RELOCATING-0} : { *(.rela.tls) }"
- 
- if [ "x${host}" = "x${target}" ]; then
-   case " $EMULATION_LIBPATH " in
-diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
-index 51a650f692e..12d71f5ef9e 100644
---- a/ld/emulparams/elf_i386.sh
-+++ b/ld/emulparams/elf_i386.sh
-@@ -28,6 +28,8 @@ OTHER_PLT_SECTIONS="
- .plt.got      ${RELOCATING-0} : { *(.plt.got) }
- .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
- "
-+OTHER_GOT_RELOC_SECTIONS="
-+  .rel.tls	${RELOCATING-0} : { *(.rel.tls) }"
- 
- # Linux modify the default library search path to first include
- # a 32-bit specific directory.
-diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
-index 6e66f2e1035..4bab1489b94 100644
---- a/ld/emulparams/elf_x86_64.sh
-+++ b/ld/emulparams/elf_x86_64.sh
-@@ -34,6 +34,8 @@ OTHER_PLT_SECTIONS="
- .plt.got      ${RELOCATING-0} : { *(.plt.got) }
- .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
- "
-+OTHER_GOT_RELOC_SECTIONS="
-+  .rela.tls	${RELOCATING-0} : { *(.rela.tls) }"
- 
- if [ "x${host}" = "x${target}" ]; then
-   case " $EMULATION_LIBPATH " in
-diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
-index 5b189ecb7f7..4ea46bbe901 100644
---- a/ld/testsuite/ld-i386/i386.exp
-+++ b/ld/testsuite/ld-i386/i386.exp
-@@ -522,6 +522,7 @@ run_dump_test "pr31047"
- run_dump_test "pr32191"
- run_dump_test "pr33260"
- run_dump_test "pr33260-2"
-+run_dump_test "pr28387"
- 
- if { !([istarget "i?86-*-linux*"]
-        || [istarget "i?86-*-gnu*"]
-diff --git a/ld/testsuite/ld-i386/pr17057.d b/ld/testsuite/ld-i386/pr17057.d
-index 29cc676a5af..af4e6c99276 100644
---- a/ld/testsuite/ld-i386/pr17057.d
-+++ b/ld/testsuite/ld-i386/pr17057.d
-@@ -3,7 +3,10 @@
- #ld: -shared -melf_i386
- #readelf: -r --wide
- 
--Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 2 entries:
-+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
-  Offset     Info    Type                Sym. Value  Symbol's Name
--[0-9a-f ]+R_386_JUMP_SLOT +0+ +foo
- [0-9a-f ]+R_386_TLS_DESC +0+ +my_tls
-+
-+Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-+ Offset     Info    Type                Sym. Value  Symbol's Name
-+[0-9a-f ]+R_386_JUMP_SLOT +0+ +foo
-diff --git a/ld/testsuite/ld-i386/pr28387.d b/ld/testsuite/ld-i386/pr28387.d
-new file mode 100644
-index 00000000000..fd1e980142d
---- /dev/null
-+++ b/ld/testsuite/ld-i386/pr28387.d
-@@ -0,0 +1,35 @@
-+#as: --32
-+#ld: -shared -melf_i386 -z nocombreloc -z noseparate-code --no-ld-generated-unwind-info --hash-style=sysv
-+#readelf: -d -r -S --wide
-+
-+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
-+
-+Section Headers:
-+ +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
-+#...
-+ +\[[ 0-9]+\] .rel.data +REL +0+128 0+128 0+8 08 +AI +2 +11 +4
-+ +\[[ 0-9]+\] .rel.tls +REL +0+130 0+130 0+8 08 +AI +2 +10 +4
-+ +\[[ 0-9]+\] .rel.plt +REL +0+138 0+138 0+8 08 +AI +2 +10 +4
-+#...
-+Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
-+ +Tag +Type +Name/Value
-+#...
-+ 0x[0-9a-f]+ +\(PLTRELSZ\) +8 \(bytes\)
-+ 0x[0-9a-f]+ +\(PLTREL\) +REL
-+ 0x[0-9a-f]+ +\(JMPREL\) +0x138
-+#...
-+ 0x[0-9a-f]+ +\(REL\) +0x128
-+ 0x[0-9a-f]+ +\(RELSZ\) +16 \(bytes\)
-+ 0x[0-9a-f]+ +\(RELENT\) +8 \(bytes\)
-+#...
-+Relocation section '.rel.data' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name
-+[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +foo
-+
-+Relocation section '.rel.tls' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name
-+[0-9a-f]+ +[0-9a-f]+ +R_386_TLS_DESC +0+ +foo
-+
-+Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name
-+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +bar
-diff --git a/ld/testsuite/ld-i386/pr28387.s b/ld/testsuite/ld-i386/pr28387.s
-new file mode 100644
-index 00000000000..beb318917b8
---- /dev/null
-+++ b/ld/testsuite/ld-i386/pr28387.s
-@@ -0,0 +1,12 @@
-+	.text
-+	.p2align 4
-+	.globl	main
-+	.type	main, @function
-+main:
-+	leal	foo@TLSDESC(%ebx), %eax
-+	call	*foo@TLSCALL(%eax)
-+	call	bar@PLT
-+	ret
-+	.data
-+	.dc.a	foo
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-i386/tlsdesc.rd b/ld/testsuite/ld-i386/tlsdesc.rd
-index ec418d1a1fc..ebd80b19928 100644
---- a/ld/testsuite/ld-i386/tlsdesc.rd
-+++ b/ld/testsuite/ld-i386/tlsdesc.rd
-@@ -14,7 +14,6 @@ Section Headers:
-  +\[[ 0-9]+\] \.dynsym +.*
-  +\[[ 0-9]+\] \.dynstr +.*
-  +\[[ 0-9]+\] \.rel.dyn +.*
-- +\[[ 0-9]+\] \.rel.plt +.*
-  +\[[ 0-9]+\] \.text +.*
-  +\[[ 0-9]+\] \.tdata +PROGBITS +[0-9a-f]+ [0-9a-f]+ 000060 00 WAT +0 +0 +1
-  +\[[ 0-9]+\] \.tbss +NOBITS +[0-9aa-f]+ [0-9a-f]+ 000020 00 WAT +0 +0 +1
-@@ -40,12 +39,12 @@ Program Headers:
- 
-  Section to Segment mapping:
-  +Segment Sections...
-- +00 +.hash .dynsym .dynstr .rel.dyn .rel.plt .text *
-+ +00 +.hash .dynsym .dynstr .rel.dyn .text *
-  +01 +.tdata .dynamic .got .got.plt *
-  +02 +.dynamic *
-  +03 +.tdata .tbss *
- 
--Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries:
-+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 25 entries:
-  Offset +Info +Type +Sym.Value +Sym. Name
- [0-9a-f ]+R_386_TLS_TPOFF32
- [0-9a-f ]+R_386_TLS_TPOFF *
-@@ -62,71 +61,68 @@ Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries:
- [0-9a-f ]+R_386_TLS_TPOFF *
- [0-9a-f ]+R_386_TLS_TPOFF *
- [0-9a-f ]+R_386_TLS_TPOFF32
-+[0-9a-f ]+R_386_TLS_DESC *
-+[0-9a-f ]+R_386_TLS_DESC *
-+[0-9a-f ]+R_386_TLS_DESC *
-+[0-9a-f ]+R_386_TLS_DESC *
- [0-9a-f ]+R_386_TLS_TPOFF +0+8 +sg3
- [0-9a-f ]+R_386_TLS_TPOFF32 0+c +sg4
- [0-9a-f ]+R_386_TLS_TPOFF +0+c +sg4
- [0-9a-f ]+R_386_TLS_TPOFF +0+10 +sg5
- [0-9a-f ]+R_386_TLS_TPOFF32 0+4 +sg2
--
--Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 5 entries:
-- Offset +Info +Type +Sym.Value +Sym. Name
- [0-9a-f ]+R_386_TLS_DESC * 0+ +sg1
--[0-9a-f ]+R_386_TLS_DESC *
--[0-9a-f ]+R_386_TLS_DESC *
--[0-9a-f ]+R_386_TLS_DESC *
--[0-9a-f ]+R_386_TLS_DESC *
- 
- Symbol table '\.dynsym' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
-- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
-- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
-- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
-- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
-- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
-- +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +6 fn1
-- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
-- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
-- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
-+ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +6 sg8
-+ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +6 sg3
-+ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +6 sg4
-+ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +6 sg5
-+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +6 sg1
-+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +5 fn1
-+ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +6 sg2
-+ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +6 sg6
-+ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +6 sg7
- 
- Symbol table '\.symtab' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
- .* FILE +LOCAL +DEFAULT +ABS .*tlsdesc.o
-- +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +7 sl1
-- +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +7 sl2
-- +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +7 sl3
-- +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +7 sl4
-- +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +7 sl5
-- +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +7 sl6
-- +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +7 sl7
-- +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +7 sl8
-+ +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +6 sl1
-+ +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +6 sl2
-+ +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +6 sl3
-+ +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +6 sl4
-+ +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +6 sl5
-+ +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +6 sl6
-+ +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +6 sl7
-+ +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +6 sl8
- .* FILE +LOCAL +DEFAULT +ABS 
-- +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +8 sH1
-- +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_
-- +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
-- +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +7 sh3
-- +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +8 sH2
-- +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +8 sH7
-- +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +7 sh7
-- +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +7 sh8
-- +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +8 sH4
-- +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +7 sh4
-- +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +8 sH3
-- +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +7 sh5
-- +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +8 sH5
-- +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +8 sH6
-- +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +8 sH8
-- +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +7 sh1
-- +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
-- +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +7 sh2
-- +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +7 sh6
-- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
-- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
-- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
-- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
-- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
-- +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +6 fn1
-- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
-- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
-- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
-+ +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +7 sH1
-+ +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +6 _TLS_MODULE_BASE_
-+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +8 _DYNAMIC
-+ +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +6 sh3
-+ +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +7 sH2
-+ +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +7 sH7
-+ +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +6 sh7
-+ +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +6 sh8
-+ +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +7 sH4
-+ +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +6 sh4
-+ +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +7 sH3
-+ +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +6 sh5
-+ +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +7 sH5
-+ +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +7 sH6
-+ +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +7 sH8
-+ +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +6 sh1
-+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +10 _GLOBAL_OFFSET_TABLE_
-+ +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +6 sh2
-+ +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +6 sh6
-+ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +6 sg8
-+ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +6 sg3
-+ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +6 sg4
-+ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +6 sg5
-+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +6 sg1
-+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +5 fn1
-+ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +6 sg2
-+ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +6 sg6
-+ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +6 sg7
-diff --git a/ld/testsuite/ld-i386/tlsdesc2.d b/ld/testsuite/ld-i386/tlsdesc2.d
-index b8569e893b8..c37557a94ef 100644
---- a/ld/testsuite/ld-i386/tlsdesc2.d
-+++ b/ld/testsuite/ld-i386/tlsdesc2.d
-@@ -3,8 +3,9 @@
- #ld: -melf_i386 -shared -z now
- #readelf: -d --wide
- 
-+#failif
- #...
- .*\(PLTRELSZ\).*
- .*\(PLTREL\).*
- .*\(JMPREL\).*
--#pass
-+#...
-diff --git a/ld/testsuite/ld-i386/tlsgdesc.rd b/ld/testsuite/ld-i386/tlsgdesc.rd
-index 0744aeb78b0..a129bf6f7e4 100644
---- a/ld/testsuite/ld-i386/tlsgdesc.rd
-+++ b/ld/testsuite/ld-i386/tlsgdesc.rd
-@@ -41,22 +41,22 @@ Program Headers:
-  +01 +.dynamic .got .got.plt *
-  +02 +.dynamic *
- 
--Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
-+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 10 entries:
-  Offset +Info +Type +Sym.Value +Sym. Name
- [0-9a-f ]+R_386_TLS_TPOFF32 0+ +sG3
- [0-9a-f ]+R_386_TLS_TPOFF +0+ +sG5
- [0-9a-f ]+R_386_TLS_DTPMOD3 0+ +sG2
- [0-9a-f ]+R_386_TLS_DTPOFF3 0+ +sG2
-+[0-9a-f ]+R_386_TLS_DESC +0+ +sG2
- [0-9a-f ]+R_386_TLS_TPOFF +0+ +sG4
- [0-9a-f ]+R_386_TLS_TPOFF32 0+ +sG6
- [0-9a-f ]+R_386_TLS_DTPMOD3 0+ +sG1
- [0-9a-f ]+R_386_TLS_DTPOFF3 0+ +sG1
-+[0-9a-f ]+R_386_TLS_DESC +0+ +sG1
- 
--Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 3 entries:
-+Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-  Offset +Info +Type +Sym.Value +Sym. Name
- [0-9a-f ]+R_386_JUMP_SLOT +0+ +___tls_get_addr
--[0-9a-f ]+R_386_TLS_DESC +0+ +sG1
--[0-9a-f ]+R_386_TLS_DESC +0+ +sG2
- 
- Symbol table '\.dynsym' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-diff --git a/ld/testsuite/ld-x86-64/pr28387-x32.d b/ld/testsuite/ld-x86-64/pr28387-x32.d
-new file mode 100644
-index 00000000000..0302126014c
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr28387-x32.d
-@@ -0,0 +1,36 @@
-+#source: pr28387.s
-+#as: --x32
-+#ld: -shared -melf32_x86_64 -z nocombreloc -z nomark-plt -z noseparate-code -z max-page-size=0x200000 --no-ld-generated-unwind-info --hash-style=sysv
-+#readelf: -d -r -S --wide
-+
-+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
-+
-+Section Headers:
-+ +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
-+#...
-+ +\[[ 0-9]+\] .rela.data +RELA +0+128 0+128 0+c 0c +AI +2 +12 +4
-+ +\[[ 0-9]+\] .rela.tls +RELA +0+134 0+134 0+c 0c +AI +2 +11 +4
-+ +\[[ 0-9]+\] .rela.plt +RELA +0+140 0+140 0+c 0c +AI +2 +11 +4
-+#...
-+Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
-+ +Tag +Type +Name/Value
-+#...
-+ 0x[0-9a-f]+ +\(PLTRELSZ\) +12 \(bytes\)
-+ 0x[0-9a-f]+ +\(PLTREL\) +RELA
-+ 0x[0-9a-f]+ +\(JMPREL\) +0x140
-+#...
-+ 0x[0-9a-f]+ +\(RELA\) +0x128
-+ 0x[0-9a-f]+ +\(RELASZ\) +24 \(bytes\)
-+ 0x[0-9a-f]+ +\(RELAENT\) +12 \(bytes\)
-+#...
-+Relocation section '.rela.data' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +foo \+ 0
-+
-+Relocation section '.rela.tls' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_TLSDESC +0+ +foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +bar \+ 0
-diff --git a/ld/testsuite/ld-x86-64/pr28387.d b/ld/testsuite/ld-x86-64/pr28387.d
-new file mode 100644
-index 00000000000..07df0fbc5a7
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr28387.d
-@@ -0,0 +1,35 @@
-+#as: --64
-+#ld: -shared -melf_x86_64 -z nocombreloc -z nomark-plt -z noseparate-code -z max-page-size=0x200000 --no-ld-generated-unwind-info --hash-style=sysv
-+#readelf: -d -r -S --wide
-+
-+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
-+
-+Section Headers:
-+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
-+#...
-+ +\[[ 0-9]+\] .rela.data +RELA +0+1b8 0+1b8 0+18 18 +AI +2 +12 +8
-+ +\[[ 0-9]+\] .rela.tls +RELA +0+1d0 0+1d0 0+18 18 +AI +2 +11 +8
-+ +\[[ 0-9]+\] .rela.plt +RELA +0+1e8 0+1e8 0+18 18 +AI +2 +11 +8
-+#...
-+Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
-+ +Tag +Type +Name/Value
-+#...
-+ 0x[0-9a-f]+ +\(PLTRELSZ\) +24 \(bytes\)
-+ 0x[0-9a-f]+ +\(PLTREL\) +RELA
-+ 0x[0-9a-f]+ +\(JMPREL\) +0x1e8
-+#...
-+ 0x[0-9a-f]+ +\(RELA\) +0x1b8
-+ 0x[0-9a-f]+ +\(RELASZ\) +48 \(bytes\)
-+ 0x[0-9a-f]+ +\(RELAENT\) +24 \(bytes\)
-+#...
-+Relocation section '.rela.data' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +foo \+ 0
-+
-+Relocation section '.rela.tls' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_TLSDESC +0+ +foo \+ 0
-+
-+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-+ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
-+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +bar \+ 0
-diff --git a/ld/testsuite/ld-x86-64/pr28387.s b/ld/testsuite/ld-x86-64/pr28387.s
-new file mode 100644
-index 00000000000..bbfa7b5f129
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr28387.s
-@@ -0,0 +1,11 @@
-+	.text
-+	.globl	main
-+	.type	main, @function
-+main:
-+	leaq	foo@TLSDESC(%rip), %rax
-+	call	*foo@TLSCALL(%rax)
-+	call	bar@PLT
-+	ret
-+	.data
-+	.dc.a	foo
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/tlsdesc.pd b/ld/testsuite/ld-x86-64/tlsdesc.pd
-index 490fc906c51..7e124ea32e5 100644
---- a/ld/testsuite/ld-x86-64/tlsdesc.pd
-+++ b/ld/testsuite/ld-x86-64/tlsdesc.pd
-@@ -10,10 +10,10 @@
- Disassembly of section .plt:
- 
- [0-9a-f]+ <.plt>:
-- [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
-- [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201360 <_GLOBAL_OFFSET_TABLE_\+0x10>
-+ [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201328 <_GLOBAL_OFFSET_TABLE_\+0x8>
-+ [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201330 <_GLOBAL_OFFSET_TABLE_\+0x10>
-  [0-9a-f]+:	0f 1f 40 00          	nopl   0x0\(%rax\)
-  [0-9a-f]+:	f3 0f 1e fa          	endbr64
-- [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
-- [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201348 <.*>
-+ [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201328 <_GLOBAL_OFFSET_TABLE_\+0x8>
-+ [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201318 <.*>
- 
-diff --git a/ld/testsuite/ld-x86-64/tlsdesc.rd b/ld/testsuite/ld-x86-64/tlsdesc.rd
-index 98bda5b2a39..14e945a8bae 100644
---- a/ld/testsuite/ld-x86-64/tlsdesc.rd
-+++ b/ld/testsuite/ld-x86-64/tlsdesc.rd
-@@ -14,14 +14,13 @@ Section Headers:
-  +\[[ 0-9]+\] .dynsym +.*
-  +\[[ 0-9]+\] .dynstr +.*
-  +\[[ 0-9]+\] .rela.dyn +.*
-- +\[[ 0-9]+\] .rela.plt +.*
-  +\[[ 0-9]+\] .plt +PROGBITS +0+3b0 0+3b0 0+20 10 +AX +0 +0 +(4|16)
-  +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+153 00 +AX +0 +0 4096
-  +\[[ 0-9]+\] .tdata +PROGBITS +0+201153 0+1153 0+60 00 WAT +0 +0 +1
-  +\[[ 0-9]+\] .tbss +NOBITS +0+2011b3 0+11b3 0+20 00 WAT +0 +0 +1
-- +\[[ 0-9]+\] .dynamic +DYNAMIC +0+2011b8 0+11b8 0+150 10 +WA +3 +0 +8
-- +\[[ 0-9]+\] .got +PROGBITS +0+201308 0+1308 0+48 08 +WA +0 +0 +8
-- +\[[ 0-9]+\] .got.plt +PROGBITS +0+201350 0+1350 0+68 08 +WA +0 +0 +8
-+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+2011b8 0+11b8 0+120 10 +WA +3 +0 +8
-+ +\[[ 0-9]+\] .got +PROGBITS +0+2012d8 0+12d8 0+48 08 +WA +0 +0 +8
-+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+201320 0+1320 0+68 08 +WA +0 +0 +8
-  +\[[ 0-9]+\] .symtab +.*
-  +\[[ 0-9]+\] .strtab +.*
-  +\[[ 0-9]+\] .shstrtab +.*
-@@ -35,18 +34,18 @@ There are [0-9]+ program headers, starting at offset [0-9]+
- Program Headers:
-  +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
-  +LOAD +0x0+ 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
-- +LOAD +0x0+1153 0x0+201153 0x0+201153 0x0+265 0x0+265 RW +0x200000
-- +DYNAMIC +0x0+11b8 0x0+2011b8 0x0+2011b8 0x0+150 0x0+150 RW +0x8
-+ +LOAD +0x0+1153 0x0+201153 0x0+201153 0x0+235 0x0+235 RW +0x200000
-+ +DYNAMIC +0x0+11b8 0x0+2011b8 0x0+2011b8 0x0+120 0x0+120 RW +0x8
-  +TLS +0x0+1153 0x0+201153 0x0+201153 0x0+60 0x0+80 R +0x1
- 
-  Section to Segment mapping:
-  +Segment Sections...
-- +00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
-+ +00 +.hash .dynsym .dynstr .rela.dyn .plt .text *
-  +01 +.tdata .dynamic .got .got.plt *
-  +02 +.dynamic *
-  +03 +.tdata .tbss *
- 
--Dynamic section at offset 0x[0-9a-f]+ contains 16 entries:
-+Dynamic section at offset 0x[0-9a-f]+ contains 13 entries:
-  +Tag +Type +Name/Value
-  0x[0-9a-f]+ +\(HASH\).*
-  0x[0-9a-f]+ +\(STRTAB\).*
-@@ -54,87 +53,81 @@ Dynamic section at offset 0x[0-9a-f]+ contains 16 entries:
-  0x[0-9a-f]+ +\(STRSZ\).*
-  0x[0-9a-f]+ +\(SYMENT\).*
-  0x[0-9a-f]+ +\(PLTGOT\).*
-- 0x[0-9a-f]+ +\(PLTRELSZ\).*
-- 0x[0-9a-f]+ +\(PLTREL\).*
-- 0x[0-9a-f]+ +\(JMPREL\).*
-  0x[0-9a-f]+ +\(TLSDESC_PLT\) +0x3c0
-- 0x[0-9a-f]+ +\(TLSDESC_GOT\) +0x201348
-+ 0x[0-9a-f]+ +\(TLSDESC_GOT\) +0x201318
-  0x[0-9a-f]+ +\(RELA\).*
-  0x[0-9a-f]+ +\(RELASZ\).*
-  0x[0-9a-f]+ +\(RELAENT\).*
-  0x[0-9a-f]+ +\(FLAGS\).*
-  0x[0-9a-f]+ +\(NULL\).*
- 
--Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
-+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 13 entries:
-  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
--0+201308 +[0-9a-f]+ R_X86_64_TPOFF64 +24
--0+201310 +[0-9a-f]+ R_X86_64_TPOFF64 +30
--0+201318 +[0-9a-f]+ R_X86_64_TPOFF64 +64
--0+201328 +[0-9a-f]+ R_X86_64_TPOFF64 +50
--0+201330 +[0-9a-f]+ R_X86_64_TPOFF64 +70
--0+201340 +[0-9a-f]+ R_X86_64_TPOFF64 +44
--0+201320 +[0-9a-f]+ R_X86_64_TPOFF64 +0+10 sg5 \+ 0
--0+201338 +[0-9a-f]+ R_X86_64_TPOFF64 +0+4 sg2 \+ 0
--
--Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 5 entries:
-- +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
--0+201398 +[0-9a-f]+ R_X86_64_TLSDESC +0+ sg1 \+ 0
--0+201368 +[0-9a-f]+ R_X86_64_TLSDESC +20
--0+2013a8 +[0-9a-f]+ R_X86_64_TLSDESC +40
--0+201378 +[0-9a-f]+ R_X86_64_TLSDESC +60
--0+201388 +[0-9a-f]+ R_X86_64_TLSDESC +0
-+0+2012d8 +[0-9a-f]+ R_X86_64_TPOFF64 +24
-+0+2012e0 +[0-9a-f]+ R_X86_64_TPOFF64 +30
-+0+2012e8 +[0-9a-f]+ R_X86_64_TPOFF64 +64
-+0+2012f8 +[0-9a-f]+ R_X86_64_TPOFF64 +50
-+0+201300 +[0-9a-f]+ R_X86_64_TPOFF64 +70
-+0+201310 +[0-9a-f]+ R_X86_64_TPOFF64 +44
-+0+201338 +[0-9a-f]+ R_X86_64_TLSDESC +20
-+0+201348 +[0-9a-f]+ R_X86_64_TLSDESC +60
-+0+201358 +[0-9a-f]+ R_X86_64_TLSDESC +0
-+0+201378 +[0-9a-f]+ R_X86_64_TLSDESC +40
-+0+2012f0 +[0-9a-f]+ R_X86_64_TPOFF64 +0+10 sg5 \+ 0
-+0+201308 +[0-9a-f]+ R_X86_64_TPOFF64 +0+4 sg2 \+ 0
-+0+201368 +[0-9a-f]+ R_X86_64_TLSDESC +0+ sg1 \+ 0
- 
- Symbol table '\.dynsym' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
-- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +8 sg8
-- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +8 sg3
-- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +8 sg4
-- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +8 sg5
-- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +8 sg1
-- +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +7 fn1
-- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +8 sg2
-- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +8 sg6
-- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +8 sg7
-+ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
-+ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
-+ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
-+ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
-+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
-+ +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +6 fn1
-+ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
-+ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
-+ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
- 
- Symbol table '\.symtab' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
- .* FILE +LOCAL +DEFAULT +ABS .*tlsdesc.o
-- +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +8 sl1
-- +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +8 sl2
-- +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +8 sl3
-- +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +8 sl4
-- +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +8 sl5
-- +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +8 sl6
-- +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +8 sl7
-- +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +8 sl8
-+ +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +7 sl1
-+ +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +7 sl2
-+ +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +7 sl3
-+ +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +7 sl4
-+ +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +7 sl5
-+ +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +7 sl6
-+ +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +7 sl7
-+ +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +7 sl8
- .* FILE +LOCAL +DEFAULT +ABS 
-- +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +9 sH1
-- +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +8 _TLS_MODULE_BASE_
-- +[0-9]+: 0+2011b8 +0 +OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
-- +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +8 sh3
-- +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +9 sH2
-- +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +9 sH7
-- +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +8 sh7
-- +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +8 sh8
-- +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +9 sH4
-- +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +8 sh4
-- +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +9 sH3
-- +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +8 sh5
-- +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +9 sH5
-- +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +9 sH6
-- +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +9 sH8
-- +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +8 sh1
-- +[0-9]+: 0+201350 +0 +OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
-- +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +8 sh2
-- +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +8 sh6
-- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +8 sg8
-- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +8 sg3
-- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +8 sg4
-- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +8 sg5
-- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +8 sg1
-- +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +7 fn1
-- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +8 sg2
-- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +8 sg6
-- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +8 sg7
-+ +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +8 sH1
-+ +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_
-+ +[0-9]+: 0+2011b8 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
-+ +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +7 sh3
-+ +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +8 sH2
-+ +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +8 sH7
-+ +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +7 sh7
-+ +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +7 sh8
-+ +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +8 sH4
-+ +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +7 sh4
-+ +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +8 sH3
-+ +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +7 sh5
-+ +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +8 sH5
-+ +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +8 sH6
-+ +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +8 sH8
-+ +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +7 sh1
-+ +[0-9]+: 0+201320 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
-+ +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +7 sh2
-+ +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +7 sh6
-+ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
-+ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
-+ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
-+ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
-+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
-+ +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +6 fn1
-+ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
-+ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
-+ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
-diff --git a/ld/testsuite/ld-x86-64/tlsdesc2.d b/ld/testsuite/ld-x86-64/tlsdesc2.d
-index 86797579bac..d0f5ebf62a2 100644
---- a/ld/testsuite/ld-x86-64/tlsdesc2.d
-+++ b/ld/testsuite/ld-x86-64/tlsdesc2.d
-@@ -3,8 +3,8 @@
- #ld: -melf_x86_64 -shared -z now
- #readelf: -d --wide
- 
--#...
-+#failif
- .*\(PLTRELSZ\).*
- .*\(PLTREL\).*
- .*\(JMPREL\).*
--#pass
-+#...
-diff --git a/ld/testsuite/ld-x86-64/tlsgdesc.rd b/ld/testsuite/ld-x86-64/tlsgdesc.rd
-index ca8f19bf3f7..ef15ce94c5a 100644
---- a/ld/testsuite/ld-x86-64/tlsgdesc.rd
-+++ b/ld/testsuite/ld-x86-64/tlsgdesc.rd
-@@ -41,22 +41,22 @@ Program Headers:
-  +01 +.dynamic .got .got.plt *
-  +02 +.dynamic *
- 
--Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
-+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 10 entries:
-  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
- [0-9a-f]+ +0+100000012 R_X86_64_TPOFF64 +0+ sG3 \+ 0
- [0-9a-f]+ +0+200000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0
- [0-9a-f]+ +0+300000010 R_X86_64_DTPMOD64 +0+ sG2 \+ 0
- [0-9a-f]+ +0+300000011 R_X86_64_DTPOFF64 +0+ sG2 \+ 0
-+[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
- [0-9a-f]+ +0+400000012 R_X86_64_TPOFF64 +0+ sG4 \+ 0
- [0-9a-f]+ +0+600000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0
- [0-9a-f]+ +0+800000010 R_X86_64_DTPMOD64 +0+ sG1 \+ 0
- [0-9a-f]+ +0+800000011 R_X86_64_DTPOFF64 +0+ sG1 \+ 0
-+[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
- 
--Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 3 entries:
-+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
-  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
- [0-9a-f]+ +0+500000007 R_X86_64_JUMP_SLOT +0+ __tls_get_addr \+ 0
--[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
--[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
- 
- Symbol table '\.dynsym' contains [0-9]+ entries:
-  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
-diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index 63cf1e45c14..5b759d8a5d0 100644
---- a/ld/testsuite/ld-x86-64/x86-64.exp
-+++ b/ld/testsuite/ld-x86-64/x86-64.exp
-@@ -570,6 +570,8 @@ run_dump_test "pr33260-2"
- run_dump_test "pr33260-2-x32"
- run_dump_test "pr33292"
- run_dump_test "pr33292-x32"
-+run_dump_test "pr28387"
-+run_dump_test "pr28387-x32"
- 
- if { ![skip_sframe_tests] } {
-     run_dump_test "sframe-simple-1"
-
-base-commit: 8b7a074374f812a00f6f30be849f1b1f32bbe230
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-27  2:49 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-27  2:49 UTC (permalink / raw
  To: gentoo-commits

commit:     dd5e93f8a04c854492dfbf890835b4bed6487c1d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 27 02:48:38 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 27 02:48:38 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=dd5e93f8

9999: add readelf -G support

Bug: https://sourceware.org/PR33314
Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0007-readelf-Add-G-got-contents-options.patch | 2031 ++++++++++++++++++++
 1 file changed, 2031 insertions(+)

diff --git a/9999/0007-readelf-Add-G-got-contents-options.patch b/9999/0007-readelf-Add-G-got-contents-options.patch
new file mode 100644
index 0000000..5cae8ee
--- /dev/null
+++ b/9999/0007-readelf-Add-G-got-contents-options.patch
@@ -0,0 +1,2031 @@
+From d10474f6defab5484fd8a9a79c3fa8588ca37396 Mon Sep 17 00:00:00 2001
+Message-ID: <d10474f6defab5484fd8a9a79c3fa8588ca37396.1756262897.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 26 Aug 2025 19:45:44 -0700
+Subject: [PATCH] readelf: Add -G/--got-contents options
+
+On Tue, Aug 26, 2025 at 02:53:40PM -0700, H.J. Lu wrote:
+> Add -G/--got-contents options to readelf, inspired by the similar option
+> on Solaris, to display the contents of GOT sections:
+>
+> $ readelf -G libfoo.so
+>
+> Global Offset Table '.got' contains 5 entries:
+>  Index:    Address       Reloc         Sym. Name + Addend/Value
+>      0: 000000002fc8 R_X86_64_GLOB_DAT bar + 0
+>      1: 000000002fd0 R_X86_64_GLOB_DAT __gmon_start__ + 0
+>      2: 000000002fd8 R_X86_64_GLOB_DAT _ITM_registerTMCloneTable + 0
+>      3: 000000002fe0 R_X86_64_GLOB_DAT __cxa_finalize@GLIBC_2.2.5 + 0
+>      4: 000000002fe8                   0
+>
+> Global Offset Table '.got.plt' contains 4 entries:
+>  Index:    Address       Reloc         Sym. Name + Addend/Value
+>      0: 000000002ff0                   2dd0
+>      1: 000000002ff8                   0
+>      2: 000000003000 R_X86_64_JUMP_SLO printf@GLIBC_2.2.5 + 2c0
+>      3: 000000003008                   0
+>
+> Any comments?
+>
+
+The updated patch with typo fix.
+
+H.J.
+---
+ binutils/NEWS                           |   3 +
+ binutils/doc/binutils.texi              |  11 +-
+ binutils/readelf.c                      | 896 +++++++++++++++++++-----
+ ld/testsuite/ld-i386/binutils.exp       |  45 ++
+ ld/testsuite/ld-i386/got-1.s            |   7 +
+ ld/testsuite/ld-i386/libgot-1a.rd       |   9 +
+ ld/testsuite/ld-i386/libgot-1b.rd       | 119 ++++
+ ld/testsuite/ld-i386/libgot-1c.rd       |  12 +
+ ld/testsuite/ld-i386/libgot-1d.rd       |  12 +
+ ld/testsuite/ld-x86-64/binutils.exp     |  59 ++
+ ld/testsuite/ld-x86-64/got-1.s          |   7 +
+ ld/testsuite/ld-x86-64/libgot-1a-x32.rd |   9 +
+ ld/testsuite/ld-x86-64/libgot-1a.rd     |   9 +
+ ld/testsuite/ld-x86-64/libgot-1b-x32.rd | 119 ++++
+ ld/testsuite/ld-x86-64/libgot-1b.rd     | 119 ++++
+ ld/testsuite/ld-x86-64/libgot-1c-x32.rd |  12 +
+ ld/testsuite/ld-x86-64/libgot-1c.rd     |  12 +
+ ld/testsuite/ld-x86-64/libgot-1d-x32.rd |  12 +
+ ld/testsuite/ld-x86-64/libgot-1d.rd     |  12 +
+ 19 files changed, 1317 insertions(+), 167 deletions(-)
+ create mode 100644 ld/testsuite/ld-i386/binutils.exp
+ create mode 100644 ld/testsuite/ld-i386/got-1.s
+ create mode 100644 ld/testsuite/ld-i386/libgot-1a.rd
+ create mode 100644 ld/testsuite/ld-i386/libgot-1b.rd
+ create mode 100644 ld/testsuite/ld-i386/libgot-1c.rd
+ create mode 100644 ld/testsuite/ld-i386/libgot-1d.rd
+ create mode 100644 ld/testsuite/ld-x86-64/binutils.exp
+ create mode 100644 ld/testsuite/ld-x86-64/got-1.s
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1a-x32.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1a.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1b-x32.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1b.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1c-x32.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1c.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1d-x32.rd
+ create mode 100644 ld/testsuite/ld-x86-64/libgot-1d.rd
+
+diff --git a/binutils/NEWS b/binutils/NEWS
+index ccda8559897..9af862a4735 100644
+--- a/binutils/NEWS
++++ b/binutils/NEWS
+@@ -1,5 +1,8 @@
+ -*- text -*-
+ 
++* Add -G/--got-contents options to readelf to display the contents of
++  Global Offset Table (GOT) sections.
++
+ * Internal changes to plugin support, and stricter target checking may result
+   in some errors being exposed in user options passed to the various binutils.
+   For example objcopy --target=TARGET now will only work if the input file is
+diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
+index 4543341e00c..15f31d1bcef 100644
+--- a/binutils/doc/binutils.texi
++++ b/binutils/doc/binutils.texi
+@@ -5036,6 +5036,7 @@ readelf [@option{-a}|@option{--all}]
+         [@option{-h}|@option{--file-header}]
+         [@option{-l}|@option{--program-headers}|@option{--segments}]
+         [@option{-S}|@option{--section-headers}|@option{--sections}]
++        [@option{-G}|@option{--got-contents}]
+         [@option{-g}|@option{--section-groups}]
+         [@option{-t}|@option{--section-details}]
+         [@option{-e}|@option{--headers}]
+@@ -5111,7 +5112,8 @@ given.
+ Equivalent to specifying @option{--file-header},
+ @option{--program-headers}, @option{--sections}, @option{--symbols},
+ @option{--relocs}, @option{--dynamic}, @option{--notes},
+-@option{--version-info}, @option{--arch-specific}, @option{--unwind},
++@option{--got-contents}, @option{--version-info},
++@option{--arch-specific}, @option{--unwind},
+ @option{--section-groups} and @option{--histogram}.
+ 
+ Note - this option does not enable @option{--use-dynamic} itself, so
+@@ -5143,6 +5145,13 @@ Suppress "no symbols" diagnostic.
+ Displays the information contained in the file's section headers, if it
+ has any.
+ 
++@item -G
++@itemx --got-contents
++@cindex ELF section information
++@cindex ELF reloc information
++Displays the contents of the file's Global Offset Table (GOT) sections,
++if it has any.
++
+ @item -g
+ @itemx --section-groups
+ @cindex ELF section group information
+diff --git a/binutils/readelf.c b/binutils/readelf.c
+index bb81c824ac3..15064daa969 100644
+--- a/binutils/readelf.c
++++ b/binutils/readelf.c
+@@ -229,6 +229,7 @@ static bool do_dyn_syms = false;
+ static bool do_lto_syms = false;
+ static bool do_reloc = false;
+ static bool do_sections = false;
++static bool do_got_section_contents = false;
+ static bool do_section_groups = false;
+ static bool do_section_details = false;
+ static bool do_segments = false;
+@@ -372,6 +373,21 @@ enum versioned_symbol_info
+   symbol_public
+ };
+ 
++/* Relocation entries */
++
++typedef struct elf_relocation
++{
++  bfd_vma r_offset;	/* Location at which to apply the action */
++  bfd_vma r_addend;	/* Constant addend used to compute value */
++  const char *r_name;	/* Relocation name.  */
++  char *r_symbol;	/* Relocation symbol.  */
++  relocation_type r_type; /* Relocation type.  */
++} elf_relocation;
++
++static elf_relocation *all_relocations_root;
++static elf_relocation *all_relocations;
++static size_t all_relocations_count;
++
+ static int
+ fseek64 (FILE *stream, int64_t offset, int whence)
+ {
+@@ -1767,6 +1783,32 @@ symcmp (const void *p, const void *q)
+   return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
+ }
+ 
++static void
++update_all_relocations (size_t nentries)
++{
++  size_t sz;
++
++  if (!do_got_section_contents)
++    return;
++
++  if (!all_relocations_root)
++    {
++      sz = nentries * sizeof (elf_relocation);
++      all_relocations_root = (elf_relocation *) xmalloc (sz);
++      all_relocations = all_relocations_root;
++      all_relocations_count = nentries;
++    }
++  else
++    {
++      size_t orig_count = all_relocations_count;
++      sz = (orig_count + nentries) * sizeof (elf_relocation);
++      all_relocations_root = (elf_relocation *)
++	xrealloc (all_relocations_root, sz);
++      all_relocations = all_relocations_root + orig_count;
++      all_relocations_count += nentries;
++    }
++}
++
+ static uint64_t
+ count_relr_relocations (Filedata *          filedata,
+ 			Elf_Internal_Shdr * section)
+@@ -1836,7 +1878,8 @@ dump_relr_relocations (Filedata *          filedata,
+ 		       Elf_Internal_Sym *  symtab,
+ 		       uint64_t            nsyms,
+ 		       char *              strtab,
+-		       uint64_t            strtablen)
++		       uint64_t            strtablen,
++		       bool                dump_reloc)
+ {
+   uint64_t *  relrs;
+   uint64_t    nentries, i;
+@@ -1861,7 +1904,8 @@ dump_relr_relocations (Filedata *          filedata,
+     num_bits_in_entry = 63;
+   else
+     {
+-      warn (_("Unexpected entsize for RELR section\n"));
++      if (dump_reloc)
++	warn (_("Unexpected entsize for RELR section\n"));
+       return false;
+     }
+ 
+@@ -1875,6 +1919,161 @@ dump_relr_relocations (Filedata *          filedata,
+   if (symtab == NULL)
+     nsyms = 0;
+ 
++  const char *rtype = NULL;
++  if (do_got_section_contents)
++    switch (filedata->file_header.e_machine)
++      {
++      default:
++	break;
++
++      case EM_386:
++      case EM_IAMCU:
++	rtype = "R_386_RELATIVE";
++	break;
++
++      case EM_68K:
++	rtype = "R_68K_RELATIVE";
++	break;
++
++      case EM_860:
++	rtype = "R_860_RELATIVE";
++	break;
++
++      case EM_AARCH64:
++	rtype = "R_AARCH64_RELATIVE";
++	break;
++
++      case EM_AMDGPU:
++	rtype = "R_AMDGPU_RELATIVE64";
++	break;
++
++      case EM_ALPHA:
++	rtype = "R_ALPHA_RELATIVE";
++	break;
++
++      case EM_ALTERA_NIOS2:
++	rtype = "R_NIOS2_RELATIVE";
++	break;
++
++      case EM_ARM:
++	rtype = "R_ARM_RELATIVE";
++	break;
++
++      case EM_ARC:
++      case EM_ARC_COMPACT:
++      case EM_ARC_COMPACT2:
++      case EM_ARC_COMPACT3:
++      case EM_ARC_COMPACT3_64:
++	rtype = "R_ARC_RELATIVE";
++	break;
++
++      case EM_CRIS:
++	rtype = "R_CRIS_RELATIVE";
++	break;
++
++      case EM_CSKY:
++	rtype = "R_CKCORE_RELATIVE";
++	break;
++
++      case EM_KVX:
++	rtype = "R_KVX_RELATIVE";
++	break;
++
++      case EM_LATTICEMICO32:
++	rtype = "R_LM32_RELATIVE";
++	break;
++
++      case EM_LOONGARCH:
++	rtype = "R_LARCH_RELATIVE";
++	break;
++
++      case EM_M32R:
++      case EM_CYGNUS_M32R:
++	rtype = "R_M32R_RELATIVE";
++	break;
++
++      case EM_MCORE:
++	rtype = "R_MCORE_RELATIVE";
++	break;
++
++      case EM_METAG:
++	rtype = "R_METAG_RELATIVE";
++	break;
++
++      case EM_MN10300:
++      case EM_CYGNUS_MN10300:
++	rtype = "R_MN10300_RELATIVE";
++	break;
++
++      case EM_NDS32:
++	rtype = "R_NDS32_RELATIVE";
++	break;
++
++      case EM_OR1K:
++	rtype = "R_OR1K_RELATIVE";
++	break;
++
++      case EM_PPC:
++	rtype = "R_PPC_RELATIVE";
++	break;
++
++      case EM_PPC64:
++	rtype = "R_PPC64_RELATIVE";
++	break;
++
++      case EM_RISCV:
++	rtype = "R_RISCV_RELATIVE";
++	break;
++
++      case EM_S370:
++	rtype = "R_I370_RELATIVE";
++	break;
++
++      case EM_S390_OLD:
++      case EM_S390:
++	rtype = "R_390_RELATIVE";
++	break;
++
++      case EM_SH:
++	rtype = "R_SH_RELATIVE";
++	break;
++
++      case EM_OLD_SPARCV9:
++      case EM_SPARC32PLUS:
++      case EM_SPARCV9:
++      case EM_SPARC:
++	rtype = "R_SPARC_RELATIVE";
++	break;
++
++      case EM_TILEGX:
++	rtype = "R_TILEGX_RELATIVE";
++	break;
++
++      case EM_TILEPRO:
++	rtype = "R_TILEPRO_RELATIVE";
++	break;
++
++      case EM_V850:
++      case EM_CYGNUS_V850:
++	rtype = "R_V850_RELATIVE";
++	break;
++
++      case EM_VAX:
++	rtype = "R_VAX_RELATIVE";
++	break;
++
++      case EM_X86_64:
++      case EM_L1OM:
++      case EM_K1OM:
++	rtype = "R_X86_64_RELATIVE";
++	break;
++
++      case EM_XTENSA_OLD:
++      case EM_XTENSA:
++	rtype = "R_XTENSA_RELATIVE";
++	break;
++      }
++
+   if (symtab != NULL)
+     {
+       /* Symbol tables are not sorted on address, but we want a quick lookup
+@@ -1885,11 +2084,15 @@ dump_relr_relocations (Filedata *          filedata,
+       nsyms = filter_display_syms (filedata, symtab, nsyms, strtab, strtablen);
+     }
+ 
+-  if (relr_entsize == sizeof (Elf32_External_Relr))
+-    printf (_ ("Index: Entry    Address   Symbolic Address\n"));
+-  else
+-    printf (_ ("Index: Entry            Address           Symbolic Address\n"));
++  if (dump_reloc)
++    {
++      if (relr_entsize == sizeof (Elf32_External_Relr))
++	printf (_ ("Index: Entry    Address   Symbolic Address\n"));
++      else
++	printf (_ ("Index: Entry            Address           Symbolic Address\n"));
++    }
+ 
++  uint64_t r = 0;
+   for (i = 0; i < nentries; i++)
+     {
+       uint64_t entry;
+@@ -1899,16 +2102,34 @@ dump_relr_relocations (Filedata *          filedata,
+       else
+ 	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+ 
+-      /* We assume that there will never be more than 9999 entries.  */
+-      printf (_("%04u:  "), (unsigned int) i);
+-      print_vma (entry, ZERO_HEX);
+-      printf (" ");
++      if (dump_reloc)
++	{
++	  /* We assume that there will never be more than 9999
++	     entries.  */
++	  printf (_("%04u:  "), (unsigned int) i);
++	  print_vma (entry, ZERO_HEX);
++	  printf (" ");
++	}
+ 
+       if ((entry & 1) == 0)
+ 	{
+ 	  where = entry;
+-	  print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, where);
+-	  printf ("\n");
++	  if (dump_reloc)
++	    {
++	      print_relr_addr_and_sym (filedata, symtab, nsyms, strtab,
++				       where);
++	      printf ("\n");
++	    }
++
++	  if (do_got_section_contents)
++	    {
++	      all_relocations[r].r_offset = where;
++	      all_relocations[r].r_name = rtype;
++	      all_relocations[r].r_symbol = NULL;
++	      all_relocations[r].r_type = reltype_relr;
++	      r++;
++	    }
++
+ 	  where += relr_entsize;
+ 	}
+       else
+@@ -1921,7 +2142,7 @@ dump_relr_relocations (Filedata *          filedata,
+ 	    /* This can actually happen when the linker is allowed to shrink
+ 	       RELR sections.  For more details see: https://reviews.llvm.org/D67164. */
+ 	    continue;
+-	  else if (i == 0)
++	  else if (dump_reloc && i == 0)
+ 	    warn (_("Unusual RELR bitmap - no previous entry to set the base address\n"));
+ 
+ 	  for (j = 0; entry >>= 1; j++)
+@@ -1929,19 +2150,35 @@ dump_relr_relocations (Filedata *          filedata,
+ 	      {
+ 		uint64_t addr = where + (j * relr_entsize);
+ 
+-		if (first)
++		if (dump_reloc)
+ 		  {
+-		    print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr);
+-		    first = false;
++		    if (first)
++		      {
++			print_relr_addr_and_sym (filedata, symtab, nsyms,
++						 strtab, addr);
++			first = false;
++		      }
++		    else
++		      {
++			printf (_("\n%*s "),
++				relr_entsize == 4 ? 15 : 23, " ");
++			print_relr_addr_and_sym (filedata, symtab, nsyms,
++						 strtab, addr);
++		      }
+ 		  }
+-		else
++
++		if (do_got_section_contents)
+ 		  {
+-		    printf (_("\n%*s "), relr_entsize == 4 ? 15 : 23, " ");
+-		    print_relr_addr_and_sym (filedata, symtab, nsyms, strtab, addr);
++		    all_relocations[r].r_offset = addr;
++		    all_relocations[r].r_name = rtype;
++		    all_relocations[r].r_symbol = NULL;
++		    all_relocations[r].r_type = reltype_relr;
++		    r++;
+ 		  }
+ 	      }
+ 
+-	  printf ("\n");
++	  if (dump_reloc)
++	    printf ("\n");
+ 	  where += num_bits_in_entry * relr_entsize;
+ 	}
+     }
+@@ -1962,7 +2199,8 @@ dump_relocations (Filedata *          filedata,
+ 		  char *              strtab,
+ 		  uint64_t            strtablen,
+ 		  relocation_type     rel_type,
+-		  bool                is_dynsym)
++		  bool                is_dynsym,
++		  bool                dump_reloc)
+ {
+   size_t i;
+   Elf_Internal_Rela * rels;
+@@ -1987,38 +2225,41 @@ dump_relocations (Filedata *          filedata,
+       return false;
+     }
+ 
+-  if (is_32bit_elf)
++  if (dump_reloc)
+     {
+-      if (rel_type == reltype_rela)
+-	{
+-	  if (do_wide)
+-	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
+-	  else
+-	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
+-	}
+-      else
+-	{
+-	  if (do_wide)
+-	    printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
+-	  else
+-	    printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
+-	}
+-    }
+-  else
+-    {
+-      if (rel_type == reltype_rela)
++      if (is_32bit_elf)
+ 	{
+-	  if (do_wide)
+-	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
++	  if (rel_type == reltype_rela)
++	    {
++	      if (do_wide)
++		printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name + Addend\n"));
++	      else
++		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name + Addend\n"));
++	    }
+ 	  else
+-	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
++	    {
++	      if (do_wide)
++		printf (_(" Offset     Info    Type                Sym. Value  Symbol's Name\n"));
++	      else
++		printf (_(" Offset     Info    Type            Sym.Value  Sym. Name\n"));
++	    }
+ 	}
+       else
+ 	{
+-	  if (do_wide)
+-	    printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
++	  if (rel_type == reltype_rela)
++	    {
++	      if (do_wide)
++		printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend\n"));
++	      else
++		printf (_("  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n"));
++	    }
+ 	  else
+-	    printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
++	    {
++	      if (do_wide)
++		printf (_("    Offset             Info             Type               Symbol's Value  Symbol's Name\n"));
++	      else
++		printf (_("  Offset          Info           Type           Sym. Value    Sym. Name\n"));
++	    }
+ 	}
+     }
+ 
+@@ -2036,18 +2277,17 @@ dump_relocations (Filedata *          filedata,
+       type = get_reloc_type (filedata, inf);
+       symtab_index = get_reloc_symindex  (inf);
+ 
+-      if (is_32bit_elf)
+-	{
+-	  printf ("%8.8lx  %8.8lx ",
+-		  (unsigned long) offset & 0xffffffff,
+-		  (unsigned long) inf & 0xffffffff);
+-	}
+-      else
++      if (dump_reloc)
+ 	{
+-	  printf (do_wide
+-		  ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
+-		  : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
+-		  offset, inf);
++	  if (is_32bit_elf)
++	    printf ("%8.8lx  %8.8lx ",
++		    (unsigned long) offset & 0xffffffff,
++		    (unsigned long) inf & 0xffffffff);
++	  else
++	    printf (do_wide
++		    ? "%16.16" PRIx64 "  %16.16" PRIx64 " "
++		    : "%12.12" PRIx64 "  %12.12" PRIx64 " ",
++		    offset, inf);
+ 	}
+ 
+       switch (filedata->file_header.e_machine)
+@@ -2397,10 +2637,15 @@ dump_relocations (Filedata *          filedata,
+ 	  break;
+ 	}
+ 
+-      if (rtype == NULL)
+-	printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
+-      else
+-	printf (do_wide ? "%-22s" : "%-17.17s", rtype);
++      char *symbol_name = NULL;
++      if (dump_reloc)
++	{
++	  if (rtype == NULL)
++	    printf (_("unrecognized: %-7lx"),
++		    (unsigned long) type & 0xffffffff);
++	  else
++	    printf (do_wide ? "%-22s" : "%-17.17s", rtype);
++	}
+ 
+       if (filedata->file_header.e_machine == EM_ALPHA
+ 	  && rtype != NULL
+@@ -2419,23 +2664,29 @@ dump_relocations (Filedata *          filedata,
+ 	    default: rtype = NULL;
+ 	    }
+ 
+-	  if (rtype)
+-	    printf (" (%s)", rtype);
+-	  else
++	  if (dump_reloc)
+ 	    {
+-	      putchar (' ');
+-	      printf (_("<unknown addend: %" PRIx64 ">"),
+-		      rels[i].r_addend);
+-	      res = false;
++	      if (rtype)
++		printf (" (%s)", rtype);
++	      else
++		{
++		  putchar (' ');
++		  printf (_("<unknown addend: %" PRIx64 ">"),
++			  rels[i].r_addend);
++		  res = false;
++		}
+ 	    }
+ 	}
+       else if (symtab_index)
+ 	{
+ 	  if (symtab == NULL || symtab_index >= nsyms)
+ 	    {
+-	      error (_(" bad symbol index: %08lx in reloc\n"),
+-		     (unsigned long) symtab_index);
+-	      res = false;
++	      if (dump_reloc)
++		{
++		  error (_(" bad symbol index: %08lx in reloc\n"),
++			 (unsigned long) symtab_index);
++		  res = false;
++		}
+ 	    }
+ 	  else
+ 	    {
+@@ -2454,7 +2705,8 @@ dump_relocations (Filedata *          filedata,
+ 					     &sym_info,
+ 					     &vna_other);
+ 
+-	      printf (" ");
++	      if (dump_reloc)
++		printf (" ");
+ 
+ 	      if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
+ 		{
+@@ -2479,13 +2731,30 @@ dump_relocations (Filedata *          filedata,
+ 		  else
+ 		    name = strtab + psym->st_name;
+ 
+-		  len = print_symbol_name (width, name);
+-		  if (version_string)
+-		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
+-			    version_string);
+-		  printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
++		  if (do_got_section_contents)
++		    {
++		      if (version_string)
++			symbol_name = concat (name,
++					      sym_info == symbol_public
++					      ? "@@" : "@",
++					      version_string, NULL);
++		      else
++			symbol_name = xstrdup (name);
++		    }
++
++		  if (dump_reloc)
++		    {
++		      len = print_symbol_name (width, name);
++		      if (version_string)
++			printf (sym_info == symbol_public
++				? "@@%s" : "@%s",
++				version_string);
++		      printf ("()%-*s",
++			      len <= width ? (width + 1) - len : 1,
++			      " ");
++		    }
+ 		}
+-	      else
++	      else if (dump_reloc)
+ 		{
+ 		  print_vma (psym->st_value, LONG_HEX);
+ 
+@@ -2500,25 +2769,49 @@ dump_relocations (Filedata *          filedata,
+ 		    sec_name = printable_section_name_from_index
+ 		      (filedata, psym->st_shndx, NULL);
+ 
+-		  print_symbol_name (22, sec_name);
++		  if (do_got_section_contents)
++		    symbol_name = xstrdup (sec_name);
++		  if (dump_reloc)
++		    print_symbol_name (22, sec_name);
+ 		}
+ 	      else if (strtab == NULL)
+-		printf (_("<string table index: %3ld>"), psym->st_name);
++		{
++		  if (dump_reloc)
++		    printf (_("<string table index: %3ld>"),
++			    psym->st_name);
++		}
+ 	      else if (psym->st_name >= strtablen)
+ 		{
+-		  error (_("<corrupt string table index: %3ld>\n"),
+-			 psym->st_name);
+-		  res = false;
++		  if (dump_reloc)
++		    {
++		      error (_("<corrupt string table index: %3ld>\n"),
++			     psym->st_name);
++		      res = false;
++		    }
+ 		}
+ 	      else
+ 		{
+-		  print_symbol_name (22, strtab + psym->st_name);
+-		  if (version_string)
+-		    printf (sym_info == symbol_public ? "@@%s" : "@%s",
+-			    version_string);
++		  if (dump_reloc)
++		    {
++		      print_symbol_name (22, strtab + psym->st_name);
++		      if (version_string)
++			printf (sym_info == symbol_public
++				? "@@%s" : "@%s",
++				version_string);
++		    }
++		  if (all_relocations)
++		    {
++		      if (version_string)
++			symbol_name = concat (strtab + psym->st_name,
++					      sym_info == symbol_public
++					      ? "@@" : "@",
++					      version_string, NULL);
++		      else
++			symbol_name = xstrdup (strtab + psym->st_name);
++		    }
+ 		}
+ 
+-	      if (rel_type == reltype_rela)
++	      if (dump_reloc && rel_type == reltype_rela)
+ 		{
+ 		  uint64_t off = rels[i].r_addend;
+ 
+@@ -2529,7 +2822,7 @@ dump_relocations (Filedata *          filedata,
+ 		}
+ 	    }
+ 	}
+-      else if (rel_type == reltype_rela)
++      else if (dump_reloc && rel_type == reltype_rela)
+ 	{
+ 	  uint64_t off = rels[i].r_addend;
+ 
+@@ -2540,37 +2833,50 @@ dump_relocations (Filedata *          filedata,
+ 	    printf ("%" PRIx64, off);
+ 	}
+ 
+-      if (filedata->file_header.e_machine == EM_SPARCV9
+-	  && rtype != NULL
+-	  && streq (rtype, "R_SPARC_OLO10"))
+-	printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf));
+-
+-      putchar ('\n');
++      if (do_got_section_contents)
++	{
++	  all_relocations[i].r_offset = offset;
++	  all_relocations[i].r_name = rtype;
++	  all_relocations[i].r_symbol = symbol_name;
++	  all_relocations[i].r_addend = rels[i].r_addend;
++	  all_relocations[i].r_type = rel_type;
++	}
+ 
+-      if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
++      if (dump_reloc)
+ 	{
+-	  uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf);
+-	  uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf);
+-	  const char * rtype2 = elf_mips_reloc_type (type2);
+-	  const char * rtype3 = elf_mips_reloc_type (type3);
++	  if (filedata->file_header.e_machine == EM_SPARCV9
++	      && rtype != NULL
++	      && streq (rtype, "R_SPARC_OLO10"))
++	    printf (" + %" PRIx64, ELF64_R_TYPE_DATA (inf));
+ 
+-	  printf ("                    Type2: ");
++	  putchar ('\n');
+ 
+-	  if (rtype2 == NULL)
+-	    printf (_("unrecognized: %-7lx"),
+-		    (unsigned long) type2 & 0xffffffff);
+-	  else
+-	    printf ("%-17.17s", rtype2);
++	  if (! is_32bit_elf
++	      && filedata->file_header.e_machine == EM_MIPS)
++	    {
++	      uint64_t type2 = ELF64_MIPS_R_TYPE2 (inf);
++	      uint64_t type3 = ELF64_MIPS_R_TYPE3 (inf);
++	      const char * rtype2 = elf_mips_reloc_type (type2);
++	      const char * rtype3 = elf_mips_reloc_type (type3);
+ 
+-	  printf ("\n                    Type3: ");
++	      printf ("                    Type2: ");
+ 
+-	  if (rtype3 == NULL)
+-	    printf (_("unrecognized: %-7lx"),
+-		    (unsigned long) type3 & 0xffffffff);
+-	  else
+-	    printf ("%-17.17s", rtype3);
++	      if (rtype2 == NULL)
++		printf (_("unrecognized: %-7lx"),
++			(unsigned long) type2 & 0xffffffff);
++	      else
++		printf ("%-17.17s", rtype2);
+ 
+-	  putchar ('\n');
++	      printf ("\n                    Type3: ");
++
++	      if (rtype3 == NULL)
++		printf (_("unrecognized: %-7lx"),
++			(unsigned long) type3 & 0xffffffff);
++	      else
++		printf ("%-17.17s", rtype3);
++
++	      putchar ('\n');
++	    }
+ 	}
+     }
+ 
+@@ -6112,6 +6418,7 @@ static struct option options[] =
+   {"use-dynamic",      no_argument, 0, 'D'},
+   {"dynamic",	       no_argument, 0, 'd'},
+   {"headers",	       no_argument, 0, 'e'},
++  {"got-contents",     no_argument, 0, 'G'},
+   {"section-groups",   no_argument, 0, 'g'},
+   {"help",	       no_argument, 0, 'H'},
+   {"file-header",      no_argument, 0, 'h'},
+@@ -6184,6 +6491,8 @@ usage (FILE * stream)
+   fprintf (stream, _("\
+      --sections          An alias for --section-headers\n"));
+   fprintf (stream, _("\
++  -G --got               Display GOT section contents\n"));
++  fprintf (stream, _("\
+   -g --section-groups    Display the section groups\n"));
+   fprintf (stream, _("\
+   -t --section-details   Display the section details\n"));
+@@ -6418,7 +6727,7 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+     usage (stderr);
+ 
+   while ((c = getopt_long
+-	  (argc, argv, "ACDHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options, NULL)) != EOF)
++	  (argc, argv, "ACDGHILNPR:STU:VWXacdeghi:j:lnp:rstuvw::x:z", options, NULL)) != EOF)
+     {
+       switch (c)
+ 	{
+@@ -6442,8 +6751,13 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv)
+ 	  do_histogram = true;
+ 	  do_arch = true;
+ 	  do_notes = true;
++	  do_got_section_contents = true;
+ 	  break;
+ 
++	case 'G':
++	  do_got_section_contents = true;
++	  do_dump = true;
++	  break;
+ 	case 'g':
+ 	  do_section_groups = true;
+ 	  break;
+@@ -9438,7 +9752,8 @@ rel_type_from_sh_type (unsigned int sh_type)
+ 
+ static bool
+ display_relocations (Elf_Internal_Shdr *  section,
+-		     Filedata *           filedata)
++		     Filedata *           filedata,
++		     bool                 dump_reloc)
+ {
+   relocation_type rel_type = rel_type_from_sh_type (section->sh_type);
+ 
+@@ -9450,19 +9765,23 @@ display_relocations (Elf_Internal_Shdr *  section,
+   if (rel_size == 0)
+     return false;
+ 
+-  if (filedata->is_separate)
+-    printf (_("\nIn linked file '%s' relocation section "),
+-	    printable_string (filedata->file_name, 0));
+-  else
+-    printf (_("\nRelocation section "));
++  if (dump_reloc)
++    {
++      if (filedata->is_separate)
++	printf (_("\nIn linked file '%s' relocation section "),
++		printable_string (filedata->file_name, 0));
++      else
++	printf (_("\nRelocation section "));
+ 
+-  if (filedata->string_table == NULL)
+-    printf ("%d", section->sh_name);
+-  else
+-    printf ("'%s'", printable_section_name (filedata, section));
++      if (filedata->string_table == NULL)
++	printf ("%d", section->sh_name);
++      else
++	printf ("'%s'", printable_section_name (filedata, section));
++    }
+ 
+-  uint64_t num_rela = rel_size / section->sh_entsize;
+   uint64_t rel_offset = section->sh_offset;
++  uint64_t num_rela = rel_size / section->sh_entsize;
++  uint64_t num_reloc;
+ 
+   if (rel_type == reltype_relr)
+     {
+@@ -9471,26 +9790,33 @@ display_relocations (Elf_Internal_Shdr *  section,
+ 	 the number of words in the compressed RELR format.  So also provide
+ 	 the number of locations affected.  */
+ 
+-      uint64_t num_reloc = count_relr_relocations (filedata, section);
++      num_reloc = count_relr_relocations (filedata, section);
+ 
+-      printf (_(" at offset %#" PRIx64), rel_offset);
+-      printf (ngettext (" contains %" PRIu64 " entry which relocates",
+-			" contains %" PRIu64 " entries which relocate",
+-			num_rela), num_rela);
+-      printf (ngettext (" %" PRIu64 " location:\n",
+-			" %" PRIu64 " locations:\n",
+-			num_reloc), num_reloc);
++      if (dump_reloc)
++	{
++	  printf (_(" at offset %#" PRIx64), rel_offset);
++	  printf (ngettext (" contains %" PRIu64 " entry which relocates",
++			    " contains %" PRIu64 " entries which relocate",
++			    num_rela), num_rela);
++	  printf (ngettext (" %" PRIu64 " location:\n",
++			    " %" PRIu64 " locations:\n",
++			    num_reloc), num_reloc);
++	}
+     }
+   else
+     {
+-      printf (ngettext (" at offset %#" PRIx64
+-			" contains %" PRIu64 " entry:\n",
+-			" at offset %#" PRIx64
+-			" contains %" PRIu64 " entries:\n",
+-			num_rela),
+-	      rel_offset, num_rela);
++      num_reloc = num_rela;
++      if (dump_reloc)
++	printf (ngettext (" at offset %#" PRIx64
++			  " contains %" PRIu64 " entry:\n",
++			  " at offset %#" PRIx64
++			  " contains %" PRIu64 " entries:\n",
++			  num_rela),
++		rel_offset, num_rela);
+     }
+ 
++  update_all_relocations (num_reloc);
++
+   Elf_Internal_Shdr * symsec;
+   Elf_Internal_Sym *  symtab = NULL;
+   uint64_t            nsyms = 0;
+@@ -9522,12 +9848,15 @@ display_relocations (Elf_Internal_Shdr *  section,
+   bool res;
+ 
+   if (rel_type == reltype_relr)
+-    res = dump_relr_relocations (filedata, section, symtab, nsyms, strtab, strtablen);
++    res = dump_relr_relocations (filedata, section, symtab, nsyms,
++				 strtab, strtablen, dump_reloc);
+   else
+     res = dump_relocations (filedata, rel_offset, rel_size,
+ 			    symtab, nsyms, strtab, strtablen,
+ 			    rel_type,
+-			    symsec == NULL ? false : symsec->sh_type == SHT_DYNSYM);
++			    symsec == NULL
++			    ? false : symsec->sh_type == SHT_DYNSYM,
++			    dump_reloc);
+   free (strtab);
+   free (symtab);
+ 
+@@ -9541,14 +9870,16 @@ process_relocs (Filedata * filedata)
+ {
+   uint64_t rel_size;
+   uint64_t rel_offset;
++  unsigned int rel_entsz;
+ 
+-  if (!do_reloc)
++  if (!do_reloc && !do_got_section_contents)
+     return true;
+ 
+   if (do_using_dynamic)
+     {
+       relocation_type rel_type;
+       const char * name;
++      const char * entsz_name;
+       bool  has_dynamic_reloc;
+       unsigned int i;
+ 
+@@ -9556,57 +9887,97 @@ process_relocs (Filedata * filedata)
+ 
+       for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
+ 	{
++	  rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
++
++	  if (!rel_size)
++	    continue;
++
++	  has_dynamic_reloc = true;
++
+ 	  rel_type = dynamic_relocations [i].rel_type;
+ 	  name = dynamic_relocations [i].name;
+-	  rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
+ 	  rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc];
+ 
+-	  if (rel_size)
+-	    has_dynamic_reloc = true;
+-
+ 	  if (rel_type == reltype_unknown)
+ 	    {
+-	      if (dynamic_relocations [i].reloc == DT_JMPREL)
+-		switch (filedata->dynamic_info[DT_PLTREL])
+-		  {
+-		  case DT_REL:
+-		    rel_type = reltype_rel;
+-		    break;
+-		  case DT_RELA:
+-		    rel_type = reltype_rela;
+-		    break;
+-		  }
++	      if (dynamic_relocations [i].reloc != DT_JMPREL)
++		abort ();
++
++	      switch (filedata->dynamic_info[DT_PLTREL])
++		{
++		default:
++		  printf (_("<missing dynamic or corrupt tag: DT_PLTREL>\n"));
++		  continue;
++		case DT_REL:
++		  rel_type = reltype_rel;
++		  break;
++		case DT_RELA:
++		  rel_type = reltype_rela;
++		  break;
++		}
+ 	    }
+ 
+-	  if (rel_size)
++	  switch (rel_type)
++	    {
++	    default:
++	      abort ();
++	    case reltype_rel:
++	      rel_entsz = filedata->dynamic_info[DT_RELENT];
++	      entsz_name = "DT_RELENT";
++	      break;
++	    case reltype_rela:
++	      rel_entsz = filedata->dynamic_info[DT_RELAENT];
++	      entsz_name = "DT_RELAENT";
++	      break;
++	    case reltype_relr:
++	      rel_entsz = filedata->dynamic_info[DT_RELRENT];
++	      entsz_name = "DT_RELRENT";
++	      break;
++	    }
++
++	  if (do_reloc)
+ 	    {
+ 	      if (filedata->is_separate)
+ 		printf
+-		  (_("\nIn linked file '%s' section '%s' at offset %#" PRIx64
+-		     " contains %" PRId64 " bytes:\n"),
++		  (_("\nIn linked file '%s' section '%s' at offset"
++		     "%#" PRIx64 " contains %" PRId64 " bytes:\n"),
+ 		   filedata->file_name, name, rel_offset, rel_size);
+ 	      else
+ 		printf
+ 		  (_("\n'%s' relocation section at offset %#" PRIx64
+ 		     " contains %" PRId64 " bytes:\n"),
+ 		   name, rel_offset, rel_size);
++	    }
++
++	  if (rel_type != reltype_relr)
++	    {
++	      if (rel_entsz == 0)
++		{
++		  printf (_("<missing or corrupt dynamic tag: %s>\n"),
++			  entsz_name);
++		  continue;
++		}
++
++	      update_all_relocations (rel_size / rel_entsz);
+ 
+ 	      dump_relocations (filedata,
+-				offset_from_vma (filedata, rel_offset, rel_size),
++				offset_from_vma (filedata, rel_offset,
++						 rel_size),
+ 				rel_size,
+ 				filedata->dynamic_symbols,
+ 				filedata->num_dynamic_syms,
+ 				filedata->dynamic_strings,
+ 				filedata->dynamic_strings_length,
+-				rel_type, true /* is_dynamic */);
++				rel_type, true /* is_dynamic */,
++				do_reloc);
+ 	    }
+ 	}
+ 
+       if (is_ia64_vms (filedata))
+-        if (process_ia64_vms_dynamic_relocs (filedata))
++	if (process_ia64_vms_dynamic_relocs (filedata))
+ 	  has_dynamic_reloc = true;
+ 
+-      if (! has_dynamic_reloc)
++      if (do_reloc && ! has_dynamic_reloc)
+ 	{
+ 	  if (filedata->is_separate)
+ 	    printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
+@@ -9625,11 +9996,11 @@ process_relocs (Filedata * filedata)
+ 	   i < filedata->file_header.e_shnum;
+ 	   i++, section++)
+ 	{
+-	  if (display_relocations (section, filedata))
++	  if (display_relocations (section, filedata, do_reloc))
+ 	    found = true;
+ 	}
+ 
+-      if (! found)
++      if (do_reloc && ! found)
+ 	{
+ 	  /* Users sometimes forget the -D option, so try to be helpful.  */
+ 	  for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
+@@ -17613,7 +17984,7 @@ process_section_contents (Filedata * filedata)
+ 	    case SHT_RELA:
+ 	    case SHT_REL:
+ 	    case SHT_RELR:
+-	      res &= display_relocations (section, filedata);
++	      res &= display_relocations (section, filedata, true);
+ 	      break;
+ 
+ 	    case SHT_NOTE:
+@@ -17704,6 +18075,196 @@ process_section_contents (Filedata * filedata)
+   return res;
+ }
+ 
++static int
++elf_relocation_cmp (const void *p, const void *q)
++{
++  elf_relocation *rp = (elf_relocation *) p;
++  elf_relocation *rq = (elf_relocation *) q;
++
++  return (rp->r_offset > rq->r_offset
++	  ? 1
++	  : (rp->r_offset < rq->r_offset ? -1 : 0));
++}
++
++static void
++display_elf_relocation_at (uint64_t offset, uint64_t g)
++{
++  bool matched = false;
++
++  for (size_t i = 0; i < all_relocations_count; i++)
++    if (all_relocations_root[i].r_offset == offset)
++      {
++	if (do_wide)
++	  printf (" %-22s", all_relocations_root[i].r_name);
++	else
++	  printf (" %-17.17s", all_relocations_root[i].r_name);
++
++	uint64_t off;
++	switch (all_relocations_root[i].r_type)
++	  {
++	  default:
++	    abort ();
++	  case reltype_rel:
++	  case reltype_relr:
++	    off = g;
++	    break;
++	  case reltype_rela:
++	    off = all_relocations_root[i].r_addend;
++	    break;
++	  }
++
++	if (all_relocations_root[i].r_symbol)
++	  {
++	    printf (" %s", all_relocations_root[i].r_symbol);
++	    if ((int64_t) off < 0)
++	      printf (" - %" PRIx64, -off);
++	    else
++	      printf (" + %" PRIx64, off);
++	  }
++	else
++	  {
++	    if ((int64_t) off < 0)
++	      printf (" -%" PRIx64, -off);
++	    else
++	      printf (" %" PRIx64, off);
++	  }
++
++	matched = true;
++	break;
++      }
++    else if (all_relocations_root[i].r_offset > offset)
++      break;
++
++  if (!matched)
++    {
++      if (do_wide)
++	printf ("%*c", 24, ' ');
++      else
++	printf ("%*c", 19, ' ');
++      printf ("%" PRIx64, g);
++    }
++}
++
++static bool
++process_got_section_contents (Filedata * filedata)
++{
++  Elf_Internal_Shdr * section;
++  unsigned int i;
++  uint64_t entries;
++  unsigned char *data;
++  bool res = true;
++
++  if (! do_got_section_contents)
++    return res;
++
++  qsort (all_relocations_root, all_relocations_count,
++	 sizeof (elf_relocation), elf_relocation_cmp);
++
++  initialise_dumps_byname (filedata);
++
++  for (i = 0, section = filedata->section_headers;
++       i < filedata->file_header.e_shnum;
++       i++, section++)
++    if (section->sh_type == SHT_PROGBITS
++	&& section->sh_size != 0)
++      {
++	const char *name = printable_section_name (filedata, section);
++
++	if (!startswith (name, ".got"))
++	  continue;
++
++	data = (unsigned char *) get_section_contents (section,
++						       filedata);
++	if (data == NULL)
++	  {
++	    res = false;
++	    goto out;
++	  }
++
++	uint32_t entsz = section->sh_entsize;
++	entries = section->sh_size / entsz;
++	if (entries == 1)
++	  printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),
++		  name);
++	else
++	  printf (_("\nGlobal Offset Table '%s' contains %" PRIu64
++		    " entries:\n"), name, entries);
++
++	uint64_t g;
++
++	if (is_32bit_elf)
++	  {
++	    uint32_t j, n = entries;
++	    uint32_t addr;
++	    struct got32
++	      {
++		unsigned char bytes[4];
++	      } *got;
++
++	    if (do_wide)
++	      printf (_("   Index:  Address      Reloc             Sym. Name + Addend/Value\n"));
++		      /* |---9---| |---8--| |---------22---------| |...........  */
++	    else
++	      printf (_(" Index:  Address      Reloc        Sym. Name + Addend/Value\n"));
++		      /* |--7--| |---8--| |-------17------| |...........  */
++	    addr = section->sh_addr;
++	    got = (struct got32 *) data;
++
++	    for (j = 0; j < n; j++)
++	      {
++		g = BYTE_GET (got[j].bytes);
++		if (do_wide)
++		  printf ("%8" PRIu32 ": %8.8" PRIx32, j, addr);
++		else
++		  printf ("%6" PRIu32 ": %8.8" PRIx32, j, addr);
++		display_elf_relocation_at (addr, g);
++		putchar ('\n');
++		addr += entsz;
++	      }
++	  }
++	else
++	  {
++	    uint64_t j, addr;
++	    struct got64
++	      {
++		unsigned char bytes[4];
++	      } *got;
++
++	    if (do_wide)
++	      printf (_("   Index:      Address          Reloc             Sym. Name + Addend/Value\n"));
++		      /* |---9---| |------16------| |---------22---------| |...........  */
++	    else
++	      printf (_(" Index:    Address       Reloc         Sym. Name + Addend/Value\n"));
++		      /* |--7--| |----12----| |------17-------| |...........  */
++
++	    addr = section->sh_addr;
++	    got = (struct got64 *) data;
++	    for (j = 0; j < entries; j++)
++	      {
++		g = BYTE_GET (got[j].bytes);
++		if (do_wide)
++		  printf ("%8" PRIu64 ": %16.16" PRIx64, j, addr);
++		else
++		  printf ("%6" PRIu64 ": %12.12" PRIx64, j, addr);
++		display_elf_relocation_at (addr, g);
++		putchar ('\n');
++		addr += entsz;
++	      }
++	  }
++
++	free (data);
++      }
++
++ out:
++  for (size_t j = 0; j < all_relocations_count; j++)
++    free (all_relocations_root[j].r_symbol);
++  free (all_relocations_root);
++  all_relocations_root = NULL;
++  all_relocations = NULL;
++  all_relocations_count = 0;
++  return res;
++}
++
+ static void
+ process_mips_fpe_exception (int mask)
+ {
+@@ -23819,6 +24380,9 @@ process_object (Filedata * filedata)
+   if (! process_section_contents (filedata))
+     res = false;
+ 
++  if (! process_got_section_contents (filedata))
++    res = false;
++
+   if (have_separate_files)
+     {
+       separate_info * d;
+diff --git a/ld/testsuite/ld-i386/binutils.exp b/ld/testsuite/ld-i386/binutils.exp
+new file mode 100644
+index 00000000000..eb8c14215c3
+--- /dev/null
++++ b/ld/testsuite/ld-i386/binutils.exp
+@@ -0,0 +1,45 @@
++# Expect script for ELF/i386 binutils tests on linker outputs.
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
++# MA 02110-1301, USA.
++#
++
++if ![is_elf_format] {
++    return
++}
++
++if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
++    return
++}
++
++run_ld_link_tests [list \
++    [list \
++	"Build libgot-1.so" \
++	"-shared -melf_i386 --no-ld-generated-unwind-info \
++	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
++	 $NO_DT_RELR_LDFLAGS" \
++	"" \
++	"--32 -mx86-used-note=no --generate-missing-build-notes=no" \
++	{got-1.s} \
++	{{readelf -rW libgot-1a.rd} \
++	 {readelf -aW libgot-1b.rd} \
++	 {readelf -G libgot-1c.rd} \
++	 {readelf -GW libgot-1d.rd}} \
++	"libgot-1.so" \
++    ] \
++]
+diff --git a/ld/testsuite/ld-i386/got-1.s b/ld/testsuite/ld-i386/got-1.s
+new file mode 100644
+index 00000000000..30e45f9be43
+--- /dev/null
++++ b/ld/testsuite/ld-i386/got-1.s
+@@ -0,0 +1,7 @@
++	.text
++	.globl	func
++	.type	func, @function
++func:
++	call	*foo@GOT(%ebx)
++	jmp	bar@PLT
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-i386/libgot-1a.rd b/ld/testsuite/ld-i386/libgot-1a.rd
+new file mode 100644
+index 00000000000..b8609b8fbe2
+--- /dev/null
++++ b/ld/testsuite/ld-i386/libgot-1a.rd
+@@ -0,0 +1,9 @@
++
++Relocation section '.rel.dyn' at offset 0x128 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name
++0+2001fc  00000206 R_386_GLOB_DAT         00000000   foo
++
++Relocation section '.rel.plt' at offset 0x130 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name
++0+20020c  00000307 R_386_JUMP_SLOT        00000000   bar
++#pass
+diff --git a/ld/testsuite/ld-i386/libgot-1b.rd b/ld/testsuite/ld-i386/libgot-1b.rd
+new file mode 100644
+index 00000000000..070fa424d4d
+--- /dev/null
++++ b/ld/testsuite/ld-i386/libgot-1b.rd
+@@ -0,0 +1,119 @@
++ELF Header:
++  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
++  Class:                             ELF32
++  Data:                              2's complement, little endian
++  Version:                           1 \(current\)
++  OS/ABI:                            UNIX - System V
++  ABI Version:                       0
++  Type:                              DYN \(Shared object file\)
++  Machine:                           Intel 80386
++  Version:                           0x1
++  Entry point address:               0x0
++  Start of program headers:          52 \(bytes into file\)
++  Start of section headers:          768 \(bytes into file\)
++  Flags:                             0x0
++  Size of this header:               52 \(bytes\)
++  Size of program headers:           32 \(bytes\)
++  Number of program headers:         4
++  Size of section headers:           40 \(bytes\)
++  Number of section headers:         14
++  Section header string table index: 13
++
++Section Headers:
++  \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
++  \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
++  \[ 1\] .hash             HASH            000000b4 0000b4 000024 04   A  2   0  4
++  \[ 2\] .dynsym           DYNSYM          000000d8 0000d8 000040 10   A  3   1  4
++  \[ 3\] .dynstr           STRTAB          00000118 000118 00000e 00   A  0   0  1
++  \[ 4\] .rel.dyn          REL             00000128 000128 000008 08   A  2   0  4
++  \[ 5\] .rel.plt          REL             00000130 000130 000008 08  AI  2  10  4
++  \[ 6\] .plt              PROGBITS        00000140 000140 000020 04  AX  0   0 16
++  \[ 7\] .text             PROGBITS        00000160 000160 00000b 00  AX  0   0  1
++  \[ 8\] .dynamic          DYNAMIC         0020016c 00016c 000090 08  WA  3   0  4
++  \[ 9\] .got              PROGBITS        002001fc 0001fc 000004 04  WA  0   0  4
++  \[10\] .got.plt          PROGBITS        00200200 000200 000010 04  WA  0   0  4
++  \[11\] .symtab           SYMTAB          00000000 000210 000060 10     12   3  4
++  \[12\] .strtab           STRTAB          00000000 000270 00002d 00      0   0  1
++  \[13\] .shstrtab         STRTAB          00000000 00029d 000060 00      0   0  1
++Key to Flags:
++  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
++  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
++  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
++  D \(mbind\), p \(processor specific\)
++
++There are no section groups in this file.
++
++Program Headers:
++  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
++  LOAD           0x000000 0x00000000 0x00000000 0x0016b 0x0016b R E 0x200000
++  LOAD           0x00016c 0x0020016c 0x0020016c 0x000a4 0x000a4 RW  0x200000
++  DYNAMIC        0x00016c 0x0020016c 0x0020016c 0x00090 0x00090 RW  0x4
++  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
++
++ Section to Segment mapping:
++  Segment Sections...
++   00     .hash .dynsym .dynstr .rel.dyn .rel.plt .plt .text 
++   01     .dynamic .got .got.plt 
++   02     .dynamic 
++   03     
++
++Dynamic section at offset 0x16c contains 13 entries:
++  Tag        Type                         Name/Value
++ 0x00000004 \(HASH\)                       0xb4
++ 0x00000005 \(STRTAB\)                     0x118
++ 0x00000006 \(SYMTAB\)                     0xd8
++ 0x0000000a \(STRSZ\)                      14 \(bytes\)
++ 0x0000000b \(SYMENT\)                     16 \(bytes\)
++ 0x00000003 \(PLTGOT\)                     0x200200
++ 0x00000002 \(PLTRELSZ\)                   8 \(bytes\)
++ 0x00000014 \(PLTREL\)                     REL
++ 0x00000017 \(JMPREL\)                     0x130
++ 0x00000011 \(REL\)                        0x128
++ 0x00000012 \(RELSZ\)                      8 \(bytes\)
++ 0x00000013 \(RELENT\)                     8 \(bytes\)
++ 0x00000000 \(NULL\)                       0x0
++
++Relocation section '.rel.dyn' at offset 0x128 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name
++0+2001fc  00000206 R_386_GLOB_DAT         00000000   foo
++
++Relocation section '.rel.plt' at offset 0x130 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name
++0+20020c  00000307 R_386_JUMP_SLOT        00000000   bar
++No processor specific unwind information to decode
++
++Symbol table '.dynsym' contains 4 entries:
++   Num:    Value  Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Symbol table '.symtab' contains 6 entries:
++   Num:    Value  Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 0020016c     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
++ +[a-f0-9]+: 00200200     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
++ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Histogram for bucket list length \(total of 3 buckets\):
++ Length  Number     % of total  Coverage
++      0  1          \( 33.3%\)
++      1  1          \( 33.3%\)     33.3%
++      2  1          \( 33.3%\)    100.0%
++
++No version information found in this file.
++
++Global Offset Table '.got' contains 1 entry:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200                        20016c
++ +[a-f0-9]+: 00200204                        0
++ +[a-f0-9]+: 00200208                        0
++ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
++#pass
+diff --git a/ld/testsuite/ld-i386/libgot-1c.rd b/ld/testsuite/ld-i386/libgot-1c.rd
+new file mode 100644
+index 00000000000..a69279ab8cc
+--- /dev/null
++++ b/ld/testsuite/ld-i386/libgot-1c.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++ Index:  Address      Reloc        Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 002001fc R_386_GLOB_DAT    foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++ Index:  Address      Reloc        Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200                   20016c
++ +[a-f0-9]+: 00200204                   0
++ +[a-f0-9]+: 00200208                   0
++ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT   bar \+ 156
++#pass
+diff --git a/ld/testsuite/ld-i386/libgot-1d.rd b/ld/testsuite/ld-i386/libgot-1d.rd
+new file mode 100644
+index 00000000000..af5e3df0153
+--- /dev/null
++++ b/ld/testsuite/ld-i386/libgot-1d.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 002001fc R_386_GLOB_DAT         foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200                        20016c
++ +[a-f0-9]+: 00200204                        0
++ +[a-f0-9]+: 00200208                        0
++ +[a-f0-9]+: 0020020c R_386_JUMP_SLOT        bar \+ 156
++#pass
+diff --git a/ld/testsuite/ld-x86-64/binutils.exp b/ld/testsuite/ld-x86-64/binutils.exp
+new file mode 100644
+index 00000000000..70609a8da12
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/binutils.exp
+@@ -0,0 +1,59 @@
++# Expect script for ELF/x86-64 binutils tests on linker outputs.
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
++# MA 02110-1301, USA.
++#
++
++if ![is_elf_format] {
++    return
++}
++
++if { ![istarget "x86_64-*-*"] } {
++    return
++}
++
++run_ld_link_tests [list \
++    [list \
++	"Build libgot-1.so" \
++	"-shared -melf_x86_64 --no-ld-generated-unwind-info \
++	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
++	 -z nomark-plt $NO_DT_RELR_LDFLAGS" \
++	"" \
++	"--64 -mx86-used-note=no --generate-missing-build-notes=no" \
++	{got-1.s} \
++	{{readelf -rW libgot-1a.rd} \
++	 {readelf -aW libgot-1b.rd} \
++	 {readelf -G libgot-1c.rd} \
++	 {readelf -GW libgot-1d.rd}} \
++	"libgot-1.so" \
++    ] \
++    [list \
++	"Build libgot-1-x32.so" \
++	"-shared -melf32_x86_64 --no-ld-generated-unwind-info \
++	 -z noseparate-code -z max-page-size=0x200000 --hash-style=sysv \
++	 -z nomark-plt $NO_DT_RELR_LDFLAGS" \
++	"" \
++	"--x32 -mx86-used-note=no --generate-missing-build-notes=no" \
++	{got-1.s} \
++	{{readelf -rW libgot-1a-x32.rd} \
++	 {readelf -aW libgot-1b-x32.rd} \
++	 {readelf -G libgot-1c-x32.rd} \
++	 {readelf -GW libgot-1d-x32.rd}} \
++	"libgot-1-x32.so" \
++    ] \
++]
+diff --git a/ld/testsuite/ld-x86-64/got-1.s b/ld/testsuite/ld-x86-64/got-1.s
+new file mode 100644
+index 00000000000..76370691f1d
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/got-1.s
+@@ -0,0 +1,7 @@
++	.text
++	.globl	func
++	.type	func, @function
++func:
++	call	*foo@GOTPCREL(%rip)
++	jmp	bar@PLT
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/libgot-1a-x32.rd b/ld/testsuite/ld-x86-64/libgot-1a-x32.rd
+new file mode 100644
+index 00000000000..6861d6588d6
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1a-x32.rd
+@@ -0,0 +1,9 @@
++
++Relocation section '.rela.dyn' at offset 0x128 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
++0+200200  00000206 R_X86_64_GLOB_DAT      00000000   foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x134 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
++0+200220  00000307 R_X86_64_JUMP_SLOT     00000000   bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1a.rd b/ld/testsuite/ld-x86-64/libgot-1a.rd
+new file mode 100644
+index 00000000000..8ed447003c7
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1a.rd
+@@ -0,0 +1,9 @@
++
++Relocation section '.rela.dyn' at offset 0x1b8 contains 1 entry:
++    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
++0+200340  0000000200000006 R_X86_64_GLOB_DAT      0000000000000000 foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x1d0 contains 1 entry:
++    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
++0+200360  0000000300000007 R_X86_64_JUMP_SLOT     0000000000000000 bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1b-x32.rd b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
+new file mode 100644
+index 00000000000..2245275b980
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1b-x32.rd
+@@ -0,0 +1,119 @@
++ELF Header:
++  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
++  Class:                             ELF32
++  Data:                              2's complement, little endian
++  Version:                           1 \(current\)
++  OS/ABI:                            UNIX - System V
++  ABI Version:                       0
++  Type:                              DYN \(Shared object file\)
++  Machine:                           Advanced Micro Devices X86-64
++  Version:                           0x1
++  Entry point address:               0x0
++  Start of program headers:          52 \(bytes into file\)
++  Start of section headers:          792 \(bytes into file\)
++  Flags:                             0x0
++  Size of this header:               52 \(bytes\)
++  Size of program headers:           32 \(bytes\)
++  Number of program headers:         4
++  Size of section headers:           40 \(bytes\)
++  Number of section headers:         14
++  Section header string table index: 13
++
++Section Headers:
++  \[Nr\] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
++  \[ 0\]                   NULL            00000000 000000 000000 00      0   0  0
++  \[ 1\] .hash             HASH            000000b4 0000b4 000024 04   A  2   0  4
++  \[ 2\] .dynsym           DYNSYM          000000d8 0000d8 000040 10   A  3   1  4
++  \[ 3\] .dynstr           STRTAB          00000118 000118 00000e 00   A  0   0  1
++  \[ 4\] .rela.dyn         RELA            00000128 000128 00000c 0c   A  2   0  4
++  \[ 5\] .rela.plt         RELA            00000134 000134 00000c 0c  AI  2  10  4
++  \[ 6\] .plt              PROGBITS        00000140 000140 000020 10  AX  0   0 16
++  \[ 7\] .text             PROGBITS        00000160 000160 00000b 00  AX  0   0  1
++  \[ 8\] .dynamic          DYNAMIC         0020016c 00016c 000090 08  WA  3   0  4
++  \[ 9\] .got              PROGBITS        00200200 000200 000008 08  WA  0   0  8
++  \[10\] .got.plt          PROGBITS        00200208 000208 000020 08  WA  0   0  8
++  \[11\] .symtab           SYMTAB          00000000 000228 000060 10     12   3  4
++  \[12\] .strtab           STRTAB          00000000 000288 00002d 00      0   0  1
++  \[13\] .shstrtab         STRTAB          00000000 0002b5 000062 00      0   0  1
++Key to Flags:
++  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
++  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
++  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
++  D \(mbind\), l \(large\), p \(processor specific\)
++
++There are no section groups in this file.
++
++Program Headers:
++  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
++  LOAD           0x000000 0x00000000 0x00000000 0x0016b 0x0016b R E 0x200000
++  LOAD           0x00016c 0x0020016c 0x0020016c 0x000bc 0x000bc RW  0x200000
++  DYNAMIC        0x00016c 0x0020016c 0x0020016c 0x00090 0x00090 RW  0x4
++  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
++
++ Section to Segment mapping:
++  Segment Sections...
++   00     .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text 
++   01     .dynamic .got .got.plt 
++   02     .dynamic 
++   03     
++
++Dynamic section at offset 0x16c contains 13 entries:
++  Tag        Type                         Name/Value
++ 0x00000004 \(HASH\)                       0xb4
++ 0x00000005 \(STRTAB\)                     0x118
++ 0x00000006 \(SYMTAB\)                     0xd8
++ 0x0000000a \(STRSZ\)                      14 \(bytes\)
++ 0x0000000b \(SYMENT\)                     16 \(bytes\)
++ 0x00000003 \(PLTGOT\)                     0x200208
++ 0x00000002 \(PLTRELSZ\)                   12 \(bytes\)
++ 0x00000014 \(PLTREL\)                     RELA
++ 0x00000017 \(JMPREL\)                     0x134
++ 0x00000007 \(RELA\)                       0x128
++ 0x00000008 \(RELASZ\)                     12 \(bytes\)
++ 0x00000009 \(RELAENT\)                    12 \(bytes\)
++ 0x00000000 \(NULL\)                       0x0
++
++Relocation section '.rela.dyn' at offset 0x128 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
++0+200200  00000206 R_X86_64_GLOB_DAT      00000000   foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x134 contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name \+ Addend
++0+200220  00000307 R_X86_64_JUMP_SLOT     00000000   bar \+ 0
++No processor specific unwind information to decode
++
++Symbol table '.dynsym' contains 4 entries:
++   Num:    Value  Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Symbol table '.symtab' contains 6 entries:
++   Num:    Value  Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 0020016c     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
++ +[a-f0-9]+: 00200208     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
++ +[a-f0-9]+: 00000160     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Histogram for bucket list length \(total of 3 buckets\):
++ Length  Number     % of total  Coverage
++      0  1          \( 33.3%\)
++      1  1          \( 33.3%\)     33.3%
++      2  1          \( 33.3%\)    100.0%
++
++No version information found in this file.
++
++Global Offset Table '.got' contains 1 entry:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200208                        20016c
++ +[a-f0-9]+: 00200210                        0
++ +[a-f0-9]+: 00200218                        0
++ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1b.rd b/ld/testsuite/ld-x86-64/libgot-1b.rd
+new file mode 100644
+index 00000000000..9d5cc030f72
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1b.rd
+@@ -0,0 +1,119 @@
++ELF Header:
++  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
++  Class:                             ELF64
++  Data:                              2's complement, little endian
++  Version:                           1 \(current\)
++  OS/ABI:                            UNIX - System V
++  ABI Version:                       0
++  Type:                              DYN \(Shared object file\)
++  Machine:                           Advanced Micro Devices X86-64
++  Version:                           0x1
++  Entry point address:               0x0
++  Start of program headers:          64 \(bytes into file\)
++  Start of section headers:          1160 \(bytes into file\)
++  Flags:                             0x0
++  Size of this header:               64 \(bytes\)
++  Size of program headers:           56 \(bytes\)
++  Number of program headers:         4
++  Size of section headers:           64 \(bytes\)
++  Number of section headers:         14
++  Section header string table index: 13
++
++Section Headers:
++  \[Nr\] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
++  \[ 0\]                   NULL            0000000000000000 000000 000000 00      0   0  0
++  \[ 1\] .hash             HASH            0000000000000120 000120 000024 04   A  2   0  8
++  \[ 2\] .dynsym           DYNSYM          0000000000000148 000148 000060 18   A  3   1  8
++  \[ 3\] .dynstr           STRTAB          00000000000001a8 0001a8 00000e 00   A  0   0  1
++  \[ 4\] .rela.dyn         RELA            00000000000001b8 0001b8 000018 18   A  2   0  8
++  \[ 5\] .rela.plt         RELA            00000000000001d0 0001d0 000018 18  AI  2  10  8
++  \[ 6\] .plt              PROGBITS        00000000000001f0 0001f0 000020 10  AX  0   0 16
++  \[ 7\] .text             PROGBITS        0000000000000210 000210 00000b 00  AX  0   0  1
++  \[ 8\] .dynamic          DYNAMIC         0000000000200220 000220 000120 10  WA  3   0  8
++  \[ 9\] .got              PROGBITS        0000000000200340 000340 000008 08  WA  0   0  8
++  \[10\] .got.plt          PROGBITS        0000000000200348 000348 000020 08  WA  0   0  8
++  \[11\] .symtab           SYMTAB          0000000000000000 000368 000090 18     12   3  8
++  \[12\] .strtab           STRTAB          0000000000000000 0003f8 00002d 00      0   0  1
++  \[13\] .shstrtab         STRTAB          0000000000000000 000425 000062 00      0   0  1
++Key to Flags:
++  W \(write\), A \(alloc\), X \(execute\), M \(merge\), S \(strings\), I \(info\),
++  L \(link order\), O \(extra OS processing required\), G \(group\), T \(TLS\),
++  C \(compressed\), x \(unknown\), o \(OS specific\), E \(exclude\),
++  D \(mbind\), l \(large\), p \(processor specific\)
++
++There are no section groups in this file.
++
++Program Headers:
++  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
++  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x00021b 0x00021b R E 0x200000
++  LOAD           0x000220 0x0000000000200220 0x0000000000200220 0x000148 0x000148 RW  0x200000
++  DYNAMIC        0x000220 0x0000000000200220 0x0000000000200220 0x000120 0x000120 RW  0x8
++  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x10
++
++ Section to Segment mapping:
++  Segment Sections...
++   00     .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text 
++   01     .dynamic .got .got.plt 
++   02     .dynamic 
++   03     
++
++Dynamic section at offset 0x220 contains 13 entries:
++  Tag        Type                         Name/Value
++ 0x0000000000000004 \(HASH\)               0x120
++ 0x0000000000000005 \(STRTAB\)             0x1a8
++ 0x0000000000000006 \(SYMTAB\)             0x148
++ 0x000000000000000a \(STRSZ\)              14 \(bytes\)
++ 0x000000000000000b \(SYMENT\)             24 \(bytes\)
++ 0x0000000000000003 \(PLTGOT\)             0x200348
++ 0x0000000000000002 \(PLTRELSZ\)           24 \(bytes\)
++ 0x0000000000000014 \(PLTREL\)             RELA
++ 0x0000000000000017 \(JMPREL\)             0x1d0
++ 0x0000000000000007 \(RELA\)               0x1b8
++ 0x0000000000000008 \(RELASZ\)             24 \(bytes\)
++ 0x0000000000000009 \(RELAENT\)            24 \(bytes\)
++ 0x0000000000000000 \(NULL\)               0x0
++
++Relocation section '.rela.dyn' at offset 0x1b8 contains 1 entry:
++    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
++0+200340  0000000200000006 R_X86_64_GLOB_DAT      0000000000000000 foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x1d0 contains 1 entry:
++    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
++0+200360  0000000300000007 R_X86_64_JUMP_SLOT     0000000000000000 bar \+ 0
++No processor specific unwind information to decode
++
++Symbol table '.dynsym' contains 4 entries:
++   Num:    Value          Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 0000000000000210     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Symbol table '.symtab' contains 6 entries:
++   Num:    Value          Size Type    Bind   Vis      Ndx Name
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
++ +[a-f0-9]+: 0000000000200220     0 OBJECT  LOCAL  DEFAULT    8 _DYNAMIC
++ +[a-f0-9]+: 0000000000200348     0 OBJECT  LOCAL  DEFAULT   10 _GLOBAL_OFFSET_TABLE_
++ +[a-f0-9]+: 0000000000000210     0 FUNC    GLOBAL DEFAULT    7 func
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND foo
++ +[a-f0-9]+: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
++
++Histogram for bucket list length \(total of 3 buckets\):
++ Length  Number     % of total  Coverage
++      0  1          \( 33.3%\)
++      1  1          \( 33.3%\)     33.3%
++      2  1          \( 33.3%\)    100.0%
++
++No version information found in this file.
++
++Global Offset Table '.got' contains 1 entry:
++   Index:      Address          Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:      Address          Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 0000000000200348                        200220
++ +[a-f0-9]+: 0000000000200350                        0
++ +[a-f0-9]+: 0000000000200358                        0
++ +[a-f0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1c-x32.rd b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
+new file mode 100644
+index 00000000000..bec8ac79e07
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1c-x32.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++ Index:  Address      Reloc        Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++ Index:  Address      Reloc        Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200208                   20016c
++ +[a-f0-9]+: 00200210                   0
++ +[a-f0-9]+: 00200218                   0
++ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLO bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1c.rd b/ld/testsuite/ld-x86-64/libgot-1c.rd
+new file mode 100644
+index 00000000000..4944b3111c3
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1c.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++ Index:    Address       Reloc         Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 000000200340 R_X86_64_GLOB_DAT foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++ Index:    Address       Reloc         Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 000000200348                   200220
++ +[a-f0-9]+: 000000200350                   0
++ +[a-f0-9]+: 000000200358                   0
++ +[a-f0-9]+: 000000200360 R_X86_64_JUMP_SLO bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1d-x32.rd b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
+new file mode 100644
+index 00000000000..fdad77aab84
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1d-x32.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200200 R_X86_64_GLOB_DAT      foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:  Address      Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 00200208                        20016c
++ +[a-f0-9]+: 00200210                        0
++ +[a-f0-9]+: 00200218                        0
++ +[a-f0-9]+: 00200220 R_X86_64_JUMP_SLOT     bar \+ 0
++#pass
+diff --git a/ld/testsuite/ld-x86-64/libgot-1d.rd b/ld/testsuite/ld-x86-64/libgot-1d.rd
+new file mode 100644
+index 00000000000..2e0a6c1e0db
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/libgot-1d.rd
+@@ -0,0 +1,12 @@
++
++Global Offset Table '.got' contains 1 entry:
++   Index:      Address          Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 0000000000200340 R_X86_64_GLOB_DAT      foo \+ 0
++
++Global Offset Table '.got.plt' contains 4 entries:
++   Index:      Address          Reloc             Sym. Name \+ Addend/Value
++ +[a-f0-9]+: 0000000000200348                        200220
++ +[a-f0-9]+: 0000000000200350                        0
++ +[a-f0-9]+: 0000000000200358                        0
++ +[a-f0-9]+: 0000000000200360 R_X86_64_JUMP_SLOT     bar \+ 0
++#pass
+
+base-commit: f5493d6c96da9faf5f16d748cf6c899f0836b12d
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-25  2:49 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-25  2:49 UTC (permalink / raw
  To: gentoo-commits

commit:     de50d3ef0f4736b06574fbfe2a6587841adc0099
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 25 02:48:47 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 25 02:48:47 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=de50d3ef

9999: TLSDESC relocs shouldn't be resolved lazily

Bug: https://sourceware.org/PR27137
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ut-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch | 931 +++++++++++++++++++++
 1 file changed, 931 insertions(+)

diff --git a/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch b/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch
new file mode 100644
index 0000000..1df59c2
--- /dev/null
+++ b/9999/0006-x86-Don-t-put-R_386_TLS_DESC-R_X86_64_TLSDESC-in-.re.patch
@@ -0,0 +1,931 @@
+From 0b2d86d4c1c26b6e1d48a5dc7842b21698d80abc Mon Sep 17 00:00:00 2001
+Message-ID: <0b2d86d4c1c26b6e1d48a5dc7842b21698d80abc.1756090103.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sun, 24 Aug 2025 14:43:44 -0700
+Subject: [PATCH] x86: Don't put R_386_TLS_DESC/R_X86_64_TLSDESC in
+ .rel.plt/.rela.plt
+
+Since lazy tlsdesc relocation has data races:
+
+https://sourceware.org/bugzilla/show_bug.cgi?id=27137
+
+put R_386_TLS_DESC and R_X86_64_TLSDESC relocation in .rela.tls/.rel.tls
+section, instead of .rel.plt/.rela.plt section.
+
+Tested with glibc/i686 and glibc/x86-64 compiled with -mtls-dialect=gnu2
+as well as GCC 16 configured with --with-tls=gnu2.
+
+bfd/
+
+	PR ld/28387
+	* elf32-i386.c (elf_i386_relocate_section): Put R_386_TLS_DESC
+	in rel_tls_desc instead of elf.srelplt.
+	* elf64-x86-64.c (elf_x86_64_relocate_section): Put
+	R_X86_64_TLSDESC in rel_tls_desc instead of elf.srelplt.
+	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Use rel_tls_desc,
+	instead of elf.srelplt, for GOT_TLS_GDESC_P.
+	(_bfd_elf_x86_get_reloc_section): New function.
+	(_bfd_x86_elf_late_size_sections): Use rel_tls_desc, instead of
+	elf.srelplt, for GOT_TLS_GDESC_P.  Remove next_tls_desc_index.
+	(_bfd_x86_elf_link_setup_gnu_properties): Allocate
+	.rela.tls/.rel.tls section for rel_tls_desc.
+	* elfxx-x86.h (elf_x86_link_hash_table): Add rel_tls_desc.
+	Remove next_tls_desc_index.
+	(_bfd_elf_x86_get_reloc_section): New.
+	(elf_backend_get_reloc_section): Likewise.
+
+ld/
+
+	PR ld/28387
+	* emulparams/elf32_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): New.
+	* emulparams/elf_i386.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
+	* emulparams/elf_x86_64.sh (OTHER_GOT_RELOC_SECTIONS): Likewise.
+	* testsuite/ld-i386/i386.exp: Run pr28387.
+	* testsuite/ld-i386/pr17057.d: Adjusted
+	* testsuite/ld-i386/tlsdesc.rd: Likewise.
+	* testsuite/ld-i386/tlsdesc2.d: Likewise.
+	* testsuite/ld-i386/tlsgdesc.rd: Likewise.
+	* testsuite/ld-x86-64/tlsdesc.pd: Likewise.
+	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
+	* testsuite/ld-x86-64/tlsdesc2.d: Likewise.
+	* testsuite/ld-x86-64/tlsgdesc.rd: Likewise.
+	* testsuite/ld-i386/pr28387.d: New file.
+	* testsuite/ld-i386/pr28387.s: Likewise.
+	* testsuite/ld-x86-64/pr28387-x32.d: Likewise.
+	* testsuite/ld-x86-64/pr28387.d: Likewise.
+	* testsuite/ld-x86-64/pr28387.s: Likewise.
+	* testsuite/ld-x86-64/x86-64.exp: Run pr28387 and pr28387-x32.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf32-i386.c                     |  10 +-
+ bfd/elf64-x86-64.c                   |   2 +-
+ bfd/elfxx-x86.c                      |  23 ++++-
+ bfd/elfxx-x86.h                      |  13 ++-
+ ld/emulparams/elf32_x86_64.sh        |   2 +
+ ld/emulparams/elf_i386.sh            |   2 +
+ ld/emulparams/elf_x86_64.sh          |   2 +
+ ld/testsuite/ld-i386/i386.exp        |   1 +
+ ld/testsuite/ld-i386/pr17057.d       |   7 +-
+ ld/testsuite/ld-i386/pr28387.d       |  35 +++++++
+ ld/testsuite/ld-i386/pr28387.s       |  12 +++
+ ld/testsuite/ld-i386/tlsdesc.rd      | 106 ++++++++++----------
+ ld/testsuite/ld-i386/tlsdesc2.d      |   3 +-
+ ld/testsuite/ld-i386/tlsgdesc.rd     |   8 +-
+ ld/testsuite/ld-x86-64/pr28387-x32.d |  36 +++++++
+ ld/testsuite/ld-x86-64/pr28387.d     |  35 +++++++
+ ld/testsuite/ld-x86-64/pr28387.s     |  11 +++
+ ld/testsuite/ld-x86-64/tlsdesc.pd    |   8 +-
+ ld/testsuite/ld-x86-64/tlsdesc.rd    | 141 +++++++++++++--------------
+ ld/testsuite/ld-x86-64/tlsdesc2.d    |   4 +-
+ ld/testsuite/ld-x86-64/tlsgdesc.rd   |   8 +-
+ ld/testsuite/ld-x86-64/x86-64.exp    |   2 +
+ 22 files changed, 309 insertions(+), 162 deletions(-)
+ create mode 100644 ld/testsuite/ld-i386/pr28387.d
+ create mode 100644 ld/testsuite/ld-i386/pr28387.s
+ create mode 100644 ld/testsuite/ld-x86-64/pr28387-x32.d
+ create mode 100644 ld/testsuite/ld-x86-64/pr28387.d
+ create mode 100644 ld/testsuite/ld-x86-64/pr28387.s
+
+diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
+index 657563f2f4f..4b99b8e0202 100644
+--- a/bfd/elf32-i386.c
++++ b/bfd/elf32-i386.c
+@@ -3163,7 +3163,6 @@ elf_i386_relocate_section (bfd *output_bfd,
+ 
+ 	      if (GOT_TLS_GDESC_P (tls_type))
+ 		{
+-		  bfd_byte *loc;
+ 		  outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
+ 		  BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
+ 			      <= htab->elf.sgotplt->size);
+@@ -3171,13 +3170,8 @@ elf_i386_relocate_section (bfd *output_bfd,
+ 				     + htab->elf.sgotplt->output_offset
+ 				     + offplt
+ 				     + htab->sgotplt_jump_table_size);
+-		  sreloc = htab->elf.srelplt;
+-		  loc = sreloc->contents;
+-		  loc += (htab->next_tls_desc_index++
+-			  * sizeof (Elf32_External_Rel));
+-		  BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
+-			      <= sreloc->contents + sreloc->size);
+-		  bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
++		  sreloc = htab->rel_tls_desc;
++		  elf_append_rel (output_bfd, sreloc, &outrel);
+ 		  if (indx == 0)
+ 		    {
+ 		      BFD_ASSERT (! unresolved_reloc);
+diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
+index 580975b6d67..4f0e97c4a9a 100644
+--- a/bfd/elf64-x86-64.c
++++ b/bfd/elf64-x86-64.c
+@@ -4627,7 +4627,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
+ 				     + htab->elf.sgotplt->output_offset
+ 				     + offplt
+ 				     + htab->sgotplt_jump_table_size);
+-		  sreloc = htab->elf.srelplt;
++		  sreloc = htab->rel_tls_desc;
+ 		  if (indx == 0)
+ 		    outrel.r_addend = relocation - _bfd_x86_elf_dtpoff_base (info);
+ 		  else
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index 3de48397e78..6dc15864833 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -366,7 +366,7 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
+ 	htab->elf.srelgot->size += htab->sizeof_reloc;
+       if (GOT_TLS_GDESC_P (tls_type))
+ 	{
+-	  htab->elf.srelplt->size += htab->sizeof_reloc;
++	  htab->rel_tls_desc->size += htab->sizeof_reloc;
+ 	  if (bed->target_id == X86_64_ELF_DATA)
+ 	    htab->elf.tlsdesc_plt = (bfd_vma) -1;
+ 	}
+@@ -2157,6 +2157,16 @@ _bfd_elf_x86_finish_relative_relocs (struct bfd_link_info *info)
+   return true;
+ }
+ 
++asection *
++_bfd_elf_x86_get_reloc_section (bfd *abfd, const char *name)
++{
++  /* Treat .rel.tls/.rela.tls section the same as .rel.plt/.rela.plt
++     section.  */
++  if (strcmp (name, ".tls") == 0)
++    name = ".plt";
++  return _bfd_elf_plt_get_reloc_section (abfd, name);
++}
++
+ bool
+ _bfd_elf_x86_valid_reloc_p (asection *input_section,
+ 			    struct bfd_link_info *info,
+@@ -2376,7 +2386,7 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
+ 		    srel->size += htab->sizeof_reloc;
+ 		  if (GOT_TLS_GDESC_P (*local_tls_type))
+ 		    {
+-		      htab->elf.srelplt->size += htab->sizeof_reloc;
++		      htab->rel_tls_desc->size += htab->sizeof_reloc;
+ 		      if (bed->target_id == X86_64_ELF_DATA)
+ 			htab->elf.tlsdesc_plt = (bfd_vma) -1;
+ 		    }
+@@ -2417,7 +2427,6 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
+      so that R_{386,X86_64}_IRELATIVE entries come last.  */
+   if (htab->elf.srelplt)
+     {
+-      htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
+       htab->sgotplt_jump_table_size
+ 	= elf_x86_compute_jump_table_size (htab);
+       htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
+@@ -4742,6 +4751,14 @@ _bfd_x86_elf_link_setup_gnu_properties
+ 	    }
+ 	}
+ 
++      sec = bfd_make_section_anyway_with_flags
++	(dynobj, bed->rela_plts_and_copies_p ? ".rela.tls" : ".rel.tls",
++	 bed->dynamic_sec_flags | SEC_READONLY);
++      if (sec == NULL
++	  || !bfd_set_section_alignment (sec, bed->s->log_file_align))
++	return false;
++      htab->rel_tls_desc = sec;
++
+       if (!info->no_ld_generated_unwind_info)
+ 	{
+ 	  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
+diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
+index 2a28987f208..5593203f9ec 100644
+--- a/bfd/elfxx-x86.h
++++ b/bfd/elfxx-x86.h
+@@ -650,14 +650,14 @@ struct elf_x86_link_hash_table
+   /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt.  */
+   bfd_vma next_irelative_index;
+ 
++  /* The .rela.tls/.rel.tls section for R_386_TLS_DESC or R_X86_64_TLSDESC
++     relocation.  */
++  asection *rel_tls_desc;
++
+   /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.
+      This is used for i386 only.  */
+   asection *srelplt2;
+ 
+-  /* The index of the next unused R_386_TLS_DESC slot in .rel.plt.  This
+-     is only used for i386.  */
+-  bfd_vma next_tls_desc_index;
+-
+   /* DT_RELR bitmap.  */
+   struct elf_dt_relr_bitmap dt_relr_bitmap;
+ 
+@@ -871,6 +871,9 @@ extern bool _bfd_elf_x86_size_relative_relocs
+ extern bool _bfd_elf_x86_finish_relative_relocs
+   (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
+ 
++extern asection * _bfd_elf_x86_get_reloc_section
++  (bfd *, const char *) ATTRIBUTE_HIDDEN;
++
+ extern void _bfd_elf32_write_addend 
+   (bfd *, uint64_t, void *) ATTRIBUTE_HIDDEN;
+ extern void _bfd_elf64_write_addend
+@@ -994,6 +997,8 @@ extern void _bfd_x86_elf_link_report_tls_transition_error
+   _bfd_elf_x86_size_relative_relocs
+ #define elf_backend_finish_relative_relocs \
+   _bfd_elf_x86_finish_relative_relocs
++#define elf_backend_get_reloc_section \
++  _bfd_elf_x86_get_reloc_section
+ #define elf_backend_use_mmap true
+ 
+ #define ELF_P_ALIGN ELF_MINPAGESIZE
+diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
+index 4db1a979058..8a07f50e47f 100644
+--- a/ld/emulparams/elf32_x86_64.sh
++++ b/ld/emulparams/elf32_x86_64.sh
+@@ -33,6 +33,8 @@ OTHER_PLT_SECTIONS="
+ .plt.got      ${RELOCATING-0} : { *(.plt.got) }
+ .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
+ "
++OTHER_GOT_RELOC_SECTIONS="
++  .rela.tls	${RELOCATING-0} : { *(.rela.tls) }"
+ 
+ if [ "x${host}" = "x${target}" ]; then
+   case " $EMULATION_LIBPATH " in
+diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
+index 51a650f692e..12d71f5ef9e 100644
+--- a/ld/emulparams/elf_i386.sh
++++ b/ld/emulparams/elf_i386.sh
+@@ -28,6 +28,8 @@ OTHER_PLT_SECTIONS="
+ .plt.got      ${RELOCATING-0} : { *(.plt.got) }
+ .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
+ "
++OTHER_GOT_RELOC_SECTIONS="
++  .rel.tls	${RELOCATING-0} : { *(.rel.tls) }"
+ 
+ # Linux modify the default library search path to first include
+ # a 32-bit specific directory.
+diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
+index 6e66f2e1035..4bab1489b94 100644
+--- a/ld/emulparams/elf_x86_64.sh
++++ b/ld/emulparams/elf_x86_64.sh
+@@ -34,6 +34,8 @@ OTHER_PLT_SECTIONS="
+ .plt.got      ${RELOCATING-0} : { *(.plt.got) }
+ .plt.sec      ${RELOCATING-0} : { *(.plt.sec) }
+ "
++OTHER_GOT_RELOC_SECTIONS="
++  .rela.tls	${RELOCATING-0} : { *(.rela.tls) }"
+ 
+ if [ "x${host}" = "x${target}" ]; then
+   case " $EMULATION_LIBPATH " in
+diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
+index 5b189ecb7f7..4ea46bbe901 100644
+--- a/ld/testsuite/ld-i386/i386.exp
++++ b/ld/testsuite/ld-i386/i386.exp
+@@ -522,6 +522,7 @@ run_dump_test "pr31047"
+ run_dump_test "pr32191"
+ run_dump_test "pr33260"
+ run_dump_test "pr33260-2"
++run_dump_test "pr28387"
+ 
+ if { !([istarget "i?86-*-linux*"]
+        || [istarget "i?86-*-gnu*"]
+diff --git a/ld/testsuite/ld-i386/pr17057.d b/ld/testsuite/ld-i386/pr17057.d
+index 29cc676a5af..af4e6c99276 100644
+--- a/ld/testsuite/ld-i386/pr17057.d
++++ b/ld/testsuite/ld-i386/pr17057.d
+@@ -3,7 +3,10 @@
+ #ld: -shared -melf_i386
+ #readelf: -r --wide
+ 
+-Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 2 entries:
++Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
+  Offset     Info    Type                Sym. Value  Symbol's Name
+-[0-9a-f ]+R_386_JUMP_SLOT +0+ +foo
+ [0-9a-f ]+R_386_TLS_DESC +0+ +my_tls
++
++Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
++ Offset     Info    Type                Sym. Value  Symbol's Name
++[0-9a-f ]+R_386_JUMP_SLOT +0+ +foo
+diff --git a/ld/testsuite/ld-i386/pr28387.d b/ld/testsuite/ld-i386/pr28387.d
+new file mode 100644
+index 00000000000..fd1e980142d
+--- /dev/null
++++ b/ld/testsuite/ld-i386/pr28387.d
+@@ -0,0 +1,35 @@
++#as: --32
++#ld: -shared -melf_i386 -z nocombreloc -z noseparate-code --no-ld-generated-unwind-info --hash-style=sysv
++#readelf: -d -r -S --wide
++
++There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
++
++Section Headers:
++ +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
++#...
++ +\[[ 0-9]+\] .rel.data +REL +0+128 0+128 0+8 08 +AI +2 +11 +4
++ +\[[ 0-9]+\] .rel.tls +REL +0+130 0+130 0+8 08 +AI +2 +10 +4
++ +\[[ 0-9]+\] .rel.plt +REL +0+138 0+138 0+8 08 +AI +2 +10 +4
++#...
++Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
++ +Tag +Type +Name/Value
++#...
++ 0x[0-9a-f]+ +\(PLTRELSZ\) +8 \(bytes\)
++ 0x[0-9a-f]+ +\(PLTREL\) +REL
++ 0x[0-9a-f]+ +\(JMPREL\) +0x138
++#...
++ 0x[0-9a-f]+ +\(REL\) +0x128
++ 0x[0-9a-f]+ +\(RELSZ\) +16 \(bytes\)
++ 0x[0-9a-f]+ +\(RELENT\) +8 \(bytes\)
++#...
++Relocation section '.rel.data' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name
++[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +foo
++
++Relocation section '.rel.tls' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name
++[0-9a-f]+ +[0-9a-f]+ +R_386_TLS_DESC +0+ +foo
++
++Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name
++[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +bar
+diff --git a/ld/testsuite/ld-i386/pr28387.s b/ld/testsuite/ld-i386/pr28387.s
+new file mode 100644
+index 00000000000..beb318917b8
+--- /dev/null
++++ b/ld/testsuite/ld-i386/pr28387.s
+@@ -0,0 +1,12 @@
++	.text
++	.p2align 4
++	.globl	main
++	.type	main, @function
++main:
++	leal	foo@TLSDESC(%ebx), %eax
++	call	*foo@TLSCALL(%eax)
++	call	bar@PLT
++	ret
++	.data
++	.dc.a	foo
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-i386/tlsdesc.rd b/ld/testsuite/ld-i386/tlsdesc.rd
+index ec418d1a1fc..ebd80b19928 100644
+--- a/ld/testsuite/ld-i386/tlsdesc.rd
++++ b/ld/testsuite/ld-i386/tlsdesc.rd
+@@ -14,7 +14,6 @@ Section Headers:
+  +\[[ 0-9]+\] \.dynsym +.*
+  +\[[ 0-9]+\] \.dynstr +.*
+  +\[[ 0-9]+\] \.rel.dyn +.*
+- +\[[ 0-9]+\] \.rel.plt +.*
+  +\[[ 0-9]+\] \.text +.*
+  +\[[ 0-9]+\] \.tdata +PROGBITS +[0-9a-f]+ [0-9a-f]+ 000060 00 WAT +0 +0 +1
+  +\[[ 0-9]+\] \.tbss +NOBITS +[0-9aa-f]+ [0-9a-f]+ 000020 00 WAT +0 +0 +1
+@@ -40,12 +39,12 @@ Program Headers:
+ 
+  Section to Segment mapping:
+  +Segment Sections...
+- +00 +.hash .dynsym .dynstr .rel.dyn .rel.plt .text *
++ +00 +.hash .dynsym .dynstr .rel.dyn .text *
+  +01 +.tdata .dynamic .got .got.plt *
+  +02 +.dynamic *
+  +03 +.tdata .tbss *
+ 
+-Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries:
++Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 25 entries:
+  Offset +Info +Type +Sym.Value +Sym. Name
+ [0-9a-f ]+R_386_TLS_TPOFF32
+ [0-9a-f ]+R_386_TLS_TPOFF *
+@@ -62,71 +61,68 @@ Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 20 entries:
+ [0-9a-f ]+R_386_TLS_TPOFF *
+ [0-9a-f ]+R_386_TLS_TPOFF *
+ [0-9a-f ]+R_386_TLS_TPOFF32
++[0-9a-f ]+R_386_TLS_DESC *
++[0-9a-f ]+R_386_TLS_DESC *
++[0-9a-f ]+R_386_TLS_DESC *
++[0-9a-f ]+R_386_TLS_DESC *
+ [0-9a-f ]+R_386_TLS_TPOFF +0+8 +sg3
+ [0-9a-f ]+R_386_TLS_TPOFF32 0+c +sg4
+ [0-9a-f ]+R_386_TLS_TPOFF +0+c +sg4
+ [0-9a-f ]+R_386_TLS_TPOFF +0+10 +sg5
+ [0-9a-f ]+R_386_TLS_TPOFF32 0+4 +sg2
+-
+-Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 5 entries:
+- Offset +Info +Type +Sym.Value +Sym. Name
+ [0-9a-f ]+R_386_TLS_DESC * 0+ +sg1
+-[0-9a-f ]+R_386_TLS_DESC *
+-[0-9a-f ]+R_386_TLS_DESC *
+-[0-9a-f ]+R_386_TLS_DESC *
+-[0-9a-f ]+R_386_TLS_DESC *
+ 
+ Symbol table '\.dynsym' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
+- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
+- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
+- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
+- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
+- +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +6 fn1
+- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
+- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
+- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
++ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +6 sg8
++ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +6 sg3
++ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +6 sg4
++ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +6 sg5
++ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +6 sg1
++ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +5 fn1
++ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +6 sg2
++ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +6 sg6
++ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +6 sg7
+ 
+ Symbol table '\.symtab' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ .* FILE +LOCAL +DEFAULT +ABS .*tlsdesc.o
+- +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +7 sl1
+- +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +7 sl2
+- +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +7 sl3
+- +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +7 sl4
+- +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +7 sl5
+- +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +7 sl6
+- +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +7 sl7
+- +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +7 sl8
++ +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +6 sl1
++ +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +6 sl2
++ +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +6 sl3
++ +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +6 sl4
++ +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +6 sl5
++ +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +6 sl6
++ +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +6 sl7
++ +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +6 sl8
+ .* FILE +LOCAL +DEFAULT +ABS 
+- +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +8 sH1
+- +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_
+- +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
+- +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +7 sh3
+- +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +8 sH2
+- +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +8 sH7
+- +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +7 sh7
+- +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +7 sh8
+- +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +8 sH4
+- +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +7 sh4
+- +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +8 sH3
+- +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +7 sh5
+- +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +8 sH5
+- +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +8 sH6
+- +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +8 sH8
+- +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +7 sh1
+- +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
+- +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +7 sh2
+- +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +7 sh6
+- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
+- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
+- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
+- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
+- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
+- +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +6 fn1
+- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
+- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
+- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
++ +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +7 sH1
++ +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +6 _TLS_MODULE_BASE_
++ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +8 _DYNAMIC
++ +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +6 sh3
++ +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +7 sH2
++ +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +7 sH7
++ +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +6 sh7
++ +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +6 sh8
++ +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +7 sH4
++ +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +6 sh4
++ +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +7 sH3
++ +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +6 sh5
++ +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +7 sH5
++ +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +7 sH6
++ +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +7 sH8
++ +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +6 sh1
++ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +10 _GLOBAL_OFFSET_TABLE_
++ +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +6 sh2
++ +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +6 sh6
++ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +6 sg8
++ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +6 sg3
++ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +6 sg4
++ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +6 sg5
++ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +6 sg1
++ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +5 fn1
++ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +6 sg2
++ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +6 sg6
++ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +6 sg7
+diff --git a/ld/testsuite/ld-i386/tlsdesc2.d b/ld/testsuite/ld-i386/tlsdesc2.d
+index b8569e893b8..c37557a94ef 100644
+--- a/ld/testsuite/ld-i386/tlsdesc2.d
++++ b/ld/testsuite/ld-i386/tlsdesc2.d
+@@ -3,8 +3,9 @@
+ #ld: -melf_i386 -shared -z now
+ #readelf: -d --wide
+ 
++#failif
+ #...
+ .*\(PLTRELSZ\).*
+ .*\(PLTREL\).*
+ .*\(JMPREL\).*
+-#pass
++#...
+diff --git a/ld/testsuite/ld-i386/tlsgdesc.rd b/ld/testsuite/ld-i386/tlsgdesc.rd
+index 0744aeb78b0..a129bf6f7e4 100644
+--- a/ld/testsuite/ld-i386/tlsgdesc.rd
++++ b/ld/testsuite/ld-i386/tlsgdesc.rd
+@@ -41,22 +41,22 @@ Program Headers:
+  +01 +.dynamic .got .got.plt *
+  +02 +.dynamic *
+ 
+-Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
++Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 10 entries:
+  Offset +Info +Type +Sym.Value +Sym. Name
+ [0-9a-f ]+R_386_TLS_TPOFF32 0+ +sG3
+ [0-9a-f ]+R_386_TLS_TPOFF +0+ +sG5
+ [0-9a-f ]+R_386_TLS_DTPMOD3 0+ +sG2
+ [0-9a-f ]+R_386_TLS_DTPOFF3 0+ +sG2
++[0-9a-f ]+R_386_TLS_DESC +0+ +sG2
+ [0-9a-f ]+R_386_TLS_TPOFF +0+ +sG4
+ [0-9a-f ]+R_386_TLS_TPOFF32 0+ +sG6
+ [0-9a-f ]+R_386_TLS_DTPMOD3 0+ +sG1
+ [0-9a-f ]+R_386_TLS_DTPOFF3 0+ +sG1
++[0-9a-f ]+R_386_TLS_DESC +0+ +sG1
+ 
+-Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 3 entries:
++Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entry:
+  Offset +Info +Type +Sym.Value +Sym. Name
+ [0-9a-f ]+R_386_JUMP_SLOT +0+ +___tls_get_addr
+-[0-9a-f ]+R_386_TLS_DESC +0+ +sG1
+-[0-9a-f ]+R_386_TLS_DESC +0+ +sG2
+ 
+ Symbol table '\.dynsym' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+diff --git a/ld/testsuite/ld-x86-64/pr28387-x32.d b/ld/testsuite/ld-x86-64/pr28387-x32.d
+new file mode 100644
+index 00000000000..0302126014c
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr28387-x32.d
+@@ -0,0 +1,36 @@
++#source: pr28387.s
++#as: --x32
++#ld: -shared -melf32_x86_64 -z nocombreloc -z nomark-plt -z noseparate-code -z max-page-size=0x200000 --no-ld-generated-unwind-info --hash-style=sysv
++#readelf: -d -r -S --wide
++
++There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
++
++Section Headers:
++ +\[Nr\] Name +Type +Addr +Off +Size +ES Flg Lk Inf Al
++#...
++ +\[[ 0-9]+\] .rela.data +RELA +0+128 0+128 0+c 0c +AI +2 +12 +4
++ +\[[ 0-9]+\] .rela.tls +RELA +0+134 0+134 0+c 0c +AI +2 +11 +4
++ +\[[ 0-9]+\] .rela.plt +RELA +0+140 0+140 0+c 0c +AI +2 +11 +4
++#...
++Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
++ +Tag +Type +Name/Value
++#...
++ 0x[0-9a-f]+ +\(PLTRELSZ\) +12 \(bytes\)
++ 0x[0-9a-f]+ +\(PLTREL\) +RELA
++ 0x[0-9a-f]+ +\(JMPREL\) +0x140
++#...
++ 0x[0-9a-f]+ +\(RELA\) +0x128
++ 0x[0-9a-f]+ +\(RELASZ\) +24 \(bytes\)
++ 0x[0-9a-f]+ +\(RELAENT\) +12 \(bytes\)
++#...
++Relocation section '.rela.data' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +0+ +foo \+ 0
++
++Relocation section '.rela.tls' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_TLSDESC +0+ +foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +bar \+ 0
+diff --git a/ld/testsuite/ld-x86-64/pr28387.d b/ld/testsuite/ld-x86-64/pr28387.d
+new file mode 100644
+index 00000000000..07df0fbc5a7
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr28387.d
+@@ -0,0 +1,35 @@
++#as: --64
++#ld: -shared -melf_x86_64 -z nocombreloc -z nomark-plt -z noseparate-code -z max-page-size=0x200000 --no-ld-generated-unwind-info --hash-style=sysv
++#readelf: -d -r -S --wide
++
++There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
++
++Section Headers:
++ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
++#...
++ +\[[ 0-9]+\] .rela.data +RELA +0+1b8 0+1b8 0+18 18 +AI +2 +12 +8
++ +\[[ 0-9]+\] .rela.tls +RELA +0+1d0 0+1d0 0+18 18 +AI +2 +11 +8
++ +\[[ 0-9]+\] .rela.plt +RELA +0+1e8 0+1e8 0+18 18 +AI +2 +11 +8
++#...
++Dynamic section at offset 0x[0-9a-f]+ contains [0-9]+ entries:
++ +Tag +Type +Name/Value
++#...
++ 0x[0-9a-f]+ +\(PLTRELSZ\) +24 \(bytes\)
++ 0x[0-9a-f]+ +\(PLTREL\) +RELA
++ 0x[0-9a-f]+ +\(JMPREL\) +0x1e8
++#...
++ 0x[0-9a-f]+ +\(RELA\) +0x1b8
++ 0x[0-9a-f]+ +\(RELASZ\) +48 \(bytes\)
++ 0x[0-9a-f]+ +\(RELAENT\) +24 \(bytes\)
++#...
++Relocation section '.rela.data' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +0+ +foo \+ 0
++
++Relocation section '.rela.tls' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_TLSDESC +0+ +foo \+ 0
++
++Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
++ +Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
++[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +bar \+ 0
+diff --git a/ld/testsuite/ld-x86-64/pr28387.s b/ld/testsuite/ld-x86-64/pr28387.s
+new file mode 100644
+index 00000000000..bbfa7b5f129
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr28387.s
+@@ -0,0 +1,11 @@
++	.text
++	.globl	main
++	.type	main, @function
++main:
++	leaq	foo@TLSDESC(%rip), %rax
++	call	*foo@TLSCALL(%rax)
++	call	bar@PLT
++	ret
++	.data
++	.dc.a	foo
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/tlsdesc.pd b/ld/testsuite/ld-x86-64/tlsdesc.pd
+index 490fc906c51..7e124ea32e5 100644
+--- a/ld/testsuite/ld-x86-64/tlsdesc.pd
++++ b/ld/testsuite/ld-x86-64/tlsdesc.pd
+@@ -10,10 +10,10 @@
+ Disassembly of section .plt:
+ 
+ [0-9a-f]+ <.plt>:
+- [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
+- [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201360 <_GLOBAL_OFFSET_TABLE_\+0x10>
++ [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201328 <_GLOBAL_OFFSET_TABLE_\+0x8>
++ [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201330 <_GLOBAL_OFFSET_TABLE_\+0x10>
+  [0-9a-f]+:	0f 1f 40 00          	nopl   0x0\(%rax\)
+  [0-9a-f]+:	f3 0f 1e fa          	endbr64
+- [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
+- [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201348 <.*>
++ [0-9a-f]+:	ff 35 .. .. 20 00    	push   .*\(%rip\)        # 201328 <_GLOBAL_OFFSET_TABLE_\+0x8>
++ [0-9a-f]+:	ff 25 .. .. 20 00    	jmp    \*.*\(%rip\)        # 201318 <.*>
+ 
+diff --git a/ld/testsuite/ld-x86-64/tlsdesc.rd b/ld/testsuite/ld-x86-64/tlsdesc.rd
+index 98bda5b2a39..14e945a8bae 100644
+--- a/ld/testsuite/ld-x86-64/tlsdesc.rd
++++ b/ld/testsuite/ld-x86-64/tlsdesc.rd
+@@ -14,14 +14,13 @@ Section Headers:
+  +\[[ 0-9]+\] .dynsym +.*
+  +\[[ 0-9]+\] .dynstr +.*
+  +\[[ 0-9]+\] .rela.dyn +.*
+- +\[[ 0-9]+\] .rela.plt +.*
+  +\[[ 0-9]+\] .plt +PROGBITS +0+3b0 0+3b0 0+20 10 +AX +0 +0 +(4|16)
+  +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+153 00 +AX +0 +0 4096
+  +\[[ 0-9]+\] .tdata +PROGBITS +0+201153 0+1153 0+60 00 WAT +0 +0 +1
+  +\[[ 0-9]+\] .tbss +NOBITS +0+2011b3 0+11b3 0+20 00 WAT +0 +0 +1
+- +\[[ 0-9]+\] .dynamic +DYNAMIC +0+2011b8 0+11b8 0+150 10 +WA +3 +0 +8
+- +\[[ 0-9]+\] .got +PROGBITS +0+201308 0+1308 0+48 08 +WA +0 +0 +8
+- +\[[ 0-9]+\] .got.plt +PROGBITS +0+201350 0+1350 0+68 08 +WA +0 +0 +8
++ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+2011b8 0+11b8 0+120 10 +WA +3 +0 +8
++ +\[[ 0-9]+\] .got +PROGBITS +0+2012d8 0+12d8 0+48 08 +WA +0 +0 +8
++ +\[[ 0-9]+\] .got.plt +PROGBITS +0+201320 0+1320 0+68 08 +WA +0 +0 +8
+  +\[[ 0-9]+\] .symtab +.*
+  +\[[ 0-9]+\] .strtab +.*
+  +\[[ 0-9]+\] .shstrtab +.*
+@@ -35,18 +34,18 @@ There are [0-9]+ program headers, starting at offset [0-9]+
+ Program Headers:
+  +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+  +LOAD +0x0+ 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+- +LOAD +0x0+1153 0x0+201153 0x0+201153 0x0+265 0x0+265 RW +0x200000
+- +DYNAMIC +0x0+11b8 0x0+2011b8 0x0+2011b8 0x0+150 0x0+150 RW +0x8
++ +LOAD +0x0+1153 0x0+201153 0x0+201153 0x0+235 0x0+235 RW +0x200000
++ +DYNAMIC +0x0+11b8 0x0+2011b8 0x0+2011b8 0x0+120 0x0+120 RW +0x8
+  +TLS +0x0+1153 0x0+201153 0x0+201153 0x0+60 0x0+80 R +0x1
+ 
+  Section to Segment mapping:
+  +Segment Sections...
+- +00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
++ +00 +.hash .dynsym .dynstr .rela.dyn .plt .text *
+  +01 +.tdata .dynamic .got .got.plt *
+  +02 +.dynamic *
+  +03 +.tdata .tbss *
+ 
+-Dynamic section at offset 0x[0-9a-f]+ contains 16 entries:
++Dynamic section at offset 0x[0-9a-f]+ contains 13 entries:
+  +Tag +Type +Name/Value
+  0x[0-9a-f]+ +\(HASH\).*
+  0x[0-9a-f]+ +\(STRTAB\).*
+@@ -54,87 +53,81 @@ Dynamic section at offset 0x[0-9a-f]+ contains 16 entries:
+  0x[0-9a-f]+ +\(STRSZ\).*
+  0x[0-9a-f]+ +\(SYMENT\).*
+  0x[0-9a-f]+ +\(PLTGOT\).*
+- 0x[0-9a-f]+ +\(PLTRELSZ\).*
+- 0x[0-9a-f]+ +\(PLTREL\).*
+- 0x[0-9a-f]+ +\(JMPREL\).*
+  0x[0-9a-f]+ +\(TLSDESC_PLT\) +0x3c0
+- 0x[0-9a-f]+ +\(TLSDESC_GOT\) +0x201348
++ 0x[0-9a-f]+ +\(TLSDESC_GOT\) +0x201318
+  0x[0-9a-f]+ +\(RELA\).*
+  0x[0-9a-f]+ +\(RELASZ\).*
+  0x[0-9a-f]+ +\(RELAENT\).*
+  0x[0-9a-f]+ +\(FLAGS\).*
+  0x[0-9a-f]+ +\(NULL\).*
+ 
+-Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
++Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 13 entries:
+  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+-0+201308 +[0-9a-f]+ R_X86_64_TPOFF64 +24
+-0+201310 +[0-9a-f]+ R_X86_64_TPOFF64 +30
+-0+201318 +[0-9a-f]+ R_X86_64_TPOFF64 +64
+-0+201328 +[0-9a-f]+ R_X86_64_TPOFF64 +50
+-0+201330 +[0-9a-f]+ R_X86_64_TPOFF64 +70
+-0+201340 +[0-9a-f]+ R_X86_64_TPOFF64 +44
+-0+201320 +[0-9a-f]+ R_X86_64_TPOFF64 +0+10 sg5 \+ 0
+-0+201338 +[0-9a-f]+ R_X86_64_TPOFF64 +0+4 sg2 \+ 0
+-
+-Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 5 entries:
+- +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+-0+201398 +[0-9a-f]+ R_X86_64_TLSDESC +0+ sg1 \+ 0
+-0+201368 +[0-9a-f]+ R_X86_64_TLSDESC +20
+-0+2013a8 +[0-9a-f]+ R_X86_64_TLSDESC +40
+-0+201378 +[0-9a-f]+ R_X86_64_TLSDESC +60
+-0+201388 +[0-9a-f]+ R_X86_64_TLSDESC +0
++0+2012d8 +[0-9a-f]+ R_X86_64_TPOFF64 +24
++0+2012e0 +[0-9a-f]+ R_X86_64_TPOFF64 +30
++0+2012e8 +[0-9a-f]+ R_X86_64_TPOFF64 +64
++0+2012f8 +[0-9a-f]+ R_X86_64_TPOFF64 +50
++0+201300 +[0-9a-f]+ R_X86_64_TPOFF64 +70
++0+201310 +[0-9a-f]+ R_X86_64_TPOFF64 +44
++0+201338 +[0-9a-f]+ R_X86_64_TLSDESC +20
++0+201348 +[0-9a-f]+ R_X86_64_TLSDESC +60
++0+201358 +[0-9a-f]+ R_X86_64_TLSDESC +0
++0+201378 +[0-9a-f]+ R_X86_64_TLSDESC +40
++0+2012f0 +[0-9a-f]+ R_X86_64_TPOFF64 +0+10 sg5 \+ 0
++0+201308 +[0-9a-f]+ R_X86_64_TPOFF64 +0+4 sg2 \+ 0
++0+201368 +[0-9a-f]+ R_X86_64_TLSDESC +0+ sg1 \+ 0
+ 
+ Symbol table '\.dynsym' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +8 sg8
+- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +8 sg3
+- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +8 sg4
+- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +8 sg5
+- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +8 sg1
+- +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +7 fn1
+- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +8 sg2
+- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +8 sg6
+- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +8 sg7
++ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
++ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
++ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
++ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
++ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
++ +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +6 fn1
++ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
++ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
++ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
+ 
+ Symbol table '\.symtab' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+  +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ .* FILE +LOCAL +DEFAULT +ABS .*tlsdesc.o
+- +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +8 sl1
+- +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +8 sl2
+- +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +8 sl3
+- +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +8 sl4
+- +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +8 sl5
+- +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +8 sl6
+- +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +8 sl7
+- +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +8 sl8
++ +[0-9]+: 0+20 +0 +TLS +LOCAL +DEFAULT +7 sl1
++ +[0-9]+: 0+24 +0 +TLS +LOCAL +DEFAULT +7 sl2
++ +[0-9]+: 0+28 +0 +TLS +LOCAL +DEFAULT +7 sl3
++ +[0-9]+: 0+2c +0 +TLS +LOCAL +DEFAULT +7 sl4
++ +[0-9]+: 0+30 +0 +TLS +LOCAL +DEFAULT +7 sl5
++ +[0-9]+: 0+34 +0 +TLS +LOCAL +DEFAULT +7 sl6
++ +[0-9]+: 0+38 +0 +TLS +LOCAL +DEFAULT +7 sl7
++ +[0-9]+: 0+3c +0 +TLS +LOCAL +DEFAULT +7 sl8
+ .* FILE +LOCAL +DEFAULT +ABS 
+- +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +9 sH1
+- +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +8 _TLS_MODULE_BASE_
+- +[0-9]+: 0+2011b8 +0 +OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
+- +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +8 sh3
+- +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +9 sH2
+- +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +9 sH7
+- +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +8 sh7
+- +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +8 sh8
+- +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +9 sH4
+- +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +8 sh4
+- +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +9 sH3
+- +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +8 sh5
+- +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +9 sH5
+- +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +9 sH6
+- +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +9 sH8
+- +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +8 sh1
+- +[0-9]+: 0+201350 +0 +OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
+- +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +8 sh2
+- +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +8 sh6
+- +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +8 sg8
+- +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +8 sg3
+- +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +8 sg4
+- +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +8 sg5
+- +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +8 sg1
+- +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +7 fn1
+- +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +8 sg2
+- +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +8 sg6
+- +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +8 sg7
++ +[0-9]+: 0+60 +0 +TLS +LOCAL +DEFAULT +8 sH1
++ +[0-9]+: 0+ +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_
++ +[0-9]+: 0+2011b8 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
++ +[0-9]+: 0+48 +0 +TLS +LOCAL +DEFAULT +7 sh3
++ +[0-9]+: 0+64 +0 +TLS +LOCAL +DEFAULT +8 sH2
++ +[0-9]+: 0+78 +0 +TLS +LOCAL +DEFAULT +8 sH7
++ +[0-9]+: 0+58 +0 +TLS +LOCAL +DEFAULT +7 sh7
++ +[0-9]+: 0+5c +0 +TLS +LOCAL +DEFAULT +7 sh8
++ +[0-9]+: 0+6c +0 +TLS +LOCAL +DEFAULT +8 sH4
++ +[0-9]+: 0+4c +0 +TLS +LOCAL +DEFAULT +7 sh4
++ +[0-9]+: 0+68 +0 +TLS +LOCAL +DEFAULT +8 sH3
++ +[0-9]+: 0+50 +0 +TLS +LOCAL +DEFAULT +7 sh5
++ +[0-9]+: 0+70 +0 +TLS +LOCAL +DEFAULT +8 sH5
++ +[0-9]+: 0+74 +0 +TLS +LOCAL +DEFAULT +8 sH6
++ +[0-9]+: 0+7c +0 +TLS +LOCAL +DEFAULT +8 sH8
++ +[0-9]+: 0+40 +0 +TLS +LOCAL +DEFAULT +7 sh1
++ +[0-9]+: 0+201320 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
++ +[0-9]+: 0+44 +0 +TLS +LOCAL +DEFAULT +7 sh2
++ +[0-9]+: 0+54 +0 +TLS +LOCAL +DEFAULT +7 sh6
++ +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8
++ +[0-9]+: 0+8 +0 +TLS +GLOBAL +DEFAULT +7 sg3
++ +[0-9]+: 0+c +0 +TLS +GLOBAL +DEFAULT +7 sg4
++ +[0-9]+: 0+10 +0 +TLS +GLOBAL +DEFAULT +7 sg5
++ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1
++ +[0-9]+: 0+1000 +0 +FUNC +GLOBAL +DEFAULT +6 fn1
++ +[0-9]+: 0+4 +0 +TLS +GLOBAL +DEFAULT +7 sg2
++ +[0-9]+: 0+14 +0 +TLS +GLOBAL +DEFAULT +7 sg6
++ +[0-9]+: 0+18 +0 +TLS +GLOBAL +DEFAULT +7 sg7
+diff --git a/ld/testsuite/ld-x86-64/tlsdesc2.d b/ld/testsuite/ld-x86-64/tlsdesc2.d
+index 86797579bac..d0f5ebf62a2 100644
+--- a/ld/testsuite/ld-x86-64/tlsdesc2.d
++++ b/ld/testsuite/ld-x86-64/tlsdesc2.d
+@@ -3,8 +3,8 @@
+ #ld: -melf_x86_64 -shared -z now
+ #readelf: -d --wide
+ 
+-#...
++#failif
+ .*\(PLTRELSZ\).*
+ .*\(PLTREL\).*
+ .*\(JMPREL\).*
+-#pass
++#...
+diff --git a/ld/testsuite/ld-x86-64/tlsgdesc.rd b/ld/testsuite/ld-x86-64/tlsgdesc.rd
+index ca8f19bf3f7..ef15ce94c5a 100644
+--- a/ld/testsuite/ld-x86-64/tlsgdesc.rd
++++ b/ld/testsuite/ld-x86-64/tlsgdesc.rd
+@@ -41,22 +41,22 @@ Program Headers:
+  +01 +.dynamic .got .got.plt *
+  +02 +.dynamic *
+ 
+-Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
++Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 10 entries:
+  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+ [0-9a-f]+ +0+100000012 R_X86_64_TPOFF64 +0+ sG3 \+ 0
+ [0-9a-f]+ +0+200000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0
+ [0-9a-f]+ +0+300000010 R_X86_64_DTPMOD64 +0+ sG2 \+ 0
+ [0-9a-f]+ +0+300000011 R_X86_64_DTPOFF64 +0+ sG2 \+ 0
++[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
+ [0-9a-f]+ +0+400000012 R_X86_64_TPOFF64 +0+ sG4 \+ 0
+ [0-9a-f]+ +0+600000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0
+ [0-9a-f]+ +0+800000010 R_X86_64_DTPMOD64 +0+ sG1 \+ 0
+ [0-9a-f]+ +0+800000011 R_X86_64_DTPOFF64 +0+ sG1 \+ 0
++[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
+ 
+-Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 3 entries:
++Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry:
+  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+ [0-9a-f]+ +0+500000007 R_X86_64_JUMP_SLOT +0+ __tls_get_addr \+ 0
+-[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
+-[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
+ 
+ Symbol table '\.dynsym' contains [0-9]+ entries:
+  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
+index 63cf1e45c14..5b759d8a5d0 100644
+--- a/ld/testsuite/ld-x86-64/x86-64.exp
++++ b/ld/testsuite/ld-x86-64/x86-64.exp
+@@ -570,6 +570,8 @@ run_dump_test "pr33260-2"
+ run_dump_test "pr33260-2-x32"
+ run_dump_test "pr33292"
+ run_dump_test "pr33292-x32"
++run_dump_test "pr28387"
++run_dump_test "pr28387-x32"
+ 
+ if { ![skip_sframe_tests] } {
+     run_dump_test "sframe-simple-1"
+
+base-commit: 8b7a074374f812a00f6f30be849f1b1f32bbe230
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-20 23:30 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-20 23:30 UTC (permalink / raw
  To: gentoo-commits

commit:     949d5c865398a24fe5c1d956bf91754d24593203
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 23:29:55 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 23:29:55 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=949d5c86

9999: drop patch merged upstream

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ntsize-when-clearing-SEC_MERGE-SEC_STRING.patch | 87 ----------------------
 1 file changed, 87 deletions(-)

diff --git a/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch b/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch
deleted file mode 100644
index b9c30be..0000000
--- a/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch
+++ /dev/null
@@ -1,87 +0,0 @@
-From 3e39ade99e4e24f741c7d5631412e89d1bc5bde4 Mon Sep 17 00:00:00 2001
-Message-ID: <3e39ade99e4e24f741c7d5631412e89d1bc5bde4.1755728184.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Wed, 20 Aug 2025 12:27:53 -0700
-Subject: [PATCH] elf: Clear entsize when clearing SEC_MERGE|SEC_STRINGS
-
-When generating an output from input SEC_MERGE|SEC_STRINGS sections with
-different entsize, we clear the SEC_MERGE|SEC_STRINGS bits.  We also need
-to clear entsize.
-
-	PR ld/33291
-	* ldlang.c (lang_add_section): Clearing entsize when clearing
-	SEC_MERGE|SEC_STRINGS.
-	* testsuite/ld-elf/pr33291.d: New file.
-	* testsuite/ld-elf/pr33291a.s: Likewise.
-	* testsuite/ld-elf/pr33291b.s: Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- ld/ldlang.c                    | 1 +
- ld/testsuite/ld-elf/pr33291.d  | 9 +++++++++
- ld/testsuite/ld-elf/pr33291a.s | 8 ++++++++
- ld/testsuite/ld-elf/pr33291b.s | 7 +++++++
- 4 files changed, 25 insertions(+)
- create mode 100644 ld/testsuite/ld-elf/pr33291.d
- create mode 100644 ld/testsuite/ld-elf/pr33291a.s
- create mode 100644 ld/testsuite/ld-elf/pr33291b.s
-
-diff --git a/ld/ldlang.c b/ld/ldlang.c
-index 8ba95b04e23..0bb4a17df19 100644
---- a/ld/ldlang.c
-+++ b/ld/ldlang.c
-@@ -2861,6 +2861,7 @@ lang_add_section (lang_statement_list_type *ptr,
- 	      && output->bfd_section->entsize != section->entsize))
- 	{
- 	  output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
-+	  output->bfd_section->entsize = 0;
- 	  flags &= ~ (SEC_MERGE | SEC_STRINGS);
- 	}
-     }
-diff --git a/ld/testsuite/ld-elf/pr33291.d b/ld/testsuite/ld-elf/pr33291.d
-new file mode 100644
-index 00000000000..9f08118433e
---- /dev/null
-+++ b/ld/testsuite/ld-elf/pr33291.d
-@@ -0,0 +1,9 @@
-+#source: pr33291a.s
-+#source: pr33291b.s
-+#ld: -shared
-+#readelf: -S --wide
-+#xfail: ![check_shared_lib_support] 
-+
-+#...
-+  \[[ 0-9]+\] \.rodata[ 	]+PROGBITS[ 	]+[0-9a-f]+ [0-9a-f]+ 0+9 00 +A +0 +0 +8
-+#...
-diff --git a/ld/testsuite/ld-elf/pr33291a.s b/ld/testsuite/ld-elf/pr33291a.s
-new file mode 100644
-index 00000000000..07e9f7c2c21
---- /dev/null
-+++ b/ld/testsuite/ld-elf/pr33291a.s
-@@ -0,0 +1,8 @@
-+	.globl	foo
-+	.section	.rodata.cst8,"aM",%progbits,8
-+	.align 8
-+	.type	foo, %object
-+	.size	foo, 8
-+foo:
-+	.quad	131073
-+	.section	.note.GNU-stack,"",%progbits
-diff --git a/ld/testsuite/ld-elf/pr33291b.s b/ld/testsuite/ld-elf/pr33291b.s
-new file mode 100644
-index 00000000000..69f6b3db594
---- /dev/null
-+++ b/ld/testsuite/ld-elf/pr33291b.s
-@@ -0,0 +1,7 @@
-+	.globl	bar
-+	.section	.rodata.cst1,"aM",%progbits,1
-+	.type	bar, %object
-+	.size	bar, 1
-+bar:
-+	.byte	1
-+	.section	.note.GNU-stack,"",%progbits
-
-base-commit: fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-20 22:17 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-20 22:17 UTC (permalink / raw
  To: gentoo-commits

commit:     e2e29fbc91c3fff57c973a0eec733effe482bb37
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 22:15:44 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 22:15:44 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=e2e29fbc

9999: drop merged TLS patches

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch | 1353 --------------------
 ...GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch |  160 ---
 ...-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch |  470 -------
 3 files changed, 1983 deletions(-)

diff --git a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
deleted file mode 100644
index b459a36..0000000
--- a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
+++ /dev/null
@@ -1,1353 +0,0 @@
-From b6b200c936241a908de6d0c9e8c13db8cf16a31f Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Fri, 4 Jul 2025 08:39:03 +0800
-Subject: [PATCH] x86: Add GLIBC_ABI_GNU2_TLS version dependency
-
-On Linux/x86, programs and shared libraries compiled with
--mtls-dialect=gnu2 may fail silently at run-time against glibc without
-the GNU2 TLS run-time fixes for:
-
-https://sourceware.org/bugzilla/show_bug.cgi?id=31501
-https://sourceware.org/bugzilla/show_bug.cgi?id=31372
-
-A version tag, GLIBC_ABI_GNU2_TLS, has been added to glibc to indicate
-that glibc has the working GNU2 TLS run-time.  Add the --gnu2-tls-tag
-option to i386/x86-64 ELF linker to add the GLIBC_ABI_GNU2_TLS version
-dependency in output programs and shared libraries when linking against
-glibc if input relocatable object files have R_386_TLS_DESC_CALL or
-R_X86_64_TLSDESC_CALL relocation.  The output will fail to load and run
-at run-time against glibc which doesn't define the GLIBC_ABI_GNU2_TLS
-version.
-
-Add the --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag
-by default.  If unspecified, linker will add the GLIBC_ABI_GNU2_TLS
-version dependency if input object files have R_386_TLS_DESC_CALL or
-R_X86_64_TLSDESC_CALL relocation and libc.so defines the GLIBC_ABI_GNU2_TLS
-version.
-
-Update elf_link_add_glibc_verneed to properly add the GLIBC_2.36 version
-dependency when -z mark-plt -z nopack-relative-relocs passed to x86-64
-ELF linker.
-
-bfd/
-
-	PR ld/33130
-	* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Add
-	a pointer to bool argument.
-	* elf-linker-x86.h (elf_linker_x86_params): Add
-	gnu2_tls_version_tag.
-	* elf32-i386.c (elf_i386_scan_relocs): Set has_tls_desc_call to
-	1 for R_386_TLS_DESC_CALL.
-	(elf_i386_add_glibc_version_dependency): New.  Undef before
-	FreeBSD support.
-	* elf64-x86-64.c (elf_x86_64_scan_relocs): Set has_tls_desc_call
-	to 1 for R_X86_64_TLSDESC_CALL.
-	(elf_x86_64_add_glibc_version_dependency): Add GLIBC_ABI_GNU2_TLS
-	version dependency if GLIBC_ABI_GNU2_TLS dependency isn't disabled
-	and has_tlsdesc_call isn't 0.
-	(elf_backend_add_glibc_version_dependency): Undef before CloudABI
-	support and redefine for elf32-x86-64.
-	* elflink.c (elf_link_add_glibc_verneed): Changed to return bool.
-	Remove the pointer to elf_find_verdep_info argument.  Add a
-	pointer to bool argument, auto_version. Return true if linked
-	against glibc.  Otherwise return false.  If the version dependency
-	is added, set *auto_version to true.  If *auto_version is true,
-	add the version dependency only if libc.so defines the version.
-	(_bfd_elf_link_add_glibc_version_dependency): Add a pointer to
-	bool argument and pass it to elf_link_add_glibc_verneed.
-	(_bfd_elf_link_add_dt_relr_dependency): Pass NULL to
-	_bfd_elf_link_add_glibc_version_dependency.
-	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_desc_call.
-
-ld/
-
-	PR ld/33130
-	* NEWS: Mention --gnu2-tls-tag, --no-gnu2-tls-tag and
-	--enable-gnu2-tls-tag.
-	* config.in: Regenerated.
-	* configure: Likewise.
-	* configure.ac: Add --enable-gnu2-tls-tag.
-	* ld.texi: Document --gnu2-tls-tag/--no-gnu2-tls-tag.
-	* ldlex.h (option_values): Add OPTION_GNU2_TLS_VERSION_TAG and
-	OPTION_NO_GNU2_TLS_VERSION_TAG.
-	* emulparams/elf32_x86_64.sh (EXTRA_EM_FILE): Changed to
-	"elf-x86-64-glibc".
-	* emulparams/elf_i386.sh (EXTRA_EM_FILE): Set to "elf-i386-glibc".
-	* emulparams/elf_i386_fbsd.sh (EXTRA_EM_FILE): New.  Set to
-	"elf-x86".
-        * emulparams/elf_i386_haiku.sh (EXTRA_EM_FILE): Likewise.
-	* emulparams/elf_x86_64.sh (EXTRA_EM_FILE): Likewise.
-	* emulparams/elf_x86_64_cloudabi.sh (EXTRA_EM_FILE): New.  Set
-	to "elf-x86-64".
-	* emulparams/elf_x86_64_fbsd.sh (EXTRA_EM_FILE): Likewise.
-	* emulparams/elf_x86_64_haiku.sh (EXTRA_EM_FILE): Likewise.
-	* (EXTRA_EM_FILE): Likewise.
-	* (EXTRA_EM_FILE): Likewise.
-        * emultempl/elf-i386-glibc.em: New file.
-	* emultempl/elf-x86-64-glibc.em: Likewise.
-	* emultempl/elf-x86-64.em: Likewise.
-	* emultempl/elf-x86-glibc.em: Likewise.
-	* emultempl/elf-x86.em (elf_x86_64_before_parse): Removed.
-	(LDEMUL_BEFORE_PARSE): Likewise.
-	(elf_x86_64_before_allocation): Likewise.
-	(LDEMUL_BEFORE_ALLOCATION): Likewise.
-	* emultempl/solaris2-x86-64.em: New file.
-	* testsuite/ld-i386/gnu2-tls-1.s: Likewise.
-	* testsuite/ld-i386/gnu2-tls-1a.rd: Likewise.
-	* testsuite/ld-i386/gnu2-tls-1b.rd: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1.s: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1a.rd: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1b.rd: Likewise.
-	* testsuite/ld-x86-64/mark-plt-2.rd: Likewise.
-	* testsuite/ld-x86-64/mark-plt-2.s: Likewise.
-	* testsuite/ld-i386/i386.exp: Run GLIBC_ABI_GNU2_TLS tests.
-	* testsuite/ld-x86-64/x86-64.exp: Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-bfd.h                         |   2 +-
- bfd/elf-linker-x86.h                  |   8 ++
- bfd/elf32-i386.c                      |  44 ++++++++-
- bfd/elf64-x86-64.c                    |  36 +++++--
- bfd/elflink.c                         | 130 +++++++++++++++-----------
- bfd/elfxx-x86.h                       |   4 +
- ld/NEWS                               |   6 ++
- ld/config.in                          |   4 +
- ld/configure                          |  29 +++++-
- ld/configure.ac                       |  19 ++++
- ld/emulparams/elf32_x86_64.sh         |   2 +-
- ld/emulparams/elf_i386.sh             |   2 +-
- ld/emulparams/elf_i386_fbsd.sh        |   1 +
- ld/emulparams/elf_i386_haiku.sh       |   1 +
- ld/emulparams/elf_x86_64.sh           |   2 +-
- ld/emulparams/elf_x86_64_fbsd.sh      |   1 +
- ld/emulparams/elf_x86_64_haiku.sh     |   1 +
- ld/emultempl/elf-i386-glibc.em        |  41 ++++++++
- ld/emultempl/elf-x86-64-glibc.em      |  37 ++++++++
- ld/emultempl/elf-x86-64.em            |  68 ++++++++++++++
- ld/emultempl/elf-x86-glibc.em         |  70 ++++++++++++++
- ld/emultempl/elf-x86.em               |  58 ------------
- ld/emultempl/solaris2-x86-64.em       |  23 +++++
- ld/ld.texi                            |  15 +++
- ld/ldlex.h                            |   3 +
- ld/testsuite/ld-i386/gnu2-tls-1.s     |  11 +++
- ld/testsuite/ld-i386/gnu2-tls-1a.rd   |   7 ++
- ld/testsuite/ld-i386/gnu2-tls-1b.rd   |   4 +
- ld/testsuite/ld-i386/i386.exp         |  23 +++++
- ld/testsuite/ld-x86-64/gnu2-tls-1.s   |  11 +++
- ld/testsuite/ld-x86-64/gnu2-tls-1a.rd |   7 ++
- ld/testsuite/ld-x86-64/gnu2-tls-1b.rd |   4 +
- ld/testsuite/ld-x86-64/mark-plt-2.rd  |   7 ++
- ld/testsuite/ld-x86-64/mark-plt-2.s   |  13 +++
- ld/testsuite/ld-x86-64/x86-64.exp     |  26 +++++-
- 36 files changed, 596 insertions(+), 125 deletions(-)
- create mode 100644 ld/emultempl/elf-i386-glibc.em
- create mode 100644 ld/emultempl/elf-x86-64-glibc.em
- create mode 100644 ld/emultempl/elf-x86-64.em
- create mode 100644 ld/emultempl/elf-x86-glibc.em
- create mode 100644 ld/emultempl/solaris2-x86-64.em
- create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1.s
- create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1a.rd
- create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1b.rd
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1.s
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
- create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.rd
- create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.s
-
-diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index accdd6d41a8..feb470fc477 100644
---- a/bfd/elf-bfd.h
-+++ b/bfd/elf-bfd.h
-@@ -2632,7 +2632,7 @@ extern bool _bfd_elf_link_output_relocs
-    struct elf_link_hash_entry **);
- 
- extern void _bfd_elf_link_add_glibc_version_dependency
--  (struct elf_find_verdep_info *, const char *const []);
-+  (struct elf_find_verdep_info *, const char *const [], bool *);
- 
- extern void _bfd_elf_link_add_dt_relr_dependency
-   (struct elf_find_verdep_info *);
-diff --git a/bfd/elf-linker-x86.h b/bfd/elf-linker-x86.h
-index 2c98257038f..fe322152e14 100644
---- a/bfd/elf-linker-x86.h
-+++ b/bfd/elf-linker-x86.h
-@@ -72,6 +72,14 @@ struct elf_linker_x86_params
-   /* Mark PLT with dynamic tags.  */
-   unsigned int mark_plt : 1;
- 
-+  /* Add the GLIBC_ABI_GNU2_TLS version dependency if input object files
-+     have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL relocation:
-+     0: Disable.
-+     1: Enable.
-+     2: Auto.  Enable if libc.so has the GLIBC_ABI_GNU2_TLS version.
-+   */
-+  unsigned int gnu2_tls_version_tag : 2;
-+
-   /* X86-64 ISA level needed.  */
-   unsigned int isa_level;
- 
-diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
-index b755b39ab55..9d06f1494cf 100644
---- a/bfd/elf32-i386.c
-+++ b/bfd/elf32-i386.c
-@@ -1687,6 +1687,10 @@ elf_i386_scan_relocs (bfd *abfd,
- 	  size_reloc = true;
- 	  goto do_size;
- 
-+	case R_386_TLS_DESC_CALL:
-+	  htab->has_tls_desc_call = 1;
-+	  goto need_got;
-+
- 	case R_386_TLS_IE_32:
- 	case R_386_TLS_IE:
- 	case R_386_TLS_GOTIE:
-@@ -1698,7 +1702,7 @@ elf_i386_scan_relocs (bfd *abfd,
- 	case R_386_GOT32X:
- 	case R_386_TLS_GD:
- 	case R_386_TLS_GOTDESC:
--	case R_386_TLS_DESC_CALL:
-+ need_got:
- 	  /* This symbol requires a global offset table entry.  */
- 	  {
- 	    int tls_type, old_tls_type;
-@@ -4492,6 +4496,40 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
-   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
- }
- 
-+static void
-+elf_i386_add_glibc_version_dependency
-+  (struct elf_find_verdep_info *rinfo)
-+{
-+  int i = 0;
-+  const char *version[3] = { NULL, NULL, NULL };
-+  bool auto_version[3] = { false, false, false };
-+  struct elf_x86_link_hash_table *htab;
-+
-+  if (rinfo->info->enable_dt_relr)
-+    {
-+      version[i] = "GLIBC_ABI_DT_RELR";
-+      i++;
-+    }
-+
-+  htab = elf_x86_hash_table (rinfo->info, I386_ELF_DATA);
-+  if (htab != NULL)
-+    {
-+      if (htab->params->gnu2_tls_version_tag && htab->has_tls_desc_call)
-+	{
-+	  version[i] = "GLIBC_ABI_GNU2_TLS";
-+	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU2_TLS
-+	     version.  */
-+	  if (htab->params->gnu2_tls_version_tag == 2)
-+	    auto_version[i] = true;
-+	  i++;
-+	}
-+    }
-+
-+  if (i != 0)
-+    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
-+						auto_version);
-+}
-+
- #define TARGET_LITTLE_SYM		i386_elf32_vec
- #define TARGET_LITTLE_NAME		"elf32-i386"
- #define ELF_ARCH			bfd_arch_i386
-@@ -4532,6 +4570,8 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
- #define elf_backend_relocate_section	      elf_i386_relocate_section
- #define elf_backend_setup_gnu_properties      elf_i386_link_setup_gnu_properties
- #define elf_backend_hide_symbol		      _bfd_x86_elf_hide_symbol
-+#define elf_backend_add_glibc_version_dependency \
-+  elf_i386_add_glibc_version_dependency
- 
- #define elf_backend_linux_prpsinfo32_ugid16	true
- 
-@@ -4539,6 +4579,8 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
- 
- #include "elf32-target.h"
- 
-+#undef elf_backend_add_glibc_version_dependency
-+
- /* FreeBSD support.  */
- 
- #undef	TARGET_LITTLE_SYM
-diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index b6fd466178e..1edce6e8703 100644
---- a/bfd/elf64-x86-64.c
-+++ b/bfd/elf64-x86-64.c
-@@ -2694,6 +2694,10 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
- 	    eh->zero_undefweak &= 0x2;
- 	  break;
- 
-+	case R_X86_64_TLSDESC_CALL:
-+	  htab->has_tls_desc_call = 1;
-+	  goto need_got;
-+
- 	case R_X86_64_GOTTPOFF:
- 	case R_X86_64_CODE_4_GOTTPOFF:
- 	case R_X86_64_CODE_5_GOTTPOFF:
-@@ -2715,7 +2719,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
- 	case R_X86_64_GOTPLT64:
- 	case R_X86_64_GOTPC32_TLSDESC:
- 	case R_X86_64_CODE_4_GOTPC32_TLSDESC:
--	case R_X86_64_TLSDESC_CALL:
-+need_got:
- 	  /* This symbol requires a global offset table entry.	*/
- 	  {
- 	    int tls_type, old_tls_type;
-@@ -6243,7 +6247,8 @@ elf_x86_64_add_glibc_version_dependency
-   (struct elf_find_verdep_info *rinfo)
- {
-   unsigned int i = 0;
--  const char *version[3] = { NULL, NULL, NULL };
-+  const char *version[4] = { NULL, NULL, NULL, NULL };
-+  bool auto_version[4] = { false, false, false, false };
-   struct elf_x86_link_hash_table *htab;
- 
-   if (rinfo->info->enable_dt_relr)
-@@ -6253,14 +6258,27 @@ elf_x86_64_add_glibc_version_dependency
-     }
- 
-   htab = elf_x86_hash_table (rinfo->info, X86_64_ELF_DATA);
--  if (htab != NULL && htab->params->mark_plt)
-+  if (htab != NULL)
-     {
--      version[i] = "GLIBC_2.36";
--      i++;
-+      if (htab->params->gnu2_tls_version_tag && htab->has_tls_desc_call)
-+	{
-+	  version[i] = "GLIBC_ABI_GNU2_TLS";
-+	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU2_TLS
-+	     version.  */
-+	  if (htab->params->gnu2_tls_version_tag == 2)
-+	    auto_version[i] = true;
-+	  i++;
-+	}
-+      if (htab->params->mark_plt)
-+	{
-+	  version[i] = "GLIBC_2.36";
-+	  i++;
-+	}
-     }
- 
-   if (i != 0)
--    _bfd_elf_link_add_glibc_version_dependency (rinfo, version);
-+    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
-+						auto_version);
- }
- 
- static const struct bfd_elf_special_section
-@@ -6479,6 +6499,10 @@ elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUS
- #define elf_backend_bfd_from_remote_memory \
-   _bfd_elf32_bfd_from_remote_memory
- 
-+#undef elf_backend_add_glibc_version_dependency
-+#define elf_backend_add_glibc_version_dependency \
-+  elf_x86_64_add_glibc_version_dependency
-+
- #undef elf_backend_size_info
- #define elf_backend_size_info \
-   _bfd_elf32_size_info
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index f6c0c04e82e..d2c43f31bf5 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -2281,68 +2281,85 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
-   return true;
- }
- \f
--/* Return the glibc version reference if VERSION_DEP is added to the
--   list of glibc version dependencies successfully.  VERSION_DEP will
--   be put into the .gnu.version_r section.  GLIBC_MINOR_BASE is the
--   pointer to the glibc minor base version.  */
-+/* Return true if linked against glibc.  Otherwise return false.  If
-+   linked against glibc, add VERSION_DEP to the list of glibc version
-+   dependencies and set *AUTO_VERSION to true.  If *AUTO_VERSION is
-+   true, add VERSION_DEP to the version dependency list only if libc.so
-+   defines VERSION_DEP.  GLIBC_MINOR_BASE is the pointer to the glibc
-+   minor base version.  */
- 
--static Elf_Internal_Verneed *
-+static bool
- elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
--			    Elf_Internal_Verneed *glibc_verref,
- 			    const char *version_dep,
--			    int *glibc_minor_base)
-+			    int *glibc_minor_base,
-+			    bool *auto_version)
- {
-   Elf_Internal_Verneed *t;
-   Elf_Internal_Vernaux *a;
-   size_t amt;
-   int minor_version = -1;
-+  bool added = false;
-+  bool glibc = false;
- 
--  if (glibc_verref != NULL)
-+  for (t = elf_tdata (rinfo->info->output_bfd)->verref;
-+       t != NULL;
-+       t = t->vn_nextref)
-     {
--      t = glibc_verref;
-+      const char *soname = bfd_elf_get_dt_soname (t->vn_bfd);
-+      if (soname != NULL && startswith (soname, "libc.so."))
-+	break;
-+    }
- 
--      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
-+  /* Skip the shared library if it isn't libc.so.  */
-+  if (t == NULL)
-+    goto update_auto_version_and_return;
-+
-+  for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
-+    {
-+      /* Return if VERSION_DEP dependency has been added.  */
-+      if (a->vna_nodename == version_dep
-+	  || strcmp (a->vna_nodename, version_dep) == 0)
- 	{
--	  /* Return if VERSION_DEP dependency has been added.  */
--	  if (a->vna_nodename == version_dep
--	      || strcmp (a->vna_nodename, version_dep) == 0)
--	    return t;
-+	  glibc = true;
-+	  goto update_auto_version_and_return;
- 	}
--    }
--  else
--    {
--      for (t = elf_tdata (rinfo->info->output_bfd)->verref;
--	   t != NULL;
--	   t = t->vn_nextref)
-+
-+      /* Check if libc.so provides GLIBC_2.XX version.  */
-+      if (startswith (a->vna_nodename, "GLIBC_2."))
- 	{
--	  const char *soname = bfd_elf_get_dt_soname (t->vn_bfd);
--	  if (soname != NULL && startswith (soname, "libc.so."))
--	    break;
-+	  minor_version = strtol (a->vna_nodename + 8, NULL, 10);
-+	  if (minor_version < *glibc_minor_base)
-+	    *glibc_minor_base = minor_version;
- 	}
-+    }
- 
--      /* Skip the shared library if it isn't libc.so.  */
--      if (t == NULL)
--	return t;
-+  /* Skip if it isn't linked against glibc.  */
-+  if (minor_version < 0)
-+    goto update_auto_version_and_return;
- 
--      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
--	{
--	  /* Return if VERSION_DEP dependency has been added.  */
--	  if (a->vna_nodename == version_dep
--	      || strcmp (a->vna_nodename, version_dep) == 0)
--	    return t;
-+  glibc = true;
- 
--	  /* Check if libc.so provides GLIBC_2.XX version.  */
--	  if (startswith (a->vna_nodename, "GLIBC_2."))
--	    {
--	      minor_version = strtol (a->vna_nodename + 8, NULL, 10);
--	      if (minor_version < *glibc_minor_base)
--		*glibc_minor_base = minor_version;
--	    }
--	}
-+  if (auto_version && *auto_version)
-+    {
-+      /* Add VERSION_DEP to the version dependency list only if
-+	 libc.so defines VERSION_DEP.  */
- 
--      /* Skip if it isn't linked against glibc.  */
--      if (minor_version < 0)
--	return NULL;
-+      bool defined = false;
-+      Elf_Internal_Verdef *d;
-+
-+      for (d = elf_tdata (t->vn_bfd)->verdef;
-+	   d != NULL;
-+	   d = d->vd_nextdef)
-+	if (strcmp (d->vd_nodename, version_dep) == 0)
-+	  {
-+	    defined = true;
-+	    break;
-+	  }
-+
-+      /* Set *AUTO_VERSION to false and return true to indicate that
-+	 libc.so doesn't define VERSION_DEP.  */
-+      if (!defined)
-+	goto update_auto_version_and_return;
-     }
- 
-   /* Skip if 2.GLIBC_MINOR_BASE includes VERSION_DEP.  */
-@@ -2350,7 +2367,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
-     {
-       minor_version = strtol (version_dep + 8, NULL, 10);
-       if (minor_version <= *glibc_minor_base)
--	return NULL;
-+	goto update_auto_version_and_return;
-     }
- 
-   amt = sizeof *a;
-@@ -2358,7 +2375,8 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
-   if (a == NULL)
-     {
-       rinfo->failed = true;
--      return NULL;
-+      glibc = false;
-+      goto update_auto_version_and_return;
-     }
- 
-   a->vna_nodename = version_dep;
-@@ -2369,7 +2387,13 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
- 
-   t->vn_auxptr = a;
- 
--  return t;
-+  added = true;
-+
-+ update_auto_version_and_return:
-+  if (auto_version)
-+    *auto_version = added;
-+
-+  return glibc;
- }
- 
- /* Add VERSION_DEP to the list of version dependencies when linked
-@@ -2378,19 +2402,19 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
- void
- _bfd_elf_link_add_glibc_version_dependency
-   (struct elf_find_verdep_info *rinfo,
--   const char *const version_dep[])
-+   const char *const version_dep[],
-+   bool *auto_version)
- {
--  Elf_Internal_Verneed *t = NULL;
-   int glibc_minor_base = INT_MAX;
- 
-   do
-     {
--      t = elf_link_add_glibc_verneed (rinfo, t, *version_dep,
--				      &glibc_minor_base);
--      /* Return if there is no glibc version reference.  */
--      if (t == NULL)
-+      /* Return if not linked against glibc.  */
-+      if (!elf_link_add_glibc_verneed (rinfo, *version_dep,
-+				       &glibc_minor_base, auto_version))
- 	return;
-       version_dep++;
-+      auto_version++;
-     }
-   while (*version_dep != NULL);
- }
-@@ -2408,7 +2432,7 @@ _bfd_elf_link_add_dt_relr_dependency (struct elf_find_verdep_info *rinfo)
- 	  "GLIBC_ABI_DT_RELR",
- 	  NULL
- 	};
--      _bfd_elf_link_add_glibc_version_dependency (rinfo, version);
-+      _bfd_elf_link_add_glibc_version_dependency (rinfo, version, NULL);
-     }
- }
- 
-diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
-index f6ee6a65356..791a2a2592f 100644
---- a/bfd/elfxx-x86.h
-+++ b/bfd/elfxx-x86.h
-@@ -670,6 +670,10 @@ struct elf_x86_link_hash_table
-   /* Number of relative reloc generation pass.  */
-   unsigned int generate_relative_reloc_pass;
- 
-+  /* TRUE if inputs have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
-+     relocation.  */
-+  unsigned int has_tls_desc_call : 1;
-+
-    /* Value used to fill the unused bytes of the first PLT entry.  This
-       is only used for i386.  */
-   bfd_byte plt0_pad_byte;
-diff --git a/ld/NEWS b/ld/NEWS
-index 54c1df5aadf..bacabc8440e 100644
---- a/ld/NEWS
-+++ b/ld/NEWS
-@@ -1,5 +1,11 @@
- -*- text -*-
- 
-+* Add --gnu2-tls-tag/--no-gnu2-tls-tag options to i386 and x86-64 ELF
-+  linkers to add the GLIBC_ABI_GNU2_TLS version dependency in output if
-+  input object files have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
-+  relocation.  Also added --enable-gnu2-tls-tag configure option to
-+  enable --gnu2-tls-tag by default.
-+
- * NaCl target support is removed.
- 
- Changes in 2.45:
-diff --git a/ld/config.in b/ld/config.in
-index 37812241bd9..64dbc3e0c88 100644
---- a/ld/config.in
-+++ b/ld/config.in
-@@ -31,6 +31,10 @@
-    when a .note-GNU-stack section is missing. */
- #undef DEFAULT_LD_EXECSTACK
- 
-+/* Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker
-+   by default. */
-+#undef DEFAULT_LD_GNU2_TLS_TAG
-+
- /* Define to 1 if you want to enable --rosegment in the ELF linker by default.
-    */
- #undef DEFAULT_LD_ROSEGMENT
-diff --git a/ld/configure b/ld/configure
-index 124b44182bc..6f1a3559964 100755
---- a/ld/configure
-+++ b/ld/configure
-@@ -851,6 +851,7 @@ enable_textrel_check
- enable_separate_code
- enable_rosegment
- enable_mark_plt
-+enable_gnu2_tls_tag
- enable_memory_seal
- enable_warn_execstack
- enable_error_execstack
-@@ -1548,6 +1549,8 @@ Optional Features:
-   --enable-separate-code  enable -z separate-code in ELF linker by default
-   --enable-rosegment      enable --rosegment in the ELF linker by default
-   --enable-mark-plt       enable -z mark-plt in ELF x86-64 linker by default
-+  --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF i386/x86-64 linker by
-+                          default
-   --enable-memory-seal    enable -z memory-seal in ELF linker by default
-   --enable-warn-execstack enable warnings when creating an executable stack
-   --enable-error-execstack
-@@ -11514,7 +11517,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11517 "configure"
-+#line 11520 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -11620,7 +11623,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11623 "configure"
-+#line 11626 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -15507,6 +15510,18 @@ esac
- fi
- 
- 
-+# Decide if --gnu2-tls-tag should be enabled in ELF i386 and x86-64
-+# linkers by default.
-+ac_default_ld_enable_gnu2_tls_tag=unset
-+# Check whether --enable-gnu2-tls-tag was given.
-+if test "${enable_gnu2_tls_tag+set}" = set; then :
-+  enableval=$enable_gnu2_tls_tag; case "${enableval}" in
-+  yes) ac_default_ld_enable_gnu2_tls_tag=1 ;;
-+  no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
-+esac
-+fi
-+
-+
- # Decide if -z memory-seal should be enabled in ELF linker by default.
- ac_default_ld_z_memory_seal=unset
- # Check whether --enable-memory-seal was given.
-@@ -18981,6 +18996,16 @@ cat >>confdefs.h <<_ACEOF
- _ACEOF
- 
- 
-+if test "${ac_default_ld_enable_gnu2_tls_tag}" = unset; then
-+  # Default to enable --gnu2-tls-tag if libc.so has the GLIBC_ABI_GNU2_TLS
-+  # version.
-+  ac_default_ld_enable_gnu2_tls_tag=2
-+fi
-+
-+cat >>confdefs.h <<_ACEOF
-+#define DEFAULT_LD_GNU2_TLS_TAG $ac_default_ld_enable_gnu2_tls_tag
-+_ACEOF
-+
- 
- 
- cat >>confdefs.h <<_ACEOF
-diff --git a/ld/configure.ac b/ld/configure.ac
-index e306c1ded4a..4b9068a415e 100644
---- a/ld/configure.ac
-+++ b/ld/configure.ac
-@@ -245,6 +245,17 @@ AC_ARG_ENABLE(mark-plt,
-   no) ac_default_ld_z_mark_plt=0 ;;
- esac])
- 
-+# Decide if --gnu2-tls-tag should be enabled in ELF i386 and x86-64
-+# linkers by default.
-+ac_default_ld_enable_gnu2_tls_tag=unset
-+AC_ARG_ENABLE(gnu2-tls-tag,
-+	      AS_HELP_STRING([--enable-gnu2-tls-tag],
-+	      [enable --gnu2-tls-tag in ELF i386/x86-64 linker by default]),
-+[case "${enableval}" in
-+  yes) ac_default_ld_enable_gnu2_tls_tag=1 ;;
-+  no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
-+esac])
-+
- # Decide if -z memory-seal should be enabled in ELF linker by default.
- ac_default_ld_z_memory_seal=unset
- AC_ARG_ENABLE(memory-seal,
-@@ -646,6 +657,14 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_MEMORY_SEAL,
-   $ac_default_ld_z_memory_seal,
-   [Define to 1 if you want to enable -z memory_seal in ELF linker by default.])
- 
-+if test "${ac_default_ld_enable_gnu2_tls_tag}" = unset; then
-+  # Default to enable --gnu2-tls-tag if libc.so has the GLIBC_ABI_GNU2_TLS
-+  # version.
-+  ac_default_ld_enable_gnu2_tls_tag=2
-+fi
-+AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU2_TLS_TAG,
-+  $ac_default_ld_enable_gnu2_tls_tag,
-+  [Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker by default.])
- 
- AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK,
-   $ac_default_ld_warn_execstack,
-diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
-index 6a92eec129d..4db1a979058 100644
---- a/ld/emulparams/elf32_x86_64.sh
-+++ b/ld/emulparams/elf32_x86_64.sh
-@@ -20,7 +20,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
- ARCH="i386:x64-32"
- MACHINE=
- TEMPLATE_NAME=elf
--EXTRA_EM_FILE="elf-x86"
-+EXTRA_EM_FILE="elf-x86-64-glibc"
- GENERATE_SHLIB_SCRIPT=yes
- GENERATE_PIE_SCRIPT=yes
- NO_SMALL_DATA=yes
-diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
-index 6f698bb0b06..51a650f692e 100644
---- a/ld/emulparams/elf_i386.sh
-+++ b/ld/emulparams/elf_i386.sh
-@@ -17,7 +17,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
- ARCH=i386
- MACHINE=
- TEMPLATE_NAME=elf
--EXTRA_EM_FILE="elf-x86"
-+EXTRA_EM_FILE="elf-i386-glibc"
- GENERATE_SHLIB_SCRIPT=yes
- GENERATE_PIE_SCRIPT=yes
- NO_SMALL_DATA=yes
-diff --git a/ld/emulparams/elf_i386_fbsd.sh b/ld/emulparams/elf_i386_fbsd.sh
-index d1d6604504a..d39a5cf882f 100644
---- a/ld/emulparams/elf_i386_fbsd.sh
-+++ b/ld/emulparams/elf_i386_fbsd.sh
-@@ -1,3 +1,4 @@
- source_sh ${srcdir}/emulparams/elf_i386.sh
- source_sh ${srcdir}/emulparams/elf_fbsd.sh
-+EXTRA_EM_FILE="elf-x86"
- OUTPUT_FORMAT="elf32-i386-freebsd"
-diff --git a/ld/emulparams/elf_i386_haiku.sh b/ld/emulparams/elf_i386_haiku.sh
-index 6c4001e4e05..c931c0e3f91 100644
---- a/ld/emulparams/elf_i386_haiku.sh
-+++ b/ld/emulparams/elf_i386_haiku.sh
-@@ -1,5 +1,6 @@
- source_sh ${srcdir}/emulparams/elf_i386.sh
- source_sh ${srcdir}/emulparams/elf_haiku.sh
-+EXTRA_EM_FILE="elf-x86"
- TEXT_START_ADDR=0x200000
- NONPAGED_TEXT_START_ADDR=0x200000
- MAXPAGESIZE=0x1000
-diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
-index 92449745c7a..6e66f2e1035 100644
---- a/ld/emulparams/elf_x86_64.sh
-+++ b/ld/emulparams/elf_x86_64.sh
-@@ -21,7 +21,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
- ARCH="i386:x86-64"
- MACHINE=
- TEMPLATE_NAME=elf
--EXTRA_EM_FILE="elf-x86"
-+EXTRA_EM_FILE="elf-x86-64-glibc"
- GENERATE_SHLIB_SCRIPT=yes
- GENERATE_PIE_SCRIPT=yes
- NO_SMALL_DATA=yes
-diff --git a/ld/emulparams/elf_x86_64_fbsd.sh b/ld/emulparams/elf_x86_64_fbsd.sh
-index 7ef974addca..17fdc83b075 100644
---- a/ld/emulparams/elf_x86_64_fbsd.sh
-+++ b/ld/emulparams/elf_x86_64_fbsd.sh
-@@ -1,3 +1,4 @@
- source_sh ${srcdir}/emulparams/elf_x86_64.sh
- source_sh ${srcdir}/emulparams/elf_fbsd.sh
-+EXTRA_EM_FILE="elf-x86-64"
- OUTPUT_FORMAT="elf64-x86-64-freebsd"
-diff --git a/ld/emulparams/elf_x86_64_haiku.sh b/ld/emulparams/elf_x86_64_haiku.sh
-index e6231cdfb15..7b033840fb6 100644
---- a/ld/emulparams/elf_x86_64_haiku.sh
-+++ b/ld/emulparams/elf_x86_64_haiku.sh
-@@ -1,2 +1,3 @@
- source_sh ${srcdir}/emulparams/elf_x86_64.sh
- source_sh ${srcdir}/emulparams/elf_haiku.sh
-+EXTRA_EM_FILE="elf-x86-64"
-diff --git a/ld/emultempl/elf-i386-glibc.em b/ld/emultempl/elf-i386-glibc.em
-new file mode 100644
-index 00000000000..547823750a4
---- /dev/null
-+++ b/ld/emultempl/elf-i386-glibc.em
-@@ -0,0 +1,41 @@
-+# This shell script emits a C file. -*- C -*-
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the license, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; see the file COPYING3. If not,
-+# see <http://www.gnu.org/licenses/>.
-+#
-+
-+# This file is sourced from elf.em, and defines i386 glibc specific
-+# routines.
-+#
-+
-+source_em ${srcdir}/emultempl/elf-x86.em
-+source_em ${srcdir}/emultempl/elf-x86-glibc.em
-+
-+# Define some shell vars to insert bits of code into the standard elf
-+# parse_args and list_options functions.
-+#
-+
-+fragment <<EOF
-+static void
-+elf_i386_glibc_before_parse (void)
-+{
-+  elf_x86_before_parse ();
-+  elf_x86_glibc_before_parse ();
-+}
-+EOF
-+
-+LDEMUL_BEFORE_PARSE=elf_i386_glibc_before_parse
-diff --git a/ld/emultempl/elf-x86-64-glibc.em b/ld/emultempl/elf-x86-64-glibc.em
-new file mode 100644
-index 00000000000..1e62d4f48bc
---- /dev/null
-+++ b/ld/emultempl/elf-x86-64-glibc.em
-@@ -0,0 +1,37 @@
-+# This shell script emits a C file. -*- C -*-
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the license, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; see the file COPYING3. If not,
-+# see <http://www.gnu.org/licenses/>.
-+#
-+
-+# This file is sourced from elf.em, and defines x86-64 glibc specific
-+# routines.
-+#
-+
-+source_em ${srcdir}/emultempl/elf-x86-64.em
-+source_em ${srcdir}/emultempl/elf-x86-glibc.em
-+
-+fragment <<EOF
-+static void
-+elf_x86_64_glibc_before_parse (void)
-+{
-+  elf_x86_64_before_parse ();
-+  elf_x86_glibc_before_parse ();
-+}
-+EOF
-+
-+LDEMUL_BEFORE_PARSE=elf_x86_64_glibc_before_parse
-diff --git a/ld/emultempl/elf-x86-64.em b/ld/emultempl/elf-x86-64.em
-new file mode 100644
-index 00000000000..ca7ccc0f478
---- /dev/null
-+++ b/ld/emultempl/elf-x86-64.em
-@@ -0,0 +1,68 @@
-+# This shell script emits a C file. -*- C -*-
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the license, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; see the file COPYING3. If not,
-+# see <http://www.gnu.org/licenses/>.
-+#
-+
-+# This file is sourced from elf.em, and defines x86-64 specific routines.
-+#
-+
-+source_em ${srcdir}/emultempl/elf-x86.em
-+
-+fragment <<EOF
-+static void
-+elf_x86_64_before_parse (void)
-+{
-+  params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
-+
-+  elf_x86_before_parse ();
-+}
-+
-+static void
-+elf_x86_64_before_allocation (void)
-+{
-+  if (!bfd_link_relocatable (&link_info)
-+      && is_elf_hash_table (link_info.hash)
-+      && expld.phase != lang_mark_phase_enum)
-+    {
-+      struct elf_link_hash_table *htab = elf_hash_table (&link_info);
-+      /* Run one_lang_size_sections_pass to estimate the output section
-+	 layout before sizing dynamic sections.  */
-+      expld.dataseg.phase = exp_seg_none;
-+      expld.phase = lang_mark_phase_enum;
-+      /* NB: Exclude linker created GOT setions when estimating output
-+	 section layout as sizing dynamic sections may change linker
-+	 created GOT sections.  */
-+      if (htab->sgot != NULL)
-+	htab->sgot->flags |= SEC_EXCLUDE;
-+      if (htab->sgotplt != NULL)
-+	htab->sgotplt->flags |= SEC_EXCLUDE;
-+      one_lang_size_sections_pass (NULL, false);
-+      /* Restore linker created GOT setions.  */
-+      if (htab->sgot != NULL)
-+	htab->sgot->flags &= ~SEC_EXCLUDE;
-+      if (htab->sgotplt != NULL)
-+	htab->sgotplt->flags &= ~SEC_EXCLUDE;
-+      lang_reset_memory_regions ();
-+    }
-+
-+  gld${EMULATION_NAME}_before_allocation ();
-+}
-+EOF
-+
-+LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
-+LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
-diff --git a/ld/emultempl/elf-x86-glibc.em b/ld/emultempl/elf-x86-glibc.em
-new file mode 100644
-index 00000000000..0fc37a6b59c
---- /dev/null
-+++ b/ld/emultempl/elf-x86-glibc.em
-@@ -0,0 +1,70 @@
-+# This shell script emits a C file. -*- C -*-
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the license, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; see the file COPYING3. If not,
-+# see <http://www.gnu.org/licenses/>.
-+#
-+
-+# This file is sourced from elf.em, and defines x86 glibc specific
-+# routines.
-+#
-+
-+fragment <<EOF
-+static void
-+elf_x86_glibc_before_parse (void)
-+{
-+  params.gnu2_tls_version_tag = DEFAULT_LD_GNU2_TLS_TAG;
-+}
-+EOF
-+
-+# Define some shell vars to insert bits of code into the standard elf
-+# parse_args and list_options functions.
-+#
-+
-+PARSE_AND_LIST_LONGOPTS_X86='
-+  { "gnu2-tls-tag", no_argument, NULL, OPTION_GNU2_TLS_VERSION_TAG },
-+  { "no-gnu2-tls-tag", no_argument, NULL, OPTION_NO_GNU2_TLS_VERSION_TAG },
-+'
-+
-+PARSE_AND_LIST_OPTIONS_X86='
-+  if (DEFAULT_LD_GNU2_TLS_TAG == 0)
-+    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency\n\
-+  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency (default)\n"));
-+  else if (DEFAULT_LD_GNU2_TLS_TAG == 1)
-+    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency (default)\n\
-+  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency\n"));
-+  else
-+    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency (auto)\n\
-+                                when no options are specified (default)\n\
-+  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency\n"));
-+'
-+
-+PARSE_AND_LIST_ARGS_CASES_X86='
-+    case OPTION_GNU2_TLS_VERSION_TAG:
-+      params.gnu2_tls_version_tag = 1;
-+      break;
-+
-+    case OPTION_NO_GNU2_TLS_VERSION_TAG:
-+      params.gnu2_tls_version_tag = 0;
-+      break;
-+'
-+
-+PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_X86"
-+PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86"
-+PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_X86"
-diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em
-index f72a0cd0d4a..411a4d62294 100644
---- a/ld/emultempl/elf-x86.em
-+++ b/ld/emultempl/elf-x86.em
-@@ -56,61 +56,3 @@ EOF
- 
- LDEMUL_BEFORE_PARSE=elf_x86_before_parse
- fi
--
--case x${OUTPUT_FORMAT}${CALL_NOP_BYTE} in
--  x*x86-64*0x67)
--fragment <<EOF
--
--static void
--elf_x86_64_before_parse (void)
--{
--  params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
--
--  elf_x86_before_parse ();
--}
--EOF
--
--    LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
--    ;;
--esac
--
--case x${OUTPUT_FORMAT} in
--  x*x86-64*)
--fragment <<EOF
--
--static void
--elf_x86_64_before_allocation (void)
--{
--  if (!bfd_link_relocatable (&link_info)
--      && is_elf_hash_table (link_info.hash)
--      && expld.phase != lang_mark_phase_enum)
--    {
--      struct elf_link_hash_table *htab = elf_hash_table (&link_info);
--      /* Run one_lang_size_sections_pass to estimate the output section
--	 layout before sizing dynamic sections.  */
--      expld.dataseg.phase = exp_seg_none;
--      expld.phase = lang_mark_phase_enum;
--      /* NB: Exclude linker created GOT setions when estimating output
--	 section layout as sizing dynamic sections may change linker
--	 created GOT sections.  */
--      if (htab->sgot != NULL)
--	htab->sgot->flags |= SEC_EXCLUDE;
--      if (htab->sgotplt != NULL)
--	htab->sgotplt->flags |= SEC_EXCLUDE;
--      one_lang_size_sections_pass (NULL, false);
--      /* Restore linker created GOT setions.  */
--      if (htab->sgot != NULL)
--	htab->sgot->flags &= ~SEC_EXCLUDE;
--      if (htab->sgotplt != NULL)
--	htab->sgotplt->flags &= ~SEC_EXCLUDE;
--      lang_reset_memory_regions ();
--    }
--
--  gld${EMULATION_NAME}_before_allocation ();
--}
--
--EOF
--
--LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
--    ;;
--esac
-diff --git a/ld/emultempl/solaris2-x86-64.em b/ld/emultempl/solaris2-x86-64.em
-new file mode 100644
-index 00000000000..788b3cf4800
---- /dev/null
-+++ b/ld/emultempl/solaris2-x86-64.em
-@@ -0,0 +1,23 @@
-+# This shell script emits a C file. -*- C -*-
-+#   Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-+# MA 02110-1301, USA.
-+#
-+
-+source_em "${srcdir}/emultempl/elf-x86-64.em"
-+source_em "${srcdir}/emultempl/solaris2.em"
-diff --git a/ld/ld.texi b/ld/ld.texi
-index 413335ad765..0e13f7d8e35 100644
---- a/ld/ld.texi
-+++ b/ld/ld.texi
-@@ -1745,6 +1745,21 @@ Supported for Linux/i386 and Linux/x86_64.
- 
- Other keywords are ignored for Solaris compatibility.
- 
-+@item --gnu2-tls-tag
-+@itemx --no-gnu2-tls-tag
-+Add @code{GLIBC_ABI_GNU2_TLS} version tag dependency in output programs
-+and shared libraries when linking against glibc if input relocatable
-+object files have @code{R_386_TLS_DESC_CALL} or
-+@code{R_X86_64_TLSDESC_CALL} relocation.  The output will fail to load
-+and run at run-time against glibc which doesn't define the
-+@code{GLIBC_ABI_GNU2_TLS} version tag.  Unless disabled by the
-+@option{--disable-gnu2-tls-tag} configure option at the linker build
-+time, when no options are specified, linker will add the
-+@code{GLIBC_ABI_GNU2_TLS} version tag dependency if inputs have
-+@code{R_386_TLS_DESC_CALL} or @code{R_X86_64_TLSDESC_CALL} relocation
-+and libc.so defines the @code{GLIBC_ABI_GNU2_TLS} version tag.
-+Supported for Linux/i386 and Linux/x86_64.
-+
- @kindex -(
- @cindex groups of archives
- @item -( @var{archives} -)
-diff --git a/ld/ldlex.h b/ld/ldlex.h
-index d0c2e5d6db8..020712df0e7 100644
---- a/ld/ldlex.h
-+++ b/ld/ldlex.h
-@@ -469,6 +469,9 @@ enum option_values
-   OPTION_NO_LITERAL_MOVEMENT,
-   OPTION_ABI_WINDOWED,
-   OPTION_ABI_CALL0,
-+  /* Used by emultempl/elf-x86-glibc.em.  */
-+  OPTION_GNU2_TLS_VERSION_TAG,
-+  OPTION_NO_GNU2_TLS_VERSION_TAG,
- };
- 
- /* The initial parser states.  */
-diff --git a/ld/testsuite/ld-i386/gnu2-tls-1.s b/ld/testsuite/ld-i386/gnu2-tls-1.s
-new file mode 100644
-index 00000000000..e3841c71653
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu2-tls-1.s
-@@ -0,0 +1,11 @@
-+	.section	.text.startup,"ax",@progbits
-+	.p2align 4
-+	.globl	main
-+	.type	main, @function
-+main:
-+	leal	ld@TLSDESC(%ebx), %eax
-+	call	*ld@TLSCALL(%eax)
-+	addl	%gs:0, %eax
-+	ret
-+	.size	main, .-main
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-i386/gnu2-tls-1a.rd b/ld/testsuite/ld-i386/gnu2-tls-1a.rd
-new file mode 100644
-index 00000000000..3eb926a227c
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu2-tls-1a.rd
-@@ -0,0 +1,7 @@
-+#...
-+Version needs section '.gnu.version_r' contains 1 entry:
-+ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
-+ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
-+#pass
-diff --git a/ld/testsuite/ld-i386/gnu2-tls-1b.rd b/ld/testsuite/ld-i386/gnu2-tls-1b.rd
-new file mode 100644
-index 00000000000..33ef8acb232
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu2-tls-1b.rd
-@@ -0,0 +1,4 @@
-+#failif
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
-+#...
-diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
-index 86748b1a494..74ef1672f86 100644
---- a/ld/testsuite/ld-i386/i386.exp
-+++ b/ld/testsuite/ld-i386/i386.exp
-@@ -1516,6 +1516,29 @@ run_ld_link_tests [list \
-     ] \
- ]
- 
-+# The musl C library does not support --gnu2-tls-tag.
-+if { ![istarget *-*-musl]
-+     && [check_compiler_available] } {
-+    run_cc_link_tests [list \
-+	[list \
-+	    "Build gnu2-tls-1a.so" \
-+	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-1a.rd}} \
-+	    "gnu2-tls-1a.so" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-1b.so" \
-+	    "-shared -Wl,--no-as-needed,--no-gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-1b.rd}} \
-+	    "gnu2-tls-1b.so" \
-+	] \
-+    ]
-+}
-+
- # Linux only tests
- run_dump_test "pltgot-1"
- run_dump_test "pltgot-2"
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1.s b/ld/testsuite/ld-x86-64/gnu2-tls-1.s
-new file mode 100644
-index 00000000000..eca788c9ca2
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1.s
-@@ -0,0 +1,11 @@
-+	.section	.text.startup,"ax",@progbits
-+	.p2align 4
-+	.globl	main
-+	.type	main, @function
-+main:
-+	leaq	foo@TLSDESC(%rip), %rax
-+	call	*foo@TLSCALL(%rax)
-+	movl	%fs:(%rax), %eax
-+	ret
-+	.size	main, .-main
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
-new file mode 100644
-index 00000000000..3eb926a227c
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
-@@ -0,0 +1,7 @@
-+#...
-+Version needs section '.gnu.version_r' contains 1 entry:
-+ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
-+ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
-new file mode 100644
-index 00000000000..33ef8acb232
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
-@@ -0,0 +1,4 @@
-+#failif
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
-+#...
-diff --git a/ld/testsuite/ld-x86-64/mark-plt-2.rd b/ld/testsuite/ld-x86-64/mark-plt-2.rd
-new file mode 100644
-index 00000000000..b0ed7024420
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/mark-plt-2.rd
-@@ -0,0 +1,7 @@
-+#...
-+Version needs section '.gnu.version_r' contains 1 entry:
-+ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
-+ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
-+#...
-+  0x[a-f0-9]+:   Name: (GLIBC_2.36|GLIBC_ABI_DT_X86_64_PLT)  Flags: none  Version: [0-9]+
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/mark-plt-2.s b/ld/testsuite/ld-x86-64/mark-plt-2.s
-new file mode 100644
-index 00000000000..c816567c204
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/mark-plt-2.s
-@@ -0,0 +1,13 @@
-+	.text
-+	.globl	foo
-+	.type	foo, @function
-+foo:
-+	subq	$8, %rsp
-+	leaq	xxx@TLSDESC(%rip), %rax
-+	.nops 10
-+	call	*xxx@TLSCALL(%rax)
-+	movl	%fs:(%rax), %eax
-+	addq	$8, %rsp
-+	call	bar
-+	ret
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index a72a7da12c1..25480f70185 100644
---- a/ld/testsuite/ld-x86-64/x86-64.exp
-+++ b/ld/testsuite/ld-x86-64/x86-64.exp
-@@ -2360,7 +2360,7 @@ run_dump_test "ibt-plt-3b-x32"
- run_dump_test "ibt-plt-3c-x32"
- run_dump_test "ibt-plt-3d-x32"
- 
--# Skip -z mark-plt tests on MUSL.
-+# Skip -z mark-plt and --gnu2-tls-tag tests on MUSL.
- if { [istarget "x86_64-*-musl*"]} {
-     set ASFLAGS "$saved_ASFLAGS"
-     return
-@@ -2386,6 +2386,30 @@ if { [check_compiler_available] } {
- 	     {readelf {-W --version-info} mark-plt-1b.rd}} \
- 	    "mark-plt-1.so" \
- 	] \
-+	[list \
-+	    "Build mark-plt-2.so" \
-+	    "-shared -Wl,--no-as-needed,-z,mark-plt,-z,nopack-relative-relocs" \
-+	    "-fPIC" \
-+	    { mark-plt-2.s } \
-+	    {{readelf {-W --version-info} mark-plt-2.rd}} \
-+	    "mark-plt-2.so" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-1a.so" \
-+	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-1a.rd}} \
-+	    "gnu2-tls-1a.so" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-1b.so" \
-+	    "-shared -Wl,--no-as-needed,--no-gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-1b.rd}} \
-+	    "gnu2-tls-1b.so" \
-+	] \
-     ]
- }
- 
--- 
-2.50.1
-

diff --git a/9999/0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch b/9999/0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
deleted file mode 100644
index c9c7175..0000000
--- a/9999/0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
+++ /dev/null
@@ -1,160 +0,0 @@
-From 9269afaad66f2d88126768e4c647ba711117bcca Mon Sep 17 00:00:00 2001
-Message-ID: <9269afaad66f2d88126768e4c647ba711117bcca.1755548203.git.sam@gentoo.org>
-In-Reply-To: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
-References: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 18 Aug 2025 13:13:21 -0700
-Subject: [PATCH 2/3] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
-
-On Linux/x86-64, programs and shared libraries created with -z mark-plt
-have the GLIBC_2.36 version tag dependency since -z mark-plt uses the
-r_addend field of the R_X86_64_JUMP_SLOT relocation to store the offset
-of the indirect branch instruction.  Glibc versions which don't have the
-commit added to glibc 2.36:
-
-commit f8587a61892cbafd98ce599131bf4f103466f084
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Fri May 20 19:21:48 2022 -0700
-
-    x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
-
-won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation.  If
-glibc versions defines GLIBC_ABI_DT_X86_64_PLT version tag with
-
-commit 399384e0c8193e31aea014220ccfa24300ae5938
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Thu Aug 14 07:03:20 2025 -0700
-
-    x86-64: Add GLIBC_ABI_DT_X86_64_PLT [BZ #33212]
-
-to indicate inclusion of the commit:
-
-commit f8587a61892cbafd98ce599131bf4f103466f084
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Fri May 20 19:21:48 2022 -0700
-
-    x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
-
-we can add GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of
-GLIBC_2.36 version tag dependency.
-
-	PR ld/33213
-	* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Change
-	return type to bool.
-	* elf64-x86-64.c (elf_x86_64_add_glibc_version_dependency): Add
-	GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of,
-	GLIBC_2.36 version tag dependency, for -z mark-plt if libc.so
-	defines GLIBC_ABI_DT_X86_64_PLT version tag.
-	* elflink.c (_bfd_elf_link_add_glibc_version_dependency): Change
-	return type to bool.  Return false if elf_link_add_glibc_verneed
-	returns false.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-bfd.h                         |  2 +-
- bfd/elf64-x86-64.c                    | 24 +++++++++++++++++++-----
- bfd/elflink.c                         |  6 ++++--
- ld/testsuite/ld-x86-64/mark-plt-1a.rd |  2 +-
- 4 files changed, 25 insertions(+), 9 deletions(-)
-
-diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
-index feb470fc477..de7cc410a99 100644
---- a/bfd/elf-bfd.h
-+++ b/bfd/elf-bfd.h
-@@ -2631,7 +2631,7 @@ extern bool _bfd_elf_link_output_relocs
-   (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *,
-    struct elf_link_hash_entry **);
- 
--extern void _bfd_elf_link_add_glibc_version_dependency
-+extern bool _bfd_elf_link_add_glibc_version_dependency
-   (struct elf_find_verdep_info *, const char *const [], bool *);
- 
- extern void _bfd_elf_link_add_dt_relr_dependency
-diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index edfa608d2d7..31a4b0ce489 100644
---- a/bfd/elf64-x86-64.c
-+++ b/bfd/elf64-x86-64.c
-@@ -6246,7 +6246,7 @@ static void
- elf_x86_64_add_glibc_version_dependency
-   (struct elf_find_verdep_info *rinfo)
- {
--  unsigned int i = 0;
-+  int i = 0, mark_plt = -1;
-   const char *version[4] = { NULL, NULL, NULL, NULL };
-   bool auto_version[4] = { false, false, false, false };
-   struct elf_x86_link_hash_table *htab;
-@@ -6271,14 +6271,28 @@ elf_x86_64_add_glibc_version_dependency
- 	}
-       if (htab->params->mark_plt)
- 	{
--	  version[i] = "GLIBC_2.36";
-+	  mark_plt = i;
-+	  auto_version[i] = true;
-+	  version[i] = "GLIBC_ABI_DT_X86_64_PLT";
- 	  i++;
- 	}
-     }
- 
--  if (i != 0)
--    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
--						auto_version);
-+  if (i == 0
-+      || !_bfd_elf_link_add_glibc_version_dependency (rinfo, version,
-+						      auto_version))
-+    return;
-+
-+  if (mark_plt < 0 || auto_version[mark_plt])
-+    return;
-+
-+  /* Add the GLIBC_2.36 version dependency if libc.so doesn't have
-+     GLIBC_ABI_DT_X86_64_PLT.  */
-+  version[0] = "GLIBC_2.36";
-+  auto_version[0] = false;
-+  version[1] = NULL;
-+  _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
-+					      auto_version);
- }
- 
- static const struct bfd_elf_special_section
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index ac40423751f..98759a3dec6 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -2401,7 +2401,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
- /* Add VERSION_DEP to the list of version dependencies when linked
-    against glibc.  */
- 
--void
-+bool
- _bfd_elf_link_add_glibc_version_dependency
-   (struct elf_find_verdep_info *rinfo,
-    const char *const version_dep[],
-@@ -2414,11 +2414,13 @@ _bfd_elf_link_add_glibc_version_dependency
-       /* Return if not linked against glibc.  */
-       if (!elf_link_add_glibc_verneed (rinfo, *version_dep,
- 				       &glibc_minor_base, auto_version))
--	return;
-+	return false;
-       version_dep++;
-       auto_version++;
-     }
-   while (*version_dep != NULL);
-+
-+  return true;
- }
- 
- /* Add GLIBC_ABI_DT_RELR to the list of version dependencies when
-diff --git a/ld/testsuite/ld-x86-64/mark-plt-1a.rd b/ld/testsuite/ld-x86-64/mark-plt-1a.rd
-index 1234fbe038c..b0ed7024420 100644
---- a/ld/testsuite/ld-x86-64/mark-plt-1a.rd
-+++ b/ld/testsuite/ld-x86-64/mark-plt-1a.rd
-@@ -3,5 +3,5 @@ Version needs section '.gnu.version_r' contains 1 entry:
-  Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
-  +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
- #...
--  0x[a-f0-9]+:   Name: GLIBC_2.36  Flags: none  Version: [0-9]+
-+  0x[a-f0-9]+:   Name: (GLIBC_2.36|GLIBC_ABI_DT_X86_64_PLT)  Flags: none  Version: [0-9]+
- #pass
--- 
-2.50.1
-

diff --git a/9999/0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch b/9999/0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
deleted file mode 100644
index 8a758c8..0000000
--- a/9999/0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
+++ /dev/null
@@ -1,470 +0,0 @@
-From 7a3c2c05795a290a1436e0ca0f21514325c8ef44 Mon Sep 17 00:00:00 2001
-Message-ID: <7a3c2c05795a290a1436e0ca0f21514325c8ef44.1755548203.git.sam@gentoo.org>
-In-Reply-To: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
-References: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 18 Aug 2025 13:13:22 -0700
-Subject: [PATCH 3/3] i386: Add GLIBC_ABI_GNU_TLS version dependency
-
-On Linux/i386, programs and shared libraries compiled with
--mtls-dialect=gnu may fail silently at run-time against glibc without
-the GNU TLS run-time fix for:
-
-https://sourceware.org/bugzilla/show_bug.cgi?id=32996
-
-The glibc version tag, GLIBC_ABI_GNU_TLS, has been added to indicate
-that glibc has the working GNU TLS run-time:
-
-commit ed1b7a5a489ab555a27fad9c101ebe2e1c1ba881
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Mon Jul 28 12:16:11 2025 -0700
-
-    i386: Add GLIBC_ABI_GNU_TLS version [BZ #33221]
-
-Add the --gnu-tls-tag option to x86-64 ELF linker to add the
-GLIBC_ABI_GNU_TLS version dependency in output programs and shared
-libraries when linking against glibc if input relocatable object files
-call ___tls_get_addr.  The output will fail to load and run at run-time
-against glibc which doesn't define the GLIBC_ABI_GNU_TLS version.
-
-Add the --enable-gnu-tls-tag configure option to enable --gnu-tls-tag
-by default.  If unspecified, linker will add the GLIBC_ABI_GNU_TLS
-version dependency if input call ___tls_get_addr and libc.so defines
-the GLIBC_ABI_GNU2_TLS version.
-
-bfd/
-
-	PR ld/33287
-	* elf-linker-x86.h (elf_linker_x86_params): Add
-	gnu_tls_version_tag.
-	* elf32-i386.c (elf_backend_add_glibc_version_dependency): Add
-	GLIBC_ABI_GNU_TLS support.
-	* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set
-	has_tls_get_addr_call to 1 if ___tls_get_addr is used.
-	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_get_addr_call.
-
-ld/
-
-	PR ld/33287
-	* Mention --gnu-tls-tag, --no-gnu-tls-tag and --enable-gnu-tls-tag.
-	* config.in: Regenerated.
-	* configure: Likewise.
-	* configure.ac: Add --enable-gnu-tls-tag.
-	* ld.texi: Document --gnu-tls-tag and --enable-gnu-tls-tag.
-	* ldlex.h (option_values): Add OPTION_GNU_TLS_VERSION_TAG and
-	OPTION_NO_GNU_TLS_VERSION_TAG.
-	* emultempl/elf-i386-glibc.em (elf_i386_glibc_before_parse):
-	Initialize params.gnu_tls_version_tag.
-	(PARSE_AND_LIST_LONGOPTS_386): New.
-	(PARSE_AND_LIST_OPTIONS_386): Likewise.
-	(PARSE_AND_LIST_ARGS_CASES_386): Likewise.
-	(PARSE_AND_LIST_LONGOPTS): Append $PARSE_AND_LIST_LONGOPTS_386.
-	(PARSE_AND_LIST_OPTIONS): Append $PARSE_AND_LIST_OPTIONS_386.
-	(PARSE_AND_LIST_ARGS_CASES): Append
-	$PARSE_AND_LIST_ARGS_CASES_386.
-	* testsuite/ld-i386/gnu-tls-1.s: Likewise.
-	* testsuite/ld-i386/gnu-tls-1a.rd: Likewise.
-	* testsuite/ld-i386/gnu-tls-1b.rd: Likewise.
-	* testsuite/ld-i386/i386.exp: Run PR ld/33287 tests.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-linker-x86.h               |  9 ++++++++
- bfd/elf32-i386.c                   | 14 ++++++++++--
- bfd/elfxx-x86.c                    |  2 ++
- bfd/elfxx-x86.h                    |  3 +++
- ld/NEWS                            |  5 +++++
- ld/config.in                       |  4 ++++
- ld/configure                       | 28 +++++++++++++++++++++--
- ld/configure.ac                    | 19 ++++++++++++++++
- ld/emultempl/elf-i386-glibc.em     | 36 ++++++++++++++++++++++++++++++
- ld/ld.texi                         | 13 +++++++++++
- ld/ldlex.h                         |  3 +++
- ld/testsuite/ld-i386/gnu-tls-1.s   |  9 ++++++++
- ld/testsuite/ld-i386/gnu-tls-1a.rd |  7 ++++++
- ld/testsuite/ld-i386/gnu-tls-1b.rd |  4 ++++
- ld/testsuite/ld-i386/i386.exp      | 18 ++++++++++++++-
- 15 files changed, 169 insertions(+), 5 deletions(-)
- create mode 100644 ld/testsuite/ld-i386/gnu-tls-1.s
- create mode 100644 ld/testsuite/ld-i386/gnu-tls-1a.rd
- create mode 100644 ld/testsuite/ld-i386/gnu-tls-1b.rd
-
-diff --git a/bfd/elf-linker-x86.h b/bfd/elf-linker-x86.h
-index fe322152e14..cdd739e572a 100644
---- a/bfd/elf-linker-x86.h
-+++ b/bfd/elf-linker-x86.h
-@@ -80,6 +80,15 @@ struct elf_linker_x86_params
-    */
-   unsigned int gnu2_tls_version_tag : 2;
- 
-+  /* Add the GLIBC_ABI_GNU_TLS version dependency if input object files
-+     call ___tls_get_addr:
-+     0: Disable.
-+     1: Enable.
-+     2: Auto.  Enable if libc.so has the GLIBC_ABI_GNU_TLS version.
-+     This is only used by i386.
-+   */
-+  unsigned int gnu_tls_version_tag : 2;
-+
-   /* X86-64 ISA level needed.  */
-   unsigned int isa_level;
- 
-diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
-index c1115a52d1b..3f1a0b14577 100644
---- a/bfd/elf32-i386.c
-+++ b/bfd/elf32-i386.c
-@@ -4501,8 +4501,8 @@ elf_i386_add_glibc_version_dependency
-   (struct elf_find_verdep_info *rinfo)
- {
-   int i = 0;
--  const char *version[3] = { NULL, NULL, NULL };
--  bool auto_version[3] = { false, false, false };
-+  const char *version[4] = { NULL, NULL, NULL, NULL };
-+  bool auto_version[4] = { false, false, false, false };
-   struct elf_x86_link_hash_table *htab;
- 
-   if (rinfo->info->enable_dt_relr)
-@@ -4523,6 +4523,16 @@ elf_i386_add_glibc_version_dependency
- 	    auto_version[i] = true;
- 	  i++;
- 	}
-+      if (htab->params->gnu_tls_version_tag
-+	  && htab->has_tls_get_addr_call)
-+	{
-+	  version[i] = "GLIBC_ABI_GNU_TLS";
-+	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU_TLS
-+	     version.  */
-+	  if (htab->params->gnu_tls_version_tag == 2)
-+	    auto_version[i] = true;
-+	  i++;
-+	}
-     }
- 
-   if (i != 0)
-diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
-index e2c61b85fc6..3de48397e78 100644
---- a/bfd/elfxx-x86.c
-+++ b/bfd/elfxx-x86.c
-@@ -882,6 +882,8 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
- 		  h = (struct elf_link_hash_entry *) h->root.u.i.link;
- 		  elf_x86_hash_entry (h)->tls_get_addr = 1;
- 		}
-+
-+	      htab->has_tls_get_addr_call = 1;
- 	    }
- 
- 	  /* Pass NULL for __ehdr_start which will be defined by
-diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
-index 791a2a2592f..2a28987f208 100644
---- a/bfd/elfxx-x86.h
-+++ b/bfd/elfxx-x86.h
-@@ -674,6 +674,9 @@ struct elf_x86_link_hash_table
-      relocation.  */
-   unsigned int has_tls_desc_call : 1;
- 
-+  /* TRUE if inputs call ___tls_get_addr.  This is only used for i386.  */
-+  unsigned int has_tls_get_addr_call : 1;
-+
-    /* Value used to fill the unused bytes of the first PLT entry.  This
-       is only used for i386.  */
-   bfd_byte plt0_pad_byte;
-diff --git a/ld/NEWS b/ld/NEWS
-index bacabc8440e..8794e883522 100644
---- a/ld/NEWS
-+++ b/ld/NEWS
-@@ -1,5 +1,10 @@
- -*- text -*-
- 
-+* Add --gnu-tls-tag/--no-gnu-tls-tag options to i386 ELF linker to add
-+  the GLIBC_ABI_GNU_TLS version dependency in output if input object
-+  files call ___tls_get_addr.  Also added --enable-gnu-tls-tag configure
-+  option to enable --gnu-tls-tag by default.
-+
- * Add --gnu2-tls-tag/--no-gnu2-tls-tag options to i386 and x86-64 ELF
-   linkers to add the GLIBC_ABI_GNU2_TLS version dependency in output if
-   input object files have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
-diff --git a/ld/config.in b/ld/config.in
-index 64dbc3e0c88..790efd336be 100644
---- a/ld/config.in
-+++ b/ld/config.in
-@@ -35,6 +35,10 @@
-    by default. */
- #undef DEFAULT_LD_GNU2_TLS_TAG
- 
-+/* Define to 1 if you want to enable --gnu-tls-tag in ELF i386 linker by
-+   default. */
-+#undef DEFAULT_LD_GNU_TLS_TAG
-+
- /* Define to 1 if you want to enable --rosegment in the ELF linker by default.
-    */
- #undef DEFAULT_LD_ROSEGMENT
-diff --git a/ld/configure b/ld/configure
-index 6f1a3559964..fe23178cd29 100755
---- a/ld/configure
-+++ b/ld/configure
-@@ -852,6 +852,7 @@ enable_separate_code
- enable_rosegment
- enable_mark_plt
- enable_gnu2_tls_tag
-+enable_gnu_tls_tag
- enable_memory_seal
- enable_warn_execstack
- enable_error_execstack
-@@ -1551,6 +1552,7 @@ Optional Features:
-   --enable-mark-plt       enable -z mark-plt in ELF x86-64 linker by default
-   --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF i386/x86-64 linker by
-                           default
-+  --enable-gnu-tls-tag    enable --gnu-tls-tag in ELF i386 linker by default
-   --enable-memory-seal    enable -z memory-seal in ELF linker by default
-   --enable-warn-execstack enable warnings when creating an executable stack
-   --enable-error-execstack
-@@ -11517,7 +11519,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11520 "configure"
-+#line 11522 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -11623,7 +11625,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11626 "configure"
-+#line 11628 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -15522,6 +15524,17 @@ esac
- fi
- 
- 
-+# Decide if --gnu-tls-tag should be enabled in ELF i386 linker by default.
-+ac_default_ld_enable_gnu_tls_tag=unset
-+# Check whether --enable-gnu-tls-tag was given.
-+if test "${enable_gnu_tls_tag+set}" = set; then :
-+  enableval=$enable_gnu_tls_tag; case "${enableval}" in
-+  yes) ac_default_ld_enable_gnu_tls_tag=1 ;;
-+  no) ac_default_ld_enable_gnu_tls_tag=0 ;;
-+esac
-+fi
-+
-+
- # Decide if -z memory-seal should be enabled in ELF linker by default.
- ac_default_ld_z_memory_seal=unset
- # Check whether --enable-memory-seal was given.
-@@ -19007,6 +19020,17 @@ cat >>confdefs.h <<_ACEOF
- _ACEOF
- 
- 
-+if test "${ac_default_ld_enable_gnu_tls_tag}" = unset; then
-+  # Default to enable --gnu-tls-tag if libc.so has the GLIBC_ABI_GNU_TLS
-+  # version.
-+  ac_default_ld_enable_gnu_tls_tag=2
-+fi
-+
-+cat >>confdefs.h <<_ACEOF
-+#define DEFAULT_LD_GNU_TLS_TAG $ac_default_ld_enable_gnu_tls_tag
-+_ACEOF
-+
-+
- 
- cat >>confdefs.h <<_ACEOF
- #define DEFAULT_LD_WARN_EXECSTACK $ac_default_ld_warn_execstack
-diff --git a/ld/configure.ac b/ld/configure.ac
-index 4b9068a415e..3e44e3361ef 100644
---- a/ld/configure.ac
-+++ b/ld/configure.ac
-@@ -256,6 +256,16 @@ AC_ARG_ENABLE(gnu2-tls-tag,
-   no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
- esac])
- 
-+# Decide if --gnu-tls-tag should be enabled in ELF i386 linker by default.
-+ac_default_ld_enable_gnu_tls_tag=unset
-+AC_ARG_ENABLE(gnu-tls-tag,
-+	      AS_HELP_STRING([--enable-gnu-tls-tag],
-+	      [enable --gnu-tls-tag in ELF i386 linker by default]),
-+[case "${enableval}" in
-+  yes) ac_default_ld_enable_gnu_tls_tag=1 ;;
-+  no) ac_default_ld_enable_gnu_tls_tag=0 ;;
-+esac])
-+
- # Decide if -z memory-seal should be enabled in ELF linker by default.
- ac_default_ld_z_memory_seal=unset
- AC_ARG_ENABLE(memory-seal,
-@@ -666,6 +676,15 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU2_TLS_TAG,
-   $ac_default_ld_enable_gnu2_tls_tag,
-   [Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker by default.])
- 
-+if test "${ac_default_ld_enable_gnu_tls_tag}" = unset; then
-+  # Default to enable --gnu-tls-tag if libc.so has the GLIBC_ABI_GNU_TLS
-+  # version.
-+  ac_default_ld_enable_gnu_tls_tag=2
-+fi
-+AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU_TLS_TAG,
-+  $ac_default_ld_enable_gnu_tls_tag,
-+  [Define to 1 if you want to enable --gnu-tls-tag in ELF i386 linker by default.])
-+
- AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK,
-   $ac_default_ld_warn_execstack,
-   [Define to 1 if you want to enable --warn-execstack in ELF linker by default.])
-diff --git a/ld/emultempl/elf-i386-glibc.em b/ld/emultempl/elf-i386-glibc.em
-index 547823750a4..26a7296cf76 100644
---- a/ld/emultempl/elf-i386-glibc.em
-+++ b/ld/emultempl/elf-i386-glibc.em
-@@ -35,7 +35,43 @@ elf_i386_glibc_before_parse (void)
- {
-   elf_x86_before_parse ();
-   elf_x86_glibc_before_parse ();
-+  params.gnu_tls_version_tag = DEFAULT_LD_GNU_TLS_TAG;
- }
- EOF
- 
- LDEMUL_BEFORE_PARSE=elf_i386_glibc_before_parse
-+
-+PARSE_AND_LIST_LONGOPTS_386='
-+  { "gnu-tls-tag", no_argument, NULL, OPTION_GNU_TLS_VERSION_TAG },
-+  { "no-gnu-tls-tag", no_argument, NULL, OPTION_NO_GNU_TLS_VERSION_TAG },
-+'
-+
-+PARSE_AND_LIST_OPTIONS_386='
-+  if (DEFAULT_LD_GNU_TLS_TAG == 0)
-+    fprintf (file, _("\
-+  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency\n\
-+  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency (default)\n"));
-+  else if (DEFAULT_LD_GNU_TLS_TAG == 1)
-+    fprintf (file, _("\
-+  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency (default)\n\
-+  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency\n"));
-+  else
-+    fprintf (file, _("\
-+  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency (auto)\n\
-+                                when no options are specified (default)\n\
-+  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency\n"));
-+'
-+
-+PARSE_AND_LIST_ARGS_CASES_386='
-+    case OPTION_GNU_TLS_VERSION_TAG:
-+      params.gnu_tls_version_tag = 1;
-+      break;
-+
-+    case OPTION_NO_GNU_TLS_VERSION_TAG:
-+      params.gnu_tls_version_tag = 0;
-+      break;
-+'
-+
-+PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_386"
-+PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_386"
-+PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_386"
-diff --git a/ld/ld.texi b/ld/ld.texi
-index 0e13f7d8e35..cf750d15259 100644
---- a/ld/ld.texi
-+++ b/ld/ld.texi
-@@ -1745,6 +1745,19 @@ Supported for Linux/i386 and Linux/x86_64.
- 
- Other keywords are ignored for Solaris compatibility.
- 
-+@item --gnu-tls-tag
-+@itemx --no-gnu-tls-tag
-+Add @code{GLIBC_ABI_GNU_TLS} version tag dependency in output programs
-+and shared libraries when linking against glibc if input relocatable
-+object files call @code{___tls_get_addr}.  The output will fail to load
-+and run at run-time against glibc which doesn't define the
-+@code{GLIBC_ABI_GNU_TLS} version tag.  Unless disabled by the
-+@option{--disable-gnu-tls-tag} configure option at the linker build
-+time, when no options are specified, linker will add the
-+@code{GLIBC_ABI_GNU_TLS} version tag dependency if inputs have
-+@code{___tls_get_addr} call and libc.so defines the
-+@code{GLIBC_ABI_GNU_TLS} version tag.  Supported for Linux/i386.
-+
- @item --gnu2-tls-tag
- @itemx --no-gnu2-tls-tag
- Add @code{GLIBC_ABI_GNU2_TLS} version tag dependency in output programs
-diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 286ab0ba6d1..c8d61478c60 100644
---- a/ld/ldlex.h
-+++ b/ld/ldlex.h
-@@ -474,6 +474,9 @@ enum option_values
-   /* Used by emultempl/elf-x86-glibc.em.  */
-   OPTION_GNU2_TLS_VERSION_TAG,
-   OPTION_NO_GNU2_TLS_VERSION_TAG,
-+  /* Used by emultempl/elf-i386-glibc.em.  */
-+  OPTION_GNU_TLS_VERSION_TAG,
-+  OPTION_NO_GNU_TLS_VERSION_TAG,
- };
- 
- /* The initial parser states.  */
-diff --git a/ld/testsuite/ld-i386/gnu-tls-1.s b/ld/testsuite/ld-i386/gnu-tls-1.s
-new file mode 100644
-index 00000000000..02ae207a9b5
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu-tls-1.s
-@@ -0,0 +1,9 @@
-+	.text
-+	.p2align 4
-+	.globl	func
-+	.type	func, @function
-+func:
-+	leal	foo@tlsgd(,%ebx,1), %eax
-+	call	___tls_get_addr@PLT
-+	ret
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-i386/gnu-tls-1a.rd b/ld/testsuite/ld-i386/gnu-tls-1a.rd
-new file mode 100644
-index 00000000000..65d889de7d9
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu-tls-1a.rd
-@@ -0,0 +1,7 @@
-+#...
-+Version needs section '.gnu.version_r' contains [0-9]+ entries:
-+ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
-+ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU_TLS  Flags: none  Version: [0-9]+
-+#pass
-diff --git a/ld/testsuite/ld-i386/gnu-tls-1b.rd b/ld/testsuite/ld-i386/gnu-tls-1b.rd
-new file mode 100644
-index 00000000000..02006e47da1
---- /dev/null
-+++ b/ld/testsuite/ld-i386/gnu-tls-1b.rd
-@@ -0,0 +1,4 @@
-+#failif
-+#...
-+  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU_TLS  Flags: none  Version: [0-9]+
-+#...
-diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
-index 74ef1672f86..2b6a36e63f8 100644
---- a/ld/testsuite/ld-i386/i386.exp
-+++ b/ld/testsuite/ld-i386/i386.exp
-@@ -1516,10 +1516,26 @@ run_ld_link_tests [list \
-     ] \
- ]
- 
--# The musl C library does not support --gnu2-tls-tag.
-+# The musl C library does not support --gnu-tls-tag nor --gnu2-tls-tag.
- if { ![istarget *-*-musl]
-      && [check_compiler_available] } {
-     run_cc_link_tests [list \
-+	[list \
-+	    "Build gnu-tls-1a.so" \
-+	    "-shared -Wl,--no-as-needed,--gnu-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu-tls-1a.rd}} \
-+	    "gnu-tls-1a.so" \
-+	] \
-+	[list \
-+	    "Build gnu-tls-1b.so" \
-+	    "-shared -Wl,--no-as-needed,--no-gnu-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu-tls-1b.rd}} \
-+	    "gnu-tls-1b.so" \
-+	] \
- 	[list \
- 	    "Build gnu2-tls-1a.so" \
- 	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
--- 
-2.50.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-20 22:17 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-20 22:17 UTC (permalink / raw
  To: gentoo-commits

commit:     2020f0c37a487cbf01e87b6e923e9cb3dbed0087
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 22:17:46 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 22:17:46 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=2020f0c3

9999: switch to H.J.'s section size patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ntsize-when-clearing-SEC_MERGE-SEC_STRING.patch | 87 ++++++++++++++++++++++
 9999/0006-ld-section-size.patch                    | 75 -------------------
 2 files changed, 87 insertions(+), 75 deletions(-)

diff --git a/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch b/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch
new file mode 100644
index 0000000..b9c30be
--- /dev/null
+++ b/9999/0006-elf-Clear-entsize-when-clearing-SEC_MERGE-SEC_STRING.patch
@@ -0,0 +1,87 @@
+From 3e39ade99e4e24f741c7d5631412e89d1bc5bde4 Mon Sep 17 00:00:00 2001
+Message-ID: <3e39ade99e4e24f741c7d5631412e89d1bc5bde4.1755728184.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Wed, 20 Aug 2025 12:27:53 -0700
+Subject: [PATCH] elf: Clear entsize when clearing SEC_MERGE|SEC_STRINGS
+
+When generating an output from input SEC_MERGE|SEC_STRINGS sections with
+different entsize, we clear the SEC_MERGE|SEC_STRINGS bits.  We also need
+to clear entsize.
+
+	PR ld/33291
+	* ldlang.c (lang_add_section): Clearing entsize when clearing
+	SEC_MERGE|SEC_STRINGS.
+	* testsuite/ld-elf/pr33291.d: New file.
+	* testsuite/ld-elf/pr33291a.s: Likewise.
+	* testsuite/ld-elf/pr33291b.s: Likewise.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ ld/ldlang.c                    | 1 +
+ ld/testsuite/ld-elf/pr33291.d  | 9 +++++++++
+ ld/testsuite/ld-elf/pr33291a.s | 8 ++++++++
+ ld/testsuite/ld-elf/pr33291b.s | 7 +++++++
+ 4 files changed, 25 insertions(+)
+ create mode 100644 ld/testsuite/ld-elf/pr33291.d
+ create mode 100644 ld/testsuite/ld-elf/pr33291a.s
+ create mode 100644 ld/testsuite/ld-elf/pr33291b.s
+
+diff --git a/ld/ldlang.c b/ld/ldlang.c
+index 8ba95b04e23..0bb4a17df19 100644
+--- a/ld/ldlang.c
++++ b/ld/ldlang.c
+@@ -2861,6 +2861,7 @@ lang_add_section (lang_statement_list_type *ptr,
+ 	      && output->bfd_section->entsize != section->entsize))
+ 	{
+ 	  output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
++	  output->bfd_section->entsize = 0;
+ 	  flags &= ~ (SEC_MERGE | SEC_STRINGS);
+ 	}
+     }
+diff --git a/ld/testsuite/ld-elf/pr33291.d b/ld/testsuite/ld-elf/pr33291.d
+new file mode 100644
+index 00000000000..9f08118433e
+--- /dev/null
++++ b/ld/testsuite/ld-elf/pr33291.d
+@@ -0,0 +1,9 @@
++#source: pr33291a.s
++#source: pr33291b.s
++#ld: -shared
++#readelf: -S --wide
++#xfail: ![check_shared_lib_support] 
++
++#...
++  \[[ 0-9]+\] \.rodata[ 	]+PROGBITS[ 	]+[0-9a-f]+ [0-9a-f]+ 0+9 00 +A +0 +0 +8
++#...
+diff --git a/ld/testsuite/ld-elf/pr33291a.s b/ld/testsuite/ld-elf/pr33291a.s
+new file mode 100644
+index 00000000000..07e9f7c2c21
+--- /dev/null
++++ b/ld/testsuite/ld-elf/pr33291a.s
+@@ -0,0 +1,8 @@
++	.globl	foo
++	.section	.rodata.cst8,"aM",%progbits,8
++	.align 8
++	.type	foo, %object
++	.size	foo, 8
++foo:
++	.quad	131073
++	.section	.note.GNU-stack,"",%progbits
+diff --git a/ld/testsuite/ld-elf/pr33291b.s b/ld/testsuite/ld-elf/pr33291b.s
+new file mode 100644
+index 00000000000..69f6b3db594
+--- /dev/null
++++ b/ld/testsuite/ld-elf/pr33291b.s
+@@ -0,0 +1,7 @@
++	.globl	bar
++	.section	.rodata.cst1,"aM",%progbits,1
++	.type	bar, %object
++	.size	bar, 1
++bar:
++	.byte	1
++	.section	.note.GNU-stack,"",%progbits
+
+base-commit: fbcdc06c238be4fd6da7fb9bff4dd4c7f749ae07
+-- 
+2.51.0
+

diff --git a/9999/0006-ld-section-size.patch b/9999/0006-ld-section-size.patch
deleted file mode 100644
index 7526cbd..0000000
--- a/9999/0006-ld-section-size.patch
+++ /dev/null
@@ -1,75 +0,0 @@
-From 79b01a9700c96203028dc8c9472e91c38eda5e83 Mon Sep 17 00:00:00 2001
-Message-ID: <79b01a9700c96203028dc8c9472e91c38eda5e83.1755600645.git.sam@gentoo.org>
-From: Jan Beulich <jbeulich@suse.com>
-Date: Tue, 19 Aug 2025 10:35:38 +0200
-Subject: [PATCH] ld: entry size and merge/strings attributes propagation
-
-PR ld/33291
-
-As indicated in other recent commits, the three properties can be
-largely independent (ELF generally being the target here): Entry size
-doesn't require either of merge/strings, and strings also doesn't
-require merge. Commit 98e6d3f5bd4e ("gas/ELF: allow specifying entity
-size for arbitrary sections") uncovered issues with ld's handling.
-
-Zap entry size when it doesn't match between input sections. In that
-case SEC_MERGE and SEC_STRINGS also need to be removed, as their
-underlying granularity is lost. Then deal with SEC_MERGE and
-SEC_STRINGS separately.
-
-Otoh record entry size from the first input independent of SEC_MERGE.
----
- ld/ldlang.c | 27 ++++++++++++++++++---------
- 1 file changed, 18 insertions(+), 9 deletions(-)
-
-diff --git a/ld/ldlang.c b/ld/ldlang.c
-index 8ba95b04e23..54292a8dfe1 100644
---- a/ld/ldlang.c
-+++ b/ld/ldlang.c
-@@ -2854,14 +2854,24 @@ lang_add_section (lang_statement_list_type *ptr,
-       /* Only set SEC_READONLY flag on the first input section.  */
-       flags &= ~ SEC_READONLY;
- 
--      /* Keep SEC_MERGE and SEC_STRINGS only if they are the same.  */
--      if ((output->bfd_section->flags & (SEC_MERGE | SEC_STRINGS))
--	  != (flags & (SEC_MERGE | SEC_STRINGS))
--	  || ((flags & SEC_MERGE) != 0
--	      && output->bfd_section->entsize != section->entsize))
-+      /* Keep entry size, SEC_MERGE, and SEC_STRINGS only if entry sizes are
-+	 the same.  */
-+      if (output->bfd_section->entsize != section->entsize)
- 	{
--	  output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
--	  flags &= ~ (SEC_MERGE | SEC_STRINGS);
-+	  output->bfd_section->entsize = 0;
-+	  flags &= ~(SEC_MERGE | SEC_STRINGS);
-+	}
-+
-+      /* Keep SEC_MERGE and SEC_STRINGS (each) only if they are the same.  */
-+      if ((output->bfd_section->flags ^ flags) & SEC_MERGE)
-+	{
-+	  output->bfd_section->flags &= ~SEC_MERGE;
-+	  flags &= ~SEC_MERGE;
-+	}
-+      if ((output->bfd_section->flags ^ flags) & SEC_STRINGS)
-+	{
-+	  output->bfd_section->flags &= ~SEC_STRINGS;
-+	  flags &= ~SEC_STRINGS;
- 	}
-     }
-   output->bfd_section->flags |= flags;
-@@ -2876,8 +2886,7 @@ lang_add_section (lang_statement_list_type *ptr,
- 				     link_info.output_bfd,
- 				     output->bfd_section,
- 				     &link_info);
--      if ((flags & SEC_MERGE) != 0)
--	output->bfd_section->entsize = section->entsize;
-+      output->bfd_section->entsize = section->entsize;
-     }
- 
-   if ((flags & SEC_TIC54X_BLOCK) != 0
-
-base-commit: 09292f4ae2ccb46130652f6b310ee7a5227326d3
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-20 20:44 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-20 20:44 UTC (permalink / raw
  To: gentoo-commits

commit:     86a70a7e63ef3bb301284b6ab65f5fce54f01991
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 20:44:27 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 20:44:27 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=86a70a7e

9999: drop test patch merged upstream

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ile-some-tests-with-mdirect-extern-access.patch | 708 ---------------------
 1 file changed, 708 deletions(-)

diff --git a/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch b/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch
deleted file mode 100644
index 94449be..0000000
--- a/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch
+++ /dev/null
@@ -1,708 +0,0 @@
-From 9d753e17740040d4d063bbbdd1e2df6346805cd8 Mon Sep 17 00:00:00 2001
-Message-ID: <9d753e17740040d4d063bbbdd1e2df6346805cd8.1755623414.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 19 Aug 2025 04:59:10 -0700
-Subject: [PATCH] ld: Compile some tests with -mdirect-extern-access
-
-When GCC enables -mno-direct-extern-access by default, some tests fail
-without -mdirect-extern-access.  Define DIRECT_EXTERN_ACCESS_CFLAGS
-to compile these tests with -mdirect-extern-access.  Also pass
-"-z noindirect-extern-access" to linker to support the C library
-compiled with -mno-direct-extern-access.
-
-	PR ld/33267
-	* testsuite/config/default.exp (DIRECT_EXTERN_ACCESS_CFLAGS): New.
-	* testsuite/ld-elf/linux-x86.exp: Compile some tests with
-	$DIRECT_EXTERN_ACCESS_CFLAGS.
-	* testsuite/ld-elfvers/vers.exp (need_direct_extern_access): New
-	for i?86.
-	Compile tests with $need_direct_extern_access.
-	* testsuite/ld-i386/i386.exp: Compile some tests with
-	$DIRECT_EXTERN_ACCESS_CFLAGS.
-	* testsuite/ld-ifunc/ifunc.exp (need_direct_extern_access): New
-	for i?86.
-	Compile tests with $need_direct_extern_access.
-	* testsuite/ld-shared/shared.exp (need_direct_extern_access): New
-	for i?86.
-	Compile tests with $need_direct_extern_access.
-	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET_TEST): Add
-	$DIRECT_EXTERN_ACCESS_CFLAGS.
-	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
-	* testsuite/ld-vsb/vsb.exp (need_direct_extern_access): New
-	for i?86.
-	Compile tests with $need_direct_extern_access.
-	* testsuite/ld-x86-64/x86-64.exp: Compile some tests with
-	$DIRECT_EXTERN_ACCESS_CFLAGS and link some tests with
-	"-Wl,-z,noindirect-extern-access".
-
-Co-Authored-By: Sam James <sam@gentoo.org>
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
-Signed-off-by: Sam James <sam@gentoo.org>
----
- ld/testsuite/config/default.exp   |  9 ++++
- ld/testsuite/ld-elf/linux-x86.exp | 14 +++---
- ld/testsuite/ld-elfvers/vers.exp  | 10 +++-
- ld/testsuite/ld-i386/i386.exp     | 31 ++++++------
- ld/testsuite/ld-ifunc/ifunc.exp   |  9 ++++
- ld/testsuite/ld-shared/shared.exp | 11 ++++-
- ld/testsuite/ld-srec/srec.exp     |  7 +--
- ld/testsuite/ld-vsb/vsb.exp       | 14 ++++--
- ld/testsuite/ld-x86-64/x86-64.exp | 78 +++++++++++++++----------------
- 9 files changed, 114 insertions(+), 69 deletions(-)
-
-diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
-index 9f286831e07..3619f523762 100644
---- a/ld/testsuite/config/default.exp
-+++ b/ld/testsuite/config/default.exp
-@@ -456,6 +456,15 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
-     }
- }
- 
-+if { ![info exists DIRECT_EXTERN_ACCESS_CFLAGS] } then {
-+    set DIRECT_EXTERN_ACCESS_CFLAGS ""
-+    if [compiler_supports "-mdirect-extern-access"] {
-+	set DIRECT_EXTERN_ACCESS_CFLAGS "-mdirect-extern-access"
-+    } elseif [compiler_supports "-fdirect-access-external-data"] {
-+	set DIRECT_EXTERN_ACCESS_CFLAGS "-fdirect-access-external-data"
-+    }
-+}
-+
- if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
-     set NOCF_PROTECTION_CFLAGS ""
-     if [compiler_supports "-fcf-protection=none"] {
-diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
-index 27173b916da..a4dfc8ad394 100644
---- a/ld/testsuite/ld-elf/linux-x86.exp
-+++ b/ld/testsuite/ld-elf/linux-x86.exp
-@@ -84,9 +84,9 @@ run_cc_link_tests [list \
-     ] \
-     [list \
- 	"Build indirect-extern-access-1a without PIE" \
--	"$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
-+	"$NOPIE_LDFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wl,--no-as-needed -z noexecstack \
- 	 tmpdir/indirect-extern-access-1.so" \
--	"$NOPIE_CFLAGS" \
-+	"$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	{ indirect-extern-access.S indirect-extern-access-1b.c } \
- 	{{readelf -rn indirect-extern-access-1.rd}} \
- 	"indirect-extern-access-1a" \
-@@ -101,9 +101,9 @@ run_cc_link_tests [list \
-     ] \
-     [list \
- 	"Build indirect-extern-access-2a without PIE" \
--	"$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
-+	"$NOPIE_LDFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wl,--no-as-needed -z noexecstack \
- 	 tmpdir/indirect-extern-access-2.so" \
--	"$NOPIE_CFLAGS" \
-+	"$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	{ indirect-extern-access.S indirect-extern-access-1b.c } \
- 	{{readelf -rn indirect-extern-access-2.rd}} \
- 	"indirect-extern-access-2a" \
-@@ -375,11 +375,11 @@ proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
- 
- check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
- check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
--check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
-+check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" "$NOPIE_LDFLAGS" ""
- if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
--    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
-+    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE $DIRECT_EXTERN_ACCESS_CFLAGS" "-pie" ""
- } else {
--    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
-+    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE $DIRECT_EXTERN_ACCESS_CFLAGS" "-pie" "pr25749-1b.err"
- }
- check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
- check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
-diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
-index 4f59e0c174b..80faaa01079 100644
---- a/ld/testsuite/ld-elfvers/vers.exp
-+++ b/ld/testsuite/ld-elfvers/vers.exp
-@@ -60,6 +60,13 @@ if { ![istarget *-*-solaris2*]
-     return
- }
- 
-+set need_direct_extern_access ""
-+if { [istarget i?86-*-linux*]
-+     || [istarget i?86-*-gnu*] } then {
-+    # These targets need direct extern access in some tests.
-+    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
-+}
-+
- set diff diff
- set tmpdir tmpdir
- set VOBJDUMP_FLAGS --private-headers
-@@ -558,7 +565,8 @@ proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp
-   global shared
-   # Make sure that PLT is used since PLT is expected.
-   global PLT_CFLAGS
--  build_binary "$shared -z notext" $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
-+  global need_direct_extern_access
-+  build_binary "$shared -z notext" "$PLT_CFLAGS $need_direct_extern_access" $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
- }
- 
- proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
-diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
-index 86748b1a494..8633a663ec0 100644
---- a/ld/testsuite/ld-i386/i386.exp
-+++ b/ld/testsuite/ld-i386/i386.exp
-@@ -712,7 +712,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17689.so" \
- 	    "-shared" \
--	    "-fPIC -Wa,-mrelax-relocations=yes" \
-+	    "-fPIC $DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { pr17689a.c } \
- 	    {} \
- 	    "pr17689.so" \
-@@ -736,7 +736,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17689.a" \
- 	    "" \
--	    "-Wa,-mrelax-relocations=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { pr17689b.S } \
- 	    {} \
- 	    "pr17689.a" \
-@@ -744,7 +744,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17689 with PIE and GOTOFF" \
- 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
--	    "-Wa,-mrelax-relocations=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { dummy.c } \
- 	    {{readelf {-Wr} pr17689.rd}} \
- 	    "pr17689" \
-@@ -752,7 +752,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17689 with PIE, -z now and GOTOFF" \
- 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
--	    "-Wa,-mrelax-relocations=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { dummy.c } \
- 	    {{readelf {-Wr} pr17689now.rd}} \
- 	    "pr17689now" \
-@@ -760,7 +760,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17689ver with PIE and GOTOFF" \
- 	    "tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
--	    "-Wa,-mrelax-relocations=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { dummy.c } \
- 	    {{readelf {-Wr} pr17689ver.rd}} \
- 	    "pr17689ver" \
-@@ -768,7 +768,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr17827 with PIE and GOTOFF" \
- 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
--	    "-Wa,-mrelax-relocations=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
- 	    { dummy.c } \
- 	    {{readelf {-Wr} pr17827.rd}} \
- 	    "pr17827" \
-@@ -874,7 +874,7 @@ if { [isnative]
- 	[list \
- 	    "Build property 1 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-no-copy.S} \
- 	    {{readelf {-n} property-1a.r}} \
- 	    "property-1.o" \
-@@ -898,7 +898,7 @@ if { [isnative]
- 	[list \
- 	    "Build property 2 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-stack.S} \
- 	    {{readelf {-n} property-2a.r}} \
- 	    "property-2.o" \
-@@ -922,7 +922,7 @@ if { [isnative]
- 	[list \
- 	    "Build property 3 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-x86-1.S property-stack.S} \
- 	    {{readelf {-n} property-3a.r}} \
- 	    "property-3.o" \
-@@ -946,7 +946,7 @@ if { [isnative]
- 	[list \
- 	    "Build property 4 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
- 	    {{readelf {-n} property-4a.r}} \
- 	    "property-4.o" \
-@@ -978,7 +978,7 @@ if { [isnative]
- 	[list \
- 	    "Build property 5 (.o)" \
- 	    "-r -nostdlib -Wl,-z,stack-size=0x900000" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
- 	    {{readelf {-n} property-5a.r}} \
- 	    "property-5.o" \
-@@ -1002,7 +1002,7 @@ if { [isnative]
- 	[list \
- 	    "Build property-6.o" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {property-6b.c property-stack.S} \
- 	    {{readelf {-n} property-2a.r}} \
- 	    "property-6.o" \
-@@ -1069,6 +1069,7 @@ if { [isnative]
- 	    { dummy.c } \
- 	    "pr17689" \
- 	    "pr17689.out" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	] \
- 	[list \
- 	    "Run pr17689 with PIE, -z now and GOTOFF" \
-@@ -1077,6 +1078,7 @@ if { [isnative]
- 	    { dummy.c } \
- 	    "pr17689now" \
- 	    "pr17689.out" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	] \
- 	[list \
- 	    "Run pr17689ver with PIE and GOTOFF" \
-@@ -1085,6 +1087,7 @@ if { [isnative]
- 	    { dummy.c } \
- 	    "pr17689ver" \
- 	    "pr17689.out" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	] \
- 	[list \
- 	    "Run pr18900" \
-@@ -1320,7 +1323,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr28875" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr28875.so" \
--	    "$NOPIE_CFLAGS" \
-+	    "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
- 	    { pr28875b.c } \
- 	    {{error_output "pr28875.err"}} \
- 	    "pr28875" \
-@@ -1328,7 +1331,7 @@ if { [isnative]
- 	[list \
- 	    "Build pr21997-1" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr21997-1b.c } \
- 	    {{error_output "pr21997-1.err"}} \
- 	    "pr21997-1" \
-diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
-index e8b93b347ef..07a8a2f2bcc 100644
---- a/ld/testsuite/ld-ifunc/ifunc.exp
-+++ b/ld/testsuite/ld-ifunc/ifunc.exp
-@@ -54,6 +54,13 @@ if ![check_shared_lib_support] {
-     return
- }
- 
-+set need_direct_extern_access ""
-+if { [istarget i?86-*-linux*]
-+     || [istarget i?86-*-gnu*] } then {
-+    # These targets need direct extern access in some tests.
-+    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
-+}
-+
- set saved_ASFLAGS "$ASFLAGS"
- if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
-     set ASFLAGS "$ASFLAGS -mx86-used-note=no"
-@@ -497,6 +504,7 @@ if { [check_ifunc_available] } {
- 	    { ifunc-main.c } \
- 	    "ifunc-main" \
- 	    "ifunc-main.out" \
-+	    "$need_direct_extern_access" \
- 	] \
- 	[list \
- 	    "Run ifunc-main with -fpic" \
-@@ -514,6 +522,7 @@ if { [check_ifunc_available] } {
- 	    { ifunc-main.c } \
- 	    "ifunc-mainn" \
- 	    "ifunc-main.out" \
-+	    "$need_direct_extern_access" \
- 	] \
- 	[list \
- 	    "Run ifunc-main with PIE (-z now)" \
-diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
-index e7f77fad567..daafee07410 100644
---- a/ld/testsuite/ld-shared/shared.exp
-+++ b/ld/testsuite/ld-shared/shared.exp
-@@ -62,6 +62,13 @@ if { ![istarget hppa*64*-*-hpux*] \
-     return
- }
- 
-+set need_direct_extern_access ""
-+if { [istarget i?86-*-linux*]
-+     || [istarget i?86-*-gnu*] } then {
-+    # These targets need direct extern access in some tests.
-+    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
-+}
-+
- set tmpdir tmpdir
- set SHCFLAG ""
- set shared_needs_pic "no"
-@@ -217,8 +224,8 @@ if ![ld_compile "$CC_FOR_TARGET $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $
-     # will need to do more relocation work.  However, note that not
-     # using -fpic will cause some of the tests to return different
-     # results.  Make sure that PLT is used since PLT is expected.
--    if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
--	 || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
-+    if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG $need_direct_extern_access" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
-+	 || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG $need_direct_extern_access" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
- 	unsupported "shared (non PIC)"
-     } else { if { [is_xcoff_format] } {
- 	shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o xcoff "" $NOPIE_LDFLAGS
-diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
-index 5afc84c24b6..227411a9f8a 100644
---- a/ld/testsuite/ld-srec/srec.exp
-+++ b/ld/testsuite/ld-srec/srec.exp
-@@ -364,11 +364,12 @@ if { ![check_compiler_available] } {
- # Pass -fplt to CC and CXX since -fno-plt doesn't work with S-records
- # tests. Also add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if PIE doesn't work
- # with S-records.  Also add $NOCF_PROTECTION_CFLAGS for S-records.
--# Also add $NOSANITIZE_CFLAGS for S-records.
-+# Also add $NOSANITIZE_CFLAGS for S-records.  Also add
-+# $DIRECT_EXTERN_ACCESS_CFLAGS.
- set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
--append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
-+append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS"
- set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
--append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
-+append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS"
- 
- # S-records can't handle .note.gnu.property sections.
- if { [is_elf_format] \
-diff --git a/ld/testsuite/ld-vsb/vsb.exp b/ld/testsuite/ld-vsb/vsb.exp
-index 84ae1edc95c..8eff759327e 100644
---- a/ld/testsuite/ld-vsb/vsb.exp
-+++ b/ld/testsuite/ld-vsb/vsb.exp
-@@ -50,6 +50,13 @@ if { ![istarget hppa*64*-*-hpux*] \
-     return
- }
- 
-+set need_direct_extern_access ""
-+if { [istarget i?86-*-linux*]
-+     || [istarget i?86-*-gnu*] } then {
-+    # These targets need direct extern access in some tests.
-+    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
-+}
-+
- if [is_xcoff_format] {
-     set test_list [lsort [glob -nocomplain $srcdir/$subdir/*-xcoff*.d]]
- } else {
-@@ -238,6 +245,7 @@ proc visibility_run {visibility} {
-     global COMPRESS_LDFLAG
-     global NOSANITIZE_CFLAGS
-     global NOLTO_CFLAGS
-+    global need_direct_extern_access
- 
-     if [ string match $visibility "hidden" ] {
- 	set VSBCFLAG "-DHIDDEN_TEST"
-@@ -284,7 +292,7 @@ proc visibility_run {visibility} {
-     } else {
-     # Compile the main program.  Make sure that PLT is used since PLT
-     # is expected.
--    if ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
-+    if ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
- 	unsupported "visibility ($visibility) (non PIC)"
- 	unsupported "visibility ($visibility)"
-     } else {
-@@ -294,8 +302,8 @@ proc visibility_run {visibility} {
- 	# will need to do more relocation work.  However, note that not
- 	# using -fpic will cause some of the tests to return different
- 	# results.  Make sure that PLT is used since PLT is expected.
--	if { ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
--	     || ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
-+	if { ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
-+	     || ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
- 	    unsupported "visibility ($visibility) (non PIC)"
- 	} else {
- 	    # SunOS non PIC shared libraries don't permit some cases of
-diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index a72a7da12c1..9d975319cf5 100644
---- a/ld/testsuite/ld-x86-64/x86-64.exp
-+++ b/ld/testsuite/ld-x86-64/x86-64.exp
-@@ -1007,7 +1007,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build pr17689.so" \
- 	    "-shared" \
--	    "-fPIC -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
- 	    { pr17689a.c } \
- 	    {} \
- 	    "pr17689.so" \
-@@ -1015,7 +1015,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build pr17689now.so with -z now" \
- 	    "-shared -Wl,-z,now" \
--	    "-fPIC -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
- 	    { pr17689a.c } \
- 	    {{readelf {-Wr} pr17689now.rd}} \
- 	    "pr17689now.so" \
-@@ -1023,30 +1023,30 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build pr17689b.o" \
- 	    "" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr17689b.S } \
- 	    {} \
- 	] \
- 	[list \
- 	    "Build pr17689 with PIE without -fPIE" \
--	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,noindirect-extern-access" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    {{readelf {-Wr} pr17689.rd}} \
- 	    "pr17689" \
- 	] \
- 	[list \
- 	    "Build pr17689 with PIE -z now without -fPIE" \
--	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now -Wl,-z,noindirect-extern-access" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    {{readelf {-Wr} pr17689now.rd}} \
- 	    "pr17689now" \
- 	] \
- 	[list \
- 	    "Build pr17827 with PIE without -fPIE" \
--	    "-Wl,--as-needed tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "-Wl,--as-needed tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,noindirect-extern-access" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    {{readelf {-Wr} pr17827.rd}} \
- 	    "pr17827" \
-@@ -1151,7 +1151,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build property 1 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-no-copy.S} \
- 	    {{readelf {-n} property-1a.r}} \
- 	    "property-1.o" \
-@@ -1175,7 +1175,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build property 2 (.o)" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {pass.c property-stack.S} \
- 	    {{readelf {-n} property-2a.r}} \
- 	    "property-2.o" \
-@@ -1199,7 +1199,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build property-6.o" \
- 	    "-r -nostdlib" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    {property-6b.c property-stack.S} \
- 	    {{readelf {-n} property-2a.r}} \
- 	    "property-6.o" \
-@@ -1230,16 +1230,16 @@ if { [isnative] && [check_compiler_available] } {
- 	] \
- 	[list \
- 	    "Build pr22001-1.so" \
--	    "-shared" \
--	    "-fPIC -Wa,-mx86-used-note=yes" \
-+	    "-shared -Wl,-z,noindirect-extern-access" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1a.c } \
- 	    {} \
- 	    "pr22001-1.so" \
- 	] \
- 	[list \
- 	    "Build pr22001-1a" \
--	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext,-z,noindirect-extern-access tmpdir/pr22001-1.so" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1b.c } \
- 	    {{error_output "pr22001-1a.err"}} \
- 	    "pr22001-1a" \
-@@ -1247,7 +1247,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build pr21997-1.so" \
- 	    "-shared" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { property-stack.S property-no-copy.S pr21997-1a.S } \
- 	    {} \
- 	    "pr21997-1.so" \
-@@ -1255,7 +1255,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build pr21997-1a" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr21997-1b.c } \
- 	    {{error_output "pr21997-1a.err"}} \
- 	    "pr21997-1a" \
-@@ -1401,7 +1401,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build protected-func-2 without PIE" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-func-2b.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { protected-func-1b.c } \
- 	    {{error_output "pr28875-func.err"}} \
- 	    "protected-func-2" \
-@@ -1417,7 +1417,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build protected-func-2a without PIE" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-func-2c.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { protected-func-1b.c } \
- 	    {{error_output "pr28875-func.err"}} \
- 	    "protected-func-2a" \
-@@ -1441,7 +1441,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Build protected-data-1 without PIE" \
- 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-data-1b.so" \
--	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { protected-data-1b.c } \
- 	    {{error_output "pr28875-data.err"}} \
- 	    "protected-data-1" \
-@@ -1535,7 +1535,7 @@ if { [isnative] && [check_compiler_available] } {
- 		{ pr22001-1c.c } \
- 		"pr22001-1b" \
- 		"pass.out" \
--		"$NOPIE_CFLAGS" \
-+		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS" \
- 	    ] \
- 	    [list \
- 		"Run pr25416-5a (GDesc -> IE -maddress-mode=short)" \
-@@ -1603,8 +1603,8 @@ if { [isnative] && [check_compiler_available] } {
- 	run_cc_link_tests [list \
- 	    [list \
- 		"Build pr22001-1b" \
--		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
--		"$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext,-z,noindirect-extern-access tmpdir/pr22001-1.so" \
-+		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 		{ pr22001-1c.c } \
- 		{{error_output "pr22001-1b.err"}} \
- 		"pr22001-1b" \
-@@ -1612,14 +1612,14 @@ if { [isnative] && [check_compiler_available] } {
- 	    [list \
- 		"Build pr21997-1b" \
- 		"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
--		"$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
-+		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
- 		{ pr21997-1c.c } \
- 		{{error_output "pr21997-1b.err"}} \
- 		"pr21997-1b" \
- 	    ] \
- 	    [list \
- 		"Build lam-u48.so" \
--		"-shared -Wl,-z,lam-u48" \
-+		"-shared -Wl,-z,lam-u48,-z,noindirect-extern-access" \
- 		"" \
- 		{dummy.s} \
- 		{{readelf -n lam-u48.rd}}  \
-@@ -1627,7 +1627,7 @@ if { [isnative] && [check_compiler_available] } {
- 	    ] \
- 	    [list \
- 		"Build lam-u57.so" \
--		"-shared -Wl,-z,lam-u57" \
-+		"-shared -Wl,-z,lam-u57,-z,noindirect-extern-access" \
- 		"" \
- 		{dummy.s} \
- 		{{readelf -n lam-u57.rd}}  \
-@@ -1659,23 +1659,23 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Run copyreloc-main with PIE without -fPIE" \
- 	    "-Wl,--as-needed -pie tmpdir/copyreloc-main.o tmpdir/copyreloc-lib.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    "copyreloc-main" \
- 	    "copyreloc-main.out" \
- 	] \
- 	[list \
- 	    "Run pr17689 with PIE without -fPIE" \
--	    "-Wl,--no-as-needed -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "-Wl,--no-as-needed,-z,noindirect-extern-access -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    "pr17689" \
- 	    "pr17689.out" \
- 	] \
- 	[list \
- 	    "Run pr17689 with PIE -z now without -fPIE" \
--	    "-Wl,--as-needed,-z,now -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "-Wl,--as-needed,-z,now,-z,noindirect-extern-access -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { dummy.s } \
- 	    "pr17689now" \
- 	    "pr17689.out" \
-@@ -1750,25 +1750,25 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Run pr22001-1a (PIC 1)" \
- 	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1b.c } \
- 	    "pr22001-1a-pic-1" \
- 	    "pass.out" \
--	    "-fPIC" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC" \
- 	] \
- 	[list \
- 	    "Run pr22001-1a (PIC 2)" \
- 	    "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1b.c } \
- 	    "pr22001-1a-pic-2" \
- 	    "pass.out" \
--	    "-fPIC" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC" \
- 	] \
- 	[list \
- 	    "Run pr22001-1b (PIC 1)" \
- 	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1c.c } \
- 	    "pr22001-1b-pic-1" \
- 	    "pass.out" \
-@@ -1777,7 +1777,7 @@ if { [isnative] && [check_compiler_available] } {
- 	[list \
- 	    "Run pr22001-1b (PIC 2)" \
- 	    "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
--	    "-Wa,-mx86-used-note=yes" \
-+	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
- 	    { pr22001-1c.c } \
- 	    "pr22001-1b-pic-2" \
- 	    "pass.out" \
-@@ -2196,7 +2196,7 @@ if { [isnative] && [check_compiler_available] } {
- 	}
-     }
- 
--    undefined_weak "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS"
-+    undefined_weak "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS" "$NOPIE_LDFLAGS"
-     undefined_weak "-fPIE" "$NOPIE_LDFLAGS"
-     undefined_weak "-fPIE" "-pie"
-     undefined_weak "-fPIE" "$NOPIE_LDFLAGS -Wl,-z,nodynamic-undefined-weak"
-
-base-commit: 4f68e8167e9a24903d88bc52892479a28ffaaabe
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-20  4:39 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-20  4:39 UTC (permalink / raw
  To: gentoo-commits

commit:     95ade38b3a37d033fb53b837e85c0c3f17a6559d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 04:39:11 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 04:39:11 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=95ade38b

9999: cloudabi is gone

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
index 4c33ef0..b459a36 100644
--- a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
+++ b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
@@ -120,7 +120,6 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/emulparams/elf_i386_fbsd.sh        |   1 +
  ld/emulparams/elf_i386_haiku.sh       |   1 +
  ld/emulparams/elf_x86_64.sh           |   2 +-
- ld/emulparams/elf_x86_64_cloudabi.sh  |   1 +
  ld/emulparams/elf_x86_64_fbsd.sh      |   1 +
  ld/emulparams/elf_x86_64_haiku.sh     |   1 +
  ld/emultempl/elf-i386-glibc.em        |  41 ++++++++
@@ -337,15 +336,6 @@ index b6fd466178e..1edce6e8703 100644
  }
  
  static const struct bfd_elf_special_section
-@@ -6355,6 +6373,8 @@ elf_x86_64_special_sections[]=
- 
- #include "elf64-target.h"
- 
-+#undef elf_backend_add_glibc_version_dependency
-+
- /* CloudABI support.  */
- 
- #undef	TARGET_LITTLE_SYM
 @@ -6479,6 +6499,10 @@ elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUS
  #define elf_backend_bfd_from_remote_memory \
    _bfd_elf32_bfd_from_remote_memory
@@ -776,14 +766,6 @@ index 92449745c7a..6e66f2e1035 100644
  GENERATE_SHLIB_SCRIPT=yes
  GENERATE_PIE_SCRIPT=yes
  NO_SMALL_DATA=yes
-diff --git a/ld/emulparams/elf_x86_64_cloudabi.sh b/ld/emulparams/elf_x86_64_cloudabi.sh
-index 1f8732ebbad..e605233391b 100644
---- a/ld/emulparams/elf_x86_64_cloudabi.sh
-+++ b/ld/emulparams/elf_x86_64_cloudabi.sh
-@@ -1,2 +1,3 @@
- source_sh ${srcdir}/emulparams/elf_x86_64.sh
-+EXTRA_EM_FILE="elf-x86-64"
- OUTPUT_FORMAT="elf64-x86-64-cloudabi"
 diff --git a/ld/emulparams/elf_x86_64_fbsd.sh b/ld/emulparams/elf_x86_64_fbsd.sh
 index 7ef974addca..17fdc83b075 100644
 --- a/ld/emulparams/elf_x86_64_fbsd.sh


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-19 20:54 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-19 20:54 UTC (permalink / raw
  To: gentoo-commits

commit:     07f1295681d48567dfc62dd15593cf57d4b240e5
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 20:53:44 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 20:54:26 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=07f12956

9999: refresh patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch | 56 ++++++++++++----------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
index 63b7fa1..4c33ef0 100644
--- a/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
+++ b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
@@ -1,8 +1,7 @@
-From 40fd19259a3b9a576bedba9f9ce236d2f1b42da9 Mon Sep 17 00:00:00 2001
-Message-ID: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
+From b6b200c936241a908de6d0c9e8c13db8cf16a31f Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 18 Aug 2025 13:13:20 -0700
-Subject: [PATCH 1/3] x86: Add GLIBC_ABI_GNU2_TLS version dependency
+Date: Fri, 4 Jul 2025 08:39:03 +0800
+Subject: [PATCH] x86: Add GLIBC_ABI_GNU2_TLS version dependency
 
 On Linux/x86, programs and shared libraries compiled with
 -mtls-dialect=gnu2 may fail silently at run-time against glibc without
@@ -46,6 +45,8 @@ bfd/
 	(elf_x86_64_add_glibc_version_dependency): Add GLIBC_ABI_GNU2_TLS
 	version dependency if GLIBC_ABI_GNU2_TLS dependency isn't disabled
 	and has_tlsdesc_call isn't 0.
+	(elf_backend_add_glibc_version_dependency): Undef before CloudABI
+	support and redefine for elf32-x86-64.
 	* elflink.c (elf_link_add_glibc_verneed): Changed to return bool.
 	Remove the pointer to elf_find_verdep_info argument.  Add a
 	pointer to bool argument, auto_version. Return true if linked
@@ -56,8 +57,6 @@ bfd/
 	bool argument and pass it to elf_link_add_glibc_verneed.
 	(_bfd_elf_link_add_dt_relr_dependency): Pass NULL to
 	_bfd_elf_link_add_glibc_version_dependency.
-	(elf_backend_add_glibc_version_dependency): Undef before CloudABI
-	support.
 	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_desc_call.
 
 ld/
@@ -109,7 +108,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  bfd/elf-bfd.h                         |   2 +-
  bfd/elf-linker-x86.h                  |   8 ++
  bfd/elf32-i386.c                      |  44 ++++++++-
- bfd/elf64-x86-64.c                    |  32 +++++--
+ bfd/elf64-x86-64.c                    |  36 +++++--
  bfd/elflink.c                         | 130 +++++++++++++++-----------
  bfd/elfxx-x86.h                       |   4 +
  ld/NEWS                               |   6 ++
@@ -142,7 +141,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/testsuite/ld-x86-64/mark-plt-2.rd  |   7 ++
  ld/testsuite/ld-x86-64/mark-plt-2.s   |  13 +++
  ld/testsuite/ld-x86-64/x86-64.exp     |  26 +++++-
- 36 files changed, 592 insertions(+), 125 deletions(-)
+ 36 files changed, 596 insertions(+), 125 deletions(-)
  create mode 100644 ld/emultempl/elf-i386-glibc.em
  create mode 100644 ld/emultempl/elf-x86-64-glibc.em
  create mode 100644 ld/emultempl/elf-x86-64.em
@@ -190,7 +189,7 @@ index 2c98257038f..fe322152e14 100644
    unsigned int isa_level;
  
 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
-index abe26e476ff..c1115a52d1b 100644
+index b755b39ab55..9d06f1494cf 100644
 --- a/bfd/elf32-i386.c
 +++ b/bfd/elf32-i386.c
 @@ -1687,6 +1687,10 @@ elf_i386_scan_relocs (bfd *abfd,
@@ -273,7 +272,7 @@ index abe26e476ff..c1115a52d1b 100644
  
  #undef	TARGET_LITTLE_SYM
 diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index b6f97b5b69b..edfa608d2d7 100644
+index b6fd466178e..1edce6e8703 100644
 --- a/bfd/elf64-x86-64.c
 +++ b/bfd/elf64-x86-64.c
 @@ -2694,6 +2694,10 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
@@ -347,11 +346,22 @@ index b6f97b5b69b..edfa608d2d7 100644
  /* CloudABI support.  */
  
  #undef	TARGET_LITTLE_SYM
+@@ -6479,6 +6499,10 @@ elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUS
+ #define elf_backend_bfd_from_remote_memory \
+   _bfd_elf32_bfd_from_remote_memory
+ 
++#undef elf_backend_add_glibc_version_dependency
++#define elf_backend_add_glibc_version_dependency \
++  elf_x86_64_add_glibc_version_dependency
++
+ #undef elf_backend_size_info
+ #define elf_backend_size_info \
+   _bfd_elf32_size_info
 diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 7b0375406ac..ac40423751f 100644
+index f6c0c04e82e..d2c43f31bf5 100644
 --- a/bfd/elflink.c
 +++ b/bfd/elflink.c
-@@ -2283,68 +2283,85 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
+@@ -2281,68 +2281,85 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
    return true;
  }
  \f
@@ -480,7 +490,7 @@ index 7b0375406ac..ac40423751f 100644
      }
  
    /* Skip if 2.GLIBC_MINOR_BASE includes VERSION_DEP.  */
-@@ -2352,7 +2369,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+@@ -2350,7 +2367,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
      {
        minor_version = strtol (version_dep + 8, NULL, 10);
        if (minor_version <= *glibc_minor_base)
@@ -489,7 +499,7 @@ index 7b0375406ac..ac40423751f 100644
      }
  
    amt = sizeof *a;
-@@ -2360,7 +2377,8 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+@@ -2358,7 +2375,8 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
    if (a == NULL)
      {
        rinfo->failed = true;
@@ -499,7 +509,7 @@ index 7b0375406ac..ac40423751f 100644
      }
  
    a->vna_nodename = version_dep;
-@@ -2371,7 +2389,13 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+@@ -2369,7 +2387,13 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
  
    t->vn_auxptr = a;
  
@@ -514,7 +524,7 @@ index 7b0375406ac..ac40423751f 100644
  }
  
  /* Add VERSION_DEP to the list of version dependencies when linked
-@@ -2380,19 +2404,19 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+@@ -2378,19 +2402,19 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
  void
  _bfd_elf_link_add_glibc_version_dependency
    (struct elf_find_verdep_info *rinfo,
@@ -540,7 +550,7 @@ index 7b0375406ac..ac40423751f 100644
      }
    while (*version_dep != NULL);
  }
-@@ -2410,7 +2434,7 @@ _bfd_elf_link_add_dt_relr_dependency (struct elf_find_verdep_info *rinfo)
+@@ -2408,7 +2432,7 @@ _bfd_elf_link_add_dt_relr_dependency (struct elf_find_verdep_info *rinfo)
  	  "GLIBC_ABI_DT_RELR",
  	  NULL
  	};
@@ -1153,10 +1163,10 @@ index 413335ad765..0e13f7d8e35 100644
  @cindex groups of archives
  @item -( @var{archives} -)
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 815da76a4c0..286ab0ba6d1 100644
+index d0c2e5d6db8..020712df0e7 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
-@@ -471,6 +471,9 @@ enum option_values
+@@ -469,6 +469,9 @@ enum option_values
    OPTION_NO_LITERAL_MOVEMENT,
    OPTION_ABI_WINDOWED,
    OPTION_ABI_CALL0,
@@ -1313,10 +1323,10 @@ index 00000000000..c816567c204
 +	ret
 +	.section	.note.GNU-stack,"",@progbits
 diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index 6b86bc3d018..1b011451bcc 100644
+index a72a7da12c1..25480f70185 100644
 --- a/ld/testsuite/ld-x86-64/x86-64.exp
 +++ b/ld/testsuite/ld-x86-64/x86-64.exp
-@@ -2358,7 +2358,7 @@ run_dump_test "ibt-plt-3b-x32"
+@@ -2360,7 +2360,7 @@ run_dump_test "ibt-plt-3b-x32"
  run_dump_test "ibt-plt-3c-x32"
  run_dump_test "ibt-plt-3d-x32"
  
@@ -1325,7 +1335,7 @@ index 6b86bc3d018..1b011451bcc 100644
  if { [istarget "x86_64-*-musl*"]} {
      set ASFLAGS "$saved_ASFLAGS"
      return
-@@ -2384,6 +2384,30 @@ if { [check_compiler_available] } {
+@@ -2386,6 +2386,30 @@ if { [check_compiler_available] } {
  	     {readelf {-W --version-info} mark-plt-1b.rd}} \
  	    "mark-plt-1.so" \
  	] \
@@ -1356,8 +1366,6 @@ index 6b86bc3d018..1b011451bcc 100644
      ]
  }
  
-
-base-commit: b6ebe65cdac1afc15d5459318007be2d1d8832d0
 -- 
 2.50.1
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-19 17:11 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-19 17:11 UTC (permalink / raw
  To: gentoo-commits

commit:     f295987f6a0da443424f2d5d30071d6363c88927
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 17:10:31 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 17:10:31 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f295987f

9999: fix tests with -mno-direct-extern-access

Bug: https://sourceware.org/PR33267
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...ile-some-tests-with-mdirect-extern-access.patch | 708 +++++++++++++++++++++
 1 file changed, 708 insertions(+)

diff --git a/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch b/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch
new file mode 100644
index 0000000..94449be
--- /dev/null
+++ b/9999/0010-ld-Compile-some-tests-with-mdirect-extern-access.patch
@@ -0,0 +1,708 @@
+From 9d753e17740040d4d063bbbdd1e2df6346805cd8 Mon Sep 17 00:00:00 2001
+Message-ID: <9d753e17740040d4d063bbbdd1e2df6346805cd8.1755623414.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 19 Aug 2025 04:59:10 -0700
+Subject: [PATCH] ld: Compile some tests with -mdirect-extern-access
+
+When GCC enables -mno-direct-extern-access by default, some tests fail
+without -mdirect-extern-access.  Define DIRECT_EXTERN_ACCESS_CFLAGS
+to compile these tests with -mdirect-extern-access.  Also pass
+"-z noindirect-extern-access" to linker to support the C library
+compiled with -mno-direct-extern-access.
+
+	PR ld/33267
+	* testsuite/config/default.exp (DIRECT_EXTERN_ACCESS_CFLAGS): New.
+	* testsuite/ld-elf/linux-x86.exp: Compile some tests with
+	$DIRECT_EXTERN_ACCESS_CFLAGS.
+	* testsuite/ld-elfvers/vers.exp (need_direct_extern_access): New
+	for i?86.
+	Compile tests with $need_direct_extern_access.
+	* testsuite/ld-i386/i386.exp: Compile some tests with
+	$DIRECT_EXTERN_ACCESS_CFLAGS.
+	* testsuite/ld-ifunc/ifunc.exp (need_direct_extern_access): New
+	for i?86.
+	Compile tests with $need_direct_extern_access.
+	* testsuite/ld-shared/shared.exp (need_direct_extern_access): New
+	for i?86.
+	Compile tests with $need_direct_extern_access.
+	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET_TEST): Add
+	$DIRECT_EXTERN_ACCESS_CFLAGS.
+	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
+	* testsuite/ld-vsb/vsb.exp (need_direct_extern_access): New
+	for i?86.
+	Compile tests with $need_direct_extern_access.
+	* testsuite/ld-x86-64/x86-64.exp: Compile some tests with
+	$DIRECT_EXTERN_ACCESS_CFLAGS and link some tests with
+	"-Wl,-z,noindirect-extern-access".
+
+Co-Authored-By: Sam James <sam@gentoo.org>
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+Signed-off-by: Sam James <sam@gentoo.org>
+---
+ ld/testsuite/config/default.exp   |  9 ++++
+ ld/testsuite/ld-elf/linux-x86.exp | 14 +++---
+ ld/testsuite/ld-elfvers/vers.exp  | 10 +++-
+ ld/testsuite/ld-i386/i386.exp     | 31 ++++++------
+ ld/testsuite/ld-ifunc/ifunc.exp   |  9 ++++
+ ld/testsuite/ld-shared/shared.exp | 11 ++++-
+ ld/testsuite/ld-srec/srec.exp     |  7 +--
+ ld/testsuite/ld-vsb/vsb.exp       | 14 ++++--
+ ld/testsuite/ld-x86-64/x86-64.exp | 78 +++++++++++++++----------------
+ 9 files changed, 114 insertions(+), 69 deletions(-)
+
+diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
+index 9f286831e07..3619f523762 100644
+--- a/ld/testsuite/config/default.exp
++++ b/ld/testsuite/config/default.exp
+@@ -456,6 +456,15 @@ if { ![info exists NOPIE_CFLAGS] || ![info exists NOPIE_LDFLAGS] } then {
+     }
+ }
+ 
++if { ![info exists DIRECT_EXTERN_ACCESS_CFLAGS] } then {
++    set DIRECT_EXTERN_ACCESS_CFLAGS ""
++    if [compiler_supports "-mdirect-extern-access"] {
++	set DIRECT_EXTERN_ACCESS_CFLAGS "-mdirect-extern-access"
++    } elseif [compiler_supports "-fdirect-access-external-data"] {
++	set DIRECT_EXTERN_ACCESS_CFLAGS "-fdirect-access-external-data"
++    }
++}
++
+ if { ![info exists NOCF_PROTECTION_CFLAGS] } then {
+     set NOCF_PROTECTION_CFLAGS ""
+     if [compiler_supports "-fcf-protection=none"] {
+diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
+index 27173b916da..a4dfc8ad394 100644
+--- a/ld/testsuite/ld-elf/linux-x86.exp
++++ b/ld/testsuite/ld-elf/linux-x86.exp
+@@ -84,9 +84,9 @@ run_cc_link_tests [list \
+     ] \
+     [list \
+ 	"Build indirect-extern-access-1a without PIE" \
+-	"$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
++	"$NOPIE_LDFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wl,--no-as-needed -z noexecstack \
+ 	 tmpdir/indirect-extern-access-1.so" \
+-	"$NOPIE_CFLAGS" \
++	"$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	{ indirect-extern-access.S indirect-extern-access-1b.c } \
+ 	{{readelf -rn indirect-extern-access-1.rd}} \
+ 	"indirect-extern-access-1a" \
+@@ -101,9 +101,9 @@ run_cc_link_tests [list \
+     ] \
+     [list \
+ 	"Build indirect-extern-access-2a without PIE" \
+-	"$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
++	"$NOPIE_LDFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wl,--no-as-needed -z noexecstack \
+ 	 tmpdir/indirect-extern-access-2.so" \
+-	"$NOPIE_CFLAGS" \
++	"$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	{ indirect-extern-access.S indirect-extern-access-1b.c } \
+ 	{{readelf -rn indirect-extern-access-2.rd}} \
+ 	"indirect-extern-access-2a" \
+@@ -375,11 +375,11 @@ proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
+ 
+ check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
+ check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
+-check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
++check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" "$NOPIE_LDFLAGS" ""
+ if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
+-    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
++    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE $DIRECT_EXTERN_ACCESS_CFLAGS" "-pie" ""
+ } else {
+-    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
++    check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE $DIRECT_EXTERN_ACCESS_CFLAGS" "-pie" "pr25749-1b.err"
+ }
+ check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
+ check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
+diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
+index 4f59e0c174b..80faaa01079 100644
+--- a/ld/testsuite/ld-elfvers/vers.exp
++++ b/ld/testsuite/ld-elfvers/vers.exp
+@@ -60,6 +60,13 @@ if { ![istarget *-*-solaris2*]
+     return
+ }
+ 
++set need_direct_extern_access ""
++if { [istarget i?86-*-linux*]
++     || [istarget i?86-*-gnu*] } then {
++    # These targets need direct extern access in some tests.
++    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
++}
++
+ set diff diff
+ set tmpdir tmpdir
+ set VOBJDUMP_FLAGS --private-headers
+@@ -558,7 +565,8 @@ proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp
+   global shared
+   # Make sure that PLT is used since PLT is expected.
+   global PLT_CFLAGS
+-  build_binary "$shared -z notext" $PLT_CFLAGS $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
++  global need_direct_extern_access
++  build_binary "$shared -z notext" "$PLT_CFLAGS $need_direct_extern_access" $test $source $libname $other $mapfile $verexp $versymexp $symexp ""
+ }
+ 
+ proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
+diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
+index 86748b1a494..8633a663ec0 100644
+--- a/ld/testsuite/ld-i386/i386.exp
++++ b/ld/testsuite/ld-i386/i386.exp
+@@ -712,7 +712,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17689.so" \
+ 	    "-shared" \
+-	    "-fPIC -Wa,-mrelax-relocations=yes" \
++	    "-fPIC $DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { pr17689a.c } \
+ 	    {} \
+ 	    "pr17689.so" \
+@@ -736,7 +736,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17689.a" \
+ 	    "" \
+-	    "-Wa,-mrelax-relocations=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { pr17689b.S } \
+ 	    {} \
+ 	    "pr17689.a" \
+@@ -744,7 +744,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17689 with PIE and GOTOFF" \
+ 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
+-	    "-Wa,-mrelax-relocations=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { dummy.c } \
+ 	    {{readelf {-Wr} pr17689.rd}} \
+ 	    "pr17689" \
+@@ -752,7 +752,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17689 with PIE, -z now and GOTOFF" \
+ 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
+-	    "-Wa,-mrelax-relocations=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { dummy.c } \
+ 	    {{readelf {-Wr} pr17689now.rd}} \
+ 	    "pr17689now" \
+@@ -760,7 +760,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17689ver with PIE and GOTOFF" \
+ 	    "tmpdir/pr17689b.o tmpdir/pr17689ver.so -pie" \
+-	    "-Wa,-mrelax-relocations=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { dummy.c } \
+ 	    {{readelf {-Wr} pr17689ver.rd}} \
+ 	    "pr17689ver" \
+@@ -768,7 +768,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr17827 with PIE and GOTOFF" \
+ 	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
+-	    "-Wa,-mrelax-relocations=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mrelax-relocations=yes" \
+ 	    { dummy.c } \
+ 	    {{readelf {-Wr} pr17827.rd}} \
+ 	    "pr17827" \
+@@ -874,7 +874,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property 1 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-no-copy.S} \
+ 	    {{readelf {-n} property-1a.r}} \
+ 	    "property-1.o" \
+@@ -898,7 +898,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property 2 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-stack.S} \
+ 	    {{readelf {-n} property-2a.r}} \
+ 	    "property-2.o" \
+@@ -922,7 +922,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property 3 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-x86-1.S property-stack.S} \
+ 	    {{readelf {-n} property-3a.r}} \
+ 	    "property-3.o" \
+@@ -946,7 +946,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property 4 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ 	    {{readelf {-n} property-4a.r}} \
+ 	    "property-4.o" \
+@@ -978,7 +978,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property 5 (.o)" \
+ 	    "-r -nostdlib -Wl,-z,stack-size=0x900000" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-x86-2.S property-x86-1.S property-stack.S} \
+ 	    {{readelf {-n} property-5a.r}} \
+ 	    "property-5.o" \
+@@ -1002,7 +1002,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build property-6.o" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {property-6b.c property-stack.S} \
+ 	    {{readelf {-n} property-2a.r}} \
+ 	    "property-6.o" \
+@@ -1069,6 +1069,7 @@ if { [isnative]
+ 	    { dummy.c } \
+ 	    "pr17689" \
+ 	    "pr17689.out" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	] \
+ 	[list \
+ 	    "Run pr17689 with PIE, -z now and GOTOFF" \
+@@ -1077,6 +1078,7 @@ if { [isnative]
+ 	    { dummy.c } \
+ 	    "pr17689now" \
+ 	    "pr17689.out" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	] \
+ 	[list \
+ 	    "Run pr17689ver with PIE and GOTOFF" \
+@@ -1085,6 +1087,7 @@ if { [isnative]
+ 	    { dummy.c } \
+ 	    "pr17689ver" \
+ 	    "pr17689.out" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	] \
+ 	[list \
+ 	    "Run pr18900" \
+@@ -1320,7 +1323,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr28875" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr28875.so" \
+-	    "$NOPIE_CFLAGS" \
++	    "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS" \
+ 	    { pr28875b.c } \
+ 	    {{error_output "pr28875.err"}} \
+ 	    "pr28875" \
+@@ -1328,7 +1331,7 @@ if { [isnative]
+ 	[list \
+ 	    "Build pr21997-1" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$NOPIE_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr21997-1b.c } \
+ 	    {{error_output "pr21997-1.err"}} \
+ 	    "pr21997-1" \
+diff --git a/ld/testsuite/ld-ifunc/ifunc.exp b/ld/testsuite/ld-ifunc/ifunc.exp
+index e8b93b347ef..07a8a2f2bcc 100644
+--- a/ld/testsuite/ld-ifunc/ifunc.exp
++++ b/ld/testsuite/ld-ifunc/ifunc.exp
+@@ -54,6 +54,13 @@ if ![check_shared_lib_support] {
+     return
+ }
+ 
++set need_direct_extern_access ""
++if { [istarget i?86-*-linux*]
++     || [istarget i?86-*-gnu*] } then {
++    # These targets need direct extern access in some tests.
++    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
++}
++
+ set saved_ASFLAGS "$ASFLAGS"
+ if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
+     set ASFLAGS "$ASFLAGS -mx86-used-note=no"
+@@ -497,6 +504,7 @@ if { [check_ifunc_available] } {
+ 	    { ifunc-main.c } \
+ 	    "ifunc-main" \
+ 	    "ifunc-main.out" \
++	    "$need_direct_extern_access" \
+ 	] \
+ 	[list \
+ 	    "Run ifunc-main with -fpic" \
+@@ -514,6 +522,7 @@ if { [check_ifunc_available] } {
+ 	    { ifunc-main.c } \
+ 	    "ifunc-mainn" \
+ 	    "ifunc-main.out" \
++	    "$need_direct_extern_access" \
+ 	] \
+ 	[list \
+ 	    "Run ifunc-main with PIE (-z now)" \
+diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
+index e7f77fad567..daafee07410 100644
+--- a/ld/testsuite/ld-shared/shared.exp
++++ b/ld/testsuite/ld-shared/shared.exp
+@@ -62,6 +62,13 @@ if { ![istarget hppa*64*-*-hpux*] \
+     return
+ }
+ 
++set need_direct_extern_access ""
++if { [istarget i?86-*-linux*]
++     || [istarget i?86-*-gnu*] } then {
++    # These targets need direct extern access in some tests.
++    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
++}
++
+ set tmpdir tmpdir
+ set SHCFLAG ""
+ set shared_needs_pic "no"
+@@ -217,8 +224,8 @@ if ![ld_compile "$CC_FOR_TARGET $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $
+     # will need to do more relocation work.  However, note that not
+     # using -fpic will cause some of the tests to return different
+     # results.  Make sure that PLT is used since PLT is expected.
+-    if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
+-	 || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
++    if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG $need_direct_extern_access" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
++	 || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG $need_direct_extern_access" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
+ 	unsupported "shared (non PIC)"
+     } else { if { [is_xcoff_format] } {
+ 	shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o xcoff "" $NOPIE_LDFLAGS
+diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
+index 5afc84c24b6..227411a9f8a 100644
+--- a/ld/testsuite/ld-srec/srec.exp
++++ b/ld/testsuite/ld-srec/srec.exp
+@@ -364,11 +364,12 @@ if { ![check_compiler_available] } {
+ # Pass -fplt to CC and CXX since -fno-plt doesn't work with S-records
+ # tests. Also add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if PIE doesn't work
+ # with S-records.  Also add $NOCF_PROTECTION_CFLAGS for S-records.
+-# Also add $NOSANITIZE_CFLAGS for S-records.
++# Also add $NOSANITIZE_CFLAGS for S-records.  Also add
++# $DIRECT_EXTERN_ACCESS_CFLAGS.
+ set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
+-append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
++append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS"
+ set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
+-append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
++append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $DIRECT_EXTERN_ACCESS_CFLAGS"
+ 
+ # S-records can't handle .note.gnu.property sections.
+ if { [is_elf_format] \
+diff --git a/ld/testsuite/ld-vsb/vsb.exp b/ld/testsuite/ld-vsb/vsb.exp
+index 84ae1edc95c..8eff759327e 100644
+--- a/ld/testsuite/ld-vsb/vsb.exp
++++ b/ld/testsuite/ld-vsb/vsb.exp
+@@ -50,6 +50,13 @@ if { ![istarget hppa*64*-*-hpux*] \
+     return
+ }
+ 
++set need_direct_extern_access ""
++if { [istarget i?86-*-linux*]
++     || [istarget i?86-*-gnu*] } then {
++    # These targets need direct extern access in some tests.
++    set need_direct_extern_access "$DIRECT_EXTERN_ACCESS_CFLAGS"
++}
++
+ if [is_xcoff_format] {
+     set test_list [lsort [glob -nocomplain $srcdir/$subdir/*-xcoff*.d]]
+ } else {
+@@ -238,6 +245,7 @@ proc visibility_run {visibility} {
+     global COMPRESS_LDFLAG
+     global NOSANITIZE_CFLAGS
+     global NOLTO_CFLAGS
++    global need_direct_extern_access
+ 
+     if [ string match $visibility "hidden" ] {
+ 	set VSBCFLAG "-DHIDDEN_TEST"
+@@ -284,7 +292,7 @@ proc visibility_run {visibility} {
+     } else {
+     # Compile the main program.  Make sure that PLT is used since PLT
+     # is expected.
+-    if ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
++    if ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
+ 	unsupported "visibility ($visibility) (non PIC)"
+ 	unsupported "visibility ($visibility)"
+     } else {
+@@ -294,8 +302,8 @@ proc visibility_run {visibility} {
+ 	# will need to do more relocation work.  However, note that not
+ 	# using -fpic will cause some of the tests to return different
+ 	# results.  Make sure that PLT is used since PLT is expected.
+-	if { ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
+-	     || ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
++	if { ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
++	     || ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS $need_direct_extern_access" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
+ 	    unsupported "visibility ($visibility) (non PIC)"
+ 	} else {
+ 	    # SunOS non PIC shared libraries don't permit some cases of
+diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
+index a72a7da12c1..9d975319cf5 100644
+--- a/ld/testsuite/ld-x86-64/x86-64.exp
++++ b/ld/testsuite/ld-x86-64/x86-64.exp
+@@ -1007,7 +1007,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build pr17689.so" \
+ 	    "-shared" \
+-	    "-fPIC -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
+ 	    { pr17689a.c } \
+ 	    {} \
+ 	    "pr17689.so" \
+@@ -1015,7 +1015,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build pr17689now.so with -z now" \
+ 	    "-shared -Wl,-z,now" \
+-	    "-fPIC -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
+ 	    { pr17689a.c } \
+ 	    {{readelf {-Wr} pr17689now.rd}} \
+ 	    "pr17689now.so" \
+@@ -1023,30 +1023,30 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build pr17689b.o" \
+ 	    "" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr17689b.S } \
+ 	    {} \
+ 	] \
+ 	[list \
+ 	    "Build pr17689 with PIE without -fPIE" \
+-	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,noindirect-extern-access" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    {{readelf {-Wr} pr17689.rd}} \
+ 	    "pr17689" \
+ 	] \
+ 	[list \
+ 	    "Build pr17689 with PIE -z now without -fPIE" \
+-	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,now -Wl,-z,noindirect-extern-access" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    {{readelf {-Wr} pr17689now.rd}} \
+ 	    "pr17689now" \
+ 	] \
+ 	[list \
+ 	    "Build pr17827 with PIE without -fPIE" \
+-	    "-Wl,--as-needed tmpdir/pr17689b.o tmpdir/pr17689.so -pie" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "-Wl,--as-needed tmpdir/pr17689b.o tmpdir/pr17689.so -pie -Wl,-z,noindirect-extern-access" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    {{readelf {-Wr} pr17827.rd}} \
+ 	    "pr17827" \
+@@ -1151,7 +1151,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build property 1 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-no-copy.S} \
+ 	    {{readelf {-n} property-1a.r}} \
+ 	    "property-1.o" \
+@@ -1175,7 +1175,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build property 2 (.o)" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {pass.c property-stack.S} \
+ 	    {{readelf {-n} property-2a.r}} \
+ 	    "property-2.o" \
+@@ -1199,7 +1199,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build property-6.o" \
+ 	    "-r -nostdlib" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    {property-6b.c property-stack.S} \
+ 	    {{readelf {-n} property-2a.r}} \
+ 	    "property-6.o" \
+@@ -1230,16 +1230,16 @@ if { [isnative] && [check_compiler_available] } {
+ 	] \
+ 	[list \
+ 	    "Build pr22001-1.so" \
+-	    "-shared" \
+-	    "-fPIC -Wa,-mx86-used-note=yes" \
++	    "-shared -Wl,-z,noindirect-extern-access" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1a.c } \
+ 	    {} \
+ 	    "pr22001-1.so" \
+ 	] \
+ 	[list \
+ 	    "Build pr22001-1a" \
+-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext,-z,noindirect-extern-access tmpdir/pr22001-1.so" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1b.c } \
+ 	    {{error_output "pr22001-1a.err"}} \
+ 	    "pr22001-1a" \
+@@ -1247,7 +1247,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build pr21997-1.so" \
+ 	    "-shared" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { property-stack.S property-no-copy.S pr21997-1a.S } \
+ 	    {} \
+ 	    "pr21997-1.so" \
+@@ -1255,7 +1255,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build pr21997-1a" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr21997-1b.c } \
+ 	    {{error_output "pr21997-1a.err"}} \
+ 	    "pr21997-1a" \
+@@ -1401,7 +1401,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build protected-func-2 without PIE" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-func-2b.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { protected-func-1b.c } \
+ 	    {{error_output "pr28875-func.err"}} \
+ 	    "protected-func-2" \
+@@ -1417,7 +1417,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build protected-func-2a without PIE" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-func-2c.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { protected-func-1b.c } \
+ 	    {{error_output "pr28875-func.err"}} \
+ 	    "protected-func-2a" \
+@@ -1441,7 +1441,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Build protected-data-1 without PIE" \
+ 	    "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libprotected-data-1b.so" \
+-	    "$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { protected-data-1b.c } \
+ 	    {{error_output "pr28875-data.err"}} \
+ 	    "protected-data-1" \
+@@ -1535,7 +1535,7 @@ if { [isnative] && [check_compiler_available] } {
+ 		{ pr22001-1c.c } \
+ 		"pr22001-1b" \
+ 		"pass.out" \
+-		"$NOPIE_CFLAGS" \
++		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS" \
+ 	    ] \
+ 	    [list \
+ 		"Run pr25416-5a (GDesc -> IE -maddress-mode=short)" \
+@@ -1603,8 +1603,8 @@ if { [isnative] && [check_compiler_available] } {
+ 	run_cc_link_tests [list \
+ 	    [list \
+ 		"Build pr22001-1b" \
+-		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext tmpdir/pr22001-1.so" \
+-		"$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed,-z,notext,-z,noindirect-extern-access tmpdir/pr22001-1.so" \
++		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 		{ pr22001-1c.c } \
+ 		{{error_output "pr22001-1b.err"}} \
+ 		"pr22001-1b" \
+@@ -1612,14 +1612,14 @@ if { [isnative] && [check_compiler_available] } {
+ 	    [list \
+ 		"Build pr21997-1b" \
+ 		"$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/pr21997-1.so" \
+-		"$NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
++		"$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS -Wa,-mx86-used-note=yes" \
+ 		{ pr21997-1c.c } \
+ 		{{error_output "pr21997-1b.err"}} \
+ 		"pr21997-1b" \
+ 	    ] \
+ 	    [list \
+ 		"Build lam-u48.so" \
+-		"-shared -Wl,-z,lam-u48" \
++		"-shared -Wl,-z,lam-u48,-z,noindirect-extern-access" \
+ 		"" \
+ 		{dummy.s} \
+ 		{{readelf -n lam-u48.rd}}  \
+@@ -1627,7 +1627,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	    ] \
+ 	    [list \
+ 		"Build lam-u57.so" \
+-		"-shared -Wl,-z,lam-u57" \
++		"-shared -Wl,-z,lam-u57,-z,noindirect-extern-access" \
+ 		"" \
+ 		{dummy.s} \
+ 		{{readelf -n lam-u57.rd}}  \
+@@ -1659,23 +1659,23 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Run copyreloc-main with PIE without -fPIE" \
+ 	    "-Wl,--as-needed -pie tmpdir/copyreloc-main.o tmpdir/copyreloc-lib.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    "copyreloc-main" \
+ 	    "copyreloc-main.out" \
+ 	] \
+ 	[list \
+ 	    "Run pr17689 with PIE without -fPIE" \
+-	    "-Wl,--no-as-needed -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "-Wl,--no-as-needed,-z,noindirect-extern-access -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    "pr17689" \
+ 	    "pr17689.out" \
+ 	] \
+ 	[list \
+ 	    "Run pr17689 with PIE -z now without -fPIE" \
+-	    "-Wl,--as-needed,-z,now -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "-Wl,--as-needed,-z,now,-z,noindirect-extern-access -pie tmpdir/pr17689b.o tmpdir/pr17689.so" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { dummy.s } \
+ 	    "pr17689now" \
+ 	    "pr17689.out" \
+@@ -1750,25 +1750,25 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Run pr22001-1a (PIC 1)" \
+ 	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1b.c } \
+ 	    "pr22001-1a-pic-1" \
+ 	    "pass.out" \
+-	    "-fPIC" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC" \
+ 	] \
+ 	[list \
+ 	    "Run pr22001-1a (PIC 2)" \
+ 	    "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1b.c } \
+ 	    "pr22001-1a-pic-2" \
+ 	    "pass.out" \
+-	    "-fPIC" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -fPIC" \
+ 	] \
+ 	[list \
+ 	    "Run pr22001-1b (PIC 1)" \
+ 	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1c.c } \
+ 	    "pr22001-1b-pic-1" \
+ 	    "pass.out" \
+@@ -1777,7 +1777,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	[list \
+ 	    "Run pr22001-1b (PIC 2)" \
+ 	    "-pie -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+-	    "-Wa,-mx86-used-note=yes" \
++	    "$DIRECT_EXTERN_ACCESS_CFLAGS -Wa,-mx86-used-note=yes" \
+ 	    { pr22001-1c.c } \
+ 	    "pr22001-1b-pic-2" \
+ 	    "pass.out" \
+@@ -2196,7 +2196,7 @@ if { [isnative] && [check_compiler_available] } {
+ 	}
+     }
+ 
+-    undefined_weak "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS"
++    undefined_weak "$DIRECT_EXTERN_ACCESS_CFLAGS $NOPIE_CFLAGS" "$NOPIE_LDFLAGS"
+     undefined_weak "-fPIE" "$NOPIE_LDFLAGS"
+     undefined_weak "-fPIE" "-pie"
+     undefined_weak "-fPIE" "$NOPIE_LDFLAGS -Wl,-z,nodynamic-undefined-weak"
+
+base-commit: 4f68e8167e9a24903d88bc52892479a28ffaaabe
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-19 16:28 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-19 16:28 UTC (permalink / raw
  To: gentoo-commits

commit:     9803ce1d3e6624162ab5c2064eb3198cfca33f2f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 16:28:40 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 16:28:40 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=9803ce1d

9999: drop upstreamed patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0010-elf-Prune-empty-generic-properties.patch | 204 ---------------------
 1 file changed, 204 deletions(-)

diff --git a/9999/0010-elf-Prune-empty-generic-properties.patch b/9999/0010-elf-Prune-empty-generic-properties.patch
deleted file mode 100644
index 598781d..0000000
--- a/9999/0010-elf-Prune-empty-generic-properties.patch
+++ /dev/null
@@ -1,204 +0,0 @@
-From 5179e6a3d41c8e5df76065f24f5eec32e93b4584 Mon Sep 17 00:00:00 2001
-Message-ID: <5179e6a3d41c8e5df76065f24f5eec32e93b4584.1755575227.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 18 Aug 2025 18:37:00 -0700
-Subject: [PATCH] elf: Prune empty generic properties
-
-Prune empty generic properties before discarding empty property note
-section and leave processor specific properties to the backend.
-
-bfd/
-
-	PR ld/33292
-	* elf-properties.c (elf_prune_empty_properties): New function.
-	(_bfd_elf_link_setup_gnu_properties): Call
-	elf_prune_empty_properties before discarding empty property note
-	section.  Move indirect_extern_access processing before
-	elf_prune_empty_properties call.
-
-ld/
-
-	PR ld/33292
-	* testsuite/ld-x86-64/pr33292-x32.d: New file.
-	* testsuite/ld-x86-64/pr33292.d: Likewise.
-	* testsuite/ld-x86-64/pr33292.s: Likewise.
-	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/33292 tests.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elf-properties.c                 | 51 +++++++++++++++++++---------
- ld/testsuite/ld-x86-64/pr33292-x32.d | 10 ++++++
- ld/testsuite/ld-x86-64/pr33292.d     |  9 +++++
- ld/testsuite/ld-x86-64/pr33292.s     | 34 +++++++++++++++++++
- ld/testsuite/ld-x86-64/x86-64.exp    |  2 ++
- 5 files changed, 90 insertions(+), 16 deletions(-)
- create mode 100644 ld/testsuite/ld-x86-64/pr33292-x32.d
- create mode 100644 ld/testsuite/ld-x86-64/pr33292.d
- create mode 100644 ld/testsuite/ld-x86-64/pr33292.s
-
-diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
-index 07ab38098e6..73eb231d861 100644
---- a/bfd/elf-properties.c
-+++ b/bfd/elf-properties.c
-@@ -697,6 +697,23 @@ _bfd_elf_link_create_gnu_property_sec (struct bfd_link_info *info, bfd *elf_bfd,
-   return sec;
- }
- 
-+/* Prune empty generic properties.  */
-+
-+static void
-+elf_prune_empty_properties (elf_property_list **pp)
-+{
-+  elf_property_list *p;
-+
-+  while ((p = *pp) != NULL)
-+    if ((p->property.pr_type < GNU_PROPERTY_LOPROC
-+	 || p->property.pr_type >= GNU_PROPERTY_LOUSER)
-+	&& p->property.pr_datasz != 0
-+	&& p->property.pr_kind == property_number
-+	&& p->property.u.number == 0)
-+      *pp = p->next;
-+    else
-+      pp = &p->next;
-+}
- 
- /* Set up GNU properties.  Return the first relocatable ELF input with
-    GNU properties if found.  Otherwise, return NULL.  */
-@@ -878,22 +895,6 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
-       if (bed->fixup_gnu_properties)
- 	bed->fixup_gnu_properties (info, &elf_properties (first_pbfd));
- 
--      if (elf_properties (first_pbfd) == NULL)
--	{
--	  /* Discard .note.gnu.property section if all properties have
--	     been removed.  */
--	  sec->output_section = bfd_abs_section_ptr;
--	  return NULL;
--	}
--
--      /* Compute the section size.  */
--      list = elf_properties (first_pbfd);
--      size = elf_get_gnu_property_section_size (list, align_size);
--
--      /* Update .note.gnu.property section now.  */
--      sec->size = size;
--      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
--
-       if (info->indirect_extern_access <= 0)
- 	{
- 	  /* Get GNU_PROPERTY_1_NEEDED properties.  */
-@@ -917,6 +918,24 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
- 	    }
- 	}
- 
-+      elf_prune_empty_properties (&elf_properties (first_pbfd));
-+
-+      if (elf_properties (first_pbfd) == NULL)
-+	{
-+	  /* Discard .note.gnu.property section if all properties have
-+	     been removed.  */
-+	  sec->output_section = bfd_abs_section_ptr;
-+	  return NULL;
-+	}
-+
-+      /* Compute the section size.  */
-+      list = elf_properties (first_pbfd);
-+      size = elf_get_gnu_property_section_size (list, align_size);
-+
-+      /* Update .note.gnu.property section now.  */
-+      sec->size = size;
-+      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
-+
-       elf_write_gnu_properties (info, first_pbfd, contents, list, size,
- 				align_size);
- 
-diff --git a/ld/testsuite/ld-x86-64/pr33292-x32.d b/ld/testsuite/ld-x86-64/pr33292-x32.d
-new file mode 100644
-index 00000000000..0d6cf8115cd
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr33292-x32.d
-@@ -0,0 +1,10 @@
-+#source: pr33292.s
-+#as: --x32 -mx86-used-note=yes
-+#ld: -shared -m elf32_x86_64 -z noindirect-extern-access
-+#readelf: -n
-+
-+Displaying notes found in: .note.gnu.property
-+[ 	]+Owner[ 	]+Data size[ 	]+Description
-+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
-+      Properties: x86 feature used: x86
-+	x86 ISA used: x86-64-baseline
-diff --git a/ld/testsuite/ld-x86-64/pr33292.d b/ld/testsuite/ld-x86-64/pr33292.d
-new file mode 100644
-index 00000000000..456b8499b57
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr33292.d
-@@ -0,0 +1,9 @@
-+#as: --64 -defsym __64_bit__=1 -mx86-used-note=yes
-+#ld: -shared -m elf_x86_64 -z noindirect-extern-access
-+#readelf: -n
-+
-+Displaying notes found in: .note.gnu.property
-+[ 	]+Owner[ 	]+Data size[ 	]+Description
-+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
-+      Properties: x86 feature used: x86
-+	x86 ISA used: x86-64-baseline
-diff --git a/ld/testsuite/ld-x86-64/pr33292.s b/ld/testsuite/ld-x86-64/pr33292.s
-new file mode 100644
-index 00000000000..8d14e880712
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/pr33292.s
-@@ -0,0 +1,34 @@
-+	.section ".note.gnu.property", "a"
-+.ifdef __64_bit__
-+	.p2align 3
-+.else
-+	.p2align 2
-+.endif
-+	.long 1f - 0f		/* name length */
-+	.long 5f - 2f		/* data length */
-+	.long 5			/* note type */
-+0:	.asciz "GNU"		/* vendor name */
-+1:
-+.ifdef __64_bit__
-+	.p2align 3
-+.else
-+	.p2align 2
-+.endif
-+2:	.long 0xb0008000	/* pr_type.  */
-+	.long 4f - 3f		/* pr_datasz.  */
-+3:
-+	.long 0x1
-+4:
-+.ifdef __64_bit__
-+	.p2align 3
-+.else
-+	.p2align 2
-+.endif
-+5:
-+
-+	.text
-+	.globl	foo
-+	.type	foo, @function
-+foo:
-+	ret
-+	.section	.note.GNU-stack
-diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index 0c66d1b26f7..9d975319cf5 100644
---- a/ld/testsuite/ld-x86-64/x86-64.exp
-+++ b/ld/testsuite/ld-x86-64/x86-64.exp
-@@ -568,6 +568,8 @@ run_dump_test "pr33260"
- run_dump_test "pr33260-x32"
- run_dump_test "pr33260-2"
- run_dump_test "pr33260-2-x32"
-+run_dump_test "pr33292"
-+run_dump_test "pr33292-x32"
- 
- if { ![skip_sframe_tests] } {
-     run_dump_test "sframe-simple-1"
-
-base-commit: 7e432e93f8aaa14368476cf5eae9d55c18a266fb
-prerequisite-patch-id: f9e52c2b633aadd966330c2c4529c890981bac7e
--- 
-2.51.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-19 10:51 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-19 10:51 UTC (permalink / raw
  To: gentoo-commits

commit:     db510fe7b24c057ed7e420dc88ab7a4108b256a9
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 10:51:04 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 10:51:04 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=db510fe7

9999: update section size patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-ld-section-size.patch | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/9999/0006-ld-section-size.patch b/9999/0006-ld-section-size.patch
index 70f6f28..7526cbd 100644
--- a/9999/0006-ld-section-size.patch
+++ b/9999/0006-ld-section-size.patch
@@ -1,7 +1,32 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33291#c10
+From 79b01a9700c96203028dc8c9472e91c38eda5e83 Mon Sep 17 00:00:00 2001
+Message-ID: <79b01a9700c96203028dc8c9472e91c38eda5e83.1755600645.git.sam@gentoo.org>
+From: Jan Beulich <jbeulich@suse.com>
+Date: Tue, 19 Aug 2025 10:35:38 +0200
+Subject: [PATCH] ld: entry size and merge/strings attributes propagation
+
+PR ld/33291
+
+As indicated in other recent commits, the three properties can be
+largely independent (ELF generally being the target here): Entry size
+doesn't require either of merge/strings, and strings also doesn't
+require merge. Commit 98e6d3f5bd4e ("gas/ELF: allow specifying entity
+size for arbitrary sections") uncovered issues with ld's handling.
+
+Zap entry size when it doesn't match between input sections. In that
+case SEC_MERGE and SEC_STRINGS also need to be removed, as their
+underlying granularity is lost. Then deal with SEC_MERGE and
+SEC_STRINGS separately.
+
+Otoh record entry size from the first input independent of SEC_MERGE.
+---
+ ld/ldlang.c | 27 ++++++++++++++++++---------
+ 1 file changed, 18 insertions(+), 9 deletions(-)
+
+diff --git a/ld/ldlang.c b/ld/ldlang.c
+index 8ba95b04e23..54292a8dfe1 100644
 --- a/ld/ldlang.c
 +++ b/ld/ldlang.c
-@@ -2857,14 +2857,24 @@ lang_add_section (lang_statement_list_ty
+@@ -2854,14 +2854,24 @@ lang_add_section (lang_statement_list_type *ptr,
        /* Only set SEC_READONLY flag on the first input section.  */
        flags &= ~ SEC_READONLY;
  
@@ -33,14 +58,18 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=33291#c10
  	}
      }
    output->bfd_section->flags |= flags;
-@@ -2879,8 +2889,9 @@ lang_add_section (lang_statement_list_ty
+@@ -2876,8 +2886,7 @@ lang_add_section (lang_statement_list_type *ptr,
  				     link_info.output_bfd,
  				     output->bfd_section,
  				     &link_info);
 -      if ((flags & SEC_MERGE) != 0)
-+      //todo if (no earlier data statements)
- 	output->bfd_section->entsize = section->entsize;
-+      //todo also need to deal with later data statements
+-	output->bfd_section->entsize = section->entsize;
++      output->bfd_section->entsize = section->entsize;
      }
  
    if ((flags & SEC_TIC54X_BLOCK) != 0
+
+base-commit: 09292f4ae2ccb46130652f6b310ee7a5227326d3
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-19  3:48 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-19  3:48 UTC (permalink / raw
  To: gentoo-commits

commit:     f96ad7995e3833535278b5edcc9cbfa636eca2ac
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 19 03:47:53 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 19 03:47:53 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f96ad799

9999: add fix for property pruning

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0010-elf-Prune-empty-generic-properties.patch | 204 +++++++++++++++++++++
 1 file changed, 204 insertions(+)

diff --git a/9999/0010-elf-Prune-empty-generic-properties.patch b/9999/0010-elf-Prune-empty-generic-properties.patch
new file mode 100644
index 0000000..598781d
--- /dev/null
+++ b/9999/0010-elf-Prune-empty-generic-properties.patch
@@ -0,0 +1,204 @@
+From 5179e6a3d41c8e5df76065f24f5eec32e93b4584 Mon Sep 17 00:00:00 2001
+Message-ID: <5179e6a3d41c8e5df76065f24f5eec32e93b4584.1755575227.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Mon, 18 Aug 2025 18:37:00 -0700
+Subject: [PATCH] elf: Prune empty generic properties
+
+Prune empty generic properties before discarding empty property note
+section and leave processor specific properties to the backend.
+
+bfd/
+
+	PR ld/33292
+	* elf-properties.c (elf_prune_empty_properties): New function.
+	(_bfd_elf_link_setup_gnu_properties): Call
+	elf_prune_empty_properties before discarding empty property note
+	section.  Move indirect_extern_access processing before
+	elf_prune_empty_properties call.
+
+ld/
+
+	PR ld/33292
+	* testsuite/ld-x86-64/pr33292-x32.d: New file.
+	* testsuite/ld-x86-64/pr33292.d: Likewise.
+	* testsuite/ld-x86-64/pr33292.s: Likewise.
+	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/33292 tests.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-properties.c                 | 51 +++++++++++++++++++---------
+ ld/testsuite/ld-x86-64/pr33292-x32.d | 10 ++++++
+ ld/testsuite/ld-x86-64/pr33292.d     |  9 +++++
+ ld/testsuite/ld-x86-64/pr33292.s     | 34 +++++++++++++++++++
+ ld/testsuite/ld-x86-64/x86-64.exp    |  2 ++
+ 5 files changed, 90 insertions(+), 16 deletions(-)
+ create mode 100644 ld/testsuite/ld-x86-64/pr33292-x32.d
+ create mode 100644 ld/testsuite/ld-x86-64/pr33292.d
+ create mode 100644 ld/testsuite/ld-x86-64/pr33292.s
+
+diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
+index 07ab38098e6..73eb231d861 100644
+--- a/bfd/elf-properties.c
++++ b/bfd/elf-properties.c
+@@ -697,6 +697,23 @@ _bfd_elf_link_create_gnu_property_sec (struct bfd_link_info *info, bfd *elf_bfd,
+   return sec;
+ }
+ 
++/* Prune empty generic properties.  */
++
++static void
++elf_prune_empty_properties (elf_property_list **pp)
++{
++  elf_property_list *p;
++
++  while ((p = *pp) != NULL)
++    if ((p->property.pr_type < GNU_PROPERTY_LOPROC
++	 || p->property.pr_type >= GNU_PROPERTY_LOUSER)
++	&& p->property.pr_datasz != 0
++	&& p->property.pr_kind == property_number
++	&& p->property.u.number == 0)
++      *pp = p->next;
++    else
++      pp = &p->next;
++}
+ 
+ /* Set up GNU properties.  Return the first relocatable ELF input with
+    GNU properties if found.  Otherwise, return NULL.  */
+@@ -878,22 +895,6 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
+       if (bed->fixup_gnu_properties)
+ 	bed->fixup_gnu_properties (info, &elf_properties (first_pbfd));
+ 
+-      if (elf_properties (first_pbfd) == NULL)
+-	{
+-	  /* Discard .note.gnu.property section if all properties have
+-	     been removed.  */
+-	  sec->output_section = bfd_abs_section_ptr;
+-	  return NULL;
+-	}
+-
+-      /* Compute the section size.  */
+-      list = elf_properties (first_pbfd);
+-      size = elf_get_gnu_property_section_size (list, align_size);
+-
+-      /* Update .note.gnu.property section now.  */
+-      sec->size = size;
+-      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
+-
+       if (info->indirect_extern_access <= 0)
+ 	{
+ 	  /* Get GNU_PROPERTY_1_NEEDED properties.  */
+@@ -917,6 +918,24 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
+ 	    }
+ 	}
+ 
++      elf_prune_empty_properties (&elf_properties (first_pbfd));
++
++      if (elf_properties (first_pbfd) == NULL)
++	{
++	  /* Discard .note.gnu.property section if all properties have
++	     been removed.  */
++	  sec->output_section = bfd_abs_section_ptr;
++	  return NULL;
++	}
++
++      /* Compute the section size.  */
++      list = elf_properties (first_pbfd);
++      size = elf_get_gnu_property_section_size (list, align_size);
++
++      /* Update .note.gnu.property section now.  */
++      sec->size = size;
++      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
++
+       elf_write_gnu_properties (info, first_pbfd, contents, list, size,
+ 				align_size);
+ 
+diff --git a/ld/testsuite/ld-x86-64/pr33292-x32.d b/ld/testsuite/ld-x86-64/pr33292-x32.d
+new file mode 100644
+index 00000000000..0d6cf8115cd
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr33292-x32.d
+@@ -0,0 +1,10 @@
++#source: pr33292.s
++#as: --x32 -mx86-used-note=yes
++#ld: -shared -m elf32_x86_64 -z noindirect-extern-access
++#readelf: -n
++
++Displaying notes found in: .note.gnu.property
++[ 	]+Owner[ 	]+Data size[ 	]+Description
++  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
++      Properties: x86 feature used: x86
++	x86 ISA used: x86-64-baseline
+diff --git a/ld/testsuite/ld-x86-64/pr33292.d b/ld/testsuite/ld-x86-64/pr33292.d
+new file mode 100644
+index 00000000000..456b8499b57
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr33292.d
+@@ -0,0 +1,9 @@
++#as: --64 -defsym __64_bit__=1 -mx86-used-note=yes
++#ld: -shared -m elf_x86_64 -z noindirect-extern-access
++#readelf: -n
++
++Displaying notes found in: .note.gnu.property
++[ 	]+Owner[ 	]+Data size[ 	]+Description
++  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
++      Properties: x86 feature used: x86
++	x86 ISA used: x86-64-baseline
+diff --git a/ld/testsuite/ld-x86-64/pr33292.s b/ld/testsuite/ld-x86-64/pr33292.s
+new file mode 100644
+index 00000000000..8d14e880712
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/pr33292.s
+@@ -0,0 +1,34 @@
++	.section ".note.gnu.property", "a"
++.ifdef __64_bit__
++	.p2align 3
++.else
++	.p2align 2
++.endif
++	.long 1f - 0f		/* name length */
++	.long 5f - 2f		/* data length */
++	.long 5			/* note type */
++0:	.asciz "GNU"		/* vendor name */
++1:
++.ifdef __64_bit__
++	.p2align 3
++.else
++	.p2align 2
++.endif
++2:	.long 0xb0008000	/* pr_type.  */
++	.long 4f - 3f		/* pr_datasz.  */
++3:
++	.long 0x1
++4:
++.ifdef __64_bit__
++	.p2align 3
++.else
++	.p2align 2
++.endif
++5:
++
++	.text
++	.globl	foo
++	.type	foo, @function
++foo:
++	ret
++	.section	.note.GNU-stack
+diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
+index 0c66d1b26f7..9d975319cf5 100644
+--- a/ld/testsuite/ld-x86-64/x86-64.exp
++++ b/ld/testsuite/ld-x86-64/x86-64.exp
+@@ -568,6 +568,8 @@ run_dump_test "pr33260"
+ run_dump_test "pr33260-x32"
+ run_dump_test "pr33260-2"
+ run_dump_test "pr33260-2-x32"
++run_dump_test "pr33292"
++run_dump_test "pr33292-x32"
+ 
+ if { ![skip_sframe_tests] } {
+     run_dump_test "sframe-simple-1"
+
+base-commit: 7e432e93f8aaa14368476cf5eae9d55c18a266fb
+prerequisite-patch-id: f9e52c2b633aadd966330c2c4529c890981bac7e
+-- 
+2.51.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-18 20:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-18 20:21 UTC (permalink / raw
  To: gentoo-commits

commit:     d419b3c41c991be91a6fcb94ed3001822361f9da
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 18 20:20:16 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 18 20:20:16 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d419b3c4

9999: drop upstreamed patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...Properly-override-compiler-flags-in-tests.patch | 393 ---------------------
 1 file changed, 393 deletions(-)

diff --git a/9999/0006-ld-Properly-override-compiler-flags-in-tests.patch b/9999/0006-ld-Properly-override-compiler-flags-in-tests.patch
deleted file mode 100644
index cd38be5..0000000
--- a/9999/0006-ld-Properly-override-compiler-flags-in-tests.patch
+++ /dev/null
@@ -1,393 +0,0 @@
-From d4cbc75a7fb72c0fadf86fea73d86540fdc88166 Mon Sep 17 00:00:00 2001
-Message-ID: <d4cbc75a7fb72c0fadf86fea73d86540fdc88166.1755459855.git.sam@gentoo.org>
-In-Reply-To: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
-References: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sat, 16 Aug 2025 14:49:05 -0700
-Subject: [PATCH 3/3] ld: Properly override compiler flags in tests
-
-Some tests need to be compiled with additional flags.  When binutils is
-built and compiled with
-
-CC="gcc -fsanitize=address,undefined" CXX="g++ -fsanitize=address,undefined"
-
-some linker tests fail to disable address sanitizer options since
-proc default_ld_compile has
-
-    set ccexe $cc
-    set ccparm [string first " " $cc]
-    set ccflags ""
-    if { $ccparm > 0 } then {
-        set ccflags [string range $cc $ccparm end]
-        set ccexe [string range $cc 0 $ccparm]
-        set cc $ccexe
-    }
-...
-    set cmd "$cc $flags $ccflags -c $source -o $object"
-
-Compiler flags in $CC and $CXX will be the last ones.  Add
-CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST to use them in
-proc default_ld_compile
-
-    set cflag_test ""
-    set cxxflag_test ""
-    if {[string match "*++*" $ccexe]} {
-        append flags " $CXXFLAGS_FOR_TARGET"
-        set cflag_test "$CXXFLAGS_FOR_TARGET_TEST"
-    } else {
-        append flags " $CFLAGS_FOR_TARGET"
-        set cflag_test "$CFLAGS_FOR_TARGET_TEST"
-    }
-...
-    set cmd "$cc $flags $ccflags $cflag_test -c $source -o $object"
-
-so that they will be the last flags passed to compiler.  Also update
-run_ld_link_exec_tests and run_cc_link_tests to make
-CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST the last flags
-passed to compiler.
-
-	* testsuite/config/default.exp (CFLAGS_FOR_TARGET_TEST): New.
-	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
-	* testsuite/ld-elf/dwarf.exp (CFLAGS_FOR_TARGET): Renamed to ...
-	(CFLAGS_FOR_TARGET_TEST): This.
-	* testsuite/ld-elf/shared.exp: Save, append and restore
-	CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST for
-	$build_tests.  Save, append and restore CFLAGS_FOR_TARGET_TEST,
-	instead of CFLAGS_FOR_TARGET, for $dlopen_run_tests.
-	* testsuite/ld-plugin/plugin.exp (CFLAGS_FOR_TARGET): Renamed to
-	...
-	(CFLAGS_FOR_TARGET_TEST): This.
-	* testsuite/ld-shared/shared.exp (CFLAGS_FOR_TARGET): Renamed to
-	...
-	(CFLAGS_FOR_TARGET_TEST): This.
-	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET): Renamed to ...
-	(CFLAGS_FOR_TARGET_TEST): This.
-	(CXXFLAGS_FOR_TARGET): Renamed to ...
-	(CXXFLAGS_FOR_TARGET_TEST): This.
-	* testsuite/lib/ld-lib.exp (default_ld_compile): Append
-	CFLAGS_FOR_TARGET_TEST/CXXFLAGS_FOR_TARGET_TEST to compiler flags.
-	(run_ld_link_exec_tests): Append CFLAGS_FOR_TARGET_TEST and
-	CXXFLAGS_FOR_TARGET_TEST to compiler.
-	(run_cc_link_tests): Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- ld/testsuite/config/default.exp   |  6 ++++++
- ld/testsuite/ld-elf/dwarf.exp     |  6 +++---
- ld/testsuite/ld-elf/shared.exp    | 12 +++++++++---
- ld/testsuite/ld-plugin/plugin.exp | 10 +++++-----
- ld/testsuite/ld-shared/shared.exp |  8 ++++----
- ld/testsuite/ld-srec/srec.exp     | 28 ++++++++++++++--------------
- ld/testsuite/lib/ld-lib.exp       | 28 +++++++++++++++++++---------
- 7 files changed, 60 insertions(+), 38 deletions(-)
-
-diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
-index 1c12ce60193..9f286831e07 100644
---- a/ld/testsuite/config/default.exp
-+++ b/ld/testsuite/config/default.exp
-@@ -117,12 +117,18 @@ if {![info exists CC_FOR_TARGET]} {
- if {![info exists CFLAGS_FOR_TARGET]} {
-     set CFLAGS_FOR_TARGET "-g -O2"
- }
-+if {![info exists CFLAGS_FOR_TARGET_TEST]} {
-+    set CFLAGS_FOR_TARGET_TEST ""
-+}
- if {![info exists CXX_FOR_TARGET]} {
-     set CXX_FOR_TARGET [find_g++]
- }
- if {![info exists CXXFLAGS_FOR_TARGET]} {
-     set CXXFLAGS_FOR_TARGET ""
- }
-+if {![info exists CXXFLAGS_FOR_TARGET_TEST]} {
-+    set CXXFLAGS_FOR_TARGET_TEST ""
-+}
- 
- # This allows us to run the linker testsuite with clang as the compilation
- # driver instead of gcc.  The syntax of the overrides are as follows, one
-diff --git a/ld/testsuite/ld-elf/dwarf.exp b/ld/testsuite/ld-elf/dwarf.exp
-index c7b2915a963..4f7963526e9 100644
---- a/ld/testsuite/ld-elf/dwarf.exp
-+++ b/ld/testsuite/ld-elf/dwarf.exp
-@@ -69,11 +69,11 @@ set run_tests {
- }
- 
- # Disable all sanitizers.
--set old_CFLAGS "$CFLAGS_FOR_TARGET"
--append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
-+set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
- run_cc_link_tests $build_tests
- run_ld_link_exec_tests $run_tests
--set CFLAGS_FOR_TARGET "$old_CFLAGS"
-+set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
- 
- proc strip_test {} {
-     global ld
-diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
-index ee881c2d619..a24525a2ff8 100644
---- a/ld/testsuite/ld-elf/shared.exp
-+++ b/ld/testsuite/ld-elf/shared.exp
-@@ -972,7 +972,13 @@ append build_tests {
-    {pr26580-b.c} {} "libpr26580-2.so"}
- }
- 
-+set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
-+append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
-+append CXXFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
- run_cc_link_tests $build_tests
-+set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-+set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
- 
- run_cc_link_tests [list \
-     [list \
-@@ -1259,10 +1265,10 @@ if [check_libdl_available] {
-   # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
-   # sections.
-   # Disable all sanitizers.
--  set old_CFLAGS "$CFLAGS_FOR_TARGET"
--  append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
-+  set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+  append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
-   run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsd*"
--  set CFLAGS_FOR_TARGET "$old_CFLAGS"
-+  set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
- }
- 
- # Check --no-add-needed and --no-copy-dt-needed-entries
-diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp
-index 38a40363681..2e148e4cbf8 100644
---- a/ld/testsuite/ld-plugin/plugin.exp
-+++ b/ld/testsuite/ld-plugin/plugin.exp
-@@ -87,11 +87,11 @@ set regcln "-plugin-opt registercleanup"
- set failed_compile 0
- set _ ""
- set plugin_nm_output ""
--set old_CFLAGS "$CFLAGS_FOR_TARGET"
--append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
-+set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
- if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget m9s12x*-*-*] } {
-     # otherwise get FAILS due to _.frame
--    append CFLAGS_FOR_TARGET " -fomit-frame-pointer"
-+    append CFLAGS_FOR_TARGET_TEST " -fomit-frame-pointer"
- }
- 
- if { $can_compile && \
-@@ -291,7 +291,7 @@ if { !$can_compile || $failed_compile } {
- 	    unsupported [lindex $testitem 0]
- 	}
-     }
--    set CFLAGS_FOR_TARGET "$old_CFLAGS"
-+    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-     return
- }
- 
-@@ -394,4 +394,4 @@ if [ar_simple_create $ar "--plugin $plugin4_path" "tmpdir/libpr20070.a" \
-     unsupported "PR ld/20070"
- }
- 
--set CFLAGS_FOR_TARGET "$old_CFLAGS"
-+set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
-index 29de93a1957..e7f77fad567 100644
---- a/ld/testsuite/ld-shared/shared.exp
-+++ b/ld/testsuite/ld-shared/shared.exp
-@@ -67,8 +67,8 @@ set SHCFLAG ""
- set shared_needs_pic "no"
- 
- # Disable all sanitizers.
--set old_CFLAGS "$CFLAGS_FOR_TARGET"
--append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
-+set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
- 
- if { [is_xcoff_format] } {
-     # Not all the useful features are available with AIX shared
-@@ -104,7 +104,7 @@ if [istarget arm*-*-linux*] {
- 	set file [open $tmpdir/movw-detect.c w]
- 	puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
- 	close $file
--	if [run_host_cmd_yesno "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
-+	if [run_host_cmd_yesno "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET_TEST -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
- 	    set shared_needs_pic "yes"
- 	}
-     }
-@@ -343,4 +343,4 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
-     }
- }
- 
--set CFLAGS_FOR_TARGET "$old_CFLAGS"
-+set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
-index bec59130425..5afc84c24b6 100644
---- a/ld/testsuite/ld-srec/srec.exp
-+++ b/ld/testsuite/ld-srec/srec.exp
-@@ -365,24 +365,24 @@ if { ![check_compiler_available] } {
- # tests. Also add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if PIE doesn't work
- # with S-records.  Also add $NOCF_PROTECTION_CFLAGS for S-records.
- # Also add $NOSANITIZE_CFLAGS for S-records.
--set old_CFLAGS "$CFLAGS_FOR_TARGET"
--append CFLAGS_FOR_TARGET " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
--set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
--append CXXFLAGS_FOR_TARGET " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
-+set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
-+append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
-+set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
-+append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
- 
- # S-records can't handle .note.gnu.property sections.
- if { [is_elf_format] \
-      && ([istarget "i?86-*-*"] || [istarget "x86_64-*-*"]) } {
--    append CFLAGS_FOR_TARGET " -Wa,-mx86-used-note=no"
--    append CXXFLAGS_FOR_TARGET " -Wa,-mx86-used-note=no"
-+    append CFLAGS_FOR_TARGET_TEST " -Wa,-mx86-used-note=no"
-+    append CXXFLAGS_FOR_TARGET_TEST " -Wa,-mx86-used-note=no"
- }
- 
- if { ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/sr1.c tmpdir/sr1.o] \
-      || ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/sr2.c tmpdir/sr2.o] } {
-     unsupported $test1
-     unsupported $test2
--    set CFLAGS_FOR_TARGET "$old_CFLAGS"
--    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
-+    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-+    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
-     return
- }
- 
-@@ -454,15 +454,15 @@ run_srec_test $test1 "tmpdir/sr1.o tmpdir/sr2.o"
- 
- if { ![is_remote host] && [which $CXX_FOR_TARGET] == 0 } {
-     untested $test2
--    set CFLAGS_FOR_TARGET "$old_CFLAGS"
--    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
-+    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-+    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
-     return
- }
- 
- if ![ld_compile "$CXX_FOR_TARGET -fno-exceptions" $srcdir/$subdir/sr3.cc tmpdir/sr3.o] {
-     unsupported $test2
--    set CFLAGS_FOR_TARGET "$old_CFLAGS"
--    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
-+    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-+    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
-     return
- }
- 
-@@ -488,5 +488,5 @@ setup_xfail "bpf-*-*"
- 
- run_srec_test $test2 "tmpdir/sr3.o"
- 
--set CFLAGS_FOR_TARGET "$old_CFLAGS"
--set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
-+set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
-+set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 22d2f987b87..d1343eb12ca 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -253,6 +253,8 @@ proc default_ld_link { ld target objects } {
- proc default_ld_compile { cc source object } {
-     global CFLAGS_FOR_TARGET
-     global CXXFLAGS_FOR_TARGET
-+    global CFLAGS_FOR_TARGET_TEST
-+    global CXXFLAGS_FOR_TARGET_TEST
-     global srcdir
-     global subdir
-     global host_triplet
-@@ -286,10 +288,14 @@ proc default_ld_compile { cc source object } {
-     }
- 
-     set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""]
-+    set cflag_test ""
-+    set cxxflag_test ""
-     if {[string match "*++*" $ccexe]} {
- 	append flags " $CXXFLAGS_FOR_TARGET"
-+	set cflag_test "$CXXFLAGS_FOR_TARGET_TEST"
-     } else {
- 	append flags " $CFLAGS_FOR_TARGET"
-+	set cflag_test "$CFLAGS_FOR_TARGET_TEST"
-     }
- 
-     if [board_info [target_info name] exists cflags] {
-@@ -300,7 +306,7 @@ proc default_ld_compile { cc source object } {
- 	append flags " [board_info [target_info name] multilib_flags]"
-     }
- 
--    set cmd "$cc $flags $ccflags -c $source -o $object"
-+    set cmd "$cc $flags $ccflags $cflag_test -c $source -o $object"
-     verbose -log "$cmd"
- 
-     set status [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
-@@ -727,6 +733,8 @@ proc run_ld_link_exec_tests { ldtests args } {
-     global env
-     global CC_FOR_TARGET
-     global CXX_FOR_TARGET
-+    global CFLAGS_FOR_TARGET_TEST
-+    global CXXFLAGS_FOR_TARGET_TEST
-     global errcnt
-     global exec_output
-     global STATIC_LDFLAGS
-@@ -780,9 +788,9 @@ proc run_ld_link_exec_tests { ldtests args } {
- 	    lappend objfiles $objfile
- 
- 	    if { [ string match "c++" $lang ] } {
--		set cmd "$CXX_FOR_TARGET -c $cflags"
-+		set cmd "$CXX_FOR_TARGET -c $cflags $CXXFLAGS_FOR_TARGET_TEST"
- 	    } else {
--		set cmd "$CC_FOR_TARGET -c $cflags"
-+		set cmd "$CC_FOR_TARGET -c $cflags $CFLAGS_FOR_TARGET_TEST"
- 	    }
- 	    if ![ld_compile $cmd $srcdir/$subdir/$src_file $objfile] {
- 		set failed 1
-@@ -799,10 +807,10 @@ proc run_ld_link_exec_tests { ldtests args } {
- 	    set link_cmd $ld
- 	} elseif { [ string match "c++" $lang ] } {
- 	    set link_proc ld_link
--	    set link_cmd $CXX_FOR_TARGET
-+	    set link_cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST"
- 	} else {
- 	    set link_proc ld_link
--	    set link_cmd $CC_FOR_TARGET
-+	    set link_cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST"
- 	}
- 
- 	if { $binfile eq "tmpdir/" } {
-@@ -888,6 +896,8 @@ proc run_cc_link_tests { ldtests } {
-     global env
-     global CC_FOR_TARGET
-     global CXX_FOR_TARGET
-+    global CFLAGS_FOR_TARGET_TEST
-+    global CXXFLAGS_FOR_TARGET_TEST
-     global ar
-     global exec_output
-     global STATIC_LDFLAGS
-@@ -969,9 +979,9 @@ proc run_cc_link_tests { ldtests } {
- 	    lappend objfiles $objfile
- 
- 	    if { [ string match "c++" $lang ] } {
--		set cmd "$CXX_FOR_TARGET -c $cflags"
-+		set cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST -c $cflags"
- 	    } else {
--		set cmd "$CC_FOR_TARGET -c $cflags"
-+		set cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST -c $cflags"
- 	    }
- 	    if ![ld_compile $cmd $srcdir/$subdir/$src_file $objfile] {
- 		set failed 1
-@@ -987,9 +997,9 @@ proc run_cc_link_tests { ldtests } {
- 	reset_vars
- 
- 	if { [ string match "c++" $lang ] } {
--	    set cc_cmd $CXX_FOR_TARGET
-+	    set cc_cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST"
- 	} else {
--	    set cc_cmd $CC_FOR_TARGET
-+	    set cc_cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST"
- 	}
- 
- 	if { $binfile eq "tmpdir/" } {
--- 
-2.50.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-18 20:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-18 20:21 UTC (permalink / raw
  To: gentoo-commits

commit:     6053b202b86f488ee6a213a260b7e05891fe8a88
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 18 20:20:58 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 18 20:20:58 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=6053b202

9999: renumber patches

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/{0007-ld-section-size.patch => 0006-ld-section-size.patch}           | 0
 ...ncy.patch => 0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch} | 0
 ...ch => 0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch} | 0
 ...ncy.patch => 0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch} | 0
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/9999/0007-ld-section-size.patch b/9999/0006-ld-section-size.patch
similarity index 100%
rename from 9999/0007-ld-section-size.patch
rename to 9999/0006-ld-section-size.patch

diff --git a/9999/0008-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
similarity index 100%
rename from 9999/0008-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
rename to 9999/0007-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch

diff --git a/9999/0009-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch b/9999/0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
similarity index 100%
rename from 9999/0009-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
rename to 9999/0008-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch

diff --git a/9999/0010-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch b/9999/0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
similarity index 100%
rename from 9999/0010-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
rename to 9999/0009-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch


^ permalink raw reply	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-18 20:19 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-18 20:19 UTC (permalink / raw
  To: gentoo-commits

commit:     02dab36626c7c292159c02bf13e3dcd3854d4402
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 18 20:18:37 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 18 20:19:15 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=02dab366

9999: refresh patches for GNU(2) TLS markers, reorder

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...roperly-override-compiler-flags-in-tests.patch} |   0
 ...ction-size.patch => 0007-ld-section-size.patch} |   0
 ...dd-GLIBC_ABI_GNU2_TLS-version-dependency.patch} | 807 ++++++++++++++-------
 ...LIBC_ABI_DT_X86_64_PLT-version-dependenc.patch} |  11 +-
 ...-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch | 470 ++++++++++++
 5 files changed, 1025 insertions(+), 263 deletions(-)

diff --git a/9999/0008-ld-Properly-override-compiler-flags-in-tests.patch b/9999/0006-ld-Properly-override-compiler-flags-in-tests.patch
similarity index 100%
rename from 9999/0008-ld-Properly-override-compiler-flags-in-tests.patch
rename to 9999/0006-ld-Properly-override-compiler-flags-in-tests.patch

diff --git a/9999/0009-ld-section-size.patch b/9999/0007-ld-section-size.patch
similarity index 100%
rename from 9999/0009-ld-section-size.patch
rename to 9999/0007-ld-section-size.patch

diff --git a/9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0008-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
similarity index 55%
rename from 9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
rename to 9999/0008-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
index 15230cc..63b7fa1 100644
--- a/9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
+++ b/9999/0008-x86-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
@@ -1,46 +1,47 @@
-From 35d2c802f63122702ac48296dac025470c5d1467 Mon Sep 17 00:00:00 2001
-Message-ID: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+From 40fd19259a3b9a576bedba9f9ce236d2f1b42da9 Mon Sep 17 00:00:00 2001
+Message-ID: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 17 Aug 2025 11:58:53 -0700
-Subject: [PATCH 1/3] x86-64: Add GLIBC_ABI_GNU2_TLS version dependency
+Date: Mon, 18 Aug 2025 13:13:20 -0700
+Subject: [PATCH 1/3] x86: Add GLIBC_ABI_GNU2_TLS version dependency
 
-On Linux/x86-64, programs and shared libraries compiled with
+On Linux/x86, programs and shared libraries compiled with
 -mtls-dialect=gnu2 may fail silently at run-time against glibc without
-the GNU2 TLS run-time fix for:
+the GNU2 TLS run-time fixes for:
 
+https://sourceware.org/bugzilla/show_bug.cgi?id=31501
 https://sourceware.org/bugzilla/show_bug.cgi?id=31372
 
 A version tag, GLIBC_ABI_GNU2_TLS, has been added to glibc to indicate
-that glibc has the working GNU2 TLS run-time by:
-
-commit 9df8fa397d515dc86ff5565f6c45625e672d539e
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Mon Jul 28 12:18:22 2025 -0700
-
-    x86-64: Add GLIBC_ABI_GNU2_TLS version [BZ #33129]
-
-Add the --gnu2-tls-tag option to x86-64 ELF linker to add the
-GLIBC_ABI_GNU2_TLS version dependency in output programs and shared
-libraries when linking against glibc if input relocatable object files
-have R_X86_64_TLSDESC_CALL relocation.  The output will fail to load and
-run at run-time against glibc which doesn't define the GLIBC_ABI_GNU2_TLS
+that glibc has the working GNU2 TLS run-time.  Add the --gnu2-tls-tag
+option to i386/x86-64 ELF linker to add the GLIBC_ABI_GNU2_TLS version
+dependency in output programs and shared libraries when linking against
+glibc if input relocatable object files have R_386_TLS_DESC_CALL or
+R_X86_64_TLSDESC_CALL relocation.  The output will fail to load and run
+at run-time against glibc which doesn't define the GLIBC_ABI_GNU2_TLS
 version.
 
 Add the --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag
 by default.  If unspecified, linker will add the GLIBC_ABI_GNU2_TLS
-version dependency if inputs have R_X86_64_TLSDESC_CALL relocation and
-libc.so defines the GLIBC_ABI_GNU2_TLS version.
+version dependency if input object files have R_386_TLS_DESC_CALL or
+R_X86_64_TLSDESC_CALL relocation and libc.so defines the GLIBC_ABI_GNU2_TLS
+version.
 
 Update elf_link_add_glibc_verneed to properly add the GLIBC_2.36 version
-dependency when -z mark-plt -z nopack-relative-relocs passed to linker.
+dependency when -z mark-plt -z nopack-relative-relocs passed to x86-64
+ELF linker.
 
 bfd/
 
 	PR ld/33130
 	* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Add
 	a pointer to bool argument.
-	* elf-linker-x86.h (elf_linker_x86_params): Add gnu2_tls.
-	* elf64-x86-64.c (elf_x86_64_scan_relocs): Set has_tlsdesc_call
+	* elf-linker-x86.h (elf_linker_x86_params): Add
+	gnu2_tls_version_tag.
+	* elf32-i386.c (elf_i386_scan_relocs): Set has_tls_desc_call to
+	1 for R_386_TLS_DESC_CALL.
+	(elf_i386_add_glibc_version_dependency): New.  Undef before
+	FreeBSD support.
+	* elf64-x86-64.c (elf_x86_64_scan_relocs): Set has_tls_desc_call
 	to 1 for R_X86_64_TLSDESC_CALL.
 	(elf_x86_64_add_glibc_version_dependency): Add GLIBC_ABI_GNU2_TLS
 	version dependency if GLIBC_ABI_GNU2_TLS dependency isn't disabled
@@ -55,7 +56,9 @@ bfd/
 	bool argument and pass it to elf_link_add_glibc_verneed.
 	(_bfd_elf_link_add_dt_relr_dependency): Pass NULL to
 	_bfd_elf_link_add_glibc_version_dependency.
-	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tlsdesc_call.
+	(elf_backend_add_glibc_version_dependency): Undef before CloudABI
+	support.
+	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_desc_call.
 
 ld/
 
@@ -66,32 +69,47 @@ ld/
 	* configure: Likewise.
 	* configure.ac: Add --enable-gnu2-tls-tag.
 	* ld.texi: Document --gnu2-tls-tag/--no-gnu2-tls-tag.
-	* ldlex.h (option_values): Add OPTION_GNU2_TLS_TAG and
-	OPTION_NO_GNU2_TLS_TAG.
+	* ldlex.h (option_values): Add OPTION_GNU2_TLS_VERSION_TAG and
+	OPTION_NO_GNU2_TLS_VERSION_TAG.
 	* emulparams/elf32_x86_64.sh (EXTRA_EM_FILE): Changed to
-	"elf-x86-64".
+	"elf-x86-64-glibc".
+	* emulparams/elf_i386.sh (EXTRA_EM_FILE): Set to "elf-i386-glibc".
+	* emulparams/elf_i386_fbsd.sh (EXTRA_EM_FILE): New.  Set to
+	"elf-x86".
+        * emulparams/elf_i386_haiku.sh (EXTRA_EM_FILE): Likewise.
 	* emulparams/elf_x86_64.sh (EXTRA_EM_FILE): Likewise.
-	* emultempl/elf-x86-64.em: New file.
+	* emulparams/elf_x86_64_cloudabi.sh (EXTRA_EM_FILE): New.  Set
+	to "elf-x86-64".
+	* emulparams/elf_x86_64_fbsd.sh (EXTRA_EM_FILE): Likewise.
+	* emulparams/elf_x86_64_haiku.sh (EXTRA_EM_FILE): Likewise.
+	* (EXTRA_EM_FILE): Likewise.
+	* (EXTRA_EM_FILE): Likewise.
+        * emultempl/elf-i386-glibc.em: New file.
+	* emultempl/elf-x86-64-glibc.em: Likewise.
+	* emultempl/elf-x86-64.em: Likewise.
+	* emultempl/elf-x86-glibc.em: Likewise.
 	* emultempl/elf-x86.em (elf_x86_64_before_parse): Removed.
 	(LDEMUL_BEFORE_PARSE): Likewise.
 	(elf_x86_64_before_allocation): Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1.rd: New file.
-	* testsuite/ld-x86-64/gnu2-tls-1a.od: New file.
-	* testsuite/ld-x86-64/gnu2-tls-1a.s: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1b.od: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1b.s: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-1c.od: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-2.rd: Likewise.
-	* testsuite/ld-x86-64/gnu2-tls-2.s: Likewise.
+	(LDEMUL_BEFORE_ALLOCATION): Likewise.
+	* emultempl/solaris2-x86-64.em: New file.
+	* testsuite/ld-i386/gnu2-tls-1.s: Likewise.
+	* testsuite/ld-i386/gnu2-tls-1a.rd: Likewise.
+	* testsuite/ld-i386/gnu2-tls-1b.rd: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1.s: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1a.rd: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1b.rd: Likewise.
 	* testsuite/ld-x86-64/mark-plt-2.rd: Likewise.
 	* testsuite/ld-x86-64/mark-plt-2.s: Likewise.
-	* testsuite/ld-x86-64/x86-64.exp: Run GLIBC_ABI_GNU2_TLS tests.
+	* testsuite/ld-i386/i386.exp: Run GLIBC_ABI_GNU2_TLS tests.
+	* testsuite/ld-x86-64/x86-64.exp: Likewise.
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  bfd/elf-bfd.h                         |   2 +-
  bfd/elf-linker-x86.h                  |   8 ++
- bfd/elf64-x86-64.c                    |  30 ++++--
+ bfd/elf32-i386.c                      |  44 ++++++++-
+ bfd/elf64-x86-64.c                    |  32 +++++--
  bfd/elflink.c                         | 130 +++++++++++++++-----------
  bfd/elfxx-x86.h                       |   4 +
  ld/NEWS                               |   6 ++
@@ -99,32 +117,43 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/configure                          |  29 +++++-
  ld/configure.ac                       |  19 ++++
  ld/emulparams/elf32_x86_64.sh         |   2 +-
+ ld/emulparams/elf_i386.sh             |   2 +-
+ ld/emulparams/elf_i386_fbsd.sh        |   1 +
+ ld/emulparams/elf_i386_haiku.sh       |   1 +
  ld/emulparams/elf_x86_64.sh           |   2 +-
- ld/emultempl/elf-x86-64.em            | 108 +++++++++++++++++++++
+ ld/emulparams/elf_x86_64_cloudabi.sh  |   1 +
+ ld/emulparams/elf_x86_64_fbsd.sh      |   1 +
+ ld/emulparams/elf_x86_64_haiku.sh     |   1 +
+ ld/emultempl/elf-i386-glibc.em        |  41 ++++++++
+ ld/emultempl/elf-x86-64-glibc.em      |  37 ++++++++
+ ld/emultempl/elf-x86-64.em            |  68 ++++++++++++++
+ ld/emultempl/elf-x86-glibc.em         |  70 ++++++++++++++
  ld/emultempl/elf-x86.em               |  58 ------------
- ld/ld.texi                            |  13 +++
+ ld/emultempl/solaris2-x86-64.em       |  23 +++++
+ ld/ld.texi                            |  15 +++
  ld/ldlex.h                            |   3 +
- ld/testsuite/ld-x86-64/gnu2-tls-1.rd  |   7 ++
- ld/testsuite/ld-x86-64/gnu2-tls-1a.od |  13 +++
- ld/testsuite/ld-x86-64/gnu2-tls-1a.s  |  14 +++
- ld/testsuite/ld-x86-64/gnu2-tls-1b.od |  13 +++
- ld/testsuite/ld-x86-64/gnu2-tls-1b.s  |   9 ++
- ld/testsuite/ld-x86-64/gnu2-tls-1c.od |  13 +++
- ld/testsuite/ld-x86-64/gnu2-tls-2.rd  |   4 +
- ld/testsuite/ld-x86-64/gnu2-tls-2.s   |  13 +++
+ ld/testsuite/ld-i386/gnu2-tls-1.s     |  11 +++
+ ld/testsuite/ld-i386/gnu2-tls-1a.rd   |   7 ++
+ ld/testsuite/ld-i386/gnu2-tls-1b.rd   |   4 +
+ ld/testsuite/ld-i386/i386.exp         |  23 +++++
+ ld/testsuite/ld-x86-64/gnu2-tls-1.s   |  11 +++
+ ld/testsuite/ld-x86-64/gnu2-tls-1a.rd |   7 ++
+ ld/testsuite/ld-x86-64/gnu2-tls-1b.rd |   4 +
  ld/testsuite/ld-x86-64/mark-plt-2.rd  |   7 ++
  ld/testsuite/ld-x86-64/mark-plt-2.s   |  13 +++
- ld/testsuite/ld-x86-64/x86-64.exp     |  53 ++++++++++-
- 26 files changed, 454 insertions(+), 123 deletions(-)
+ ld/testsuite/ld-x86-64/x86-64.exp     |  26 +++++-
+ 36 files changed, 592 insertions(+), 125 deletions(-)
+ create mode 100644 ld/emultempl/elf-i386-glibc.em
+ create mode 100644 ld/emultempl/elf-x86-64-glibc.em
  create mode 100644 ld/emultempl/elf-x86-64.em
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1.rd
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.od
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.s
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.od
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.s
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1c.od
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-2.rd
- create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-2.s
+ create mode 100644 ld/emultempl/elf-x86-glibc.em
+ create mode 100644 ld/emultempl/solaris2-x86-64.em
+ create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1.s
+ create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1a.rd
+ create mode 100644 ld/testsuite/ld-i386/gnu2-tls-1b.rd
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1.s
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
  create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.rd
  create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.s
 
@@ -142,7 +171,7 @@ index accdd6d41a8..feb470fc477 100644
  extern void _bfd_elf_link_add_dt_relr_dependency
    (struct elf_find_verdep_info *);
 diff --git a/bfd/elf-linker-x86.h b/bfd/elf-linker-x86.h
-index 2c98257038f..7656b0a7932 100644
+index 2c98257038f..fe322152e14 100644
 --- a/bfd/elf-linker-x86.h
 +++ b/bfd/elf-linker-x86.h
 @@ -72,6 +72,14 @@ struct elf_linker_x86_params
@@ -150,18 +179,101 @@ index 2c98257038f..7656b0a7932 100644
    unsigned int mark_plt : 1;
  
 +  /* Add the GLIBC_ABI_GNU2_TLS version dependency if input object files
-+     have R_X86_64_TLSDESC_CALL relocation:
++     have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL relocation:
 +     0: Disable.
 +     1: Enable.
 +     2: Auto.  Enable if libc.so has the GLIBC_ABI_GNU2_TLS version.
 +   */
-+  unsigned int gnu2_tls : 2;
++  unsigned int gnu2_tls_version_tag : 2;
 +
    /* X86-64 ISA level needed.  */
    unsigned int isa_level;
  
+diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
+index abe26e476ff..c1115a52d1b 100644
+--- a/bfd/elf32-i386.c
++++ b/bfd/elf32-i386.c
+@@ -1687,6 +1687,10 @@ elf_i386_scan_relocs (bfd *abfd,
+ 	  size_reloc = true;
+ 	  goto do_size;
+ 
++	case R_386_TLS_DESC_CALL:
++	  htab->has_tls_desc_call = 1;
++	  goto need_got;
++
+ 	case R_386_TLS_IE_32:
+ 	case R_386_TLS_IE:
+ 	case R_386_TLS_GOTIE:
+@@ -1698,7 +1702,7 @@ elf_i386_scan_relocs (bfd *abfd,
+ 	case R_386_GOT32X:
+ 	case R_386_TLS_GD:
+ 	case R_386_TLS_GOTDESC:
+-	case R_386_TLS_DESC_CALL:
++ need_got:
+ 	  /* This symbol requires a global offset table entry.  */
+ 	  {
+ 	    int tls_type, old_tls_type;
+@@ -4492,6 +4496,40 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
+   return _bfd_x86_elf_link_setup_gnu_properties (info, &init_table);
+ }
+ 
++static void
++elf_i386_add_glibc_version_dependency
++  (struct elf_find_verdep_info *rinfo)
++{
++  int i = 0;
++  const char *version[3] = { NULL, NULL, NULL };
++  bool auto_version[3] = { false, false, false };
++  struct elf_x86_link_hash_table *htab;
++
++  if (rinfo->info->enable_dt_relr)
++    {
++      version[i] = "GLIBC_ABI_DT_RELR";
++      i++;
++    }
++
++  htab = elf_x86_hash_table (rinfo->info, I386_ELF_DATA);
++  if (htab != NULL)
++    {
++      if (htab->params->gnu2_tls_version_tag && htab->has_tls_desc_call)
++	{
++	  version[i] = "GLIBC_ABI_GNU2_TLS";
++	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU2_TLS
++	     version.  */
++	  if (htab->params->gnu2_tls_version_tag == 2)
++	    auto_version[i] = true;
++	  i++;
++	}
++    }
++
++  if (i != 0)
++    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
++						auto_version);
++}
++
+ #define TARGET_LITTLE_SYM		i386_elf32_vec
+ #define TARGET_LITTLE_NAME		"elf32-i386"
+ #define ELF_ARCH			bfd_arch_i386
+@@ -4532,6 +4570,8 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
+ #define elf_backend_relocate_section	      elf_i386_relocate_section
+ #define elf_backend_setup_gnu_properties      elf_i386_link_setup_gnu_properties
+ #define elf_backend_hide_symbol		      _bfd_x86_elf_hide_symbol
++#define elf_backend_add_glibc_version_dependency \
++  elf_i386_add_glibc_version_dependency
+ 
+ #define elf_backend_linux_prpsinfo32_ugid16	true
+ 
+@@ -4539,6 +4579,8 @@ elf_i386_link_setup_gnu_properties (struct bfd_link_info *info)
+ 
+ #include "elf32-target.h"
+ 
++#undef elf_backend_add_glibc_version_dependency
++
+ /* FreeBSD support.  */
+ 
+ #undef	TARGET_LITTLE_SYM
 diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index b6f97b5b69b..03873a9ed6b 100644
+index b6f97b5b69b..edfa608d2d7 100644
 --- a/bfd/elf64-x86-64.c
 +++ b/bfd/elf64-x86-64.c
 @@ -2694,6 +2694,10 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
@@ -169,7 +281,7 @@ index b6f97b5b69b..03873a9ed6b 100644
  	  break;
  
 +	case R_X86_64_TLSDESC_CALL:
-+	  htab->has_tlsdesc_call = 1;
++	  htab->has_tls_desc_call = 1;
 +	  goto need_got;
 +
  	case R_X86_64_GOTTPOFF:
@@ -203,12 +315,12 @@ index b6f97b5b69b..03873a9ed6b 100644
      {
 -      version[i] = "GLIBC_2.36";
 -      i++;
-+      if (htab->params->gnu2_tls && htab->has_tlsdesc_call)
++      if (htab->params->gnu2_tls_version_tag && htab->has_tls_desc_call)
 +	{
 +	  version[i] = "GLIBC_ABI_GNU2_TLS";
 +	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU2_TLS
 +	     version.  */
-+	  if (htab->params->gnu2_tls == 2)
++	  if (htab->params->gnu2_tls_version_tag == 2)
 +	    auto_version[i] = true;
 +	  i++;
 +	}
@@ -226,6 +338,15 @@ index b6f97b5b69b..03873a9ed6b 100644
  }
  
  static const struct bfd_elf_special_section
+@@ -6355,6 +6373,8 @@ elf_x86_64_special_sections[]=
+ 
+ #include "elf64-target.h"
+ 
++#undef elf_backend_add_glibc_version_dependency
++
+ /* CloudABI support.  */
+ 
+ #undef	TARGET_LITTLE_SYM
 diff --git a/bfd/elflink.c b/bfd/elflink.c
 index 7b0375406ac..ac40423751f 100644
 --- a/bfd/elflink.c
@@ -429,53 +550,53 @@ index 7b0375406ac..ac40423751f 100644
  }
  
 diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
-index f6ee6a65356..8fd2d81ab6b 100644
+index f6ee6a65356..791a2a2592f 100644
 --- a/bfd/elfxx-x86.h
 +++ b/bfd/elfxx-x86.h
 @@ -670,6 +670,10 @@ struct elf_x86_link_hash_table
    /* Number of relative reloc generation pass.  */
    unsigned int generate_relative_reloc_pass;
  
-+  /* TRUE if inputs have R_X86_64_TLSDESC_CALL relocation.  This is
-+     only used for x86-64.  */
-+  unsigned int has_tlsdesc_call : 1;
++  /* TRUE if inputs have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
++     relocation.  */
++  unsigned int has_tls_desc_call : 1;
 +
     /* Value used to fill the unused bytes of the first PLT entry.  This
        is only used for i386.  */
    bfd_byte plt0_pad_byte;
 diff --git a/ld/NEWS b/ld/NEWS
-index 54c1df5aadf..cfb5c9c81df 100644
+index 54c1df5aadf..bacabc8440e 100644
 --- a/ld/NEWS
 +++ b/ld/NEWS
 @@ -1,5 +1,11 @@
  -*- text -*-
  
-+* Add --gnu2-tls-tag/--no-gnu2-tls-tag options to x86-64 ELF linker to
-+  add the GLIBC_ABI_GNU2_TLS version dependency in output if input object
-+  files have R_X86_64_TLSDESC_CALL relocation.  Also added
-+  --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag by
-+  default.
++* Add --gnu2-tls-tag/--no-gnu2-tls-tag options to i386 and x86-64 ELF
++  linkers to add the GLIBC_ABI_GNU2_TLS version dependency in output if
++  input object files have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
++  relocation.  Also added --enable-gnu2-tls-tag configure option to
++  enable --gnu2-tls-tag by default.
 +
  * NaCl target support is removed.
  
  Changes in 2.45:
 diff --git a/ld/config.in b/ld/config.in
-index 37812241bd9..021577dbe4d 100644
+index 37812241bd9..64dbc3e0c88 100644
 --- a/ld/config.in
 +++ b/ld/config.in
 @@ -31,6 +31,10 @@
     when a .note-GNU-stack section is missing. */
  #undef DEFAULT_LD_EXECSTACK
  
-+/* Define to 1 if you want to enable --gnu2-tls-tag in ELF x86-64 linker by
-+   default. */
++/* Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker
++   by default. */
 +#undef DEFAULT_LD_GNU2_TLS_TAG
 +
  /* Define to 1 if you want to enable --rosegment in the ELF linker by default.
     */
  #undef DEFAULT_LD_ROSEGMENT
 diff --git a/ld/configure b/ld/configure
-index 124b44182bc..9c694525488 100755
+index 124b44182bc..6f1a3559964 100755
 --- a/ld/configure
 +++ b/ld/configure
 @@ -851,6 +851,7 @@ enable_textrel_check
@@ -490,7 +611,7 @@ index 124b44182bc..9c694525488 100755
    --enable-separate-code  enable -z separate-code in ELF linker by default
    --enable-rosegment      enable --rosegment in the ELF linker by default
    --enable-mark-plt       enable -z mark-plt in ELF x86-64 linker by default
-+  --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF x86-64 linker by
++  --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF i386/x86-64 linker by
 +                          default
    --enable-memory-seal    enable -z memory-seal in ELF linker by default
    --enable-warn-execstack enable warnings when creating an executable stack
@@ -517,8 +638,8 @@ index 124b44182bc..9c694525488 100755
  fi
  
  
-+# Decide if --gnu2-tls-tag should be enabled in ELF x86-64 linker
-+# by default.
++# Decide if --gnu2-tls-tag should be enabled in ELF i386 and x86-64
++# linkers by default.
 +ac_default_ld_enable_gnu2_tls_tag=unset
 +# Check whether --enable-gnu2-tls-tag was given.
 +if test "${enable_gnu2_tls_tag+set}" = set; then :
@@ -550,19 +671,19 @@ index 124b44182bc..9c694525488 100755
  
  cat >>confdefs.h <<_ACEOF
 diff --git a/ld/configure.ac b/ld/configure.ac
-index e306c1ded4a..d4801fb1333 100644
+index e306c1ded4a..4b9068a415e 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
 @@ -245,6 +245,17 @@ AC_ARG_ENABLE(mark-plt,
    no) ac_default_ld_z_mark_plt=0 ;;
  esac])
  
-+# Decide if --gnu2-tls-tag should be enabled in ELF x86-64 linker
-+# by default.
++# Decide if --gnu2-tls-tag should be enabled in ELF i386 and x86-64
++# linkers by default.
 +ac_default_ld_enable_gnu2_tls_tag=unset
 +AC_ARG_ENABLE(gnu2-tls-tag,
 +	      AS_HELP_STRING([--enable-gnu2-tls-tag],
-+	      [enable --gnu2-tls-tag in ELF x86-64 linker by default]),
++	      [enable --gnu2-tls-tag in ELF i386/x86-64 linker by default]),
 +[case "${enableval}" in
 +  yes) ac_default_ld_enable_gnu2_tls_tag=1 ;;
 +  no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
@@ -582,12 +703,12 @@ index e306c1ded4a..d4801fb1333 100644
 +fi
 +AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU2_TLS_TAG,
 +  $ac_default_ld_enable_gnu2_tls_tag,
-+  [Define to 1 if you want to enable --gnu2-tls-tag in ELF x86-64 linker by default.])
++  [Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker by default.])
  
  AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK,
    $ac_default_ld_warn_execstack,
 diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
-index 6a92eec129d..4807413d133 100644
+index 6a92eec129d..4db1a979058 100644
 --- a/ld/emulparams/elf32_x86_64.sh
 +++ b/ld/emulparams/elf32_x86_64.sh
 @@ -20,7 +20,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
@@ -595,12 +716,45 @@ index 6a92eec129d..4807413d133 100644
  MACHINE=
  TEMPLATE_NAME=elf
 -EXTRA_EM_FILE="elf-x86"
-+EXTRA_EM_FILE="elf-x86-64"
++EXTRA_EM_FILE="elf-x86-64-glibc"
+ GENERATE_SHLIB_SCRIPT=yes
+ GENERATE_PIE_SCRIPT=yes
+ NO_SMALL_DATA=yes
+diff --git a/ld/emulparams/elf_i386.sh b/ld/emulparams/elf_i386.sh
+index 6f698bb0b06..51a650f692e 100644
+--- a/ld/emulparams/elf_i386.sh
++++ b/ld/emulparams/elf_i386.sh
+@@ -17,7 +17,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
+ ARCH=i386
+ MACHINE=
+ TEMPLATE_NAME=elf
+-EXTRA_EM_FILE="elf-x86"
++EXTRA_EM_FILE="elf-i386-glibc"
  GENERATE_SHLIB_SCRIPT=yes
  GENERATE_PIE_SCRIPT=yes
  NO_SMALL_DATA=yes
+diff --git a/ld/emulparams/elf_i386_fbsd.sh b/ld/emulparams/elf_i386_fbsd.sh
+index d1d6604504a..d39a5cf882f 100644
+--- a/ld/emulparams/elf_i386_fbsd.sh
++++ b/ld/emulparams/elf_i386_fbsd.sh
+@@ -1,3 +1,4 @@
+ source_sh ${srcdir}/emulparams/elf_i386.sh
+ source_sh ${srcdir}/emulparams/elf_fbsd.sh
++EXTRA_EM_FILE="elf-x86"
+ OUTPUT_FORMAT="elf32-i386-freebsd"
+diff --git a/ld/emulparams/elf_i386_haiku.sh b/ld/emulparams/elf_i386_haiku.sh
+index 6c4001e4e05..c931c0e3f91 100644
+--- a/ld/emulparams/elf_i386_haiku.sh
++++ b/ld/emulparams/elf_i386_haiku.sh
+@@ -1,5 +1,6 @@
+ source_sh ${srcdir}/emulparams/elf_i386.sh
+ source_sh ${srcdir}/emulparams/elf_haiku.sh
++EXTRA_EM_FILE="elf-x86"
+ TEXT_START_ADDR=0x200000
+ NONPAGED_TEXT_START_ADDR=0x200000
+ MAXPAGESIZE=0x1000
 diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
-index 92449745c7a..39cbf2ca189 100644
+index 92449745c7a..6e66f2e1035 100644
 --- a/ld/emulparams/elf_x86_64.sh
 +++ b/ld/emulparams/elf_x86_64.sh
 @@ -21,7 +21,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
@@ -608,16 +762,131 @@ index 92449745c7a..39cbf2ca189 100644
  MACHINE=
  TEMPLATE_NAME=elf
 -EXTRA_EM_FILE="elf-x86"
-+EXTRA_EM_FILE="elf-x86-64"
++EXTRA_EM_FILE="elf-x86-64-glibc"
  GENERATE_SHLIB_SCRIPT=yes
  GENERATE_PIE_SCRIPT=yes
  NO_SMALL_DATA=yes
+diff --git a/ld/emulparams/elf_x86_64_cloudabi.sh b/ld/emulparams/elf_x86_64_cloudabi.sh
+index 1f8732ebbad..e605233391b 100644
+--- a/ld/emulparams/elf_x86_64_cloudabi.sh
++++ b/ld/emulparams/elf_x86_64_cloudabi.sh
+@@ -1,2 +1,3 @@
+ source_sh ${srcdir}/emulparams/elf_x86_64.sh
++EXTRA_EM_FILE="elf-x86-64"
+ OUTPUT_FORMAT="elf64-x86-64-cloudabi"
+diff --git a/ld/emulparams/elf_x86_64_fbsd.sh b/ld/emulparams/elf_x86_64_fbsd.sh
+index 7ef974addca..17fdc83b075 100644
+--- a/ld/emulparams/elf_x86_64_fbsd.sh
++++ b/ld/emulparams/elf_x86_64_fbsd.sh
+@@ -1,3 +1,4 @@
+ source_sh ${srcdir}/emulparams/elf_x86_64.sh
+ source_sh ${srcdir}/emulparams/elf_fbsd.sh
++EXTRA_EM_FILE="elf-x86-64"
+ OUTPUT_FORMAT="elf64-x86-64-freebsd"
+diff --git a/ld/emulparams/elf_x86_64_haiku.sh b/ld/emulparams/elf_x86_64_haiku.sh
+index e6231cdfb15..7b033840fb6 100644
+--- a/ld/emulparams/elf_x86_64_haiku.sh
++++ b/ld/emulparams/elf_x86_64_haiku.sh
+@@ -1,2 +1,3 @@
+ source_sh ${srcdir}/emulparams/elf_x86_64.sh
+ source_sh ${srcdir}/emulparams/elf_haiku.sh
++EXTRA_EM_FILE="elf-x86-64"
+diff --git a/ld/emultempl/elf-i386-glibc.em b/ld/emultempl/elf-i386-glibc.em
+new file mode 100644
+index 00000000000..547823750a4
+--- /dev/null
++++ b/ld/emultempl/elf-i386-glibc.em
+@@ -0,0 +1,41 @@
++# This shell script emits a C file. -*- C -*-
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the license, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; see the file COPYING3. If not,
++# see <http://www.gnu.org/licenses/>.
++#
++
++# This file is sourced from elf.em, and defines i386 glibc specific
++# routines.
++#
++
++source_em ${srcdir}/emultempl/elf-x86.em
++source_em ${srcdir}/emultempl/elf-x86-glibc.em
++
++# Define some shell vars to insert bits of code into the standard elf
++# parse_args and list_options functions.
++#
++
++fragment <<EOF
++static void
++elf_i386_glibc_before_parse (void)
++{
++  elf_x86_before_parse ();
++  elf_x86_glibc_before_parse ();
++}
++EOF
++
++LDEMUL_BEFORE_PARSE=elf_i386_glibc_before_parse
+diff --git a/ld/emultempl/elf-x86-64-glibc.em b/ld/emultempl/elf-x86-64-glibc.em
+new file mode 100644
+index 00000000000..1e62d4f48bc
+--- /dev/null
++++ b/ld/emultempl/elf-x86-64-glibc.em
+@@ -0,0 +1,37 @@
++# This shell script emits a C file. -*- C -*-
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the license, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; see the file COPYING3. If not,
++# see <http://www.gnu.org/licenses/>.
++#
++
++# This file is sourced from elf.em, and defines x86-64 glibc specific
++# routines.
++#
++
++source_em ${srcdir}/emultempl/elf-x86-64.em
++source_em ${srcdir}/emultempl/elf-x86-glibc.em
++
++fragment <<EOF
++static void
++elf_x86_64_glibc_before_parse (void)
++{
++  elf_x86_64_before_parse ();
++  elf_x86_glibc_before_parse ();
++}
++EOF
++
++LDEMUL_BEFORE_PARSE=elf_x86_64_glibc_before_parse
 diff --git a/ld/emultempl/elf-x86-64.em b/ld/emultempl/elf-x86-64.em
 new file mode 100644
-index 00000000000..6bb7844741c
+index 00000000000..ca7ccc0f478
 --- /dev/null
 +++ b/ld/emultempl/elf-x86-64.em
-@@ -0,0 +1,108 @@
+@@ -0,0 +1,68 @@
 +# This shell script emits a C file. -*- C -*-
 +#   Copyright (C) 2025 Free Software Foundation, Inc.
 +#
@@ -648,7 +917,6 @@ index 00000000000..6bb7844741c
 +elf_x86_64_before_parse (void)
 +{
 +  params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
-+  params.gnu2_tls = DEFAULT_LD_GNU2_TLS_TAG;
 +
 +  elf_x86_before_parse ();
 +}
@@ -687,45 +955,82 @@ index 00000000000..6bb7844741c
 +
 +LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
 +LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
+diff --git a/ld/emultempl/elf-x86-glibc.em b/ld/emultempl/elf-x86-glibc.em
+new file mode 100644
+index 00000000000..0fc37a6b59c
+--- /dev/null
++++ b/ld/emultempl/elf-x86-glibc.em
+@@ -0,0 +1,70 @@
++# This shell script emits a C file. -*- C -*-
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the license, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; see the file COPYING3. If not,
++# see <http://www.gnu.org/licenses/>.
++#
++
++# This file is sourced from elf.em, and defines x86 glibc specific
++# routines.
++#
++
++fragment <<EOF
++static void
++elf_x86_glibc_before_parse (void)
++{
++  params.gnu2_tls_version_tag = DEFAULT_LD_GNU2_TLS_TAG;
++}
++EOF
 +
 +# Define some shell vars to insert bits of code into the standard elf
 +# parse_args and list_options functions.
 +#
 +
-+PARSE_AND_LIST_LONGOPTS_X86_64='
-+  { "gnu2-tls-tag", no_argument, NULL, OPTION_GNU2_TLS_TAG },
-+  { "no-gnu2-tls-tag", no_argument, NULL, OPTION_NO_GNU2_TLS_TAG },
++PARSE_AND_LIST_LONGOPTS_X86='
++  { "gnu2-tls-tag", no_argument, NULL, OPTION_GNU2_TLS_VERSION_TAG },
++  { "no-gnu2-tls-tag", no_argument, NULL, OPTION_NO_GNU2_TLS_VERSION_TAG },
 +'
 +
-+PARSE_AND_LIST_OPTIONS_X86_64='
++PARSE_AND_LIST_OPTIONS_X86='
 +  if (DEFAULT_LD_GNU2_TLS_TAG == 0)
 +    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency\n\
-+  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency (default)\n"));
++  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency\n\
++  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency (default)\n"));
 +  else if (DEFAULT_LD_GNU2_TLS_TAG == 1)
 +    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency (default)\n\
-+  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency\n"));
++  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency (default)\n\
++  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency\n"));
 +  else
 +    fprintf (file, _("\
-+  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency (auto)\n\
++  --gnu2-tls-tag              Add GNU2_ABI_GNU2_TLS dependency (auto)\n\
 +                                when no options are specified (default)\n\
-+  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency\n"));
++  --no-gnu2-tls-tag           Do not add GNU2_ABI_GNU2_TLS dependency\n"));
 +'
 +
-+PARSE_AND_LIST_ARGS_CASES_X86_64='
-+    case OPTION_GNU2_TLS_TAG:
-+      params.gnu2_tls = 1;
++PARSE_AND_LIST_ARGS_CASES_X86='
++    case OPTION_GNU2_TLS_VERSION_TAG:
++      params.gnu2_tls_version_tag = 1;
 +      break;
 +
-+    case OPTION_NO_GNU2_TLS_TAG:
-+      params.gnu2_tls = 0;
++    case OPTION_NO_GNU2_TLS_VERSION_TAG:
++      params.gnu2_tls_version_tag = 0;
 +      break;
 +'
 +
-+PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_X86_64"
-+PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86_64"
-+PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_X86_64"
++PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_X86"
++PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86"
++PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_X86"
 diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em
 index f72a0cd0d4a..411a4d62294 100644
 --- a/ld/emultempl/elf-x86.em
@@ -792,49 +1097,97 @@ index f72a0cd0d4a..411a4d62294 100644
 -LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
 -    ;;
 -esac
+diff --git a/ld/emultempl/solaris2-x86-64.em b/ld/emultempl/solaris2-x86-64.em
+new file mode 100644
+index 00000000000..788b3cf4800
+--- /dev/null
++++ b/ld/emultempl/solaris2-x86-64.em
+@@ -0,0 +1,23 @@
++# This shell script emits a C file. -*- C -*-
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
++# MA 02110-1301, USA.
++#
++
++source_em "${srcdir}/emultempl/elf-x86-64.em"
++source_em "${srcdir}/emultempl/solaris2.em"
 diff --git a/ld/ld.texi b/ld/ld.texi
-index 413335ad765..7afff6e8ac7 100644
+index 413335ad765..0e13f7d8e35 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -1743,6 +1743,19 @@ Supported for Linux/i386 and Linux/x86_64.
+@@ -1745,6 +1745,21 @@ Supported for Linux/i386 and Linux/x86_64.
  
- @end table
+ Other keywords are ignored for Solaris compatibility.
  
 +@item --gnu2-tls-tag
 +@itemx --no-gnu2-tls-tag
 +Add @code{GLIBC_ABI_GNU2_TLS} version tag dependency in output programs
 +and shared libraries when linking against glibc if input relocatable
-+object files have @code{R_X86_64_TLSDESC_CALL} relocation.  The output
-+will fail to load and run at run-time against glibc which doesn't define
-+the @code{GLIBC_ABI_GNU2_TLS} version tag.  Unless disabled by the
++object files have @code{R_386_TLS_DESC_CALL} or
++@code{R_X86_64_TLSDESC_CALL} relocation.  The output will fail to load
++and run at run-time against glibc which doesn't define the
++@code{GLIBC_ABI_GNU2_TLS} version tag.  Unless disabled by the
 +@option{--disable-gnu2-tls-tag} configure option at the linker build
 +time, when no options are specified, linker will add the
 +@code{GLIBC_ABI_GNU2_TLS} version tag dependency if inputs have
-+@code{R_X86_64_TLSDESC_CALL} relocation and libc.so defines the
-+@code{GLIBC_ABI_GNU2_TLS} version tag.  Supported for Linux/x86_64.
++@code{R_386_TLS_DESC_CALL} or @code{R_X86_64_TLSDESC_CALL} relocation
++and libc.so defines the @code{GLIBC_ABI_GNU2_TLS} version tag.
++Supported for Linux/i386 and Linux/x86_64.
 +
- Other keywords are ignored for Solaris compatibility.
- 
  @kindex -(
+ @cindex groups of archives
+ @item -( @var{archives} -)
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 815da76a4c0..58bbd5771da 100644
+index 815da76a4c0..286ab0ba6d1 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
 @@ -471,6 +471,9 @@ enum option_values
    OPTION_NO_LITERAL_MOVEMENT,
    OPTION_ABI_WINDOWED,
    OPTION_ABI_CALL0,
-+  /* Used by emultempl/elf-x86-64.em.  */
-+  OPTION_GNU2_TLS_TAG,
-+  OPTION_NO_GNU2_TLS_TAG,
++  /* Used by emultempl/elf-x86-glibc.em.  */
++  OPTION_GNU2_TLS_VERSION_TAG,
++  OPTION_NO_GNU2_TLS_VERSION_TAG,
  };
  
  /* The initial parser states.  */
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1.rd
+diff --git a/ld/testsuite/ld-i386/gnu2-tls-1.s b/ld/testsuite/ld-i386/gnu2-tls-1.s
+new file mode 100644
+index 00000000000..e3841c71653
+--- /dev/null
++++ b/ld/testsuite/ld-i386/gnu2-tls-1.s
+@@ -0,0 +1,11 @@
++	.section	.text.startup,"ax",@progbits
++	.p2align 4
++	.globl	main
++	.type	main, @function
++main:
++	leal	ld@TLSDESC(%ebx), %eax
++	call	*ld@TLSCALL(%eax)
++	addl	%gs:0, %eax
++	ret
++	.size	main, .-main
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-i386/gnu2-tls-1a.rd b/ld/testsuite/ld-i386/gnu2-tls-1a.rd
 new file mode 100644
 index 00000000000..3eb926a227c
 --- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1.rd
++++ b/ld/testsuite/ld-i386/gnu2-tls-1a.rd
 @@ -0,0 +1,7 @@
 +#...
 +Version needs section '.gnu.version_r' contains 1 entry:
@@ -843,127 +1196,90 @@ index 00000000000..3eb926a227c
 +#...
 +  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
 +#pass
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.od b/ld/testsuite/ld-x86-64/gnu2-tls-1a.od
+diff --git a/ld/testsuite/ld-i386/gnu2-tls-1b.rd b/ld/testsuite/ld-i386/gnu2-tls-1b.rd
 new file mode 100644
-index 00000000000..e237b26898d
+index 00000000000..33ef8acb232
 --- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.od
-@@ -0,0 +1,13 @@
-+
-+.*: +file format .*
++++ b/ld/testsuite/ld-i386/gnu2-tls-1b.rd
+@@ -0,0 +1,4 @@
++#failif
 +#...
-+[a-f0-9]+ <main>:
-+ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
-+ +[a-f0-9]+:	48 8d 05 ([0-9a-f]{2} ){4}	lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo@@Base\+0x[a-f0-9]+>
-+ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
-+ +[a-f0-9]+:	ff 10                	call   \*\(%rax\)
-+ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
-+ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
-+ +[a-f0-9]+:	c3                   	ret
-+ +[a-f0-9]+:	90                   	nop
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.s b/ld/testsuite/ld-x86-64/gnu2-tls-1a.s
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
++#...
+diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
+index 86748b1a494..74ef1672f86 100644
+--- a/ld/testsuite/ld-i386/i386.exp
++++ b/ld/testsuite/ld-i386/i386.exp
+@@ -1516,6 +1516,29 @@ run_ld_link_tests [list \
+     ] \
+ ]
+ 
++# The musl C library does not support --gnu2-tls-tag.
++if { ![istarget *-*-musl]
++     && [check_compiler_available] } {
++    run_cc_link_tests [list \
++	[list \
++	    "Build gnu2-tls-1a.so" \
++	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1.s } \
++	    {{readelf {-W --version-info} gnu2-tls-1a.rd}} \
++	    "gnu2-tls-1a.so" \
++	] \
++	[list \
++	    "Build gnu2-tls-1b.so" \
++	    "-shared -Wl,--no-as-needed,--no-gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1.s } \
++	    {{readelf {-W --version-info} gnu2-tls-1b.rd}} \
++	    "gnu2-tls-1b.so" \
++	] \
++    ]
++}
++
+ # Linux only tests
+ run_dump_test "pltgot-1"
+ run_dump_test "pltgot-2"
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1.s b/ld/testsuite/ld-x86-64/gnu2-tls-1.s
 new file mode 100644
-index 00000000000..b8c004538ff
+index 00000000000..eca788c9ca2
 --- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.s
-@@ -0,0 +1,14 @@
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1.s
+@@ -0,0 +1,11 @@
 +	.section	.text.startup,"ax",@progbits
 +	.p2align 4
 +	.globl	main
 +	.type	main, @function
 +main:
-+	subq	$8, %rsp
 +	leaq	foo@TLSDESC(%rip), %rax
-+	.nops 10
 +	call	*foo@TLSCALL(%rax)
 +	movl	%fs:(%rax), %eax
-+	addq	$8, %rsp
 +	ret
 +	.size	main, .-main
 +	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.od b/ld/testsuite/ld-x86-64/gnu2-tls-1b.od
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
 new file mode 100644
-index 00000000000..8bd685006bd
+index 00000000000..3eb926a227c
 --- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.od
-@@ -0,0 +1,13 @@
-+
-+.*: +file format .*
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.rd
+@@ -0,0 +1,7 @@
 +#...
-+[a-f0-9]+ <main>:
-+ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
-+ +[a-f0-9]+:	48 c7 c0 fc ff ff ff 	mov    \$0xfffffffffffffffc,%rax
-+ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
-+ +[a-f0-9]+:	66 90                	xchg   %ax,%ax
-+ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
-+ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
-+ +[a-f0-9]+:	c3                   	ret
-+ +[a-f0-9]+:	90                   	nop
-+#pass
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.s b/ld/testsuite/ld-x86-64/gnu2-tls-1b.s
-new file mode 100644
-index 00000000000..fcc355f7e5c
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.s
-@@ -0,0 +1,9 @@
-+	.text
-+	.globl	foo
-+	.section	.tbss,"awT",@nobits
-+	.align 4
-+	.type	foo, @object
-+	.size	foo, 4
-+foo:
-+	.zero	4
-+	.section	.note.GNU-stack,"",@progbits
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1c.od b/ld/testsuite/ld-x86-64/gnu2-tls-1c.od
-new file mode 100644
-index 00000000000..8bd685006bd
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-1c.od
-@@ -0,0 +1,13 @@
-+
-+.*: +file format .*
++Version needs section '.gnu.version_r' contains 1 entry:
++ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
++ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
 +#...
-+[a-f0-9]+ <main>:
-+ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
-+ +[a-f0-9]+:	48 c7 c0 fc ff ff ff 	mov    \$0xfffffffffffffffc,%rax
-+ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
-+ +[a-f0-9]+:	66 90                	xchg   %ax,%ax
-+ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
-+ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
-+ +[a-f0-9]+:	c3                   	ret
-+ +[a-f0-9]+:	90                   	nop
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
 +#pass
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-2.rd b/ld/testsuite/ld-x86-64/gnu2-tls-2.rd
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
 new file mode 100644
 index 00000000000..33ef8acb232
 --- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-2.rd
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.rd
 @@ -0,0 +1,4 @@
 +#failif
 +#...
 +  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
 +#...
-diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-2.s b/ld/testsuite/ld-x86-64/gnu2-tls-2.s
-new file mode 100644
-index 00000000000..d957eb71f6d
---- /dev/null
-+++ b/ld/testsuite/ld-x86-64/gnu2-tls-2.s
-@@ -0,0 +1,13 @@
-+	.text
-+	.p2align 4
-+	.globl	func
-+	.type	func, @function
-+func:
-+	leaq	foo@tlsld(%rip), %rdi
-+	call	__tls_get_addr@PLT
-+	data16	leaq	foo@tlsgd(%rip), %rdi
-+	.value	0x6666
-+	rex64
-+	call	__tls_get_addr@PLT
-+	.size	func, .-func
-+	.section	.note.GNU-stack,"",@progbits
 diff --git a/ld/testsuite/ld-x86-64/mark-plt-2.rd b/ld/testsuite/ld-x86-64/mark-plt-2.rd
 new file mode 100644
 index 00000000000..b0ed7024420
@@ -997,7 +1313,7 @@ index 00000000000..c816567c204
 +	ret
 +	.section	.note.GNU-stack,"",@progbits
 diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
-index 6b86bc3d018..2ee12a2ef55 100644
+index 6b86bc3d018..1b011451bcc 100644
 --- a/ld/testsuite/ld-x86-64/x86-64.exp
 +++ b/ld/testsuite/ld-x86-64/x86-64.exp
 @@ -2358,7 +2358,7 @@ run_dump_test "ibt-plt-3b-x32"
@@ -1009,7 +1325,7 @@ index 6b86bc3d018..2ee12a2ef55 100644
  if { [istarget "x86_64-*-musl*"]} {
      set ASFLAGS "$saved_ASFLAGS"
      return
-@@ -2384,6 +2384,57 @@ if { [check_compiler_available] } {
+@@ -2384,6 +2384,30 @@ if { [check_compiler_available] } {
  	     {readelf {-W --version-info} mark-plt-1b.rd}} \
  	    "mark-plt-1.so" \
  	] \
@@ -1022,53 +1338,26 @@ index 6b86bc3d018..2ee12a2ef55 100644
 +	    "mark-plt-2.so" \
 +	] \
 +	[list \
-+	    "Build gnu2-tls-1.so" \
-+	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
-+	    {{objdump {-dw} gnu2-tls-1a.od}
-+	     {readelf {-W --version-info} gnu2-tls-1.rd}} \
-+	    "gnu2-tls-1.so" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-1-no-gnu2-tls.so" \
++	    "Build gnu2-tls-1a.so" \
 +	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
 +	    "-fPIC" \
 +	    { gnu2-tls-1.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-2.rd}} \
-+	    "gnu2-tls-1-no-gnu2-tls.so" \
++	    {{readelf {-W --version-info} gnu2-tls-1a.rd}} \
++	    "gnu2-tls-1a.so" \
 +	] \
 +	[list \
-+	    "Build gnu2-tls-1 (PDE)" \
-+	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "Build gnu2-tls-1b.so" \
++	    "-shared -Wl,--no-as-needed,--no-gnu2-tls-tag" \
 +	    "-fPIC" \
-+	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
-+	    {{objdump {-dw} gnu2-tls-1b.od}
-+	     {readelf {-W --version-info} gnu2-tls-2.rd}} \
-+	    "gnu2-tls-1.pde" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-1 (PIE)" \
-+	    "-pie -Wl,--no-as-needed,--gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
-+	    {{objdump {-dw} gnu2-tls-1c.od}
-+	     {readelf {-W --version-info} gnu2-tls-2.rd}} \
-+	    "gnu2-tls-1.pie" \
-+	] \
-+	[list \
-+	    "Build gnu2-tls-2.so" \
-+	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
-+	    "-fPIC" \
-+	    { gnu2-tls-2.s } \
-+	    {{readelf {-W --version-info} gnu2-tls-2.rd}} \
-+	    "gnu2-tls-2.s.so" \
++	    { gnu2-tls-1.s } \
++	    {{readelf {-W --version-info} gnu2-tls-1b.rd}} \
++	    "gnu2-tls-1b.so" \
 +	] \
      ]
  }
  
 
-base-commit: a5858e81363051a818ea163d52f62d8251097d11
+base-commit: b6ebe65cdac1afc15d5459318007be2d1d8832d0
 -- 
 2.50.1
 

diff --git a/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch b/9999/0009-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
similarity index 91%
rename from 9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
rename to 9999/0009-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
index 24c5262..c9c7175 100644
--- a/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
+++ b/9999/0009-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
@@ -1,7 +1,10 @@
-From ab490c8962810cab7d8eb788122012a1884c05ff Mon Sep 17 00:00:00 2001
+From 9269afaad66f2d88126768e4c647ba711117bcca Mon Sep 17 00:00:00 2001
+Message-ID: <9269afaad66f2d88126768e4c647ba711117bcca.1755548203.git.sam@gentoo.org>
+In-Reply-To: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
+References: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 17 Aug 2025 10:09:25 -0700
-Subject: [PATCH] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
+Date: Mon, 18 Aug 2025 13:13:21 -0700
+Subject: [PATCH 2/3] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
 
 On Linux/x86-64, programs and shared libraries created with -z mark-plt
 have the GLIBC_2.36 version tag dependency since -z mark-plt uses the
@@ -68,7 +71,7 @@ index feb470fc477..de7cc410a99 100644
  
  extern void _bfd_elf_link_add_dt_relr_dependency
 diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
-index 03873a9ed6b..db3c20679a3 100644
+index edfa608d2d7..31a4b0ce489 100644
 --- a/bfd/elf64-x86-64.c
 +++ b/bfd/elf64-x86-64.c
 @@ -6246,7 +6246,7 @@ static void

diff --git a/9999/0010-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch b/9999/0010-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
new file mode 100644
index 0000000..8a758c8
--- /dev/null
+++ b/9999/0010-i386-Add-GLIBC_ABI_GNU_TLS-version-dependency.patch
@@ -0,0 +1,470 @@
+From 7a3c2c05795a290a1436e0ca0f21514325c8ef44 Mon Sep 17 00:00:00 2001
+Message-ID: <7a3c2c05795a290a1436e0ca0f21514325c8ef44.1755548203.git.sam@gentoo.org>
+In-Reply-To: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
+References: <40fd19259a3b9a576bedba9f9ce236d2f1b42da9.1755548203.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Mon, 18 Aug 2025 13:13:22 -0700
+Subject: [PATCH 3/3] i386: Add GLIBC_ABI_GNU_TLS version dependency
+
+On Linux/i386, programs and shared libraries compiled with
+-mtls-dialect=gnu may fail silently at run-time against glibc without
+the GNU TLS run-time fix for:
+
+https://sourceware.org/bugzilla/show_bug.cgi?id=32996
+
+The glibc version tag, GLIBC_ABI_GNU_TLS, has been added to indicate
+that glibc has the working GNU TLS run-time:
+
+commit ed1b7a5a489ab555a27fad9c101ebe2e1c1ba881
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Mon Jul 28 12:16:11 2025 -0700
+
+    i386: Add GLIBC_ABI_GNU_TLS version [BZ #33221]
+
+Add the --gnu-tls-tag option to x86-64 ELF linker to add the
+GLIBC_ABI_GNU_TLS version dependency in output programs and shared
+libraries when linking against glibc if input relocatable object files
+call ___tls_get_addr.  The output will fail to load and run at run-time
+against glibc which doesn't define the GLIBC_ABI_GNU_TLS version.
+
+Add the --enable-gnu-tls-tag configure option to enable --gnu-tls-tag
+by default.  If unspecified, linker will add the GLIBC_ABI_GNU_TLS
+version dependency if input call ___tls_get_addr and libc.so defines
+the GLIBC_ABI_GNU2_TLS version.
+
+bfd/
+
+	PR ld/33287
+	* elf-linker-x86.h (elf_linker_x86_params): Add
+	gnu_tls_version_tag.
+	* elf32-i386.c (elf_backend_add_glibc_version_dependency): Add
+	GLIBC_ABI_GNU_TLS support.
+	* elfxx-x86.c (_bfd_x86_elf_link_check_relocs): Set
+	has_tls_get_addr_call to 1 if ___tls_get_addr is used.
+	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tls_get_addr_call.
+
+ld/
+
+	PR ld/33287
+	* Mention --gnu-tls-tag, --no-gnu-tls-tag and --enable-gnu-tls-tag.
+	* config.in: Regenerated.
+	* configure: Likewise.
+	* configure.ac: Add --enable-gnu-tls-tag.
+	* ld.texi: Document --gnu-tls-tag and --enable-gnu-tls-tag.
+	* ldlex.h (option_values): Add OPTION_GNU_TLS_VERSION_TAG and
+	OPTION_NO_GNU_TLS_VERSION_TAG.
+	* emultempl/elf-i386-glibc.em (elf_i386_glibc_before_parse):
+	Initialize params.gnu_tls_version_tag.
+	(PARSE_AND_LIST_LONGOPTS_386): New.
+	(PARSE_AND_LIST_OPTIONS_386): Likewise.
+	(PARSE_AND_LIST_ARGS_CASES_386): Likewise.
+	(PARSE_AND_LIST_LONGOPTS): Append $PARSE_AND_LIST_LONGOPTS_386.
+	(PARSE_AND_LIST_OPTIONS): Append $PARSE_AND_LIST_OPTIONS_386.
+	(PARSE_AND_LIST_ARGS_CASES): Append
+	$PARSE_AND_LIST_ARGS_CASES_386.
+	* testsuite/ld-i386/gnu-tls-1.s: Likewise.
+	* testsuite/ld-i386/gnu-tls-1a.rd: Likewise.
+	* testsuite/ld-i386/gnu-tls-1b.rd: Likewise.
+	* testsuite/ld-i386/i386.exp: Run PR ld/33287 tests.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-linker-x86.h               |  9 ++++++++
+ bfd/elf32-i386.c                   | 14 ++++++++++--
+ bfd/elfxx-x86.c                    |  2 ++
+ bfd/elfxx-x86.h                    |  3 +++
+ ld/NEWS                            |  5 +++++
+ ld/config.in                       |  4 ++++
+ ld/configure                       | 28 +++++++++++++++++++++--
+ ld/configure.ac                    | 19 ++++++++++++++++
+ ld/emultempl/elf-i386-glibc.em     | 36 ++++++++++++++++++++++++++++++
+ ld/ld.texi                         | 13 +++++++++++
+ ld/ldlex.h                         |  3 +++
+ ld/testsuite/ld-i386/gnu-tls-1.s   |  9 ++++++++
+ ld/testsuite/ld-i386/gnu-tls-1a.rd |  7 ++++++
+ ld/testsuite/ld-i386/gnu-tls-1b.rd |  4 ++++
+ ld/testsuite/ld-i386/i386.exp      | 18 ++++++++++++++-
+ 15 files changed, 169 insertions(+), 5 deletions(-)
+ create mode 100644 ld/testsuite/ld-i386/gnu-tls-1.s
+ create mode 100644 ld/testsuite/ld-i386/gnu-tls-1a.rd
+ create mode 100644 ld/testsuite/ld-i386/gnu-tls-1b.rd
+
+diff --git a/bfd/elf-linker-x86.h b/bfd/elf-linker-x86.h
+index fe322152e14..cdd739e572a 100644
+--- a/bfd/elf-linker-x86.h
++++ b/bfd/elf-linker-x86.h
+@@ -80,6 +80,15 @@ struct elf_linker_x86_params
+    */
+   unsigned int gnu2_tls_version_tag : 2;
+ 
++  /* Add the GLIBC_ABI_GNU_TLS version dependency if input object files
++     call ___tls_get_addr:
++     0: Disable.
++     1: Enable.
++     2: Auto.  Enable if libc.so has the GLIBC_ABI_GNU_TLS version.
++     This is only used by i386.
++   */
++  unsigned int gnu_tls_version_tag : 2;
++
+   /* X86-64 ISA level needed.  */
+   unsigned int isa_level;
+ 
+diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
+index c1115a52d1b..3f1a0b14577 100644
+--- a/bfd/elf32-i386.c
++++ b/bfd/elf32-i386.c
+@@ -4501,8 +4501,8 @@ elf_i386_add_glibc_version_dependency
+   (struct elf_find_verdep_info *rinfo)
+ {
+   int i = 0;
+-  const char *version[3] = { NULL, NULL, NULL };
+-  bool auto_version[3] = { false, false, false };
++  const char *version[4] = { NULL, NULL, NULL, NULL };
++  bool auto_version[4] = { false, false, false, false };
+   struct elf_x86_link_hash_table *htab;
+ 
+   if (rinfo->info->enable_dt_relr)
+@@ -4523,6 +4523,16 @@ elf_i386_add_glibc_version_dependency
+ 	    auto_version[i] = true;
+ 	  i++;
+ 	}
++      if (htab->params->gnu_tls_version_tag
++	  && htab->has_tls_get_addr_call)
++	{
++	  version[i] = "GLIBC_ABI_GNU_TLS";
++	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU_TLS
++	     version.  */
++	  if (htab->params->gnu_tls_version_tag == 2)
++	    auto_version[i] = true;
++	  i++;
++	}
+     }
+ 
+   if (i != 0)
+diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
+index e2c61b85fc6..3de48397e78 100644
+--- a/bfd/elfxx-x86.c
++++ b/bfd/elfxx-x86.c
+@@ -882,6 +882,8 @@ _bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
+ 		  h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ 		  elf_x86_hash_entry (h)->tls_get_addr = 1;
+ 		}
++
++	      htab->has_tls_get_addr_call = 1;
+ 	    }
+ 
+ 	  /* Pass NULL for __ehdr_start which will be defined by
+diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
+index 791a2a2592f..2a28987f208 100644
+--- a/bfd/elfxx-x86.h
++++ b/bfd/elfxx-x86.h
+@@ -674,6 +674,9 @@ struct elf_x86_link_hash_table
+      relocation.  */
+   unsigned int has_tls_desc_call : 1;
+ 
++  /* TRUE if inputs call ___tls_get_addr.  This is only used for i386.  */
++  unsigned int has_tls_get_addr_call : 1;
++
+    /* Value used to fill the unused bytes of the first PLT entry.  This
+       is only used for i386.  */
+   bfd_byte plt0_pad_byte;
+diff --git a/ld/NEWS b/ld/NEWS
+index bacabc8440e..8794e883522 100644
+--- a/ld/NEWS
++++ b/ld/NEWS
+@@ -1,5 +1,10 @@
+ -*- text -*-
+ 
++* Add --gnu-tls-tag/--no-gnu-tls-tag options to i386 ELF linker to add
++  the GLIBC_ABI_GNU_TLS version dependency in output if input object
++  files call ___tls_get_addr.  Also added --enable-gnu-tls-tag configure
++  option to enable --gnu-tls-tag by default.
++
+ * Add --gnu2-tls-tag/--no-gnu2-tls-tag options to i386 and x86-64 ELF
+   linkers to add the GLIBC_ABI_GNU2_TLS version dependency in output if
+   input object files have R_386_TLS_DESC_CALL or R_X86_64_TLSDESC_CALL
+diff --git a/ld/config.in b/ld/config.in
+index 64dbc3e0c88..790efd336be 100644
+--- a/ld/config.in
++++ b/ld/config.in
+@@ -35,6 +35,10 @@
+    by default. */
+ #undef DEFAULT_LD_GNU2_TLS_TAG
+ 
++/* Define to 1 if you want to enable --gnu-tls-tag in ELF i386 linker by
++   default. */
++#undef DEFAULT_LD_GNU_TLS_TAG
++
+ /* Define to 1 if you want to enable --rosegment in the ELF linker by default.
+    */
+ #undef DEFAULT_LD_ROSEGMENT
+diff --git a/ld/configure b/ld/configure
+index 6f1a3559964..fe23178cd29 100755
+--- a/ld/configure
++++ b/ld/configure
+@@ -852,6 +852,7 @@ enable_separate_code
+ enable_rosegment
+ enable_mark_plt
+ enable_gnu2_tls_tag
++enable_gnu_tls_tag
+ enable_memory_seal
+ enable_warn_execstack
+ enable_error_execstack
+@@ -1551,6 +1552,7 @@ Optional Features:
+   --enable-mark-plt       enable -z mark-plt in ELF x86-64 linker by default
+   --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF i386/x86-64 linker by
+                           default
++  --enable-gnu-tls-tag    enable --gnu-tls-tag in ELF i386 linker by default
+   --enable-memory-seal    enable -z memory-seal in ELF linker by default
+   --enable-warn-execstack enable warnings when creating an executable stack
+   --enable-error-execstack
+@@ -11517,7 +11519,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11520 "configure"
++#line 11522 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11623,7 +11625,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11626 "configure"
++#line 11628 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -15522,6 +15524,17 @@ esac
+ fi
+ 
+ 
++# Decide if --gnu-tls-tag should be enabled in ELF i386 linker by default.
++ac_default_ld_enable_gnu_tls_tag=unset
++# Check whether --enable-gnu-tls-tag was given.
++if test "${enable_gnu_tls_tag+set}" = set; then :
++  enableval=$enable_gnu_tls_tag; case "${enableval}" in
++  yes) ac_default_ld_enable_gnu_tls_tag=1 ;;
++  no) ac_default_ld_enable_gnu_tls_tag=0 ;;
++esac
++fi
++
++
+ # Decide if -z memory-seal should be enabled in ELF linker by default.
+ ac_default_ld_z_memory_seal=unset
+ # Check whether --enable-memory-seal was given.
+@@ -19007,6 +19020,17 @@ cat >>confdefs.h <<_ACEOF
+ _ACEOF
+ 
+ 
++if test "${ac_default_ld_enable_gnu_tls_tag}" = unset; then
++  # Default to enable --gnu-tls-tag if libc.so has the GLIBC_ABI_GNU_TLS
++  # version.
++  ac_default_ld_enable_gnu_tls_tag=2
++fi
++
++cat >>confdefs.h <<_ACEOF
++#define DEFAULT_LD_GNU_TLS_TAG $ac_default_ld_enable_gnu_tls_tag
++_ACEOF
++
++
+ 
+ cat >>confdefs.h <<_ACEOF
+ #define DEFAULT_LD_WARN_EXECSTACK $ac_default_ld_warn_execstack
+diff --git a/ld/configure.ac b/ld/configure.ac
+index 4b9068a415e..3e44e3361ef 100644
+--- a/ld/configure.ac
++++ b/ld/configure.ac
+@@ -256,6 +256,16 @@ AC_ARG_ENABLE(gnu2-tls-tag,
+   no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
+ esac])
+ 
++# Decide if --gnu-tls-tag should be enabled in ELF i386 linker by default.
++ac_default_ld_enable_gnu_tls_tag=unset
++AC_ARG_ENABLE(gnu-tls-tag,
++	      AS_HELP_STRING([--enable-gnu-tls-tag],
++	      [enable --gnu-tls-tag in ELF i386 linker by default]),
++[case "${enableval}" in
++  yes) ac_default_ld_enable_gnu_tls_tag=1 ;;
++  no) ac_default_ld_enable_gnu_tls_tag=0 ;;
++esac])
++
+ # Decide if -z memory-seal should be enabled in ELF linker by default.
+ ac_default_ld_z_memory_seal=unset
+ AC_ARG_ENABLE(memory-seal,
+@@ -666,6 +676,15 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU2_TLS_TAG,
+   $ac_default_ld_enable_gnu2_tls_tag,
+   [Define to 1 if you want to enable --gnu2-tls-tag in ELF i386/x86-64 linker by default.])
+ 
++if test "${ac_default_ld_enable_gnu_tls_tag}" = unset; then
++  # Default to enable --gnu-tls-tag if libc.so has the GLIBC_ABI_GNU_TLS
++  # version.
++  ac_default_ld_enable_gnu_tls_tag=2
++fi
++AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU_TLS_TAG,
++  $ac_default_ld_enable_gnu_tls_tag,
++  [Define to 1 if you want to enable --gnu-tls-tag in ELF i386 linker by default.])
++
+ AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK,
+   $ac_default_ld_warn_execstack,
+   [Define to 1 if you want to enable --warn-execstack in ELF linker by default.])
+diff --git a/ld/emultempl/elf-i386-glibc.em b/ld/emultempl/elf-i386-glibc.em
+index 547823750a4..26a7296cf76 100644
+--- a/ld/emultempl/elf-i386-glibc.em
++++ b/ld/emultempl/elf-i386-glibc.em
+@@ -35,7 +35,43 @@ elf_i386_glibc_before_parse (void)
+ {
+   elf_x86_before_parse ();
+   elf_x86_glibc_before_parse ();
++  params.gnu_tls_version_tag = DEFAULT_LD_GNU_TLS_TAG;
+ }
+ EOF
+ 
+ LDEMUL_BEFORE_PARSE=elf_i386_glibc_before_parse
++
++PARSE_AND_LIST_LONGOPTS_386='
++  { "gnu-tls-tag", no_argument, NULL, OPTION_GNU_TLS_VERSION_TAG },
++  { "no-gnu-tls-tag", no_argument, NULL, OPTION_NO_GNU_TLS_VERSION_TAG },
++'
++
++PARSE_AND_LIST_OPTIONS_386='
++  if (DEFAULT_LD_GNU_TLS_TAG == 0)
++    fprintf (file, _("\
++  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency\n\
++  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency (default)\n"));
++  else if (DEFAULT_LD_GNU_TLS_TAG == 1)
++    fprintf (file, _("\
++  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency (default)\n\
++  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency\n"));
++  else
++    fprintf (file, _("\
++  --gnu-tls-tag               Add GLIBC_ABI_GNU_TLS dependency (auto)\n\
++                                when no options are specified (default)\n\
++  --no-gnu-tls-tag            Do not add GLIBC_ABI_GNU_TLS dependency\n"));
++'
++
++PARSE_AND_LIST_ARGS_CASES_386='
++    case OPTION_GNU_TLS_VERSION_TAG:
++      params.gnu_tls_version_tag = 1;
++      break;
++
++    case OPTION_NO_GNU_TLS_VERSION_TAG:
++      params.gnu_tls_version_tag = 0;
++      break;
++'
++
++PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_386"
++PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_386"
++PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_386"
+diff --git a/ld/ld.texi b/ld/ld.texi
+index 0e13f7d8e35..cf750d15259 100644
+--- a/ld/ld.texi
++++ b/ld/ld.texi
+@@ -1745,6 +1745,19 @@ Supported for Linux/i386 and Linux/x86_64.
+ 
+ Other keywords are ignored for Solaris compatibility.
+ 
++@item --gnu-tls-tag
++@itemx --no-gnu-tls-tag
++Add @code{GLIBC_ABI_GNU_TLS} version tag dependency in output programs
++and shared libraries when linking against glibc if input relocatable
++object files call @code{___tls_get_addr}.  The output will fail to load
++and run at run-time against glibc which doesn't define the
++@code{GLIBC_ABI_GNU_TLS} version tag.  Unless disabled by the
++@option{--disable-gnu-tls-tag} configure option at the linker build
++time, when no options are specified, linker will add the
++@code{GLIBC_ABI_GNU_TLS} version tag dependency if inputs have
++@code{___tls_get_addr} call and libc.so defines the
++@code{GLIBC_ABI_GNU_TLS} version tag.  Supported for Linux/i386.
++
+ @item --gnu2-tls-tag
+ @itemx --no-gnu2-tls-tag
+ Add @code{GLIBC_ABI_GNU2_TLS} version tag dependency in output programs
+diff --git a/ld/ldlex.h b/ld/ldlex.h
+index 286ab0ba6d1..c8d61478c60 100644
+--- a/ld/ldlex.h
++++ b/ld/ldlex.h
+@@ -474,6 +474,9 @@ enum option_values
+   /* Used by emultempl/elf-x86-glibc.em.  */
+   OPTION_GNU2_TLS_VERSION_TAG,
+   OPTION_NO_GNU2_TLS_VERSION_TAG,
++  /* Used by emultempl/elf-i386-glibc.em.  */
++  OPTION_GNU_TLS_VERSION_TAG,
++  OPTION_NO_GNU_TLS_VERSION_TAG,
+ };
+ 
+ /* The initial parser states.  */
+diff --git a/ld/testsuite/ld-i386/gnu-tls-1.s b/ld/testsuite/ld-i386/gnu-tls-1.s
+new file mode 100644
+index 00000000000..02ae207a9b5
+--- /dev/null
++++ b/ld/testsuite/ld-i386/gnu-tls-1.s
+@@ -0,0 +1,9 @@
++	.text
++	.p2align 4
++	.globl	func
++	.type	func, @function
++func:
++	leal	foo@tlsgd(,%ebx,1), %eax
++	call	___tls_get_addr@PLT
++	ret
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-i386/gnu-tls-1a.rd b/ld/testsuite/ld-i386/gnu-tls-1a.rd
+new file mode 100644
+index 00000000000..65d889de7d9
+--- /dev/null
++++ b/ld/testsuite/ld-i386/gnu-tls-1a.rd
+@@ -0,0 +1,7 @@
++#...
++Version needs section '.gnu.version_r' contains [0-9]+ entries:
++ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
++ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
++#...
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU_TLS  Flags: none  Version: [0-9]+
++#pass
+diff --git a/ld/testsuite/ld-i386/gnu-tls-1b.rd b/ld/testsuite/ld-i386/gnu-tls-1b.rd
+new file mode 100644
+index 00000000000..02006e47da1
+--- /dev/null
++++ b/ld/testsuite/ld-i386/gnu-tls-1b.rd
+@@ -0,0 +1,4 @@
++#failif
++#...
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU_TLS  Flags: none  Version: [0-9]+
++#...
+diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
+index 74ef1672f86..2b6a36e63f8 100644
+--- a/ld/testsuite/ld-i386/i386.exp
++++ b/ld/testsuite/ld-i386/i386.exp
+@@ -1516,10 +1516,26 @@ run_ld_link_tests [list \
+     ] \
+ ]
+ 
+-# The musl C library does not support --gnu2-tls-tag.
++# The musl C library does not support --gnu-tls-tag nor --gnu2-tls-tag.
+ if { ![istarget *-*-musl]
+      && [check_compiler_available] } {
+     run_cc_link_tests [list \
++	[list \
++	    "Build gnu-tls-1a.so" \
++	    "-shared -Wl,--no-as-needed,--gnu-tls-tag" \
++	    "-fPIC" \
++	    { gnu-tls-1.s } \
++	    {{readelf {-W --version-info} gnu-tls-1a.rd}} \
++	    "gnu-tls-1a.so" \
++	] \
++	[list \
++	    "Build gnu-tls-1b.so" \
++	    "-shared -Wl,--no-as-needed,--no-gnu-tls-tag" \
++	    "-fPIC" \
++	    { gnu-tls-1.s } \
++	    {{readelf {-W --version-info} gnu-tls-1b.rd}} \
++	    "gnu-tls-1b.so" \
++	] \
+ 	[list \
+ 	    "Build gnu2-tls-1a.so" \
+ 	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
+-- 
+2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-18 15:39 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-18 15:39 UTC (permalink / raw
  To: gentoo-commits

commit:     61e1223b7d1b5bdc95fc287a9e9f7c48e9cb5127
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 18 15:39:20 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 18 15:39:20 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=61e1223b

9999: add section size fix

Bug: https://sourceware.org/PR33291
Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0009-ld-section-size.patch | 46 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/9999/0009-ld-section-size.patch b/9999/0009-ld-section-size.patch
new file mode 100644
index 0000000..70f6f28
--- /dev/null
+++ b/9999/0009-ld-section-size.patch
@@ -0,0 +1,46 @@
+https://sourceware.org/bugzilla/show_bug.cgi?id=33291#c10
+--- a/ld/ldlang.c
++++ b/ld/ldlang.c
+@@ -2857,14 +2857,24 @@ lang_add_section (lang_statement_list_ty
+       /* Only set SEC_READONLY flag on the first input section.  */
+       flags &= ~ SEC_READONLY;
+ 
+-      /* Keep SEC_MERGE and SEC_STRINGS only if they are the same.  */
+-      if ((output->bfd_section->flags & (SEC_MERGE | SEC_STRINGS))
+-	  != (flags & (SEC_MERGE | SEC_STRINGS))
+-	  || ((flags & SEC_MERGE) != 0
+-	      && output->bfd_section->entsize != section->entsize))
++      /* Keep entry size, SEC_MERGE, and SEC_STRINGS only if entry sizes are
++	 the same.  */
++      if (output->bfd_section->entsize != section->entsize)
+ 	{
+-	  output->bfd_section->flags &= ~ (SEC_MERGE | SEC_STRINGS);
+-	  flags &= ~ (SEC_MERGE | SEC_STRINGS);
++	  output->bfd_section->entsize = 0;
++	  flags &= ~(SEC_MERGE | SEC_STRINGS);
++	}
++
++      /* Keep SEC_MERGE and SEC_STRINGS (each) only if they are the same.  */
++      if ((output->bfd_section->flags ^ flags) & SEC_MERGE)
++	{
++	  output->bfd_section->flags &= ~SEC_MERGE;
++	  flags &= ~SEC_MERGE;
++	}
++      if ((output->bfd_section->flags ^ flags) & SEC_STRINGS)
++	{
++	  output->bfd_section->flags &= ~SEC_STRINGS;
++	  flags &= ~SEC_STRINGS;
+ 	}
+     }
+   output->bfd_section->flags |= flags;
+@@ -2879,8 +2889,9 @@ lang_add_section (lang_statement_list_ty
+ 				     link_info.output_bfd,
+ 				     output->bfd_section,
+ 				     &link_info);
+-      if ((flags & SEC_MERGE) != 0)
++      //todo if (no earlier data statements)
+ 	output->bfd_section->entsize = section->entsize;
++      //todo also need to deal with later data statements
+     }
+ 
+   if ((flags & SEC_TIC54X_BLOCK) != 0


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-17 20:58 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-17 20:58 UTC (permalink / raw
  To: gentoo-commits

commit:     98e6111945ccff76e3cdbf98685def5b60a5491b
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Aug 17 20:58:16 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug 17 20:58:16 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=98e61119

9999: tweak patch slightly

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...07-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch b/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
index a992ef1..24c5262 100644
--- a/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
+++ b/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
@@ -1,10 +1,7 @@
-From 6eafbdfab0ff4baecf85e095966f0e7f8b6e2fc8 Mon Sep 17 00:00:00 2001
-Message-ID: <6eafbdfab0ff4baecf85e095966f0e7f8b6e2fc8.1755459855.git.sam@gentoo.org>
-In-Reply-To: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
-References: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+From ab490c8962810cab7d8eb788122012a1884c05ff Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 17 Aug 2025 11:55:18 -0700
-Subject: [PATCH 2/3] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
+Date: Sun, 17 Aug 2025 10:09:25 -0700
+Subject: [PATCH] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
 
 On Linux/x86-64, programs and shared libraries created with -z mark-plt
 have the GLIBC_2.36 version tag dependency since -z mark-plt uses the


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-17 19:45 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-17 19:45 UTC (permalink / raw
  To: gentoo-commits

commit:     b6bffdb1e3510efb933b0e567a1e83da21064e11
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Aug 17 19:44:53 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug 17 19:44:53 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=b6bffdb1

9999: add some patches from H.J.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch | 1074 ++++++++++++++++++++
 ...GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch |  160 +++
 ...Properly-override-compiler-flags-in-tests.patch |  393 +++++++
 3 files changed, 1627 insertions(+)

diff --git a/9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch b/9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
new file mode 100644
index 0000000..15230cc
--- /dev/null
+++ b/9999/0006-x86-64-Add-GLIBC_ABI_GNU2_TLS-version-dependency.patch
@@ -0,0 +1,1074 @@
+From 35d2c802f63122702ac48296dac025470c5d1467 Mon Sep 17 00:00:00 2001
+Message-ID: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sun, 17 Aug 2025 11:58:53 -0700
+Subject: [PATCH 1/3] x86-64: Add GLIBC_ABI_GNU2_TLS version dependency
+
+On Linux/x86-64, programs and shared libraries compiled with
+-mtls-dialect=gnu2 may fail silently at run-time against glibc without
+the GNU2 TLS run-time fix for:
+
+https://sourceware.org/bugzilla/show_bug.cgi?id=31372
+
+A version tag, GLIBC_ABI_GNU2_TLS, has been added to glibc to indicate
+that glibc has the working GNU2 TLS run-time by:
+
+commit 9df8fa397d515dc86ff5565f6c45625e672d539e
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Mon Jul 28 12:18:22 2025 -0700
+
+    x86-64: Add GLIBC_ABI_GNU2_TLS version [BZ #33129]
+
+Add the --gnu2-tls-tag option to x86-64 ELF linker to add the
+GLIBC_ABI_GNU2_TLS version dependency in output programs and shared
+libraries when linking against glibc if input relocatable object files
+have R_X86_64_TLSDESC_CALL relocation.  The output will fail to load and
+run at run-time against glibc which doesn't define the GLIBC_ABI_GNU2_TLS
+version.
+
+Add the --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag
+by default.  If unspecified, linker will add the GLIBC_ABI_GNU2_TLS
+version dependency if inputs have R_X86_64_TLSDESC_CALL relocation and
+libc.so defines the GLIBC_ABI_GNU2_TLS version.
+
+Update elf_link_add_glibc_verneed to properly add the GLIBC_2.36 version
+dependency when -z mark-plt -z nopack-relative-relocs passed to linker.
+
+bfd/
+
+	PR ld/33130
+	* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Add
+	a pointer to bool argument.
+	* elf-linker-x86.h (elf_linker_x86_params): Add gnu2_tls.
+	* elf64-x86-64.c (elf_x86_64_scan_relocs): Set has_tlsdesc_call
+	to 1 for R_X86_64_TLSDESC_CALL.
+	(elf_x86_64_add_glibc_version_dependency): Add GLIBC_ABI_GNU2_TLS
+	version dependency if GLIBC_ABI_GNU2_TLS dependency isn't disabled
+	and has_tlsdesc_call isn't 0.
+	* elflink.c (elf_link_add_glibc_verneed): Changed to return bool.
+	Remove the pointer to elf_find_verdep_info argument.  Add a
+	pointer to bool argument, auto_version. Return true if linked
+	against glibc.  Otherwise return false.  If the version dependency
+	is added, set *auto_version to true.  If *auto_version is true,
+	add the version dependency only if libc.so defines the version.
+	(_bfd_elf_link_add_glibc_version_dependency): Add a pointer to
+	bool argument and pass it to elf_link_add_glibc_verneed.
+	(_bfd_elf_link_add_dt_relr_dependency): Pass NULL to
+	_bfd_elf_link_add_glibc_version_dependency.
+	* elfxx-x86.h (elf_x86_link_hash_table): Add has_tlsdesc_call.
+
+ld/
+
+	PR ld/33130
+	* NEWS: Mention --gnu2-tls-tag, --no-gnu2-tls-tag and
+	--enable-gnu2-tls-tag.
+	* config.in: Regenerated.
+	* configure: Likewise.
+	* configure.ac: Add --enable-gnu2-tls-tag.
+	* ld.texi: Document --gnu2-tls-tag/--no-gnu2-tls-tag.
+	* ldlex.h (option_values): Add OPTION_GNU2_TLS_TAG and
+	OPTION_NO_GNU2_TLS_TAG.
+	* emulparams/elf32_x86_64.sh (EXTRA_EM_FILE): Changed to
+	"elf-x86-64".
+	* emulparams/elf_x86_64.sh (EXTRA_EM_FILE): Likewise.
+	* emultempl/elf-x86-64.em: New file.
+	* emultempl/elf-x86.em (elf_x86_64_before_parse): Removed.
+	(LDEMUL_BEFORE_PARSE): Likewise.
+	(elf_x86_64_before_allocation): Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1.rd: New file.
+	* testsuite/ld-x86-64/gnu2-tls-1a.od: New file.
+	* testsuite/ld-x86-64/gnu2-tls-1a.s: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1b.od: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1b.s: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-1c.od: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-2.rd: Likewise.
+	* testsuite/ld-x86-64/gnu2-tls-2.s: Likewise.
+	* testsuite/ld-x86-64/mark-plt-2.rd: Likewise.
+	* testsuite/ld-x86-64/mark-plt-2.s: Likewise.
+	* testsuite/ld-x86-64/x86-64.exp: Run GLIBC_ABI_GNU2_TLS tests.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-bfd.h                         |   2 +-
+ bfd/elf-linker-x86.h                  |   8 ++
+ bfd/elf64-x86-64.c                    |  30 ++++--
+ bfd/elflink.c                         | 130 +++++++++++++++-----------
+ bfd/elfxx-x86.h                       |   4 +
+ ld/NEWS                               |   6 ++
+ ld/config.in                          |   4 +
+ ld/configure                          |  29 +++++-
+ ld/configure.ac                       |  19 ++++
+ ld/emulparams/elf32_x86_64.sh         |   2 +-
+ ld/emulparams/elf_x86_64.sh           |   2 +-
+ ld/emultempl/elf-x86-64.em            | 108 +++++++++++++++++++++
+ ld/emultempl/elf-x86.em               |  58 ------------
+ ld/ld.texi                            |  13 +++
+ ld/ldlex.h                            |   3 +
+ ld/testsuite/ld-x86-64/gnu2-tls-1.rd  |   7 ++
+ ld/testsuite/ld-x86-64/gnu2-tls-1a.od |  13 +++
+ ld/testsuite/ld-x86-64/gnu2-tls-1a.s  |  14 +++
+ ld/testsuite/ld-x86-64/gnu2-tls-1b.od |  13 +++
+ ld/testsuite/ld-x86-64/gnu2-tls-1b.s  |   9 ++
+ ld/testsuite/ld-x86-64/gnu2-tls-1c.od |  13 +++
+ ld/testsuite/ld-x86-64/gnu2-tls-2.rd  |   4 +
+ ld/testsuite/ld-x86-64/gnu2-tls-2.s   |  13 +++
+ ld/testsuite/ld-x86-64/mark-plt-2.rd  |   7 ++
+ ld/testsuite/ld-x86-64/mark-plt-2.s   |  13 +++
+ ld/testsuite/ld-x86-64/x86-64.exp     |  53 ++++++++++-
+ 26 files changed, 454 insertions(+), 123 deletions(-)
+ create mode 100644 ld/emultempl/elf-x86-64.em
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1.rd
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.od
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1a.s
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.od
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1b.s
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-1c.od
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-2.rd
+ create mode 100644 ld/testsuite/ld-x86-64/gnu2-tls-2.s
+ create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.rd
+ create mode 100644 ld/testsuite/ld-x86-64/mark-plt-2.s
+
+diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
+index accdd6d41a8..feb470fc477 100644
+--- a/bfd/elf-bfd.h
++++ b/bfd/elf-bfd.h
+@@ -2632,7 +2632,7 @@ extern bool _bfd_elf_link_output_relocs
+    struct elf_link_hash_entry **);
+ 
+ extern void _bfd_elf_link_add_glibc_version_dependency
+-  (struct elf_find_verdep_info *, const char *const []);
++  (struct elf_find_verdep_info *, const char *const [], bool *);
+ 
+ extern void _bfd_elf_link_add_dt_relr_dependency
+   (struct elf_find_verdep_info *);
+diff --git a/bfd/elf-linker-x86.h b/bfd/elf-linker-x86.h
+index 2c98257038f..7656b0a7932 100644
+--- a/bfd/elf-linker-x86.h
++++ b/bfd/elf-linker-x86.h
+@@ -72,6 +72,14 @@ struct elf_linker_x86_params
+   /* Mark PLT with dynamic tags.  */
+   unsigned int mark_plt : 1;
+ 
++  /* Add the GLIBC_ABI_GNU2_TLS version dependency if input object files
++     have R_X86_64_TLSDESC_CALL relocation:
++     0: Disable.
++     1: Enable.
++     2: Auto.  Enable if libc.so has the GLIBC_ABI_GNU2_TLS version.
++   */
++  unsigned int gnu2_tls : 2;
++
+   /* X86-64 ISA level needed.  */
+   unsigned int isa_level;
+ 
+diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
+index b6f97b5b69b..03873a9ed6b 100644
+--- a/bfd/elf64-x86-64.c
++++ b/bfd/elf64-x86-64.c
+@@ -2694,6 +2694,10 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
+ 	    eh->zero_undefweak &= 0x2;
+ 	  break;
+ 
++	case R_X86_64_TLSDESC_CALL:
++	  htab->has_tlsdesc_call = 1;
++	  goto need_got;
++
+ 	case R_X86_64_GOTTPOFF:
+ 	case R_X86_64_CODE_4_GOTTPOFF:
+ 	case R_X86_64_CODE_5_GOTTPOFF:
+@@ -2715,7 +2719,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
+ 	case R_X86_64_GOTPLT64:
+ 	case R_X86_64_GOTPC32_TLSDESC:
+ 	case R_X86_64_CODE_4_GOTPC32_TLSDESC:
+-	case R_X86_64_TLSDESC_CALL:
++need_got:
+ 	  /* This symbol requires a global offset table entry.	*/
+ 	  {
+ 	    int tls_type, old_tls_type;
+@@ -6243,7 +6247,8 @@ elf_x86_64_add_glibc_version_dependency
+   (struct elf_find_verdep_info *rinfo)
+ {
+   unsigned int i = 0;
+-  const char *version[3] = { NULL, NULL, NULL };
++  const char *version[4] = { NULL, NULL, NULL, NULL };
++  bool auto_version[4] = { false, false, false, false };
+   struct elf_x86_link_hash_table *htab;
+ 
+   if (rinfo->info->enable_dt_relr)
+@@ -6253,14 +6258,27 @@ elf_x86_64_add_glibc_version_dependency
+     }
+ 
+   htab = elf_x86_hash_table (rinfo->info, X86_64_ELF_DATA);
+-  if (htab != NULL && htab->params->mark_plt)
++  if (htab != NULL)
+     {
+-      version[i] = "GLIBC_2.36";
+-      i++;
++      if (htab->params->gnu2_tls && htab->has_tlsdesc_call)
++	{
++	  version[i] = "GLIBC_ABI_GNU2_TLS";
++	  /* 2 == auto, enable if libc.so defines the GLIBC_ABI_GNU2_TLS
++	     version.  */
++	  if (htab->params->gnu2_tls == 2)
++	    auto_version[i] = true;
++	  i++;
++	}
++      if (htab->params->mark_plt)
++	{
++	  version[i] = "GLIBC_2.36";
++	  i++;
++	}
+     }
+ 
+   if (i != 0)
+-    _bfd_elf_link_add_glibc_version_dependency (rinfo, version);
++    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
++						auto_version);
+ }
+ 
+ static const struct bfd_elf_special_section
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index 7b0375406ac..ac40423751f 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -2283,68 +2283,85 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
+   return true;
+ }
+ \f
+-/* Return the glibc version reference if VERSION_DEP is added to the
+-   list of glibc version dependencies successfully.  VERSION_DEP will
+-   be put into the .gnu.version_r section.  GLIBC_MINOR_BASE is the
+-   pointer to the glibc minor base version.  */
++/* Return true if linked against glibc.  Otherwise return false.  If
++   linked against glibc, add VERSION_DEP to the list of glibc version
++   dependencies and set *AUTO_VERSION to true.  If *AUTO_VERSION is
++   true, add VERSION_DEP to the version dependency list only if libc.so
++   defines VERSION_DEP.  GLIBC_MINOR_BASE is the pointer to the glibc
++   minor base version.  */
+ 
+-static Elf_Internal_Verneed *
++static bool
+ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+-			    Elf_Internal_Verneed *glibc_verref,
+ 			    const char *version_dep,
+-			    int *glibc_minor_base)
++			    int *glibc_minor_base,
++			    bool *auto_version)
+ {
+   Elf_Internal_Verneed *t;
+   Elf_Internal_Vernaux *a;
+   size_t amt;
+   int minor_version = -1;
++  bool added = false;
++  bool glibc = false;
+ 
+-  if (glibc_verref != NULL)
++  for (t = elf_tdata (rinfo->info->output_bfd)->verref;
++       t != NULL;
++       t = t->vn_nextref)
+     {
+-      t = glibc_verref;
++      const char *soname = bfd_elf_get_dt_soname (t->vn_bfd);
++      if (soname != NULL && startswith (soname, "libc.so."))
++	break;
++    }
+ 
+-      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
++  /* Skip the shared library if it isn't libc.so.  */
++  if (t == NULL)
++    goto update_auto_version_and_return;
++
++  for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
++    {
++      /* Return if VERSION_DEP dependency has been added.  */
++      if (a->vna_nodename == version_dep
++	  || strcmp (a->vna_nodename, version_dep) == 0)
+ 	{
+-	  /* Return if VERSION_DEP dependency has been added.  */
+-	  if (a->vna_nodename == version_dep
+-	      || strcmp (a->vna_nodename, version_dep) == 0)
+-	    return t;
++	  glibc = true;
++	  goto update_auto_version_and_return;
+ 	}
+-    }
+-  else
+-    {
+-      for (t = elf_tdata (rinfo->info->output_bfd)->verref;
+-	   t != NULL;
+-	   t = t->vn_nextref)
++
++      /* Check if libc.so provides GLIBC_2.XX version.  */
++      if (startswith (a->vna_nodename, "GLIBC_2."))
+ 	{
+-	  const char *soname = bfd_elf_get_dt_soname (t->vn_bfd);
+-	  if (soname != NULL && startswith (soname, "libc.so."))
+-	    break;
++	  minor_version = strtol (a->vna_nodename + 8, NULL, 10);
++	  if (minor_version < *glibc_minor_base)
++	    *glibc_minor_base = minor_version;
+ 	}
++    }
+ 
+-      /* Skip the shared library if it isn't libc.so.  */
+-      if (t == NULL)
+-	return t;
++  /* Skip if it isn't linked against glibc.  */
++  if (minor_version < 0)
++    goto update_auto_version_and_return;
+ 
+-      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
+-	{
+-	  /* Return if VERSION_DEP dependency has been added.  */
+-	  if (a->vna_nodename == version_dep
+-	      || strcmp (a->vna_nodename, version_dep) == 0)
+-	    return t;
++  glibc = true;
+ 
+-	  /* Check if libc.so provides GLIBC_2.XX version.  */
+-	  if (startswith (a->vna_nodename, "GLIBC_2."))
+-	    {
+-	      minor_version = strtol (a->vna_nodename + 8, NULL, 10);
+-	      if (minor_version < *glibc_minor_base)
+-		*glibc_minor_base = minor_version;
+-	    }
+-	}
++  if (auto_version && *auto_version)
++    {
++      /* Add VERSION_DEP to the version dependency list only if
++	 libc.so defines VERSION_DEP.  */
+ 
+-      /* Skip if it isn't linked against glibc.  */
+-      if (minor_version < 0)
+-	return NULL;
++      bool defined = false;
++      Elf_Internal_Verdef *d;
++
++      for (d = elf_tdata (t->vn_bfd)->verdef;
++	   d != NULL;
++	   d = d->vd_nextdef)
++	if (strcmp (d->vd_nodename, version_dep) == 0)
++	  {
++	    defined = true;
++	    break;
++	  }
++
++      /* Set *AUTO_VERSION to false and return true to indicate that
++	 libc.so doesn't define VERSION_DEP.  */
++      if (!defined)
++	goto update_auto_version_and_return;
+     }
+ 
+   /* Skip if 2.GLIBC_MINOR_BASE includes VERSION_DEP.  */
+@@ -2352,7 +2369,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+     {
+       minor_version = strtol (version_dep + 8, NULL, 10);
+       if (minor_version <= *glibc_minor_base)
+-	return NULL;
++	goto update_auto_version_and_return;
+     }
+ 
+   amt = sizeof *a;
+@@ -2360,7 +2377,8 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+   if (a == NULL)
+     {
+       rinfo->failed = true;
+-      return NULL;
++      glibc = false;
++      goto update_auto_version_and_return;
+     }
+ 
+   a->vna_nodename = version_dep;
+@@ -2371,7 +2389,13 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+ 
+   t->vn_auxptr = a;
+ 
+-  return t;
++  added = true;
++
++ update_auto_version_and_return:
++  if (auto_version)
++    *auto_version = added;
++
++  return glibc;
+ }
+ 
+ /* Add VERSION_DEP to the list of version dependencies when linked
+@@ -2380,19 +2404,19 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+ void
+ _bfd_elf_link_add_glibc_version_dependency
+   (struct elf_find_verdep_info *rinfo,
+-   const char *const version_dep[])
++   const char *const version_dep[],
++   bool *auto_version)
+ {
+-  Elf_Internal_Verneed *t = NULL;
+   int glibc_minor_base = INT_MAX;
+ 
+   do
+     {
+-      t = elf_link_add_glibc_verneed (rinfo, t, *version_dep,
+-				      &glibc_minor_base);
+-      /* Return if there is no glibc version reference.  */
+-      if (t == NULL)
++      /* Return if not linked against glibc.  */
++      if (!elf_link_add_glibc_verneed (rinfo, *version_dep,
++				       &glibc_minor_base, auto_version))
+ 	return;
+       version_dep++;
++      auto_version++;
+     }
+   while (*version_dep != NULL);
+ }
+@@ -2410,7 +2434,7 @@ _bfd_elf_link_add_dt_relr_dependency (struct elf_find_verdep_info *rinfo)
+ 	  "GLIBC_ABI_DT_RELR",
+ 	  NULL
+ 	};
+-      _bfd_elf_link_add_glibc_version_dependency (rinfo, version);
++      _bfd_elf_link_add_glibc_version_dependency (rinfo, version, NULL);
+     }
+ }
+ 
+diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
+index f6ee6a65356..8fd2d81ab6b 100644
+--- a/bfd/elfxx-x86.h
++++ b/bfd/elfxx-x86.h
+@@ -670,6 +670,10 @@ struct elf_x86_link_hash_table
+   /* Number of relative reloc generation pass.  */
+   unsigned int generate_relative_reloc_pass;
+ 
++  /* TRUE if inputs have R_X86_64_TLSDESC_CALL relocation.  This is
++     only used for x86-64.  */
++  unsigned int has_tlsdesc_call : 1;
++
+    /* Value used to fill the unused bytes of the first PLT entry.  This
+       is only used for i386.  */
+   bfd_byte plt0_pad_byte;
+diff --git a/ld/NEWS b/ld/NEWS
+index 54c1df5aadf..cfb5c9c81df 100644
+--- a/ld/NEWS
++++ b/ld/NEWS
+@@ -1,5 +1,11 @@
+ -*- text -*-
+ 
++* Add --gnu2-tls-tag/--no-gnu2-tls-tag options to x86-64 ELF linker to
++  add the GLIBC_ABI_GNU2_TLS version dependency in output if input object
++  files have R_X86_64_TLSDESC_CALL relocation.  Also added
++  --enable-gnu2-tls-tag configure option to enable --gnu2-tls-tag by
++  default.
++
+ * NaCl target support is removed.
+ 
+ Changes in 2.45:
+diff --git a/ld/config.in b/ld/config.in
+index 37812241bd9..021577dbe4d 100644
+--- a/ld/config.in
++++ b/ld/config.in
+@@ -31,6 +31,10 @@
+    when a .note-GNU-stack section is missing. */
+ #undef DEFAULT_LD_EXECSTACK
+ 
++/* Define to 1 if you want to enable --gnu2-tls-tag in ELF x86-64 linker by
++   default. */
++#undef DEFAULT_LD_GNU2_TLS_TAG
++
+ /* Define to 1 if you want to enable --rosegment in the ELF linker by default.
+    */
+ #undef DEFAULT_LD_ROSEGMENT
+diff --git a/ld/configure b/ld/configure
+index 124b44182bc..9c694525488 100755
+--- a/ld/configure
++++ b/ld/configure
+@@ -851,6 +851,7 @@ enable_textrel_check
+ enable_separate_code
+ enable_rosegment
+ enable_mark_plt
++enable_gnu2_tls_tag
+ enable_memory_seal
+ enable_warn_execstack
+ enable_error_execstack
+@@ -1548,6 +1549,8 @@ Optional Features:
+   --enable-separate-code  enable -z separate-code in ELF linker by default
+   --enable-rosegment      enable --rosegment in the ELF linker by default
+   --enable-mark-plt       enable -z mark-plt in ELF x86-64 linker by default
++  --enable-gnu2-tls-tag   enable --gnu2-tls-tag in ELF x86-64 linker by
++                          default
+   --enable-memory-seal    enable -z memory-seal in ELF linker by default
+   --enable-warn-execstack enable warnings when creating an executable stack
+   --enable-error-execstack
+@@ -11514,7 +11517,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11517 "configure"
++#line 11520 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11620,7 +11623,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11623 "configure"
++#line 11626 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -15507,6 +15510,18 @@ esac
+ fi
+ 
+ 
++# Decide if --gnu2-tls-tag should be enabled in ELF x86-64 linker
++# by default.
++ac_default_ld_enable_gnu2_tls_tag=unset
++# Check whether --enable-gnu2-tls-tag was given.
++if test "${enable_gnu2_tls_tag+set}" = set; then :
++  enableval=$enable_gnu2_tls_tag; case "${enableval}" in
++  yes) ac_default_ld_enable_gnu2_tls_tag=1 ;;
++  no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
++esac
++fi
++
++
+ # Decide if -z memory-seal should be enabled in ELF linker by default.
+ ac_default_ld_z_memory_seal=unset
+ # Check whether --enable-memory-seal was given.
+@@ -18981,6 +18996,16 @@ cat >>confdefs.h <<_ACEOF
+ _ACEOF
+ 
+ 
++if test "${ac_default_ld_enable_gnu2_tls_tag}" = unset; then
++  # Default to enable --gnu2-tls-tag if libc.so has the GLIBC_ABI_GNU2_TLS
++  # version.
++  ac_default_ld_enable_gnu2_tls_tag=2
++fi
++
++cat >>confdefs.h <<_ACEOF
++#define DEFAULT_LD_GNU2_TLS_TAG $ac_default_ld_enable_gnu2_tls_tag
++_ACEOF
++
+ 
+ 
+ cat >>confdefs.h <<_ACEOF
+diff --git a/ld/configure.ac b/ld/configure.ac
+index e306c1ded4a..d4801fb1333 100644
+--- a/ld/configure.ac
++++ b/ld/configure.ac
+@@ -245,6 +245,17 @@ AC_ARG_ENABLE(mark-plt,
+   no) ac_default_ld_z_mark_plt=0 ;;
+ esac])
+ 
++# Decide if --gnu2-tls-tag should be enabled in ELF x86-64 linker
++# by default.
++ac_default_ld_enable_gnu2_tls_tag=unset
++AC_ARG_ENABLE(gnu2-tls-tag,
++	      AS_HELP_STRING([--enable-gnu2-tls-tag],
++	      [enable --gnu2-tls-tag in ELF x86-64 linker by default]),
++[case "${enableval}" in
++  yes) ac_default_ld_enable_gnu2_tls_tag=1 ;;
++  no) ac_default_ld_enable_gnu2_tls_tag=0 ;;
++esac])
++
+ # Decide if -z memory-seal should be enabled in ELF linker by default.
+ ac_default_ld_z_memory_seal=unset
+ AC_ARG_ENABLE(memory-seal,
+@@ -646,6 +657,14 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_MEMORY_SEAL,
+   $ac_default_ld_z_memory_seal,
+   [Define to 1 if you want to enable -z memory_seal in ELF linker by default.])
+ 
++if test "${ac_default_ld_enable_gnu2_tls_tag}" = unset; then
++  # Default to enable --gnu2-tls-tag if libc.so has the GLIBC_ABI_GNU2_TLS
++  # version.
++  ac_default_ld_enable_gnu2_tls_tag=2
++fi
++AC_DEFINE_UNQUOTED(DEFAULT_LD_GNU2_TLS_TAG,
++  $ac_default_ld_enable_gnu2_tls_tag,
++  [Define to 1 if you want to enable --gnu2-tls-tag in ELF x86-64 linker by default.])
+ 
+ AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK,
+   $ac_default_ld_warn_execstack,
+diff --git a/ld/emulparams/elf32_x86_64.sh b/ld/emulparams/elf32_x86_64.sh
+index 6a92eec129d..4807413d133 100644
+--- a/ld/emulparams/elf32_x86_64.sh
++++ b/ld/emulparams/elf32_x86_64.sh
+@@ -20,7 +20,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
+ ARCH="i386:x64-32"
+ MACHINE=
+ TEMPLATE_NAME=elf
+-EXTRA_EM_FILE="elf-x86"
++EXTRA_EM_FILE="elf-x86-64"
+ GENERATE_SHLIB_SCRIPT=yes
+ GENERATE_PIE_SCRIPT=yes
+ NO_SMALL_DATA=yes
+diff --git a/ld/emulparams/elf_x86_64.sh b/ld/emulparams/elf_x86_64.sh
+index 92449745c7a..39cbf2ca189 100644
+--- a/ld/emulparams/elf_x86_64.sh
++++ b/ld/emulparams/elf_x86_64.sh
+@@ -21,7 +21,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
+ ARCH="i386:x86-64"
+ MACHINE=
+ TEMPLATE_NAME=elf
+-EXTRA_EM_FILE="elf-x86"
++EXTRA_EM_FILE="elf-x86-64"
+ GENERATE_SHLIB_SCRIPT=yes
+ GENERATE_PIE_SCRIPT=yes
+ NO_SMALL_DATA=yes
+diff --git a/ld/emultempl/elf-x86-64.em b/ld/emultempl/elf-x86-64.em
+new file mode 100644
+index 00000000000..6bb7844741c
+--- /dev/null
++++ b/ld/emultempl/elf-x86-64.em
+@@ -0,0 +1,108 @@
++# This shell script emits a C file. -*- C -*-
++#   Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the license, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; see the file COPYING3. If not,
++# see <http://www.gnu.org/licenses/>.
++#
++
++# This file is sourced from elf.em, and defines x86-64 specific routines.
++#
++
++source_em ${srcdir}/emultempl/elf-x86.em
++
++fragment <<EOF
++static void
++elf_x86_64_before_parse (void)
++{
++  params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
++  params.gnu2_tls = DEFAULT_LD_GNU2_TLS_TAG;
++
++  elf_x86_before_parse ();
++}
++
++static void
++elf_x86_64_before_allocation (void)
++{
++  if (!bfd_link_relocatable (&link_info)
++      && is_elf_hash_table (link_info.hash)
++      && expld.phase != lang_mark_phase_enum)
++    {
++      struct elf_link_hash_table *htab = elf_hash_table (&link_info);
++      /* Run one_lang_size_sections_pass to estimate the output section
++	 layout before sizing dynamic sections.  */
++      expld.dataseg.phase = exp_seg_none;
++      expld.phase = lang_mark_phase_enum;
++      /* NB: Exclude linker created GOT setions when estimating output
++	 section layout as sizing dynamic sections may change linker
++	 created GOT sections.  */
++      if (htab->sgot != NULL)
++	htab->sgot->flags |= SEC_EXCLUDE;
++      if (htab->sgotplt != NULL)
++	htab->sgotplt->flags |= SEC_EXCLUDE;
++      one_lang_size_sections_pass (NULL, false);
++      /* Restore linker created GOT setions.  */
++      if (htab->sgot != NULL)
++	htab->sgot->flags &= ~SEC_EXCLUDE;
++      if (htab->sgotplt != NULL)
++	htab->sgotplt->flags &= ~SEC_EXCLUDE;
++      lang_reset_memory_regions ();
++    }
++
++  gld${EMULATION_NAME}_before_allocation ();
++}
++EOF
++
++LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
++LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
++
++# Define some shell vars to insert bits of code into the standard elf
++# parse_args and list_options functions.
++#
++
++PARSE_AND_LIST_LONGOPTS_X86_64='
++  { "gnu2-tls-tag", no_argument, NULL, OPTION_GNU2_TLS_TAG },
++  { "no-gnu2-tls-tag", no_argument, NULL, OPTION_NO_GNU2_TLS_TAG },
++'
++
++PARSE_AND_LIST_OPTIONS_X86_64='
++  if (DEFAULT_LD_GNU2_TLS_TAG == 0)
++    fprintf (file, _("\
++  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency\n\
++  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency (default)\n"));
++  else if (DEFAULT_LD_GNU2_TLS_TAG == 1)
++    fprintf (file, _("\
++  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency (default)\n\
++  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency\n"));
++  else
++    fprintf (file, _("\
++  --gnu2-tls-tag              Add GLIBC_ABI_GNU2_TLS dependency (auto)\n\
++                                when no options are specified (default)\n\
++  --no-gnu2-tls-tag           Do not add GLIBC_ABI_GNU2_TLS dependency\n"));
++'
++
++PARSE_AND_LIST_ARGS_CASES_X86_64='
++    case OPTION_GNU2_TLS_TAG:
++      params.gnu2_tls = 1;
++      break;
++
++    case OPTION_NO_GNU2_TLS_TAG:
++      params.gnu2_tls = 0;
++      break;
++'
++
++PARSE_AND_LIST_LONGOPTS="$PARSE_AND_LIST_LONGOPTS $PARSE_AND_LIST_LONGOPTS_X86_64"
++PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86_64"
++PARSE_AND_LIST_ARGS_CASES="$PARSE_AND_LIST_ARGS_CASES $PARSE_AND_LIST_ARGS_CASES_X86_64"
+diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em
+index f72a0cd0d4a..411a4d62294 100644
+--- a/ld/emultempl/elf-x86.em
++++ b/ld/emultempl/elf-x86.em
+@@ -56,61 +56,3 @@ EOF
+ 
+ LDEMUL_BEFORE_PARSE=elf_x86_before_parse
+ fi
+-
+-case x${OUTPUT_FORMAT}${CALL_NOP_BYTE} in
+-  x*x86-64*0x67)
+-fragment <<EOF
+-
+-static void
+-elf_x86_64_before_parse (void)
+-{
+-  params.mark_plt = DEFAULT_LD_Z_MARK_PLT;
+-
+-  elf_x86_before_parse ();
+-}
+-EOF
+-
+-    LDEMUL_BEFORE_PARSE=elf_x86_64_before_parse
+-    ;;
+-esac
+-
+-case x${OUTPUT_FORMAT} in
+-  x*x86-64*)
+-fragment <<EOF
+-
+-static void
+-elf_x86_64_before_allocation (void)
+-{
+-  if (!bfd_link_relocatable (&link_info)
+-      && is_elf_hash_table (link_info.hash)
+-      && expld.phase != lang_mark_phase_enum)
+-    {
+-      struct elf_link_hash_table *htab = elf_hash_table (&link_info);
+-      /* Run one_lang_size_sections_pass to estimate the output section
+-	 layout before sizing dynamic sections.  */
+-      expld.dataseg.phase = exp_seg_none;
+-      expld.phase = lang_mark_phase_enum;
+-      /* NB: Exclude linker created GOT setions when estimating output
+-	 section layout as sizing dynamic sections may change linker
+-	 created GOT sections.  */
+-      if (htab->sgot != NULL)
+-	htab->sgot->flags |= SEC_EXCLUDE;
+-      if (htab->sgotplt != NULL)
+-	htab->sgotplt->flags |= SEC_EXCLUDE;
+-      one_lang_size_sections_pass (NULL, false);
+-      /* Restore linker created GOT setions.  */
+-      if (htab->sgot != NULL)
+-	htab->sgot->flags &= ~SEC_EXCLUDE;
+-      if (htab->sgotplt != NULL)
+-	htab->sgotplt->flags &= ~SEC_EXCLUDE;
+-      lang_reset_memory_regions ();
+-    }
+-
+-  gld${EMULATION_NAME}_before_allocation ();
+-}
+-
+-EOF
+-
+-LDEMUL_BEFORE_ALLOCATION=elf_x86_64_before_allocation
+-    ;;
+-esac
+diff --git a/ld/ld.texi b/ld/ld.texi
+index 413335ad765..7afff6e8ac7 100644
+--- a/ld/ld.texi
++++ b/ld/ld.texi
+@@ -1743,6 +1743,19 @@ Supported for Linux/i386 and Linux/x86_64.
+ 
+ @end table
+ 
++@item --gnu2-tls-tag
++@itemx --no-gnu2-tls-tag
++Add @code{GLIBC_ABI_GNU2_TLS} version tag dependency in output programs
++and shared libraries when linking against glibc if input relocatable
++object files have @code{R_X86_64_TLSDESC_CALL} relocation.  The output
++will fail to load and run at run-time against glibc which doesn't define
++the @code{GLIBC_ABI_GNU2_TLS} version tag.  Unless disabled by the
++@option{--disable-gnu2-tls-tag} configure option at the linker build
++time, when no options are specified, linker will add the
++@code{GLIBC_ABI_GNU2_TLS} version tag dependency if inputs have
++@code{R_X86_64_TLSDESC_CALL} relocation and libc.so defines the
++@code{GLIBC_ABI_GNU2_TLS} version tag.  Supported for Linux/x86_64.
++
+ Other keywords are ignored for Solaris compatibility.
+ 
+ @kindex -(
+diff --git a/ld/ldlex.h b/ld/ldlex.h
+index 815da76a4c0..58bbd5771da 100644
+--- a/ld/ldlex.h
++++ b/ld/ldlex.h
+@@ -471,6 +471,9 @@ enum option_values
+   OPTION_NO_LITERAL_MOVEMENT,
+   OPTION_ABI_WINDOWED,
+   OPTION_ABI_CALL0,
++  /* Used by emultempl/elf-x86-64.em.  */
++  OPTION_GNU2_TLS_TAG,
++  OPTION_NO_GNU2_TLS_TAG,
+ };
+ 
+ /* The initial parser states.  */
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1.rd b/ld/testsuite/ld-x86-64/gnu2-tls-1.rd
+new file mode 100644
+index 00000000000..3eb926a227c
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1.rd
+@@ -0,0 +1,7 @@
++#...
++Version needs section '.gnu.version_r' contains 1 entry:
++ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
++ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
++#...
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
++#pass
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.od b/ld/testsuite/ld-x86-64/gnu2-tls-1a.od
+new file mode 100644
+index 00000000000..e237b26898d
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.od
+@@ -0,0 +1,13 @@
++
++.*: +file format .*
++#...
++[a-f0-9]+ <main>:
++ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
++ +[a-f0-9]+:	48 8d 05 ([0-9a-f]{2} ){4}	lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo@@Base\+0x[a-f0-9]+>
++ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
++ +[a-f0-9]+:	ff 10                	call   \*\(%rax\)
++ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
++ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
++ +[a-f0-9]+:	c3                   	ret
++ +[a-f0-9]+:	90                   	nop
++#pass
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1a.s b/ld/testsuite/ld-x86-64/gnu2-tls-1a.s
+new file mode 100644
+index 00000000000..b8c004538ff
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1a.s
+@@ -0,0 +1,14 @@
++	.section	.text.startup,"ax",@progbits
++	.p2align 4
++	.globl	main
++	.type	main, @function
++main:
++	subq	$8, %rsp
++	leaq	foo@TLSDESC(%rip), %rax
++	.nops 10
++	call	*foo@TLSCALL(%rax)
++	movl	%fs:(%rax), %eax
++	addq	$8, %rsp
++	ret
++	.size	main, .-main
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.od b/ld/testsuite/ld-x86-64/gnu2-tls-1b.od
+new file mode 100644
+index 00000000000..8bd685006bd
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.od
+@@ -0,0 +1,13 @@
++
++.*: +file format .*
++#...
++[a-f0-9]+ <main>:
++ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
++ +[a-f0-9]+:	48 c7 c0 fc ff ff ff 	mov    \$0xfffffffffffffffc,%rax
++ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
++ +[a-f0-9]+:	66 90                	xchg   %ax,%ax
++ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
++ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
++ +[a-f0-9]+:	c3                   	ret
++ +[a-f0-9]+:	90                   	nop
++#pass
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1b.s b/ld/testsuite/ld-x86-64/gnu2-tls-1b.s
+new file mode 100644
+index 00000000000..fcc355f7e5c
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1b.s
+@@ -0,0 +1,9 @@
++	.text
++	.globl	foo
++	.section	.tbss,"awT",@nobits
++	.align 4
++	.type	foo, @object
++	.size	foo, 4
++foo:
++	.zero	4
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-1c.od b/ld/testsuite/ld-x86-64/gnu2-tls-1c.od
+new file mode 100644
+index 00000000000..8bd685006bd
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-1c.od
+@@ -0,0 +1,13 @@
++
++.*: +file format .*
++#...
++[a-f0-9]+ <main>:
++ +[a-f0-9]+:	48 83 ec 08          	sub    \$0x8,%rsp
++ +[a-f0-9]+:	48 c7 c0 fc ff ff ff 	mov    \$0xfffffffffffffffc,%rax
++ +[a-f0-9]+:	66 2e 0f 1f 84 00 00 00 00 00 	cs nopw 0x0\(%rax,%rax,1\)
++ +[a-f0-9]+:	66 90                	xchg   %ax,%ax
++ +[a-f0-9]+:	64 8b 00             	mov    %fs:\(%rax\),%eax
++ +[a-f0-9]+:	48 83 c4 08          	add    \$0x8,%rsp
++ +[a-f0-9]+:	c3                   	ret
++ +[a-f0-9]+:	90                   	nop
++#pass
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-2.rd b/ld/testsuite/ld-x86-64/gnu2-tls-2.rd
+new file mode 100644
+index 00000000000..33ef8acb232
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-2.rd
+@@ -0,0 +1,4 @@
++#failif
++#...
++  0x[a-f0-9]+:   Name: GLIBC_ABI_GNU2_TLS  Flags: none  Version: [0-9]+
++#...
+diff --git a/ld/testsuite/ld-x86-64/gnu2-tls-2.s b/ld/testsuite/ld-x86-64/gnu2-tls-2.s
+new file mode 100644
+index 00000000000..d957eb71f6d
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/gnu2-tls-2.s
+@@ -0,0 +1,13 @@
++	.text
++	.p2align 4
++	.globl	func
++	.type	func, @function
++func:
++	leaq	foo@tlsld(%rip), %rdi
++	call	__tls_get_addr@PLT
++	data16	leaq	foo@tlsgd(%rip), %rdi
++	.value	0x6666
++	rex64
++	call	__tls_get_addr@PLT
++	.size	func, .-func
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/mark-plt-2.rd b/ld/testsuite/ld-x86-64/mark-plt-2.rd
+new file mode 100644
+index 00000000000..b0ed7024420
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/mark-plt-2.rd
+@@ -0,0 +1,7 @@
++#...
++Version needs section '.gnu.version_r' contains 1 entry:
++ Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
++ +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
++#...
++  0x[a-f0-9]+:   Name: (GLIBC_2.36|GLIBC_ABI_DT_X86_64_PLT)  Flags: none  Version: [0-9]+
++#pass
+diff --git a/ld/testsuite/ld-x86-64/mark-plt-2.s b/ld/testsuite/ld-x86-64/mark-plt-2.s
+new file mode 100644
+index 00000000000..c816567c204
+--- /dev/null
++++ b/ld/testsuite/ld-x86-64/mark-plt-2.s
+@@ -0,0 +1,13 @@
++	.text
++	.globl	foo
++	.type	foo, @function
++foo:
++	subq	$8, %rsp
++	leaq	xxx@TLSDESC(%rip), %rax
++	.nops 10
++	call	*xxx@TLSCALL(%rax)
++	movl	%fs:(%rax), %eax
++	addq	$8, %rsp
++	call	bar
++	ret
++	.section	.note.GNU-stack,"",@progbits
+diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
+index 6b86bc3d018..2ee12a2ef55 100644
+--- a/ld/testsuite/ld-x86-64/x86-64.exp
++++ b/ld/testsuite/ld-x86-64/x86-64.exp
+@@ -2358,7 +2358,7 @@ run_dump_test "ibt-plt-3b-x32"
+ run_dump_test "ibt-plt-3c-x32"
+ run_dump_test "ibt-plt-3d-x32"
+ 
+-# Skip -z mark-plt tests on MUSL.
++# Skip -z mark-plt and --gnu2-tls-tag tests on MUSL.
+ if { [istarget "x86_64-*-musl*"]} {
+     set ASFLAGS "$saved_ASFLAGS"
+     return
+@@ -2384,6 +2384,57 @@ if { [check_compiler_available] } {
+ 	     {readelf {-W --version-info} mark-plt-1b.rd}} \
+ 	    "mark-plt-1.so" \
+ 	] \
++	[list \
++	    "Build mark-plt-2.so" \
++	    "-shared -Wl,--no-as-needed,-z,mark-plt,-z,nopack-relative-relocs" \
++	    "-fPIC" \
++	    { mark-plt-2.s } \
++	    {{readelf {-W --version-info} mark-plt-2.rd}} \
++	    "mark-plt-2.so" \
++	] \
++	[list \
++	    "Build gnu2-tls-1.so" \
++	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
++	    {{objdump {-dw} gnu2-tls-1a.od}
++	     {readelf {-W --version-info} gnu2-tls-1.rd}} \
++	    "gnu2-tls-1.so" \
++	] \
++	[list \
++	    "Build gnu2-tls-1-no-gnu2-tls.so" \
++	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1.s } \
++	    {{readelf {-W --version-info} gnu2-tls-2.rd}} \
++	    "gnu2-tls-1-no-gnu2-tls.so" \
++	] \
++	[list \
++	    "Build gnu2-tls-1 (PDE)" \
++	    "$NOPIE_LDFLAGS -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
++	    {{objdump {-dw} gnu2-tls-1b.od}
++	     {readelf {-W --version-info} gnu2-tls-2.rd}} \
++	    "gnu2-tls-1.pde" \
++	] \
++	[list \
++	    "Build gnu2-tls-1 (PIE)" \
++	    "-pie -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-1a.s gnu2-tls-1b.s } \
++	    {{objdump {-dw} gnu2-tls-1c.od}
++	     {readelf {-W --version-info} gnu2-tls-2.rd}} \
++	    "gnu2-tls-1.pie" \
++	] \
++	[list \
++	    "Build gnu2-tls-2.so" \
++	    "-shared -Wl,--no-as-needed,--gnu2-tls-tag" \
++	    "-fPIC" \
++	    { gnu2-tls-2.s } \
++	    {{readelf {-W --version-info} gnu2-tls-2.rd}} \
++	    "gnu2-tls-2.s.so" \
++	] \
+     ]
+ }
+ 
+
+base-commit: a5858e81363051a818ea163d52f62d8251097d11
+-- 
+2.50.1
+

diff --git a/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch b/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
new file mode 100644
index 0000000..a992ef1
--- /dev/null
+++ b/9999/0007-x86-64-Add-GLIBC_ABI_DT_X86_64_PLT-version-dependenc.patch
@@ -0,0 +1,160 @@
+From 6eafbdfab0ff4baecf85e095966f0e7f8b6e2fc8 Mon Sep 17 00:00:00 2001
+Message-ID: <6eafbdfab0ff4baecf85e095966f0e7f8b6e2fc8.1755459855.git.sam@gentoo.org>
+In-Reply-To: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+References: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sun, 17 Aug 2025 11:55:18 -0700
+Subject: [PATCH 2/3] x86-64: Add GLIBC_ABI_DT_X86_64_PLT version dependency
+
+On Linux/x86-64, programs and shared libraries created with -z mark-plt
+have the GLIBC_2.36 version tag dependency since -z mark-plt uses the
+r_addend field of the R_X86_64_JUMP_SLOT relocation to store the offset
+of the indirect branch instruction.  Glibc versions which don't have the
+commit added to glibc 2.36:
+
+commit f8587a61892cbafd98ce599131bf4f103466f084
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Fri May 20 19:21:48 2022 -0700
+
+    x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
+
+won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation.  If
+glibc versions defines GLIBC_ABI_DT_X86_64_PLT version tag with
+
+commit 399384e0c8193e31aea014220ccfa24300ae5938
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Thu Aug 14 07:03:20 2025 -0700
+
+    x86-64: Add GLIBC_ABI_DT_X86_64_PLT [BZ #33212]
+
+to indicate inclusion of the commit:
+
+commit f8587a61892cbafd98ce599131bf4f103466f084
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Fri May 20 19:21:48 2022 -0700
+
+    x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT
+
+we can add GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of
+GLIBC_2.36 version tag dependency.
+
+	PR ld/33213
+	* elf-bfd.h (_bfd_elf_link_add_glibc_version_dependency): Change
+	return type to bool.
+	* elf64-x86-64.c (elf_x86_64_add_glibc_version_dependency): Add
+	GLIBC_ABI_DT_X86_64_PLT version tag dependency, instead of,
+	GLIBC_2.36 version tag dependency, for -z mark-plt if libc.so
+	defines GLIBC_ABI_DT_X86_64_PLT version tag.
+	* elflink.c (_bfd_elf_link_add_glibc_version_dependency): Change
+	return type to bool.  Return false if elf_link_add_glibc_verneed
+	returns false.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elf-bfd.h                         |  2 +-
+ bfd/elf64-x86-64.c                    | 24 +++++++++++++++++++-----
+ bfd/elflink.c                         |  6 ++++--
+ ld/testsuite/ld-x86-64/mark-plt-1a.rd |  2 +-
+ 4 files changed, 25 insertions(+), 9 deletions(-)
+
+diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
+index feb470fc477..de7cc410a99 100644
+--- a/bfd/elf-bfd.h
++++ b/bfd/elf-bfd.h
+@@ -2631,7 +2631,7 @@ extern bool _bfd_elf_link_output_relocs
+   (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *,
+    struct elf_link_hash_entry **);
+ 
+-extern void _bfd_elf_link_add_glibc_version_dependency
++extern bool _bfd_elf_link_add_glibc_version_dependency
+   (struct elf_find_verdep_info *, const char *const [], bool *);
+ 
+ extern void _bfd_elf_link_add_dt_relr_dependency
+diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
+index 03873a9ed6b..db3c20679a3 100644
+--- a/bfd/elf64-x86-64.c
++++ b/bfd/elf64-x86-64.c
+@@ -6246,7 +6246,7 @@ static void
+ elf_x86_64_add_glibc_version_dependency
+   (struct elf_find_verdep_info *rinfo)
+ {
+-  unsigned int i = 0;
++  int i = 0, mark_plt = -1;
+   const char *version[4] = { NULL, NULL, NULL, NULL };
+   bool auto_version[4] = { false, false, false, false };
+   struct elf_x86_link_hash_table *htab;
+@@ -6271,14 +6271,28 @@ elf_x86_64_add_glibc_version_dependency
+ 	}
+       if (htab->params->mark_plt)
+ 	{
+-	  version[i] = "GLIBC_2.36";
++	  mark_plt = i;
++	  auto_version[i] = true;
++	  version[i] = "GLIBC_ABI_DT_X86_64_PLT";
+ 	  i++;
+ 	}
+     }
+ 
+-  if (i != 0)
+-    _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
+-						auto_version);
++  if (i == 0
++      || !_bfd_elf_link_add_glibc_version_dependency (rinfo, version,
++						      auto_version))
++    return;
++
++  if (mark_plt < 0 || auto_version[mark_plt])
++    return;
++
++  /* Add the GLIBC_2.36 version dependency if libc.so doesn't have
++     GLIBC_ABI_DT_X86_64_PLT.  */
++  version[0] = "GLIBC_2.36";
++  auto_version[0] = false;
++  version[1] = NULL;
++  _bfd_elf_link_add_glibc_version_dependency (rinfo, version,
++					      auto_version);
+ }
+ 
+ static const struct bfd_elf_special_section
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index ac40423751f..98759a3dec6 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -2401,7 +2401,7 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
+ /* Add VERSION_DEP to the list of version dependencies when linked
+    against glibc.  */
+ 
+-void
++bool
+ _bfd_elf_link_add_glibc_version_dependency
+   (struct elf_find_verdep_info *rinfo,
+    const char *const version_dep[],
+@@ -2414,11 +2414,13 @@ _bfd_elf_link_add_glibc_version_dependency
+       /* Return if not linked against glibc.  */
+       if (!elf_link_add_glibc_verneed (rinfo, *version_dep,
+ 				       &glibc_minor_base, auto_version))
+-	return;
++	return false;
+       version_dep++;
+       auto_version++;
+     }
+   while (*version_dep != NULL);
++
++  return true;
+ }
+ 
+ /* Add GLIBC_ABI_DT_RELR to the list of version dependencies when
+diff --git a/ld/testsuite/ld-x86-64/mark-plt-1a.rd b/ld/testsuite/ld-x86-64/mark-plt-1a.rd
+index 1234fbe038c..b0ed7024420 100644
+--- a/ld/testsuite/ld-x86-64/mark-plt-1a.rd
++++ b/ld/testsuite/ld-x86-64/mark-plt-1a.rd
+@@ -3,5 +3,5 @@ Version needs section '.gnu.version_r' contains 1 entry:
+  Addr: 0x[0-9a-f]+ +Offset: 0x[0-9a-f]+ +Link: +[0-9]+ +\(.dynstr\)
+  +0+: Version: 1 +File: libc\.so\.6(|\.1) +Cnt: +[0-9]+
+ #...
+-  0x[a-f0-9]+:   Name: GLIBC_2.36  Flags: none  Version: [0-9]+
++  0x[a-f0-9]+:   Name: (GLIBC_2.36|GLIBC_ABI_DT_X86_64_PLT)  Flags: none  Version: [0-9]+
+ #pass
+-- 
+2.50.1
+

diff --git a/9999/0008-ld-Properly-override-compiler-flags-in-tests.patch b/9999/0008-ld-Properly-override-compiler-flags-in-tests.patch
new file mode 100644
index 0000000..cd38be5
--- /dev/null
+++ b/9999/0008-ld-Properly-override-compiler-flags-in-tests.patch
@@ -0,0 +1,393 @@
+From d4cbc75a7fb72c0fadf86fea73d86540fdc88166 Mon Sep 17 00:00:00 2001
+Message-ID: <d4cbc75a7fb72c0fadf86fea73d86540fdc88166.1755459855.git.sam@gentoo.org>
+In-Reply-To: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+References: <35d2c802f63122702ac48296dac025470c5d1467.1755459855.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sat, 16 Aug 2025 14:49:05 -0700
+Subject: [PATCH 3/3] ld: Properly override compiler flags in tests
+
+Some tests need to be compiled with additional flags.  When binutils is
+built and compiled with
+
+CC="gcc -fsanitize=address,undefined" CXX="g++ -fsanitize=address,undefined"
+
+some linker tests fail to disable address sanitizer options since
+proc default_ld_compile has
+
+    set ccexe $cc
+    set ccparm [string first " " $cc]
+    set ccflags ""
+    if { $ccparm > 0 } then {
+        set ccflags [string range $cc $ccparm end]
+        set ccexe [string range $cc 0 $ccparm]
+        set cc $ccexe
+    }
+...
+    set cmd "$cc $flags $ccflags -c $source -o $object"
+
+Compiler flags in $CC and $CXX will be the last ones.  Add
+CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST to use them in
+proc default_ld_compile
+
+    set cflag_test ""
+    set cxxflag_test ""
+    if {[string match "*++*" $ccexe]} {
+        append flags " $CXXFLAGS_FOR_TARGET"
+        set cflag_test "$CXXFLAGS_FOR_TARGET_TEST"
+    } else {
+        append flags " $CFLAGS_FOR_TARGET"
+        set cflag_test "$CFLAGS_FOR_TARGET_TEST"
+    }
+...
+    set cmd "$cc $flags $ccflags $cflag_test -c $source -o $object"
+
+so that they will be the last flags passed to compiler.  Also update
+run_ld_link_exec_tests and run_cc_link_tests to make
+CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST the last flags
+passed to compiler.
+
+	* testsuite/config/default.exp (CFLAGS_FOR_TARGET_TEST): New.
+	(CXXFLAGS_FOR_TARGET_TEST): Likewise.
+	* testsuite/ld-elf/dwarf.exp (CFLAGS_FOR_TARGET): Renamed to ...
+	(CFLAGS_FOR_TARGET_TEST): This.
+	* testsuite/ld-elf/shared.exp: Save, append and restore
+	CFLAGS_FOR_TARGET_TEST and CXXFLAGS_FOR_TARGET_TEST for
+	$build_tests.  Save, append and restore CFLAGS_FOR_TARGET_TEST,
+	instead of CFLAGS_FOR_TARGET, for $dlopen_run_tests.
+	* testsuite/ld-plugin/plugin.exp (CFLAGS_FOR_TARGET): Renamed to
+	...
+	(CFLAGS_FOR_TARGET_TEST): This.
+	* testsuite/ld-shared/shared.exp (CFLAGS_FOR_TARGET): Renamed to
+	...
+	(CFLAGS_FOR_TARGET_TEST): This.
+	* testsuite/ld-srec/srec.exp (CFLAGS_FOR_TARGET): Renamed to ...
+	(CFLAGS_FOR_TARGET_TEST): This.
+	(CXXFLAGS_FOR_TARGET): Renamed to ...
+	(CXXFLAGS_FOR_TARGET_TEST): This.
+	* testsuite/lib/ld-lib.exp (default_ld_compile): Append
+	CFLAGS_FOR_TARGET_TEST/CXXFLAGS_FOR_TARGET_TEST to compiler flags.
+	(run_ld_link_exec_tests): Append CFLAGS_FOR_TARGET_TEST and
+	CXXFLAGS_FOR_TARGET_TEST to compiler.
+	(run_cc_link_tests): Likewise.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ ld/testsuite/config/default.exp   |  6 ++++++
+ ld/testsuite/ld-elf/dwarf.exp     |  6 +++---
+ ld/testsuite/ld-elf/shared.exp    | 12 +++++++++---
+ ld/testsuite/ld-plugin/plugin.exp | 10 +++++-----
+ ld/testsuite/ld-shared/shared.exp |  8 ++++----
+ ld/testsuite/ld-srec/srec.exp     | 28 ++++++++++++++--------------
+ ld/testsuite/lib/ld-lib.exp       | 28 +++++++++++++++++++---------
+ 7 files changed, 60 insertions(+), 38 deletions(-)
+
+diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
+index 1c12ce60193..9f286831e07 100644
+--- a/ld/testsuite/config/default.exp
++++ b/ld/testsuite/config/default.exp
+@@ -117,12 +117,18 @@ if {![info exists CC_FOR_TARGET]} {
+ if {![info exists CFLAGS_FOR_TARGET]} {
+     set CFLAGS_FOR_TARGET "-g -O2"
+ }
++if {![info exists CFLAGS_FOR_TARGET_TEST]} {
++    set CFLAGS_FOR_TARGET_TEST ""
++}
+ if {![info exists CXX_FOR_TARGET]} {
+     set CXX_FOR_TARGET [find_g++]
+ }
+ if {![info exists CXXFLAGS_FOR_TARGET]} {
+     set CXXFLAGS_FOR_TARGET ""
+ }
++if {![info exists CXXFLAGS_FOR_TARGET_TEST]} {
++    set CXXFLAGS_FOR_TARGET_TEST ""
++}
+ 
+ # This allows us to run the linker testsuite with clang as the compilation
+ # driver instead of gcc.  The syntax of the overrides are as follows, one
+diff --git a/ld/testsuite/ld-elf/dwarf.exp b/ld/testsuite/ld-elf/dwarf.exp
+index c7b2915a963..4f7963526e9 100644
+--- a/ld/testsuite/ld-elf/dwarf.exp
++++ b/ld/testsuite/ld-elf/dwarf.exp
+@@ -69,11 +69,11 @@ set run_tests {
+ }
+ 
+ # Disable all sanitizers.
+-set old_CFLAGS "$CFLAGS_FOR_TARGET"
+-append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
++set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
+ run_cc_link_tests $build_tests
+ run_ld_link_exec_tests $run_tests
+-set CFLAGS_FOR_TARGET "$old_CFLAGS"
++set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
+ 
+ proc strip_test {} {
+     global ld
+diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
+index ee881c2d619..a24525a2ff8 100644
+--- a/ld/testsuite/ld-elf/shared.exp
++++ b/ld/testsuite/ld-elf/shared.exp
+@@ -972,7 +972,13 @@ append build_tests {
+    {pr26580-b.c} {} "libpr26580-2.so"}
+ }
+ 
++set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
++append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
++append CXXFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
+ run_cc_link_tests $build_tests
++set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
++set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
+ 
+ run_cc_link_tests [list \
+     [list \
+@@ -1259,10 +1265,10 @@ if [check_libdl_available] {
+   # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
+   # sections.
+   # Disable all sanitizers.
+-  set old_CFLAGS "$CFLAGS_FOR_TARGET"
+-  append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
++  set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++  append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
+   run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsd*"
+-  set CFLAGS_FOR_TARGET "$old_CFLAGS"
++  set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
+ }
+ 
+ # Check --no-add-needed and --no-copy-dt-needed-entries
+diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp
+index 38a40363681..2e148e4cbf8 100644
+--- a/ld/testsuite/ld-plugin/plugin.exp
++++ b/ld/testsuite/ld-plugin/plugin.exp
+@@ -87,11 +87,11 @@ set regcln "-plugin-opt registercleanup"
+ set failed_compile 0
+ set _ ""
+ set plugin_nm_output ""
+-set old_CFLAGS "$CFLAGS_FOR_TARGET"
+-append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
++set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
+ if { [istarget m681*-*-*] || [istarget m68hc1*-*-*] || [istarget m9s12x*-*-*] } {
+     # otherwise get FAILS due to _.frame
+-    append CFLAGS_FOR_TARGET " -fomit-frame-pointer"
++    append CFLAGS_FOR_TARGET_TEST " -fomit-frame-pointer"
+ }
+ 
+ if { $can_compile && \
+@@ -291,7 +291,7 @@ if { !$can_compile || $failed_compile } {
+ 	    unsupported [lindex $testitem 0]
+ 	}
+     }
+-    set CFLAGS_FOR_TARGET "$old_CFLAGS"
++    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
+     return
+ }
+ 
+@@ -394,4 +394,4 @@ if [ar_simple_create $ar "--plugin $plugin4_path" "tmpdir/libpr20070.a" \
+     unsupported "PR ld/20070"
+ }
+ 
+-set CFLAGS_FOR_TARGET "$old_CFLAGS"
++set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
+diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
+index 29de93a1957..e7f77fad567 100644
+--- a/ld/testsuite/ld-shared/shared.exp
++++ b/ld/testsuite/ld-shared/shared.exp
+@@ -67,8 +67,8 @@ set SHCFLAG ""
+ set shared_needs_pic "no"
+ 
+ # Disable all sanitizers.
+-set old_CFLAGS "$CFLAGS_FOR_TARGET"
+-append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
++set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++append CFLAGS_FOR_TARGET_TEST " $NOSANITIZE_CFLAGS"
+ 
+ if { [is_xcoff_format] } {
+     # Not all the useful features are available with AIX shared
+@@ -104,7 +104,7 @@ if [istarget arm*-*-linux*] {
+ 	set file [open $tmpdir/movw-detect.c w]
+ 	puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
+ 	close $file
+-	if [run_host_cmd_yesno "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
++	if [run_host_cmd_yesno "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET_TEST -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
+ 	    set shared_needs_pic "yes"
+ 	}
+     }
+@@ -343,4 +343,4 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
+     }
+ }
+ 
+-set CFLAGS_FOR_TARGET "$old_CFLAGS"
++set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
+diff --git a/ld/testsuite/ld-srec/srec.exp b/ld/testsuite/ld-srec/srec.exp
+index bec59130425..5afc84c24b6 100644
+--- a/ld/testsuite/ld-srec/srec.exp
++++ b/ld/testsuite/ld-srec/srec.exp
+@@ -365,24 +365,24 @@ if { ![check_compiler_available] } {
+ # tests. Also add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if PIE doesn't work
+ # with S-records.  Also add $NOCF_PROTECTION_CFLAGS for S-records.
+ # Also add $NOSANITIZE_CFLAGS for S-records.
+-set old_CFLAGS "$CFLAGS_FOR_TARGET"
+-append CFLAGS_FOR_TARGET " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
+-set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET"
+-append CXXFLAGS_FOR_TARGET " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
++set old_CFLAGS "$CFLAGS_FOR_TARGET_TEST"
++append CFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
++set old_CXXFLAGS "$CXXFLAGS_FOR_TARGET_TEST"
++append CXXFLAGS_FOR_TARGET_TEST " $PLT_CFLAGS $NOPIE_CFLAGS $NOPIE_LDFLAGS $NOCF_PROTECTION_CFLAGS $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
+ 
+ # S-records can't handle .note.gnu.property sections.
+ if { [is_elf_format] \
+      && ([istarget "i?86-*-*"] || [istarget "x86_64-*-*"]) } {
+-    append CFLAGS_FOR_TARGET " -Wa,-mx86-used-note=no"
+-    append CXXFLAGS_FOR_TARGET " -Wa,-mx86-used-note=no"
++    append CFLAGS_FOR_TARGET_TEST " -Wa,-mx86-used-note=no"
++    append CXXFLAGS_FOR_TARGET_TEST " -Wa,-mx86-used-note=no"
+ }
+ 
+ if { ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/sr1.c tmpdir/sr1.o] \
+      || ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/sr2.c tmpdir/sr2.o] } {
+     unsupported $test1
+     unsupported $test2
+-    set CFLAGS_FOR_TARGET "$old_CFLAGS"
+-    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
++    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
++    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
+     return
+ }
+ 
+@@ -454,15 +454,15 @@ run_srec_test $test1 "tmpdir/sr1.o tmpdir/sr2.o"
+ 
+ if { ![is_remote host] && [which $CXX_FOR_TARGET] == 0 } {
+     untested $test2
+-    set CFLAGS_FOR_TARGET "$old_CFLAGS"
+-    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
++    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
++    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
+     return
+ }
+ 
+ if ![ld_compile "$CXX_FOR_TARGET -fno-exceptions" $srcdir/$subdir/sr3.cc tmpdir/sr3.o] {
+     unsupported $test2
+-    set CFLAGS_FOR_TARGET "$old_CFLAGS"
+-    set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
++    set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
++    set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
+     return
+ }
+ 
+@@ -488,5 +488,5 @@ setup_xfail "bpf-*-*"
+ 
+ run_srec_test $test2 "tmpdir/sr3.o"
+ 
+-set CFLAGS_FOR_TARGET "$old_CFLAGS"
+-set CXXFLAGS_FOR_TARGET "$old_CXXFLAGS"
++set CFLAGS_FOR_TARGET_TEST "$old_CFLAGS"
++set CXXFLAGS_FOR_TARGET_TEST "$old_CXXFLAGS"
+diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
+index 22d2f987b87..d1343eb12ca 100644
+--- a/ld/testsuite/lib/ld-lib.exp
++++ b/ld/testsuite/lib/ld-lib.exp
+@@ -253,6 +253,8 @@ proc default_ld_link { ld target objects } {
+ proc default_ld_compile { cc source object } {
+     global CFLAGS_FOR_TARGET
+     global CXXFLAGS_FOR_TARGET
++    global CFLAGS_FOR_TARGET_TEST
++    global CXXFLAGS_FOR_TARGET_TEST
+     global srcdir
+     global subdir
+     global host_triplet
+@@ -286,10 +288,14 @@ proc default_ld_compile { cc source object } {
+     }
+ 
+     set ccexe [string replace $ccexe 0 [string last "/" $ccexe] ""]
++    set cflag_test ""
++    set cxxflag_test ""
+     if {[string match "*++*" $ccexe]} {
+ 	append flags " $CXXFLAGS_FOR_TARGET"
++	set cflag_test "$CXXFLAGS_FOR_TARGET_TEST"
+     } else {
+ 	append flags " $CFLAGS_FOR_TARGET"
++	set cflag_test "$CFLAGS_FOR_TARGET_TEST"
+     }
+ 
+     if [board_info [target_info name] exists cflags] {
+@@ -300,7 +306,7 @@ proc default_ld_compile { cc source object } {
+ 	append flags " [board_info [target_info name] multilib_flags]"
+     }
+ 
+-    set cmd "$cc $flags $ccflags -c $source -o $object"
++    set cmd "$cc $flags $ccflags $cflag_test -c $source -o $object"
+     verbose -log "$cmd"
+ 
+     set status [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
+@@ -727,6 +733,8 @@ proc run_ld_link_exec_tests { ldtests args } {
+     global env
+     global CC_FOR_TARGET
+     global CXX_FOR_TARGET
++    global CFLAGS_FOR_TARGET_TEST
++    global CXXFLAGS_FOR_TARGET_TEST
+     global errcnt
+     global exec_output
+     global STATIC_LDFLAGS
+@@ -780,9 +788,9 @@ proc run_ld_link_exec_tests { ldtests args } {
+ 	    lappend objfiles $objfile
+ 
+ 	    if { [ string match "c++" $lang ] } {
+-		set cmd "$CXX_FOR_TARGET -c $cflags"
++		set cmd "$CXX_FOR_TARGET -c $cflags $CXXFLAGS_FOR_TARGET_TEST"
+ 	    } else {
+-		set cmd "$CC_FOR_TARGET -c $cflags"
++		set cmd "$CC_FOR_TARGET -c $cflags $CFLAGS_FOR_TARGET_TEST"
+ 	    }
+ 	    if ![ld_compile $cmd $srcdir/$subdir/$src_file $objfile] {
+ 		set failed 1
+@@ -799,10 +807,10 @@ proc run_ld_link_exec_tests { ldtests args } {
+ 	    set link_cmd $ld
+ 	} elseif { [ string match "c++" $lang ] } {
+ 	    set link_proc ld_link
+-	    set link_cmd $CXX_FOR_TARGET
++	    set link_cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST"
+ 	} else {
+ 	    set link_proc ld_link
+-	    set link_cmd $CC_FOR_TARGET
++	    set link_cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST"
+ 	}
+ 
+ 	if { $binfile eq "tmpdir/" } {
+@@ -888,6 +896,8 @@ proc run_cc_link_tests { ldtests } {
+     global env
+     global CC_FOR_TARGET
+     global CXX_FOR_TARGET
++    global CFLAGS_FOR_TARGET_TEST
++    global CXXFLAGS_FOR_TARGET_TEST
+     global ar
+     global exec_output
+     global STATIC_LDFLAGS
+@@ -969,9 +979,9 @@ proc run_cc_link_tests { ldtests } {
+ 	    lappend objfiles $objfile
+ 
+ 	    if { [ string match "c++" $lang ] } {
+-		set cmd "$CXX_FOR_TARGET -c $cflags"
++		set cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST -c $cflags"
+ 	    } else {
+-		set cmd "$CC_FOR_TARGET -c $cflags"
++		set cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST -c $cflags"
+ 	    }
+ 	    if ![ld_compile $cmd $srcdir/$subdir/$src_file $objfile] {
+ 		set failed 1
+@@ -987,9 +997,9 @@ proc run_cc_link_tests { ldtests } {
+ 	reset_vars
+ 
+ 	if { [ string match "c++" $lang ] } {
+-	    set cc_cmd $CXX_FOR_TARGET
++	    set cc_cmd "$CXX_FOR_TARGET $CXXFLAGS_FOR_TARGET_TEST"
+ 	} else {
+-	    set cc_cmd $CC_FOR_TARGET
++	    set cc_cmd "$CC_FOR_TARGET $CFLAGS_FOR_TARGET_TEST"
+ 	}
+ 
+ 	if { $binfile eq "tmpdir/" } {
+-- 
+2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-06 13:19 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-06 13:19 UTC (permalink / raw
  To: gentoo-commits

commit:     d7e8dae1a4f7e3e1492b1ce05b8d20a14d40648e
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  6 13:19:45 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug  6 13:19:45 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d7e8dae1

9999: drop patch merged upstream

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...n-t-treat-fat-IR-objects-as-plugin-object.patch | 474 ---------------------
 1 file changed, 474 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
deleted file mode 100644
index ca9a282..0000000
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ /dev/null
@@ -1,474 +0,0 @@
-https://inbox.sourceware.org/binutils/20250806040426.3697458-1-hjl.tools@gmail.com/T/#u
-
-From 2d6b40ce9b89f5e6b2497071910baab839d8e60b Mon Sep 17 00:00:00 2001
-Message-ID: <2d6b40ce9b89f5e6b2497071910baab839d8e60b.1754453238.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 5 Aug 2025 21:04:26 -0700
-Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
-
-Fat IR objects contains both regular sections and IR sections.  After
-
-commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Sun May 4 05:12:46 2025 +0800
-
-    strip: Add GCC LTO IR support
-
-"strip --strip-debug" no longer strips debug sections in fat IR objects
-since fat IR objects are recognized as plugin object and copied as unknown
-objects.  Add a is_strip_input field to bfd to indicate called from strip.
-Update bfd_check_format_matches not to treat archive member nor standalone
-fat IR object as IR object so that strip can remove debug and IR sections
-in fat IR object.  For archive member, it is copied as an unknown object
-if the plugin target is in use or it is a slim IR object.  For standalone
-fat IR object, it is copied as non-IR object.
-
-bfd/
-
-	PR binutils/33246
-	* archive.c: Include "plugin-api.h" and "plugin.h" if plugin is
-	enabled.
-	(_bfd_compute_and_write_armap): Don't complain plugin is needed
-	when the plugin target is in use.
-	* bfd-in2.h: Regenerated.
-	* bfd.c (bfd): Add is_strip_input.
-	* format.c (bfd_set_lto_type): If there is .llvm.lto section,
-	set LTO type to lto_fat_ir_object.
-	(bfd_check_format_matches): Don't set LTO type when setting
-	format.  When called from strip, don't treat archive member nor
-	standalone fat IR object as an IR object.
-	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
-	type derived from input sections.
-
-nm/
-
-	PR binutils/33246
-	* nm.c (filter_symbols): Don't complain plugin is needed when
-	the plugin target is in use.
-	(display_rel_file): Likewise.
-	* objcopy.c (copy_archive): Set the BFD is_strip_input field of
-	archive member to 1 to indicate called from strip.  Also copy
-	slim IR archive member as unknown object.
-	(copy_file): Set the BFD is_strip_input field of input bfd to
-	1 to indicate called from strip.
-	(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
-	sections will be removed.
-
-ld/
-
-	PR binutils/33246
-	* testsuite/ld-plugin/lto-binutils.exp (run_pr33246_test): New.
-	Run binutils/33246 tests with GCC and Clang.
-	* testsuite/ld-plugin/pr33246.c: New file.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/archive.c                           |  10 ++
- bfd/bfd-in2.h                           |   3 +
- bfd/bfd.c                               |   3 +
- bfd/format.c                            |  25 +++-
- bfd/plugin.c                            |   3 +
- binutils/nm.c                           |   9 +-
- binutils/objcopy.c                      |  13 +-
- ld/testsuite/ld-plugin/lto-binutils.exp | 175 ++++++++++++++++++++++++
- ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 9 files changed, 238 insertions(+), 7 deletions(-)
- create mode 100644 ld/testsuite/ld-plugin/pr33246.c
-
-diff --git a/bfd/archive.c b/bfd/archive.c
-index c61d4b12658..697b2ed23f2 100644
---- a/bfd/archive.c
-+++ b/bfd/archive.c
-@@ -141,6 +141,10 @@ SUBSECTION
- #include "hashtab.h"
- #include "filenames.h"
- #include "bfdlink.h"
-+#if BFD_SUPPORTS_PLUGINS
-+#include "plugin-api.h"
-+#include "plugin.h"
-+#endif
- 
- #ifndef errno
- extern int errno;
-@@ -2343,6 +2347,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
- 	  long src_count;
- 
- 	  if (bfd_get_lto_type (current) == lto_slim_ir_object
-+#if BFD_SUPPORTS_PLUGINS
-+	      && !bfd_plugin_target_p (current->xvec)
-+#endif
- 	      && report_plugin_err)
- 	    {
- 	      report_plugin_err = false;
-@@ -2400,6 +2407,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
- 
- 		      if (bfd_lto_slim_symbol_p (current,
- 						 syms[src_count]->name)
-+#if BFD_SUPPORTS_PLUGINS
-+			  && !bfd_plugin_target_p (current->xvec)
-+#endif
- 			  && report_plugin_err)
- 			{
- 			  report_plugin_err = false;
-diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index b013ef954da..12512a3962c 100644
---- a/bfd/bfd-in2.h
-+++ b/bfd/bfd-in2.h
-@@ -2131,6 +2131,9 @@ struct bfd
-   /* Set if this is the linker input BFD.  */
-   unsigned int is_linker_input : 1;
- 
-+  /* Set if this is the strip input BFD.  */
-+  unsigned int is_strip_input : 1;
-+
-   /* If this is an input for a compiler plug-in library.  */
-   ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
- 
-diff --git a/bfd/bfd.c b/bfd/bfd.c
-index 858ab5ce017..4aded6809bb 100644
---- a/bfd/bfd.c
-+++ b/bfd/bfd.c
-@@ -296,6 +296,9 @@ CODE_FRAGMENT
- .  {* Set if this is the linker input BFD.  *}
- .  unsigned int is_linker_input : 1;
- .
-+.  {* Set if this is the strip input BFD.  *}
-+.  unsigned int is_strip_input : 1;
-+.
- .  {* If this is an input for a compiler plug-in library.  *}
- .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
- .
-diff --git a/bfd/format.c b/bfd/format.c
-index d2bc318977c..bd9fa8d6c33 100644
---- a/bfd/format.c
-+++ b/bfd/format.c
-@@ -389,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
- 	    abfd->object_only_section = sec;
- 	    break;
- 	  }
-+	else if (strcmp (sec->name, ".llvm.lto") == 0)
-+	  {
-+	    type = lto_fat_ir_object;
-+	    break;
-+	  }
- 	else if (lsection.major_version == 0
- 		 && startswith (sec->name, ".gnu.lto_.lto.")
- 		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-@@ -453,10 +458,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
-     }
- 
-   if (abfd->format != bfd_unknown)
--    {
--      bfd_set_lto_type (abfd);
--      return abfd->format == format;
--    }
-+    return abfd->format == format;
- 
-   if (matching != NULL || *bfd_associated_vector != NULL)
-     {
-@@ -510,7 +512,20 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- 
-       cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
- 
--      if (cleanup)
-+      /* When called from strip, don't treat archive member nor
-+	 standalone fat IR object as an IR object.  For archive
-+	 member, it will be copied as an unknown object if the
-+	 plugin target is in use or it is a slim IR object.  For
-+	 standalone fat IR object, it will be copied as non-IR
-+	 object.  */
-+      if (cleanup
-+#if BFD_SUPPORTS_PLUGINS
-+	  && (!abfd->is_strip_input
-+	      || !bfd_plugin_target_p (abfd->xvec)
-+	      || (abfd->lto_type != lto_fat_ir_object
-+		  && abfd->my_archive == NULL))
-+#endif
-+	  )
- 	goto ok_ret;
- 
-       /* For a long time the code has dropped through to check all
-diff --git a/bfd/plugin.c b/bfd/plugin.c
-index ebdf2505cbc..43ca444e7a1 100644
---- a/bfd/plugin.c
-+++ b/bfd/plugin.c
-@@ -206,6 +206,9 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
- 	  bfd_close (nbfd);
- 	  return;
- 	}
-+
-+      /* Copy LTO type derived from input sections.  */
-+      abfd->lto_type = nbfd->lto_type;
-     }
-   else
-     {
-diff --git a/binutils/nm.c b/binutils/nm.c
-index a5d56311dde..d44083dcc94 100644
---- a/binutils/nm.c
-+++ b/binutils/nm.c
-@@ -802,6 +802,9 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
- 	continue;
- 
-       if (bfd_lto_slim_symbol_p (abfd, sym->name)
-+#if BFD_SUPPORTS_PLUGINS
-+	  && !bfd_plugin_target_p (abfd->xvec)
-+#endif
- 	  && report_plugin_err)
- 	{
- 	  report_plugin_err = false;
-@@ -1484,7 +1487,11 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
- 
-   /* lto_type is set to lto_non_ir_object when a bfd is loaded with a
-      compiler LTO plugin.  */
--  if (bfd_get_lto_type (abfd) == lto_slim_ir_object)
-+  if (bfd_get_lto_type (abfd) == lto_slim_ir_object
-+#if BFD_SUPPORTS_PLUGINS
-+      && !bfd_plugin_target_p (abfd->xvec)
-+#endif
-+     )
-     {
-       report_plugin_err = false;
-       non_fatal (_("%s: plugin needed to handle lto object"),
-diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 8bd523aba13..3404bec1d08 100644
---- a/binutils/objcopy.c
-+++ b/binutils/objcopy.c
-@@ -3689,6 +3689,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
-       bool ok_object;
-       const char *element_name;
- 
-+      this_element->is_strip_input = 1;
-+
-       element_name = bfd_get_filename (this_element);
-       /* PR binutils/17533: Do not allow directory traversal
- 	 outside of the current directory tree by archive members.  */
-@@ -3769,7 +3771,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
- 
- #if BFD_SUPPORTS_PLUGINS
-       /* Copy LTO IR file as unknown object.  */
--      if (bfd_plugin_target_p (this_element->xvec))
-+      if ((!lto_sections_removed
-+	   && this_element->lto_type == lto_slim_ir_object)
-+	  || bfd_plugin_target_p (this_element->xvec))
- 	ok_object = false;
-       else
- #endif
-@@ -3966,6 +3970,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
-       break;
-     }
- 
-+  ibfd->is_strip_input = 1;
-+
-   if (bfd_check_format (ibfd, bfd_archive))
-     {
-       bool force_output_target;
-@@ -5072,6 +5078,11 @@ strip_main (int argc, char *argv[])
- 					       SECTION_CONTEXT_REMOVE)
- 			  || !!find_section_list (".llvm.lto", false,
- 					       SECTION_CONTEXT_REMOVE));
-+  /* NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
-+     will be removed to avoid undefined references to symbols in GCC LTO
-+     debug sections.  */
-+  if (!lto_sections_removed)
-+    find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
- #endif
- 
-   i = optind;
-diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
-index 88d35171045..de017f0b946 100644
---- a/ld/testsuite/ld-plugin/lto-binutils.exp
-+++ b/ld/testsuite/ld-plugin/lto-binutils.exp
-@@ -355,3 +355,178 @@ run_cc_link_tests [list \
- 	"tmpdir/libstrip-1b-fat-s.a" \
-     ] \
- ]
-+
-+proc run_pr33246_test { llvm fat } {
-+    global srcdir
-+    global subdir
-+    global plug_opt
-+    global llvm_plug_opt
-+    global ar
-+    global CLANG_FOR_TARGET
-+    global CC_FOR_TARGET
-+    global NM
-+    global READELF
-+    global strip
-+
-+    set strip_flags "--strip-debug --enable-deterministic-archives"
-+
-+    set test pr33246
-+    set testname "${test}${llvm}${fat} with $strip_flags"
-+
-+    if { "$llvm" == "-llvm" } {
-+	# Skip native x32 and i?86 targets since system LLVMgold.so may
-+	# not be compatible with native x32 and i?86 targets binutils.
-+	if { [istarget "x86_64-*-linux*-gnux32"]
-+	     || [istarget "i?86-*-*"]
-+	     || ![info exists CLANG_FOR_TARGET]
-+	     || [string match "" $llvm_plug_opt] } then {
-+	    untested $testname
-+	    return
-+	}
-+	set CC $CLANG_FOR_TARGET
-+	set binutils_plug_opt "$llvm_plug_opt"
-+    } else {
-+	if { ![info exists CC_FOR_TARGET]
-+	     || [string match "" $plug_opt] } then {
-+	    untested $testname
-+	    return
-+	}
-+	set CC $CC_FOR_TARGET
-+	set binutils_plug_opt "$plug_opt"
-+    }
-+
-+    append strip_flags " $binutils_plug_opt"
-+
-+    set src $srcdir/$subdir/${test}.c
-+    set obj tmpdir/${test}${llvm}${fat}.o
-+    set archive tmpdir/${test}${llvm}${fat}.a
-+    set CFLAGS "-c -g -O2 -flto"
-+    if { "$fat" == "-fat" } {
-+	append CFLAGS " -ffat-lto-objects"
-+    } else {
-+	append CFLAGS " -fno-fat-lto-objects"
-+    }
-+
-+    set cmd "$CC $CFLAGS -o $obj $src"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($obj)"
-+	return
-+    }
-+
-+    set cmd "$strip $strip_flags $obj -o ${obj}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $obj)"
-+	return
-+    }
-+
-+    set cmd "$NM $binutils_plug_opt ${obj}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $obj)"
-+	return
-+    }
-+
-+    if { "$fat" == "-fat" } {
-+	set cmd "$READELF -SW ${obj}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if [regexp " \.debug_" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $obj)"
-+	    return
-+	}
-+    } else {
-+	set cmd "cmp $obj ${obj}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if ![string match "" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $obj)"
-+	    return
-+	}
-+    }
-+
-+    pass "$testname (strip $obj)"
-+
-+    set cmd "$ar $binutils_plug_opt -D -s -r -c $archive $obj"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($archive)"
-+	return
-+    }
-+
-+    set cmd "$strip $strip_flags $archive -o ${archive}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $archive)"
-+	return
-+    }
-+
-+    set cmd "$NM $binutils_plug_opt ${archive}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $archive)"
-+	return
-+    }
-+
-+    if { "$fat" == "-fat" } {
-+	set cmd "$READELF -SW ${archive}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if [regexp " \.debug_" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $archive)"
-+	    return
-+	}
-+    } else {
-+	set cmd "cmp $archive ${archive}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if ![string match "" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $archive)"
-+	    return
-+	}
-+    }
-+
-+    pass "$testname (strip $archive)"
-+}
-+
-+run_pr33246_test "" ""
-+run_pr33246_test "" "-fat"
-+run_pr33246_test "-llvm" ""
-+run_pr33246_test "-llvm" "-fat"
-diff --git a/ld/testsuite/ld-plugin/pr33246.c b/ld/testsuite/ld-plugin/pr33246.c
-new file mode 100644
-index 00000000000..cd0130cacdf
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr33246.c
-@@ -0,0 +1,4 @@
-+void
-+foo (void)
-+{
-+}
-
-base-commit: d6e93eedfb9e75846c3083f49f9015eda1a2be33
--- 
-2.50.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-06  4:07 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-06  4:07 UTC (permalink / raw
  To: gentoo-commits

commit:     96a63f007bbaf13ef507bdeb61327a0dce815d79
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  6 04:07:36 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug  6 04:07:36 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=96a63f00

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...n-t-treat-fat-IR-objects-as-plugin-object.patch | 72 ++++++++++++----------
 1 file changed, 38 insertions(+), 34 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index 7957964..ca9a282 100644
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,9 +1,9 @@
-https://inbox.sourceware.org/binutils/20250806010532.3404344-1-hjl.tools@gmail.com/
+https://inbox.sourceware.org/binutils/20250806040426.3697458-1-hjl.tools@gmail.com/T/#u
 
-From e48e12720aa4a7c3f97d70dc0d64e5ac665ccdd5 Mon Sep 17 00:00:00 2001
-Message-ID: <e48e12720aa4a7c3f97d70dc0d64e5ac665ccdd5.1754442448.git.sam@gentoo.org>
+From 2d6b40ce9b89f5e6b2497071910baab839d8e60b Mon Sep 17 00:00:00 2001
+Message-ID: <2d6b40ce9b89f5e6b2497071910baab839d8e60b.1754453238.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 5 Aug 2025 18:05:32 -0700
+Date: Tue, 5 Aug 2025 21:04:26 -0700
 Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
 
 Fat IR objects contains both regular sections and IR sections.  After
@@ -63,20 +63,20 @@ ld/
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
- bfd/archive.c                           |  12 +-
+ bfd/archive.c                           |  10 ++
  bfd/bfd-in2.h                           |   3 +
  bfd/bfd.c                               |   3 +
- bfd/format.c                            |  22 ++-
+ bfd/format.c                            |  25 +++-
  bfd/plugin.c                            |   3 +
- binutils/nm.c                           |   6 +-
+ binutils/nm.c                           |   9 +-
  binutils/objcopy.c                      |  13 +-
  ld/testsuite/ld-plugin/lto-binutils.exp | 175 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 9 files changed, 230 insertions(+), 11 deletions(-)
+ 9 files changed, 238 insertions(+), 7 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
-index c61d4b12658..491c44f5191 100644
+index c61d4b12658..697b2ed23f2 100644
 --- a/bfd/archive.c
 +++ b/bfd/archive.c
 @@ -141,6 +141,10 @@ SUBSECTION
@@ -90,25 +90,23 @@ index c61d4b12658..491c44f5191 100644
  
  #ifndef errno
  extern int errno;
-@@ -2342,7 +2346,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
- 	  long symcount;
+@@ -2343,6 +2347,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
  	  long src_count;
  
--	  if (bfd_get_lto_type (current) == lto_slim_ir_object
-+	  if (!bfd_plugin_target_p (current->xvec)
-+	      && bfd_get_lto_type (current) == lto_slim_ir_object
+ 	  if (bfd_get_lto_type (current) == lto_slim_ir_object
++#if BFD_SUPPORTS_PLUGINS
++	      && !bfd_plugin_target_p (current->xvec)
++#endif
  	      && report_plugin_err)
  	    {
  	      report_plugin_err = false;
-@@ -2398,8 +2403,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
- 			  map = new_map;
- 			}
+@@ -2400,6 +2407,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
  
--		      if (bfd_lto_slim_symbol_p (current,
--						 syms[src_count]->name)
-+		      if (!bfd_plugin_target_p (current->xvec)
-+			  && bfd_lto_slim_symbol_p (current,
-+						    syms[src_count]->name)
+ 		      if (bfd_lto_slim_symbol_p (current,
+ 						 syms[src_count]->name)
++#if BFD_SUPPORTS_PLUGINS
++			  && !bfd_plugin_target_p (current->xvec)
++#endif
  			  && report_plugin_err)
  			{
  			  report_plugin_err = false;
@@ -141,7 +139,7 @@ index 858ab5ce017..4aded6809bb 100644
  .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
  .
 diff --git a/bfd/format.c b/bfd/format.c
-index d2bc318977c..d883aa5e5a8 100644
+index d2bc318977c..bd9fa8d6c33 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
 @@ -389,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
@@ -168,7 +166,7 @@ index d2bc318977c..d883aa5e5a8 100644
  
    if (matching != NULL || *bfd_associated_vector != NULL)
      {
-@@ -510,7 +512,17 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+@@ -510,7 +512,20 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
@@ -180,10 +178,13 @@ index d2bc318977c..d883aa5e5a8 100644
 +	 standalone fat IR object, it will be copied as non-IR
 +	 object.  */
 +      if (cleanup
++#if BFD_SUPPORTS_PLUGINS
 +	  && (!abfd->is_strip_input
 +	      || !bfd_plugin_target_p (abfd->xvec)
 +	      || (abfd->lto_type != lto_fat_ir_object
-+		  && abfd->my_archive == NULL)))
++		  && abfd->my_archive == NULL))
++#endif
++	  )
  	goto ok_ret;
  
        /* For a long time the code has dropped through to check all
@@ -202,26 +203,29 @@ index ebdf2505cbc..43ca444e7a1 100644
    else
      {
 diff --git a/binutils/nm.c b/binutils/nm.c
-index a5d56311dde..94333042ee2 100644
+index a5d56311dde..d44083dcc94 100644
 --- a/binutils/nm.c
 +++ b/binutils/nm.c
-@@ -801,7 +801,8 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
-       if (sym == NULL)
+@@ -802,6 +802,9 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
  	continue;
  
--      if (bfd_lto_slim_symbol_p (abfd, sym->name)
-+      if (!bfd_plugin_target_p (abfd->xvec)
-+	  && bfd_lto_slim_symbol_p (abfd, sym->name)
+       if (bfd_lto_slim_symbol_p (abfd, sym->name)
++#if BFD_SUPPORTS_PLUGINS
++	  && !bfd_plugin_target_p (abfd->xvec)
++#endif
  	  && report_plugin_err)
  	{
  	  report_plugin_err = false;
-@@ -1484,7 +1485,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
+@@ -1484,7 +1487,11 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
  
    /* lto_type is set to lto_non_ir_object when a bfd is loaded with a
       compiler LTO plugin.  */
 -  if (bfd_get_lto_type (abfd) == lto_slim_ir_object)
-+  if (!bfd_plugin_target_p (abfd->xvec)
-+      && bfd_get_lto_type (abfd) == lto_slim_ir_object)
++  if (bfd_get_lto_type (abfd) == lto_slim_ir_object
++#if BFD_SUPPORTS_PLUGINS
++      && !bfd_plugin_target_p (abfd->xvec)
++#endif
++     )
      {
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-06  1:08 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-06  1:08 UTC (permalink / raw
  To: gentoo-commits

commit:     21500ae31ee33f2c9f701a977249d09e8f7eb526
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Aug  6 01:07:57 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Aug  6 01:07:57 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=21500ae3

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...n-t-treat-fat-IR-objects-as-plugin-object.patch | 397 +++------------------
 1 file changed, 44 insertions(+), 353 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index b34bbbb..7957964 100644
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,8 +1,9 @@
-https://inbox.sourceware.org/binutils/CAMe9rOprvH1SusdkbmAnE7L0Sr4kYeMZTYAQBw4t9oTySVsgjw@mail.gmail.com/
+https://inbox.sourceware.org/binutils/20250806010532.3404344-1-hjl.tools@gmail.com/
 
-From a0fafaa5186a248ac75e178d39fa257ddbce5f2d Mon Sep 17 00:00:00 2001
+From e48e12720aa4a7c3f97d70dc0d64e5ac665ccdd5 Mon Sep 17 00:00:00 2001
+Message-ID: <e48e12720aa4a7c3f97d70dc0d64e5ac665ccdd5.1754442448.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 3 Aug 2025 10:28:40 -0700
+Date: Tue, 5 Aug 2025 18:05:32 -0700
 Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
 
 Fat IR objects contains both regular sections and IR sections.  After
@@ -15,10 +16,12 @@ Date:   Sun May 4 05:12:46 2025 +0800
 
 "strip --strip-debug" no longer strips debug sections in fat IR objects
 since fat IR objects are recognized as plugin object and copied as unknown
-objects.  Update strip not to treat archive member nor standalone fat IR
-object as IR object so that strip can remove debug and IR sections in
-fat IR object.  For archive member, it is copied as an unknown object if
-it isn't a fat IR object nor a slim IR object.
+objects.  Add a is_strip_input field to bfd to indicate called from strip.
+Update bfd_check_format_matches not to treat archive member nor standalone
+fat IR object as IR object so that strip can remove debug and IR sections
+in fat IR object.  For archive member, it is copied as an unknown object
+if the plugin target is in use or it is a slim IR object.  For standalone
+fat IR object, it is copied as non-IR object.
 
 bfd/
 
@@ -28,14 +31,12 @@ bfd/
 	(_bfd_compute_and_write_armap): Don't complain plugin is needed
 	when the plugin target is in use.
 	* bfd-in2.h: Regenerated.
-	* format.c (bfd_check_format_lto): Removed.
-	(bfd_check_format): Updated.
-	(bfd_set_lto_type): If there is .llvm.lto section, set LTO type
-	to lto_fat_ir_object.
-	(bfd_check_format_matches_lto): Removed.
+	* bfd.c (bfd): Add is_strip_input.
+	* format.c (bfd_set_lto_type): If there is .llvm.lto section,
+	set LTO type to lto_fat_ir_object.
 	(bfd_check_format_matches): Don't set LTO type when setting
-	format.  When called from strip, don't treat archive
-	member nor standalone fat IR object as an IR object.
+	format.  When called from strip, don't treat archive member nor
+	standalone fat IR object as an IR object.
 	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
 	type derived from input sections.
 
@@ -45,12 +46,11 @@ nm/
 	* nm.c (filter_symbols): Don't complain plugin is needed when
 	the plugin target is in use.
 	(display_rel_file): Likewise.
-	* objcopy.c (copy_archive): Pass true to bfd_check_format_lto
-	to indicat called from strip.  Also copy slim IR archive member
-	as unknown object.
-	(copy_file): Call bfd_check_format_lto, instead of
-	bfd_check_format.  Pass true to bfd_check_format_lto and
-	bfd_check_format_matches_lto.
+	* objcopy.c (copy_archive): Set the BFD is_strip_input field of
+	archive member to 1 to indicate called from strip.  Also copy
+	slim IR archive member as unknown object.
+	(copy_file): Set the BFD is_strip_input field of input bfd to
+	1 to indicate called from strip.
 	(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
 	sections will be removed.
 
@@ -61,19 +61,18 @@ ld/
 	Run binutils/33246 tests with GCC and Clang.
 	* testsuite/ld-plugin/pr33246.c: New file.
 
-Co-Authored-By: Alan Modra <amodra@gmail.com>
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  bfd/archive.c                           |  12 +-
- bfd/bfd-in2.h                           |  10 +-
+ bfd/bfd-in2.h                           |   3 +
  bfd/bfd.c                               |   3 +
- bfd/format.c                            | 140 +++++++------------
- bfd/plugin.c                            |   7 +-
+ bfd/format.c                            |  22 ++-
+ bfd/plugin.c                            |   3 +
  binutils/nm.c                           |   6 +-
- binutils/objcopy.c                      |  57 +++++---
+ binutils/objcopy.c                      |  13 +-
  ld/testsuite/ld-plugin/lto-binutils.exp | 175 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 9 files changed, 290 insertions(+), 124 deletions(-)
+ 9 files changed, 230 insertions(+), 11 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
@@ -114,7 +113,7 @@ index c61d4b12658..491c44f5191 100644
  			{
  			  report_plugin_err = false;
 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index 2ff3e930bfa..12512a3962c 100644
+index b013ef954da..12512a3962c 100644
 --- a/bfd/bfd-in2.h
 +++ b/bfd/bfd-in2.h
 @@ -2131,6 +2131,9 @@ struct bfd
@@ -127,22 +126,6 @@ index 2ff3e930bfa..12512a3962c 100644
    /* If this is an input for a compiler plug-in library.  */
    ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
  
-@@ -2903,15 +2906,8 @@ bool generic_core_file_matches_executable_p
-    (bfd *core_bfd, bfd *exec_bfd);
- 
- /* Extracted from format.c.  */
--bool bfd_check_format_lto (bfd *abfd, bfd_format format,
--    bool lto_sections_removed);
--
- bool bfd_check_format (bfd *abfd, bfd_format format);
- 
--bool bfd_check_format_matches_lto
--   (bfd *abfd, bfd_format format, char ***matching,
--    bool lto_sections_removed);
--
- bool bfd_check_format_matches
-    (bfd *abfd, bfd_format format, char ***matching);
- 
 diff --git a/bfd/bfd.c b/bfd/bfd.c
 index 858ab5ce017..4aded6809bb 100644
 --- a/bfd/bfd.c
@@ -158,65 +141,10 @@ index 858ab5ce017..4aded6809bb 100644
  .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
  .
 diff --git a/bfd/format.c b/bfd/format.c
-index f3a0774af08..f8e73b7eaea 100644
+index d2bc318977c..d883aa5e5a8 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
-@@ -56,19 +56,16 @@ extern const size_t _bfd_target_vector_entries;
- 
- /*
- FUNCTION
--	bfd_check_format_lto
-+	bfd_check_format
- 
- SYNOPSIS
--	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
--				   bool lto_sections_removed);
-+	bool bfd_check_format (bfd *abfd, bfd_format format);
- 
- DESCRIPTION
- 	Verify if the file attached to the BFD @var{abfd} is compatible
- 	with the format @var{format} (i.e., one of <<bfd_object>>,
- 	<<bfd_archive>> or <<bfd_core>>).
- 
--	If LTO_SECTION_REMOVED is true, ignore plugin target.
--
- 	If the BFD has been set to a specific target before the
- 	call, only the named target and format combination is
- 	checked. If the target has not been set, or has been set to
-@@ -102,31 +99,10 @@ DESCRIPTION
- 	itself.
- */
- 
--bool
--bfd_check_format_lto (bfd *abfd, bfd_format format,
--		      bool lto_sections_removed)
--{
--  return bfd_check_format_matches_lto (abfd, format, NULL,
--				       lto_sections_removed);
--}
--
--
--/*
--FUNCTION
--	bfd_check_format
--
--SYNOPSIS
--	bool bfd_check_format (bfd *abfd, bfd_format format);
--
--DESCRIPTION
--	Similar to bfd_check_format_plugin, except plugin target isn't
--	ignored.
--*/
--
- bool
- bfd_check_format (bfd *abfd, bfd_format format)
- {
--  return bfd_check_format_matches_lto (abfd, format, NULL, false);
-+  return bfd_check_format_matches (abfd, format, NULL);
- }
- 
- struct bfd_preserve
-@@ -413,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+@@ -389,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
  	    abfd->object_only_section = sec;
  	    break;
  	  }
@@ -228,53 +156,7 @@ index f3a0774af08..f8e73b7eaea 100644
  	else if (lsection.major_version == 0
  		 && startswith (sec->name, ".gnu.lto_.lto.")
  		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-@@ -431,36 +412,32 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
- 
- /*
- FUNCTION
--	bfd_check_format_matches_lto
-+	bfd_check_format_matches
- 
- SYNOPSIS
--	bool bfd_check_format_matches_lto
--	  (bfd *abfd, bfd_format format, char ***matching,
--	   bool lto_sections_removed);
-+	bool bfd_check_format_matches
-+	  (bfd *abfd, bfd_format format, char ***matching);
- 
- DESCRIPTION
- 	Like <<bfd_check_format>>, except when it returns FALSE with
--	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
--	case, if @var{matching} is not NULL, it will be filled in with
--	a NULL-terminated list of the names of the formats that matched,
--	allocated with <<malloc>>.
-+	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.
-+	In that case, if @var{matching} is not NULL, it will be filled
-+	in with a NULL-terminated list of the names of the formats
-+	that matched, allocated with <<malloc>>.
- 	Then the user may choose a format and try again.
- 
- 	When done with the list that @var{matching} points to, the caller
- 	should free it.
--
--	If LTO_SECTION_REMOVED is true, ignore plugin target.
- */
- 
- bool
--bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
--			      char ***matching,
--			      bool lto_sections_removed ATTRIBUTE_UNUSED)
-+bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- {
-   extern const bfd_target binary_vec;
-   const bfd_target * const *target;
-   const bfd_target **matching_vector = NULL;
-   const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
-+  const bfd_target *fail_targ;
-   int match_count, best_count, best_match;
-   int ar_match_index;
-   unsigned int initial_section_id = _bfd_section_id;
-@@ -481,10 +458,7 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -453,10 +458,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
      }
  
    if (abfd->format != bfd_unknown)
@@ -286,34 +168,17 @@ index f3a0774af08..f8e73b7eaea 100644
  
    if (matching != NULL || *bfd_associated_vector != NULL)
      {
-@@ -524,20 +498,30 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
-   if (!bfd_preserve_save (abfd, &preserve, NULL))
-     goto err_ret;
- 
--  /* If the target type was explicitly specified, just check that target.
--     If LTO_SECTION_REMOVED is true, don't match the plugin target.  */
-+  /* If the target type was explicitly specified, just check that target.  */
-+  fail_targ = NULL;
-   if (!abfd->target_defaulted
- #if BFD_SUPPORTS_PLUGINS
--      && (!lto_sections_removed || !bfd_plugin_target_p (abfd->xvec))
-+      && !(abfd->plugin_format == bfd_plugin_no
-+	   && bfd_plugin_target_p (save_targ))
- #endif
--     )
-+      )
-     {
-       if (bfd_seek (abfd, 0, SEEK_SET) != 0)	/* rewind! */
- 	goto err_ret;
+@@ -510,7 +512,17 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
 -      if (cleanup)
 +      /* When called from strip, don't treat archive member nor
 +	 standalone fat IR object as an IR object.  For archive
-+	 member, it will be copied as an unknown object if it
-+	 isn't a fat IR object.  For standalone fat IR object,
-+	 it will be copied as non-IR object.  */
++	 member, it will be copied as an unknown object if the
++	 plugin target is in use or it is a slim IR object.  For
++	 standalone fat IR object, it will be copied as non-IR
++	 object.  */
 +      if (cleanup
 +	  && (!abfd->is_strip_input
 +	      || !bfd_plugin_target_p (abfd->xvec)
@@ -322,107 +187,11 @@ index f3a0774af08..f8e73b7eaea 100644
  	goto ok_ret;
  
        /* For a long time the code has dropped through to check all
-@@ -554,10 +538,10 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
- 	 target.  */
-       if (format == bfd_archive && save_targ == &binary_vec)
- 	goto err_unrecog;
-+      fail_targ = save_targ;
-     }
- 
--  /* Since the target type was defaulted, check them all in the hope
--     that one will be uniquely recognized.  */
-+  /* Check all targets in the hope that one will be recognized.  */
-   right_targ = NULL;
-   ar_right_targ = NULL;
-   match_targ = NULL;
-@@ -571,26 +555,26 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
-       void **high_water;
- 
-       /* The binary target matches anything, so don't return it when
--	 searching.  Don't match the plugin target if we have another
--	 alternative since we want to properly set the input format
--	 before allowing a plugin to claim the file.  Also, don't
--	 check the default target twice.   If LTO_SECTION_REMOVED is
--	 true, don't match the plugin target.  */
-+	 searching.  Also, don't check the current target twice when
-+	 it has failed already.
-+	 Don't match the plugin target during linking if we have 
-+	 another alternative since we want to properly set the input
-+	 format before allowing a plugin to claim the file.
-+	 Also as an optimisation don't match the plugin target when
-+	 abfd->plugin_format is set to bfd_plugin_no.  (This occurs
-+	 when LTO sections have been stripped or when we have a
-+	 recursive call here from the plugin object_p via
-+	 bfd_plugin_get_symbols_in_object_only.)  */
-       if (*target == &binary_vec
-+	  || *target == fail_targ
- #if BFD_SUPPORTS_PLUGINS
--	  || ((lto_sections_removed || match_count != 0)
-+	  || (((abfd->is_linker_input && match_count != 0)
-+	       || abfd->plugin_format == bfd_plugin_no)
- 	      && bfd_plugin_target_p (*target))
- #endif
--	  || (!abfd->target_defaulted && *target == save_targ))
-+	  )
- 	continue;
- 
--#if BFD_SUPPORTS_PLUGINS
--      /* If the plugin target is explicitly specified when a BFD file
--	 is opened, don't check it twice.  */
--      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
--	continue;
--#endif
--
-       /* If we already tried a match, the bfd is modified and may
- 	 have sections attached, which will confuse the next
- 	 _bfd_check_format call.  */
-@@ -831,32 +815,6 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
-   return false;
- }
- 
--/*
--FUNCTION
--	bfd_check_format_matches
--
--SYNOPSIS
--	bool bfd_check_format_matches
--	  (bfd *abfd, bfd_format format, char ***matching);
--
--DESCRIPTION
--	Like <<bfd_check_format>>, except when it returns FALSE with
--	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
--	case, if @var{matching} is not NULL, it will be filled in with
--	a NULL-terminated list of the names of the formats that matched,
--	allocated with <<malloc>>.
--	Then the user may choose a format and try again.
--
--	When done with the list that @var{matching} points to, the caller
--	should free it.
--*/
--
--bool
--bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
--{
--  return bfd_check_format_matches_lto (abfd, format, matching, false);
--}
--
- /*
- FUNCTION
- 	bfd_set_format
 diff --git a/bfd/plugin.c b/bfd/plugin.c
-index 1c72b748a8f..be9d1e58bf3 100644
+index ebdf2505cbc..43ca444e7a1 100644
 --- a/bfd/plugin.c
 +++ b/bfd/plugin.c
-@@ -196,13 +196,17 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
- 	     abfd->filename, bfd_errmsg (bfd_get_error ()));
- 	  return;
- 	}
--      else if (!bfd_check_format (nbfd, bfd_object))
-+      nbfd->plugin_format = bfd_plugin_no;
-+      if (!bfd_check_format (nbfd, bfd_object))
- 	{
- 	  /* There is no object only section if it isn't a bfd_object
- 	     file.  */
+@@ -206,6 +206,9 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
  	  bfd_close (nbfd);
  	  return;
  	}
@@ -432,14 +201,6 @@ index 1c72b748a8f..be9d1e58bf3 100644
      }
    else
      {
-@@ -239,6 +243,7 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
- 
-   /* Open the file containing object only section.  */
-   nbfd = bfd_openr (object_only_file, NULL);
-+  nbfd->plugin_format = bfd_plugin_no;
-   if (!bfd_check_format (nbfd, bfd_object))
-     {
-       (*_bfd_error_handler)
 diff --git a/binutils/nm.c b/binutils/nm.c
 index a5d56311dde..94333042ee2 100644
 --- a/binutils/nm.c
@@ -465,19 +226,10 @@ index a5d56311dde..94333042ee2 100644
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 5774711abe6..3404bec1d08 100644
+index 8bd523aba13..3404bec1d08 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
-@@ -170,6 +170,8 @@ static bool sections_removed;
- #if BFD_SUPPORTS_PLUGINS
- /* TRUE if all GCC LTO sections are to be removed.  */
- static bool lto_sections_removed;
-+#else
-+#define lto_sections_removed false
- #endif
- 
- /* TRUE if only some sections are to be copied.  */
-@@ -3687,6 +3689,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+@@ -3689,6 +3689,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
        bool ok_object;
        const char *element_name;
  
@@ -486,22 +238,7 @@ index 5774711abe6..3404bec1d08 100644
        element_name = bfd_get_filename (this_element);
        /* PR binutils/17533: Do not allow directory traversal
  	 outside of the current directory tree by archive members.  */
-@@ -3745,11 +3749,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
- 
- #if BFD_SUPPORTS_PLUGINS
-       /* Ignore plugin target if all LTO sections should be removed.  */
--      ok_object = bfd_check_format_lto (this_element, bfd_object,
--					lto_sections_removed);
--#else
--      ok_object = bfd_check_format (this_element, bfd_object);
-+      if (lto_sections_removed)
-+	this_element->plugin_format = bfd_plugin_no;
- #endif
-+      ok_object = bfd_check_format (this_element, bfd_object);
- 
-       /* PR binutils/3110: Cope with archives
- 	 containing multiple target types.  */
-@@ -3768,7 +3771,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+@@ -3769,7 +3771,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
  
  #if BFD_SUPPORTS_PLUGINS
        /* Copy LTO IR file as unknown object.  */
@@ -512,33 +249,7 @@ index 5774711abe6..3404bec1d08 100644
  	ok_object = false;
        else
  #endif
-@@ -3863,6 +3868,25 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
-   return ok;
- }
- 
-+static bool
-+check_format_object (bfd *ibfd, char ***obj_matching,
-+		     bool no_plugins ATTRIBUTE_UNUSED)
-+{
-+#if BFD_SUPPORTS_PLUGINS
-+  /* Ignore plugin target first if all LTO sections should be
-+     removed.  Try with plugin target next if ignoring plugin
-+     target fails to match the format.  */
-+  if (no_plugins && ibfd->plugin_format == bfd_plugin_unknown)
-+    {
-+      ibfd->plugin_format = bfd_plugin_no;
-+      if (bfd_check_format_matches (ibfd, bfd_object, obj_matching))
-+	return true;
-+      ibfd->plugin_format = bfd_plugin_unknown;
-+    }
-+#endif
-+  return bfd_check_format_matches (ibfd, bfd_object, obj_matching);
-+}
-+
- /* The top-level control.  */
- 
- static void
-@@ -3946,6 +3970,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3966,6 +3970,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
        break;
      }
  
@@ -547,30 +258,7 @@ index 5774711abe6..3404bec1d08 100644
    if (bfd_check_format (ibfd, bfd_archive))
      {
        bool force_output_target;
-@@ -3988,21 +4014,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
- 			 input_arch, target_defaulted))
- 	status = 1;
-     }
--  else if (
--#if BFD_SUPPORTS_PLUGINS
--	   /* Ignore plugin target first if all LTO sections should be
--	      removed.  Try with plugin target next if ignoring plugin
--	      target fails to match the format.  */
--	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
--					 lto_sections_removed)
--	   || (lto_sections_removed
--	       && bfd_check_format_matches_lto (ibfd, bfd_object,
--						&obj_matching, false))
--#else
--	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
--					 false)
--#endif
--	   )
-+  else if (check_format_object (ibfd, &obj_matching, lto_sections_removed))
-     {
-       bfd *obfd;
-     do_copy:
-@@ -5066,6 +5078,11 @@ strip_main (int argc, char *argv[])
+@@ -5072,6 +5078,11 @@ strip_main (int argc, char *argv[])
  					       SECTION_CONTEXT_REMOVE)
  			  || !!find_section_list (".llvm.lto", false,
  					       SECTION_CONTEXT_REMOVE));
@@ -775,5 +463,8 @@ index 00000000000..cd0130cacdf
 +foo (void)
 +{
 +}
+
+base-commit: d6e93eedfb9e75846c3083f49f9015eda1a2be33
 -- 
 2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-05 20:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-05 20:21 UTC (permalink / raw
  To: gentoo-commits

commit:     f81f9f5a26d3b0b70d5ef0fb58e00b5842b9bf68
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug  5 20:20:51 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug  5 20:20:51 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f81f9f5a

999(: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...n-t-treat-fat-IR-objects-as-plugin-object.patch | 449 +++++++++++++++------
 1 file changed, 330 insertions(+), 119 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index 9c24514..b34bbbb 100644
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c27
+https://inbox.sourceware.org/binutils/CAMe9rOprvH1SusdkbmAnE7L0Sr4kYeMZTYAQBw4t9oTySVsgjw@mail.gmail.com/
 
-From ec362769c8e381900cd432d288ca5b5641bac02b Mon Sep 17 00:00:00 2001
+From a0fafaa5186a248ac75e178d39fa257ddbce5f2d Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
 Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
@@ -18,7 +18,7 @@ since fat IR objects are recognized as plugin object and copied as unknown
 objects.  Update strip not to treat archive member nor standalone fat IR
 object as IR object so that strip can remove debug and IR sections in
 fat IR object.  For archive member, it is copied as an unknown object if
-it isn't a fat IR object or a slim IR object.
+it isn't a fat IR object nor a slim IR object.
 
 bfd/
 
@@ -28,17 +28,14 @@ bfd/
 	(_bfd_compute_and_write_armap): Don't complain plugin is needed
 	when the plugin target is in use.
 	* bfd-in2.h: Regenerated.
-	* format.c (bfd_check_format_lto): Add a bool argument to
-	indicate called from strip.
+	* format.c (bfd_check_format_lto): Removed.
 	(bfd_check_format): Updated.
-	(bfd_set_lto_type): If there is .llvm.lto section,
-	set LTO type to lto_fat_ir_object.
-	(bfd_check_format_matches_lto): Add a bool argument to indicate
-	called from strip.  When called from strip, don't treat archive
-	member nor standalone fat IR object as an IR object.  Don't set
-	LTO type when setting format.  Set LTO type if IR sections won't
-	be removed.
-	(bfd_check_format_matches): Updated.
+	(bfd_set_lto_type): If there is .llvm.lto section, set LTO type
+	to lto_fat_ir_object.
+	(bfd_check_format_matches_lto): Removed.
+	(bfd_check_format_matches): Don't set LTO type when setting
+	format.  When called from strip, don't treat archive
+	member nor standalone fat IR object as an IR object.
 	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
 	type derived from input sections.
 
@@ -64,21 +61,23 @@ ld/
 	Run binutils/33246 tests with GCC and Clang.
 	* testsuite/ld-plugin/pr33246.c: New file.
 
+Co-Authored-By: Alan Modra <amodra@gmail.com>
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
- bfd/archive.c                           |  10 +-
- bfd/bfd-in2.h                           |   5 +-
- bfd/format.c                            |  48 +++++--
- bfd/plugin.c                            |   3 +
+ bfd/archive.c                           |  12 +-
+ bfd/bfd-in2.h                           |  10 +-
+ bfd/bfd.c                               |   3 +
+ bfd/format.c                            | 140 +++++++------------
+ bfd/plugin.c                            |   7 +-
  binutils/nm.c                           |   6 +-
- binutils/objcopy.c                      |  21 ++-
+ binutils/objcopy.c                      |  57 +++++---
  ld/testsuite/ld-plugin/lto-binutils.exp | 175 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 8 files changed, 248 insertions(+), 24 deletions(-)
+ 9 files changed, 290 insertions(+), 124 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
-index c61d4b12658..c323fb4fbd3 100644
+index c61d4b12658..491c44f5191 100644
 --- a/bfd/archive.c
 +++ b/bfd/archive.c
 @@ -141,6 +141,10 @@ SUBSECTION
@@ -102,84 +101,122 @@ index c61d4b12658..c323fb4fbd3 100644
  	      && report_plugin_err)
  	    {
  	      report_plugin_err = false;
-@@ -2398,7 +2403,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
+@@ -2398,8 +2403,9 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
  			  map = new_map;
  			}
  
 -		      if (bfd_lto_slim_symbol_p (current,
+-						 syms[src_count]->name)
 +		      if (!bfd_plugin_target_p (current->xvec)
 +			  && bfd_lto_slim_symbol_p (current,
- 						 syms[src_count]->name)
++						    syms[src_count]->name)
  			  && report_plugin_err)
  			{
+ 			  report_plugin_err = false;
 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index 2ff3e930bfa..351c9a97c52 100644
+index 2ff3e930bfa..12512a3962c 100644
 --- a/bfd/bfd-in2.h
 +++ b/bfd/bfd-in2.h
-@@ -2904,13 +2904,14 @@ bool generic_core_file_matches_executable_p
+@@ -2131,6 +2131,9 @@ struct bfd
+   /* Set if this is the linker input BFD.  */
+   unsigned int is_linker_input : 1;
+ 
++  /* Set if this is the strip input BFD.  */
++  unsigned int is_strip_input : 1;
++
+   /* If this is an input for a compiler plug-in library.  */
+   ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ 
+@@ -2903,15 +2906,8 @@ bool generic_core_file_matches_executable_p
+    (bfd *core_bfd, bfd *exec_bfd);
  
  /* Extracted from format.c.  */
- bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-bool bfd_check_format_lto (bfd *abfd, bfd_format format,
 -    bool lto_sections_removed);
-+    bool lto_sections_removed,
-+    bool from_strip);
- 
+-
  bool bfd_check_format (bfd *abfd, bfd_format format);
  
- bool bfd_check_format_matches_lto
-    (bfd *abfd, bfd_format format, char ***matching,
+-bool bfd_check_format_matches_lto
+-   (bfd *abfd, bfd_format format, char ***matching,
 -    bool lto_sections_removed);
-+    bool lto_sections_removed, bool from_strip);
- 
+-
  bool bfd_check_format_matches
     (bfd *abfd, bfd_format format, char ***matching);
+ 
+diff --git a/bfd/bfd.c b/bfd/bfd.c
+index 858ab5ce017..4aded6809bb 100644
+--- a/bfd/bfd.c
++++ b/bfd/bfd.c
+@@ -296,6 +296,9 @@ CODE_FRAGMENT
+ .  {* Set if this is the linker input BFD.  *}
+ .  unsigned int is_linker_input : 1;
+ .
++.  {* Set if this is the strip input BFD.  *}
++.  unsigned int is_strip_input : 1;
++.
+ .  {* If this is an input for a compiler plug-in library.  *}
+ .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ .
 diff --git a/bfd/format.c b/bfd/format.c
-index f3a0774af08..bc7a5bc2cac 100644
+index f3a0774af08..f8e73b7eaea 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
-@@ -60,7 +60,8 @@ FUNCTION
+@@ -56,19 +56,16 @@ extern const size_t _bfd_target_vector_entries;
+ 
+ /*
+ FUNCTION
+-	bfd_check_format_lto
++	bfd_check_format
  
  SYNOPSIS
- 	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
 -				   bool lto_sections_removed);
-+				   bool lto_sections_removed,
-+				   bool from_strip);
++	bool bfd_check_format (bfd *abfd, bfd_format format);
  
  DESCRIPTION
  	Verify if the file attached to the BFD @var{abfd} is compatible
-@@ -69,6 +70,8 @@ DESCRIPTION
+ 	with the format @var{format} (i.e., one of <<bfd_object>>,
+ 	<<bfd_archive>> or <<bfd_core>>).
  
- 	If LTO_SECTION_REMOVED is true, ignore plugin target.
- 
-+	If FROM_STRIP is true, this is called from strip.
-+
+-	If LTO_SECTION_REMOVED is true, ignore plugin target.
+-
  	If the BFD has been set to a specific target before the
  	call, only the named target and format combination is
  	checked. If the target has not been set, or has been set to
-@@ -104,10 +107,11 @@ DESCRIPTION
+@@ -102,31 +99,10 @@ DESCRIPTION
+ 	itself.
+ */
  
- bool
- bfd_check_format_lto (bfd *abfd, bfd_format format,
+-bool
+-bfd_check_format_lto (bfd *abfd, bfd_format format,
 -		      bool lto_sections_removed)
-+		      bool lto_sections_removed, bool from_strip)
- {
-   return bfd_check_format_matches_lto (abfd, format, NULL,
+-{
+-  return bfd_check_format_matches_lto (abfd, format, NULL,
 -				       lto_sections_removed);
-+				       lto_sections_removed,
-+				       from_strip);
- }
- 
- 
-@@ -126,7 +130,7 @@ DESCRIPTION
+-}
+-
+-
+-/*
+-FUNCTION
+-	bfd_check_format
+-
+-SYNOPSIS
+-	bool bfd_check_format (bfd *abfd, bfd_format format);
+-
+-DESCRIPTION
+-	Similar to bfd_check_format_plugin, except plugin target isn't
+-	ignored.
+-*/
+-
  bool
  bfd_check_format (bfd *abfd, bfd_format format)
  {
 -  return bfd_check_format_matches_lto (abfd, format, NULL, false);
-+  return bfd_check_format_matches_lto (abfd, format, NULL, false, false);
++  return bfd_check_format_matches (abfd, format, NULL);
  }
  
  struct bfd_preserve
-@@ -413,6 +417,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+@@ -413,6 +389,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
  	    abfd->object_only_section = sec;
  	    break;
  	  }
@@ -191,33 +228,53 @@ index f3a0774af08..bc7a5bc2cac 100644
  	else if (lsection.major_version == 0
  		 && startswith (sec->name, ".gnu.lto_.lto.")
  		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-@@ -436,7 +445,7 @@ FUNCTION
+@@ -431,36 +412,32 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+ 
+ /*
+ FUNCTION
+-	bfd_check_format_matches_lto
++	bfd_check_format_matches
+ 
  SYNOPSIS
- 	bool bfd_check_format_matches_lto
- 	  (bfd *abfd, bfd_format format, char ***matching,
+-	bool bfd_check_format_matches_lto
+-	  (bfd *abfd, bfd_format format, char ***matching,
 -	   bool lto_sections_removed);
-+	   bool lto_sections_removed, bool from_strip);
++	bool bfd_check_format_matches
++	  (bfd *abfd, bfd_format format, char ***matching);
  
  DESCRIPTION
  	Like <<bfd_check_format>>, except when it returns FALSE with
-@@ -450,12 +459,15 @@ DESCRIPTION
- 	should free it.
+-	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
+-	case, if @var{matching} is not NULL, it will be filled in with
+-	a NULL-terminated list of the names of the formats that matched,
+-	allocated with <<malloc>>.
++	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.
++	In that case, if @var{matching} is not NULL, it will be filled
++	in with a NULL-terminated list of the names of the formats
++	that matched, allocated with <<malloc>>.
+ 	Then the user may choose a format and try again.
  
- 	If LTO_SECTION_REMOVED is true, ignore plugin target.
-+
-+	If FROM_STRIP is true, this is called from strip.
+ 	When done with the list that @var{matching} points to, the caller
+ 	should free it.
+-
+-	If LTO_SECTION_REMOVED is true, ignore plugin target.
  */
  
  bool
- bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
- 			      char ***matching,
+-bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+-			      char ***matching,
 -			      bool lto_sections_removed ATTRIBUTE_UNUSED)
-+			      bool lto_sections_removed ATTRIBUTE_UNUSED,
-+			      bool from_strip ATTRIBUTE_UNUSED)
++bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
  {
    extern const bfd_target binary_vec;
    const bfd_target * const *target;
-@@ -481,10 +493,7 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+   const bfd_target **matching_vector = NULL;
+   const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
++  const bfd_target *fail_targ;
+   int match_count, best_count, best_match;
+   int ar_match_index;
+   unsigned int initial_section_id = _bfd_section_id;
+@@ -481,10 +458,7 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
      }
  
    if (abfd->format != bfd_unknown)
@@ -229,7 +286,25 @@ index f3a0774af08..bc7a5bc2cac 100644
  
    if (matching != NULL || *bfd_associated_vector != NULL)
      {
-@@ -537,7 +546,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -524,20 +498,30 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+   if (!bfd_preserve_save (abfd, &preserve, NULL))
+     goto err_ret;
+ 
+-  /* If the target type was explicitly specified, just check that target.
+-     If LTO_SECTION_REMOVED is true, don't match the plugin target.  */
++  /* If the target type was explicitly specified, just check that target.  */
++  fail_targ = NULL;
+   if (!abfd->target_defaulted
+ #if BFD_SUPPORTS_PLUGINS
+-      && (!lto_sections_removed || !bfd_plugin_target_p (abfd->xvec))
++      && !(abfd->plugin_format == bfd_plugin_no
++	   && bfd_plugin_target_p (save_targ))
+ #endif
+-     )
++      )
+     {
+       if (bfd_seek (abfd, 0, SEEK_SET) != 0)	/* rewind! */
+ 	goto err_ret;
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
@@ -240,40 +315,114 @@ index f3a0774af08..bc7a5bc2cac 100644
 +	 isn't a fat IR object.  For standalone fat IR object,
 +	 it will be copied as non-IR object.  */
 +      if (cleanup
-+	  && (!from_strip
++	  && (!abfd->is_strip_input
 +	      || !bfd_plugin_target_p (abfd->xvec)
 +	      || (abfd->lto_type != lto_fat_ir_object
 +		  && abfd->my_archive == NULL)))
  	goto ok_ret;
  
        /* For a long time the code has dropped through to check all
-@@ -621,6 +639,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
- 	{
- 	  int match_priority = abfd->xvec->match_priority;
+@@ -554,10 +538,10 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+ 	 target.  */
+       if (format == bfd_archive && save_targ == &binary_vec)
+ 	goto err_unrecog;
++      fail_targ = save_targ;
+     }
  
-+	  /* Set LTO type if IR sections won't be removed so that it
-+	     can be checked for fat and slim IR objects.  */
-+	  if (!lto_sections_removed)
-+	    bfd_set_lto_type (abfd);
-+
- 	  if (abfd->format != bfd_archive
- 	      || (bfd_has_map (abfd)
- 		  && bfd_get_error () != bfd_error_wrong_object_format))
-@@ -854,7 +877,8 @@ DESCRIPTION
- bool
- bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- {
--  return bfd_check_format_matches_lto (abfd, format, matching, false);
-+  return bfd_check_format_matches_lto (abfd, format, matching, false,
-+				       false);
+-  /* Since the target type was defaulted, check them all in the hope
+-     that one will be uniquely recognized.  */
++  /* Check all targets in the hope that one will be recognized.  */
+   right_targ = NULL;
+   ar_right_targ = NULL;
+   match_targ = NULL;
+@@ -571,26 +555,26 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+       void **high_water;
+ 
+       /* The binary target matches anything, so don't return it when
+-	 searching.  Don't match the plugin target if we have another
+-	 alternative since we want to properly set the input format
+-	 before allowing a plugin to claim the file.  Also, don't
+-	 check the default target twice.   If LTO_SECTION_REMOVED is
+-	 true, don't match the plugin target.  */
++	 searching.  Also, don't check the current target twice when
++	 it has failed already.
++	 Don't match the plugin target during linking if we have 
++	 another alternative since we want to properly set the input
++	 format before allowing a plugin to claim the file.
++	 Also as an optimisation don't match the plugin target when
++	 abfd->plugin_format is set to bfd_plugin_no.  (This occurs
++	 when LTO sections have been stripped or when we have a
++	 recursive call here from the plugin object_p via
++	 bfd_plugin_get_symbols_in_object_only.)  */
+       if (*target == &binary_vec
++	  || *target == fail_targ
+ #if BFD_SUPPORTS_PLUGINS
+-	  || ((lto_sections_removed || match_count != 0)
++	  || (((abfd->is_linker_input && match_count != 0)
++	       || abfd->plugin_format == bfd_plugin_no)
+ 	      && bfd_plugin_target_p (*target))
+ #endif
+-	  || (!abfd->target_defaulted && *target == save_targ))
++	  )
+ 	continue;
+ 
+-#if BFD_SUPPORTS_PLUGINS
+-      /* If the plugin target is explicitly specified when a BFD file
+-	 is opened, don't check it twice.  */
+-      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
+-	continue;
+-#endif
+-
+       /* If we already tried a match, the bfd is modified and may
+ 	 have sections attached, which will confuse the next
+ 	 _bfd_check_format call.  */
+@@ -831,32 +815,6 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+   return false;
  }
  
+-/*
+-FUNCTION
+-	bfd_check_format_matches
+-
+-SYNOPSIS
+-	bool bfd_check_format_matches
+-	  (bfd *abfd, bfd_format format, char ***matching);
+-
+-DESCRIPTION
+-	Like <<bfd_check_format>>, except when it returns FALSE with
+-	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
+-	case, if @var{matching} is not NULL, it will be filled in with
+-	a NULL-terminated list of the names of the formats that matched,
+-	allocated with <<malloc>>.
+-	Then the user may choose a format and try again.
+-
+-	When done with the list that @var{matching} points to, the caller
+-	should free it.
+-*/
+-
+-bool
+-bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+-{
+-  return bfd_check_format_matches_lto (abfd, format, matching, false);
+-}
+-
  /*
+ FUNCTION
+ 	bfd_set_format
 diff --git a/bfd/plugin.c b/bfd/plugin.c
-index 1c72b748a8f..6dd22d75137 100644
+index 1c72b748a8f..be9d1e58bf3 100644
 --- a/bfd/plugin.c
 +++ b/bfd/plugin.c
-@@ -203,6 +203,9 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
+@@ -196,13 +196,17 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
+ 	     abfd->filename, bfd_errmsg (bfd_get_error ()));
+ 	  return;
+ 	}
+-      else if (!bfd_check_format (nbfd, bfd_object))
++      nbfd->plugin_format = bfd_plugin_no;
++      if (!bfd_check_format (nbfd, bfd_object))
+ 	{
+ 	  /* There is no object only section if it isn't a bfd_object
+ 	     file.  */
  	  bfd_close (nbfd);
  	  return;
  	}
@@ -283,6 +432,14 @@ index 1c72b748a8f..6dd22d75137 100644
      }
    else
      {
+@@ -239,6 +243,7 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
+ 
+   /* Open the file containing object only section.  */
+   nbfd = bfd_openr (object_only_file, NULL);
++  nbfd->plugin_format = bfd_plugin_no;
+   if (!bfd_check_format (nbfd, bfd_object))
+     {
+       (*_bfd_error_handler)
 diff --git a/binutils/nm.c b/binutils/nm.c
 index a5d56311dde..94333042ee2 100644
 --- a/binutils/nm.c
@@ -308,19 +465,43 @@ index a5d56311dde..94333042ee2 100644
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 5774711abe6..496f0a13daa 100644
+index 5774711abe6..3404bec1d08 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
-@@ -3746,7 +3746,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+@@ -170,6 +170,8 @@ static bool sections_removed;
+ #if BFD_SUPPORTS_PLUGINS
+ /* TRUE if all GCC LTO sections are to be removed.  */
+ static bool lto_sections_removed;
++#else
++#define lto_sections_removed false
+ #endif
+ 
+ /* TRUE if only some sections are to be copied.  */
+@@ -3687,6 +3689,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+       bool ok_object;
+       const char *element_name;
+ 
++      this_element->is_strip_input = 1;
++
+       element_name = bfd_get_filename (this_element);
+       /* PR binutils/17533: Do not allow directory traversal
+ 	 outside of the current directory tree by archive members.  */
+@@ -3745,11 +3749,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+ 
  #if BFD_SUPPORTS_PLUGINS
        /* Ignore plugin target if all LTO sections should be removed.  */
-       ok_object = bfd_check_format_lto (this_element, bfd_object,
+-      ok_object = bfd_check_format_lto (this_element, bfd_object,
 -					lto_sections_removed);
-+					lto_sections_removed, true);
- #else
-       ok_object = bfd_check_format (this_element, bfd_object);
+-#else
+-      ok_object = bfd_check_format (this_element, bfd_object);
++      if (lto_sections_removed)
++	this_element->plugin_format = bfd_plugin_no;
  #endif
-@@ -3768,7 +3768,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
++      ok_object = bfd_check_format (this_element, bfd_object);
+ 
+       /* PR binutils/3110: Cope with archives
+ 	 containing multiple target types.  */
+@@ -3768,7 +3771,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
  
  #if BFD_SUPPORTS_PLUGINS
        /* Copy LTO IR file as unknown object.  */
@@ -331,35 +512,65 @@ index 5774711abe6..496f0a13daa 100644
  	ok_object = false;
        else
  #endif
-@@ -3946,7 +3948,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3863,6 +3868,25 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+   return ok;
+ }
+ 
++static bool
++check_format_object (bfd *ibfd, char ***obj_matching,
++		     bool no_plugins ATTRIBUTE_UNUSED)
++{
++#if BFD_SUPPORTS_PLUGINS
++  /* Ignore plugin target first if all LTO sections should be
++     removed.  Try with plugin target next if ignoring plugin
++     target fails to match the format.  */
++  if (no_plugins && ibfd->plugin_format == bfd_plugin_unknown)
++    {
++      ibfd->plugin_format = bfd_plugin_no;
++      if (bfd_check_format_matches (ibfd, bfd_object, obj_matching))
++	return true;
++      ibfd->plugin_format = bfd_plugin_unknown;
++    }
++#endif
++  return bfd_check_format_matches (ibfd, bfd_object, obj_matching);
++}
++
+ /* The top-level control.  */
+ 
+ static void
+@@ -3946,6 +3970,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
        break;
      }
  
--  if (bfd_check_format (ibfd, bfd_archive))
-+  if (bfd_check_format_lto (ibfd, bfd_archive, lto_sections_removed,
-+			    true))
++  ibfd->is_strip_input = 1;
++
+   if (bfd_check_format (ibfd, bfd_archive))
      {
        bool force_output_target;
-       bfd *obfd;
-@@ -3994,13 +3997,14 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
- 	      removed.  Try with plugin target next if ignoring plugin
- 	      target fails to match the format.  */
- 	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+@@ -3988,21 +4014,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+ 			 input_arch, target_defaulted))
+ 	status = 1;
+     }
+-  else if (
+-#if BFD_SUPPORTS_PLUGINS
+-	   /* Ignore plugin target first if all LTO sections should be
+-	      removed.  Try with plugin target next if ignoring plugin
+-	      target fails to match the format.  */
+-	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
 -					 lto_sections_removed)
-+					 lto_sections_removed, true)
- 	   || (lto_sections_removed
- 	       && bfd_check_format_matches_lto (ibfd, bfd_object,
+-	   || (lto_sections_removed
+-	       && bfd_check_format_matches_lto (ibfd, bfd_object,
 -						&obj_matching, false))
-+						&obj_matching, false,
-+						true))
- #else
- 	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+-#else
+-	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
 -					 false)
-+					 false, true)
- #endif
- 	   )
+-#endif
+-	   )
++  else if (check_format_object (ibfd, &obj_matching, lto_sections_removed))
      {
-@@ -5066,6 +5070,11 @@ strip_main (int argc, char *argv[])
+       bfd *obfd;
+     do_copy:
+@@ -5066,6 +5078,11 @@ strip_main (int argc, char *argv[])
  					       SECTION_CONTEXT_REMOVE)
  			  || !!find_section_list (".llvm.lto", false,
  					       SECTION_CONTEXT_REMOVE));


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-04 21:43 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-04 21:43 UTC (permalink / raw
  To: gentoo-commits

commit:     ec22d23e98d0a6f9d7eb532c60369496e65a7238
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  4 21:43:26 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  4 21:43:26 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=ec22d23e

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index e8f6b00..9c24514 100644
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c24
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c27
 
-From 3f4cd3fcdc566dce8ef7d978d328817428acbe63 Mon Sep 17 00:00:00 2001
+From ec362769c8e381900cd432d288ca5b5641bac02b Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
 Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
@@ -372,7 +372,7 @@ index 5774711abe6..496f0a13daa 100644
  
    i = optind;
 diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
-index 88d35171045..145eb410588 100644
+index 88d35171045..de017f0b946 100644
 --- a/ld/testsuite/ld-plugin/lto-binutils.exp
 +++ b/ld/testsuite/ld-plugin/lto-binutils.exp
 @@ -355,3 +355,178 @@ run_cc_link_tests [list \
@@ -392,7 +392,7 @@ index 88d35171045..145eb410588 100644
 +    global READELF
 +    global strip
 +
-+    set strip_flags "--strip-debug --disable-deterministic-archives"
++    set strip_flags "--strip-debug --enable-deterministic-archives"
 +
 +    set test pr33246
 +    set testname "${test}${llvm}${fat} with $strip_flags"
@@ -490,7 +490,7 @@ index 88d35171045..145eb410588 100644
 +
 +    pass "$testname (strip $obj)"
 +
-+    set cmd "$ar $binutils_plug_opt -s -r -c $archive $obj"
++    set cmd "$ar $binutils_plug_opt -D -s -r -c $archive $obj"
 +    send_log "$cmd\n"
 +    verbose "$cmd" 1
 +    catch "exec $cmd" got


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-04 21:05 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-04 21:05 UTC (permalink / raw
  To: gentoo-commits

commit:     3fb476e361a1202a6c899859f397d2b913a14f43
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  4 21:05:19 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  4 21:05:19 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=3fb476e3

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index 3b2fb26..e8f6b00 100644
--- a/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c14
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c24
 
-From a3f9e4f1e527f3908aeb2f41d85be8e17dbe9eb8 Mon Sep 17 00:00:00 2001
+From 3f4cd3fcdc566dce8ef7d978d328817428acbe63 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
 Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
@@ -372,7 +372,7 @@ index 5774711abe6..496f0a13daa 100644
  
    i = optind;
 diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
-index 88d35171045..0609dc608c1 100644
+index 88d35171045..145eb410588 100644
 --- a/ld/testsuite/ld-plugin/lto-binutils.exp
 +++ b/ld/testsuite/ld-plugin/lto-binutils.exp
 @@ -355,3 +355,178 @@ run_cc_link_tests [list \
@@ -392,7 +392,7 @@ index 88d35171045..0609dc608c1 100644
 +    global READELF
 +    global strip
 +
-+    set strip_flags "--strip-debug"
++    set strip_flags "--strip-debug --disable-deterministic-archives"
 +
 +    set test pr33246
 +    set testname "${test}${llvm}${fat} with $strip_flags"


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-04 15:32 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-04 15:32 UTC (permalink / raw
  To: gentoo-commits

commit:     d2bf436381911edf1f31d5910a6b26a1504c954e
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  4 15:32:31 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  4 15:32:31 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d2bf4363

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-t-treat-fat-IR-objects-as-plugin-object.patch} | 101 +++++++++++++++------
 1 file changed, 73 insertions(+), 28 deletions(-)

diff --git a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
similarity index 84%
rename from 9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
rename to 9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
index c6d732b..3b2fb26 100644
--- a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
+++ b/9999/0006-strip-Don-t-treat-fat-IR-objects-as-plugin-object.patch
@@ -1,26 +1,24 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c12
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c14
 
-From 4ef8b87fc5466a0b3cb162dfacfc0ffefd90670c Mon Sep 17 00:00:00 2001
+From a3f9e4f1e527f3908aeb2f41d85be8e17dbe9eb8 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
-Subject: [PATCH] strip: Don't use plugin on fat IR objects
+Subject: [PATCH] strip: Don't treat fat IR objects as plugin object
 
 Fat IR objects contains both regular sections and IR sections.  After
 
-717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d is the first bad commit
-commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d (HEAD)
+commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
 Author: H.J. Lu <hjl.tools@gmail.com>
 Date:   Sun May 4 05:12:46 2025 +0800
 
     strip: Add GCC LTO IR support
 
 "strip --strip-debug" no longer strips debug sections in fat IR objects
-since fat IR objects are copied as unknown objects.  When called from
-strip, don't treat archive member nor standalone fat IR object as an IR
-object.  For archive member, it will be copied as an unknown object if
-it isn't a fat IR object.  For standalone fat IR object, it will be
-copied as non-IR object.  Debug sections and IR sections can be removed
-by strip as usual.
+since fat IR objects are recognized as plugin object and copied as unknown
+objects.  Update strip not to treat archive member nor standalone fat IR
+object as IR object so that strip can remove debug and IR sections in
+fat IR object.  For archive member, it is copied as an unknown object if
+it isn't a fat IR object or a slim IR object.
 
 bfd/
 
@@ -37,8 +35,9 @@ bfd/
 	set LTO type to lto_fat_ir_object.
 	(bfd_check_format_matches_lto): Add a bool argument to indicate
 	called from strip.  When called from strip, don't treat archive
-	member nor standalone fat IR object as an IR object.  Set LTO
-	type if IR sections won't be removed.
+	member nor standalone fat IR object as an IR object.  Don't set
+	LTO type when setting format.  Set LTO type if IR sections won't
+	be removed.
 	(bfd_check_format_matches): Updated.
 	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
 	type derived from input sections.
@@ -50,7 +49,8 @@ nm/
 	the plugin target is in use.
 	(display_rel_file): Likewise.
 	* objcopy.c (copy_archive): Pass true to bfd_check_format_lto
-	to indicat called from strip.
+	to indicat called from strip.  Also copy slim IR archive member
+	as unknown object.
 	(copy_file): Call bfd_check_format_lto, instead of
 	bfd_check_format.  Pass true to bfd_check_format_lto and
 	bfd_check_format_matches_lto.
@@ -68,13 +68,13 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  bfd/archive.c                           |  10 +-
  bfd/bfd-in2.h                           |   5 +-
- bfd/format.c                            |  43 +++++--
+ bfd/format.c                            |  48 +++++--
  bfd/plugin.c                            |   3 +
  binutils/nm.c                           |   6 +-
- binutils/objcopy.c                      |  17 ++-
- ld/testsuite/ld-plugin/lto-binutils.exp | 153 ++++++++++++++++++++++++
+ binutils/objcopy.c                      |  21 ++-
+ ld/testsuite/ld-plugin/lto-binutils.exp | 175 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 8 files changed, 222 insertions(+), 19 deletions(-)
+ 8 files changed, 248 insertions(+), 24 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
@@ -134,7 +134,7 @@ index 2ff3e930bfa..351c9a97c52 100644
  bool bfd_check_format_matches
     (bfd *abfd, bfd_format format, char ***matching);
 diff --git a/bfd/format.c b/bfd/format.c
-index f3a0774af08..ea827bf3001 100644
+index f3a0774af08..bc7a5bc2cac 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
 @@ -60,7 +60,8 @@ FUNCTION
@@ -217,7 +217,19 @@ index f3a0774af08..ea827bf3001 100644
  {
    extern const bfd_target binary_vec;
    const bfd_target * const *target;
-@@ -537,7 +549,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -481,10 +493,7 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+     }
+ 
+   if (abfd->format != bfd_unknown)
+-    {
+-      bfd_set_lto_type (abfd);
+-      return abfd->format == format;
+-    }
++    return abfd->format == format;
+ 
+   if (matching != NULL || *bfd_associated_vector != NULL)
+     {
+@@ -537,7 +546,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
@@ -235,7 +247,7 @@ index f3a0774af08..ea827bf3001 100644
  	goto ok_ret;
  
        /* For a long time the code has dropped through to check all
-@@ -621,6 +642,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -621,6 +639,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
  	{
  	  int match_priority = abfd->xvec->match_priority;
  
@@ -247,7 +259,7 @@ index f3a0774af08..ea827bf3001 100644
  	  if (abfd->format != bfd_archive
  	      || (bfd_has_map (abfd)
  		  && bfd_get_error () != bfd_error_wrong_object_format))
-@@ -854,7 +880,8 @@ DESCRIPTION
+@@ -854,7 +877,8 @@ DESCRIPTION
  bool
  bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
  {
@@ -296,7 +308,7 @@ index a5d56311dde..94333042ee2 100644
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 5774711abe6..72ecf2cb2b1 100644
+index 5774711abe6..496f0a13daa 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
 @@ -3746,7 +3746,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
@@ -308,7 +320,18 @@ index 5774711abe6..72ecf2cb2b1 100644
  #else
        ok_object = bfd_check_format (this_element, bfd_object);
  #endif
-@@ -3946,7 +3946,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3768,7 +3768,9 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+ 
+ #if BFD_SUPPORTS_PLUGINS
+       /* Copy LTO IR file as unknown object.  */
+-      if (bfd_plugin_target_p (this_element->xvec))
++      if ((!lto_sections_removed
++	   && this_element->lto_type == lto_slim_ir_object)
++	  || bfd_plugin_target_p (this_element->xvec))
+ 	ok_object = false;
+       else
+ #endif
+@@ -3946,7 +3948,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
        break;
      }
  
@@ -318,7 +341,7 @@ index 5774711abe6..72ecf2cb2b1 100644
      {
        bool force_output_target;
        bfd *obfd;
-@@ -3994,13 +3995,14 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3994,13 +3997,14 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
  	      removed.  Try with plugin target next if ignoring plugin
  	      target fails to match the format.  */
  	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
@@ -336,7 +359,7 @@ index 5774711abe6..72ecf2cb2b1 100644
  #endif
  	   )
      {
-@@ -5066,6 +5068,11 @@ strip_main (int argc, char *argv[])
+@@ -5066,6 +5070,11 @@ strip_main (int argc, char *argv[])
  					       SECTION_CONTEXT_REMOVE)
  			  || !!find_section_list (".llvm.lto", false,
  					       SECTION_CONTEXT_REMOVE));
@@ -349,10 +372,10 @@ index 5774711abe6..72ecf2cb2b1 100644
  
    i = optind;
 diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
-index 88d35171045..9d19aa0c57e 100644
+index 88d35171045..0609dc608c1 100644
 --- a/ld/testsuite/ld-plugin/lto-binutils.exp
 +++ b/ld/testsuite/ld-plugin/lto-binutils.exp
-@@ -355,3 +355,156 @@ run_cc_link_tests [list \
+@@ -355,3 +355,178 @@ run_cc_link_tests [list \
  	"tmpdir/libstrip-1b-fat-s.a" \
      ] \
  ]
@@ -452,6 +475,17 @@ index 88d35171045..9d19aa0c57e 100644
 +	    fail "$testname (strip $obj)"
 +	    return
 +	}
++    } else {
++	set cmd "cmp $obj ${obj}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if ![string match "" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $obj)"
++	    return
++	}
 +    }
 +
 +    pass "$testname (strip $obj)"
@@ -500,6 +534,17 @@ index 88d35171045..9d19aa0c57e 100644
 +	    fail "$testname (strip $archive)"
 +	    return
 +	}
++    } else {
++	set cmd "cmp $archive ${archive}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if ![string match "" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $archive)"
++	    return
++	}
 +    }
 +
 +    pass "$testname (strip $archive)"


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-04 11:06 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-04 11:06 UTC (permalink / raw
  To: gentoo-commits

commit:     afaa35ce4365c9038d49086d0b1068d61d86ead3
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  4 11:06:06 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  4 11:06:06 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=afaa35ce

9999: refresh strip LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-strip-Don-t-use-plugin-on-fat-IR-objects.patch | 224 +++++++++++++++------
 1 file changed, 160 insertions(+), 64 deletions(-)

diff --git a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
index 5347343..c6d732b 100644
--- a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
+++ b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c10
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c12
 
-From d499c2eea8d7f74f89f55a5a740f0d43e0c46c9b Mon Sep 17 00:00:00 2001
+From 4ef8b87fc5466a0b3cb162dfacfc0ffefd90670c Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 3 Aug 2025 10:28:40 -0700
 Subject: [PATCH] strip: Don't use plugin on fat IR objects
@@ -14,12 +14,13 @@ Date:   Sun May 4 05:12:46 2025 +0800
 
     strip: Add GCC LTO IR support
 
-"strip --strip-debug" no longer strips debug sections in fat IR objects.
-When called from strip, don't treat archive member nor standalone fat
-IR object as an IR object.  For archive member, it will be copied as
-an unknown object if it isn't a fat IR object.  For standalone fat IR
-object, it will be copied as non-IR object.  Debug sections and IR
-sections can be removed by strip as usual.
+"strip --strip-debug" no longer strips debug sections in fat IR objects
+since fat IR objects are copied as unknown objects.  When called from
+strip, don't treat archive member nor standalone fat IR object as an IR
+object.  For archive member, it will be copied as an unknown object if
+it isn't a fat IR object.  For standalone fat IR object, it will be
+copied as non-IR object.  Debug sections and IR sections can be removed
+by strip as usual.
 
 bfd/
 
@@ -29,12 +30,16 @@ bfd/
 	(_bfd_compute_and_write_armap): Don't complain plugin is needed
 	when the plugin target is in use.
 	* bfd-in2.h: Regenerated.
-	* bfd.c (bfd): Add is_strip_input.
-	* format.c (bfd_set_lto_type): If there is .llvm.lto section,
+	* format.c (bfd_check_format_lto): Add a bool argument to
+	indicate called from strip.
+	(bfd_check_format): Updated.
+	(bfd_set_lto_type): If there is .llvm.lto section,
 	set LTO type to lto_fat_ir_object.
-	(bfd_check_format_matches_lto): When called from strip, don't
-	treat archive member nor standalone fat IR object as an IR
-	object.  Set LTO type if IR sections won't be removed.
+	(bfd_check_format_matches_lto): Add a bool argument to indicate
+	called from strip.  When called from strip, don't treat archive
+	member nor standalone fat IR object as an IR object.  Set LTO
+	type if IR sections won't be removed.
+	(bfd_check_format_matches): Updated.
 	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
 	type derived from input sections.
 
@@ -44,9 +49,11 @@ nm/
 	* nm.c (filter_symbols): Don't complain plugin is needed when
 	the plugin target is in use.
 	(display_rel_file): Likewise.
-	* objcopy.c (copy_archive): Set the is_strip_input field to 1
-	on input archive member.
-	(copy_file): Set the is_strip_input field to 1 on input object.
+	* objcopy.c (copy_archive): Pass true to bfd_check_format_lto
+	to indicat called from strip.
+	(copy_file): Call bfd_check_format_lto, instead of
+	bfd_check_format.  Pass true to bfd_check_format_lto and
+	bfd_check_format_matches_lto.
 	(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
 	sections will be removed.
 
@@ -60,15 +67,14 @@ ld/
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  bfd/archive.c                           |  10 +-
- bfd/bfd-in2.h                           |   3 +
- bfd/bfd.c                               |   3 +
- bfd/format.c                            |  21 +++-
+ bfd/bfd-in2.h                           |   5 +-
+ bfd/format.c                            |  43 +++++--
  bfd/plugin.c                            |   3 +
  binutils/nm.c                           |   6 +-
- binutils/objcopy.c                      |   9 ++
+ binutils/objcopy.c                      |  17 ++-
  ld/testsuite/ld-plugin/lto-binutils.exp | 153 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/pr33246.c        |   4 +
- 9 files changed, 207 insertions(+), 5 deletions(-)
+ 8 files changed, 222 insertions(+), 19 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/pr33246.c
 
 diff --git a/bfd/archive.c b/bfd/archive.c
@@ -107,38 +113,73 @@ index c61d4b12658..c323fb4fbd3 100644
  			  && report_plugin_err)
  			{
 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index 2ff3e930bfa..bcff44a0f44 100644
+index 2ff3e930bfa..351c9a97c52 100644
 --- a/bfd/bfd-in2.h
 +++ b/bfd/bfd-in2.h
-@@ -2131,6 +2131,9 @@ struct bfd
-   /* Set if this is the linker input BFD.  */
-   unsigned int is_linker_input : 1;
+@@ -2904,13 +2904,14 @@ bool generic_core_file_matches_executable_p
  
-+  /* Set if this is the strip input BFD.  */
-+  unsigned int is_strip_input : 1;
-+
-   /* If this is an input for a compiler plug-in library.  */
-   ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ /* Extracted from format.c.  */
+ bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-    bool lto_sections_removed);
++    bool lto_sections_removed,
++    bool from_strip);
+ 
+ bool bfd_check_format (bfd *abfd, bfd_format format);
+ 
+ bool bfd_check_format_matches_lto
+    (bfd *abfd, bfd_format format, char ***matching,
+-    bool lto_sections_removed);
++    bool lto_sections_removed, bool from_strip);
  
-diff --git a/bfd/bfd.c b/bfd/bfd.c
-index 858ab5ce017..4aded6809bb 100644
---- a/bfd/bfd.c
-+++ b/bfd/bfd.c
-@@ -296,6 +296,9 @@ CODE_FRAGMENT
- .  {* Set if this is the linker input BFD.  *}
- .  unsigned int is_linker_input : 1;
- .
-+.  {* Set if this is the strip input BFD.  *}
-+.  unsigned int is_strip_input : 1;
-+.
- .  {* If this is an input for a compiler plug-in library.  *}
- .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
- .
+ bool bfd_check_format_matches
+    (bfd *abfd, bfd_format format, char ***matching);
 diff --git a/bfd/format.c b/bfd/format.c
-index f3a0774af08..f88b9be1adc 100644
+index f3a0774af08..ea827bf3001 100644
 --- a/bfd/format.c
 +++ b/bfd/format.c
-@@ -413,6 +413,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+@@ -60,7 +60,8 @@ FUNCTION
+ 
+ SYNOPSIS
+ 	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
+-				   bool lto_sections_removed);
++				   bool lto_sections_removed,
++				   bool from_strip);
+ 
+ DESCRIPTION
+ 	Verify if the file attached to the BFD @var{abfd} is compatible
+@@ -69,6 +70,8 @@ DESCRIPTION
+ 
+ 	If LTO_SECTION_REMOVED is true, ignore plugin target.
+ 
++	If FROM_STRIP is true, this is called from strip.
++
+ 	If the BFD has been set to a specific target before the
+ 	call, only the named target and format combination is
+ 	checked. If the target has not been set, or has been set to
+@@ -104,10 +107,11 @@ DESCRIPTION
+ 
+ bool
+ bfd_check_format_lto (bfd *abfd, bfd_format format,
+-		      bool lto_sections_removed)
++		      bool lto_sections_removed, bool from_strip)
+ {
+   return bfd_check_format_matches_lto (abfd, format, NULL,
+-				       lto_sections_removed);
++				       lto_sections_removed,
++				       from_strip);
+ }
+ 
+ 
+@@ -126,7 +130,7 @@ DESCRIPTION
+ bool
+ bfd_check_format (bfd *abfd, bfd_format format)
+ {
+-  return bfd_check_format_matches_lto (abfd, format, NULL, false);
++  return bfd_check_format_matches_lto (abfd, format, NULL, false, false);
+ }
+ 
+ struct bfd_preserve
+@@ -413,6 +417,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
  	    abfd->object_only_section = sec;
  	    break;
  	  }
@@ -150,7 +191,33 @@ index f3a0774af08..f88b9be1adc 100644
  	else if (lsection.major_version == 0
  		 && startswith (sec->name, ".gnu.lto_.lto.")
  		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-@@ -537,7 +542,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -436,7 +445,7 @@ FUNCTION
+ SYNOPSIS
+ 	bool bfd_check_format_matches_lto
+ 	  (bfd *abfd, bfd_format format, char ***matching,
+-	   bool lto_sections_removed);
++	   bool lto_sections_removed, bool from_strip);
+ 
+ DESCRIPTION
+ 	Like <<bfd_check_format>>, except when it returns FALSE with
+@@ -450,12 +459,15 @@ DESCRIPTION
+ 	should free it.
+ 
+ 	If LTO_SECTION_REMOVED is true, ignore plugin target.
++
++	If FROM_STRIP is true, this is called from strip.
+ */
+ 
+ bool
+ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+ 			      char ***matching,
+-			      bool lto_sections_removed ATTRIBUTE_UNUSED)
++			      bool lto_sections_removed ATTRIBUTE_UNUSED,
++			      bool from_strip ATTRIBUTE_UNUSED)
+ {
+   extern const bfd_target binary_vec;
+   const bfd_target * const *target;
+@@ -537,7 +549,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
  
        cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
  
@@ -161,14 +228,14 @@ index f3a0774af08..f88b9be1adc 100644
 +	 isn't a fat IR object.  For standalone fat IR object,
 +	 it will be copied as non-IR object.  */
 +      if (cleanup
-+	  && (!abfd->is_strip_input
++	  && (!from_strip
 +	      || !bfd_plugin_target_p (abfd->xvec)
 +	      || (abfd->lto_type != lto_fat_ir_object
 +		  && abfd->my_archive == NULL)))
  	goto ok_ret;
  
        /* For a long time the code has dropped through to check all
-@@ -621,6 +635,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+@@ -621,6 +642,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
  	{
  	  int match_priority = abfd->xvec->match_priority;
  
@@ -180,6 +247,16 @@ index f3a0774af08..f88b9be1adc 100644
  	  if (abfd->format != bfd_archive
  	      || (bfd_has_map (abfd)
  		  && bfd_get_error () != bfd_error_wrong_object_format))
+@@ -854,7 +880,8 @@ DESCRIPTION
+ bool
+ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+ {
+-  return bfd_check_format_matches_lto (abfd, format, matching, false);
++  return bfd_check_format_matches_lto (abfd, format, matching, false,
++				       false);
+ }
+ 
+ /*
 diff --git a/bfd/plugin.c b/bfd/plugin.c
 index 1c72b748a8f..6dd22d75137 100644
 --- a/bfd/plugin.c
@@ -219,28 +296,47 @@ index a5d56311dde..94333042ee2 100644
        report_plugin_err = false;
        non_fatal (_("%s: plugin needed to handle lto object"),
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 5774711abe6..1f3b288be00 100644
+index 5774711abe6..72ecf2cb2b1 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
-@@ -3687,6 +3687,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
-       bool ok_object;
-       const char *element_name;
- 
-+      this_element->is_strip_input = 1;
-+
-       element_name = bfd_get_filename (this_element);
-       /* PR binutils/17533: Do not allow directory traversal
- 	 outside of the current directory tree by archive members.  */
-@@ -3946,6 +3948,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3746,7 +3746,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+ #if BFD_SUPPORTS_PLUGINS
+       /* Ignore plugin target if all LTO sections should be removed.  */
+       ok_object = bfd_check_format_lto (this_element, bfd_object,
+-					lto_sections_removed);
++					lto_sections_removed, true);
+ #else
+       ok_object = bfd_check_format (this_element, bfd_object);
+ #endif
+@@ -3946,7 +3946,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
        break;
      }
  
-+  ibfd->is_strip_input = 1;
-+
-   if (bfd_check_format (ibfd, bfd_archive))
+-  if (bfd_check_format (ibfd, bfd_archive))
++  if (bfd_check_format_lto (ibfd, bfd_archive, lto_sections_removed,
++			    true))
      {
        bool force_output_target;
-@@ -5066,6 +5070,11 @@ strip_main (int argc, char *argv[])
+       bfd *obfd;
+@@ -3994,13 +3995,14 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+ 	      removed.  Try with plugin target next if ignoring plugin
+ 	      target fails to match the format.  */
+ 	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+-					 lto_sections_removed)
++					 lto_sections_removed, true)
+ 	   || (lto_sections_removed
+ 	       && bfd_check_format_matches_lto (ibfd, bfd_object,
+-						&obj_matching, false))
++						&obj_matching, false,
++						true))
+ #else
+ 	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
+-					 false)
++					 false, true)
+ #endif
+ 	   )
+     {
+@@ -5066,6 +5068,11 @@ strip_main (int argc, char *argv[])
  					       SECTION_CONTEXT_REMOVE)
  			  || !!find_section_list (".llvm.lto", false,
  					       SECTION_CONTEXT_REMOVE));


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-03 23:43 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-03 23:43 UTC (permalink / raw
  To: gentoo-commits

commit:     de495ba52b3a319cc60b6092f29134d7f6c77cfd
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun Aug  3 23:42:40 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug  3 23:42:40 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=de495ba5

9999: add another strip LTO patch

Bug: https://sourceware.org/PR33246
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-strip-Don-t-use-plugin-on-fat-IR-objects.patch | 427 +++++++++++++++++++++
 1 file changed, 427 insertions(+)

diff --git a/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
new file mode 100644
index 0000000..5347343
--- /dev/null
+++ b/9999/0006-strip-Don-t-use-plugin-on-fat-IR-objects.patch
@@ -0,0 +1,427 @@
+https://sourceware.org/bugzilla/show_bug.cgi?id=33246#c10
+
+From d499c2eea8d7f74f89f55a5a740f0d43e0c46c9b Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sun, 3 Aug 2025 10:28:40 -0700
+Subject: [PATCH] strip: Don't use plugin on fat IR objects
+
+Fat IR objects contains both regular sections and IR sections.  After
+
+717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d is the first bad commit
+commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d (HEAD)
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Sun May 4 05:12:46 2025 +0800
+
+    strip: Add GCC LTO IR support
+
+"strip --strip-debug" no longer strips debug sections in fat IR objects.
+When called from strip, don't treat archive member nor standalone fat
+IR object as an IR object.  For archive member, it will be copied as
+an unknown object if it isn't a fat IR object.  For standalone fat IR
+object, it will be copied as non-IR object.  Debug sections and IR
+sections can be removed by strip as usual.
+
+bfd/
+
+	PR binutils/33246
+	* archive.c: Include "plugin-api.h" and "plugin.h" if plugin is
+	enabled.
+	(_bfd_compute_and_write_armap): Don't complain plugin is needed
+	when the plugin target is in use.
+	* bfd-in2.h: Regenerated.
+	* bfd.c (bfd): Add is_strip_input.
+	* format.c (bfd_set_lto_type): If there is .llvm.lto section,
+	set LTO type to lto_fat_ir_object.
+	(bfd_check_format_matches_lto): When called from strip, don't
+	treat archive member nor standalone fat IR object as an IR
+	object.  Set LTO type if IR sections won't be removed.
+	* plugin.c (bfd_plugin_get_symbols_in_object_only): Copy LTO
+	type derived from input sections.
+
+nm/
+
+	PR binutils/33246
+	* nm.c (filter_symbols): Don't complain plugin is needed when
+	the plugin target is in use.
+	(display_rel_file): Likewise.
+	* objcopy.c (copy_archive): Set the is_strip_input field to 1
+	on input archive member.
+	(copy_file): Set the is_strip_input field to 1 on input object.
+	(strip_main): Keep .gnu.debuglto_* sections unless all GCC LTO
+	sections will be removed.
+
+ld/
+
+	PR binutils/33246
+	* testsuite/ld-plugin/lto-binutils.exp (run_pr33246_test): New.
+	Run binutils/33246 tests with GCC and Clang.
+	* testsuite/ld-plugin/pr33246.c: New file.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/archive.c                           |  10 +-
+ bfd/bfd-in2.h                           |   3 +
+ bfd/bfd.c                               |   3 +
+ bfd/format.c                            |  21 +++-
+ bfd/plugin.c                            |   3 +
+ binutils/nm.c                           |   6 +-
+ binutils/objcopy.c                      |   9 ++
+ ld/testsuite/ld-plugin/lto-binutils.exp | 153 ++++++++++++++++++++++++
+ ld/testsuite/ld-plugin/pr33246.c        |   4 +
+ 9 files changed, 207 insertions(+), 5 deletions(-)
+ create mode 100644 ld/testsuite/ld-plugin/pr33246.c
+
+diff --git a/bfd/archive.c b/bfd/archive.c
+index c61d4b12658..c323fb4fbd3 100644
+--- a/bfd/archive.c
++++ b/bfd/archive.c
+@@ -141,6 +141,10 @@ SUBSECTION
+ #include "hashtab.h"
+ #include "filenames.h"
+ #include "bfdlink.h"
++#if BFD_SUPPORTS_PLUGINS
++#include "plugin-api.h"
++#include "plugin.h"
++#endif
+ 
+ #ifndef errno
+ extern int errno;
+@@ -2342,7 +2346,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
+ 	  long symcount;
+ 	  long src_count;
+ 
+-	  if (bfd_get_lto_type (current) == lto_slim_ir_object
++	  if (!bfd_plugin_target_p (current->xvec)
++	      && bfd_get_lto_type (current) == lto_slim_ir_object
+ 	      && report_plugin_err)
+ 	    {
+ 	      report_plugin_err = false;
+@@ -2398,7 +2403,8 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
+ 			  map = new_map;
+ 			}
+ 
+-		      if (bfd_lto_slim_symbol_p (current,
++		      if (!bfd_plugin_target_p (current->xvec)
++			  && bfd_lto_slim_symbol_p (current,
+ 						 syms[src_count]->name)
+ 			  && report_plugin_err)
+ 			{
+diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
+index 2ff3e930bfa..bcff44a0f44 100644
+--- a/bfd/bfd-in2.h
++++ b/bfd/bfd-in2.h
+@@ -2131,6 +2131,9 @@ struct bfd
+   /* Set if this is the linker input BFD.  */
+   unsigned int is_linker_input : 1;
+ 
++  /* Set if this is the strip input BFD.  */
++  unsigned int is_strip_input : 1;
++
+   /* If this is an input for a compiler plug-in library.  */
+   ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ 
+diff --git a/bfd/bfd.c b/bfd/bfd.c
+index 858ab5ce017..4aded6809bb 100644
+--- a/bfd/bfd.c
++++ b/bfd/bfd.c
+@@ -296,6 +296,9 @@ CODE_FRAGMENT
+ .  {* Set if this is the linker input BFD.  *}
+ .  unsigned int is_linker_input : 1;
+ .
++.  {* Set if this is the strip input BFD.  *}
++.  unsigned int is_strip_input : 1;
++.
+ .  {* If this is an input for a compiler plug-in library.  *}
+ .  ENUM_BITFIELD (bfd_plugin_format) plugin_format : 2;
+ .
+diff --git a/bfd/format.c b/bfd/format.c
+index f3a0774af08..f88b9be1adc 100644
+--- a/bfd/format.c
++++ b/bfd/format.c
+@@ -413,6 +413,11 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+ 	    abfd->object_only_section = sec;
+ 	    break;
+ 	  }
++	else if (strcmp (sec->name, ".llvm.lto") == 0)
++	  {
++	    type = lto_fat_ir_object;
++	    break;
++	  }
+ 	else if (lsection.major_version == 0
+ 		 && startswith (sec->name, ".gnu.lto_.lto.")
+ 		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
+@@ -537,7 +542,16 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+ 
+       cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ 
+-      if (cleanup)
++      /* When called from strip, don't treat archive member nor
++	 standalone fat IR object as an IR object.  For archive
++	 member, it will be copied as an unknown object if it
++	 isn't a fat IR object.  For standalone fat IR object,
++	 it will be copied as non-IR object.  */
++      if (cleanup
++	  && (!abfd->is_strip_input
++	      || !bfd_plugin_target_p (abfd->xvec)
++	      || (abfd->lto_type != lto_fat_ir_object
++		  && abfd->my_archive == NULL)))
+ 	goto ok_ret;
+ 
+       /* For a long time the code has dropped through to check all
+@@ -621,6 +635,11 @@ bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
+ 	{
+ 	  int match_priority = abfd->xvec->match_priority;
+ 
++	  /* Set LTO type if IR sections won't be removed so that it
++	     can be checked for fat and slim IR objects.  */
++	  if (!lto_sections_removed)
++	    bfd_set_lto_type (abfd);
++
+ 	  if (abfd->format != bfd_archive
+ 	      || (bfd_has_map (abfd)
+ 		  && bfd_get_error () != bfd_error_wrong_object_format))
+diff --git a/bfd/plugin.c b/bfd/plugin.c
+index 1c72b748a8f..6dd22d75137 100644
+--- a/bfd/plugin.c
++++ b/bfd/plugin.c
+@@ -203,6 +203,9 @@ bfd_plugin_get_symbols_in_object_only (bfd *abfd)
+ 	  bfd_close (nbfd);
+ 	  return;
+ 	}
++
++      /* Copy LTO type derived from input sections.  */
++      abfd->lto_type = nbfd->lto_type;
+     }
+   else
+     {
+diff --git a/binutils/nm.c b/binutils/nm.c
+index a5d56311dde..94333042ee2 100644
+--- a/binutils/nm.c
++++ b/binutils/nm.c
+@@ -801,7 +801,8 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
+       if (sym == NULL)
+ 	continue;
+ 
+-      if (bfd_lto_slim_symbol_p (abfd, sym->name)
++      if (!bfd_plugin_target_p (abfd->xvec)
++	  && bfd_lto_slim_symbol_p (abfd, sym->name)
+ 	  && report_plugin_err)
+ 	{
+ 	  report_plugin_err = false;
+@@ -1484,7 +1485,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
+ 
+   /* lto_type is set to lto_non_ir_object when a bfd is loaded with a
+      compiler LTO plugin.  */
+-  if (bfd_get_lto_type (abfd) == lto_slim_ir_object)
++  if (!bfd_plugin_target_p (abfd->xvec)
++      && bfd_get_lto_type (abfd) == lto_slim_ir_object)
+     {
+       report_plugin_err = false;
+       non_fatal (_("%s: plugin needed to handle lto object"),
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index 5774711abe6..1f3b288be00 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -3687,6 +3687,8 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+       bool ok_object;
+       const char *element_name;
+ 
++      this_element->is_strip_input = 1;
++
+       element_name = bfd_get_filename (this_element);
+       /* PR binutils/17533: Do not allow directory traversal
+ 	 outside of the current directory tree by archive members.  */
+@@ -3946,6 +3948,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+       break;
+     }
+ 
++  ibfd->is_strip_input = 1;
++
+   if (bfd_check_format (ibfd, bfd_archive))
+     {
+       bool force_output_target;
+@@ -5066,6 +5070,11 @@ strip_main (int argc, char *argv[])
+ 					       SECTION_CONTEXT_REMOVE)
+ 			  || !!find_section_list (".llvm.lto", false,
+ 					       SECTION_CONTEXT_REMOVE));
++  /* NB: Must keep .gnu.debuglto_* sections unless all GCC LTO sections
++     will be removed to avoid undefined references to symbols in GCC LTO
++     debug sections.  */
++  if (!lto_sections_removed)
++    find_section_list (".gnu.debuglto_*", true, SECTION_CONTEXT_KEEP);
+ #endif
+ 
+   i = optind;
+diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
+index 88d35171045..9d19aa0c57e 100644
+--- a/ld/testsuite/ld-plugin/lto-binutils.exp
++++ b/ld/testsuite/ld-plugin/lto-binutils.exp
+@@ -355,3 +355,156 @@ run_cc_link_tests [list \
+ 	"tmpdir/libstrip-1b-fat-s.a" \
+     ] \
+ ]
++
++proc run_pr33246_test { llvm fat } {
++    global srcdir
++    global subdir
++    global plug_opt
++    global llvm_plug_opt
++    global ar
++    global CLANG_FOR_TARGET
++    global CC_FOR_TARGET
++    global NM
++    global READELF
++    global strip
++
++    set strip_flags "--strip-debug"
++
++    set test pr33246
++    set testname "${test}${llvm}${fat} with $strip_flags"
++
++    if { "$llvm" == "-llvm" } {
++	# Skip native x32 and i?86 targets since system LLVMgold.so may
++	# not be compatible with native x32 and i?86 targets binutils.
++	if { [istarget "x86_64-*-linux*-gnux32"]
++	     || [istarget "i?86-*-*"]
++	     || ![info exists CLANG_FOR_TARGET]
++	     || [string match "" $llvm_plug_opt] } then {
++	    untested $testname
++	    return
++	}
++	set CC $CLANG_FOR_TARGET
++	set binutils_plug_opt "$llvm_plug_opt"
++    } else {
++	if { ![info exists CC_FOR_TARGET]
++	     || [string match "" $plug_opt] } then {
++	    untested $testname
++	    return
++	}
++	set CC $CC_FOR_TARGET
++	set binutils_plug_opt "$plug_opt"
++    }
++
++    append strip_flags " $binutils_plug_opt"
++
++    set src $srcdir/$subdir/${test}.c
++    set obj tmpdir/${test}${llvm}${fat}.o
++    set archive tmpdir/${test}${llvm}${fat}.a
++    set CFLAGS "-c -g -O2 -flto"
++    if { "$fat" == "-fat" } {
++	append CFLAGS " -ffat-lto-objects"
++    } else {
++	append CFLAGS " -fno-fat-lto-objects"
++    }
++
++    set cmd "$CC $CFLAGS -o $obj $src"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($obj)"
++	return
++    }
++
++    set cmd "$strip $strip_flags $obj -o ${obj}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $obj)"
++	return
++    }
++
++    set cmd "$NM $binutils_plug_opt ${obj}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $obj)"
++	return
++    }
++
++    if { "$fat" == "-fat" } {
++	set cmd "$READELF -SW ${obj}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if [regexp " \.debug_" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $obj)"
++	    return
++	}
++    }
++
++    pass "$testname (strip $obj)"
++
++    set cmd "$ar $binutils_plug_opt -s -r -c $archive $obj"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($archive)"
++	return
++    }
++
++    set cmd "$strip $strip_flags $archive -o ${archive}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $archive)"
++	return
++    }
++
++    set cmd "$NM $binutils_plug_opt ${archive}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $archive)"
++	return
++    }
++
++    if { "$fat" == "-fat" } {
++	set cmd "$READELF -SW ${archive}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if [regexp " \.debug_" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $archive)"
++	    return
++	}
++    }
++
++    pass "$testname (strip $archive)"
++}
++
++run_pr33246_test "" ""
++run_pr33246_test "" "-fat"
++run_pr33246_test "-llvm" ""
++run_pr33246_test "-llvm" "-fat"
+diff --git a/ld/testsuite/ld-plugin/pr33246.c b/ld/testsuite/ld-plugin/pr33246.c
+new file mode 100644
+index 00000000000..cd0130cacdf
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr33246.c
+@@ -0,0 +1,4 @@
++void
++foo (void)
++{
++}
+-- 
+2.50.1


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-01 11:28 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-01 11:28 UTC (permalink / raw
  To: gentoo-commits

commit:     e9a57066f586150f389cc6183d7585bbcd31c92d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Aug  1 11:28:22 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug  1 11:28:22 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=e9a57066

9999: drop upstreamed test fix

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...st-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch | 57 ----------------------
 1 file changed, 57 deletions(-)

diff --git a/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch b/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch
deleted file mode 100644
index 1076168..0000000
--- a/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch
+++ /dev/null
@@ -1,57 +0,0 @@
-https://inbox.sourceware.org/binutils/20250731133439.665517-1-hjl.tools@gmail.com/
-
-From d752cad608e8d508e85e949a1ac0cca3b3cb3557 Mon Sep 17 00:00:00 2001
-Message-ID: <d752cad608e8d508e85e949a1ac0cca3b3cb3557.1754036184.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Thu, 31 Jul 2025 06:34:39 -0700
-Subject: [PATCH] gprof: Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh
-
-Both tst-gmon-gprof.sh and tst-gmon-gprof-l.sh generate gmon.out and
-process it.  Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid
-the race condition.
-
-	* testsuite/Makefile.am (tst-gmon-gprof-l.out): Depend on
-	tst-gmon-gprof.out.
-	* testsuite/Makefile.in: Regenerated.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- gprof/testsuite/Makefile.am | 4 +++-
- gprof/testsuite/Makefile.in | 4 +++-
- 2 files changed, 6 insertions(+), 2 deletions(-)
-
-diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
-index 0c80b12e6e4..7ab1c2ea6b7 100644
---- a/gprof/testsuite/Makefile.am
-+++ b/gprof/testsuite/Makefile.am
-@@ -37,7 +37,9 @@ tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
- 
- check_SCRIPTS += tst-gmon-gprof-l.sh
- check_DATA += tst-gmon-gprof-l.out
--tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
-+# Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid the race
-+# condition since they both generate gmon.out.
-+tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF) tst-gmon-gprof.out
- 	$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
- 
- endif NATIVE
-diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
-index 2ac5f241012..ab8a2cbb16e 100644
---- a/gprof/testsuite/Makefile.in
-+++ b/gprof/testsuite/Makefile.in
-@@ -884,7 +884,9 @@ uninstall-am:
- @NATIVE_TRUE@	$(LINK) tst-gmon.$(OBJEXT)
- @NATIVE_TRUE@tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
- @NATIVE_TRUE@	$(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT)
--@NATIVE_TRUE@tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
-+# Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid the race
-+# condition since they both generate gmon.out.
-+@NATIVE_TRUE@tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF) tst-gmon-gprof.out
- @NATIVE_TRUE@	$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
- 
- # Tell versions [3.59,3.63) of GNU make to not export all variables.
-
-base-commit: 711667472193c31b67eb3c190d7c91f660ac4bb0
--- 
-2.50.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-08-01  8:17 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-08-01  8:17 UTC (permalink / raw
  To: gentoo-commits

commit:     f05ec3bd6ad1e7830fec94c1aa1770a9a411bd5c
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Aug  1 08:17:41 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug  1 08:17:41 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f05ec3bd

9999: add fix for race condition in gprof tests

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...st-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch b/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch
new file mode 100644
index 0000000..1076168
--- /dev/null
+++ b/9999/0006-gprof-Run-tst-gmon-gprof-l.sh-after-tst-gmon-gprof.s.patch
@@ -0,0 +1,57 @@
+https://inbox.sourceware.org/binutils/20250731133439.665517-1-hjl.tools@gmail.com/
+
+From d752cad608e8d508e85e949a1ac0cca3b3cb3557 Mon Sep 17 00:00:00 2001
+Message-ID: <d752cad608e8d508e85e949a1ac0cca3b3cb3557.1754036184.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Thu, 31 Jul 2025 06:34:39 -0700
+Subject: [PATCH] gprof: Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh
+
+Both tst-gmon-gprof.sh and tst-gmon-gprof-l.sh generate gmon.out and
+process it.  Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid
+the race condition.
+
+	* testsuite/Makefile.am (tst-gmon-gprof-l.out): Depend on
+	tst-gmon-gprof.out.
+	* testsuite/Makefile.in: Regenerated.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ gprof/testsuite/Makefile.am | 4 +++-
+ gprof/testsuite/Makefile.in | 4 +++-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
+index 0c80b12e6e4..7ab1c2ea6b7 100644
+--- a/gprof/testsuite/Makefile.am
++++ b/gprof/testsuite/Makefile.am
+@@ -37,7 +37,9 @@ tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
+ 
+ check_SCRIPTS += tst-gmon-gprof-l.sh
+ check_DATA += tst-gmon-gprof-l.out
+-tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
++# Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid the race
++# condition since they both generate gmon.out.
++tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF) tst-gmon-gprof.out
+ 	$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
+ 
+ endif NATIVE
+diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
+index 2ac5f241012..ab8a2cbb16e 100644
+--- a/gprof/testsuite/Makefile.in
++++ b/gprof/testsuite/Makefile.in
+@@ -884,7 +884,9 @@ uninstall-am:
+ @NATIVE_TRUE@	$(LINK) tst-gmon.$(OBJEXT)
+ @NATIVE_TRUE@tst-gmon-gprof.out: tst-gmon$(EXEEXT) $(GPROF)
+ @NATIVE_TRUE@	$(srcdir)/tst-gmon-gprof.sh $(GPROF) tst-gmon$(EXEEXT)
+-@NATIVE_TRUE@tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF)
++# Run tst-gmon-gprof-l.sh after tst-gmon-gprof.sh to avoid the race
++# condition since they both generate gmon.out.
++@NATIVE_TRUE@tst-gmon-gprof-l.out: tst-gmon$(EXEEXT) $(GPROF) tst-gmon-gprof.out
+ @NATIVE_TRUE@	$(srcdir)/tst-gmon-gprof-l.sh $(GPROF) tst-gmon$(EXEEXT)
+ 
+ # Tell versions [3.59,3.63) of GNU make to not export all variables.
+
+base-commit: 711667472193c31b67eb3c190d7c91f660ac4bb0
+-- 
+2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-31 11:39 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-07-31 11:39 UTC (permalink / raw
  To: gentoo-commits

commit:     8eb5c7fc4e1325c68456d935a20c3f2821682fa4
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 31 11:07:40 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jul 31 11:39:17 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=8eb5c7fc

9999: add test failure fix

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...reat-default-output_target-as-unspecified.patch | 151 +++++++++++++++++++++
 1 file changed, 151 insertions(+)

diff --git a/9999/0006-strip-Treat-default-output_target-as-unspecified.patch b/9999/0006-strip-Treat-default-output_target-as-unspecified.patch
new file mode 100644
index 0000000..4694921
--- /dev/null
+++ b/9999/0006-strip-Treat-default-output_target-as-unspecified.patch
@@ -0,0 +1,151 @@
+https://inbox.sourceware.org/binutils/CAMe9rOqPdWMoGgvmecsu-PBokZ2x5J9WK3S01Mv5tCqSFyW-Sg@mail.gmail.com/
+
+From 044bbf7a436f73d54aed5c41e932bad518dc64bf Mon Sep 17 00:00:00 2001
+Message-ID: <044bbf7a436f73d54aed5c41e932bad518dc64bf.1753960038.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Wed, 30 Jul 2025 20:34:46 -0700
+Subject: [PATCH] strip: Treat "default" output_target as unspecified
+
+Treat output target as unspecified if it is set to "default".
+
+binutils/
+
+	PR binutils/33230
+	* objcopy.c (copy_file): Treat "default" output_target as
+	unspecified.
+
+binutils/testsuite/
+
+	PR binutils/33230
+	* binutils-all/x86-64/x86-64.exp (run_pr33230_test): New.
+	Run binutils/33230 tests with readelf if supported.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ binutils/objcopy.c                            |  6 +-
+ .../testsuite/binutils-all/x86-64/x86-64.exp  | 76 ++++++++++++++-----
+ 2 files changed, 60 insertions(+), 22 deletions(-)
+
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index e90117af90b..5774711abe6 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -3953,7 +3953,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+ 
+       /* bfd_get_target does not return the correct value until
+ 	 bfd_check_format succeeds.  */
+-      if (output_target == NULL)
++      if (output_target == NULL
++	  || strcmp (output_target, "default") == 0)
+ 	{
+ 	  output_target = bfd_get_target (ibfd);
+ 	  force_output_target = false;
+@@ -4008,7 +4009,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+ 
+       /* bfd_get_target does not return the correct value until
+ 	 bfd_check_format succeeds.  */
+-      if (output_target == NULL)
++      if (output_target == NULL
++	  || strcmp (output_target, "default") == 0)
+ 	output_target = bfd_get_target (ibfd);
+ 
+       if (ofd >= 0)
+diff --git a/binutils/testsuite/binutils-all/x86-64/x86-64.exp b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
+index a3fe6b13a7c..6d1b308eca6 100644
+--- a/binutils/testsuite/binutils-all/x86-64/x86-64.exp
++++ b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
+@@ -255,6 +255,56 @@ run_pr33198_test "-fat" "-R .gnu.lto_* -R .gnu.debuglto_* -R .llvm.lto -N __gnu_
+ run_pr33198_test "" "-R .llvm.lto"
+ run_pr33198_test "-fat" "-R .llvm.lto"
+ 
++proc run_pr33230_test { testname obj strip_flags run_readelf } {
++    global srcdir
++    global subdir
++    global READELF
++    global STRIP
++
++    append strip_flags " --strip-debug"
++    append testname " ($strip_flags)"
++
++    set cmd "$STRIP $strip_flags $obj -o ${obj}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if { $run_readelf == "yes" } {
++	if ![string match "" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (${obj})"
++	    return
++	}
++	set cmd "$READELF -h $obj"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if { ![regexp "Machine: +AArch64" $got] } then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (${obj})"
++	    return
++	}
++	set cmd "$READELF -h ${obj}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if { ![regexp "Machine: +AArch64" $got] } then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (${obj}.strip)"
++	    return
++	}
++    } elseif { ![regexp "Unable to recognise the format" $got] } then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname"
++	return
++    }
++
++    pass "$testname"
++}
++
+ set t $srcdir/$subdir/pr33230.obj.bz2
+ # We need to strip the ".bz2", but can leave the dirname.
+ set test $subdir/[file tail $t]
+@@ -264,26 +314,12 @@ set obj tmpdir/pr33230.o
+ if {[catch "system \"bzip2 -dc $t > $obj\""] != 0} {
+   untested "bzip2 -dc ($testname)"
+ } else {
+-    set cmd "$STRIP $obj -o ${obj}.strip"
+-    send_log "$cmd\n"
+-    verbose "$cmd" 1
+-    catch "exec $cmd" got
+-    if [regexp "Unable to recognise the format" $got] then {
+-	pass "$testname"
+-    } else {
+-	send_log "$got\n"
+-	verbose "$got" 1
+-	fail "$testname"
+-    }
+-    set cmd "$STRIP --input-target=default $obj -o ${obj}.strip"
+-    send_log "$cmd\n"
+-    verbose "$cmd" 1
+-    catch "exec $cmd" got
+-    if [regexp "Unable to recognise the format" $got] then {
+-	pass "$testname"
++    catch "exec $STRIP --help" got
++    if { [regexp "elf64-littleaarch64" $got] } {
++	set run_readelf "yes"
+     } else {
+-	send_log "$got\n"
+-	verbose "$got" 1
+-	fail "$testname (--input-target=default)"
++	set run_readelf "no"
+     }
++    run_pr33230_test "$testname" $obj "" $run_readelf
++    run_pr33230_test "$testname" $obj "--input-target=default" $run_readelf
+ }
+
+base-commit: c7c272f06d2d456d1d99762325fd0dd7db31d540
+-- 
+2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-28 12:24 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2025-07-28 12:24 UTC (permalink / raw
  To: gentoo-commits

commit:     45a5900d24f054ee4a32159c67bb4c9f58df05d2
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 28 12:24:26 2025 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Mon Jul 28 12:24:26 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=45a5900d

Rebase patches for binutils-2.45

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...iberty-install-PIC-version-of-libiberty.a.patch |  8 ++--
 ...oo-add-with-extra-soversion-suffix-option.patch | 54 ++++++++++++++--------
 ...-also-libctf-optionally-a-gentoo-specific.patch | 10 ++--
 ...ilar-libiberty-fix-as-in-7d53105d-for-lib.patch | 16 +++----
 ...-Adjust-testsuites-for-flto-and-without-g.patch | 25 ++++------
 5 files changed, 63 insertions(+), 50 deletions(-)

diff --git a/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 34afb9b..3ff9191 100644
--- a/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From a40f75efe4a34fbb447a026a52202b415013a984 Mon Sep 17 00:00:00 2001
+From bd82239c2a628ace1b6fddcec96871641fadfbec Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 1/5] Gentoo: libiberty: install PIC version of libiberty.a
@@ -18,10 +18,10 @@ general are fairly low, and we'd rather have things work for all of them.
  1 file changed, 1 insertion(+)
 
 diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
-index b77a41c781c..5e3725d16ff 100644
+index d507f27a9ef..51fefcb31c2 100644
 --- a/libiberty/Makefile.in
 +++ b/libiberty/Makefile.in
-@@ -258,6 +258,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+@@ -260,6 +260,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
  	  $(AR) $(AR_FLAGS) $(TARGETLIB) \
  	    $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \
  	  $(RANLIB) $(TARGETLIB); \
@@ -30,5 +30,5 @@ index b77a41c781c..5e3725d16ff 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.44.2
+2.49.1
 

diff --git a/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
index e7e4ae8..a1a35fd 100644
--- a/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 87a5dd82a8e08967694943e866aa9b26c4fc6a63 Mon Sep 17 00:00:00 2001
+From 062144ba260931e309a621355b92a2ca3b1ec12c Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 2/5] Gentoo: add --with-extra-soversion-suffix= option
@@ -29,12 +29,12 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
 ---
  bfd/Makefile.am  |  5 +++++
  bfd/Makefile.in  |  4 ++++
- bfd/configure    | 13 +++++++++++++
+ bfd/configure    | 17 +++++++++++++++--
  bfd/configure.ac |  7 +++++++
- 4 files changed, 29 insertions(+)
+ 4 files changed, 31 insertions(+), 2 deletions(-)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 0dc733eaba9..5bd636d931a 100644
+index 4987ac9cccc..23de1c6b5d7 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 0dc733eaba9..5bd636d931a 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -999,6 +1001,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -995,6 +997,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index 0dc733eaba9..5bd636d931a 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index b3d97d478ea..38209d1b234 100644
+index 8a670ad1d05..2218f61e604 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -348,6 +348,7 @@ ECHO_T = @ECHO_T@
+@@ -347,6 +347,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index b3d97d478ea..38209d1b234 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2471,6 +2472,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2464,6 +2465,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,7 +79,7 @@ index b3d97d478ea..38209d1b234 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 83cb19c7015..a60c76319b9 100755
+index 86561b30ac4..317c2f44982 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -701,6 +701,7 @@ WARN_CFLAGS
@@ -88,9 +88,9 @@ index 83cb19c7015..a60c76319b9 100755
  PKGVERSION
 +EXTRA_SOVERSION_SUFFIX
  DEBUGDIR
- ENABLE_BFD_64_BIT_FALSE
- ENABLE_BFD_64_BIT_TRUE
-@@ -842,6 +843,7 @@ enable_secureplt
+ PLUGINS_FALSE
+ PLUGINS_TRUE
+@@ -840,6 +841,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -98,16 +98,34 @@ index 83cb19c7015..a60c76319b9 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1530,6 +1532,8 @@ Optional Packages:
+@@ -1528,6 +1530,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
 +  --with-extra-soversion-suffix=SUFFIX
-+                          Append '.SUFFIX' to SONAME [default=]
++                          Append '.SUFFIX' to SONAME [[default=]]
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12082,6 +12086,15 @@ fi
+@@ -11153,7 +11157,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11156 "configure"
++#line 11160 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11259,7 +11263,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11262 "configure"
++#line 11266 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12030,6 +12034,15 @@ fi
  
  
  
@@ -124,10 +142,10 @@ index 83cb19c7015..a60c76319b9 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index 6bcfd1b7368..dde0a3af03e 100644
+index 5879a04785d..3e40e9476a7 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
-@@ -167,6 +167,13 @@ AC_ARG_WITH(separate-debug-dir,
+@@ -173,6 +173,13 @@ AC_ARG_WITH(separate-debug-dir,
  [DEBUGDIR="${withval}"])
  AC_SUBST(DEBUGDIR)
  
@@ -142,5 +160,5 @@ index 6bcfd1b7368..dde0a3af03e 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.44.2
+2.49.1
 

diff --git a/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 70c605a..7a73c68 100644
--- a/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From 225a5f5b9f40c1f335146ec882bd5517e4573f62 Mon Sep 17 00:00:00 2001
+From ef7b999d6d7748f0b6e159df52b4b663e5032072 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 3/5] Gentoo: Give also libctf optionally a gentoo-specific
@@ -12,7 +12,7 @@ Subject: [PATCH 3/5] Gentoo: Give also libctf optionally a gentoo-specific
  4 files changed, 62 insertions(+), 2 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index fb1a306c888..5fcc73bd04e 100644
+index 6e136220497..12301277275 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
 @@ -31,6 +31,9 @@ info_TEXINFOS =
@@ -45,7 +45,7 @@ index fb1a306c888..5fcc73bd04e 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 54f5daa79ee..b7a80edfab6 100644
+index 5d9587766dc..639d7147b02 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
 @@ -430,6 +430,7 @@ AUTOCONF = @AUTOCONF@
@@ -150,7 +150,7 @@ index 7466d56a18b..54c86592b70 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index 64544b83a9f..1ce43327c25 100644
+index fbd8ec12a14..3e83f43ba13 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
 @@ -76,6 +76,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
@@ -171,5 +171,5 @@ index 64544b83a9f..1ce43327c25 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.44.2
+2.49.1
 

diff --git a/9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index 54c7ba8..bb17a3b 100644
--- a/9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,7 +1,7 @@
-From 24694fe84ea1ac172f709bd1b079ebb996e4feb9 Mon Sep 17 00:00:00 2001
+From 845089ce66869d79e86869ec1972a33036010706 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
-Subject: [PATCH 5/5] Apply a similar libiberty fix as in 7d53105d for
+Subject: [PATCH 4/5] Apply a similar libiberty fix as in 7d53105d for
  libopcodes and libgprofng
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
@@ -18,7 +18,7 @@ Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 8 insertions(+), 6 deletions(-)
 
 diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
-index fb4b8a0fafa..3d7cb18ff71 100644
+index f6d3f5da759..36c334bb359 100644
 --- a/gprofng/src/Makefile.am
 +++ b/gprofng/src/Makefile.am
 @@ -144,7 +144,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -32,7 +32,7 @@ index fb4b8a0fafa..3d7cb18ff71 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
-index cef4b275305..295fd3ee2df 100644
+index 0cdd4443670..8021b2d4a3d 100644
 --- a/gprofng/src/Makefile.in
 +++ b/gprofng/src/Makefile.in
 @@ -552,7 +552,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -46,10 +46,10 @@ index cef4b275305..295fd3ee2df 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index 0075b6dc0ef..76fca3e9246 100755
+index 3dd6b692f89..54544895689 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
-@@ -14379,10 +14379,10 @@ if test "$enable_shared" = "yes"; then
+@@ -13881,10 +13881,10 @@ if test "$enable_shared" = "yes"; then
    case "${host}" in
      *-*-cygwin*)
        SHARED_LDFLAGS="-no-undefined"
@@ -63,7 +63,7 @@ index 0075b6dc0ef..76fca3e9246 100755
        ;;
    esac
 diff --git a/opcodes/configure.ac b/opcodes/configure.ac
-index 4d918e3ef9b..9692e69693e 100644
+index e31ddde9e57..8fdf538ecf8 100644
 --- a/opcodes/configure.ac
 +++ b/opcodes/configure.ac
 @@ -195,10 +195,10 @@ if test "$enable_shared" = "yes"; then
@@ -80,5 +80,5 @@ index 4d918e3ef9b..9692e69693e 100644
        ;;
    esac
 -- 
-2.44.2
+2.49.1
 

diff --git a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
index 20a8c62..e2735aa 100644
--- a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
+++ b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
@@ -1,8 +1,7 @@
-From f22ea3e751a11ab8cfb5524468d97a998cca0325 Mon Sep 17 00:00:00 2001
-Message-ID: <f22ea3e751a11ab8cfb5524468d97a998cca0325.1741810888.git.sam@gentoo.org>
+From 3d6a0b4a3f6b0582781979062cc6730e858997ae Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Mon, 10 Mar 2025 17:07:16 -0700
-Subject: [PATCH] Adjust testsuites for -flto and without -g
+Subject: [PATCH 5/5] Adjust testsuites for -flto and without -g
 
 Adjust testsuites for binutils built with -flto and without -g:
 
@@ -50,16 +49,14 @@ libctf/
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  binutils/testsuite/binutils-all/objcopy.exp | 14 +++++++++++---
- gprof/testsuite/Makefile.am                 | 10 +++++-----
- gprof/testsuite/Makefile.in                 | 12 +++++-------
  ld/testsuite/ld-ctf/ctf.exp                 |  5 +++++
  libctf/Makefile.am                          |  3 ++-
  libctf/Makefile.in                          |  3 ++-
  libctf/testsuite/lib/ctf-lib.exp            | 14 ++++++++++++--
- 7 files changed, 42 insertions(+), 19 deletions(-)
+ 5 files changed, 32 insertions(+), 7 deletions(-)
 
 diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
-index a706efbba18..42a29927a5d 100644
+index 6aa6d2d9fe7..9371d928d60 100644
 --- a/binutils/testsuite/binutils-all/objcopy.exp
 +++ b/binutils/testsuite/binutils-all/objcopy.exp
 @@ -36,6 +36,11 @@ if ![is_remote host] {
@@ -100,7 +97,7 @@ index a706efbba18..42a29927a5d 100644
  	untested $test
  	return
      }
-@@ -1381,10 +1388,11 @@ proc objcopy_test_without_global_symbol { } {
+@@ -1462,10 +1469,11 @@ proc objcopy_test_without_global_symbol { } {
      global OBJDUMPFLAGS
      global srcdir
      global subdir
@@ -134,10 +131,10 @@ index c314f2995af..08b47d2db18 100644
 +
 +set CFLAGS_FOR_TARGET "$old_CFLAGS"
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index 6e136220497..bf214d8a000 100644
+index 12301277275..26980667cc3 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
-@@ -102,11 +102,12 @@ check-DEJAGNU: site.exp development.exp
+@@ -114,11 +114,12 @@ check-DEJAGNU: site.exp development.exp
  	else \
  	  TEST_CROSS=yes; \
  	fi; \
@@ -152,10 +149,10 @@ index 6e136220497..bf214d8a000 100644
  	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
  	fi
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 5d9587766dc..e5bb94c681b 100644
+index 639d7147b02..812134c70c9 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -1819,11 +1819,12 @@ check-DEJAGNU: site.exp development.exp
+@@ -1826,11 +1826,12 @@ check-DEJAGNU: site.exp development.exp
  	else \
  	  TEST_CROSS=yes; \
  	fi; \
@@ -208,8 +205,6 @@ index 64d2a40ad9f..6d3b75e22a2 100644
  
  	if { $comp_output != ""} {
  	    send_log "compilation of CTF program [concat $src] failed with <$comp_output>"
-
-base-commit: add96080cf9e460afe478cfad489d7f22ab10678
 -- 
-2.48.1
+2.49.1
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-24 17:25 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-07-24 17:25 UTC (permalink / raw
  To: gentoo-commits

commit:     7b3646267bbca9cf13930a89c16157e1b666782f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 24 17:24:55 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jul 24 17:24:55 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=7b364626

9999: drop patch merged upstream

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...006-strip-Properly-handle-LLVM-IR-bitcode.patch | 541 ---------------------
 1 file changed, 541 deletions(-)

diff --git a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
deleted file mode 100644
index 1d2ab13..0000000
--- a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
+++ /dev/null
@@ -1,541 +0,0 @@
-https://inbox.sourceware.org/binutils/20250724035840.2641495-1-hjl.tools@gmail.com/
-
-From 080651084a14bee1bcc5f0fcfa7071d1428cd6c6 Mon Sep 17 00:00:00 2001
-Message-ID: <080651084a14bee1bcc5f0fcfa7071d1428cd6c6.1753329792.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Wed, 23 Jul 2025 20:58:40 -0700
-Subject: [PATCH] strip: Properly handle LLVM IR bitcode
-
-commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
-Author: H.J. Lu <hjl.tools@gmail.com>
-Date:   Sun May 4 05:12:46 2025 +0800
-
-    strip: Add GCC LTO IR support
-
-added "-R .gnu.lto_.*" to strip to remove the GCC LTO sections.  When
-"-R .gnu.lto_.*" is used, the plugin target is ignored so that the LTO
-sections are stripped as the regular sections.  It works for the non-fat
-GCC LTO IR since the GCC LTO IR is stored in the regular sections.  When
-the plugin target is ignored, the GCC LTO IR can be recognized as the
-normal object files.  But it doesn't work for the non-fat LLVM IR which
-is stored in a standalone file.
-
-1. Add bfd_check_format_matches_lto and bfd_check_format_lto to take an
-argument, lto_sections_removed, to indicate if LTO sections should be
-ignored.
-2. Update strip to always enable the plugin target so that the plugin
-target is enabled when checking for bfd_archive.
-3. Update strip to ignore the plugin target for bfd_object when all LTO
-sections should be removed.  If the object is unknown, copy it as an
-unknown file without any messages.
-4. Treat the "-R .llvm.lto" strip option as removing all LTO sections.
-
-bfd/
-
-	PR binutils/33198
-	* format.c (bfd_check_format_lto): New function.
-	(bfd_check_format): Call bfd_check_format_matches_lto.
-	(bfd_check_format_matches): Renamed to ...
-	(bfd_check_format_matches_lto): This.  Add an argument,
-	lto_sections_removed, to indicate if LTO sections should be
-	removed and don't match the plugin target if lto_sections_removed
-	is true.
-	(bfd_check_format_matches): Call bfd_check_format_matches_lto.
-	* bfd-in2.h: Regenerated.
-
-binutils/
-
-	PR binutils/33198
-	* objcopy.c (copy_archive): Call bfd_check_format_lto, instead
-	of bfd_check_format, and pass lto_sections_removed.  Remove the
-	non-fatal message on unknown element since it will be copied as
-	an unknown file.
-	(copy_file): Don't check lto_sections_removed when enabling LTO
-	plugin in strip.
-	(copy_file): Ignore plugin target first if all LTO sections should
-	be removed.  Try with plugin target next if ignoring plugin target
-	fails to match the format.
-	(strip_main): Also set lto_sections_removed for -R .llvm.lto.
-	* testsuite/binutils-all/x86-64/pr33198.c: New file.
-	* testsuite/binutils-all/x86-64/x86-64.exp (run_pr33198_test):
-	New.
-	Run binutils/33198 tests.
-	* testsuite/lib/binutils-common.exp (llvm_plug_opt): New.
-	(CLANG_FOR_TARGET): New.  Set to "clang" for native build if
-	"clang -v" reports "clang version".
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/bfd-in2.h                                 |   7 +
- bfd/format.c                                  |  84 ++++++++--
- binutils/objcopy.c                            |  40 +++--
- .../testsuite/binutils-all/x86-64/pr33198.c   |   4 +
- .../testsuite/binutils-all/x86-64/x86-64.exp  | 158 ++++++++++++++++++
- binutils/testsuite/lib/binutils-common.exp    |  27 +++
- 6 files changed, 299 insertions(+), 21 deletions(-)
- create mode 100644 binutils/testsuite/binutils-all/x86-64/pr33198.c
-
-diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index b013ef954da..2ff3e930bfa 100644
---- a/bfd/bfd-in2.h
-+++ b/bfd/bfd-in2.h
-@@ -2903,8 +2903,15 @@ bool generic_core_file_matches_executable_p
-    (bfd *core_bfd, bfd *exec_bfd);
- 
- /* Extracted from format.c.  */
-+bool bfd_check_format_lto (bfd *abfd, bfd_format format,
-+    bool lto_sections_removed);
-+
- bool bfd_check_format (bfd *abfd, bfd_format format);
- 
-+bool bfd_check_format_matches_lto
-+   (bfd *abfd, bfd_format format, char ***matching,
-+    bool lto_sections_removed);
-+
- bool bfd_check_format_matches
-    (bfd *abfd, bfd_format format, char ***matching);
- 
-diff --git a/bfd/format.c b/bfd/format.c
-index a909b70fe81..f3a0774af08 100644
---- a/bfd/format.c
-+++ b/bfd/format.c
-@@ -56,16 +56,19 @@ extern const size_t _bfd_target_vector_entries;
- 
- /*
- FUNCTION
--	bfd_check_format
-+	bfd_check_format_lto
- 
- SYNOPSIS
--	bool bfd_check_format (bfd *abfd, bfd_format format);
-+	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
-+				   bool lto_sections_removed);
- 
- DESCRIPTION
- 	Verify if the file attached to the BFD @var{abfd} is compatible
- 	with the format @var{format} (i.e., one of <<bfd_object>>,
- 	<<bfd_archive>> or <<bfd_core>>).
- 
-+	If LTO_SECTION_REMOVED is true, ignore plugin target.
-+
- 	If the BFD has been set to a specific target before the
- 	call, only the named target and format combination is
- 	checked. If the target has not been set, or has been set to
-@@ -99,10 +102,31 @@ DESCRIPTION
- 	itself.
- */
- 
-+bool
-+bfd_check_format_lto (bfd *abfd, bfd_format format,
-+		      bool lto_sections_removed)
-+{
-+  return bfd_check_format_matches_lto (abfd, format, NULL,
-+				       lto_sections_removed);
-+}
-+
-+
-+/*
-+FUNCTION
-+	bfd_check_format
-+
-+SYNOPSIS
-+	bool bfd_check_format (bfd *abfd, bfd_format format);
-+
-+DESCRIPTION
-+	Similar to bfd_check_format_plugin, except plugin target isn't
-+	ignored.
-+*/
-+
- bool
- bfd_check_format (bfd *abfd, bfd_format format)
- {
--  return bfd_check_format_matches (abfd, format, NULL);
-+  return bfd_check_format_matches_lto (abfd, format, NULL, false);
- }
- 
- struct bfd_preserve
-@@ -407,11 +431,12 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
- 
- /*
- FUNCTION
--	bfd_check_format_matches
-+	bfd_check_format_matches_lto
- 
- SYNOPSIS
--	bool bfd_check_format_matches
--	  (bfd *abfd, bfd_format format, char ***matching);
-+	bool bfd_check_format_matches_lto
-+	  (bfd *abfd, bfd_format format, char ***matching,
-+	   bool lto_sections_removed);
- 
- DESCRIPTION
- 	Like <<bfd_check_format>>, except when it returns FALSE with
-@@ -423,10 +448,14 @@ DESCRIPTION
- 
- 	When done with the list that @var{matching} points to, the caller
- 	should free it.
-+
-+	If LTO_SECTION_REMOVED is true, ignore plugin target.
- */
- 
- bool
--bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
-+bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
-+			      char ***matching,
-+			      bool lto_sections_removed ATTRIBUTE_UNUSED)
- {
-   extern const bfd_target binary_vec;
-   const bfd_target * const *target;
-@@ -495,8 +524,13 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
-   if (!bfd_preserve_save (abfd, &preserve, NULL))
-     goto err_ret;
- 
--  /* If the target type was explicitly specified, just check that target.  */
--  if (!abfd->target_defaulted)
-+  /* If the target type was explicitly specified, just check that target.
-+     If LTO_SECTION_REMOVED is true, don't match the plugin target.  */
-+  if (!abfd->target_defaulted
-+#if BFD_SUPPORTS_PLUGINS
-+      && (!lto_sections_removed || !bfd_plugin_target_p (abfd->xvec))
-+#endif
-+     )
-     {
-       if (bfd_seek (abfd, 0, SEEK_SET) != 0)	/* rewind! */
- 	goto err_ret;
-@@ -540,10 +574,12 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- 	 searching.  Don't match the plugin target if we have another
- 	 alternative since we want to properly set the input format
- 	 before allowing a plugin to claim the file.  Also, don't
--	 check the default target twice.  */
-+	 check the default target twice.   If LTO_SECTION_REMOVED is
-+	 true, don't match the plugin target.  */
-       if (*target == &binary_vec
- #if BFD_SUPPORTS_PLUGINS
--	  || (match_count != 0 && bfd_plugin_target_p (*target))
-+	  || ((lto_sections_removed || match_count != 0)
-+	      && bfd_plugin_target_p (*target))
- #endif
- 	  || (!abfd->target_defaulted && *target == save_targ))
- 	continue;
-@@ -795,6 +831,32 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
-   return false;
- }
- 
-+/*
-+FUNCTION
-+	bfd_check_format_matches
-+
-+SYNOPSIS
-+	bool bfd_check_format_matches
-+	  (bfd *abfd, bfd_format format, char ***matching);
-+
-+DESCRIPTION
-+	Like <<bfd_check_format>>, except when it returns FALSE with
-+	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
-+	case, if @var{matching} is not NULL, it will be filled in with
-+	a NULL-terminated list of the names of the formats that matched,
-+	allocated with <<malloc>>.
-+	Then the user may choose a format and try again.
-+
-+	When done with the list that @var{matching} points to, the caller
-+	should free it.
-+*/
-+
-+bool
-+bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
-+{
-+  return bfd_check_format_matches_lto (abfd, format, matching, false);
-+}
-+
- /*
- FUNCTION
- 	bfd_set_format
-diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 2ca04e84d47..905ce917708 100644
---- a/binutils/objcopy.c
-+++ b/binutils/objcopy.c
-@@ -3741,10 +3741,13 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
-       l->obfd = NULL;
-       list = l;
- 
-+#if BFD_SUPPORTS_PLUGINS
-+      /* Ignore plugin target if all LTO sections should be removed.  */
-+      ok_object = bfd_check_format_lto (this_element, bfd_object,
-+					lto_sections_removed);
-+#else
-       ok_object = bfd_check_format (this_element, bfd_object);
--      if (!ok_object)
--	bfd_nonfatal_message (NULL, this_element, NULL,
--			      _("Unable to recognise the format of file"));
-+#endif
- 
-       /* PR binutils/3110: Cope with archives
- 	 containing multiple target types.  */
-@@ -3880,9 +3883,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
-     }
- 
- #if BFD_SUPPORTS_PLUGINS
--  /* Enable LTO plugin in strip unless all LTO sections should be
--     removed.  */
--  if (is_strip && !target && !lto_sections_removed)
-+  /* Enable LTO plugin in strip.  */
-+  if (is_strip && !target)
-     target = "plugin";
- #endif
- 
-@@ -3980,7 +3982,21 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
- 			 input_arch))
- 	status = 1;
-     }
--  else if (bfd_check_format_matches (ibfd, bfd_object, &obj_matching))
-+  else if (
-+#if BFD_SUPPORTS_PLUGINS
-+	   /* Ignore plugin target first if all LTO sections should be
-+	      removed.  Try with plugin target next if ignoring plugin
-+	      target fails to match the format.  */
-+	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
-+					 lto_sections_removed)
-+	   || (lto_sections_removed
-+	       && bfd_check_format_matches_lto (ibfd, bfd_object,
-+						&obj_matching, false))
-+#else
-+	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
-+					 false)
-+#endif
-+	   )
-     {
-       bfd *obfd;
-     do_copy:
-@@ -5036,9 +5052,13 @@ strip_main (int argc, char *argv[])
- #if BFD_SUPPORTS_PLUGINS
-   /* Check if all GCC LTO sections should be removed, assuming all LTO
-      sections will be removed with -R .gnu.lto_.*.  * Remove .gnu.lto_.*
--     sections will also remove .gnu.debuglto_.  sections.  */
--  lto_sections_removed = !!find_section_list (".gnu.lto_.*", false,
--					      SECTION_CONTEXT_REMOVE);
-+     sections will also remove .gnu.debuglto_.  sections.  LLVM IR
-+     bitcode is stored in .llvm.lto section which will be removed with
-+     -R .llvm.lto.  */
-+  lto_sections_removed = (!!find_section_list (".gnu.lto_.*", false,
-+					       SECTION_CONTEXT_REMOVE)
-+			  || !!find_section_list (".llvm.lto", false,
-+					       SECTION_CONTEXT_REMOVE));
- #endif
- 
-   i = optind;
-diff --git a/binutils/testsuite/binutils-all/x86-64/pr33198.c b/binutils/testsuite/binutils-all/x86-64/pr33198.c
-new file mode 100644
-index 00000000000..cd0130cacdf
---- /dev/null
-+++ b/binutils/testsuite/binutils-all/x86-64/pr33198.c
-@@ -0,0 +1,4 @@
-+void
-+foo (void)
-+{
-+}
-diff --git a/binutils/testsuite/binutils-all/x86-64/x86-64.exp b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
-index 05c73047b60..ab1aa50a9a1 100644
---- a/binutils/testsuite/binutils-all/x86-64/x86-64.exp
-+++ b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
-@@ -96,3 +96,161 @@ if {[catch "system \"bzip2 -dc $t > $tempfile\""] != 0} {
- 	}
-     }
- }
-+
-+proc run_pr33198_test { fat strip_flags } {
-+    global srcdir
-+    global subdir
-+    global llvm_plug_opt
-+    global AR
-+    global CLANG_FOR_TARGET
-+    global NM
-+    global READELF
-+    global STRIP
-+
-+    set test pr33198
-+    set testname "${test}${fat} with $strip_flags"
-+
-+    if { [istarget "x86_64-*-linux*-gnux32"] \
-+	 || ![info exists CLANG_FOR_TARGET]
-+	 || [string match "" $llvm_plug_opt] } then {
-+	untested $testname
-+	return
-+    }
-+
-+    set src $srcdir/$subdir/${test}.c
-+    set obj tmpdir/${test}${fat}.o
-+    set archive tmpdir/${test}${fat}.a
-+    set CLANG_CFLAGS "-c -O2 -flto"
-+    if { "$fat" == "-fat" } {
-+	append CLANG_CFLAGS " -ffat-lto-objects"
-+    }
-+
-+    append strip_flags " --strip-unneeded $llvm_plug_opt"
-+
-+    set cmd "$CLANG_FOR_TARGET $CLANG_CFLAGS -o $obj $src"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($obj)"
-+	return
-+    }
-+
-+    set cmd "$NM $llvm_plug_opt $obj\n"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($obj)"
-+	return
-+    }
-+
-+    pass "$testname ($obj)"
-+
-+    set cmd "$STRIP $strip_flags $obj -o ${obj}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $obj)"
-+	return
-+    }
-+
-+    set cmd "$NM $llvm_plug_opt ${obj}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $obj)"
-+	return
-+    }
-+
-+    if { "$fat" == "-fat" } {
-+	set cmd "$READELF -SW ${obj}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if [regexp "\.llvm\.lto *LLVM_LTO *" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $obj)"
-+	    return
-+	}
-+    }
-+
-+    pass "$testname (strip $obj)"
-+
-+    set cmd "$AR $llvm_plug_opt -s -r -c $archive $obj"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($archive)"
-+	return
-+    }
-+
-+    set cmd "$NM $llvm_plug_opt $archive\n"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname ($archive)"
-+	return
-+    }
-+
-+    pass "$testname ($archive)"
-+
-+    set cmd "$STRIP $strip_flags $archive -o ${archive}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![string match "" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $archive)"
-+	return
-+    }
-+
-+    set cmd "$NM $llvm_plug_opt ${archive}.strip"
-+    send_log "$cmd\n"
-+    verbose "$cmd" 1
-+    catch "exec $cmd" got
-+    if ![regexp "0+ T foo" $got] then {
-+	send_log "$got\n"
-+	verbose "$got" 1
-+	fail "$testname (strip $archive)"
-+	return
-+    }
-+
-+    if { "$fat" == "-fat" } {
-+	set cmd "$READELF -SW ${archive}.strip"
-+	send_log "$cmd\n"
-+	verbose "$cmd" 1
-+	catch "exec $cmd" got
-+	if [regexp "\.llvm\.lto *LLVM_LTO *" $got] then {
-+	    send_log "$got\n"
-+	    verbose "$got" 1
-+	    fail "$testname (strip $archive)"
-+	    return
-+	}
-+    }
-+
-+    pass "$testname (strip $archive)"
-+}
-+
-+run_pr33198_test "" "-R .gnu.lto_* -R .gnu.debuglto_* -R .llvm.lto -N __gnu_lto_v1"
-+run_pr33198_test "-fat" "-R .gnu.lto_* -R .gnu.debuglto_* -R .llvm.lto -N __gnu_lto_v1"
-+run_pr33198_test "" "-R .llvm.lto"
-+run_pr33198_test "-fat" "-R .llvm.lto"
-diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b73b5558c27..7297f6d29d3 100644
---- a/binutils/testsuite/lib/binutils-common.exp
-+++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1811,3 +1811,30 @@ proc get_standard_section_names {} {
-     }
-     return
- }
-+
-+set llvm_plug_opt ""
-+if { [isnative] } then {
-+    if ![info exists CLANG_FOR_TARGET] then {
-+	catch "exec clang -v" got
-+	if [regexp "clang version" $got] then {
-+	    set CLANG_FOR_TARGET clang
-+	}
-+    }
-+    if [info exists CLANG_FOR_TARGET] then {
-+	set llvm_plug_so [string trim [exec $CLANG_FOR_TARGET -print-file-name=LLVMgold.so]]
-+	if { $llvm_plug_so ne "LLVMgold.so" } then {
-+	    set llvm_plug_opt "--plugin $llvm_plug_so"
-+	}
-+
-+	if { $llvm_plug_opt eq "" } then {
-+	    # If it is still blank, try llvm-config --libdir.  Clang
-+	    # searches CLANG_INSTALL_LIBDIR_BASENAME which corresponds
-+	    # to this.
-+	    catch "exec llvm-config --libdir" got
-+	    if {[file isdirectory $got] \
-+		&& [file isfile $got/LLVMgold.so]} then {
-+		set llvm_plug_opt "--plugin $got/LLVMgold.so"
-+	    }
-+	}
-+    }
-+}
-
-base-commit: 673c91580993bc285d75aca2340ae172c7030953
--- 
-2.50.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-24  4:03 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-07-24  4:03 UTC (permalink / raw
  To: gentoo-commits

commit:     d94aa680af81759b0d66385b7d3293aae70436e8
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 24 04:03:36 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jul 24 04:03:36 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d94aa680

9999: refresh patch once more for tests

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
index 09b4225..1d2ab13 100644
--- a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
+++ b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
@@ -1,8 +1,9 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33198#c11
+https://inbox.sourceware.org/binutils/20250724035840.2641495-1-hjl.tools@gmail.com/
 
-From fd317c8f4caf6147865e664e1f07f8f2465752a1 Mon Sep 17 00:00:00 2001
+From 080651084a14bee1bcc5f0fcfa7071d1428cd6c6 Mon Sep 17 00:00:00 2001
+Message-ID: <080651084a14bee1bcc5f0fcfa7071d1428cd6c6.1753329792.git.sam@gentoo.org>
 From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 22 Jul 2025 14:09:48 -0700
+Date: Wed, 23 Jul 2025 20:58:40 -0700
 Subject: [PATCH] strip: Properly handle LLVM IR bitcode
 
 commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
@@ -499,7 +500,7 @@ index 05c73047b60..ab1aa50a9a1 100644
 +run_pr33198_test "" "-R .llvm.lto"
 +run_pr33198_test "-fat" "-R .llvm.lto"
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b73b5558c27..2d72b77600b 100644
+index b73b5558c27..7297f6d29d3 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
 @@ -1811,3 +1811,30 @@ proc get_standard_section_names {} {
@@ -521,7 +522,7 @@ index b73b5558c27..2d72b77600b 100644
 +	    set llvm_plug_opt "--plugin $llvm_plug_so"
 +	}
 +
-+	if { $llvm_plug_so eq "" } then {
++	if { $llvm_plug_opt eq "" } then {
 +	    # If it is still blank, try llvm-config --libdir.  Clang
 +	    # searches CLANG_INSTALL_LIBDIR_BASENAME which corresponds
 +	    # to this.
@@ -533,5 +534,8 @@ index b73b5558c27..2d72b77600b 100644
 +	}
 +    }
 +}
+
+base-commit: 673c91580993bc285d75aca2340ae172c7030953
 -- 
 2.50.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-24  3:46 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-07-24  3:46 UTC (permalink / raw
  To: gentoo-commits

commit:     c7a682602cfbcd6267fd355fe1257de6df785a63
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 24 03:46:31 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jul 24 03:46:31 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=c7a68260

9999: update LLVM IR patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...006-strip-Properly-handle-LLVM-IR-bitcode.patch | 26 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
index ccb99ed..09b4225 100644
--- a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
+++ b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
@@ -1,6 +1,6 @@
-https://sourceware.org/bugzilla/show_bug.cgi?id=33198#c2
+https://sourceware.org/bugzilla/show_bug.cgi?id=33198#c11
 
-From 252058908602dc41b2e483e663aba211395c5c9d Mon Sep 17 00:00:00 2001
+From fd317c8f4caf6147865e664e1f07f8f2465752a1 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Tue, 22 Jul 2025 14:09:48 -0700
 Subject: [PATCH] strip: Properly handle LLVM IR bitcode
@@ -59,6 +59,9 @@ binutils/
 	* testsuite/binutils-all/x86-64/x86-64.exp (run_pr33198_test):
 	New.
 	Run binutils/33198 tests.
+	* testsuite/lib/binutils-common.exp (llvm_plug_opt): New.
+	(CLANG_FOR_TARGET): New.  Set to "clang" for native build if
+	"clang -v" reports "clang version".
 
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
@@ -67,8 +70,8 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  binutils/objcopy.c                            |  40 +++--
  .../testsuite/binutils-all/x86-64/pr33198.c   |   4 +
  .../testsuite/binutils-all/x86-64/x86-64.exp  | 158 ++++++++++++++++++
- binutils/testsuite/lib/binutils-common.exp    |  16 ++
- 6 files changed, 288 insertions(+), 21 deletions(-)
+ binutils/testsuite/lib/binutils-common.exp    |  27 +++
+ 6 files changed, 299 insertions(+), 21 deletions(-)
  create mode 100644 binutils/testsuite/binutils-all/x86-64/pr33198.c
 
 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
@@ -496,10 +499,10 @@ index 05c73047b60..ab1aa50a9a1 100644
 +run_pr33198_test "" "-R .llvm.lto"
 +run_pr33198_test "-fat" "-R .llvm.lto"
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b73b5558c27..d3a73337762 100644
+index b73b5558c27..2d72b77600b 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1811,3 +1811,19 @@ proc get_standard_section_names {} {
+@@ -1811,3 +1811,30 @@ proc get_standard_section_names {} {
      }
      return
  }
@@ -517,6 +520,17 @@ index b73b5558c27..d3a73337762 100644
 +	if { $llvm_plug_so ne "LLVMgold.so" } then {
 +	    set llvm_plug_opt "--plugin $llvm_plug_so"
 +	}
++
++	if { $llvm_plug_so eq "" } then {
++	    # If it is still blank, try llvm-config --libdir.  Clang
++	    # searches CLANG_INSTALL_LIBDIR_BASENAME which corresponds
++	    # to this.
++	    catch "exec llvm-config --libdir" got
++	    if {[file isdirectory $got] \
++		&& [file isfile $got/LLVMgold.so]} then {
++		set llvm_plug_opt "--plugin $got/LLVMgold.so"
++	    }
++	}
 +    }
 +}
 -- 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-07-23 22:37 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-07-23 22:37 UTC (permalink / raw
  To: gentoo-commits

commit:     94c4ba7c7271a8356739b2da33bb921c9caa447d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Jul 23 22:36:53 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jul 23 22:37:31 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=94c4ba7c

9999: add strip vs LTO IR patch

Bug: https://sourceware.org/PR33198
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...006-strip-Properly-handle-LLVM-IR-bitcode.patch | 523 +++++++++++++++++++++
 1 file changed, 523 insertions(+)

diff --git a/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
new file mode 100644
index 0000000..ccb99ed
--- /dev/null
+++ b/9999/0006-strip-Properly-handle-LLVM-IR-bitcode.patch
@@ -0,0 +1,523 @@
+https://sourceware.org/bugzilla/show_bug.cgi?id=33198#c2
+
+From 252058908602dc41b2e483e663aba211395c5c9d Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 22 Jul 2025 14:09:48 -0700
+Subject: [PATCH] strip: Properly handle LLVM IR bitcode
+
+commit 717a38e9a02109fcbcb18bb2ec3aa251e2ad0a0d
+Author: H.J. Lu <hjl.tools@gmail.com>
+Date:   Sun May 4 05:12:46 2025 +0800
+
+    strip: Add GCC LTO IR support
+
+added "-R .gnu.lto_.*" to strip to remove the GCC LTO sections.  When
+"-R .gnu.lto_.*" is used, the plugin target is ignored so that the LTO
+sections are stripped as the regular sections.  It works for the non-fat
+GCC LTO IR since the GCC LTO IR is stored in the regular sections.  When
+the plugin target is ignored, the GCC LTO IR can be recognized as the
+normal object files.  But it doesn't work for the non-fat LLVM IR which
+is stored in a standalone file.
+
+1. Add bfd_check_format_matches_lto and bfd_check_format_lto to take an
+argument, lto_sections_removed, to indicate if LTO sections should be
+ignored.
+2. Update strip to always enable the plugin target so that the plugin
+target is enabled when checking for bfd_archive.
+3. Update strip to ignore the plugin target for bfd_object when all LTO
+sections should be removed.  If the object is unknown, copy it as an
+unknown file without any messages.
+4. Treat the "-R .llvm.lto" strip option as removing all LTO sections.
+
+bfd/
+
+	PR binutils/33198
+	* format.c (bfd_check_format_lto): New function.
+	(bfd_check_format): Call bfd_check_format_matches_lto.
+	(bfd_check_format_matches): Renamed to ...
+	(bfd_check_format_matches_lto): This.  Add an argument,
+	lto_sections_removed, to indicate if LTO sections should be
+	removed and don't match the plugin target if lto_sections_removed
+	is true.
+	(bfd_check_format_matches): Call bfd_check_format_matches_lto.
+	* bfd-in2.h: Regenerated.
+
+binutils/
+
+	PR binutils/33198
+	* objcopy.c (copy_archive): Call bfd_check_format_lto, instead
+	of bfd_check_format, and pass lto_sections_removed.  Remove the
+	non-fatal message on unknown element since it will be copied as
+	an unknown file.
+	(copy_file): Don't check lto_sections_removed when enabling LTO
+	plugin in strip.
+	(copy_file): Ignore plugin target first if all LTO sections should
+	be removed.  Try with plugin target next if ignoring plugin target
+	fails to match the format.
+	(strip_main): Also set lto_sections_removed for -R .llvm.lto.
+	* testsuite/binutils-all/x86-64/pr33198.c: New file.
+	* testsuite/binutils-all/x86-64/x86-64.exp (run_pr33198_test):
+	New.
+	Run binutils/33198 tests.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/bfd-in2.h                                 |   7 +
+ bfd/format.c                                  |  84 ++++++++--
+ binutils/objcopy.c                            |  40 +++--
+ .../testsuite/binutils-all/x86-64/pr33198.c   |   4 +
+ .../testsuite/binutils-all/x86-64/x86-64.exp  | 158 ++++++++++++++++++
+ binutils/testsuite/lib/binutils-common.exp    |  16 ++
+ 6 files changed, 288 insertions(+), 21 deletions(-)
+ create mode 100644 binutils/testsuite/binutils-all/x86-64/pr33198.c
+
+diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
+index b013ef954da..2ff3e930bfa 100644
+--- a/bfd/bfd-in2.h
++++ b/bfd/bfd-in2.h
+@@ -2903,8 +2903,15 @@ bool generic_core_file_matches_executable_p
+    (bfd *core_bfd, bfd *exec_bfd);
+ 
+ /* Extracted from format.c.  */
++bool bfd_check_format_lto (bfd *abfd, bfd_format format,
++    bool lto_sections_removed);
++
+ bool bfd_check_format (bfd *abfd, bfd_format format);
+ 
++bool bfd_check_format_matches_lto
++   (bfd *abfd, bfd_format format, char ***matching,
++    bool lto_sections_removed);
++
+ bool bfd_check_format_matches
+    (bfd *abfd, bfd_format format, char ***matching);
+ 
+diff --git a/bfd/format.c b/bfd/format.c
+index a909b70fe81..f3a0774af08 100644
+--- a/bfd/format.c
++++ b/bfd/format.c
+@@ -56,16 +56,19 @@ extern const size_t _bfd_target_vector_entries;
+ 
+ /*
+ FUNCTION
+-	bfd_check_format
++	bfd_check_format_lto
+ 
+ SYNOPSIS
+-	bool bfd_check_format (bfd *abfd, bfd_format format);
++	bool bfd_check_format_lto (bfd *abfd, bfd_format format,
++				   bool lto_sections_removed);
+ 
+ DESCRIPTION
+ 	Verify if the file attached to the BFD @var{abfd} is compatible
+ 	with the format @var{format} (i.e., one of <<bfd_object>>,
+ 	<<bfd_archive>> or <<bfd_core>>).
+ 
++	If LTO_SECTION_REMOVED is true, ignore plugin target.
++
+ 	If the BFD has been set to a specific target before the
+ 	call, only the named target and format combination is
+ 	checked. If the target has not been set, or has been set to
+@@ -99,10 +102,31 @@ DESCRIPTION
+ 	itself.
+ */
+ 
++bool
++bfd_check_format_lto (bfd *abfd, bfd_format format,
++		      bool lto_sections_removed)
++{
++  return bfd_check_format_matches_lto (abfd, format, NULL,
++				       lto_sections_removed);
++}
++
++
++/*
++FUNCTION
++	bfd_check_format
++
++SYNOPSIS
++	bool bfd_check_format (bfd *abfd, bfd_format format);
++
++DESCRIPTION
++	Similar to bfd_check_format_plugin, except plugin target isn't
++	ignored.
++*/
++
+ bool
+ bfd_check_format (bfd *abfd, bfd_format format)
+ {
+-  return bfd_check_format_matches (abfd, format, NULL);
++  return bfd_check_format_matches_lto (abfd, format, NULL, false);
+ }
+ 
+ struct bfd_preserve
+@@ -407,11 +431,12 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+ 
+ /*
+ FUNCTION
+-	bfd_check_format_matches
++	bfd_check_format_matches_lto
+ 
+ SYNOPSIS
+-	bool bfd_check_format_matches
+-	  (bfd *abfd, bfd_format format, char ***matching);
++	bool bfd_check_format_matches_lto
++	  (bfd *abfd, bfd_format format, char ***matching,
++	   bool lto_sections_removed);
+ 
+ DESCRIPTION
+ 	Like <<bfd_check_format>>, except when it returns FALSE with
+@@ -423,10 +448,14 @@ DESCRIPTION
+ 
+ 	When done with the list that @var{matching} points to, the caller
+ 	should free it.
++
++	If LTO_SECTION_REMOVED is true, ignore plugin target.
+ */
+ 
+ bool
+-bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
++bfd_check_format_matches_lto (bfd *abfd, bfd_format format,
++			      char ***matching,
++			      bool lto_sections_removed ATTRIBUTE_UNUSED)
+ {
+   extern const bfd_target binary_vec;
+   const bfd_target * const *target;
+@@ -495,8 +524,13 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+   if (!bfd_preserve_save (abfd, &preserve, NULL))
+     goto err_ret;
+ 
+-  /* If the target type was explicitly specified, just check that target.  */
+-  if (!abfd->target_defaulted)
++  /* If the target type was explicitly specified, just check that target.
++     If LTO_SECTION_REMOVED is true, don't match the plugin target.  */
++  if (!abfd->target_defaulted
++#if BFD_SUPPORTS_PLUGINS
++      && (!lto_sections_removed || !bfd_plugin_target_p (abfd->xvec))
++#endif
++     )
+     {
+       if (bfd_seek (abfd, 0, SEEK_SET) != 0)	/* rewind! */
+ 	goto err_ret;
+@@ -540,10 +574,12 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+ 	 searching.  Don't match the plugin target if we have another
+ 	 alternative since we want to properly set the input format
+ 	 before allowing a plugin to claim the file.  Also, don't
+-	 check the default target twice.  */
++	 check the default target twice.   If LTO_SECTION_REMOVED is
++	 true, don't match the plugin target.  */
+       if (*target == &binary_vec
+ #if BFD_SUPPORTS_PLUGINS
+-	  || (match_count != 0 && bfd_plugin_target_p (*target))
++	  || ((lto_sections_removed || match_count != 0)
++	      && bfd_plugin_target_p (*target))
+ #endif
+ 	  || (!abfd->target_defaulted && *target == save_targ))
+ 	continue;
+@@ -795,6 +831,32 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+   return false;
+ }
+ 
++/*
++FUNCTION
++	bfd_check_format_matches
++
++SYNOPSIS
++	bool bfd_check_format_matches
++	  (bfd *abfd, bfd_format format, char ***matching);
++
++DESCRIPTION
++	Like <<bfd_check_format>>, except when it returns FALSE with
++	<<bfd_errno>> set to <<bfd_error_file_ambiguously_recognized>>.  In that
++	case, if @var{matching} is not NULL, it will be filled in with
++	a NULL-terminated list of the names of the formats that matched,
++	allocated with <<malloc>>.
++	Then the user may choose a format and try again.
++
++	When done with the list that @var{matching} points to, the caller
++	should free it.
++*/
++
++bool
++bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
++{
++  return bfd_check_format_matches_lto (abfd, format, matching, false);
++}
++
+ /*
+ FUNCTION
+ 	bfd_set_format
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index 2ca04e84d47..905ce917708 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -3741,10 +3741,13 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+       l->obfd = NULL;
+       list = l;
+ 
++#if BFD_SUPPORTS_PLUGINS
++      /* Ignore plugin target if all LTO sections should be removed.  */
++      ok_object = bfd_check_format_lto (this_element, bfd_object,
++					lto_sections_removed);
++#else
+       ok_object = bfd_check_format (this_element, bfd_object);
+-      if (!ok_object)
+-	bfd_nonfatal_message (NULL, this_element, NULL,
+-			      _("Unable to recognise the format of file"));
++#endif
+ 
+       /* PR binutils/3110: Cope with archives
+ 	 containing multiple target types.  */
+@@ -3880,9 +3883,8 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+     }
+ 
+ #if BFD_SUPPORTS_PLUGINS
+-  /* Enable LTO plugin in strip unless all LTO sections should be
+-     removed.  */
+-  if (is_strip && !target && !lto_sections_removed)
++  /* Enable LTO plugin in strip.  */
++  if (is_strip && !target)
+     target = "plugin";
+ #endif
+ 
+@@ -3980,7 +3982,21 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+ 			 input_arch))
+ 	status = 1;
+     }
+-  else if (bfd_check_format_matches (ibfd, bfd_object, &obj_matching))
++  else if (
++#if BFD_SUPPORTS_PLUGINS
++	   /* Ignore plugin target first if all LTO sections should be
++	      removed.  Try with plugin target next if ignoring plugin
++	      target fails to match the format.  */
++	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
++					 lto_sections_removed)
++	   || (lto_sections_removed
++	       && bfd_check_format_matches_lto (ibfd, bfd_object,
++						&obj_matching, false))
++#else
++	   bfd_check_format_matches_lto (ibfd, bfd_object, &obj_matching,
++					 false)
++#endif
++	   )
+     {
+       bfd *obfd;
+     do_copy:
+@@ -5036,9 +5052,13 @@ strip_main (int argc, char *argv[])
+ #if BFD_SUPPORTS_PLUGINS
+   /* Check if all GCC LTO sections should be removed, assuming all LTO
+      sections will be removed with -R .gnu.lto_.*.  * Remove .gnu.lto_.*
+-     sections will also remove .gnu.debuglto_.  sections.  */
+-  lto_sections_removed = !!find_section_list (".gnu.lto_.*", false,
+-					      SECTION_CONTEXT_REMOVE);
++     sections will also remove .gnu.debuglto_.  sections.  LLVM IR
++     bitcode is stored in .llvm.lto section which will be removed with
++     -R .llvm.lto.  */
++  lto_sections_removed = (!!find_section_list (".gnu.lto_.*", false,
++					       SECTION_CONTEXT_REMOVE)
++			  || !!find_section_list (".llvm.lto", false,
++					       SECTION_CONTEXT_REMOVE));
+ #endif
+ 
+   i = optind;
+diff --git a/binutils/testsuite/binutils-all/x86-64/pr33198.c b/binutils/testsuite/binutils-all/x86-64/pr33198.c
+new file mode 100644
+index 00000000000..cd0130cacdf
+--- /dev/null
++++ b/binutils/testsuite/binutils-all/x86-64/pr33198.c
+@@ -0,0 +1,4 @@
++void
++foo (void)
++{
++}
+diff --git a/binutils/testsuite/binutils-all/x86-64/x86-64.exp b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
+index 05c73047b60..ab1aa50a9a1 100644
+--- a/binutils/testsuite/binutils-all/x86-64/x86-64.exp
++++ b/binutils/testsuite/binutils-all/x86-64/x86-64.exp
+@@ -96,3 +96,161 @@ if {[catch "system \"bzip2 -dc $t > $tempfile\""] != 0} {
+ 	}
+     }
+ }
++
++proc run_pr33198_test { fat strip_flags } {
++    global srcdir
++    global subdir
++    global llvm_plug_opt
++    global AR
++    global CLANG_FOR_TARGET
++    global NM
++    global READELF
++    global STRIP
++
++    set test pr33198
++    set testname "${test}${fat} with $strip_flags"
++
++    if { [istarget "x86_64-*-linux*-gnux32"] \
++	 || ![info exists CLANG_FOR_TARGET]
++	 || [string match "" $llvm_plug_opt] } then {
++	untested $testname
++	return
++    }
++
++    set src $srcdir/$subdir/${test}.c
++    set obj tmpdir/${test}${fat}.o
++    set archive tmpdir/${test}${fat}.a
++    set CLANG_CFLAGS "-c -O2 -flto"
++    if { "$fat" == "-fat" } {
++	append CLANG_CFLAGS " -ffat-lto-objects"
++    }
++
++    append strip_flags " --strip-unneeded $llvm_plug_opt"
++
++    set cmd "$CLANG_FOR_TARGET $CLANG_CFLAGS -o $obj $src"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($obj)"
++	return
++    }
++
++    set cmd "$NM $llvm_plug_opt $obj\n"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($obj)"
++	return
++    }
++
++    pass "$testname ($obj)"
++
++    set cmd "$STRIP $strip_flags $obj -o ${obj}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $obj)"
++	return
++    }
++
++    set cmd "$NM $llvm_plug_opt ${obj}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $obj)"
++	return
++    }
++
++    if { "$fat" == "-fat" } {
++	set cmd "$READELF -SW ${obj}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if [regexp "\.llvm\.lto *LLVM_LTO *" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $obj)"
++	    return
++	}
++    }
++
++    pass "$testname (strip $obj)"
++
++    set cmd "$AR $llvm_plug_opt -s -r -c $archive $obj"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($archive)"
++	return
++    }
++
++    set cmd "$NM $llvm_plug_opt $archive\n"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname ($archive)"
++	return
++    }
++
++    pass "$testname ($archive)"
++
++    set cmd "$STRIP $strip_flags $archive -o ${archive}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![string match "" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $archive)"
++	return
++    }
++
++    set cmd "$NM $llvm_plug_opt ${archive}.strip"
++    send_log "$cmd\n"
++    verbose "$cmd" 1
++    catch "exec $cmd" got
++    if ![regexp "0+ T foo" $got] then {
++	send_log "$got\n"
++	verbose "$got" 1
++	fail "$testname (strip $archive)"
++	return
++    }
++
++    if { "$fat" == "-fat" } {
++	set cmd "$READELF -SW ${archive}.strip"
++	send_log "$cmd\n"
++	verbose "$cmd" 1
++	catch "exec $cmd" got
++	if [regexp "\.llvm\.lto *LLVM_LTO *" $got] then {
++	    send_log "$got\n"
++	    verbose "$got" 1
++	    fail "$testname (strip $archive)"
++	    return
++	}
++    }
++
++    pass "$testname (strip $archive)"
++}
++
++run_pr33198_test "" "-R .gnu.lto_* -R .gnu.debuglto_* -R .llvm.lto -N __gnu_lto_v1"
++run_pr33198_test "-fat" "-R .gnu.lto_* -R .gnu.debuglto_* -R .llvm.lto -N __gnu_lto_v1"
++run_pr33198_test "" "-R .llvm.lto"
++run_pr33198_test "-fat" "-R .llvm.lto"
+diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
+index b73b5558c27..d3a73337762 100644
+--- a/binutils/testsuite/lib/binutils-common.exp
++++ b/binutils/testsuite/lib/binutils-common.exp
+@@ -1811,3 +1811,19 @@ proc get_standard_section_names {} {
+     }
+     return
+ }
++
++set llvm_plug_opt ""
++if { [isnative] } then {
++    if ![info exists CLANG_FOR_TARGET] then {
++	catch "exec clang -v" got
++	if [regexp "clang version" $got] then {
++	    set CLANG_FOR_TARGET clang
++	}
++    }
++    if [info exists CLANG_FOR_TARGET] then {
++	set llvm_plug_so [string trim [exec $CLANG_FOR_TARGET -print-file-name=LLVMgold.so]]
++	if { $llvm_plug_so ne "LLVMgold.so" } then {
++	    set llvm_plug_opt "--plugin $llvm_plug_so"
++	}
++    }
++}
+-- 
+2.50.1


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-06-14 21:52 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-06-14 21:52 UTC (permalink / raw
  To: gentoo-commits

commit:     f1817dc6efa8459dd682a72ca12b3ca7887a5716
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 14 21:52:05 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 14 21:52:05 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f1817dc6

9999: drop upstreamed patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...orrectly-check-archive-element-for-LTO-IR.patch | 128 ---------------------
 1 file changed, 128 deletions(-)

diff --git a/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch b/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch
deleted file mode 100644
index 21ada0d..0000000
--- a/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch
+++ /dev/null
@@ -1,128 +0,0 @@
-From 0d8ad139ab054df15fddd5613826d9f6aeb44f0f Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Fri, 13 Jun 2025 08:20:49 +0800
-Subject: [PATCH] objcopy: Correctly check archive element for LTO IR
-
-Pass archive element, instead of archive, to bfd_plugin_target_p to check
-for LTO IR in archive element.
-
-	PR binutils/33078
-	* objcopy.c (copy_archive): Correctly check archive element for
-	LTO IR.
-	* testsuite/binutils-all/objcopy.exp (strip_test_archive): New.
-	Run strip_test_archive.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- binutils/objcopy.c                          |  2 +-
- binutils/testsuite/binutils-all/objcopy.exp | 82 +++++++++++++++++++++
- 2 files changed, 83 insertions(+), 1 deletion(-)
-
-diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index a973789b1d5..366e1079d82 100644
---- a/binutils/objcopy.c
-+++ b/binutils/objcopy.c
-@@ -3770,7 +3770,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
- 
- #if BFD_SUPPORTS_PLUGINS
-       /* Copy LTO IR file as unknown object.  */
--      if (bfd_plugin_target_p (ibfd->xvec))
-+      if (bfd_plugin_target_p (this_element->xvec))
- 	ok_object = false;
-       else
- #endif
-diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
-index cf94570642c..dd0dfd2e5c2 100644
---- a/binutils/testsuite/binutils-all/objcopy.exp
-+++ b/binutils/testsuite/binutils-all/objcopy.exp
-@@ -661,6 +661,88 @@ proc strip_test_with_saving_a_symbol { } {
- 
- strip_test_with_saving_a_symbol
- 
-+# Test stripping an archive.
-+
-+proc strip_test_archive { } {
-+    global AR
-+    global CC
-+    global STRIP
-+    global STRIPFLAGS
-+    global srcdir
-+    global subdir
-+
-+    set test "strip -g on archive"
-+
-+    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
-+	untested $test
-+	return
-+    }
-+
-+    set stripobjfile tmpdir/striptestprog.o
-+    set stripobjarchive testprog.o
-+    if [is_remote host] {
-+	set archive libstrip.a
-+	set objfile [remote_download host tmpdir/testprog.o]
-+	remote_file host delete $archive
-+	remote_file host delete $stripobjfile
-+	remote_file host delete $stripobjarchive
-+    } else {
-+	set archive tmpdir/libstrip.a
-+	set objfile tmpdir/testprog.o
-+	remote_file build delete $stripobjfile
-+	remote_file build delete $stripobjarchive
-+    }
-+
-+    remote_file build delete tmpdir/libstrip.a
-+
-+    set exec_output [binutils_run $STRIP "-g -o $stripobjfile $objfile"]
-+    set exec_output [prune_warnings $exec_output]
-+    if ![string equal "" $exec_output] {
-+	fail $test
-+	return
-+    }
-+
-+    set exec_output [binutils_run $AR "rc $archive ${objfile}"]
-+    set exec_output [prune_warnings $exec_output]
-+    if ![string equal "" $exec_output] {
-+	fail $test
-+	return
-+    }
-+
-+    set exec_output [binutils_run $STRIP "-g $archive"]
-+    set exec_output [prune_warnings $exec_output]
-+    if ![string equal "" $exec_output] {
-+	fail $test
-+	return
-+    }
-+
-+    set exec_output [binutils_run $AR "x $archive"]
-+    set exec_output [prune_warnings $exec_output]
-+    if ![string equal "" $exec_output] {
-+	fail $test
-+	return
-+    }
-+
-+    if [is_remote host] {
-+	set stripobjfile [remote_download host $stripobjfile]
-+	set stripobjarchive [remote_download host $stripobjarchive]
-+    }
-+
-+    send_log "cmp $stripobjarchive $stripobjfile\n"
-+    verbose "cmp $stripobjarchive $stripobjfile"
-+    set status [remote_exec build cmp "$stripobjarchive $stripobjfile"]
-+    set exec_output [lindex $status 1]
-+    set exec_output [prune_warnings $exec_output]
-+
-+    if [string equal "" $exec_output] then {
-+	pass $test
-+    } else {
-+	fail $test
-+    }
-+}
-+
-+strip_test_archive
-+
- # Build a final executable.
- 
- set exe [exeext]
--- 
-2.49.0


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-06-13  8:00 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-06-13  8:00 UTC (permalink / raw
  To: gentoo-commits

commit:     de322e0131b4407afb7385397f39b22e96330104
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 13 07:59:51 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun 13 08:00:18 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=de322e01

9999: fix strip on static libraries

Bug: https://bugs.gentoo.org/957882
Bug: https://sourceware.org/PR33078
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...orrectly-check-archive-element-for-LTO-IR.patch | 128 +++++++++++++++++++++
 1 file changed, 128 insertions(+)

diff --git a/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch b/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch
new file mode 100644
index 0000000..21ada0d
--- /dev/null
+++ b/9999/0006-objcopy-Correctly-check-archive-element-for-LTO-IR.patch
@@ -0,0 +1,128 @@
+From 0d8ad139ab054df15fddd5613826d9f6aeb44f0f Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Fri, 13 Jun 2025 08:20:49 +0800
+Subject: [PATCH] objcopy: Correctly check archive element for LTO IR
+
+Pass archive element, instead of archive, to bfd_plugin_target_p to check
+for LTO IR in archive element.
+
+	PR binutils/33078
+	* objcopy.c (copy_archive): Correctly check archive element for
+	LTO IR.
+	* testsuite/binutils-all/objcopy.exp (strip_test_archive): New.
+	Run strip_test_archive.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ binutils/objcopy.c                          |  2 +-
+ binutils/testsuite/binutils-all/objcopy.exp | 82 +++++++++++++++++++++
+ 2 files changed, 83 insertions(+), 1 deletion(-)
+
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index a973789b1d5..366e1079d82 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -3770,7 +3770,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+ 
+ #if BFD_SUPPORTS_PLUGINS
+       /* Copy LTO IR file as unknown object.  */
+-      if (bfd_plugin_target_p (ibfd->xvec))
++      if (bfd_plugin_target_p (this_element->xvec))
+ 	ok_object = false;
+       else
+ #endif
+diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
+index cf94570642c..dd0dfd2e5c2 100644
+--- a/binutils/testsuite/binutils-all/objcopy.exp
++++ b/binutils/testsuite/binutils-all/objcopy.exp
+@@ -661,6 +661,88 @@ proc strip_test_with_saving_a_symbol { } {
+ 
+ strip_test_with_saving_a_symbol
+ 
++# Test stripping an archive.
++
++proc strip_test_archive { } {
++    global AR
++    global CC
++    global STRIP
++    global STRIPFLAGS
++    global srcdir
++    global subdir
++
++    set test "strip -g on archive"
++
++    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
++	untested $test
++	return
++    }
++
++    set stripobjfile tmpdir/striptestprog.o
++    set stripobjarchive testprog.o
++    if [is_remote host] {
++	set archive libstrip.a
++	set objfile [remote_download host tmpdir/testprog.o]
++	remote_file host delete $archive
++	remote_file host delete $stripobjfile
++	remote_file host delete $stripobjarchive
++    } else {
++	set archive tmpdir/libstrip.a
++	set objfile tmpdir/testprog.o
++	remote_file build delete $stripobjfile
++	remote_file build delete $stripobjarchive
++    }
++
++    remote_file build delete tmpdir/libstrip.a
++
++    set exec_output [binutils_run $STRIP "-g -o $stripobjfile $objfile"]
++    set exec_output [prune_warnings $exec_output]
++    if ![string equal "" $exec_output] {
++	fail $test
++	return
++    }
++
++    set exec_output [binutils_run $AR "rc $archive ${objfile}"]
++    set exec_output [prune_warnings $exec_output]
++    if ![string equal "" $exec_output] {
++	fail $test
++	return
++    }
++
++    set exec_output [binutils_run $STRIP "-g $archive"]
++    set exec_output [prune_warnings $exec_output]
++    if ![string equal "" $exec_output] {
++	fail $test
++	return
++    }
++
++    set exec_output [binutils_run $AR "x $archive"]
++    set exec_output [prune_warnings $exec_output]
++    if ![string equal "" $exec_output] {
++	fail $test
++	return
++    }
++
++    if [is_remote host] {
++	set stripobjfile [remote_download host $stripobjfile]
++	set stripobjarchive [remote_download host $stripobjarchive]
++    }
++
++    send_log "cmp $stripobjarchive $stripobjfile\n"
++    verbose "cmp $stripobjarchive $stripobjfile"
++    set status [remote_exec build cmp "$stripobjarchive $stripobjfile"]
++    set exec_output [lindex $status 1]
++    set exec_output [prune_warnings $exec_output]
++
++    if [string equal "" $exec_output] then {
++	pass $test
++    } else {
++	fail $test
++    }
++}
++
++strip_test_archive
++
+ # Build a final executable.
+ 
+ set exe [exeext]
+-- 
+2.49.0


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-05-14  7:14 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-05-14  7:14 UTC (permalink / raw
  To: gentoo-commits

commit:     bca64bf5b98dc7bb07a2fb1c470a960ec43fb638
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed May 14 07:14:27 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed May 14 07:14:27 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=bca64bf5

9999: drop now-upstream strip LTO patch

\o/

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-lto-plugin.patch | 784 ---------------------------------------
 1 file changed, 784 deletions(-)

diff --git a/9999/0006-strip-lto-plugin.patch b/9999/0006-strip-lto-plugin.patch
deleted file mode 100644
index ac3cdfd..0000000
--- a/9999/0006-strip-lto-plugin.patch
+++ /dev/null
@@ -1,784 +0,0 @@
-https://bugs.gentoo.org/866422
-https://inbox.sourceware.org/binutils/CAMe9rOrW5hQ42pSMkZ9XW1LcDkv++YmG_hWoOUexMDMXZ4kaRw@mail.gmail.com/
-
-From 1e0ffbb5fd03eb10d3c4a77f2d6c05a296f970c8 Mon Sep 17 00:00:00 2001
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sun, 4 May 2025 05:12:46 +0800
-Subject: [PATCH v3] strip: Add GCC LTO IR support
-
-Add GCC LTO IR support to strip by copying GCC LTO IR input as unknown
-object file.  Don't enable LTO plugin in strip unless all LTO sections
-should be removed, assuming all LTO sections will be removed with
--R .gnu.lto_.*.  Add linker LTO tests for strip with --strip-unneeded
-and GCC LTO IR inputs.
-
-binutils/
-
-	PR binutils/21479
-	* objcopy.c: Include "plugin-api.h" and "plugin.h".
-	(lto_sections_removed): New.
-	(command_line_switch): Add OPTION_PLUGIN.
-	(strip_options): Likewise.
-	(strip_usage): Display "--plugin NAME".
-	(copy_unknown_file): New function.
-	(copy_unknown_object): Call copy_unknown_file.
-	(copy_archive): Copy input LTO IR member as unknown object.
-	(copy_file): Set input target to "plugin" for strip if it is
-	unset unless all LTO sections should be removed.  Copy input
-	LTO IR file as unknown file.
-	(strip_main): Call bfd_plugin_set_program_name. Handle
-	OPTION_PLUGIN.  Set lto_sections_removed to true if all GCC
-	LTO sections should be removed.
-	* doc/binutils.texi: Document --plugin for strip.
-
-ld/
-
-	PR binutils/21479
-	* testsuite/ld-plugin/lto-binutils.exp: New file.
-	* testsuite/ld-plugin/strip-1a-fat.c: Likewise.
-	* testsuite/ld-plugin/strip-1a-fat.rd: Likewise.
-	* testsuite/ld-plugin/strip-1b-fat.c: Likewise.
-	* testsuite/ld-plugin/strip-1b-fat.rd: Likewise.
-	* testsuite/ld-plugin/strip-1a.c: Likewise.
-	* testsuite/ld-plugin/strip-1b.c: Likewise.
-	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Add optional
-	trailing ld options.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- binutils/doc/binutils.texi              |  21 ++
- binutils/objcopy.c                      | 112 ++++++--
- ld/testsuite/ld-plugin/lto-binutils.exp | 341 ++++++++++++++++++++++++
- ld/testsuite/ld-plugin/strip-1a-fat.c   |   1 +
- ld/testsuite/ld-plugin/strip-1a-fat.rd  |   6 +
- ld/testsuite/ld-plugin/strip-1a.c       |   4 +
- ld/testsuite/ld-plugin/strip-1b-fat.c   |   1 +
- ld/testsuite/ld-plugin/strip-1b-fat.rd  |   5 +
- ld/testsuite/ld-plugin/strip-1b.c       |   3 +
- ld/testsuite/lib/ld-lib.exp             |   9 +-
- 10 files changed, 477 insertions(+), 26 deletions(-)
- create mode 100644 ld/testsuite/ld-plugin/lto-binutils.exp
- create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.c
- create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.rd
- create mode 100644 ld/testsuite/ld-plugin/strip-1a.c
- create mode 100644 ld/testsuite/ld-plugin/strip-1b-fat.c
- create mode 100644 ld/testsuite/ld-plugin/strip-1b-fat.rd
- create mode 100644 ld/testsuite/ld-plugin/strip-1b.c
-
-diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
-index 7f041d9deda..d094f7d7091 100644
---- a/binutils/doc/binutils.texi
-+++ b/binutils/doc/binutils.texi
-@@ -3566,6 +3566,7 @@ strip [@option{-F} @var{bfdname} |@option{--target=}@var{bfdname}]
-       [@option{--keep-section-symbols}]
-       [@option{--keep-file-symbols}]
-       [@option{--only-keep-debug}]
-+      [@option{--plugin} @var{name}]
-       [@option{-v} |@option{--verbose}] [@option{-V}|@option{--version}]
-       [@option{--help}] [@option{--info}]
-       @var{objfile}@dots{}
-@@ -3825,6 +3826,26 @@ currently only supports the presence of one filename containing
- debugging information, not multiple filenames on a one-per-object-file
- basis.
- 
-+@item --plugin @var{name}
-+@cindex plugins
-+Load the plugin called @var{name} to add support for extra target
-+types.  This option is only available if the toolchain has been built
-+with plugin support enabled.
-+
-+If @option{--plugin} is not provided, but plugin support has been
-+enabled then @command{strip} iterates over the files in
-+@file{$@{libdir@}/bfd-plugins} in alphabetic order and the first
-+plugin that claims the object in question is used.
-+
-+Please note that this plugin search directory is @emph{not} the one
-+used by @command{ld}'s @option{-plugin} option.  In order to make
-+@command{strip} use the  linker plugin it must be copied into the
-+@file{$@{libdir@}/bfd-plugins} directory.  For GCC based compilations
-+the linker plugin is called @file{liblto_plugin.so.0.0.0}.  For Clang
-+based compilations it is called @file{LLVMgold.so}.  The GCC plugin
-+is always backwards compatible with earlier versions, so it is
-+sufficient to just copy the newest one.
-+
- @item -V
- @itemx --version
- Show the version number for @command{strip}.
-diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 31933e13b7a..9ae6830dff3 100644
---- a/binutils/objcopy.c
-+++ b/binutils/objcopy.c
-@@ -30,6 +30,8 @@
- #include "coff/internal.h"
- #include "libcoff.h"
- #include "safe-ctype.h"
-+#include "plugin-api.h"
-+#include "plugin.h"
- 
- /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
-    header in generic PE code.  */
-@@ -165,6 +167,11 @@ static struct section_list *change_sections;
- /* TRUE if some sections are to be removed.  */
- static bool sections_removed;
- 
-+#if BFD_SUPPORTS_PLUGINS
-+/* TRUE if all GCC LTO sections are to be removed.  */
-+static bool lto_sections_removed;
-+#endif
-+
- /* TRUE if only some sections are to be copied.  */
- static bool sections_copied;
- 
-@@ -359,6 +366,7 @@ enum command_line_switch
-   OPTION_RENAME_SECTION,
-   OPTION_REVERSE_BYTES,
-   OPTION_PE_SECTION_ALIGNMENT,
-+  OPTION_PLUGIN,
-   OPTION_SET_SECTION_FLAGS,
-   OPTION_SET_SECTION_ALIGNMENT,
-   OPTION_SET_START,
-@@ -402,6 +410,7 @@ static struct option strip_options[] =
-   {"output-file", required_argument, 0, 'o'},
-   {"output-format", required_argument, 0, 'O'},	/* Obsolete */
-   {"output-target", required_argument, 0, 'O'},
-+  {"plugin", required_argument, 0, OPTION_PLUGIN},
-   {"preserve-dates", no_argument, 0, 'p'},
-   {"remove-section", required_argument, 0, 'R'},
-   {"remove-relocations", required_argument, 0, OPTION_REMOVE_RELOCS},
-@@ -758,6 +767,10 @@ strip_usage (FILE *stream, int exit_status)
-      --info                        List object formats & architectures supported\n\
-   -o <file>                        Place stripped output into <file>\n\
- "));
-+#if BFD_SUPPORTS_PLUGINS
-+  fprintf (stream, _("\
-+      --plugin NAME                Load the specified plugin\n"));
-+#endif
- 
-   list_supported_targets (program_name, stream);
-   if (REPORT_BUGS_TO[0] && exit_status == 0)
-@@ -1916,20 +1929,11 @@ add_redefine_syms_file (const char *filename)
-    Returns TRUE upon success, FALSE otherwise.  */
- 
- static bool
--copy_unknown_object (bfd *ibfd, bfd *obfd)
-+copy_unknown_file (bfd *ibfd, bfd *obfd, off_t size, unsigned int mode)
- {
-   char *cbuf;
-   bfd_size_type tocopy;
--  off_t size;
--  struct stat buf;
--
--  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
--    {
--      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
--      return false;
--    }
- 
--  size = buf.st_size;
-   if (size < 0)
-     {
-       non_fatal (_("stat returns negative size for `%s'"),
-@@ -1974,11 +1978,31 @@ copy_unknown_object (bfd *ibfd, bfd *obfd)
- 
-   /* We should at least to be able to read it back when copying an
-      unknown object in an archive.  */
--  chmod (bfd_get_filename (obfd), buf.st_mode | S_IRUSR);
-+  chmod (bfd_get_filename (obfd), mode | S_IRUSR);
-   free (cbuf);
-   return true;
- }
- 
-+/* Copy unknown object file archive member IBFD onto OBFD.
-+   Returns TRUE upon success, FALSE otherwise.  */
-+
-+static bool
-+copy_unknown_object (bfd *ibfd, bfd *obfd)
-+{
-+  struct stat buf;
-+
-+  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
-+    {
-+      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
-+      return false;
-+    }
-+
-+  if (!copy_unknown_file (ibfd, obfd, buf.st_size, buf.st_mode))
-+    return false;
-+
-+  return true;
-+}
-+
- typedef struct objcopy_internal_note
- {
-   Elf_Internal_Note  note;
-@@ -3744,7 +3768,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
- 	  goto cleanup_and_exit;
- 	}
- 
--      if (ok_object)
-+      /* Copy LTO IR file as unknown object.  */
-+      if (bfd_plugin_target_p (ibfd->xvec))
-+	ok_object = false;
-+      else if (ok_object)
- 	{
- 	  ok = copy_object (this_element, output_element, input_arch);
- 
-@@ -3845,6 +3872,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
-   char **obj_matching;
-   char **core_matching;
-   off_t size = get_file_size (input_filename);
-+  const char *target = input_target;
- 
-   if (size < 1)
-     {
-@@ -3855,9 +3883,16 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
-       return;
-     }
- 
-+#if BFD_SUPPORTS_PLUGINS
-+  /* Enable LTO plugin in strip unless all LTO sections should be
-+     removed.  */
-+  if (is_strip && !target && !lto_sections_removed)
-+    target = "plugin";
-+#endif
-+
-   /* To allow us to do "strip *" without dying on the first
-      non-object file, failures are nonfatal.  */
--  ibfd = bfd_openr (input_filename, input_target);
-+  ibfd = bfd_openr (input_filename, target);
-   if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
-     {
-       bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
-@@ -3974,17 +4009,29 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
-  	  return;
-  	}
- 
--      if (! copy_object (ibfd, obfd, input_arch))
--	status = 1;
--
--      /* PR 17512: file: 0f15796a.
--	 If the file could not be copied it may not be in a writeable
--	 state.  So use bfd_close_all_done to avoid the possibility of
--	 writing uninitialised data into the file.  */
--      if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
-+      if (bfd_plugin_target_p (ibfd->xvec))
- 	{
--	  status = 1;
--	  bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
-+	  /* Copy LTO IR file as unknown file.  */
-+	  if (!copy_unknown_file (ibfd, obfd, in_stat->st_size,
-+				  in_stat->st_mode))
-+	    status = 1;
-+	  else if (!bfd_close_all_done (obfd))
-+	    status = 1;
-+	}
-+      else
-+	{
-+	  if (! copy_object (ibfd, obfd, input_arch))
-+	    status = 1;
-+
-+	  /* PR 17512: file: 0f15796a.
-+	     If the file could not be copied it may not be in a writeable
-+	     state.  So use bfd_close_all_done to avoid the possibility of
-+	     writing uninitialised data into the file.  */
-+	  if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
-+	    {
-+	      status = 1;
-+	      bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
-+	    }
- 	}
- 
-       if (!bfd_close (ibfd))
-@@ -4837,6 +4884,10 @@ strip_main (int argc, char *argv[])
-   char *output_file = NULL;
-   bool merge_notes_set = false;
- 
-+#if BFD_SUPPORTS_PLUGINS
-+  bfd_plugin_set_program_name (argv[0]);
-+#endif
-+
-   while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
- 			   strip_options, (int *) 0)) != EOF)
-     {
-@@ -4927,6 +4978,13 @@ strip_main (int argc, char *argv[])
- 	case OPTION_KEEP_SECTION_SYMBOLS:
- 	  keep_section_symbols = true;
- 	  break;
-+	case OPTION_PLUGIN:	/* --plugin */
-+#if BFD_SUPPORTS_PLUGINS
-+	  bfd_plugin_set_plugin (optarg);
-+#else
-+	  fatal (_("sorry - this program has been built without plugin support\n"));
-+#endif
-+	  break;
- 	case 0:
- 	  /* We've been given a long option.  */
- 	  break;
-@@ -4971,6 +5029,14 @@ strip_main (int argc, char *argv[])
-   if (output_target == NULL)
-     output_target = input_target;
- 
-+#if BFD_SUPPORTS_PLUGINS
-+  /* Check if all GCC LTO sections should be removed, assuming all LTO
-+     sections will be removed with -R .gnu.lto_.*.  * Remove .gnu.lto_.*
-+     sections will also remove .gnu.debuglto_.  sections.  */
-+  lto_sections_removed = !!find_section_list (".gnu.lto_.*", false,
-+					      SECTION_CONTEXT_REMOVE);
-+#endif
-+
-   i = optind;
-   if (i == argc
-       || (output_file != NULL && (i + 1) < argc))
-diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
-new file mode 100644
-index 00000000000..db18a63a7b5
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-binutils.exp
-@@ -0,0 +1,341 @@
-+# Expect script for binutils tests with LTO
-+# Copyright (C) 2025 Free Software Foundation, Inc.
-+#
-+# This file is part of the GNU Binutils.
-+#
-+# This program is free software; you can redistribute it and/or modify
-+# it under the terms of the GNU General Public License as published by
-+# the Free Software Foundation; either version 3 of the License, or
-+# (at your option) any later version.
-+#
-+# This program is distributed in the hope that it will be useful,
-+# but WITHOUT ANY WARRANTY; without even the implied warranty of
-+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+# GNU General Public License for more details.
-+#
-+# You should have received a copy of the GNU General Public License
-+# along with this program; if not, write to the Free Software
-+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
-+# MA 02110-1301, USA.
-+#
-+
-+# Make sure that binutils can correctly handle LTO IR in ELF.
-+
-+if { !([istarget *-*-linux*]
-+       || [istarget arm*-*-uclinuxfdpiceabi]
-+       || [istarget *-*-nacl*]
-+       || [istarget *-*-gnu*]) || [istarget *ecoff] } then {
-+    return
-+}
-+
-+# Check to see if the C and C++ compilers work
-+if { ![check_compiler_available] || [which $CXX_FOR_TARGET] == 0 } {
-+    return
-+}
-+
-+# These tests require plugin and LTO.
-+if { ![check_plugin_api_available]
-+     || ![check_lto_available] } {
-+    return
-+}
-+
-+set lto_fat ""
-+set lto_no_fat ""
-+if { [check_lto_fat_available] } {
-+  set lto_fat "-ffat-lto-objects"
-+  set lto_no_fat "-fno-fat-lto-objects"
-+  set no_lto "-fno-lto"
-+}
-+
-+set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
-+
-+# List contains test-items:
-+#  0:program name
-+#  1:program options
-+#  2:input file
-+#  3:output file
-+#  4:action list (optional)
-+#
-+proc run_lto_binutils_test { lto_tests } {
-+    global srcdir
-+    global subdir
-+    global nm
-+    global objcopy
-+    global objdump
-+    global READELF
-+    global strip
-+    global lto_plugin
-+
-+    foreach testitem $lto_tests {
-+	set prog_name [lindex $testitem 0]
-+	set prog_options [lindex $testitem 1]
-+	set input tmpdir/[lindex $testitem 2]
-+	set output tmpdir/[lindex $testitem 3]
-+	set actions [lindex $testitem 4]
-+	set objfiles {}
-+	set is_unresolved 0
-+	set failed 0
-+
-+#	eval set prog \$$prog_name
-+	switch -- $prog_name {
-+	objcopy
-+	    {
-+		set prog $objcopy
-+		set prog_output "$output"
-+	    }
-+	strip
-+	    {
-+		set prog $strip
-+		set prog_output "-o $output"
-+	    }
-+	default
-+	    {
-+		perror "Unrecognized action $action"
-+		set is_unresolved 1
-+		break
-+	    }
-+	}
-+
-+	# Don't leave previous output around
-+	if { $output ne "tmpdir/" } {
-+	    remote_file host delete $output
-+	}
-+
-+	append prog_options " --plugin $lto_plugin"
-+
-+	set cmd_options "$prog_options $prog_output $input"
-+	set test_name "$prog_name $cmd_options"
-+
-+	set cmd "$prog $cmd_options"
-+	send_log "$cmd\n"
-+	set got [remote_exec host "$cmd"]
-+	if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
-+	    send_log "$got\n"
-+	    fail "$test_name"
-+	    continue
-+	}
-+
-+	if { $failed == 0 } {
-+	    foreach actionlist $actions {
-+		set action [lindex $actionlist 0]
-+		set progopts [lindex $actionlist 1]
-+
-+		# There are actions where we run regexp_diff on the
-+		# output, and there are other actions (presumably).
-+		# Handling of the former look the same.
-+		set dump_prog ""
-+		switch -- $action {
-+		    objdump
-+			{ set dump_prog $objdump }
-+		    nm
-+			{ set dump_prog $nm }
-+		    readelf
-+			{ set dump_prog $READELF }
-+		    default
-+			{
-+			    perror "Unrecognized action $action"
-+			    set is_unresolved 1
-+			    break
-+			}
-+		    }
-+
-+		if { $dump_prog != "" } {
-+		    set dumpfile [lindex $actionlist 2]
-+		    set binary $dump_prog
-+
-+		    # Ensure consistent sorting of symbols
-+		    if {[info exists env(LC_ALL)]} {
-+			set old_lc_all $env(LC_ALL)
-+		    }
-+		    set env(LC_ALL) "C"
-+		    set cmd "$binary $progopts $output > tmpdir/dump.out"
-+		    send_log "$cmd\n"
-+		    catch "exec $cmd" comp_output
-+		    if {[info exists old_lc_all]} {
-+			set env(LC_ALL) $old_lc_all
-+		    } else {
-+			unset env(LC_ALL)
-+		    }
-+		    set comp_output [prune_warnings $comp_output]
-+
-+		    if ![string match "" $comp_output] then {
-+			send_log "$comp_output\n"
-+			set failed 1
-+			break
-+		    }
-+
-+		    if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/$dumpfile"] } then {
-+			verbose -log "output is [file_contents "tmpdir/dump.out"]" 2
-+			set failed 1
-+			break
-+		    }
-+		}
-+	    }
-+	}
-+
-+	if { $failed } {
-+	    fail $test_name
-+	} elseif { $is_unresolved } {
-+	    unresolved $test_name
-+	} else {
-+	    pass $test_name
-+	}
-+    }
-+}
-+
-+run_cc_link_tests [list \
-+    [list \
-+	"Build strip-1a.o" \
-+	"" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1a.c } \
-+    ] \
-+    [list \
-+	"Build libstrip-1a.a" \
-+	"--plugin $lto_plugin" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1a.c } \
-+	{} \
-+	"libstrip-1a.a" \
-+    ] \
-+    [list \
-+	"Build strip-1a-fat.o" \
-+	"" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1a-fat.c } \
-+    ] \
-+    [list \
-+	"Build libstrip-1a-fat.a" \
-+	"--plugin $lto_plugin" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1a-fat.c } \
-+	{} \
-+	"libstrip-1a-fat.a" \
-+    ] \
-+]
-+
-+run_lto_binutils_test [list \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded" \
-+	"libstrip-1a.a" \
-+	"libstrip-1a-s.a" \
-+    ] \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded" \
-+	"strip-1a.o" \
-+	"strip-1a-s.o" \
-+    ] \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
-+	"libstrip-1a-fat.a" \
-+	"libstrip-1a-fat-s.a" \
-+	{{readelf -SW strip-1a-fat.rd}} \
-+    ] \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
-+	"strip-1a-fat.o" \
-+	"strip-1a-fat-s.o" \
-+	{{readelf -SW strip-1a-fat.rd}} \
-+    ] \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded -R .gnu.debuglto_*" \
-+	"libstrip-1a-fat.a" \
-+	"libstrip-1b-fat-s.a" \
-+	{{readelf -SW strip-1b-fat.rd}} \
-+    ] \
-+    [list \
-+	"strip" \
-+	"--strip-unneeded -R .gnu.debuglto_*" \
-+	"strip-1a-fat.o" \
-+	"strip-1b-fat-s.o" \
-+	{{readelf -SW strip-1b-fat.rd}} \
-+    ] \
-+]
-+
-+run_cc_link_tests [list \
-+    [list \
-+	"Build strip-1a (strip-1a.o)" \
-+	"" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1b.c } \
-+	{} \
-+	"libstrip-1a" \
-+	"C" \
-+	"tmpdir/strip-1a.o" \
-+    ] \
-+    [list \
-+	"Build strip-1b (strip-1a-s.o)" \
-+	"" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1b.c } \
-+	{} \
-+	"libstrip-1b" \
-+	"C" \
-+	"tmpdir/strip-1a-s.o" \
-+    ] \
-+    [list \
-+	"Build strip-1c (libstrip-1a.a)" \
-+	"" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1b.c } \
-+	{} \
-+	"libstrip-1c" \
-+	"C" \
-+	"tmpdir/libstrip-1a.a" \
-+    ] \
-+    [list \
-+	"Build strip-1d (libstrip-1a-s.a)" \
-+	"" \
-+	"-O2 -flto $lto_no_fat" \
-+	{ strip-1b.c } \
-+	{} \
-+	"libstrip-1d" \
-+	"C" \
-+	"tmpdir/libstrip-1a-s.a" \
-+    ] \
-+    [list \
-+	"Build strip-1e (strip-1a-fat-s.o)" \
-+	"" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1b-fat.c } \
-+	{} \
-+	"libstrip-1e" \
-+	"C" \
-+	"tmpdir/strip-1a-fat-s.o" \
-+    ] \
-+    [list \
-+	"Build strip-1f (libstrip-1a-fat-s.a)" \
-+	"" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1b-fat.c } \
-+	{} \
-+	"libstrip-1f" \
-+	"C" \
-+	"tmpdir/libstrip-1a-fat-s.a" \
-+    ] \
-+    [list \
-+	"Build strip-1g (strip-1b-fat-s.o)" \
-+	"" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1b-fat.c } \
-+	{} \
-+	"libstrip-1g" \
-+	"C" \
-+	"tmpdir/strip-1b-fat-s.o" \
-+    ] \
-+    [list \
-+	"Build strip-1h (libstrip-1b-fat-s.a)" \
-+	"" \
-+	"-O2 -flto $lto_fat" \
-+	{ strip-1b-fat.c } \
-+	{} \
-+	"libstrip-1h" \
-+	"C" \
-+	"tmpdir/libstrip-1b-fat-s.a" \
-+    ] \
-+]
-diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.c b/ld/testsuite/ld-plugin/strip-1a-fat.c
-new file mode 100644
-index 00000000000..03b2a5c2275
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1a-fat.c
-@@ -0,0 +1 @@
-+#include "strip-1a.c"
-diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.rd b/ld/testsuite/ld-plugin/strip-1a-fat.rd
-new file mode 100644
-index 00000000000..aefe1c55013
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1a-fat.rd
-@@ -0,0 +1,6 @@
-+#failif
-+#...
-+Section Headers:
-+#...
-+  \[[ 0-9]+\] \.gnu.lto_.*
-+#...
-diff --git a/ld/testsuite/ld-plugin/strip-1a.c b/ld/testsuite/ld-plugin/strip-1a.c
-new file mode 100644
-index 00000000000..d84af205338
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1a.c
-@@ -0,0 +1,4 @@
-+extern void foo2(void);
-+extern void foo3(void);
-+void foo1(void) { foo3(); }
-+int main(void) { foo2(); }
-diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.c b/ld/testsuite/ld-plugin/strip-1b-fat.c
-new file mode 100644
-index 00000000000..1a2e4d2d86a
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1b-fat.c
-@@ -0,0 +1 @@
-+#include "strip-1b.c"
-diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.rd b/ld/testsuite/ld-plugin/strip-1b-fat.rd
-new file mode 100644
-index 00000000000..e3a266f8bee
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1b-fat.rd
-@@ -0,0 +1,5 @@
-+#...
-+Section Headers:
-+#...
-+  \[[ 0-9]+\] \.gnu.lto_.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/strip-1b.c b/ld/testsuite/ld-plugin/strip-1b.c
-new file mode 100644
-index 00000000000..967872a0f12
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/strip-1b.c
-@@ -0,0 +1,3 @@
-+extern void foo1(void);
-+void foo2(void) { foo1(); }
-+void foo3(void) {}
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 96152718d6f..119410bc523 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -860,14 +860,15 @@ proc run_ld_link_exec_tests { ldtests args } {
- }
- 
- # List contains test-items with 3 items followed by 2 lists, one item and
--# one optional item:
-+# 2 optional items:
- #  0:name
--#  1:ld or ar options
-+#  1:leading ld or ar options
- #  2:compile options
- #  3:filenames of source files
- #  4:action and options.
- #  5:name of output file
- #  6:language (optional)
-+#  7:trailing ld options (optional), placed after object files
- #
- # Actions:
- # objdump: Apply objdump options on result.  Compare with regex (last arg).
-@@ -899,6 +900,7 @@ proc run_cc_link_tests { ldtests } {
- 	set actions [lindex $testitem 4]
- 	set binfile tmpdir/[lindex $testitem 5]
- 	set lang [lindex $testitem 6]
-+	set trailing_ldflags [lindex $testitem 7]
- 	set objfiles {}
- 	set is_unresolved 0
- 	set failed 0
-@@ -927,6 +929,7 @@ proc run_cc_link_tests { ldtests } {
- 	#verbose -log "actions   is $actions"
- 	#verbose -log "binfile   is $binfile"
- 	#verbose -log "lang      is $lang"
-+	#verbose -log "trailing_ldflags is $trailing_ldflags"
- 
- 	foreach actionlist $actions {
- 	    set action [lindex $actionlist 0]
-@@ -1006,7 +1009,7 @@ proc run_cc_link_tests { ldtests } {
- 		untested $testname
- 		continue
- 	    }
--	    ld_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"
-+	    ld_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles $trailing_ldflags"
- 	    set ld_output "$exec_output"
- 
- 	    if { $check_ld(source) == "regexp" } then {
--- 
-2.49.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-05-14  3:59 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-05-14  3:59 UTC (permalink / raw
  To: gentoo-commits

commit:     f7d21e0bc037916a14b50584e9f23b64e5d3ce50
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed May 14 03:59:20 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed May 14 03:59:20 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f7d21e0b

9999: refresh LTO strip patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-lto-plugin.patch | 64 ++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 35 deletions(-)

diff --git a/9999/0006-strip-lto-plugin.patch b/9999/0006-strip-lto-plugin.patch
index 06480f4..ac3cdfd 100644
--- a/9999/0006-strip-lto-plugin.patch
+++ b/9999/0006-strip-lto-plugin.patch
@@ -1,10 +1,10 @@
 https://bugs.gentoo.org/866422
-https://inbox.sourceware.org/binutils/CAMe9rOq_LMn22bBNAQs2=-vDxEaONziAPEvuCAJy1K3+Chu7_g@mail.gmail.com/
+https://inbox.sourceware.org/binutils/CAMe9rOrW5hQ42pSMkZ9XW1LcDkv++YmG_hWoOUexMDMXZ4kaRw@mail.gmail.com/
 
-From 55472ad8a1329a22c1b6fc97021b36059a73de61 Mon Sep 17 00:00:00 2001
+From 1e0ffbb5fd03eb10d3c4a77f2d6c05a296f970c8 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 4 May 2025 05:12:46 +0800
-Subject: [PATCH] strip: Add GCC LTO IR support
+Subject: [PATCH v3] strip: Add GCC LTO IR support
 
 Add GCC LTO IR support to strip by copying GCC LTO IR input as unknown
 object file.  Don't enable LTO plugin in strip unless all LTO sections
@@ -47,7 +47,7 @@ ld/
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  binutils/doc/binutils.texi              |  21 ++
- binutils/objcopy.c                      | 119 +++++++--
+ binutils/objcopy.c                      | 112 ++++++--
  ld/testsuite/ld-plugin/lto-binutils.exp | 341 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/strip-1a-fat.c   |   1 +
  ld/testsuite/ld-plugin/strip-1a-fat.rd  |   6 +
@@ -56,7 +56,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/testsuite/ld-plugin/strip-1b-fat.rd  |   5 +
  ld/testsuite/ld-plugin/strip-1b.c       |   3 +
  ld/testsuite/lib/ld-lib.exp             |   9 +-
- 10 files changed, 484 insertions(+), 26 deletions(-)
+ 10 files changed, 477 insertions(+), 26 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/lto-binutils.exp
  create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.c
  create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.rd
@@ -66,7 +66,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  create mode 100644 ld/testsuite/ld-plugin/strip-1b.c
 
 diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
-index c74526e929a..05a10d20924 100644
+index 7f041d9deda..d094f7d7091 100644
 --- a/binutils/doc/binutils.texi
 +++ b/binutils/doc/binutils.texi
 @@ -3566,6 +3566,7 @@ strip [@option{-F} @var{bfdname} |@option{--target=}@var{bfdname}]
@@ -105,7 +105,7 @@ index c74526e929a..05a10d20924 100644
  @itemx --version
  Show the version number for @command{strip}.
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 31933e13b7a..1396dd10bbe 100644
+index 31933e13b7a..9ae6830dff3 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
 @@ -30,6 +30,8 @@
@@ -117,17 +117,19 @@ index 31933e13b7a..1396dd10bbe 100644
  
  /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
     header in generic PE code.  */
-@@ -165,6 +167,9 @@ static struct section_list *change_sections;
+@@ -165,6 +167,11 @@ static struct section_list *change_sections;
  /* TRUE if some sections are to be removed.  */
  static bool sections_removed;
  
++#if BFD_SUPPORTS_PLUGINS
 +/* TRUE if all GCC LTO sections are to be removed.  */
 +static bool lto_sections_removed;
++#endif
 +
  /* TRUE if only some sections are to be copied.  */
  static bool sections_copied;
  
-@@ -359,6 +364,7 @@ enum command_line_switch
+@@ -359,6 +366,7 @@ enum command_line_switch
    OPTION_RENAME_SECTION,
    OPTION_REVERSE_BYTES,
    OPTION_PE_SECTION_ALIGNMENT,
@@ -135,7 +137,7 @@ index 31933e13b7a..1396dd10bbe 100644
    OPTION_SET_SECTION_FLAGS,
    OPTION_SET_SECTION_ALIGNMENT,
    OPTION_SET_START,
-@@ -402,6 +408,7 @@ static struct option strip_options[] =
+@@ -402,6 +410,7 @@ static struct option strip_options[] =
    {"output-file", required_argument, 0, 'o'},
    {"output-format", required_argument, 0, 'O'},	/* Obsolete */
    {"output-target", required_argument, 0, 'O'},
@@ -143,7 +145,7 @@ index 31933e13b7a..1396dd10bbe 100644
    {"preserve-dates", no_argument, 0, 'p'},
    {"remove-section", required_argument, 0, 'R'},
    {"remove-relocations", required_argument, 0, OPTION_REMOVE_RELOCS},
-@@ -758,6 +765,10 @@ strip_usage (FILE *stream, int exit_status)
+@@ -758,6 +767,10 @@ strip_usage (FILE *stream, int exit_status)
       --info                        List object formats & architectures supported\n\
    -o <file>                        Place stripped output into <file>\n\
  "));
@@ -154,7 +156,7 @@ index 31933e13b7a..1396dd10bbe 100644
  
    list_supported_targets (program_name, stream);
    if (REPORT_BUGS_TO[0] && exit_status == 0)
-@@ -1916,20 +1927,11 @@ add_redefine_syms_file (const char *filename)
+@@ -1916,20 +1929,11 @@ add_redefine_syms_file (const char *filename)
     Returns TRUE upon success, FALSE otherwise.  */
  
  static bool
@@ -165,18 +167,18 @@ index 31933e13b7a..1396dd10bbe 100644
    bfd_size_type tocopy;
 -  off_t size;
 -  struct stat buf;
- 
+-
 -  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
 -    {
 -      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
 -      return false;
 -    }
--
+ 
 -  size = buf.st_size;
    if (size < 0)
      {
        non_fatal (_("stat returns negative size for `%s'"),
-@@ -1974,11 +1976,40 @@ copy_unknown_object (bfd *ibfd, bfd *obfd)
+@@ -1974,11 +1978,31 @@ copy_unknown_object (bfd *ibfd, bfd *obfd)
  
    /* We should at least to be able to read it back when copying an
       unknown object in an archive.  */
@@ -192,7 +194,6 @@ index 31933e13b7a..1396dd10bbe 100644
 +static bool
 +copy_unknown_object (bfd *ibfd, bfd *obfd)
 +{
-+  off_t size;
 +  struct stat buf;
 +
 +  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
@@ -201,15 +202,7 @@ index 31933e13b7a..1396dd10bbe 100644
 +      return false;
 +    }
 +
-+  size = buf.st_size;
-+  if (size < 0)
-+    {
-+      non_fatal (_("stat returns negative size for `%s'"),
-+		 bfd_get_archive_filename (ibfd));
-+      return false;
-+    }
-+
-+  if (!copy_unknown_file (ibfd, obfd, size, buf.st_mode))
++  if (!copy_unknown_file (ibfd, obfd, buf.st_size, buf.st_mode))
 +    return false;
 +
 +  return true;
@@ -218,7 +211,7 @@ index 31933e13b7a..1396dd10bbe 100644
  typedef struct objcopy_internal_note
  {
    Elf_Internal_Note  note;
-@@ -3744,7 +3775,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+@@ -3744,7 +3768,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
  	  goto cleanup_and_exit;
  	}
  
@@ -230,7 +223,7 @@ index 31933e13b7a..1396dd10bbe 100644
  	{
  	  ok = copy_object (this_element, output_element, input_arch);
  
-@@ -3845,6 +3879,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3845,6 +3872,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
    char **obj_matching;
    char **core_matching;
    off_t size = get_file_size (input_filename);
@@ -238,7 +231,7 @@ index 31933e13b7a..1396dd10bbe 100644
  
    if (size < 1)
      {
-@@ -3855,9 +3890,16 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3855,9 +3883,16 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
        return;
      }
  
@@ -256,7 +249,7 @@ index 31933e13b7a..1396dd10bbe 100644
    if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
      {
        bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
-@@ -3974,17 +4016,29 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+@@ -3974,17 +4009,29 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
   	  return;
   	}
  
@@ -296,7 +289,7 @@ index 31933e13b7a..1396dd10bbe 100644
  	}
  
        if (!bfd_close (ibfd))
-@@ -4837,6 +4891,10 @@ strip_main (int argc, char *argv[])
+@@ -4837,6 +4884,10 @@ strip_main (int argc, char *argv[])
    char *output_file = NULL;
    bool merge_notes_set = false;
  
@@ -307,7 +300,7 @@ index 31933e13b7a..1396dd10bbe 100644
    while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
  			   strip_options, (int *) 0)) != EOF)
      {
-@@ -4927,6 +4985,13 @@ strip_main (int argc, char *argv[])
+@@ -4927,6 +4978,13 @@ strip_main (int argc, char *argv[])
  	case OPTION_KEEP_SECTION_SYMBOLS:
  	  keep_section_symbols = true;
  	  break;
@@ -321,7 +314,7 @@ index 31933e13b7a..1396dd10bbe 100644
  	case 0:
  	  /* We've been given a long option.  */
  	  break;
-@@ -4971,6 +5036,14 @@ strip_main (int argc, char *argv[])
+@@ -4971,6 +5029,14 @@ strip_main (int argc, char *argv[])
    if (output_target == NULL)
      output_target = input_target;
  
@@ -338,7 +331,7 @@ index 31933e13b7a..1396dd10bbe 100644
        || (output_file != NULL && (i + 1) < argc))
 diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
 new file mode 100644
-index 00000000000..c475d42b728
+index 00000000000..db18a63a7b5
 --- /dev/null
 +++ b/ld/testsuite/ld-plugin/lto-binutils.exp
 @@ -0,0 +1,341 @@
@@ -653,9 +646,9 @@ index 00000000000..c475d42b728
 +	"tmpdir/strip-1a-fat-s.o" \
 +    ] \
 +    [list \
-+	"Build strip-1f" \
++	"Build strip-1f (libstrip-1a-fat-s.a)" \
 +	"" \
-+	"-O2 -flto $lto_fat (libstrip-1a-fat-s.a)" \
++	"-O2 -flto $lto_fat" \
 +	{ strip-1b-fat.c } \
 +	{} \
 +	"libstrip-1f" \
@@ -788,3 +781,4 @@ index 96152718d6f..119410bc523 100644
  	    if { $check_ld(source) == "regexp" } then {
 -- 
 2.49.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-05-05  9:46 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-05-05  9:46 UTC (permalink / raw
  To: gentoo-commits

commit:     15b090aa1cb5d2522cb317db004d42ffd6180f2f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon May  5 09:46:16 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon May  5 09:46:16 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=15b090aa

9999: add ML reference to strip patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-lto-plugin.patch | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/9999/0006-strip-lto-plugin.patch b/9999/0006-strip-lto-plugin.patch
index ae85de1..06480f4 100644
--- a/9999/0006-strip-lto-plugin.patch
+++ b/9999/0006-strip-lto-plugin.patch
@@ -1,5 +1,5 @@
 https://bugs.gentoo.org/866422
-https://sourceware.org/bugzilla/show_bug.cgi?id=21479#c11
+https://inbox.sourceware.org/binutils/CAMe9rOq_LMn22bBNAQs2=-vDxEaONziAPEvuCAJy1K3+Chu7_g@mail.gmail.com/
 
 From 55472ad8a1329a22c1b6fc97021b36059a73de61 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-05-05  3:06 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-05-05  3:06 UTC (permalink / raw
  To: gentoo-commits

commit:     50adca177a5923795d493308ae2b4cedfbeaa15b
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon May  5 03:05:58 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon May  5 03:05:58 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=50adca17

9999: update strip patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-lto-plugin.patch | 141 +++++++++++++++++++++++++--------------
 1 file changed, 90 insertions(+), 51 deletions(-)

diff --git a/9999/0006-strip-lto-plugin.patch b/9999/0006-strip-lto-plugin.patch
index 962be2d..ae85de1 100644
--- a/9999/0006-strip-lto-plugin.patch
+++ b/9999/0006-strip-lto-plugin.patch
@@ -1,15 +1,16 @@
 https://bugs.gentoo.org/866422
-https://sourceware.org/bugzilla/show_bug.cgi?id=21479#c10
+https://sourceware.org/bugzilla/show_bug.cgi?id=21479#c11
 
-From 245176a7d6a92ab5283887a28a375c47585e41ee Mon Sep 17 00:00:00 2001
+From 55472ad8a1329a22c1b6fc97021b36059a73de61 Mon Sep 17 00:00:00 2001
 From: "H.J. Lu" <hjl.tools@gmail.com>
 Date: Sun, 4 May 2025 05:12:46 +0800
-Subject: [PATCH] strip: Add LTO IR support
+Subject: [PATCH] strip: Add GCC LTO IR support
 
-Add LTO IR support to strip by copying LTO IR input as unknown object
-file.  Don't enable LTO plugin in strip unless all LTO sections should
-be removed.  Add linker LTO tests for strip with --strip-unneeded and
-removing all LTO section.
+Add GCC LTO IR support to strip by copying GCC LTO IR input as unknown
+object file.  Don't enable LTO plugin in strip unless all LTO sections
+should be removed, assuming all LTO sections will be removed with
+-R .gnu.lto_.*.  Add linker LTO tests for strip with --strip-unneeded
+and GCC LTO IR inputs.
 
 binutils/
 
@@ -46,8 +47,8 @@ ld/
 Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
 ---
  binutils/doc/binutils.texi              |  21 ++
- binutils/objcopy.c                      | 130 +++++++++--
- ld/testsuite/ld-plugin/lto-binutils.exp | 292 ++++++++++++++++++++++++
+ binutils/objcopy.c                      | 119 +++++++--
+ ld/testsuite/ld-plugin/lto-binutils.exp | 341 ++++++++++++++++++++++++
  ld/testsuite/ld-plugin/strip-1a-fat.c   |   1 +
  ld/testsuite/ld-plugin/strip-1a-fat.rd  |   6 +
  ld/testsuite/ld-plugin/strip-1a.c       |   4 +
@@ -55,7 +56,7 @@ Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
  ld/testsuite/ld-plugin/strip-1b-fat.rd  |   5 +
  ld/testsuite/ld-plugin/strip-1b.c       |   3 +
  ld/testsuite/lib/ld-lib.exp             |   9 +-
- 10 files changed, 446 insertions(+), 26 deletions(-)
+ 10 files changed, 484 insertions(+), 26 deletions(-)
  create mode 100644 ld/testsuite/ld-plugin/lto-binutils.exp
  create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.c
  create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.rd
@@ -104,7 +105,7 @@ index c74526e929a..05a10d20924 100644
  @itemx --version
  Show the version number for @command{strip}.
 diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index 31933e13b7a..4990e6a7856 100644
+index 31933e13b7a..1396dd10bbe 100644
 --- a/binutils/objcopy.c
 +++ b/binutils/objcopy.c
 @@ -30,6 +30,8 @@
@@ -164,13 +165,13 @@ index 31933e13b7a..4990e6a7856 100644
    bfd_size_type tocopy;
 -  off_t size;
 -  struct stat buf;
--
+ 
 -  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
 -    {
 -      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
 -      return false;
 -    }
- 
+-
 -  size = buf.st_size;
    if (size < 0)
      {
@@ -295,25 +296,18 @@ index 31933e13b7a..4990e6a7856 100644
  	}
  
        if (!bfd_close (ibfd))
-@@ -4837,6 +4891,17 @@ strip_main (int argc, char *argv[])
+@@ -4837,6 +4891,10 @@ strip_main (int argc, char *argv[])
    char *output_file = NULL;
    bool merge_notes_set = false;
  
 +#if BFD_SUPPORTS_PLUGINS
-+  /* All GCC LTO section prefixes.  */
-+  const char *GCC_LTO_sections[] =
-+    {
-+      ".gnu.debuglto_.",
-+      ".gnu.lto_."
-+    };
-+
 +  bfd_plugin_set_program_name (argv[0]);
 +#endif
 +
    while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
  			   strip_options, (int *) 0)) != EOF)
      {
-@@ -4927,6 +4992,13 @@ strip_main (int argc, char *argv[])
+@@ -4927,6 +4985,13 @@ strip_main (int argc, char *argv[])
  	case OPTION_KEEP_SECTION_SYMBOLS:
  	  keep_section_symbols = true;
  	  break;
@@ -327,20 +321,16 @@ index 31933e13b7a..4990e6a7856 100644
  	case 0:
  	  /* We've been given a long option.  */
  	  break;
-@@ -4971,6 +5043,18 @@ strip_main (int argc, char *argv[])
+@@ -4971,6 +5036,14 @@ strip_main (int argc, char *argv[])
    if (output_target == NULL)
      output_target = input_target;
  
 +#if BFD_SUPPORTS_PLUGINS
-+  /* Check if all GCC LTO sections should be removed.  */
-+  lto_sections_removed = true;
-+  for (i = 0; i < (int) ARRAY_SIZE (GCC_LTO_sections); i++)
-+    if (!find_section_list (GCC_LTO_sections[i], false,
-+			    SECTION_CONTEXT_REMOVE))
-+      {
-+	lto_sections_removed = false;
-+	break;
-+      }
++  /* Check if all GCC LTO sections should be removed, assuming all LTO
++     sections will be removed with -R .gnu.lto_.*.  * Remove .gnu.lto_.*
++     sections will also remove .gnu.debuglto_.  sections.  */
++  lto_sections_removed = !!find_section_list (".gnu.lto_.*", false,
++					      SECTION_CONTEXT_REMOVE);
 +#endif
 +
    i = optind;
@@ -348,10 +338,10 @@ index 31933e13b7a..4990e6a7856 100644
        || (output_file != NULL && (i + 1) < argc))
 diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
 new file mode 100644
-index 00000000000..aeb03ea8326
+index 00000000000..c475d42b728
 --- /dev/null
 +++ b/ld/testsuite/ld-plugin/lto-binutils.exp
-@@ -0,0 +1,292 @@
+@@ -0,0 +1,341 @@
 +# Expect script for binutils tests with LTO
 +# Copyright (C) 2025 Free Software Foundation, Inc.
 +#
@@ -410,7 +400,7 @@ index 00000000000..aeb03ea8326
 +#  3:output file
 +#  4:action list (optional)
 +#
-+proc lto_binutils_test { lto_tests } {
++proc run_lto_binutils_test { lto_tests } {
 +    global srcdir
 +    global subdir
 +    global nm
@@ -427,20 +417,40 @@ index 00000000000..aeb03ea8326
 +	set output tmpdir/[lindex $testitem 3]
 +	set actions [lindex $testitem 4]
 +	set objfiles {}
++	set is_unresolved 0
 +	set failed 0
 +
++#	eval set prog \$$prog_name
++	switch -- $prog_name {
++	objcopy
++	    {
++		set prog $objcopy
++		set prog_output "$output"
++	    }
++	strip
++	    {
++		set prog $strip
++		set prog_output "-o $output"
++	    }
++	default
++	    {
++		perror "Unrecognized action $action"
++		set is_unresolved 1
++		break
++	    }
++	}
++
 +	# Don't leave previous output around
 +	if { $output ne "tmpdir/" } {
 +	    remote_file host delete $output
 +	}
 +
-+	eval set prog \$$prog_name
-+
 +	append prog_options " --plugin $lto_plugin"
 +
-+	set test_name "$prog_name $prog_options ($input)"
++	set cmd_options "$prog_options $prog_output $input"
++	set test_name "$prog_name $cmd_options"
 +
-+	set cmd "$prog $prog_options -o $output $input"
++	set cmd "$prog $cmd_options"
 +	send_log "$cmd\n"
 +	set got [remote_exec host "$cmd"]
 +	if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
@@ -509,6 +519,8 @@ index 00000000000..aeb03ea8326
 +
 +	if { $failed } {
 +	    fail $test_name
++	} elseif { $is_unresolved } {
++	    unresolved $test_name
 +	} else {
 +	    pass $test_name
 +	}
@@ -546,7 +558,7 @@ index 00000000000..aeb03ea8326
 +    ] \
 +]
 +
-+lto_binutils_test [list \
++run_lto_binutils_test [list \
 +    [list \
 +	"strip" \
 +	"--strip-unneeded" \
@@ -561,21 +573,28 @@ index 00000000000..aeb03ea8326
 +    ] \
 +    [list \
 +	"strip" \
-+	"-R .gnu.*lto_* -N __gnu_lto_v1" \
++	"--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
 +	"libstrip-1a-fat.a" \
 +	"libstrip-1a-fat-s.a" \
 +	{{readelf -SW strip-1a-fat.rd}} \
 +    ] \
 +    [list \
 +	"strip" \
-+	"-R .gnu.*lto_* -N __gnu_lto_v1" \
++	"--strip-unneeded -R .gnu.*lto_* -N __gnu_lto_v1" \
 +	"strip-1a-fat.o" \
 +	"strip-1a-fat-s.o" \
 +	{{readelf -SW strip-1a-fat.rd}} \
 +    ] \
 +    [list \
 +	"strip" \
-+	"-R .gnu.lto_*" \
++	"--strip-unneeded -R .gnu.debuglto_*" \
++	"libstrip-1a-fat.a" \
++	"libstrip-1b-fat-s.a" \
++	{{readelf -SW strip-1b-fat.rd}} \
++    ] \
++    [list \
++	"strip" \
++	"--strip-unneeded -R .gnu.debuglto_*" \
 +	"strip-1a-fat.o" \
 +	"strip-1b-fat-s.o" \
 +	{{readelf -SW strip-1b-fat.rd}} \
@@ -584,7 +603,7 @@ index 00000000000..aeb03ea8326
 +
 +run_cc_link_tests [list \
 +    [list \
-+	"Build strip-1a" \
++	"Build strip-1a (strip-1a.o)" \
 +	"" \
 +	"-O2 -flto $lto_no_fat" \
 +	{ strip-1b.c } \
@@ -594,7 +613,7 @@ index 00000000000..aeb03ea8326
 +	"tmpdir/strip-1a.o" \
 +    ] \
 +    [list \
-+	"Build strip-1b" \
++	"Build strip-1b (strip-1a-s.o)" \
 +	"" \
 +	"-O2 -flto $lto_no_fat" \
 +	{ strip-1b.c } \
@@ -604,7 +623,7 @@ index 00000000000..aeb03ea8326
 +	"tmpdir/strip-1a-s.o" \
 +    ] \
 +    [list \
-+	"Build strip-1c" \
++	"Build strip-1c (libstrip-1a.a)" \
 +	"" \
 +	"-O2 -flto $lto_no_fat" \
 +	{ strip-1b.c } \
@@ -614,7 +633,7 @@ index 00000000000..aeb03ea8326
 +	"tmpdir/libstrip-1a.a" \
 +    ] \
 +    [list \
-+	"Build strip-1d" \
++	"Build strip-1d (libstrip-1a-s.a)" \
 +	"" \
 +	"-O2 -flto $lto_no_fat" \
 +	{ strip-1b.c } \
@@ -624,25 +643,45 @@ index 00000000000..aeb03ea8326
 +	"tmpdir/libstrip-1a-s.a" \
 +    ] \
 +    [list \
-+	"Build strip-1e" \
++	"Build strip-1e (strip-1a-fat-s.o)" \
 +	"" \
 +	"-O2 -flto $lto_fat" \
 +	{ strip-1b-fat.c } \
 +	{} \
-+	"libstrip-1b" \
++	"libstrip-1e" \
 +	"C" \
 +	"tmpdir/strip-1a-fat-s.o" \
 +    ] \
 +    [list \
 +	"Build strip-1f" \
 +	"" \
-+	"-O2 -flto $lto_fat" \
++	"-O2 -flto $lto_fat (libstrip-1a-fat-s.a)" \
 +	{ strip-1b-fat.c } \
 +	{} \
-+	"libstrip-1d" \
++	"libstrip-1f" \
 +	"C" \
 +	"tmpdir/libstrip-1a-fat-s.a" \
 +    ] \
++    [list \
++	"Build strip-1g (strip-1b-fat-s.o)" \
++	"" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1b-fat.c } \
++	{} \
++	"libstrip-1g" \
++	"C" \
++	"tmpdir/strip-1b-fat-s.o" \
++    ] \
++    [list \
++	"Build strip-1h (libstrip-1b-fat-s.a)" \
++	"" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1b-fat.c } \
++	{} \
++	"libstrip-1h" \
++	"C" \
++	"tmpdir/libstrip-1b-fat-s.a" \
++    ] \
 +]
 diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.c b/ld/testsuite/ld-plugin/strip-1a-fat.c
 new file mode 100644


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-05-04 10:15 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-05-04 10:15 UTC (permalink / raw
  To: gentoo-commits

commit:     dbbd30a6cf0ba45b316f11a01f25428230fe2768
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sun May  4 10:14:41 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun May  4 10:14:41 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=dbbd30a6

9999: add H.J.'s patch for strip --plugin

Bug: https://sourceware.org/PR21479
Bug: https://bugs.gentoo.org/866422
Bug: https://bugs.gentoo.org/926120
Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-strip-lto-plugin.patch | 751 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 751 insertions(+)

diff --git a/9999/0006-strip-lto-plugin.patch b/9999/0006-strip-lto-plugin.patch
new file mode 100644
index 0000000..962be2d
--- /dev/null
+++ b/9999/0006-strip-lto-plugin.patch
@@ -0,0 +1,751 @@
+https://bugs.gentoo.org/866422
+https://sourceware.org/bugzilla/show_bug.cgi?id=21479#c10
+
+From 245176a7d6a92ab5283887a28a375c47585e41ee Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sun, 4 May 2025 05:12:46 +0800
+Subject: [PATCH] strip: Add LTO IR support
+
+Add LTO IR support to strip by copying LTO IR input as unknown object
+file.  Don't enable LTO plugin in strip unless all LTO sections should
+be removed.  Add linker LTO tests for strip with --strip-unneeded and
+removing all LTO section.
+
+binutils/
+
+	PR binutils/21479
+	* objcopy.c: Include "plugin-api.h" and "plugin.h".
+	(lto_sections_removed): New.
+	(command_line_switch): Add OPTION_PLUGIN.
+	(strip_options): Likewise.
+	(strip_usage): Display "--plugin NAME".
+	(copy_unknown_file): New function.
+	(copy_unknown_object): Call copy_unknown_file.
+	(copy_archive): Copy input LTO IR member as unknown object.
+	(copy_file): Set input target to "plugin" for strip if it is
+	unset unless all LTO sections should be removed.  Copy input
+	LTO IR file as unknown file.
+	(strip_main): Call bfd_plugin_set_program_name. Handle
+	OPTION_PLUGIN.  Set lto_sections_removed to true if all GCC
+	LTO sections should be removed.
+	* doc/binutils.texi: Document --plugin for strip.
+
+ld/
+
+	PR binutils/21479
+	* testsuite/ld-plugin/lto-binutils.exp: New file.
+	* testsuite/ld-plugin/strip-1a-fat.c: Likewise.
+	* testsuite/ld-plugin/strip-1a-fat.rd: Likewise.
+	* testsuite/ld-plugin/strip-1b-fat.c: Likewise.
+	* testsuite/ld-plugin/strip-1b-fat.rd: Likewise.
+	* testsuite/ld-plugin/strip-1a.c: Likewise.
+	* testsuite/ld-plugin/strip-1b.c: Likewise.
+	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Add optional
+	trailing ld options.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ binutils/doc/binutils.texi              |  21 ++
+ binutils/objcopy.c                      | 130 +++++++++--
+ ld/testsuite/ld-plugin/lto-binutils.exp | 292 ++++++++++++++++++++++++
+ ld/testsuite/ld-plugin/strip-1a-fat.c   |   1 +
+ ld/testsuite/ld-plugin/strip-1a-fat.rd  |   6 +
+ ld/testsuite/ld-plugin/strip-1a.c       |   4 +
+ ld/testsuite/ld-plugin/strip-1b-fat.c   |   1 +
+ ld/testsuite/ld-plugin/strip-1b-fat.rd  |   5 +
+ ld/testsuite/ld-plugin/strip-1b.c       |   3 +
+ ld/testsuite/lib/ld-lib.exp             |   9 +-
+ 10 files changed, 446 insertions(+), 26 deletions(-)
+ create mode 100644 ld/testsuite/ld-plugin/lto-binutils.exp
+ create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.c
+ create mode 100644 ld/testsuite/ld-plugin/strip-1a-fat.rd
+ create mode 100644 ld/testsuite/ld-plugin/strip-1a.c
+ create mode 100644 ld/testsuite/ld-plugin/strip-1b-fat.c
+ create mode 100644 ld/testsuite/ld-plugin/strip-1b-fat.rd
+ create mode 100644 ld/testsuite/ld-plugin/strip-1b.c
+
+diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
+index c74526e929a..05a10d20924 100644
+--- a/binutils/doc/binutils.texi
++++ b/binutils/doc/binutils.texi
+@@ -3566,6 +3566,7 @@ strip [@option{-F} @var{bfdname} |@option{--target=}@var{bfdname}]
+       [@option{--keep-section-symbols}]
+       [@option{--keep-file-symbols}]
+       [@option{--only-keep-debug}]
++      [@option{--plugin} @var{name}]
+       [@option{-v} |@option{--verbose}] [@option{-V}|@option{--version}]
+       [@option{--help}] [@option{--info}]
+       @var{objfile}@dots{}
+@@ -3825,6 +3826,26 @@ currently only supports the presence of one filename containing
+ debugging information, not multiple filenames on a one-per-object-file
+ basis.
+ 
++@item --plugin @var{name}
++@cindex plugins
++Load the plugin called @var{name} to add support for extra target
++types.  This option is only available if the toolchain has been built
++with plugin support enabled.
++
++If @option{--plugin} is not provided, but plugin support has been
++enabled then @command{strip} iterates over the files in
++@file{$@{libdir@}/bfd-plugins} in alphabetic order and the first
++plugin that claims the object in question is used.
++
++Please note that this plugin search directory is @emph{not} the one
++used by @command{ld}'s @option{-plugin} option.  In order to make
++@command{strip} use the  linker plugin it must be copied into the
++@file{$@{libdir@}/bfd-plugins} directory.  For GCC based compilations
++the linker plugin is called @file{liblto_plugin.so.0.0.0}.  For Clang
++based compilations it is called @file{LLVMgold.so}.  The GCC plugin
++is always backwards compatible with earlier versions, so it is
++sufficient to just copy the newest one.
++
+ @item -V
+ @itemx --version
+ Show the version number for @command{strip}.
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index 31933e13b7a..4990e6a7856 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -30,6 +30,8 @@
+ #include "coff/internal.h"
+ #include "libcoff.h"
+ #include "safe-ctype.h"
++#include "plugin-api.h"
++#include "plugin.h"
+ 
+ /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
+    header in generic PE code.  */
+@@ -165,6 +167,9 @@ static struct section_list *change_sections;
+ /* TRUE if some sections are to be removed.  */
+ static bool sections_removed;
+ 
++/* TRUE if all GCC LTO sections are to be removed.  */
++static bool lto_sections_removed;
++
+ /* TRUE if only some sections are to be copied.  */
+ static bool sections_copied;
+ 
+@@ -359,6 +364,7 @@ enum command_line_switch
+   OPTION_RENAME_SECTION,
+   OPTION_REVERSE_BYTES,
+   OPTION_PE_SECTION_ALIGNMENT,
++  OPTION_PLUGIN,
+   OPTION_SET_SECTION_FLAGS,
+   OPTION_SET_SECTION_ALIGNMENT,
+   OPTION_SET_START,
+@@ -402,6 +408,7 @@ static struct option strip_options[] =
+   {"output-file", required_argument, 0, 'o'},
+   {"output-format", required_argument, 0, 'O'},	/* Obsolete */
+   {"output-target", required_argument, 0, 'O'},
++  {"plugin", required_argument, 0, OPTION_PLUGIN},
+   {"preserve-dates", no_argument, 0, 'p'},
+   {"remove-section", required_argument, 0, 'R'},
+   {"remove-relocations", required_argument, 0, OPTION_REMOVE_RELOCS},
+@@ -758,6 +765,10 @@ strip_usage (FILE *stream, int exit_status)
+      --info                        List object formats & architectures supported\n\
+   -o <file>                        Place stripped output into <file>\n\
+ "));
++#if BFD_SUPPORTS_PLUGINS
++  fprintf (stream, _("\
++      --plugin NAME                Load the specified plugin\n"));
++#endif
+ 
+   list_supported_targets (program_name, stream);
+   if (REPORT_BUGS_TO[0] && exit_status == 0)
+@@ -1916,20 +1927,11 @@ add_redefine_syms_file (const char *filename)
+    Returns TRUE upon success, FALSE otherwise.  */
+ 
+ static bool
+-copy_unknown_object (bfd *ibfd, bfd *obfd)
++copy_unknown_file (bfd *ibfd, bfd *obfd, off_t size, unsigned int mode)
+ {
+   char *cbuf;
+   bfd_size_type tocopy;
+-  off_t size;
+-  struct stat buf;
+-
+-  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
+-    {
+-      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
+-      return false;
+-    }
+ 
+-  size = buf.st_size;
+   if (size < 0)
+     {
+       non_fatal (_("stat returns negative size for `%s'"),
+@@ -1974,11 +1976,40 @@ copy_unknown_object (bfd *ibfd, bfd *obfd)
+ 
+   /* We should at least to be able to read it back when copying an
+      unknown object in an archive.  */
+-  chmod (bfd_get_filename (obfd), buf.st_mode | S_IRUSR);
++  chmod (bfd_get_filename (obfd), mode | S_IRUSR);
+   free (cbuf);
+   return true;
+ }
+ 
++/* Copy unknown object file archive member IBFD onto OBFD.
++   Returns TRUE upon success, FALSE otherwise.  */
++
++static bool
++copy_unknown_object (bfd *ibfd, bfd *obfd)
++{
++  off_t size;
++  struct stat buf;
++
++  if (bfd_stat_arch_elt (ibfd, &buf) != 0)
++    {
++      bfd_nonfatal_message (NULL, ibfd, NULL, NULL);
++      return false;
++    }
++
++  size = buf.st_size;
++  if (size < 0)
++    {
++      non_fatal (_("stat returns negative size for `%s'"),
++		 bfd_get_archive_filename (ibfd));
++      return false;
++    }
++
++  if (!copy_unknown_file (ibfd, obfd, size, buf.st_mode))
++    return false;
++
++  return true;
++}
++
+ typedef struct objcopy_internal_note
+ {
+   Elf_Internal_Note  note;
+@@ -3744,7 +3775,10 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
+ 	  goto cleanup_and_exit;
+ 	}
+ 
+-      if (ok_object)
++      /* Copy LTO IR file as unknown object.  */
++      if (bfd_plugin_target_p (ibfd->xvec))
++	ok_object = false;
++      else if (ok_object)
+ 	{
+ 	  ok = copy_object (this_element, output_element, input_arch);
+ 
+@@ -3845,6 +3879,7 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+   char **obj_matching;
+   char **core_matching;
+   off_t size = get_file_size (input_filename);
++  const char *target = input_target;
+ 
+   if (size < 1)
+     {
+@@ -3855,9 +3890,16 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+       return;
+     }
+ 
++#if BFD_SUPPORTS_PLUGINS
++  /* Enable LTO plugin in strip unless all LTO sections should be
++     removed.  */
++  if (is_strip && !target && !lto_sections_removed)
++    target = "plugin";
++#endif
++
+   /* To allow us to do "strip *" without dying on the first
+      non-object file, failures are nonfatal.  */
+-  ibfd = bfd_openr (input_filename, input_target);
++  ibfd = bfd_openr (input_filename, target);
+   if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
+     {
+       bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+@@ -3974,17 +4016,29 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
+  	  return;
+  	}
+ 
+-      if (! copy_object (ibfd, obfd, input_arch))
+-	status = 1;
+-
+-      /* PR 17512: file: 0f15796a.
+-	 If the file could not be copied it may not be in a writeable
+-	 state.  So use bfd_close_all_done to avoid the possibility of
+-	 writing uninitialised data into the file.  */
+-      if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
++      if (bfd_plugin_target_p (ibfd->xvec))
+ 	{
+-	  status = 1;
+-	  bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
++	  /* Copy LTO IR file as unknown file.  */
++	  if (!copy_unknown_file (ibfd, obfd, in_stat->st_size,
++				  in_stat->st_mode))
++	    status = 1;
++	  else if (!bfd_close_all_done (obfd))
++	    status = 1;
++	}
++      else
++	{
++	  if (! copy_object (ibfd, obfd, input_arch))
++	    status = 1;
++
++	  /* PR 17512: file: 0f15796a.
++	     If the file could not be copied it may not be in a writeable
++	     state.  So use bfd_close_all_done to avoid the possibility of
++	     writing uninitialised data into the file.  */
++	  if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd)))
++	    {
++	      status = 1;
++	      bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
++	    }
+ 	}
+ 
+       if (!bfd_close (ibfd))
+@@ -4837,6 +4891,17 @@ strip_main (int argc, char *argv[])
+   char *output_file = NULL;
+   bool merge_notes_set = false;
+ 
++#if BFD_SUPPORTS_PLUGINS
++  /* All GCC LTO section prefixes.  */
++  const char *GCC_LTO_sections[] =
++    {
++      ".gnu.debuglto_.",
++      ".gnu.lto_."
++    };
++
++  bfd_plugin_set_program_name (argv[0]);
++#endif
++
+   while ((c = getopt_long (argc, argv, "I:O:F:K:MN:R:o:sSpdgxXHhVvwDU",
+ 			   strip_options, (int *) 0)) != EOF)
+     {
+@@ -4927,6 +4992,13 @@ strip_main (int argc, char *argv[])
+ 	case OPTION_KEEP_SECTION_SYMBOLS:
+ 	  keep_section_symbols = true;
+ 	  break;
++	case OPTION_PLUGIN:	/* --plugin */
++#if BFD_SUPPORTS_PLUGINS
++	  bfd_plugin_set_plugin (optarg);
++#else
++	  fatal (_("sorry - this program has been built without plugin support\n"));
++#endif
++	  break;
+ 	case 0:
+ 	  /* We've been given a long option.  */
+ 	  break;
+@@ -4971,6 +5043,18 @@ strip_main (int argc, char *argv[])
+   if (output_target == NULL)
+     output_target = input_target;
+ 
++#if BFD_SUPPORTS_PLUGINS
++  /* Check if all GCC LTO sections should be removed.  */
++  lto_sections_removed = true;
++  for (i = 0; i < (int) ARRAY_SIZE (GCC_LTO_sections); i++)
++    if (!find_section_list (GCC_LTO_sections[i], false,
++			    SECTION_CONTEXT_REMOVE))
++      {
++	lto_sections_removed = false;
++	break;
++      }
++#endif
++
+   i = optind;
+   if (i == argc
+       || (output_file != NULL && (i + 1) < argc))
+diff --git a/ld/testsuite/ld-plugin/lto-binutils.exp b/ld/testsuite/ld-plugin/lto-binutils.exp
+new file mode 100644
+index 00000000000..aeb03ea8326
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-binutils.exp
+@@ -0,0 +1,292 @@
++# Expect script for binutils tests with LTO
++# Copyright (C) 2025 Free Software Foundation, Inc.
++#
++# This file is part of the GNU Binutils.
++#
++# This program is free software; you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation; either version 3 of the License, or
++# (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
++# MA 02110-1301, USA.
++#
++
++# Make sure that binutils can correctly handle LTO IR in ELF.
++
++if { !([istarget *-*-linux*]
++       || [istarget arm*-*-uclinuxfdpiceabi]
++       || [istarget *-*-nacl*]
++       || [istarget *-*-gnu*]) || [istarget *ecoff] } then {
++    return
++}
++
++# Check to see if the C and C++ compilers work
++if { ![check_compiler_available] || [which $CXX_FOR_TARGET] == 0 } {
++    return
++}
++
++# These tests require plugin and LTO.
++if { ![check_plugin_api_available]
++     || ![check_lto_available] } {
++    return
++}
++
++set lto_fat ""
++set lto_no_fat ""
++if { [check_lto_fat_available] } {
++  set lto_fat "-ffat-lto-objects"
++  set lto_no_fat "-fno-fat-lto-objects"
++  set no_lto "-fno-lto"
++}
++
++set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
++
++# List contains test-items:
++#  0:program name
++#  1:program options
++#  2:input file
++#  3:output file
++#  4:action list (optional)
++#
++proc lto_binutils_test { lto_tests } {
++    global srcdir
++    global subdir
++    global nm
++    global objcopy
++    global objdump
++    global READELF
++    global strip
++    global lto_plugin
++
++    foreach testitem $lto_tests {
++	set prog_name [lindex $testitem 0]
++	set prog_options [lindex $testitem 1]
++	set input tmpdir/[lindex $testitem 2]
++	set output tmpdir/[lindex $testitem 3]
++	set actions [lindex $testitem 4]
++	set objfiles {}
++	set failed 0
++
++	# Don't leave previous output around
++	if { $output ne "tmpdir/" } {
++	    remote_file host delete $output
++	}
++
++	eval set prog \$$prog_name
++
++	append prog_options " --plugin $lto_plugin"
++
++	set test_name "$prog_name $prog_options ($input)"
++
++	set cmd "$prog $prog_options -o $output $input"
++	send_log "$cmd\n"
++	set got [remote_exec host "$cmd"]
++	if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
++	    send_log "$got\n"
++	    fail "$test_name"
++	    continue
++	}
++
++	if { $failed == 0 } {
++	    foreach actionlist $actions {
++		set action [lindex $actionlist 0]
++		set progopts [lindex $actionlist 1]
++
++		# There are actions where we run regexp_diff on the
++		# output, and there are other actions (presumably).
++		# Handling of the former look the same.
++		set dump_prog ""
++		switch -- $action {
++		    objdump
++			{ set dump_prog $objdump }
++		    nm
++			{ set dump_prog $nm }
++		    readelf
++			{ set dump_prog $READELF }
++		    default
++			{
++			    perror "Unrecognized action $action"
++			    set is_unresolved 1
++			    break
++			}
++		    }
++
++		if { $dump_prog != "" } {
++		    set dumpfile [lindex $actionlist 2]
++		    set binary $dump_prog
++
++		    # Ensure consistent sorting of symbols
++		    if {[info exists env(LC_ALL)]} {
++			set old_lc_all $env(LC_ALL)
++		    }
++		    set env(LC_ALL) "C"
++		    set cmd "$binary $progopts $output > tmpdir/dump.out"
++		    send_log "$cmd\n"
++		    catch "exec $cmd" comp_output
++		    if {[info exists old_lc_all]} {
++			set env(LC_ALL) $old_lc_all
++		    } else {
++			unset env(LC_ALL)
++		    }
++		    set comp_output [prune_warnings $comp_output]
++
++		    if ![string match "" $comp_output] then {
++			send_log "$comp_output\n"
++			set failed 1
++			break
++		    }
++
++		    if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/$dumpfile"] } then {
++			verbose -log "output is [file_contents "tmpdir/dump.out"]" 2
++			set failed 1
++			break
++		    }
++		}
++	    }
++	}
++
++	if { $failed } {
++	    fail $test_name
++	} else {
++	    pass $test_name
++	}
++    }
++}
++
++run_cc_link_tests [list \
++    [list \
++	"Build strip-1a.o" \
++	"" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1a.c } \
++    ] \
++    [list \
++	"Build libstrip-1a.a" \
++	"--plugin $lto_plugin" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1a.c } \
++	{} \
++	"libstrip-1a.a" \
++    ] \
++    [list \
++	"Build strip-1a-fat.o" \
++	"" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1a-fat.c } \
++    ] \
++    [list \
++	"Build libstrip-1a-fat.a" \
++	"--plugin $lto_plugin" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1a-fat.c } \
++	{} \
++	"libstrip-1a-fat.a" \
++    ] \
++]
++
++lto_binutils_test [list \
++    [list \
++	"strip" \
++	"--strip-unneeded" \
++	"libstrip-1a.a" \
++	"libstrip-1a-s.a" \
++    ] \
++    [list \
++	"strip" \
++	"--strip-unneeded" \
++	"strip-1a.o" \
++	"strip-1a-s.o" \
++    ] \
++    [list \
++	"strip" \
++	"-R .gnu.*lto_* -N __gnu_lto_v1" \
++	"libstrip-1a-fat.a" \
++	"libstrip-1a-fat-s.a" \
++	{{readelf -SW strip-1a-fat.rd}} \
++    ] \
++    [list \
++	"strip" \
++	"-R .gnu.*lto_* -N __gnu_lto_v1" \
++	"strip-1a-fat.o" \
++	"strip-1a-fat-s.o" \
++	{{readelf -SW strip-1a-fat.rd}} \
++    ] \
++    [list \
++	"strip" \
++	"-R .gnu.lto_*" \
++	"strip-1a-fat.o" \
++	"strip-1b-fat-s.o" \
++	{{readelf -SW strip-1b-fat.rd}} \
++    ] \
++]
++
++run_cc_link_tests [list \
++    [list \
++	"Build strip-1a" \
++	"" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1b.c } \
++	{} \
++	"libstrip-1a" \
++	"C" \
++	"tmpdir/strip-1a.o" \
++    ] \
++    [list \
++	"Build strip-1b" \
++	"" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1b.c } \
++	{} \
++	"libstrip-1b" \
++	"C" \
++	"tmpdir/strip-1a-s.o" \
++    ] \
++    [list \
++	"Build strip-1c" \
++	"" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1b.c } \
++	{} \
++	"libstrip-1c" \
++	"C" \
++	"tmpdir/libstrip-1a.a" \
++    ] \
++    [list \
++	"Build strip-1d" \
++	"" \
++	"-O2 -flto $lto_no_fat" \
++	{ strip-1b.c } \
++	{} \
++	"libstrip-1d" \
++	"C" \
++	"tmpdir/libstrip-1a-s.a" \
++    ] \
++    [list \
++	"Build strip-1e" \
++	"" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1b-fat.c } \
++	{} \
++	"libstrip-1b" \
++	"C" \
++	"tmpdir/strip-1a-fat-s.o" \
++    ] \
++    [list \
++	"Build strip-1f" \
++	"" \
++	"-O2 -flto $lto_fat" \
++	{ strip-1b-fat.c } \
++	{} \
++	"libstrip-1d" \
++	"C" \
++	"tmpdir/libstrip-1a-fat-s.a" \
++    ] \
++]
+diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.c b/ld/testsuite/ld-plugin/strip-1a-fat.c
+new file mode 100644
+index 00000000000..03b2a5c2275
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1a-fat.c
+@@ -0,0 +1 @@
++#include "strip-1a.c"
+diff --git a/ld/testsuite/ld-plugin/strip-1a-fat.rd b/ld/testsuite/ld-plugin/strip-1a-fat.rd
+new file mode 100644
+index 00000000000..aefe1c55013
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1a-fat.rd
+@@ -0,0 +1,6 @@
++#failif
++#...
++Section Headers:
++#...
++  \[[ 0-9]+\] \.gnu.lto_.*
++#...
+diff --git a/ld/testsuite/ld-plugin/strip-1a.c b/ld/testsuite/ld-plugin/strip-1a.c
+new file mode 100644
+index 00000000000..d84af205338
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1a.c
+@@ -0,0 +1,4 @@
++extern void foo2(void);
++extern void foo3(void);
++void foo1(void) { foo3(); }
++int main(void) { foo2(); }
+diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.c b/ld/testsuite/ld-plugin/strip-1b-fat.c
+new file mode 100644
+index 00000000000..1a2e4d2d86a
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1b-fat.c
+@@ -0,0 +1 @@
++#include "strip-1b.c"
+diff --git a/ld/testsuite/ld-plugin/strip-1b-fat.rd b/ld/testsuite/ld-plugin/strip-1b-fat.rd
+new file mode 100644
+index 00000000000..e3a266f8bee
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1b-fat.rd
+@@ -0,0 +1,5 @@
++#...
++Section Headers:
++#...
++  \[[ 0-9]+\] \.gnu.lto_.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/strip-1b.c b/ld/testsuite/ld-plugin/strip-1b.c
+new file mode 100644
+index 00000000000..967872a0f12
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/strip-1b.c
+@@ -0,0 +1,3 @@
++extern void foo1(void);
++void foo2(void) { foo1(); }
++void foo3(void) {}
+diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
+index 96152718d6f..119410bc523 100644
+--- a/ld/testsuite/lib/ld-lib.exp
++++ b/ld/testsuite/lib/ld-lib.exp
+@@ -860,14 +860,15 @@ proc run_ld_link_exec_tests { ldtests args } {
+ }
+ 
+ # List contains test-items with 3 items followed by 2 lists, one item and
+-# one optional item:
++# 2 optional items:
+ #  0:name
+-#  1:ld or ar options
++#  1:leading ld or ar options
+ #  2:compile options
+ #  3:filenames of source files
+ #  4:action and options.
+ #  5:name of output file
+ #  6:language (optional)
++#  7:trailing ld options (optional), placed after object files
+ #
+ # Actions:
+ # objdump: Apply objdump options on result.  Compare with regex (last arg).
+@@ -899,6 +900,7 @@ proc run_cc_link_tests { ldtests } {
+ 	set actions [lindex $testitem 4]
+ 	set binfile tmpdir/[lindex $testitem 5]
+ 	set lang [lindex $testitem 6]
++	set trailing_ldflags [lindex $testitem 7]
+ 	set objfiles {}
+ 	set is_unresolved 0
+ 	set failed 0
+@@ -927,6 +929,7 @@ proc run_cc_link_tests { ldtests } {
+ 	#verbose -log "actions   is $actions"
+ 	#verbose -log "binfile   is $binfile"
+ 	#verbose -log "lang      is $lang"
++	#verbose -log "trailing_ldflags is $trailing_ldflags"
+ 
+ 	foreach actionlist $actions {
+ 	    set action [lindex $actionlist 0]
+@@ -1006,7 +1009,7 @@ proc run_cc_link_tests { ldtests } {
+ 		untested $testname
+ 		continue
+ 	    }
+-	    ld_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles"
++	    ld_link $cc_cmd $binfile "-L$srcdir/$subdir $ldflags $objfiles $trailing_ldflags"
+ 	    set ld_output "$exec_output"
+ 
+ 	    if { $check_ld(source) == "regexp" } then {
+-- 
+2.49.0


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-04-10 17:35 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-04-10 17:35 UTC (permalink / raw
  To: gentoo-commits

commit:     d942e7ae10ce3c8fd06e893c6ce01ccd1258e877
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 10 17:34:57 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Apr 10 17:34:57 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d942e7ae

9999: drop merged LTO patch

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-LTO-archive-member-only-for-the-earlier-.patch | 186 ---------------------
 1 file changed, 186 deletions(-)

diff --git a/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch b/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch
deleted file mode 100644
index 1eb52fc..0000000
--- a/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch
+++ /dev/null
@@ -1,186 +0,0 @@
-https://inbox.sourceware.org/binutils/20250408201002.383836-1-hjl.tools@gmail.com/
-
-From b6ccbf6faecf5e2d43d776fab90f0a5d673a2817 Mon Sep 17 00:00:00 2001
-Message-ID: <b6ccbf6faecf5e2d43d776fab90f0a5d673a2817.1744165403.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 8 Apr 2025 13:10:02 -0700
-Subject: [PATCH] ld: Skip the LTO archive member only for the earlier DSO
-
-commit 2707d55e539ef323dd14a1293e762bf3d9739ee7
-Author: Michael Matz <matz@suse.de>
-Date:   Mon Mar 31 15:57:08 2025 +0200
-
-skipped the LTO archive member even when the earlier item is also an
-archive.  Instead, skip the LTO archive member only if the earlier item
-is a shared library.
-
-bfd/
-
-	PR ld/32846
-	PR ld/32854
-	* elflink.c (elf_link_add_archive_symbols): Skip the LTO archive
-	member only if the earlier item is a shared library.
-
-ld/
-
-	PR ld/32846
-	PR ld/32854
-	* testsuite/ld-plugin/lto.exp: Run ld/32846 test.
-	* testsuite/ld-plugin/pr32846a.c: New file.
-	* testsuite/ld-plugin/pr32846b.c: Likewise.
-	* testsuite/ld-plugin/pr32846c.c: Likewise.
-	* testsuite/ld-plugin/pr32846d.c: Likewise.
-	* testsuite/ld-plugin/pr32846e.c: Likewise.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/elflink.c                     |  8 +++++---
- ld/testsuite/ld-plugin/lto.exp    | 32 +++++++++++++++++++++++++++++++
- ld/testsuite/ld-plugin/pr32846a.c |  6 ++++++
- ld/testsuite/ld-plugin/pr32846b.c |  4 ++++
- ld/testsuite/ld-plugin/pr32846c.c |  6 ++++++
- ld/testsuite/ld-plugin/pr32846d.c | 12 ++++++++++++
- ld/testsuite/ld-plugin/pr32846e.c |  4 ++++
- 7 files changed, 69 insertions(+), 3 deletions(-)
- create mode 100644 ld/testsuite/ld-plugin/pr32846a.c
- create mode 100644 ld/testsuite/ld-plugin/pr32846b.c
- create mode 100644 ld/testsuite/ld-plugin/pr32846c.c
- create mode 100644 ld/testsuite/ld-plugin/pr32846d.c
- create mode 100644 ld/testsuite/ld-plugin/pr32846e.c
-
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index a76e8e38da7..2ac12144990 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -6290,8 +6290,8 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
- 		    continue;
- 
- 		  /* In the pre-LTO-plugin pass we must not mistakenly
--		     include this archive member if an earlier BFD
--		     defined this symbol.  */
-+		     include this archive member if an earlier shared
-+		     library defined this symbol.  */
- 		  struct elf_link_hash_table *htab = elf_hash_table (info);
- 		  if (htab->first_hash)
- 		    {
-@@ -6299,7 +6299,9 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
- 			  = ((struct elf_link_first_hash_entry *)
- 			     bfd_hash_lookup (htab->first_hash, symdef->name,
- 					      false, false));
--		      if (e && e->abfd != abfd)
-+		      if (e
-+			  && (e->abfd->flags & DYNAMIC) != 0
-+			  && e->abfd != abfd)
- 			continue;
- 		    }
- 		}
-diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
-index 93491902674..726dd933329 100644
---- a/ld/testsuite/ld-plugin/lto.exp
-+++ b/ld/testsuite/ld-plugin/lto.exp
-@@ -1212,6 +1212,38 @@ if { [is_elf_format] } {
- 
- if { [is_elf_format] && [check_lto_shared_available] } {
-     run_ld_link_exec_tests $lto_run_elf_shared_tests
-+    if { [check_lto_fat_available] } {
-+	run_cc_link_tests [list \
-+	    [list \
-+	    	"Build libpr32846a.a" \
-+	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
-+	    	{pr32846a.c pr32846b.c} {} "libpr32846a.a" \
-+	    ] \
-+	    [list \
-+		"Build libpr32846b.a" \
-+	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
-+		{pr32846a.c pr32846b.c pr32846c.c} {} "libpr32846b.a" \
-+	    ] \
-+	    [list \
-+	    	"Build pr32846d.o" \
-+	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
-+	    	{pr32846d.c} {} \
-+	    ] \
-+	    [list \
-+	    	"Build pr32846e.o" \
-+	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
-+	    	{pr32846e.c} {} \
-+	    ] \
-+	    [list \
-+		"Build pr32846" \
-+		"-shared -fPIC -O2 -flto $lto_no_fat -Wl,--no-undefined \
-+		 tmpdir/pr32846d.o tmpdir/libpr32846a.a \
-+		 tmpdir/libpr32846b.a tmpdir/pr32846e.o" \
-+		"-O2 -fPIC -flto $lto_no_fat" \
-+		{dummy.c} {} "pr32846" \
-+	    ] \
-+	] \
-+    }
- }
- 
- proc pr20103 {cflags libs} {
-diff --git a/ld/testsuite/ld-plugin/pr32846a.c b/ld/testsuite/ld-plugin/pr32846a.c
-new file mode 100644
-index 00000000000..8c161711bd9
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr32846a.c
-@@ -0,0 +1,6 @@
-+extern void mkdir_p (void);
-+void
-+mkdir_parents (void)
-+{
-+  mkdir_p ();
-+}
-diff --git a/ld/testsuite/ld-plugin/pr32846b.c b/ld/testsuite/ld-plugin/pr32846b.c
-new file mode 100644
-index 00000000000..9776a372d7a
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr32846b.c
-@@ -0,0 +1,4 @@
-+void
-+hash_new (void)
-+{
-+}
-diff --git a/ld/testsuite/ld-plugin/pr32846c.c b/ld/testsuite/ld-plugin/pr32846c.c
-new file mode 100644
-index 00000000000..f87cffb8865
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr32846c.c
-@@ -0,0 +1,6 @@
-+extern void hash_new (void);
-+void
-+kmod_new (void)
-+{
-+  hash_new();
-+}
-diff --git a/ld/testsuite/ld-plugin/pr32846d.c b/ld/testsuite/ld-plugin/pr32846d.c
-new file mode 100644
-index 00000000000..c6f41021adf
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr32846d.c
-@@ -0,0 +1,12 @@
-+extern void kmod_new (void);
-+extern void mkdir_parents (void);
-+void
-+do_lsmod (void)
-+{
-+  kmod_new ();
-+}
-+void
-+do_static_nodes (void)
-+{
-+  mkdir_parents();
-+}
-diff --git a/ld/testsuite/ld-plugin/pr32846e.c b/ld/testsuite/ld-plugin/pr32846e.c
-new file mode 100644
-index 00000000000..c4e5e56f4f6
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/pr32846e.c
-@@ -0,0 +1,4 @@
-+void
-+mkdir_p (void)
-+{
-+}
-
-base-commit: faaee6b411411f3c1f45768d7ac15559fd27b980
--- 
-2.49.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-04-09  2:24 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-04-09  2:24 UTC (permalink / raw
  To: gentoo-commits

commit:     d73d6d120ffc9ed75faca235ab07f831190075bd
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Apr  9 02:24:02 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Apr  9 02:24:02 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d73d6d12

9999: add H.J.'s fix for earlier revert

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...t-lto-Fix-symlookup-in-archives-vs-shared.patch | 168 -------------------
 ...-LTO-archive-member-only-for-the-earlier-.patch | 186 +++++++++++++++++++++
 2 files changed, 186 insertions(+), 168 deletions(-)

diff --git a/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch b/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch
deleted file mode 100644
index d8386fc..0000000
--- a/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch
+++ /dev/null
@@ -1,168 +0,0 @@
-From ba77d9675b2af359875bc5ef785616c18285060b Mon Sep 17 00:00:00 2001
-Message-ID: <ba77d9675b2af359875bc5ef785616c18285060b.1744072567.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Tue, 8 Apr 2025 01:35:58 +0100
-Subject: [PATCH] Revert "[lto] Fix symlookup in archives vs shared"
-
-This reverts commit 2707d55e539ef323dd14a1293e762bf3d9739ee7.
-
-Bug: https://sourceware.org/PR32846
----
- bfd/elflink.c                     | 44 +++++++------------------------
- ld/testsuite/ld-plugin/lto-20.ver |  1 -
- ld/testsuite/ld-plugin/lto-20a.c  |  2 --
- ld/testsuite/ld-plugin/lto-20b.c  | 11 --------
- ld/testsuite/ld-plugin/lto.exp    | 10 -------
- 5 files changed, 10 insertions(+), 58 deletions(-)
- delete mode 100644 ld/testsuite/ld-plugin/lto-20.ver
- delete mode 100644 ld/testsuite/ld-plugin/lto-20a.c
- delete mode 100644 ld/testsuite/ld-plugin/lto-20b.c
-
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index a76e8e38da7..13993527e3e 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -4965,7 +4965,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-       asection *sec, *new_sec;
-       flagword flags;
-       const char *name;
--      const char *defvername;
-       bool must_copy_name = false;
-       struct elf_link_hash_entry *h;
-       struct elf_link_hash_entry *hi;
-@@ -5142,7 +5141,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
-       old_alignment = 0;
-       old_bfd = NULL;
-       new_sec = sec;
--      defvername = NULL;
- 
-       if (is_elf_hash_table (&htab->root))
- 	{
-@@ -5261,7 +5259,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
- 		 default version of the symbol.  */
- 	      if ((iver.vs_vers & VERSYM_HIDDEN) == 0
- 		  && isym->st_shndx != SHN_UNDEF)
--		*p++ = ELF_VER_CHR, defvername = name;
-+		*p++ = ELF_VER_CHR;
- 	      memcpy (p, verstr, verlen + 1);
- 
- 	      name = newname;
-@@ -5711,15 +5709,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
- 		}
- 	      else if (dynamic
- 		       && h->root.u.def.section->owner == abfd)
--		{
--		  /* Add this symbol to first hash if this shared
--		     object has the first definition.  */
--		  elf_link_add_to_first_hash (abfd, info, name, must_copy_name);
--		  /* And if it was the default symbol version definition,
--		     also add the short name.  */
--		  if (defvername)
--		    elf_link_add_to_first_hash (abfd, info, defvername, false);
--		}
-+		/* Add this symbol to first hash if this shared
-+		   object has the first definition.  */
-+		elf_link_add_to_first_hash (abfd, info, name, must_copy_name);
- 	    }
- 	}
-     }
-@@ -6281,28 +6273,12 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
- 
- 	  if (h->type == bfd_link_hash_undefined)
- 	    {
--	      if (is_elf_hash_table (info->hash))
--		{
--		  /* If the archive element has already been loaded then one
--		     of the symbols defined by that element might have been
--		     made undefined due to being in a discarded section.  */
--		  if (((struct elf_link_hash_entry *) h)->indx == -3)
--		    continue;
--
--		  /* In the pre-LTO-plugin pass we must not mistakenly
--		     include this archive member if an earlier BFD
--		     defined this symbol.  */
--		  struct elf_link_hash_table *htab = elf_hash_table (info);
--		  if (htab->first_hash)
--		    {
--		      struct elf_link_first_hash_entry *e
--			  = ((struct elf_link_first_hash_entry *)
--			     bfd_hash_lookup (htab->first_hash, symdef->name,
--					      false, false));
--		      if (e && e->abfd != abfd)
--			continue;
--		    }
--		}
-+	      /* If the archive element has already been loaded then one
-+		 of the symbols defined by that element might have been
-+		 made undefined due to being in a discarded section.  */
-+	      if (is_elf_hash_table (info->hash)
-+		  && ((struct elf_link_hash_entry *) h)->indx == -3)
-+		continue;
- 	    }
- 	  else if (h->type == bfd_link_hash_common)
- 	    {
-diff --git a/ld/testsuite/ld-plugin/lto-20.ver b/ld/testsuite/ld-plugin/lto-20.ver
-deleted file mode 100644
-index ac906ac4ad1..00000000000
---- a/ld/testsuite/ld-plugin/lto-20.ver
-+++ /dev/null
-@@ -1 +0,0 @@
--FOO { global: foo; };
-diff --git a/ld/testsuite/ld-plugin/lto-20a.c b/ld/testsuite/ld-plugin/lto-20a.c
-deleted file mode 100644
-index 3d6dac96752..00000000000
---- a/ld/testsuite/ld-plugin/lto-20a.c
-+++ /dev/null
-@@ -1,2 +0,0 @@
--extern int foo ();
--int main () { return foo (); }
-diff --git a/ld/testsuite/ld-plugin/lto-20b.c b/ld/testsuite/ld-plugin/lto-20b.c
-deleted file mode 100644
-index ba123cbe38b..00000000000
---- a/ld/testsuite/ld-plugin/lto-20b.c
-+++ /dev/null
-@@ -1,11 +0,0 @@
--extern int printf (const char *, ...);
--int foo ()
--{
--#ifdef SHARED
--    printf ("PASS\n");
--    return 0;
--#else
--    printf ("FAIL\n");
--    return 1;
--#endif
--}
-diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
-index 93491902674..556bbe9beea 100644
---- a/ld/testsuite/ld-plugin/lto.exp
-+++ b/ld/testsuite/ld-plugin/lto.exp
-@@ -477,12 +477,6 @@ set lto_link_elf_tests [list \
-   [list {liblto-19.so} \
-    {-shared tmpdir/lto-19b.o tmpdir/liblto-19.a} {-O2 -fPIC} \
-    {dummy.c} {} {liblto-19.so}] \
--  [list {liblto-20_static.a} \
--   {} {-fPIC} \
--   {lto-20b.c} {} {liblto-20_static.a}] \
--  [list {liblto-20.so} \
--   {-shared -Wl,--version-script=lto-20.ver} {-DSHARED -fPIC} \
--   {lto-20b.c} {} {liblto-20.so}] \
-   [list {pr26806.so} \
-    {-shared} {-fpic -O2 -flto} \
-    {pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
-@@ -886,10 +880,6 @@ set lto_run_elf_shared_tests [list \
-    {-Wl,--as-needed,-R,tmpdir} {} \
-    {lto-19c.c} {lto-19.exe} {pass.out} {-flto -O2} {c} {} \
-    {tmpdir/liblto-19.so tmpdir/liblto-19.a}] \
--  [list {lto-20} \
--   {-Wl,--as-needed,-R,tmpdir} {} \
--   {lto-20a.c} {lto-20.exe} {pass.out} {-flto} {c} {} \
--   {tmpdir/liblto-20.so tmpdir/liblto-20_static.a -Wl,--no-as-needed}] \
-   [list {pr31482a} \
-    {-Wl,--no-as-needed,-R,tmpdir} {} \
-    {pr31482a.c} {pr31482a.exe} {pass.out} {-flto} {c} {} \
-
-base-commit: 2707d55e539ef323dd14a1293e762bf3d9739ee7
--- 
-2.49.0
-

diff --git a/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch b/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch
new file mode 100644
index 0000000..1eb52fc
--- /dev/null
+++ b/9999/0006-ld-Skip-the-LTO-archive-member-only-for-the-earlier-.patch
@@ -0,0 +1,186 @@
+https://inbox.sourceware.org/binutils/20250408201002.383836-1-hjl.tools@gmail.com/
+
+From b6ccbf6faecf5e2d43d776fab90f0a5d673a2817 Mon Sep 17 00:00:00 2001
+Message-ID: <b6ccbf6faecf5e2d43d776fab90f0a5d673a2817.1744165403.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 8 Apr 2025 13:10:02 -0700
+Subject: [PATCH] ld: Skip the LTO archive member only for the earlier DSO
+
+commit 2707d55e539ef323dd14a1293e762bf3d9739ee7
+Author: Michael Matz <matz@suse.de>
+Date:   Mon Mar 31 15:57:08 2025 +0200
+
+skipped the LTO archive member even when the earlier item is also an
+archive.  Instead, skip the LTO archive member only if the earlier item
+is a shared library.
+
+bfd/
+
+	PR ld/32846
+	PR ld/32854
+	* elflink.c (elf_link_add_archive_symbols): Skip the LTO archive
+	member only if the earlier item is a shared library.
+
+ld/
+
+	PR ld/32846
+	PR ld/32854
+	* testsuite/ld-plugin/lto.exp: Run ld/32846 test.
+	* testsuite/ld-plugin/pr32846a.c: New file.
+	* testsuite/ld-plugin/pr32846b.c: Likewise.
+	* testsuite/ld-plugin/pr32846c.c: Likewise.
+	* testsuite/ld-plugin/pr32846d.c: Likewise.
+	* testsuite/ld-plugin/pr32846e.c: Likewise.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/elflink.c                     |  8 +++++---
+ ld/testsuite/ld-plugin/lto.exp    | 32 +++++++++++++++++++++++++++++++
+ ld/testsuite/ld-plugin/pr32846a.c |  6 ++++++
+ ld/testsuite/ld-plugin/pr32846b.c |  4 ++++
+ ld/testsuite/ld-plugin/pr32846c.c |  6 ++++++
+ ld/testsuite/ld-plugin/pr32846d.c | 12 ++++++++++++
+ ld/testsuite/ld-plugin/pr32846e.c |  4 ++++
+ 7 files changed, 69 insertions(+), 3 deletions(-)
+ create mode 100644 ld/testsuite/ld-plugin/pr32846a.c
+ create mode 100644 ld/testsuite/ld-plugin/pr32846b.c
+ create mode 100644 ld/testsuite/ld-plugin/pr32846c.c
+ create mode 100644 ld/testsuite/ld-plugin/pr32846d.c
+ create mode 100644 ld/testsuite/ld-plugin/pr32846e.c
+
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index a76e8e38da7..2ac12144990 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -6290,8 +6290,8 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
+ 		    continue;
+ 
+ 		  /* In the pre-LTO-plugin pass we must not mistakenly
+-		     include this archive member if an earlier BFD
+-		     defined this symbol.  */
++		     include this archive member if an earlier shared
++		     library defined this symbol.  */
+ 		  struct elf_link_hash_table *htab = elf_hash_table (info);
+ 		  if (htab->first_hash)
+ 		    {
+@@ -6299,7 +6299,9 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
+ 			  = ((struct elf_link_first_hash_entry *)
+ 			     bfd_hash_lookup (htab->first_hash, symdef->name,
+ 					      false, false));
+-		      if (e && e->abfd != abfd)
++		      if (e
++			  && (e->abfd->flags & DYNAMIC) != 0
++			  && e->abfd != abfd)
+ 			continue;
+ 		    }
+ 		}
+diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
+index 93491902674..726dd933329 100644
+--- a/ld/testsuite/ld-plugin/lto.exp
++++ b/ld/testsuite/ld-plugin/lto.exp
+@@ -1212,6 +1212,38 @@ if { [is_elf_format] } {
+ 
+ if { [is_elf_format] && [check_lto_shared_available] } {
+     run_ld_link_exec_tests $lto_run_elf_shared_tests
++    if { [check_lto_fat_available] } {
++	run_cc_link_tests [list \
++	    [list \
++	    	"Build libpr32846a.a" \
++	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
++	    	{pr32846a.c pr32846b.c} {} "libpr32846a.a" \
++	    ] \
++	    [list \
++		"Build libpr32846b.a" \
++	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
++		{pr32846a.c pr32846b.c pr32846c.c} {} "libpr32846b.a" \
++	    ] \
++	    [list \
++	    	"Build pr32846d.o" \
++	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
++	    	{pr32846d.c} {} \
++	    ] \
++	    [list \
++	    	"Build pr32846e.o" \
++	    	"$plug_opt" "-O2 -flto $lto_no_fat" \
++	    	{pr32846e.c} {} \
++	    ] \
++	    [list \
++		"Build pr32846" \
++		"-shared -fPIC -O2 -flto $lto_no_fat -Wl,--no-undefined \
++		 tmpdir/pr32846d.o tmpdir/libpr32846a.a \
++		 tmpdir/libpr32846b.a tmpdir/pr32846e.o" \
++		"-O2 -fPIC -flto $lto_no_fat" \
++		{dummy.c} {} "pr32846" \
++	    ] \
++	] \
++    }
+ }
+ 
+ proc pr20103 {cflags libs} {
+diff --git a/ld/testsuite/ld-plugin/pr32846a.c b/ld/testsuite/ld-plugin/pr32846a.c
+new file mode 100644
+index 00000000000..8c161711bd9
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr32846a.c
+@@ -0,0 +1,6 @@
++extern void mkdir_p (void);
++void
++mkdir_parents (void)
++{
++  mkdir_p ();
++}
+diff --git a/ld/testsuite/ld-plugin/pr32846b.c b/ld/testsuite/ld-plugin/pr32846b.c
+new file mode 100644
+index 00000000000..9776a372d7a
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr32846b.c
+@@ -0,0 +1,4 @@
++void
++hash_new (void)
++{
++}
+diff --git a/ld/testsuite/ld-plugin/pr32846c.c b/ld/testsuite/ld-plugin/pr32846c.c
+new file mode 100644
+index 00000000000..f87cffb8865
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr32846c.c
+@@ -0,0 +1,6 @@
++extern void hash_new (void);
++void
++kmod_new (void)
++{
++  hash_new();
++}
+diff --git a/ld/testsuite/ld-plugin/pr32846d.c b/ld/testsuite/ld-plugin/pr32846d.c
+new file mode 100644
+index 00000000000..c6f41021adf
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr32846d.c
+@@ -0,0 +1,12 @@
++extern void kmod_new (void);
++extern void mkdir_parents (void);
++void
++do_lsmod (void)
++{
++  kmod_new ();
++}
++void
++do_static_nodes (void)
++{
++  mkdir_parents();
++}
+diff --git a/ld/testsuite/ld-plugin/pr32846e.c b/ld/testsuite/ld-plugin/pr32846e.c
+new file mode 100644
+index 00000000000..c4e5e56f4f6
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/pr32846e.c
+@@ -0,0 +1,4 @@
++void
++mkdir_p (void)
++{
++}
+
+base-commit: faaee6b411411f3c1f45768d7ac15559fd27b980
+-- 
+2.49.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-04-08  0:36 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-04-08  0:36 UTC (permalink / raw
  To: gentoo-commits

commit:     cc91de760c1833ebe917f073e4837c7664b3939a
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Apr  8 00:36:31 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Apr  8 00:36:31 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=cc91de76

9999: revert recent LTO patch

Bug: https://sourceware.org/PR32846
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...t-lto-Fix-symlookup-in-archives-vs-shared.patch | 168 +++++++++++++++++++++
 1 file changed, 168 insertions(+)

diff --git a/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch b/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch
new file mode 100644
index 0000000..d8386fc
--- /dev/null
+++ b/9999/0006-Revert-lto-Fix-symlookup-in-archives-vs-shared.patch
@@ -0,0 +1,168 @@
+From ba77d9675b2af359875bc5ef785616c18285060b Mon Sep 17 00:00:00 2001
+Message-ID: <ba77d9675b2af359875bc5ef785616c18285060b.1744072567.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Tue, 8 Apr 2025 01:35:58 +0100
+Subject: [PATCH] Revert "[lto] Fix symlookup in archives vs shared"
+
+This reverts commit 2707d55e539ef323dd14a1293e762bf3d9739ee7.
+
+Bug: https://sourceware.org/PR32846
+---
+ bfd/elflink.c                     | 44 +++++++------------------------
+ ld/testsuite/ld-plugin/lto-20.ver |  1 -
+ ld/testsuite/ld-plugin/lto-20a.c  |  2 --
+ ld/testsuite/ld-plugin/lto-20b.c  | 11 --------
+ ld/testsuite/ld-plugin/lto.exp    | 10 -------
+ 5 files changed, 10 insertions(+), 58 deletions(-)
+ delete mode 100644 ld/testsuite/ld-plugin/lto-20.ver
+ delete mode 100644 ld/testsuite/ld-plugin/lto-20a.c
+ delete mode 100644 ld/testsuite/ld-plugin/lto-20b.c
+
+diff --git a/bfd/elflink.c b/bfd/elflink.c
+index a76e8e38da7..13993527e3e 100644
+--- a/bfd/elflink.c
++++ b/bfd/elflink.c
+@@ -4965,7 +4965,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+       asection *sec, *new_sec;
+       flagword flags;
+       const char *name;
+-      const char *defvername;
+       bool must_copy_name = false;
+       struct elf_link_hash_entry *h;
+       struct elf_link_hash_entry *hi;
+@@ -5142,7 +5141,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+       old_alignment = 0;
+       old_bfd = NULL;
+       new_sec = sec;
+-      defvername = NULL;
+ 
+       if (is_elf_hash_table (&htab->root))
+ 	{
+@@ -5261,7 +5259,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 		 default version of the symbol.  */
+ 	      if ((iver.vs_vers & VERSYM_HIDDEN) == 0
+ 		  && isym->st_shndx != SHN_UNDEF)
+-		*p++ = ELF_VER_CHR, defvername = name;
++		*p++ = ELF_VER_CHR;
+ 	      memcpy (p, verstr, verlen + 1);
+ 
+ 	      name = newname;
+@@ -5711,15 +5709,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
+ 		}
+ 	      else if (dynamic
+ 		       && h->root.u.def.section->owner == abfd)
+-		{
+-		  /* Add this symbol to first hash if this shared
+-		     object has the first definition.  */
+-		  elf_link_add_to_first_hash (abfd, info, name, must_copy_name);
+-		  /* And if it was the default symbol version definition,
+-		     also add the short name.  */
+-		  if (defvername)
+-		    elf_link_add_to_first_hash (abfd, info, defvername, false);
+-		}
++		/* Add this symbol to first hash if this shared
++		   object has the first definition.  */
++		elf_link_add_to_first_hash (abfd, info, name, must_copy_name);
+ 	    }
+ 	}
+     }
+@@ -6281,28 +6273,12 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
+ 
+ 	  if (h->type == bfd_link_hash_undefined)
+ 	    {
+-	      if (is_elf_hash_table (info->hash))
+-		{
+-		  /* If the archive element has already been loaded then one
+-		     of the symbols defined by that element might have been
+-		     made undefined due to being in a discarded section.  */
+-		  if (((struct elf_link_hash_entry *) h)->indx == -3)
+-		    continue;
+-
+-		  /* In the pre-LTO-plugin pass we must not mistakenly
+-		     include this archive member if an earlier BFD
+-		     defined this symbol.  */
+-		  struct elf_link_hash_table *htab = elf_hash_table (info);
+-		  if (htab->first_hash)
+-		    {
+-		      struct elf_link_first_hash_entry *e
+-			  = ((struct elf_link_first_hash_entry *)
+-			     bfd_hash_lookup (htab->first_hash, symdef->name,
+-					      false, false));
+-		      if (e && e->abfd != abfd)
+-			continue;
+-		    }
+-		}
++	      /* If the archive element has already been loaded then one
++		 of the symbols defined by that element might have been
++		 made undefined due to being in a discarded section.  */
++	      if (is_elf_hash_table (info->hash)
++		  && ((struct elf_link_hash_entry *) h)->indx == -3)
++		continue;
+ 	    }
+ 	  else if (h->type == bfd_link_hash_common)
+ 	    {
+diff --git a/ld/testsuite/ld-plugin/lto-20.ver b/ld/testsuite/ld-plugin/lto-20.ver
+deleted file mode 100644
+index ac906ac4ad1..00000000000
+--- a/ld/testsuite/ld-plugin/lto-20.ver
++++ /dev/null
+@@ -1 +0,0 @@
+-FOO { global: foo; };
+diff --git a/ld/testsuite/ld-plugin/lto-20a.c b/ld/testsuite/ld-plugin/lto-20a.c
+deleted file mode 100644
+index 3d6dac96752..00000000000
+--- a/ld/testsuite/ld-plugin/lto-20a.c
++++ /dev/null
+@@ -1,2 +0,0 @@
+-extern int foo ();
+-int main () { return foo (); }
+diff --git a/ld/testsuite/ld-plugin/lto-20b.c b/ld/testsuite/ld-plugin/lto-20b.c
+deleted file mode 100644
+index ba123cbe38b..00000000000
+--- a/ld/testsuite/ld-plugin/lto-20b.c
++++ /dev/null
+@@ -1,11 +0,0 @@
+-extern int printf (const char *, ...);
+-int foo ()
+-{
+-#ifdef SHARED
+-    printf ("PASS\n");
+-    return 0;
+-#else
+-    printf ("FAIL\n");
+-    return 1;
+-#endif
+-}
+diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
+index 93491902674..556bbe9beea 100644
+--- a/ld/testsuite/ld-plugin/lto.exp
++++ b/ld/testsuite/ld-plugin/lto.exp
+@@ -477,12 +477,6 @@ set lto_link_elf_tests [list \
+   [list {liblto-19.so} \
+    {-shared tmpdir/lto-19b.o tmpdir/liblto-19.a} {-O2 -fPIC} \
+    {dummy.c} {} {liblto-19.so}] \
+-  [list {liblto-20_static.a} \
+-   {} {-fPIC} \
+-   {lto-20b.c} {} {liblto-20_static.a}] \
+-  [list {liblto-20.so} \
+-   {-shared -Wl,--version-script=lto-20.ver} {-DSHARED -fPIC} \
+-   {lto-20b.c} {} {liblto-20.so}] \
+   [list {pr26806.so} \
+    {-shared} {-fpic -O2 -flto} \
+    {pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
+@@ -886,10 +880,6 @@ set lto_run_elf_shared_tests [list \
+    {-Wl,--as-needed,-R,tmpdir} {} \
+    {lto-19c.c} {lto-19.exe} {pass.out} {-flto -O2} {c} {} \
+    {tmpdir/liblto-19.so tmpdir/liblto-19.a}] \
+-  [list {lto-20} \
+-   {-Wl,--as-needed,-R,tmpdir} {} \
+-   {lto-20a.c} {lto-20.exe} {pass.out} {-flto} {c} {} \
+-   {tmpdir/liblto-20.so tmpdir/liblto-20_static.a -Wl,--no-as-needed}] \
+   [list {pr31482a} \
+    {-Wl,--no-as-needed,-R,tmpdir} {} \
+    {pr31482a.c} {pr31482a.exe} {pass.out} {-flto} {c} {} \
+
+base-commit: 2707d55e539ef323dd14a1293e762bf3d9739ee7
+-- 
+2.49.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-03-29 14:18 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-03-29 14:18 UTC (permalink / raw
  To: gentoo-commits

commit:     7b411d4b9fc34eea8574162203faf93f4277e391
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 29 14:18:17 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Mar 29 14:18:28 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=7b411d4b

9999: drop -g hunks

Merged. This also drops the CFLAGS stuff for gprof but not going
to worry about that for now.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-Adjust-testsuites-for-flto-and-without-g.patch | 45 ----------------------
 1 file changed, 45 deletions(-)

diff --git a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
index 607e838..20a8c62 100644
--- a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
+++ b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
@@ -113,51 +113,6 @@ index a706efbba18..42a29927a5d 100644
  	untested $test
  	return
      }
-diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
-index c4d6c41fcf4..0c80b12e6e4 100644
---- a/gprof/testsuite/Makefile.am
-+++ b/gprof/testsuite/Makefile.am
-@@ -6,12 +6,12 @@ GPROF = ../gprof$(EXEEXT)
- 
- # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
- # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
--GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
-+# -g is needed for line number info checked by tst-gmon-gprof-l.sh.  See
-+# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
-+GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
- 
--COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
--	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
--LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
--	$(AM_LDFLAGS) $(LDFLAGS) -o $@
-+COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
-+LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
- 
- # We will add to these later, for each individual test.  Note
- # that we add each test under check_SCRIPTS;
-diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
-index 008f6be879e..2ac5f241012 100644
---- a/gprof/testsuite/Makefile.in
-+++ b/gprof/testsuite/Makefile.in
-@@ -496,13 +496,11 @@ GPROF = ../gprof$(EXEEXT)
- 
- # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
- # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
--GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
--COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
--	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
--
--LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
--	$(AM_LDFLAGS) $(LDFLAGS) -o $@
--
-+# -g is needed for line number info checked by tst-gmon-gprof-l.sh.  See
-+# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
-+GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
-+COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
-+LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
- 
- # We will add to these later, for each individual test.  Note
- # that we add each test under check_SCRIPTS;
 diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
 index c314f2995af..08b47d2db18 100644
 --- a/ld/testsuite/ld-ctf/ctf.exp


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-03-12 20:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-03-12 20:21 UTC (permalink / raw
  To: gentoo-commits

commit:     c61c48e5527b9027fc85b529b8d61fdf5c19920a
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 12 20:21:48 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Mar 12 20:21:48 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=c61c48e5

9999: add testsuite patch from H.J.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-Adjust-testsuites-for-flto-and-without-g.patch | 260 +++++++++++++++++++++
 1 file changed, 260 insertions(+)

diff --git a/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
new file mode 100644
index 0000000..607e838
--- /dev/null
+++ b/9999/0005-Adjust-testsuites-for-flto-and-without-g.patch
@@ -0,0 +1,260 @@
+From f22ea3e751a11ab8cfb5524468d97a998cca0325 Mon Sep 17 00:00:00 2001
+Message-ID: <f22ea3e751a11ab8cfb5524468d97a998cca0325.1741810888.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Mon, 10 Mar 2025 17:07:16 -0700
+Subject: [PATCH] Adjust testsuites for -flto and without -g
+
+Adjust testsuites for binutils built with -flto and without -g:
+
+1. Pass -fno-lto to objcopy tests which don't work with LTO.
+2. Update gprof testsuite to avoid LTO and compile with -g for line
+number info checked by tst-gmon-gprof-l.sh.
+3. Append $NOLTO_CFLAGS in ctf.exp.
+4. For libctf, filter out -flto in CFLAGS for "make check" and also
+prune lto-wrapper warnings.
+
+binutils/
+
+	PR binutils/32773
+	* testsuite/binutils-all/objcopy.exp (no_lto_flags): New.
+	(strip_test): Pass $no_lto_flags to target_compile.
+	(strip_test_with_saving_a_symbol): Likewise.
+	(objcopy_test_without_global_symbol): Likewise.
+
+gprof/
+
+	PR binutils/32773
+	PR gprof/32779
+	* testsuite/Makefile.am (GPROF_FLAGS): Add -g.
+	(COMPILE): Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS)".
+	(LINK) Set to "$(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS)
+	$(LDFLAGS) -o $@".
+	* testsuite/Makefile.in: Regenerated.
+
+ld/
+
+	PR binutils/32773
+	* testsuite/ld-ctf/ctf.exp (old_CFLAGS): New.
+	(CFLAGS_FOR_TARGET): Append $NOLTO_CFLAGS.
+
+libctf/
+
+	PR binutils/32773
+	* Makefile.am (check-DEJAGNU): Filter out -flto in CFLAGS.
+	* Makefile.in: Regenerated.
+	* testsuite/lib/ctf-lib.exp (prune_warnings_lto): New.
+	(run_lookup_test): Replace prune_warnings with
+	prune_warnings_lto.
+	(run_lookup_test): Likewise.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ binutils/testsuite/binutils-all/objcopy.exp | 14 +++++++++++---
+ gprof/testsuite/Makefile.am                 | 10 +++++-----
+ gprof/testsuite/Makefile.in                 | 12 +++++-------
+ ld/testsuite/ld-ctf/ctf.exp                 |  5 +++++
+ libctf/Makefile.am                          |  3 ++-
+ libctf/Makefile.in                          |  3 ++-
+ libctf/testsuite/lib/ctf-lib.exp            | 14 ++++++++++++--
+ 7 files changed, 42 insertions(+), 19 deletions(-)
+
+diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
+index a706efbba18..42a29927a5d 100644
+--- a/binutils/testsuite/binutils-all/objcopy.exp
++++ b/binutils/testsuite/binutils-all/objcopy.exp
+@@ -36,6 +36,11 @@ if ![is_remote host] {
+     set copyfile copy
+ }
+ 
++set no_lto_flags "additional_flags=-fno-lto"
++if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object $no_lto_flags] != "" } {
++    set no_lto_flags ""
++}
++
+ # Test that objcopy does not modify a file when copying it.
+ # "object" or "executable" values for type are supported.
+ 
+@@ -516,10 +521,11 @@ proc strip_test { } {
+     global srcdir
+     global subdir
+     global READELF
++    global no_lto_flags
+ 
+     set test "strip"
+ 
+-    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
++    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
+ 	untested $test
+ 	return
+     }
+@@ -628,10 +634,11 @@ proc strip_test_with_saving_a_symbol { } {
+     global NMFLAGS
+     global srcdir
+     global subdir
++    global no_lto_flags
+ 
+     set test "strip with saving a symbol"
+ 
+-    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
++    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object "debug $no_lto_flags"] != "" } {
+ 	untested $test
+ 	return
+     }
+@@ -1381,10 +1388,11 @@ proc objcopy_test_without_global_symbol { } {
+     global OBJDUMPFLAGS
+     global srcdir
+     global subdir
++    global no_lto_flags
+ 
+     set test "strip without global symbol "
+ 
+-    if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object debug] != "" } {
++    if { [target_compile $srcdir/$subdir/pr19547.c tmpdir/pr19547.o object "debug $no_lto_flags"] != "" } {
+ 	untested $test
+ 	return
+     }
+diff --git a/gprof/testsuite/Makefile.am b/gprof/testsuite/Makefile.am
+index c4d6c41fcf4..0c80b12e6e4 100644
+--- a/gprof/testsuite/Makefile.am
++++ b/gprof/testsuite/Makefile.am
+@@ -6,12 +6,12 @@ GPROF = ../gprof$(EXEEXT)
+ 
+ # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
+-GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
++# -g is needed for line number info checked by tst-gmon-gprof-l.sh.  See
++# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
++GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
+ 
+-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
+-LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
+-	$(AM_LDFLAGS) $(LDFLAGS) -o $@
++COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
++LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+ 
+ # We will add to these later, for each individual test.  Note
+ # that we add each test under check_SCRIPTS;
+diff --git a/gprof/testsuite/Makefile.in b/gprof/testsuite/Makefile.in
+index 008f6be879e..2ac5f241012 100644
+--- a/gprof/testsuite/Makefile.in
++++ b/gprof/testsuite/Makefile.in
+@@ -496,13 +496,11 @@ GPROF = ../gprof$(EXEEXT)
+ 
+ # NB: -O2 -fno-omit-frame-pointer is needed for expected call graph.  See
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=32768
+-GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg
+-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(GPROF_FLAGS)
+-
+-LINK = $(CC) $(AM_CFLAGS) $(CFLAGS) $(OPT_NO_PLUGINS) $(GPROF_FLAGS) \
+-	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+-
++# -g is needed for line number info checked by tst-gmon-gprof-l.sh.  See
++# https://sourceware.org/bugzilla/show_bug.cgi?id=32779
++GPROF_FLAGS = -O2 -fno-omit-frame-pointer -pg -g
++COMPILE = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS)
++LINK = $(CC) $(AM_CFLAGS) $(GPROF_FLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+ 
+ # We will add to these later, for each individual test.  Note
+ # that we add each test under check_SCRIPTS;
+diff --git a/ld/testsuite/ld-ctf/ctf.exp b/ld/testsuite/ld-ctf/ctf.exp
+index c314f2995af..08b47d2db18 100644
+--- a/ld/testsuite/ld-ctf/ctf.exp
++++ b/ld/testsuite/ld-ctf/ctf.exp
+@@ -33,6 +33,9 @@ if ![check_shared_lib_support] {
+     return 0
+ }
+ 
++set old_CFLAGS "$CFLAGS_FOR_TARGET"
++append CFLAGS_FOR_TARGET " $NOLTO_CFLAGS"
++
+ if {[info exists env(LC_ALL)]} {
+     set old_lc_all $env(LC_ALL)
+ }
+@@ -55,3 +58,5 @@ if {[info exists old_lc_all]} {
+ } else {
+     unset env(LC_ALL)
+ }
++
++set CFLAGS_FOR_TARGET "$old_CFLAGS"
+diff --git a/libctf/Makefile.am b/libctf/Makefile.am
+index 6e136220497..bf214d8a000 100644
+--- a/libctf/Makefile.am
++++ b/libctf/Makefile.am
+@@ -102,11 +102,12 @@ check-DEJAGNU: site.exp development.exp
+ 	else \
+ 	  TEST_CROSS=yes; \
+ 	fi; \
++	TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
+ 	runtest=$(RUNTEST); \
+ 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
+ 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
+ 		CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
+-		CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
++		CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
+ 		LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
+ 	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
+ 	fi
+diff --git a/libctf/Makefile.in b/libctf/Makefile.in
+index 5d9587766dc..e5bb94c681b 100644
+--- a/libctf/Makefile.in
++++ b/libctf/Makefile.in
+@@ -1819,11 +1819,12 @@ check-DEJAGNU: site.exp development.exp
+ 	else \
+ 	  TEST_CROSS=yes; \
+ 	fi; \
++	TEST_CFLAGS=`echo "$(CFLAGS)" | sed -e "s/-flto[^ \t]*//"`; \
+ 	runtest=$(RUNTEST); \
+ 	if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
+ 	  $$runtest --tool $(DEJATOOL) --srcdir $${srcroot}/testsuite \
+ 		CC="$(CC)" CC_FOR_TARGET="$(CC_FOR_TARGET)" TEST_CROSS="$${TEST_CROSS}" \
+-		CFLAGS="$(CFLAGS) -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
++		CFLAGS="$$TEST_CFLAGS -I$(INCDIR) -I$(srcdir) -I$(builddir) -I$(builddir)/../bfd $(ZLIBINC)" \
+ 		LIBS="$(libctf_nobfd_la_LIBADD) $(LIBS)" $(RUNTESTFLAGS); \
+ 	else echo "WARNING: could not find \`runtest'" 1>&2; :;\
+ 	fi
+diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp
+index 64d2a40ad9f..6d3b75e22a2 100644
+--- a/libctf/testsuite/lib/ctf-lib.exp
++++ b/libctf/testsuite/lib/ctf-lib.exp
+@@ -54,6 +54,16 @@ proc compile_link_one_host_cc { src output additional_args } {
+     return [run_native_host_cmd "./libtool --quiet --tag=CC --mode=link $CC $CFLAGS $src -o $output $additional_args" ]
+ }
+ 
++# Also prune lto-wrapper warnings, like
++# lto-wrapper: warning: using serial compilation of 16 LTRANS jobs
++# lto-wrapper: note: see the '-flto' option documentation for more information
++#
++proc prune_warnings_lto { msg } {
++    set msgx "lto-wrapper: (?:warning\:\[^\n\r\]+|note\:\[^\n\r\]+)"
++    regsub -all "$msgx\[\n\r\]*" $msg {} msg
++    return [prune_warnings $msg]
++}
++
+ # run_lookup_test FILE
+ #
+ # Compile with the host compiler and link a .c file into a "lookup" binary, then
+@@ -208,7 +218,7 @@ proc run_lookup_test { name } {
+     set testname $file4log
+ 
+     # Compile and link the lookup program.
+-    set comp_output [prune_warnings [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
++    set comp_output [prune_warnings_lto [compile_link_one_host_cc $opts(lookup) "tmpdir/lookup" "libctf.la $opts(lookup_link)"]]
+ 
+     if { $comp_output != ""} {
+ 	send_log "compilation of lookup program $opts(lookup) failed with <$comp_output>"
+@@ -244,7 +254,7 @@ proc run_lookup_test { name } {
+ 	    }
+ 	}
+ 
+-	set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
++	set comp_output [prune_warnings_lto [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags [concat $src] -o $lookup_output"]]
+ 
+ 	if { $comp_output != ""} {
+ 	    send_log "compilation of CTF program [concat $src] failed with <$comp_output>"
+
+base-commit: add96080cf9e460afe478cfad489d7f22ab10678
+-- 
+2.48.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-03-06 12:54 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-03-06 12:54 UTC (permalink / raw
  To: gentoo-commits

commit:     1bd87bad1171dd03613aac6fe3ff4764648d130a
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  6 12:54:08 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Mar  6 12:54:08 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=1bd87bad

9999: drop gprof revert

Merged upstream.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...f-only-process-line-numbers-for-intersect.patch | 179 ---------------------
 1 file changed, 179 deletions(-)

diff --git a/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch b/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch
deleted file mode 100644
index 210438d..0000000
--- a/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch
+++ /dev/null
@@ -1,179 +0,0 @@
-From d7ccec5522b6c7f61c95c7db4d1d91ff17cd1a31 Mon Sep 17 00:00:00 2001
-Message-ID: <d7ccec5522b6c7f61c95c7db4d1d91ff17cd1a31.1741236819.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Thu, 6 Mar 2025 04:53:27 +0000
-Subject: [PATCH] Revert "gprof: only process line numbers for intersection of
- vmas and histograms"
-
-This reverts commit b8189cf9e40bd90502c9a2ce0df39dd54419bea4.
-
-Bug: https://sourceware.org/PR32764
----
- gprof/corefile.c | 96 +++++++++++++++++++++++-------------------------
- gprof/gprof.c    | 23 ++++++------
- 2 files changed, 56 insertions(+), 63 deletions(-)
-
-diff --git a/gprof/corefile.c b/gprof/corefile.c
-index a8970b3200d..bc26bd7883e 100644
---- a/gprof/corefile.c
-+++ b/gprof/corefile.c
-@@ -755,9 +755,8 @@ core_create_line_syms (void)
-   Sym prev, *sym;
-   const char *filename;
-   Sym_Table ltab;
-+  bfd_vma vma_high;
-   size_t ltab_reserved;
--  bfd_vma bfd_vma_low = core_text_sect->vma;
--  bfd_vma bfd_vma_high = bfd_vma_low + bfd_section_size (core_text_sect);
- 
-   /* Create symbols for functions as usual.  This is necessary in
-      cases where parts of a program were not compiled with -g.  For
-@@ -787,58 +786,53 @@ core_create_line_syms (void)
-      lot cleaner now.  */
-   memset (&prev, 0, sizeof (prev));
- 
--  for (size_t i = 0; i < num_histograms; ++i)
-+  vma_high = core_text_sect->vma + bfd_section_size (core_text_sect);
-+  for (vma = core_text_sect->vma; vma < vma_high; vma += insn_boundary)
-     {
--      bfd_vma hist_vma_high = histograms[i].highpc;
--      bfd_vma vma_low = MAX (histograms[i].lowpc, bfd_vma_low);
--      bfd_vma vma_high = MIN (bfd_vma_high, hist_vma_high);
--      for (vma = vma_low; vma < vma_high; vma += insn_boundary)
-+      if (ltab.len >= ltab_reserved)
- 	{
--	  if (ltab.len >= ltab_reserved)
--	    {
--	      /* Reserve more space for line symbols.  */
--	      ltab_reserved *= 2;
--	      ltab.base = xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
--	      ltab.limit = ltab.base + ltab.len;
--	    }
--	  sym_init (ltab.limit);
--
--	  if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
--	      || (prev.name && prev.line_num == ltab.limit->line_num
--		  && strcmp (prev.name, ltab.limit->name) == 0
--		  && filename_cmp (prev.file->name, filename) == 0))
--	    continue;
--
--	  /* Make name pointer a malloc'ed string.  */
--	  ltab.limit->name = xstrdup (ltab.limit->name);
--	  ltab.limit->file = source_file_lookup_path (filename);
--
--	  ltab.limit->addr = vma;
--
--	  /* Set is_static based on the enclosing function, using either:
--	     1) the previous symbol, if it's from the same function, or
--	     2) a symtab lookup.  */
--	  if (prev.name && ltab.limit->file == prev.file
--	      && strcmp (ltab.limit->name, prev.name) == 0)
--	    {
--	      ltab.limit->is_static = prev.is_static;
--	    }
--	  else
--	    {
--	      sym = sym_lookup(&symtab, ltab.limit->addr);
--	      if (sym)
--		ltab.limit->is_static = sym->is_static;
--	    }
--
--	  prev = *ltab.limit;
--
--	  DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
--				  (unsigned long) (ltab.limit - ltab.base),
--				  ltab.limit->name,
--				  (unsigned long) ltab.limit->addr));
--	  ++ltab.limit;
--	  ++ltab.len;
-+	  /* Reserve more space for line symbols.  */
-+	  ltab_reserved *= 2;
-+	  ltab.base = (Sym *) xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
-+	  ltab.limit = ltab.base + ltab.len;
- 	}
-+      sym_init (ltab.limit);
-+
-+      if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
-+	  || (prev.name && prev.line_num == ltab.limit->line_num
-+	      && strcmp (prev.name, ltab.limit->name) == 0
-+	      && filename_cmp (prev.file->name, filename) == 0))
-+	continue;
-+
-+      /* Make name pointer a malloc'ed string.  */
-+      ltab.limit->name = xstrdup (ltab.limit->name);
-+      ltab.limit->file = source_file_lookup_path (filename);
-+
-+      ltab.limit->addr = vma;
-+
-+      /* Set is_static based on the enclosing function, using either:
-+	 1) the previous symbol, if it's from the same function, or
-+	 2) a symtab lookup.  */
-+      if (ltab.limit->file == prev.file
-+	  && strcmp (ltab.limit->name, prev.name) == 0)
-+	{
-+	  ltab.limit->is_static = prev.is_static;
-+	}
-+      else
-+	{
-+	  sym = sym_lookup(&symtab, ltab.limit->addr);
-+          if (sym)
-+	    ltab.limit->is_static = sym->is_static;
-+	}
-+
-+      prev = *ltab.limit;
-+
-+      DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
-+			      (unsigned long) (ltab.limit - ltab.base),
-+			      ltab.limit->name,
-+			      (unsigned long) ltab.limit->addr));
-+      ++ltab.limit;
-+      ++ltab.len;
-     }
- 
-   /* Reserve space for function symbols and/or trim excess space.  */
-diff --git a/gprof/gprof.c b/gprof/gprof.c
-index d1cbf25fa28..9392575f747 100644
---- a/gprof/gprof.c
-+++ b/gprof/gprof.c
-@@ -527,6 +527,17 @@ This program is free software.  This program has absolutely no warranty.\n"));
-   if (ignore_direct_calls)
-     core_get_text_space (core_bfd);
- 
-+  /* Create symbols from core image.  */
-+  if (external_symbol_table)
-+    core_create_syms_from (external_symbol_table);
-+  else if (line_granularity)
-+    core_create_line_syms ();
-+  else
-+    core_create_function_syms ();
-+
-+  /* Translate sym specs into syms.  */
-+  sym_id_parse ();
-+
-   if (file_format == FF_PROF)
-     {
-       fprintf (stderr,
-@@ -546,18 +557,6 @@ This program is free software.  This program has absolutely no warranty.\n"));
-       while (optind++ < argc);
-     }
- 
--  /* Create symbols from core image.  */
--  if (external_symbol_table)
--    core_create_syms_from (external_symbol_table);
--  else if (line_granularity)
--    core_create_line_syms ();
--  else
--    core_create_function_syms ();
--
--  /* Translate sym specs into syms.  */
--  sym_id_parse ();
--
--
-   /* If user did not specify output style, try to guess something
-      reasonable.  */
-   if (output_style == 0)
-
-base-commit: 34f65d9dee431f840b554a9de6de314cc22849d7
--- 
-2.48.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-03-06  4:54 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-03-06  4:54 UTC (permalink / raw
  To: gentoo-commits

commit:     cede467b7d5956b862883d790f438efbaca7a8b7
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  6 04:54:09 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Mar  6 04:54:50 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=cede467b

9999: revert gprof patch breaking glibc gmon tests

Bug: https://sourceware.org/PR32764
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...f-only-process-line-numbers-for-intersect.patch | 179 +++++++++++++++++++++
 1 file changed, 179 insertions(+)

diff --git a/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch b/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch
new file mode 100644
index 0000000..210438d
--- /dev/null
+++ b/9999/0005-Revert-gprof-only-process-line-numbers-for-intersect.patch
@@ -0,0 +1,179 @@
+From d7ccec5522b6c7f61c95c7db4d1d91ff17cd1a31 Mon Sep 17 00:00:00 2001
+Message-ID: <d7ccec5522b6c7f61c95c7db4d1d91ff17cd1a31.1741236819.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Thu, 6 Mar 2025 04:53:27 +0000
+Subject: [PATCH] Revert "gprof: only process line numbers for intersection of
+ vmas and histograms"
+
+This reverts commit b8189cf9e40bd90502c9a2ce0df39dd54419bea4.
+
+Bug: https://sourceware.org/PR32764
+---
+ gprof/corefile.c | 96 +++++++++++++++++++++++-------------------------
+ gprof/gprof.c    | 23 ++++++------
+ 2 files changed, 56 insertions(+), 63 deletions(-)
+
+diff --git a/gprof/corefile.c b/gprof/corefile.c
+index a8970b3200d..bc26bd7883e 100644
+--- a/gprof/corefile.c
++++ b/gprof/corefile.c
+@@ -755,9 +755,8 @@ core_create_line_syms (void)
+   Sym prev, *sym;
+   const char *filename;
+   Sym_Table ltab;
++  bfd_vma vma_high;
+   size_t ltab_reserved;
+-  bfd_vma bfd_vma_low = core_text_sect->vma;
+-  bfd_vma bfd_vma_high = bfd_vma_low + bfd_section_size (core_text_sect);
+ 
+   /* Create symbols for functions as usual.  This is necessary in
+      cases where parts of a program were not compiled with -g.  For
+@@ -787,58 +786,53 @@ core_create_line_syms (void)
+      lot cleaner now.  */
+   memset (&prev, 0, sizeof (prev));
+ 
+-  for (size_t i = 0; i < num_histograms; ++i)
++  vma_high = core_text_sect->vma + bfd_section_size (core_text_sect);
++  for (vma = core_text_sect->vma; vma < vma_high; vma += insn_boundary)
+     {
+-      bfd_vma hist_vma_high = histograms[i].highpc;
+-      bfd_vma vma_low = MAX (histograms[i].lowpc, bfd_vma_low);
+-      bfd_vma vma_high = MIN (bfd_vma_high, hist_vma_high);
+-      for (vma = vma_low; vma < vma_high; vma += insn_boundary)
++      if (ltab.len >= ltab_reserved)
+ 	{
+-	  if (ltab.len >= ltab_reserved)
+-	    {
+-	      /* Reserve more space for line symbols.  */
+-	      ltab_reserved *= 2;
+-	      ltab.base = xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
+-	      ltab.limit = ltab.base + ltab.len;
+-	    }
+-	  sym_init (ltab.limit);
+-
+-	  if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
+-	      || (prev.name && prev.line_num == ltab.limit->line_num
+-		  && strcmp (prev.name, ltab.limit->name) == 0
+-		  && filename_cmp (prev.file->name, filename) == 0))
+-	    continue;
+-
+-	  /* Make name pointer a malloc'ed string.  */
+-	  ltab.limit->name = xstrdup (ltab.limit->name);
+-	  ltab.limit->file = source_file_lookup_path (filename);
+-
+-	  ltab.limit->addr = vma;
+-
+-	  /* Set is_static based on the enclosing function, using either:
+-	     1) the previous symbol, if it's from the same function, or
+-	     2) a symtab lookup.  */
+-	  if (prev.name && ltab.limit->file == prev.file
+-	      && strcmp (ltab.limit->name, prev.name) == 0)
+-	    {
+-	      ltab.limit->is_static = prev.is_static;
+-	    }
+-	  else
+-	    {
+-	      sym = sym_lookup(&symtab, ltab.limit->addr);
+-	      if (sym)
+-		ltab.limit->is_static = sym->is_static;
+-	    }
+-
+-	  prev = *ltab.limit;
+-
+-	  DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
+-				  (unsigned long) (ltab.limit - ltab.base),
+-				  ltab.limit->name,
+-				  (unsigned long) ltab.limit->addr));
+-	  ++ltab.limit;
+-	  ++ltab.len;
++	  /* Reserve more space for line symbols.  */
++	  ltab_reserved *= 2;
++	  ltab.base = (Sym *) xrealloc (ltab.base, ltab_reserved * sizeof (Sym));
++	  ltab.limit = ltab.base + ltab.len;
+ 	}
++      sym_init (ltab.limit);
++
++      if (!get_src_info (vma, &filename, &ltab.limit->name, &ltab.limit->line_num)
++	  || (prev.name && prev.line_num == ltab.limit->line_num
++	      && strcmp (prev.name, ltab.limit->name) == 0
++	      && filename_cmp (prev.file->name, filename) == 0))
++	continue;
++
++      /* Make name pointer a malloc'ed string.  */
++      ltab.limit->name = xstrdup (ltab.limit->name);
++      ltab.limit->file = source_file_lookup_path (filename);
++
++      ltab.limit->addr = vma;
++
++      /* Set is_static based on the enclosing function, using either:
++	 1) the previous symbol, if it's from the same function, or
++	 2) a symtab lookup.  */
++      if (ltab.limit->file == prev.file
++	  && strcmp (ltab.limit->name, prev.name) == 0)
++	{
++	  ltab.limit->is_static = prev.is_static;
++	}
++      else
++	{
++	  sym = sym_lookup(&symtab, ltab.limit->addr);
++          if (sym)
++	    ltab.limit->is_static = sym->is_static;
++	}
++
++      prev = *ltab.limit;
++
++      DBG (AOUTDEBUG, printf ("[core_create_line_syms] %lu %s 0x%lx\n",
++			      (unsigned long) (ltab.limit - ltab.base),
++			      ltab.limit->name,
++			      (unsigned long) ltab.limit->addr));
++      ++ltab.limit;
++      ++ltab.len;
+     }
+ 
+   /* Reserve space for function symbols and/or trim excess space.  */
+diff --git a/gprof/gprof.c b/gprof/gprof.c
+index d1cbf25fa28..9392575f747 100644
+--- a/gprof/gprof.c
++++ b/gprof/gprof.c
+@@ -527,6 +527,17 @@ This program is free software.  This program has absolutely no warranty.\n"));
+   if (ignore_direct_calls)
+     core_get_text_space (core_bfd);
+ 
++  /* Create symbols from core image.  */
++  if (external_symbol_table)
++    core_create_syms_from (external_symbol_table);
++  else if (line_granularity)
++    core_create_line_syms ();
++  else
++    core_create_function_syms ();
++
++  /* Translate sym specs into syms.  */
++  sym_id_parse ();
++
+   if (file_format == FF_PROF)
+     {
+       fprintf (stderr,
+@@ -546,18 +557,6 @@ This program is free software.  This program has absolutely no warranty.\n"));
+       while (optind++ < argc);
+     }
+ 
+-  /* Create symbols from core image.  */
+-  if (external_symbol_table)
+-    core_create_syms_from (external_symbol_table);
+-  else if (line_granularity)
+-    core_create_line_syms ();
+-  else
+-    core_create_function_syms ();
+-
+-  /* Translate sym specs into syms.  */
+-  sym_id_parse ();
+-
+-
+   /* If user did not specify output style, try to guess something
+      reasonable.  */
+   if (output_style == 0)
+
+base-commit: 34f65d9dee431f840b554a9de6de314cc22849d7
+-- 
+2.48.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-02-03 18:02 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2025-02-03 18:02 UTC (permalink / raw
  To: gentoo-commits

commit:     2be385087cbca35633d0fb6777017ec8f07875cc
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Mon Feb  3 18:01:36 2025 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Mon Feb  3 18:01:36 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=2be38508

Drop gold patch (XFAIL 15 tests)

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...lar-libiberty-fix-as-in-7d53105d-for-lib.patch} |  0
 ...0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch | 77 ----------------------
 2 files changed, 77 deletions(-)

diff --git a/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
similarity index 100%
rename from 9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
rename to 9999/0004-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch

diff --git a/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
deleted file mode 100644
index 943d079..0000000
--- a/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ /dev/null
@@ -1,77 +0,0 @@
-From 942b4489226184460d46eb9e7450eb63a1885621 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sat, 31 Jul 2021 01:18:18 +0200
-Subject: [PATCH 4/5] Gentoo: XFAIL 15 broken ld.gold tests
-
-It seems like either the tests or ld.gold in general cannot handle
-compilers built with --enable-default-pie. No fix yet, so let's ignore
-these test failures for the moment. For details see the linked bugs.
-
-Bug: https://bugs.gentoo.org/684046
-Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22755
-Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27303
----
- gold/testsuite/Makefile.am |  6 ++++++
- gold/testsuite/Makefile.in | 16 ++++++++++++----
- 2 files changed, 18 insertions(+), 4 deletions(-)
-
-diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
-index 2f1348fd6e2..1206460f191 100644
---- a/gold/testsuite/Makefile.am
-+++ b/gold/testsuite/Makefile.am
-@@ -1,5 +1,11 @@
- # Process this file with automake to generate Makefile.in
- 
-+# Gentoo, https://bugs.gentoo.org/684046
-+XFAIL_TESTS = exception_separate_shared_12_test exception_separate_shared_21_test \
-+	weak_undef_test initpri3a justsyms_exec script_test_2 script_test_1 \
-+	justsyms binary_test script_test_3 tls_phdrs_script_test script_test_12i \
-+	dynamic_list_2 incremental_test_2 incremental_test_5
-+
- # As far as I can tell automake testing support assumes that the build
- # system and the host system are the same.  So these tests will not
- # work when building with a cross-compiler.
-diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
-index 9cf21df8d7d..df14333c558 100644
---- a/gold/testsuite/Makefile.in
-+++ b/gold/testsuite/Makefile.in
-@@ -15,10 +15,6 @@
- @SET_MAKE@
- 
- # Process this file with automake to generate Makefile.in
--
--# As far as I can tell automake testing support assumes that the build
--# system and the host system are the same.  So these tests will not
--# work when building with a cross-compiler.
- VPATH = @srcdir@
- am__is_gnu_make = { \
-   if test -z '$(MAKELEVEL)'; then \
-@@ -94,6 +90,14 @@ POST_UNINSTALL = :
- build_triplet = @build@
- host_triplet = @host@
- target_triplet = @target@
-+XFAIL_TESTS = exception_separate_shared_12_test$(EXEEXT) \
-+	exception_separate_shared_21_test$(EXEEXT) \
-+	weak_undef_test$(EXEEXT) initpri3a$(EXEEXT) \
-+	justsyms_exec$(EXEEXT) script_test_2$(EXEEXT) \
-+	script_test_1$(EXEEXT) justsyms$(EXEEXT) binary_test$(EXEEXT) \
-+	script_test_3$(EXEEXT) tls_phdrs_script_test$(EXEEXT) \
-+	script_test_12i$(EXEEXT) dynamic_list_2$(EXEEXT) \
-+	incremental_test_2$(EXEEXT) incremental_test_5$(EXEEXT)
- check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
- 	$(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
- 	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
-@@ -2782,6 +2786,10 @@ top_srcdir = @top_srcdir@
- zlibdir = @zlibdir@
- zlibinc = @zlibinc@
- 
-+# As far as I can tell automake testing support assumes that the build
-+# system and the host system are the same.  So these tests will not
-+# work when building with a cross-compiler.
-+
- # Ignore warning about AM_PROG_CC_C_O due to large_CFLAGS
- AUTOMAKE_OPTIONS = foreign -Wno-portability
- 
--- 
-2.44.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-01-14  2:09 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-01-14  2:09 UTC (permalink / raw
  To: gentoo-commits

commit:     043dad090e6059d52cfc14f7224ad755cdde1dc2
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 14 02:08:51 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 14 02:08:51 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=043dad09

9999: drop upstream LTO patches

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-LTO-and-none-LTO-output-support-for-ld-r.patch | 2928 --------------------
 ...ment-mixing-LTO-and-non-LTO-objects-for-r.patch |   42 -
 ...008-h8300-Handle-.gnu_object_only-section.patch |   37 -
 3 files changed, 3007 deletions(-)

diff --git a/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch b/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch
deleted file mode 100644
index b26d48f..0000000
--- a/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch
+++ /dev/null
@@ -1,2928 +0,0 @@
-From 9f57274faacf1dbb6c2b56d29de150b5e79ecb3d Mon Sep 17 00:00:00 2001
-Message-ID: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Mon, 4 Nov 2013 09:17:45 -0800
-Subject: [PATCH 6/8] ld: Add LTO and none-LTO output support for ld -r
-
-Link with mixed IR/non-IR objects
-
-* 2 kinds of object files
-  o non-IR object file has
-    * non-IR sections
-  o IR object file has
-    * IR sections
-    * non-IR sections
-    * The output of "ld -r" with mixed IR/non-IR objects should work with:
-        o Compilers/linkers with IR support.
-	o Compilers/linkers without IR support.
-* Add the mixed object file which has
-  o IR sections
-  o non-IR sections:
-    * Object codes from IR sections.
-    * Object codes from non-IR object files.
-  o Object-only section:
-    * With section name ".gnu_object_only" and SHT_GNU_OBJECT_ONLY type
-    on ELF:
-    https://gitlab.com/x86-psABIs/Linux-ABI
-    #define SHT_GNU_OBJECT_ONLY 0x6ffffff8	/* Object only */
-    * Contain non-IR object file.
-    * Input is discarded after link.
-* Linker action:
-  o Classify each input object file:
-    * If there is a ".gnu_object_only" section, it is a mixed object file.
-    * If there is a IR section, it is an IR object file.
-    * Otherwise, it is a non-IR object file.
-  o Relocatable non-IR link:
-    * Prepare for an object-only output.
-    * Prepare for a regular output.
-    * For each mixed object file:
-      * Add IR and non-IR sections to the regular output.
-      * For object-only section:
-	* Extract object only file.
-	* Add it to the object-only output.
-	* Discard object-only section.
-    * For each IR object file:
-      * Add IR and non-IR sections to the regular output.
-    * For each non-IR object file:
-      * Add non-IR sections to the regular output.
-      * Add non-IR sections to the object-only output.
-    * Final output:
-      * If there are IR objects, non-IR objects and the object-only
-      output isn't empty:
-	* Put the object-only output into the object-only section.
-	* Add the object-only section to the regular output.
-	* Remove the object-only output.
-  o Normal link and relocatable IR link:
-    * Prepare for output.
-    * IR link:
-      * For each mixed object file:
-	* Compile and add IR sections to the output.
-	* Discard non-IR sections.
-	* Object-only section:
-	  * Extract object only file.
-	  * Add it to the output.
-	  * Discard object-only section.
-      * For each IR object file:
-        * Compile and add IR sections to the output.
-	* Discard non-IR sections.
-      * For each non-IR object file:
-	* Add non-IR sections to the output.
-    * Non-IR link:
-      * For each mixed object file:
-	* Add non-IR sections to the output.
-	* Discard IR sections and object-only section.
-      * For each IR object file:
-	* Add non-IR sections to the output.
-	* Discard IR sections.
-      * For each non-IR object file:
-	* Add non-IR sections to the output.
-
-This is useful for Linux kernel build with LTO.
-
-bfd/
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* bfd.c (bfd_lto_object_type): Add lto_mixed_object.
-	(bfd): Add object_only_section.
-	(bfd_group_signature): New.
-	* elf.c (special_sections_g): Add .gnu_object_only.
-	* format.c: Include "plugin-api.h" and "plugin.h" if
-	BFD_SUPPORTS_PLUGINS is defined.
-	(bfd_set_lto_type): Set type to lto_mixed_object for
-	GNU_OBJECT_ONLY_SECTION_NAME section.
-	(bfd_check_format_matches): Don't check the plugin target twice
-	if the plugin target is explicitly specified.
-	* opncls.c (bfd_extract_object_only_section): New.
-	* plugin.c (bfd_plugin_fake_text_section): New.
-	(bfd_plugin_fake_data_section): Likewise.
-	(bfd_plugin_fake_bss_section): Likewise.
-	(bfd_plugin_fake_common_section): Likewise.
-	(bfd_plugin_get_symbols_in_object_only): Likewise.
-	* plugin.c (add_symbols): Call
-	bfd_plugin_get_symbols_in_object_only and count
-	plugin_data->object_only_nsyms.
-	(bfd_plugin_get_symtab_upper_bound): Count
-	plugin_data->object_only_nsyms.
-	bfd_plugin_get_symbols_in_object_only and add symbols from
-	object only section.
-	(bfd_plugin_canonicalize_symtab): Remove fake_section,
-	fake_data_section, fake_bss_section and fake_common_section.
-	Set udata.p to NULL.  Use bfd_plugin_fake_text_section,
-	bfd_plugin_fake_data_section, bfd_plugin_fake_bss_section and
-	bfd_plugin_fake_common_section.
-	Set udata.p to NULL.
-	* plugin.h (plugin_data_struct): Add object_only_nsyms and
-	object_only_syms.
-	* section.c (GNU_OBJECT_ONLY_SECTION_NAME): New.
-	* bfd-in2.h: Regenerated.
-
-binutils/
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* objcopy.c (group_signature): Removed.
-	(is_strip_section): Replace group_signature with
-	bfd_group_signature.
-	(setup_section): Likewise.
-	* readelf.c (get_os_specific_section_type_name): Handle
-	SHT_GNU_OBJECT_ONLY.
-
-gas/
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* testsuite/gas/elf/section9.s: Add the .gnu_object_only test.
-	* testsuite/gas/elf/section9.d: Updated.
-
-include/
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* elf/common.h (SHT_GNU_OBJECT_ONLY): New.
-
-ld/
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* ld.h (ld_config_type): Add emit_gnu_object_only and
-	emitting_gnu_object_only.
-	* ldelf.c (orphan_init_done): Make it file scope.
-	(ldelf_place_orphan): Rename hold to orig_hold.  Initialize hold
-	from orig_hold at run-time.
-	(ldelf_finish): New.
-	* ldelf.h (ldelf_finish): New.
-	* ldexp.c (ldexp_init): Take a bfd_boolean argument to supprt
-	object-only output.
-	(ldexp_finish): Likewise.
-	* ldexp.h (ldexp_init): Take a bfd_boolean argument.
-	(ldexp_finish): Likewise.
-	* ldfile.c (ldfile_try_open_bfd): Call
-	cmdline_check_object_only_section.
-	* ldlang.c: Include "ldwrite.h" and elf-bfd.h.
-	* ldlang.c (cmdline_object_only_file_list): New.
-	(cmdline_object_only_archive_list): Likewise.
-	(cmdline_temp_object_only_list): Likewise.
-	(cmdline_lists_init): Likewise.
-	(cmdline_list_new): Likewise.
-	(cmdline_list_append): Likewise.
-	(print_cmdline_list): Likewise.
-	(cmdline_on_object_only_archive_list_p): Likewise.
-	(cmdline_object_only_list_append): Likewise.
-	(cmdline_get_object_only_input_files): Likewise.
-	(cmdline_arg): Likewise.
-	(setup_section): Likewise.
-	(copy_section): Likewise.
-	(cmdline_fopen_temp): Likewise.
-	(cmdline_add_object_only_section): Likewise.
-	(cmdline_emit_object_only_section): Likewise.
-	(cmdline_extract_object_only_section): Likewise.
-	(cmdline_check_object_only_section): Likewise.
-	(cmdline_remove_object_only_files): Likewise.
-	(lang_init): Take a bfd_boolean argument to supprt object-only
-	output.  Call cmdline_lists_init.
-	(load_symbols): Call cmdline_on_object_only_archive_list_p
-	to check if an archive member should be loaded.
-	(lang_process): Handle object-only link.
-	* ldlang.h (lang_init): Take a bfd_boolean argument.
-	(cmdline_enum_type): New.
-	(cmdline_header_type): Likewise.
-	(cmdline_file_type): Likewise.
-	(cmdline_bfd_type): Likewise.
-	(cmdline_union_type): Likewise.
-	(cmdline_list_type): Likewise.
-	(cmdline_emit_object_only_section): Likewise.
-	(cmdline_check_object_only_section): Likewise.
-	(cmdline_remove_object_only_files): Likewise.
-	* ldmain.c (main): Call xatexit with
-	cmdline_remove_object_only_files.  Pass FALSE to lang_init,
-	ldexp_init and ldexp_finish.  Use ld_parse_linker_script.
-	Set link_info.output_bfd to NULL after close.  Call
-	cmdline_emit_object_only_section if needed.
-	(add_archive_element): Call cmdline_check_object_only_section.
-	(ld_parse_linker_script): New.
-	* ldmain.h (ld_parse_linker_script): New.
-	* plugin.c (plugin_maybe_claim): Call
-	cmdline_check_object_only_section on claimed IR files.
-	* scripttempl/elf.sc: Also discard .gnu_object_only sections.
-	* scripttempl/elf64hppa.sc: Likewise.
-	* scripttempl/elfxtensa.sc: Likewise.
-	* scripttempl/mep.sc: Likewise.
-	* scripttempl/pe.sc: Likewise.
-	* scripttempl/pep.sc: Likewise.
-	* emultempl/aarch64elf.em (gld${EMULATION_NAME}_finish): Replace
-	finish_default with ldelf_finish.
-	* emultempl/alphaelf.em (alpha_finish): Likewise.
-	* emultempl/avrelf.em (avr_finish): Likewise.
-	* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
-	* emultempl/ppc32elf.em (ppc_finish): Likewise.
-	* emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Likewise.
-	* emultempl/spuelf.em (gld${EMULATION_NAME}_finish): Likewise.
-	* testsuite/ld-plugin/lto-10.out: New file.
-	* testsuite/ld-plugin/lto-10a.c: Likewise.
-	* testsuite/ld-plugin/lto-10b.c: Likewise.
-	* testsuite/ld-plugin/lto-10r.d: Likewise.
-	* testsuite/ld-plugin/lto-4.out: Likewise.
-	* testsuite/ld-plugin/lto-4a.c: Likewise.
-	* testsuite/ld-plugin/lto-4b.c: Likewise.
-	* testsuite/ld-plugin/lto-4c.c: Likewise.
-	* testsuite/ld-plugin/lto-4r-a.d: Likewise.
-	* testsuite/ld-plugin/lto-4r-b.d: Likewise.
-	* testsuite/ld-plugin/lto-4r-c.d: Likewise.
-	* testsuite/ld-plugin/lto-4r-d.d: Likewise.
-	* testsuite/ld-plugin/lto.exp (lto_link_tests): Prepare for
-	"LTO 4[acd]", "lto-4r-[abcd]" and "LTO 10" tests.
-	(lto_run_tests): Add "LTO 4[acd]" and "LTO 10" tests.
-	Build liblto-4.a.  Run "lto-4r-[abcd]" tests.
-	Run lto-10r and create tmpdir/lto-10.o.
-	Add test for nm on mixed LTO/non-LTO object.
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- bfd/bfd-in2.h                     |   16 +-
- bfd/bfd.c                         |   46 +-
- bfd/elf.c                         |    1 +
- bfd/format.c                      |   37 +-
- bfd/opncls.c                      |   66 ++
- bfd/plugin.c                      |  193 +++++-
- bfd/plugin.h                      |    2 +
- bfd/section.c                     |    3 +
- binutils/objcopy.c                |   32 +-
- binutils/readelf.c                |    1 +
- gas/testsuite/gas/elf/section9.d  |    1 +
- gas/testsuite/gas/elf/section9.s  |    2 +
- include/elf/common.h              |    1 +
- ld/emultempl/aarch64elf.em        |    2 +-
- ld/emultempl/alphaelf.em          |    2 +-
- ld/emultempl/armelf.em            |    2 +-
- ld/emultempl/avrelf.em            |    2 +-
- ld/emultempl/elf.em               |    1 +
- ld/emultempl/ppc32elf.em          |    2 +-
- ld/emultempl/ppc64elf.em          |    2 +-
- ld/emultempl/spuelf.em            |    2 +-
- ld/ld.h                           |    6 +
- ld/ldelf.c                        |   26 +-
- ld/ldelf.h                        |    1 +
- ld/ldexp.c                        |   16 +-
- ld/ldexp.h                        |    4 +-
- ld/ldfile.c                       |    2 +
- ld/ldlang.c                       | 1027 ++++++++++++++++++++++++++++-
- ld/ldlang.h                       |   44 +-
- ld/ldmain.c                       |   80 ++-
- ld/ldmain.h                       |    2 +
- ld/plugin.c                       |    3 +
- ld/scripttempl/elf.sc             |    2 +-
- ld/scripttempl/elf64hppa.sc       |    2 +-
- ld/scripttempl/elfxtensa.sc       |    2 +-
- ld/scripttempl/mep.sc             |    2 +-
- ld/scripttempl/pe.sc              |    1 +
- ld/scripttempl/pep.sc             |    1 +
- ld/testsuite/ld-plugin/lto-10.out |    1 +
- ld/testsuite/ld-plugin/lto-10a.c  |    6 +
- ld/testsuite/ld-plugin/lto-10b.c  |    7 +
- ld/testsuite/ld-plugin/lto-10r.d  |    9 +
- ld/testsuite/ld-plugin/lto-4.out  |    2 +
- ld/testsuite/ld-plugin/lto-4a.c   |    7 +
- ld/testsuite/ld-plugin/lto-4b.c   |    9 +
- ld/testsuite/ld-plugin/lto-4c.c   |    6 +
- ld/testsuite/ld-plugin/lto-4r-a.d |    7 +
- ld/testsuite/ld-plugin/lto-4r-b.d |    7 +
- ld/testsuite/ld-plugin/lto-4r-c.d |    7 +
- ld/testsuite/ld-plugin/lto-4r-d.d |    7 +
- ld/testsuite/ld-plugin/lto.exp    |   66 ++
- 51 files changed, 1653 insertions(+), 125 deletions(-)
- create mode 100644 ld/testsuite/ld-plugin/lto-10.out
- create mode 100644 ld/testsuite/ld-plugin/lto-10a.c
- create mode 100644 ld/testsuite/ld-plugin/lto-10b.c
- create mode 100644 ld/testsuite/ld-plugin/lto-10r.d
- create mode 100644 ld/testsuite/ld-plugin/lto-4.out
- create mode 100644 ld/testsuite/ld-plugin/lto-4a.c
- create mode 100644 ld/testsuite/ld-plugin/lto-4b.c
- create mode 100644 ld/testsuite/ld-plugin/lto-4c.c
- create mode 100644 ld/testsuite/ld-plugin/lto-4r-a.d
- create mode 100644 ld/testsuite/ld-plugin/lto-4r-b.d
- create mode 100644 ld/testsuite/ld-plugin/lto-4r-c.d
- create mode 100644 ld/testsuite/ld-plugin/lto-4r-d.d
-
-diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
-index 3a5a6dd8a5f..1b82b6bcc99 100644
---- a/bfd/bfd-in2.h
-+++ b/bfd/bfd-in2.h
-@@ -925,6 +925,9 @@ extern asection _bfd_std_section[4];
- #define BFD_COM_SECTION_NAME "*COM*"
- #define BFD_IND_SECTION_NAME "*IND*"
- 
-+/* GNU object-only section name.  */
-+#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
-+
- /* Pointer to the common section.  */
- #define bfd_com_section_ptr (&_bfd_std_section[0])
- /* Pointer to the undefined section.  */
-@@ -1962,7 +1965,8 @@ enum bfd_lto_object_type
-     lto_non_object,            /* Not an LTO object.  */
-     lto_non_ir_object,         /* An object without LTO IR.  */
-     lto_slim_ir_object,        /* A slim LTO IR object.  */
--    lto_fat_ir_object          /* A fat LTO IR object.  */
-+    lto_fat_ir_object,         /* A fat LTO IR object.  */
-+    lto_mixed_object           /* A mixed LTO IR object.  */
-   };
- 
- struct bfd_mmapped_entry
-@@ -2185,7 +2189,7 @@ struct bfd
-   unsigned int read_only : 1;
- 
-   /* LTO object type.  */
--  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
-+  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 3;
- 
-   /* Set if this BFD is currently being processed by
-      bfd_check_format_matches.  This is checked by the cache to
-@@ -2217,6 +2221,9 @@ struct bfd
-   /* The last section on the section list.  */
-   struct bfd_section *section_last;
- 
-+  /* The object-only section on the section list.  */
-+  struct bfd_section *object_only_section;
-+
-   /* The number of sections.  */
-   unsigned int section_count;
- 
-@@ -2790,6 +2797,8 @@ bfd_vma bfd_emul_get_commonpagesize (const char *);
- 
- char *bfd_demangle (bfd *, const char *, int);
- 
-+asymbol *bfd_group_signature (asection *group, asymbol **isympp);
-+
- /* Extracted from bfdio.c.  */
- bfd_size_type bfd_read (void *, bfd_size_type, bfd *)
- ATTRIBUTE_WARN_UNUSED_RESULT;
-@@ -3073,6 +3082,9 @@ char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir);
- 
- const char *bfd_set_filename (bfd *abfd, const char *filename);
- 
-+const char *bfd_extract_object_only_section
-+   (bfd *abfd);
-+
- /* Extracted from reloc.c.  */
- typedef enum bfd_reloc_status
- {
-diff --git a/bfd/bfd.c b/bfd/bfd.c
-index 194f24179fd..a8d1314b83f 100644
---- a/bfd/bfd.c
-+++ b/bfd/bfd.c
-@@ -80,7 +80,8 @@ EXTERNAL
- .    lto_non_object,		{* Not an LTO object.  *}
- .    lto_non_ir_object,		{* An object without LTO IR.  *}
- .    lto_slim_ir_object,	{* A slim LTO IR object.  *}
--.    lto_fat_ir_object		{* A fat LTO IR object.  *}
-+.    lto_fat_ir_object,		{* A fat LTO IR object.  *}
-+.    lto_mixed_object		{* A mixed LTO IR object.  *}
- .  };
- .
- .struct bfd_mmapped_entry
-@@ -306,7 +307,7 @@ CODE_FRAGMENT
- .  unsigned int read_only : 1;
- .
- .  {* LTO object type.  *}
--.  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
-+.  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 3;
- .
- .  {* Set if this BFD is currently being processed by
- .     bfd_check_format_matches.  This is checked by the cache to
-@@ -338,6 +339,9 @@ CODE_FRAGMENT
- .  {* The last section on the section list.  *}
- .  struct bfd_section *section_last;
- .
-+.  {* The object-only section on the section list.  *}
-+.  struct bfd_section *object_only_section;
-+.
- .  {* The number of sections.  *}
- .  unsigned int section_count;
- .
-@@ -3034,3 +3038,41 @@ _bfd_get_link_info (bfd *abfd)
- 
-   return elf_link_info (abfd);
- }
-+
-+/*
-+FUNCTION
-+	bfd_group_signature
-+
-+SYNOPSIS
-+	asymbol *bfd_group_signature (asection *group, asymbol **isympp);
-+
-+DESCRIPTION
-+	Return a pointer to the symbol used as a signature for GROUP.
-+*/
-+
-+asymbol *
-+bfd_group_signature (asection *group, asymbol **isympp)
-+{
-+  bfd *abfd = group->owner;
-+  Elf_Internal_Shdr *ghdr;
-+
-+  /* PR 20089: An earlier error may have prevented us from loading the
-+     symbol table.  */
-+  if (isympp == NULL)
-+    return NULL;
-+
-+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
-+    return NULL;
-+
-+  ghdr = &elf_section_data (group)->this_hdr;
-+  if (ghdr->sh_link == elf_onesymtab (abfd))
-+    {
-+      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-+      Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd);
-+
-+      if (ghdr->sh_info > 0
-+	  && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
-+	return isympp[ghdr->sh_info - 1];
-+    }
-+  return NULL;
-+}
-diff --git a/bfd/elf.c b/bfd/elf.c
-index 218d58df8be..30bbdc662af 100644
---- a/bfd/elf.c
-+++ b/bfd/elf.c
-@@ -3014,6 +3014,7 @@ static const struct bfd_elf_special_section special_sections_g[] =
-   { STRING_COMMA_LEN (".gnu.linkonce.p"), -2, SHT_PROGBITS,    SHF_ALLOC + SHF_WRITE },
-   { STRING_COMMA_LEN (".gnu.lto_"),	  -1, SHT_PROGBITS,    SHF_EXCLUDE },
-   { STRING_COMMA_LEN (".got"),		   0, SHT_PROGBITS,    SHF_ALLOC + SHF_WRITE },
-+  { STRING_COMMA_LEN (".gnu_object_only"), 0, SHT_GNU_OBJECT_ONLY, SHF_EXCLUDE },
-   { STRING_COMMA_LEN (".gnu.version"),	   0, SHT_GNU_versym,  0 },
-   { STRING_COMMA_LEN (".gnu.version_d"),   0, SHT_GNU_verdef,  0 },
-   { STRING_COMMA_LEN (".gnu.version_r"),   0, SHT_GNU_verneed, 0 },
-diff --git a/bfd/format.c b/bfd/format.c
-index 125815935f6..7769ad095f6 100644
---- a/bfd/format.c
-+++ b/bfd/format.c
-@@ -46,6 +46,10 @@ SUBSECTION
- #include "sysdep.h"
- #include "bfd.h"
- #include "libbfd.h"
-+#if BFD_SUPPORTS_PLUGINS
-+#include "plugin-api.h"
-+#include "plugin.h"
-+#endif
- 
- /* IMPORT from targets.c.  */
- extern const size_t _bfd_target_vector_entries;
-@@ -349,23 +353,32 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
- #if BFD_SUPPORTS_PLUGINS
-   if (abfd->format == bfd_object
-       && abfd->lto_type == lto_non_object
--      && (abfd->flags & (DYNAMIC | EXEC_P)) == 0)
-+      && (abfd->flags
-+	  & (DYNAMIC
-+	     | (bfd_get_flavour (abfd) == bfd_target_elf_flavour
-+		? EXEC_P : 0))) == 0)
-     {
-       asection *sec;
-       enum bfd_lto_object_type type = lto_non_ir_object;
--      struct lto_section lsection;
-+      struct lto_section lsection = { 0, 0, 0, 0 };
-       /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
- 	 section.  */
-       for (sec = abfd->sections; sec != NULL; sec = sec->next)
--	if (startswith (sec->name, ".gnu.lto_.lto.")
--	    && bfd_get_section_contents (abfd, sec, &lsection, 0,
--					 sizeof (struct lto_section)))
-+	if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
-+	  {
-+	    type = lto_mixed_object;
-+	    abfd->object_only_section = sec;
-+	    break;
-+	  }
-+	else if (lsection.major_version == 0
-+		 && startswith (sec->name, ".gnu.lto_.lto.")
-+		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
-+					      sizeof (struct lto_section)))
- 	  {
- 	    if (lsection.slim_object)
- 	      type = lto_slim_ir_object;
- 	    else
- 	      type = lto_fat_ir_object;
--	    break;
- 	  }
- 
-       abfd->lto_type = type;
-@@ -397,9 +410,6 @@ bool
- bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- {
-   extern const bfd_target binary_vec;
--#if BFD_SUPPORTS_PLUGINS
--  extern const bfd_target plugin_vec;
--#endif
-   const bfd_target * const *target;
-   const bfd_target **matching_vector = NULL;
-   const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
-@@ -507,11 +517,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
- 	 check the default target twice.  */
-       if (*target == &binary_vec
- #if BFD_SUPPORTS_PLUGINS
--	  || (match_count != 0 && *target == &plugin_vec)
-+	  || (match_count != 0 && bfd_plugin_target_p (*target))
- #endif
- 	  || (!abfd->target_defaulted && *target == save_targ))
- 	continue;
- 
-+#if BFD_SUPPORTS_PLUGINS
-+      /* If the plugin target is explicitly specified when a BFD file
-+	 is opened, don't check it twice.  */
-+      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
-+	continue;
-+#endif
-+
-       /* If we already tried a match, the bfd is modified and may
- 	 have sections attached, which will confuse the next
- 	 _bfd_check_format call.  */
-diff --git a/bfd/opncls.c b/bfd/opncls.c
-index 93adbf117f0..ca7dbf23aa6 100644
---- a/bfd/opncls.c
-+++ b/bfd/opncls.c
-@@ -2054,3 +2054,69 @@ bfd_set_filename (bfd *abfd, const char *filename)
- 
-   return n;
- }
-+
-+/*
-+FUNCTION
-+	bfd_extract_object_only_section
-+
-+SYNOPSIS
-+	const char *bfd_extract_object_only_section
-+	  (bfd *abfd);
-+
-+DESCRIPTION
-+
-+	Takes a @var{ABFD} and extract the .gnu_object_only section into
-+	a temporary file.
-+
-+RETURNS
-+	The name of the temporary file is returned if all is ok.
-+	Otherwise <<NULL>> is returned and bfd_error is set.
-+*/
-+
-+const char *
-+bfd_extract_object_only_section (bfd *abfd)
-+{
-+  asection *sec = abfd->object_only_section;
-+  const char *name;
-+  FILE *file;
-+  bfd_byte *memhunk = NULL;
-+  size_t off, size;
-+  bfd_error_type err;
-+
-+  /* Get a temporary object-only file.  */
-+  name = make_temp_file (".obj-only.o");
-+
-+  /* Open the object-only file.  */
-+  file = _bfd_real_fopen (name, FOPEN_WB);
-+  if (!bfd_get_full_section_contents (abfd, sec, &memhunk))
-+    {
-+      err = bfd_get_error ();
-+
-+loser:
-+      free (memhunk);
-+      fclose (file);
-+      unlink (name);
-+      bfd_set_error (err);
-+      return NULL;
-+    }
-+
-+  off = 0;
-+  size = sec->size;
-+  while (off != size)
-+    {
-+      size_t written, nwrite = size - off;
-+
-+      written = fwrite (memhunk + off, 1, nwrite, file);
-+      if (written < nwrite && ferror (file))
-+	{
-+	  err = bfd_error_system_call;
-+	  goto loser;
-+	}
-+
-+      off += written;
-+    }
-+
-+  free (memhunk);
-+  fclose (file);
-+  return name;
-+}
-diff --git a/bfd/plugin.c b/bfd/plugin.c
-index 67454adffb9..d57ae593e78 100644
---- a/bfd/plugin.c
-+++ b/bfd/plugin.c
-@@ -160,6 +160,158 @@ register_claim_file (ld_plugin_claim_file_handler handler)
-   return LDPS_OK;
- }
- 
-+static asection bfd_plugin_fake_text_section
-+  = BFD_FAKE_SECTION (bfd_plugin_fake_text_section, NULL, "plug", 0,
-+		      SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS);
-+static asection bfd_plugin_fake_data_section
-+  = BFD_FAKE_SECTION (bfd_plugin_fake_data_section, NULL, "plug", 0,
-+		      SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS);
-+static asection bfd_plugin_fake_bss_section
-+  = BFD_FAKE_SECTION (bfd_plugin_fake_bss_section, NULL, "plug", 0,
-+		      SEC_ALLOC);
-+static asection bfd_plugin_fake_common_section
-+  = BFD_FAKE_SECTION (bfd_plugin_fake_common_section, NULL, NULL,
-+		      0, SEC_IS_COMMON);
-+
-+/* Get symbols from object only section.  */
-+
-+static void
-+bfd_plugin_get_symbols_in_object_only (bfd *abfd)
-+{
-+  struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
-+  const char *object_only_file;
-+  bfd *nbfd;
-+  long storage;
-+  long object_only_nsyms, added_nsyms, i;
-+  asymbol **object_only_syms, **added_syms;
-+
-+  plugin_data->object_only_syms = NULL;
-+  plugin_data->object_only_nsyms = 0;
-+
-+  if (abfd->sections == NULL && abfd->my_archive == NULL)
-+    {
-+      nbfd = bfd_openr (abfd->filename, NULL);
-+      if (nbfd == NULL)
-+	{
-+	  (*_bfd_error_handler)
-+	    (_("%s: failed to open to extract object only section: %s"),
-+	     abfd->filename, bfd_errmsg (bfd_get_error ()));
-+	  return;
-+	}
-+      else if (!bfd_check_format (nbfd, bfd_object))
-+	{
-+	  /* There is no object only section if it isn't a bfd_object
-+	     file.  */
-+	  bfd_close (nbfd);
-+	  return;
-+	}
-+    }
-+  else
-+    {
-+      if (!bfd_check_format (abfd, bfd_object))
-+	{
-+	  (*_bfd_error_handler)
-+	    (_("%pB: invalid file to extract object only section: %s"),
-+	     abfd, bfd_errmsg (bfd_get_error ()));
-+	  return;
-+	}
-+      nbfd = abfd;
-+    }
-+
-+  if (nbfd->lto_type == lto_mixed_object
-+      && (nbfd->flags & HAS_SYMS) != 0)
-+    {
-+      object_only_file = bfd_extract_object_only_section (nbfd);
-+      if (object_only_file == NULL)
-+	(*_bfd_error_handler)
-+	  (_("%pB: failed to extract object only section: %s"),
-+	   abfd, bfd_errmsg (bfd_get_error ()));
-+    }
-+  else
-+    object_only_file = NULL;
-+
-+  /* Close the new bfd we just opened.  */
-+  if (nbfd != abfd)
-+    bfd_close (nbfd);
-+
-+  /* Return if there is no object only section or there is no
-+     symbol in object only section.  */
-+  if (!object_only_file)
-+    return;
-+
-+  /* Open the file containing object only section.  */
-+  nbfd = bfd_openr (object_only_file, NULL);
-+  if (!bfd_check_format (nbfd, bfd_object))
-+    {
-+      (*_bfd_error_handler)
-+	(_("%pB: failed to open object only section: %s"),
-+	 abfd, bfd_errmsg (bfd_get_error ()));
-+      goto quit;
-+    }
-+
-+  storage = bfd_get_symtab_upper_bound (nbfd);
-+  if (storage <= 0)
-+    {
-+      if (storage < 0)
-+	(*_bfd_error_handler)
-+	  (_("%pB: failed to get symbol table in object only section: %s"),
-+	   abfd, bfd_errmsg (bfd_get_error ()));
-+
-+      goto quit;
-+    }
-+
-+  object_only_syms = (asymbol **) bfd_malloc (storage);
-+  object_only_nsyms = bfd_canonicalize_symtab (nbfd, object_only_syms);
-+
-+  /* FIXME: We waste some spaces if not all symbols are copied.  */
-+  added_syms = (asymbol **) bfd_alloc (abfd, storage);
-+  added_nsyms = 0;
-+
-+  /* Copy only global symbols from object only section.  */
-+  for (i = 0; i < object_only_nsyms; i++)
-+    {
-+      asection *sec = object_only_syms[i]->section;
-+      flagword flags = object_only_syms[i]->flags;
-+      asymbol *s;
-+
-+      if (bfd_is_com_section (sec))
-+	sec = &bfd_plugin_fake_common_section;
-+      else if (bfd_is_und_section (sec))
-+	;
-+      else if ((flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0)
-+	{
-+	  if ((sec->flags & SEC_CODE) != 0)
-+	    sec = &bfd_plugin_fake_text_section;
-+	  else if ((sec->flags & SEC_LOAD) != 0)
-+	    sec = &bfd_plugin_fake_data_section;
-+	  else
-+	    sec = &bfd_plugin_fake_bss_section;
-+	}
-+      else
-+	continue;
-+
-+      s = bfd_alloc (abfd, sizeof (asymbol));
-+      BFD_ASSERT (s);
-+      added_syms[added_nsyms++] = s;
-+
-+      s->section = sec;
-+      s->the_bfd = abfd;
-+      s->name = xstrdup (object_only_syms[i]->name);
-+      s->value = 0;
-+      s->flags = flags;
-+      s->udata.p = NULL;
-+    }
-+
-+  plugin_data->object_only_syms = added_syms;
-+  plugin_data->object_only_nsyms = added_nsyms;
-+
-+  free (object_only_syms);
-+
-+quit:
-+  /* Close and remove the object only section file.  */
-+  bfd_close (nbfd);
-+  unlink (object_only_file);
-+}
- 
- /* Register a claim-file handler, version 2. */
- 
-@@ -185,10 +337,13 @@ add_symbols (void * handle,
-   plugin_data->nsyms = nsyms;
-   plugin_data->syms = syms;
- 
--  if (nsyms != 0)
-+  abfd->tdata.plugin_data = plugin_data;
-+
-+  bfd_plugin_get_symbols_in_object_only (abfd);
-+
-+  if ((nsyms + plugin_data->object_only_nsyms) != 0)
-     abfd->flags |= HAS_SYMS;
- 
--  abfd->tdata.plugin_data = plugin_data;
-   return LDPS_OK;
- }
- 
-@@ -678,7 +833,8 @@ static long
- bfd_plugin_get_symtab_upper_bound (bfd *abfd)
- {
-   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
--  long nsyms = plugin_data->nsyms;
-+  /* Add symbols from object only section.  */
-+  long nsyms = plugin_data->nsyms + plugin_data->object_only_nsyms;
- 
-   BFD_ASSERT (nsyms >= 0);
- 
-@@ -712,18 +868,7 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
-   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
-   long nsyms = plugin_data->nsyms;
-   const struct ld_plugin_symbol *syms = plugin_data->syms;
--  static asection fake_text_section
--    = BFD_FAKE_SECTION (fake_text_section, NULL, "plug", 0,
--			SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS);
--  static asection fake_data_section
--    = BFD_FAKE_SECTION (fake_data_section, NULL, "plug", 0,
--			SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS);
--  static asection fake_bss_section
--    = BFD_FAKE_SECTION (fake_bss_section, NULL, "plug", 0,
--			SEC_ALLOC);
--  static asection fake_common_section
--    = BFD_FAKE_SECTION (fake_common_section, NULL, "plug", 0, SEC_IS_COMMON);
--  int i;
-+  int i, j;
- 
-   for (i = 0; i < nsyms; i++)
-     {
-@@ -736,10 +881,11 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
-       s->name = syms[i].name;
-       s->value = 0;
-       s->flags = convert_flags (&syms[i]);
-+      s->udata.p = NULL;
-       switch (syms[i].def)
- 	{
- 	case LDPK_COMMON:
--	  s->section = &fake_common_section;
-+	  s->section = &bfd_plugin_fake_common_section;
- 	  break;
- 	case LDPK_UNDEF:
- 	case LDPK_WEAKUNDEF:
-@@ -755,25 +901,28 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
- 	      case LDST_UNKNOWN:
- 		/* What is the best fake section for LDST_UNKNOWN?  */
- 	      case LDST_FUNCTION:
--		s->section = &fake_text_section;
-+		s->section = &bfd_plugin_fake_text_section;
- 		break;
- 	      case LDST_VARIABLE:
- 		if (syms[i].section_kind == LDSSK_BSS)
--		  s->section = &fake_bss_section;
-+		  s->section = &bfd_plugin_fake_bss_section;
- 		else
--		  s->section = &fake_data_section;
-+		  s->section = &bfd_plugin_fake_data_section;
- 		break;
- 	      }
- 	  else
--	    s->section = &fake_text_section;
-+	    s->section = &bfd_plugin_fake_text_section;
- 	  break;
- 	default:
- 	  BFD_ASSERT (0);
- 	}
--
--      s->udata.p = (void *) &syms[i];
-     }
- 
-+  /* Copy symbols from object only section.  */
-+  nsyms += plugin_data->object_only_nsyms;
-+  for (j = 0; j < plugin_data->object_only_nsyms; j++, i++)
-+    alocation[i] = plugin_data->object_only_syms[j];
-+
-   return nsyms;
- }
- 
-diff --git a/bfd/plugin.h b/bfd/plugin.h
-index 510689c96ba..f61e6168e2b 100644
---- a/bfd/plugin.h
-+++ b/bfd/plugin.h
-@@ -34,6 +34,8 @@ typedef struct plugin_data_struct
- {
-   int nsyms;
-   const struct ld_plugin_symbol *syms;
-+  int object_only_nsyms;
-+  asymbol **object_only_syms;
- }
- plugin_data_struct;
- 
-diff --git a/bfd/section.c b/bfd/section.c
-index 8456c73e8d0..e7674c9dc1a 100644
---- a/bfd/section.c
-+++ b/bfd/section.c
-@@ -661,6 +661,9 @@ EXTERNAL
- .#define BFD_COM_SECTION_NAME "*COM*"
- .#define BFD_IND_SECTION_NAME "*IND*"
- .
-+.{* GNU object-only section name.  *}
-+.#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
-+.
- .{* Pointer to the common section.  *}
- .#define bfd_com_section_ptr (&_bfd_std_section[0])
- .{* Pointer to the undefined section.  *}
-diff --git a/binutils/objcopy.c b/binutils/objcopy.c
-index f64417697cb..e2e6bd7ee83 100644
---- a/binutils/objcopy.c
-+++ b/binutils/objcopy.c
-@@ -1266,34 +1266,6 @@ is_specified_symbol (const char *name, htab_t htab)
-   return htab_find (htab, name) != NULL;
- }
- 
--/* Return a pointer to the symbol used as a signature for GROUP.  */
--
--static asymbol *
--group_signature (asection *group)
--{
--  bfd *abfd = group->owner;
--  Elf_Internal_Shdr *ghdr;
--
--  /* PR 20089: An earlier error may have prevented us from loading the symbol table.  */
--  if (isympp == NULL)
--    return NULL;
--
--  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
--    return NULL;
--
--  ghdr = &elf_section_data (group)->this_hdr;
--  if (ghdr->sh_link == elf_onesymtab (abfd))
--    {
--      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
--      Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd);
--
--      if (ghdr->sh_info > 0
--	  && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
--	return isympp[ghdr->sh_info - 1];
--    }
--  return NULL;
--}
--
- /* Return TRUE if the section is a DWO section.  */
- 
- static bool
-@@ -1438,7 +1410,7 @@ is_strip_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
-       const char *gname;
-       asection *elt, *first;
- 
--      gsym = group_signature (sec);
-+      gsym = bfd_group_signature (sec, isympp);
-       /* Strip groups without a valid signature.  */
-       if (gsym == NULL)
- 	return true;
-@@ -4398,7 +4370,7 @@ setup_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
- 
-   if ((isection->flags & SEC_GROUP) != 0)
-     {
--      asymbol *gsym = group_signature (isection);
-+      asymbol *gsym = bfd_group_signature (isection, isympp);
- 
-       if (gsym != NULL)
- 	{
-diff --git a/binutils/readelf.c b/binutils/readelf.c
-index 4f8f879cf91..949395483bb 100644
---- a/binutils/readelf.c
-+++ b/binutils/readelf.c
-@@ -5941,6 +5941,7 @@ get_os_specific_section_type_name (Filedata * filedata, unsigned int sh_type)
-     case SHT_GNU_ATTRIBUTES:          return "GNU_ATTRIBUTES";
-     case SHT_GNU_HASH:                return "GNU_HASH";
-     case SHT_GNU_LIBLIST:             return "GNU_LIBLIST";
-+    case SHT_GNU_OBJECT_ONLY:	      return "GNU_OBJECT_ONLY";
- 
-     case SHT_SUNW_move:               return "SUNW_MOVE";
-     case SHT_SUNW_COMDAT:             return "SUNW_COMDAT";
-diff --git a/gas/testsuite/gas/elf/section9.d b/gas/testsuite/gas/elf/section9.d
-index 63152fe4b4d..d7e97c014ac 100644
---- a/gas/testsuite/gas/elf/section9.d
-+++ b/gas/testsuite/gas/elf/section9.d
-@@ -4,4 +4,5 @@
- #...
- [ 	]*\[.*\][ 	]+\.gnu\.lto_main[ 	]+PROGBITS.*[ 	]+E[   ]+.*
- [ 	]*\[.*\][ 	]+\.gnu\.lto_\.pureconst[ 	]+PROGBITS.*[ 	]+E[   ]+.*
-+[ 	]*\[.*\][ 	]+\.gnu_object_only[ 	]+GNU_OBJECT_ONLY.*[ 	]+E[   ]+.*
- #pass
-diff --git a/gas/testsuite/gas/elf/section9.s b/gas/testsuite/gas/elf/section9.s
-index 6b8b1074ca3..abcdea10aad 100644
---- a/gas/testsuite/gas/elf/section9.s
-+++ b/gas/testsuite/gas/elf/section9.s
-@@ -2,3 +2,5 @@
- 	.byte 0,0,0,0
- 	.section .gnu.lto_.pureconst,"",%progbits
- 	.byte 0,0,0,0
-+	.section .gnu_object_only
-+	.byte 0,0,0,0
-diff --git a/include/elf/common.h b/include/elf/common.h
-index 6077db7a8b7..b0b54d87ab4 100644
---- a/include/elf/common.h
-+++ b/include/elf/common.h
-@@ -572,6 +572,7 @@
- #define SHT_GNU_HASH	             0x6ffffff6	/* GNU style symbol hash table */
- #define SHT_GNU_LIBLIST	             0x6ffffff7	/* List of prelink dependencies */
- #define SHT_CHECKSUM	             0x6ffffff8	/* Checksum for DSO content.  */
-+#define SHT_GNU_OBJECT_ONLY	     0x6ffffff9	/* Object only */
- 
- #define SHT_SUNW_move	             0x6ffffffa
- #define SHT_SUNW_COMDAT              0x6ffffffb
-diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
-index faa0d3ecd79..ae79961ada1 100644
---- a/ld/emultempl/aarch64elf.em
-+++ b/ld/emultempl/aarch64elf.em
-@@ -309,7 +309,7 @@ gld${EMULATION_NAME}_finish (void)
- 	}
-     }
- 
--  finish_default ();
-+  ldelf_finish ();
- }
- 
- /* This is a convenient point to tell BFD about target specific flags.
-diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
-index 6ecacb76a10..5ae2587a653 100644
---- a/ld/emultempl/alphaelf.em
-+++ b/ld/emultempl/alphaelf.em
-@@ -104,7 +104,7 @@ alpha_finish (void)
-   if (limit_32bit)
-     elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
- 
--  finish_default ();
-+  ldelf_finish ();
- }
- EOF
- 
-diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
-index dc2cd9f1139..02a97e7c1ff 100644
---- a/ld/emultempl/armelf.em
-+++ b/ld/emultempl/armelf.em
-@@ -456,7 +456,7 @@ gld${EMULATION_NAME}_finish (void)
- 	}
-     }
- 
--  finish_default ();
-+  ldelf_finish ();
- 
-   if (params.thumb_entry_symbol)
-     {
-diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
-index 7696a9050d9..0945702bfb6 100644
---- a/ld/emultempl/avrelf.em
-+++ b/ld/emultempl/avrelf.em
-@@ -227,7 +227,7 @@ avr_finish (void)
- 	elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
-     }
- 
--  finish_default ();
-+  ldelf_finish ();
- }
- EOF
- 
-diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
-index 4d431995d2e..0bad25d3a46 100644
---- a/ld/emultempl/elf.em
-+++ b/ld/emultempl/elf.em
-@@ -1173,6 +1173,7 @@ LDEMUL_BEFORE_PLACE_ORPHANS=${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orp
- LDEMUL_AFTER_ALLOCATION=${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}
- LDEMUL_SET_OUTPUT_ARCH=${LDEMUL_SET_OUTPUT_ARCH-ldelf_set_output_arch}
- LDEMUL_BEFORE_ALLOCATION=${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}
-+LDEMUL_FINISH=${LDEMUL_FINISH-ldelf_finish}
- LDEMUL_OPEN_DYNAMIC_ARCHIVE=${LDEMUL_OPEN_DYNAMIC_ARCHIVE-ldelf_open_dynamic_archive}
- LDEMUL_PLACE_ORPHAN=${LDEMUL_PLACE_ORPHAN-ldelf_place_orphan}
- LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
-diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
-index acd673a7b84..529a5920920 100644
---- a/ld/emultempl/ppc32elf.em
-+++ b/ld/emultempl/ppc32elf.em
-@@ -238,7 +238,7 @@ ppc_finish (void)
-     lang_for_each_statement (no_zero_padding);
-   if (!ppc_finish_symbols (&link_info))
-     einfo (_("%X%P: ppc_finish_symbols problem %E\n"));
--  finish_default ();
-+  ldelf_finish ();
- }
- 
- EOF
-diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
-index f9ace66a5b2..1e6ae7af738 100644
---- a/ld/emultempl/ppc64elf.em
-+++ b/ld/emultempl/ppc64elf.em
-@@ -616,7 +616,7 @@ gld${EMULATION_NAME}_finish (void)
-   fflush (stderr);
-   free (msg);
- 
--  finish_default ();
-+  ldelf_finish ();
- }
- 
- 
-diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em
-index dd8d259a31f..76776ba2555 100644
---- a/ld/emultempl/spuelf.em
-+++ b/ld/emultempl/spuelf.em
-@@ -432,7 +432,7 @@ gld${EMULATION_NAME}_finish (void)
- 	einfo (_("%P: --auto-overlay ignored with zero local store range\n"));
-     }
- 
--  finish_default ();
-+  ldelf_finish ();
- }
- 
- static char *
-diff --git a/ld/ld.h b/ld/ld.h
-index 48d34bc6acd..254f0a097bb 100644
---- a/ld/ld.h
-+++ b/ld/ld.h
-@@ -306,6 +306,12 @@ typedef struct
-   /* If set, store plugin intermediate files permanently.  */
-   bool plugin_save_temps;
- 
-+  /* If set, if the .gnu_object_only section should be created.  */
-+  bool emit_gnu_object_only;
-+
-+  /* If set, if the .gnu_object_only section is being created.  */
-+  bool emitting_gnu_object_only;
-+
-   /* If set, print discarded sections in map file output.  */
-   bool print_map_discarded;
- 
-diff --git a/ld/ldelf.c b/ld/ldelf.c
-index 4cbfc19c161..a66d1d21394 100644
---- a/ld/ldelf.c
-+++ b/ld/ldelf.c
-@@ -63,6 +63,7 @@ static lang_input_statement_type *global_found;
- static struct stat global_stat;
- static struct bfd_link_needed_list *global_vercheck_needed;
- static bool global_vercheck_failed;
-+static bool orphan_init_done;
- 
- void
- ldelf_after_parse (void)
-@@ -2101,7 +2102,7 @@ elf_orphan_compatible (asection *in, asection *out)
- lang_output_section_statement_type *
- ldelf_place_orphan (asection *s, const char *secname, int constraint)
- {
--  static struct orphan_save hold[] =
-+  static struct orphan_save orig_hold[] =
-     {
-       { ".text",
- 	SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
-@@ -2131,6 +2132,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
- 	SEC_HAS_CONTENTS,
- 	0, 0, 0, 0 },
-     };
-+  static struct orphan_save hold[ARRAY_SIZE (orig_hold)];
-   enum orphan_save_index
-     {
-       orphan_text = 0,
-@@ -2143,7 +2145,6 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
-       orphan_sdata,
-       orphan_nonalloc
-     };
--  static int orphan_init_done = 0;
-   struct orphan_save *place;
-   lang_output_section_statement_type *after;
-   lang_output_section_statement_type *os;
-@@ -2272,16 +2273,23 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
- 
-   if (!orphan_init_done)
-     {
--      struct orphan_save *ho;
-+      struct orphan_save *ho, *horig;
- 
-       for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
-+      for (ho = hold, horig = orig_hold;
-+	   ho < hold + ARRAY_SIZE (hold);
-+	   ++ho, ++horig)
-+	{
-+	  *ho = *horig;
-+	  if (ho->name != NULL)
- 	if (ho->name != NULL)
- 	  {
- 	    ho->os = lang_output_section_find (ho->name);
- 	    if (ho->os != NULL && ho->os->flags == 0)
- 	      ho->os->flags = ho->flags;
- 	  }
--      orphan_init_done = 1;
-+	}
-+      orphan_init_done = true;
-     }
- 
-   /* If this is a final link, then always put .gnu.warning.SYMBOL
-@@ -2428,3 +2436,13 @@ ldelf_set_output_arch (void)
-   if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour)
-     elf_link_info (link_info.output_bfd) = &link_info;
- }
-+
-+void
-+ldelf_finish (void)
-+{
-+  /* Support the object-only output.  */
-+  if (config.emit_gnu_object_only)
-+    orphan_init_done = false;
-+
-+  finish_default ();
-+}
-diff --git a/ld/ldelf.h b/ld/ldelf.h
-index 96fb1e5b6a8..a6498cf2758 100644
---- a/ld/ldelf.h
-+++ b/ld/ldelf.h
-@@ -21,6 +21,7 @@
- extern const char *ldelf_emit_note_gnu_build_id;
- extern const char *ldelf_emit_note_fdo_package_metadata;
- 
-+extern void ldelf_finish (void);
- extern void ldelf_after_parse (void);
- extern bool ldelf_load_symbols (lang_input_statement_type *);
- extern void ldelf_before_plugin_all_symbols_read (int, int, int, int,
-diff --git a/ld/ldexp.c b/ld/ldexp.c
-index f0b8d7cb748..035cef60448 100644
---- a/ld/ldexp.c
-+++ b/ld/ldexp.c
-@@ -1699,14 +1699,15 @@ align_n (bfd_vma value, bfd_vma align)
- }
- 
- void
--ldexp_init (void)
-+ldexp_init (bool object_only)
- {
-   /* The value "13" is ad-hoc, somewhat related to the expected number of
-      assignments in a linker script.  */
--  if (!bfd_hash_table_init_n (&definedness_table,
--			      definedness_newfunc,
--			      sizeof (struct definedness_hash_entry),
--			      13))
-+  if (!object_only
-+      && !bfd_hash_table_init_n (&definedness_table,
-+				 definedness_newfunc,
-+				 sizeof (struct definedness_hash_entry),
-+				 13))
-     einfo (_("%F%P: can not create hash table: %E\n"));
- }
- 
-@@ -1763,7 +1764,8 @@ ldexp_is_final_sym_absolute (const struct bfd_link_hash_entry *h)
- }
- 
- void
--ldexp_finish (void)
-+ldexp_finish (bool object_only)
- {
--  bfd_hash_table_free (&definedness_table);
-+  if (!object_only)
-+    bfd_hash_table_free (&definedness_table);
- }
-diff --git a/ld/ldexp.h b/ld/ldexp.h
-index f7d2cba4f4c..16953caf7cd 100644
---- a/ld/ldexp.h
-+++ b/ld/ldexp.h
-@@ -250,9 +250,9 @@ fill_type *exp_get_fill
-   (etree_type *, fill_type *, char *);
- bfd_vma exp_get_abs_int
-   (etree_type *, int, char *);
--void ldexp_init (void);
-+void ldexp_init (bool);
- void ldexp_finalize_syms (void);
- bool ldexp_is_final_sym_absolute (const struct bfd_link_hash_entry *);
--void ldexp_finish (void);
-+void ldexp_finish (bool);
- 
- #endif
-diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 9bf5014ad95..530a5fef5e3 100644
---- a/ld/ldfile.c
-+++ b/ld/ldfile.c
-@@ -532,7 +532,9 @@ ldfile_try_open_bfd (const char *attempt,
-       && !no_more_claiming
-       && bfd_check_format (entry->the_bfd, bfd_object))
-     plugin_maybe_claim (entry);
-+  else
- #endif /* BFD_SUPPORTS_PLUGINS */
-+    cmdline_check_object_only_section (entry->the_bfd, false);
- 
-   /* It opened OK, the format checked out, and the plugins have had
-      their chance to claim it, so this is success.  */
-diff --git a/ld/ldlang.c b/ld/ldlang.c
-index 4c8d4e7a7fc..e1e491732a9 100644
---- a/ld/ldlang.c
-+++ b/ld/ldlang.c
-@@ -37,6 +37,7 @@
- #include "ldctor.h"
- #include "ldfile.h"
- #include "ldemul.h"
-+#include "ldwrite.h"
- #include "fnmatch.h"
- #include "demangle.h"
- #include "hashtab.h"
-@@ -47,6 +48,9 @@
- #include "plugin.h"
- #endif
- 
-+/* FIXME: Put it here to avoid NAME conflict from ldgram.h.  */
-+#include "elf-bfd.h"
-+
- #ifndef offsetof
- #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
- #endif
-@@ -76,6 +80,9 @@ static lang_statement_list_type **stat_save_ptr = &stat_save[0];
- static struct unique_sections *unique_section_list;
- static struct asneeded_minfo *asneeded_list_head;
- static unsigned int opb_shift = 0;
-+static cmdline_list_type cmdline_object_only_file_list;
-+static cmdline_list_type cmdline_object_only_archive_list;
-+static cmdline_list_type cmdline_temp_object_only_list;
- 
- /* Forward declarations.  */
- static void exp_init_os (etree_type *);
-@@ -99,6 +106,10 @@ static void lang_do_version_exports_section (void);
- static void lang_finalize_version_expr_head
-   (struct bfd_elf_version_expr_head *);
- static void lang_do_memory_regions (bool);
-+static void cmdline_lists_init (void);
-+static void cmdline_get_object_only_input_files (void);
-+static void print_cmdline_list (cmdline_union_type *);
-+static bool cmdline_on_object_only_archive_list_p (bfd *);
- 
- /* Exported variables.  */
- const char *output_target;
-@@ -1353,15 +1364,20 @@ output_section_statement_table_free (void)
- /* Build enough state so that the parser can build its tree.  */
- 
- void
--lang_init (void)
-+lang_init (bool object_only)
- {
--  obstack_begin (&stat_obstack, 1000);
--  obstack_init (&pt_obstack);
-+  if (!object_only)
-+    {
-+      obstack_begin (&stat_obstack, 1000);
-+      obstack_init (&pt_obstack);
-+    }
- 
-   stat_ptr = &statement_list;
- 
-   output_section_statement_table_init ();
- 
-+  cmdline_lists_init ();
-+
-   lang_list_init (stat_ptr);
- 
-   lang_list_init (&input_file_chain);
-@@ -3142,6 +3158,12 @@ load_symbols (lang_input_statement_type *entry,
- 		  loaded = false;
- 		}
- 
-+	      if (config.emitting_gnu_object_only)
-+		{
-+		  if (!cmdline_on_object_only_archive_list_p (member))
-+		    continue;
-+		}
-+
- 	      subsbfd = member;
- 	      if (!(*link_info.callbacks
- 		    ->add_archive_element) (&link_info, member,
-@@ -8343,7 +8365,42 @@ lang_process (void)
- 	    }
- 	}
-     }
-+  else
- #endif /* BFD_SUPPORTS_PLUGINS */
-+    if (bfd_link_relocatable (&link_info))
-+    {
-+      /* Check if .gnu_object_only section should be created.  */
-+      bfd *p;
-+      int object_type;
-+
-+      object_type = 0;
-+      for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link.next)
-+	{
-+	  enum bfd_lto_object_type lto_type = bfd_get_lto_type (p);
-+	  /* NB: Treat fat IR object as IR object here.  */
-+	  if (lto_type == lto_fat_ir_object)
-+	    lto_type = lto_slim_ir_object;
-+	  object_type |= 1 << lto_type;
-+	  if ((object_type & (1 << lto_mixed_object)) != 0
-+	      || ((object_type
-+		   & (1 << lto_non_ir_object
-+		      | 1 << lto_slim_ir_object))
-+		  == (1 << lto_non_ir_object | 1 << lto_slim_ir_object)))
-+	    {
-+	      config.emit_gnu_object_only = true;
-+	      break;
-+	    }
-+	}
-+
-+      if (verbose
-+	  && (cmdline_object_only_file_list.head
-+	      || cmdline_object_only_archive_list.head))
-+	{
-+	  info_msg (_("Object-only input files:\n "));
-+	  print_cmdline_list (cmdline_object_only_file_list.head);
-+	  print_cmdline_list (cmdline_object_only_archive_list.head);
-+	}
-+    }
- 
-   struct bfd_sym_chain **sym = &link_info.gc_sym_list;
-   while (*sym)
-@@ -10022,3 +10079,967 @@ lang_print_memory_usage (void)
-       printf ("\n");
-     }
- }
-+
-+static void
-+cmdline_lists_init (void)
-+{
-+  cmdline_object_only_file_list.tail
-+    = &cmdline_object_only_file_list.head;
-+  cmdline_object_only_archive_list.tail
-+    = &cmdline_object_only_archive_list.head;
-+  cmdline_temp_object_only_list.tail
-+    = &cmdline_temp_object_only_list.head;
-+}
-+
-+/* Allocate an item with TYPE and DATA.  */
-+
-+static cmdline_union_type *
-+cmdline_list_new (cmdline_enum_type type, void *data)
-+{
-+  cmdline_union_type *new_opt;
-+
-+  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
-+  new_opt->header.type = type;
-+  switch (type)
-+    {
-+    default:
-+      break;
-+    case cmdline_is_file_enum:
-+      new_opt->file.filename = (const char *) data;
-+      break;
-+    case cmdline_is_bfd_enum:
-+      new_opt->abfd.abfd = (bfd *) data;
-+      break;
-+    }
-+  return new_opt;
-+}
-+
-+/* Append an item with TYPE and DATA to LIST.  */
-+
-+static void
-+cmdline_list_append (cmdline_list_type *list, cmdline_enum_type type,
-+		     void *data)
-+{
-+  cmdline_union_type *new_opt = cmdline_list_new (type, data);
-+  new_opt->header.next = NULL;
-+  *list->tail = new_opt;
-+  list->tail = &new_opt->header.next;
-+}
-+
-+static void
-+print_cmdline_list (cmdline_union_type *c)
-+{
-+  for (; c != NULL; c = c->header.next)
-+    switch (c->header.type)
-+      {
-+      default:
-+	abort ();
-+      case cmdline_is_file_enum:
-+	info_msg (" %s", c->file.filename);
-+	break;
-+      case cmdline_is_bfd_enum:
-+	info_msg (" [%B]", c->abfd.abfd);
-+	break;
-+      }
-+
-+  info_msg ("\n");
-+}
-+
-+/* Return TRUE if ABFD is on cmdline_object_only_archive_list.  */
-+
-+static bool
-+cmdline_on_object_only_archive_list_p (bfd *abfd)
-+{
-+  cmdline_union_type *c, *next;
-+  bfd *archive, *obfd, *oarchive;
-+  ufile_ptr origin = abfd->origin;
-+
-+  archive = abfd->my_archive;
-+  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
-+    {
-+      if (c->header.type != cmdline_is_bfd_enum)
-+	abort ();
-+
-+      next = c->header.next;
-+      obfd = c->abfd.abfd;
-+      oarchive = obfd->my_archive;
-+
-+      /* The list is grouped by archive file name and sorted by member
-+	 origin.  */
-+      if (strcmp (archive->filename, oarchive->filename) != 0)
-+	continue;
-+
-+      if (origin == obfd->origin)
-+	return true;
-+      else if (origin < obfd->origin)
-+	return false;
-+    }
-+
-+  return false;
-+}
-+
-+/* Append an item with TYPE and DATA to cmdline_object_only_file_list
-+   or cmdline_object_only_archive_list if needed.  */
-+
-+static void
-+cmdline_object_only_list_append (cmdline_enum_type type, void *data)
-+{
-+  cmdline_union_type *c;
-+  cmdline_union_type *new_opt, *next, **prev;
-+  bfd *abfd, *archive;
-+  bfd *obfd, *oarchive;
-+  bfd *nbfd, *narchive;
-+  ufile_ptr origin, norigin;
-+
-+  /* Put it on cmdline_object_only_file_list if it isn't an archive
-+     member.  */
-+  switch (type)
-+    {
-+    default:
-+      abort ();
-+    case cmdline_is_bfd_enum:
-+      abfd = (bfd *) data;
-+      archive = abfd->my_archive;
-+      if (archive)
-+	break;
-+      /* Fallthru */
-+    case cmdline_is_file_enum:
-+      cmdline_list_append (&cmdline_object_only_file_list, type, data);
-+      return;
-+    }
-+
-+  /* Put archive member on cmdline_object_only_archive_list and sort
-+     the list by archive name and archive member origin.  */
-+  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
-+  new_opt->header.type = cmdline_is_bfd_enum;
-+  new_opt->header.next = NULL;
-+  new_opt->abfd.abfd = (bfd *) data;
-+
-+  c = cmdline_object_only_archive_list.head;
-+  if (c == NULL)
-+    {
-+      cmdline_object_only_archive_list.head = new_opt;
-+      cmdline_object_only_archive_list.tail = &new_opt->header.next;
-+      return;
-+    }
-+
-+  prev = NULL;
-+  origin = abfd->origin;
-+  for (; c != NULL; c = next)
-+    {
-+      if (c->header.type != cmdline_is_bfd_enum)
-+	abort ();
-+
-+      next = c->header.next;
-+
-+      obfd = c->abfd.abfd;
-+      oarchive = obfd->my_archive;
-+
-+      if (strcmp (archive->filename, oarchive->filename) == 0)
-+	{
-+	  bool after;
-+
-+	  if (origin < obfd->origin)
-+	    {
-+	      /* Insert it before the current.  */
-+	      new_opt->header.next = c;
-+	      if (prev)
-+		*prev = new_opt;
-+	      else
-+		cmdline_object_only_archive_list.head = new_opt;
-+	      return;
-+	    }
-+
-+	  after = true;
-+
-+	  /* Check origin.  */
-+	  while (next)
-+	    {
-+	      if (next->header.type != cmdline_is_bfd_enum)
-+		abort ();
-+
-+	      nbfd = next->abfd.abfd;
-+	      norigin = nbfd->origin;
-+	      if (origin > norigin)
-+		{
-+		  /* Insert it after NEXT.  */
-+		  break;
-+		}
-+
-+	      narchive = nbfd->my_archive;
-+	      if (strcmp (archive->filename, narchive->filename) != 0)
-+		{
-+		  /* Insert it befor NEXT.  */
-+		  after = false;
-+		  break;
-+		}
-+
-+	      c = next;
-+	      next = next->header.next;
-+	    }
-+
-+	  if (after && next)
-+	    {
-+	      c = next;
-+	      next = next->header.next;
-+	    }
-+
-+	  if (*cmdline_object_only_archive_list.tail == c->header.next)
-+	    cmdline_object_only_archive_list.tail
-+	      = &new_opt->header.next;
-+
-+	  prev = &c->header.next;
-+	  new_opt->header.next = next;
-+	  *prev = new_opt;
-+	  return;
-+	}
-+
-+      prev = &c->header.next;
-+    }
-+
-+  *cmdline_object_only_archive_list.tail = new_opt;
-+  cmdline_object_only_archive_list.tail = &new_opt->header.next;
-+}
-+
-+/* Get object-only input files.  */
-+
-+static void
-+cmdline_get_object_only_input_files (void)
-+{
-+  cmdline_union_type *c, *next;
-+  bfd *abfd, *archive;
-+  bfd *nbfd, *narchive;
-+
-+  /* Add files first.  */
-+  for (c = cmdline_object_only_file_list.head;
-+       c != NULL; c = c->header.next)
-+    switch (c->header.type)
-+      {
-+      default:
-+	abort ();
-+      case cmdline_is_file_enum:
-+	lang_add_input_file (c->file.filename,
-+			     lang_input_file_is_file_enum, NULL);
-+	break;
-+      case cmdline_is_bfd_enum:
-+	abfd = c->abfd.abfd;
-+	if (abfd->my_archive)
-+	  abort ();
-+	lang_add_input_file (abfd->filename,
-+			     lang_input_file_is_file_enum, NULL);
-+	break;
-+      }
-+
-+  /* Add archive members next.  */
-+  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
-+    {
-+      if (c->header.type != cmdline_is_bfd_enum)
-+	abort ();
-+
-+      next = c->header.next;
-+
-+      abfd = c->abfd.abfd;
-+      archive = abfd->my_archive;
-+
-+      /* Add the first archive of the archive member group.  */
-+      lang_add_input_file (archive->filename,
-+			   lang_input_file_is_file_enum, NULL);
-+
-+      /* Skip the rest members in the archive member group.  */
-+      do
-+	{
-+	  if (!next)
-+	    break;
-+
-+	  if (next->header.type != cmdline_is_bfd_enum)
-+	    abort ();
-+
-+	  next = next->header.next;
-+	  if (!next)
-+	    break;
-+	  nbfd = next->abfd.abfd;
-+	  narchive = nbfd->my_archive;
-+	}
-+      while (strcmp (archive->filename, narchive->filename) == 0);
-+    }
-+}
-+
-+struct cmdline_arg
-+{
-+  bfd *obfd;
-+  asymbol **isympp;
-+  int status;
-+};
-+
-+/* Create a section in OBFD with the same
-+   name and attributes as ISECTION in IBFD.  */
-+
-+static void
-+setup_section (bfd *ibfd, sec_ptr isection, void *p)
-+{
-+  struct cmdline_arg *arg = (struct cmdline_arg *) p;
-+  bfd *obfd = arg->obfd;
-+  asymbol **isympp = arg->isympp;
-+  const char *name = isection->name;
-+  sec_ptr osection;
-+  const char *err;
-+
-+  /* Skip the object-only section.  */
-+  if (ibfd->object_only_section == isection)
-+    return;
-+
-+  /* If we have already failed earlier on, do not keep on generating
-+     complaints now.  */
-+  if (arg->status)
-+    return;
-+
-+  osection = bfd_make_section_anyway_with_flags (obfd, name,
-+						 isection->flags);
-+
-+  if (osection == NULL)
-+    {
-+      err = _("failed to create output section");
-+      goto loser;
-+    }
-+
-+  osection->size = isection->size;
-+  osection->vma = isection->vma;
-+  osection->lma = isection->lma;
-+  osection->alignment_power = isection->alignment_power;
-+
-+  /* Copy merge entity size.  */
-+  osection->entsize = isection->entsize;
-+
-+  /* This used to be mangle_section; we do here to avoid using
-+     bfd_get_section_by_name since some formats allow multiple
-+     sections with the same name.  */
-+  isection->output_section = osection;
-+  isection->output_offset = 0;
-+
-+  if ((isection->flags & SEC_GROUP) != 0)
-+    {
-+      asymbol *gsym = bfd_group_signature (isection, isympp);
-+
-+      if (gsym != NULL)
-+	{
-+	  gsym->flags |= BSF_KEEP;
-+	  if (ibfd->xvec->flavour == bfd_target_elf_flavour)
-+	    elf_group_id (isection) = gsym;
-+	}
-+    }
-+
-+  /* Allow the BFD backend to copy any private data it understands
-+     from the input section to the output section.  */
-+  if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
-+    {
-+      err = _("failed to copy private data");
-+      goto loser;
-+    }
-+
-+  /* All went well.  */
-+  return;
-+
-+loser:
-+  arg->status = 1;
-+  einfo (_("%P%F: setup_section: %s: %s\n"), err, name);
-+}
-+
-+/* Copy the data of input section ISECTION of IBFD
-+   to an output section with the same name in OBFD.
-+   If stripping then don't copy any relocation info.  */
-+
-+static void
-+copy_section (bfd *ibfd, sec_ptr isection, void *p)
-+{
-+  struct cmdline_arg *arg = (struct cmdline_arg *) p;
-+  bfd *obfd = arg->obfd;
-+  asymbol **isympp = arg->isympp;
-+  arelent **relpp;
-+  long relcount;
-+  sec_ptr osection;
-+  bfd_size_type size;
-+  long relsize;
-+  flagword flags;
-+  const char *err;
-+
-+  /* Skip the object-only section.  */
-+  if (ibfd->object_only_section == isection)
-+    return;
-+
-+  /* If we have already failed earlier on, do not keep on generating
-+     complaints now.  */
-+  if (arg->status)
-+    return;
-+
-+  flags = bfd_section_flags (isection);
-+  if ((flags & SEC_GROUP) != 0)
-+    return;
-+
-+  osection = isection->output_section;
-+  size = bfd_section_size (isection);
-+
-+  if (size == 0 || osection == 0)
-+    return;
-+
-+  relsize = bfd_get_reloc_upper_bound (ibfd, isection);
-+
-+  if (relsize < 0)
-+    {
-+      /* Do not complain if the target does not support relocations.  */
-+      if (relsize == -1
-+	  && bfd_get_error () == bfd_error_invalid_operation)
-+	relsize = 0;
-+      else
-+	{
-+	  err = bfd_errmsg (bfd_get_error ());
-+	  goto loser;
-+	}
-+    }
-+
-+  if (relsize == 0)
-+    bfd_set_reloc (obfd, osection, NULL, 0);
-+  else
-+    {
-+      relpp = (arelent **) xmalloc (relsize);
-+      relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
-+      if (relcount < 0)
-+	{
-+	  err = _("relocation count is negative");
-+	  goto loser;
-+	}
-+
-+      bfd_set_reloc (obfd, osection,
-+		     relcount == 0 ? NULL : relpp, relcount);
-+      if (relcount == 0)
-+	free (relpp);
-+    }
-+
-+  if (bfd_section_flags (isection) & SEC_HAS_CONTENTS)
-+    {
-+      bfd_byte *memhunk = NULL;
-+
-+      if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
-+	{
-+	  err = bfd_errmsg (bfd_get_error ());
-+	  goto loser;
-+	}
-+
-+      if (!bfd_set_section_contents (obfd, osection, memhunk, 0, size))
-+	{
-+	  err = bfd_errmsg (bfd_get_error ());
-+	  goto loser;
-+	}
-+      free (memhunk);
-+    }
-+
-+  /* All went well.  */
-+  return;
-+
-+loser:
-+  einfo (_("%P%F: copy_section: %s: %s\n"), err, isection->name);
-+}
-+/* Open the temporary bfd created in the same directory as PATH.  */
-+
-+static bfd *
-+cmdline_fopen_temp (const char *path, const char *target,
-+		    const char *mode)
-+{
-+#define template "ldXXXXXX"
-+  const char *slash = strrchr (path, '/');
-+  char *tmpname;
-+  size_t len;
-+  int fd;
-+
-+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
-+  {
-+    /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
-+    char *bslash = strrchr (path, '\\');
-+
-+    if (slash == NULL || (bslash != NULL && bslash > slash))
-+      slash = bslash;
-+    if (slash == NULL && path[0] != '\0' && path[1] == ':')
-+      slash = path + 1;
-+  }
-+#endif
-+
-+  if (slash != (char *) NULL)
-+    {
-+      len = slash - path;
-+      tmpname = (char *) xmalloc (len + sizeof (template) + 2);
-+      memcpy (tmpname, path, len);
-+
-+#ifdef HAVE_DOS_BASED_FILE_SYSTEM
-+      /* If tmpname is "X:", appending a slash will make it a root
-+	 directory on drive X, which is NOT the same as the current
-+	 directory on drive X.  */
-+      if (len == 2 && tmpname[1] == ':')
-+	tmpname[len++] = '.';
-+#endif
-+      tmpname[len++] = '/';
-+    }
-+  else
-+    {
-+      tmpname = (char *) xmalloc (sizeof (template));
-+      len = 0;
-+    }
-+
-+  memcpy (tmpname + len, template, sizeof (template));
-+#undef template
-+
-+#ifdef HAVE_MKSTEMP
-+  fd = mkstemp (tmpname);
-+#else
-+  tmpname = mktemp (tmpname);
-+  if (tmpname == NULL)
-+    return NULL;
-+  fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
-+#endif
-+  if (fd == -1)
-+    return NULL;
-+  return bfd_fopen (tmpname, target, mode, fd);
-+}
-+
-+/* Add the object-only section.  */
-+
-+static void
-+cmdline_add_object_only_section (bfd_byte *contents, size_t size)
-+{
-+  bfd_vma start;
-+  flagword flags;
-+  enum bfd_architecture iarch;
-+  unsigned int imach;
-+  long symcount;
-+  long symsize;
-+  asymbol **isympp = NULL;
-+  asymbol **osympp = NULL;
-+  bfd *obfd = NULL, *ibfd;
-+  const char *err;
-+  struct arg
-+    {
-+      bfd *obfd;
-+      asymbol **isympp;
-+      int status;
-+    } arg;
-+  char **matching;
-+  char *ofilename = NULL;
-+  asection *sec;
-+
-+  ibfd = bfd_openr (output_filename, output_target);
-+  if (!ibfd)
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  if (!bfd_check_format_matches (ibfd, bfd_object, &matching))
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  obfd = cmdline_fopen_temp (output_filename, output_target, FOPEN_WB);
-+  if (!obfd)
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+  /* To be used after bfd_close ().  */
-+  ofilename = xstrdup (bfd_get_filename (obfd));
-+
-+  if (!bfd_set_format (obfd, bfd_object))
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  /* Copy the start address, flags and architecture of input file to
-+     output file.  */
-+  flags = bfd_get_file_flags (ibfd);
-+  start = bfd_get_start_address (ibfd);
-+  iarch = bfd_get_arch (ibfd);
-+  imach = bfd_get_mach (ibfd);
-+  if (!bfd_set_start_address (obfd, start)
-+      || !bfd_set_file_flags (obfd, flags)
-+      || !bfd_set_arch_mach (obfd, iarch, imach))
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  symsize = bfd_get_symtab_upper_bound (ibfd);
-+  if (symsize < 0)
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  isympp = (asymbol **) xmalloc (symsize);
-+  symcount = bfd_canonicalize_symtab (ibfd, isympp);
-+  if (symcount < 0)
-+    {
-+      err = bfd_errmsg (bfd_get_error ());
-+      goto loser;
-+    }
-+
-+  arg.obfd = obfd;
-+  arg.isympp = isympp;
-+  arg.status = 0;
-+
-+  /* BFD mandates that all output sections be created and sizes set before
-+     any output is done.  Thus, we traverse all sections multiple times.  */
-+  bfd_map_over_sections (ibfd, setup_section, &arg);
-+
-+  if (arg.status)
-+    {
-+      err = _("error setting up sections");
-+      goto loser;
-+    }
-+
-+  /* Allow the BFD backend to copy any private data it understands
-+     from the input section to the output section.  */
-+  if (! bfd_copy_private_header_data (ibfd, obfd))
-+    {
-+      err = _("error copying private header data");
-+      goto loser;
-+    }
-+
-+  /* Create the object-only section.  */
-+  sec = bfd_make_section_with_flags (obfd,
-+				     GNU_OBJECT_ONLY_SECTION_NAME,
-+				     (SEC_HAS_CONTENTS
-+				      | SEC_READONLY
-+				      | SEC_DATA
-+				      | SEC_LINKER_CREATED));
-+  if (sec == NULL)
-+    {
-+      err = _("can't create object-only section");
-+      goto loser;
-+    }
-+
-+  if (! bfd_set_section_size (sec, size))
-+    {
-+      err = _("can't set object-only section size");
-+      goto loser;
-+    }
-+
-+  if (ibfd->object_only_section)
-+    {
-+      /* Filter out the object-only section symbol.  */
-+      long src_count = 0, dst_count = 0;
-+      asymbol **from, **to;
-+
-+      osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
-+      from = isympp;
-+      to = osympp;
-+      for (; src_count < symcount; src_count++)
-+	{
-+	  asymbol *sym = from[src_count];
-+	  if (bfd_asymbol_section (sym) != ibfd->object_only_section)
-+	    to[dst_count++] = sym;
-+	}
-+      to[dst_count] = NULL;
-+      symcount = dst_count;
-+      bfd_set_symtab (obfd, osympp, symcount);
-+    }
-+  else
-+    bfd_set_symtab (obfd, isympp, symcount);
-+
-+  /* This has to happen after the symbol table has been set.  */
-+  bfd_map_over_sections (ibfd, copy_section, &arg);
-+
-+  if (arg.status)
-+    {
-+      err = _("error copying sections");
-+      goto loser;
-+    }
-+
-+  /* Copy the object-only section to the output.  */
-+  if (! bfd_set_section_contents (obfd, sec, contents, 0, size))
-+    {
-+      err = _("error adding object-only section");
-+      goto loser;
-+    }
-+
-+  /* Allow the BFD backend to copy any private data it understands
-+     from the input BFD to the output BFD.  This is done last to
-+     permit the routine to look at the filtered symbol table, which is
-+     important for the ECOFF code at least.  */
-+  if (! bfd_copy_private_bfd_data (ibfd, obfd))
-+    {
-+      err = _("error copying private BFD data");
-+      goto loser;
-+    }
-+
-+  if (!bfd_close (obfd))
-+    {
-+      unlink (ofilename);
-+      einfo (_("%P%F: failed to finish output with object-only section\n"));
-+    }
-+
-+  /* Must be freed after bfd_close ().  */
-+  free (isympp);
-+  if (osympp)
-+    free (osympp);
-+
-+  if (rename (ofilename, output_filename))
-+    {
-+      unlink (ofilename);
-+      einfo (_("%P%F: failed to rename output with object-only section\n"));
-+    }
-+
-+  free (ofilename);
-+  return;
-+
-+loser:
-+  if (isympp)
-+    free (isympp);
-+  if (osympp)
-+    free (osympp);
-+  if (obfd)
-+    bfd_close (obfd);
-+  if (ofilename)
-+    unlink (ofilename);
-+  einfo (_("%P%F: failed to add object-only section: %s\n"), err);
-+}
-+
-+/* Emit the final output with object-only section.  */
-+
-+void
-+cmdline_emit_object_only_section (void)
-+{
-+  const char *saved_output_filename = output_filename;
-+  int fd;
-+  size_t size, off;
-+  bfd_byte *contents;
-+  struct stat st;
-+
-+  /* Get a temporary object-only file.  */
-+  output_filename = make_temp_file (".obj-only.o");
-+
-+  had_output_filename = false;
-+  link_info.input_bfds = NULL;
-+  link_info.input_bfds_tail = &link_info.input_bfds;
-+
-+  lang_init (true);
-+  ldexp_init (true);
-+
-+  ld_parse_linker_script ();
-+
-+  /* Set up the object-only output. */
-+  lang_final ();
-+
-+  /* Open the object-only file for output.  */
-+  lang_for_each_statement (ldlang_open_output);
-+
-+  ldemul_create_output_section_statements ();
-+
-+  if (!bfd_section_already_linked_table_init ())
-+    einfo (_("%P%F: Failed to create hash table\n"));
-+
-+  /* Call cmdline_on_object_only_archive_list_p to check which member
-+     should be loaded.  */
-+  input_flags.whole_archive = true;
-+
-+  /* Set it to avoid adding more to cmdline lists.  */
-+  config.emitting_gnu_object_only = true;
-+
-+  /* Get object-only input files.  */
-+  cmdline_get_object_only_input_files ();
-+
-+  /* Open object-only input files.  */
-+  open_input_bfds (statement_list.head, NULL, OPEN_BFD_NORMAL);
-+
-+  ldemul_after_open ();
-+
-+  bfd_section_already_linked_table_free ();
-+
-+  /* Make sure that we're not mixing architectures.  We call this
-+     after all the input files have been opened, but before we do any
-+     other processing, so that any operations merge_private_bfd_data
-+     does on the output file will be known during the rest of the
-+     link.  */
-+  lang_check ();
-+
-+  /* Size up the common data.  */
-+  lang_common ();
-+
-+  /* Update wild statements.  */
-+  update_wild_statements (statement_list.head);
-+
-+  /* Run through the contours of the script and attach input sections
-+     to the correct output sections.  */
-+  map_input_to_output_sections (statement_list.head, NULL, NULL);
-+
-+  /* Find any sections not attached explicitly and handle them.  */
-+  lang_place_orphans ();
-+
-+  /* Do anything special before sizing sections.  This is where ELF
-+     and other back-ends size dynamic sections.  */
-+  ldemul_before_allocation ();
-+
-+  /* Size up the sections.  */
-+  lang_size_sections (NULL, ! RELAXATION_ENABLED);
-+
-+  /* See if anything special should be done now we know how big
-+     everything is.  This is where relaxation is done.  */
-+  ldemul_after_allocation ();
-+
-+  ldemul_finish ();
-+
-+  /* Make sure that the section addresses make sense.  */
-+  if (command_line.check_section_addresses)
-+    lang_check_section_addresses ();
-+
-+  lang_end ();
-+
-+  ldwrite ();
-+
-+  ldexp_finish (true);
-+  lang_finish ();
-+
-+  if (! bfd_close (link_info.output_bfd))
-+    einfo (_("%P%F:%s: final close failed on object-only output: %E\n"),
-+	   output_filename);
-+
-+  link_info.output_bfd = NULL;
-+
-+  /* Read in the object-only file.  */
-+  fd = open (output_filename, O_RDONLY | O_BINARY);
-+  if (fd < 0)
-+    {
-+      bfd_set_error (bfd_error_system_call);
-+      einfo (_("%P%F:%s: cannot open object-only output: %E\n"),
-+	     output_filename);
-+    }
-+
-+  /* Get the object-only file size.  */
-+  if (fstat (fd, &st) != 0)
-+    {
-+      bfd_set_error (bfd_error_system_call);
-+      einfo (_("%P%F:%s: cannot stat object-only output: %E\n"),
-+	     output_filename);
-+    }
-+
-+  size = st.st_size;
-+  off = 0;
-+  contents = (bfd_byte *) xmalloc (size);
-+  while (off != size)
-+    {
-+      ssize_t got;
-+
-+      got = read (fd, contents + off, size - off);
-+      if (got < 0)
-+	{
-+	  bfd_set_error (bfd_error_system_call);
-+	  einfo (_("%P%F:%s: read failed on object-only output: %E\n"),
-+		 output_filename);
-+	}
-+
-+      off += got;
-+    }
-+
-+  close (fd);
-+
-+  /* Remove the temporary object-only file.  */
-+  unlink (output_filename);
-+
-+  output_filename = saved_output_filename;
-+
-+  cmdline_add_object_only_section (contents, size);
-+
-+  free (contents);
-+}
-+
-+/* Extract the object-only section.  */
-+
-+static const char *
-+cmdline_extract_object_only_section (bfd *abfd)
-+{
-+  const char *name = bfd_extract_object_only_section (abfd);
-+
-+  if (name == NULL)
-+    einfo (_("%P%F: cannot extract object-only section from %B: %E\n"),
-+	   abfd);
-+
-+  /* It should be removed after it is done.  */
-+  cmdline_list_append (&cmdline_temp_object_only_list,
-+		       cmdline_is_file_enum, (void *) name);
-+
-+  return name;
-+}
-+
-+/* Check and handle the object-only section.   */
-+
-+void
-+cmdline_check_object_only_section (bfd *abfd, bool lto)
-+{
-+  const char *filename;
-+
-+  if (config.emitting_gnu_object_only || abfd->format != bfd_object)
-+    return;
-+
-+  if (lto)
-+    {
-+      /* For LTO link, we only need to extract object-only section
-+	 from the mixed object, add it to input, and put it on LTO
-+	 claimed output.  */
-+      switch (bfd_get_lto_type (abfd))
-+	{
-+	default:
-+	  abort ();
-+	case lto_mixed_object:
-+	  filename = cmdline_extract_object_only_section (abfd);
-+	  lang_add_input_file (filename,
-+			       lang_input_file_is_file_enum, NULL);
-+	  break;
-+	case lto_non_ir_object:
-+	case lto_slim_ir_object:
-+	case lto_fat_ir_object:
-+	  break;
-+	}
-+    }
-+  else if (bfd_link_relocatable (&link_info))
-+    {
-+      /* For non-LTO relocatable link, we need to append non-IR object
-+	 file and the object file in object-only section to the object
-+	 only list.  */
-+      switch (bfd_get_lto_type (abfd))
-+	{
-+	default:
-+	  abort ();
-+	case lto_mixed_object:
-+	  filename = cmdline_extract_object_only_section (abfd);
-+	  cmdline_object_only_list_append (cmdline_is_file_enum,
-+					  (void *) filename);
-+	  break;
-+	case lto_non_ir_object:
-+	  cmdline_object_only_list_append (cmdline_is_bfd_enum, abfd);
-+	  break;
-+	case lto_slim_ir_object:
-+	case lto_fat_ir_object:
-+	  break;
-+	}
-+    }
-+}
-+
-+/* Remove temporary object-only files.  */
-+
-+void
-+cmdline_remove_object_only_files (void)
-+{
-+  cmdline_union_type *c;
-+
-+  if (config.plugin_save_temps)
-+    return;
-+
-+  c = cmdline_temp_object_only_list.head;
-+  for (; c != NULL; c = c->header.next)
-+    switch (c->header.type)
-+      {
-+      default:
-+	abort ();
-+      case cmdline_is_file_enum:
-+	unlink (c->file.filename);
-+	break;
-+      }
-+}
-diff --git a/ld/ldlang.h b/ld/ldlang.h
-index e32c5acaaca..91779a584b4 100644
---- a/ld/ldlang.h
-+++ b/ld/ldlang.h
-@@ -552,7 +552,7 @@ extern struct asneeded_minfo **asneeded_list_tail;
- extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
- 
- extern void lang_init
--  (void);
-+  (bool);
- extern void lang_finish
-   (void);
- extern lang_memory_region_type * lang_memory_region_lookup
-@@ -746,4 +746,46 @@ print_one_symbol (struct bfd_link_hash_entry *, void *);
- 
- extern void lang_add_version_string
-   (void);
-+
-+typedef enum
-+{
-+  cmdline_is_file_enum,
-+  cmdline_is_bfd_enum
-+} cmdline_enum_type;
-+
-+typedef struct cmdline_header_struct
-+{
-+  union cmdline_union *next;
-+  cmdline_enum_type type;
-+} cmdline_header_type;
-+
-+typedef struct cmdline_file_struct
-+{
-+  cmdline_header_type header;
-+  const char *filename;
-+} cmdline_file_type;
-+
-+typedef struct cmdline_bfd_struct
-+{
-+  cmdline_header_type header;
-+  bfd *abfd;
-+} cmdline_bfd_type;
-+
-+typedef union cmdline_union
-+{
-+  cmdline_header_type header;
-+  cmdline_file_type file;
-+  cmdline_bfd_type abfd;
-+} cmdline_union_type;
-+
-+typedef struct cmdline_list
-+{
-+  cmdline_union_type *head;
-+  cmdline_union_type **tail;
-+} cmdline_list_type;
-+
-+extern void cmdline_emit_object_only_section (void);
-+extern void cmdline_check_object_only_section (bfd *, bool);
-+extern void cmdline_remove_object_only_files (void);
-+
- #endif
-diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 64c4cce8371..dcef7bb9278 100644
---- a/ld/ldmain.c
-+++ b/ld/ldmain.c
-@@ -302,6 +302,9 @@ main (int argc, char **argv)
- 
-   xatexit (ld_cleanup);
- 
-+  /* Remove temporary object-only files.  */
-+  xatexit (cmdline_remove_object_only_files);
-+
-   /* Set up the sysroot directory.  */
-   ld_sysroot = get_sysroot (argc, argv);
-   if (*ld_sysroot)
-@@ -391,8 +394,8 @@ main (int argc, char **argv)
-   emulation = get_emulation (argc, argv);
-   ldemul_choose_mode (emulation);
-   default_target = ldemul_choose_target (argc, argv);
--  lang_init ();
--  ldexp_init ();
-+  lang_init (false);
-+  ldexp_init (false);
-   ldemul_before_parse ();
-   lang_has_input_file = false;
-   parse_args (argc, argv);
-@@ -407,34 +410,7 @@ main (int argc, char **argv)
- 
-   ldemul_set_symbols ();
- 
--  /* If we have not already opened and parsed a linker script,
--     try the default script from command line first.  */
--  if (saved_script_handle == NULL
--      && command_line.default_script != NULL)
--    {
--      ldfile_open_script_file (command_line.default_script);
--      parser_input = input_script;
--      yyparse ();
--    }
--
--  /* If we have not already opened and parsed a linker script
--     read the emulation's appropriate default script.  */
--  if (saved_script_handle == NULL)
--    {
--      int isfile;
--      char *s = ldemul_get_script (&isfile);
--
--      if (isfile)
--	ldfile_open_default_command_file (s);
--      else
--	{
--	  lex_string = s;
--	  lex_redirect (s, _("built in linker script"), 1);
--	}
--      parser_input = input_script;
--      yyparse ();
--      lex_string = NULL;
--    }
-+  ld_parse_linker_script ();
- 
-   if (verbose)
-     {
-@@ -572,7 +548,7 @@ main (int argc, char **argv)
-     fprintf (stderr, "lookup = %p val %lx\n", h, h ? h->u.def.value : 1);
-   }
- #endif
--  ldexp_finish ();
-+  ldexp_finish (false);
-   lang_finish ();
- 
-   if (config.dependency_file != NULL)
-@@ -597,6 +573,8 @@ main (int argc, char **argv)
-       if (!bfd_close (obfd))
- 	einfo (_("%F%P: %s: final close failed: %E\n"), output_filename);
- 
-+      link_info.output_bfd = NULL;
-+
-       /* If the --force-exe-suffix is enabled, and we're making an
- 	 executable file and it doesn't end in .exe, copy it to one
- 	 which does.  */
-@@ -644,6 +622,9 @@ main (int argc, char **argv)
- 	}
-     }
- 
-+  if (config.emit_gnu_object_only)
-+    cmdline_emit_object_only_section ();
-+
-   if (config.stats)
-     {
-       long run_time = get_run_time () - start_time;
-@@ -951,7 +932,9 @@ add_archive_element (struct bfd_link_info *info,
- 	  *subsbfd = input->the_bfd;
- 	}
-     }
-+  else
- #endif /* BFD_SUPPORTS_PLUGINS */
-+    cmdline_check_object_only_section (input->the_bfd, false);
- 
-   if (link_info.input_bfds_tail == &input->the_bfd->link.next
-       || input->the_bfd->link.next != NULL)
-@@ -1694,3 +1677,38 @@ notice (struct bfd_link_info *info,
- 
-   return true;
- }
-+
-+/* Parse the linker script.   */
-+
-+void
-+ld_parse_linker_script (void)
-+{
-+  /* If we have not already opened and parsed a linker script,
-+     try the default script from command line first.  */
-+  if (saved_script_handle == NULL
-+      && command_line.default_script != NULL)
-+    {
-+      ldfile_open_script_file (command_line.default_script);
-+      parser_input = input_script;
-+      yyparse ();
-+    }
-+
-+  /* If we have not already opened and parsed a linker script
-+     read the emulation's appropriate default script.  */
-+  if (saved_script_handle == NULL)
-+    {
-+      int isfile;
-+      char *s = ldemul_get_script (&isfile);
-+
-+      if (isfile)
-+	ldfile_open_default_command_file (s);
-+      else
-+	{
-+	  lex_string = s;
-+	  lex_redirect (s, _("built in linker script"), 1);
-+	}
-+      parser_input = input_script;
-+      yyparse ();
-+      lex_string = NULL;
-+    }
-+}
-diff --git a/ld/ldmain.h b/ld/ldmain.h
-index 0baa3c305c3..34770762f1c 100644
---- a/ld/ldmain.h
-+++ b/ld/ldmain.h
-@@ -63,4 +63,6 @@ extern void add_ignoresym (struct bfd_link_info *, const char *);
- extern void add_keepsyms_file (const char *);
- extern void track_dependency_files (const char *);
- 
-+extern void ld_parse_linker_script (void);
-+
- #endif
-diff --git a/ld/plugin.c b/ld/plugin.c
-index ecced25bd9b..ea0c6fcdd67 100644
---- a/ld/plugin.c
-+++ b/ld/plugin.c
-@@ -1341,6 +1341,9 @@ plugin_maybe_claim (lang_input_statement_type *entry)
-     {
-       bfd *abfd = entry->the_bfd->plugin_dummy_bfd;
- 
-+      /* Check object only section.  */
-+      cmdline_check_object_only_section (entry->the_bfd, true);
-+
-       /* Discard the real file's BFD and substitute the dummy one.  */
- 
-       /* We can't call bfd_close on archives.  BFD archive handling
-diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
-index ccecc1088b8..deb69dde543 100644
---- a/ld/scripttempl/elf.sc
-+++ b/ld/scripttempl/elf.sc
-@@ -244,7 +244,7 @@ RELA_IPLT=".rela.iplt    ${RELOCATING-0} :
- DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
- RODATA=".${RODATA_NAME}       ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
- DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
--DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
-+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
- if test -z "${NO_SMALL_DATA}"; then
-   SBSS=".${SBSS_NAME}         ${RELOCATING-0} :
-   {
-diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc
-index c468453d79d..b6701bf1d26 100644
---- a/ld/scripttempl/elf64hppa.sc
-+++ b/ld/scripttempl/elf64hppa.sc
-@@ -132,7 +132,7 @@ fi
- DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
- RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
- DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
--DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
-+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
- if test -z "${NO_SMALL_DATA}"; then
-   SBSS=".sbss         ${RELOCATING-0} :
-   {
-diff --git a/ld/scripttempl/elfxtensa.sc b/ld/scripttempl/elfxtensa.sc
-index fcda83c4dc9..2f62c2dbc54 100644
---- a/ld/scripttempl/elfxtensa.sc
-+++ b/ld/scripttempl/elfxtensa.sc
-@@ -145,7 +145,7 @@ fi
- DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
- RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
- DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
--DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
-+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
- INIT_LIT=".init.literal 0 : { *(.init.literal)	}"
- INIT=".init         0 : { KEEP (*(SORT_NONE(.init))) }"
- FINI_LIT=".fini.literal 0 : { *(.fini.literal)	}"
-diff --git a/ld/scripttempl/mep.sc b/ld/scripttempl/mep.sc
-index 7f0f46ae8e9..8fdf3117a40 100644
---- a/ld/scripttempl/mep.sc
-+++ b/ld/scripttempl/mep.sc
-@@ -119,7 +119,7 @@ fi
- DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
- RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
- DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
--DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
-+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
- if test -z "${NO_SMALL_DATA}"; then
-   SBSS=".sbss         ${RELOCATING-0} :
-   {
-diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
-index 6ca5f040a36..96a47515444 100644
---- a/ld/scripttempl/pe.sc
-+++ b/ld/scripttempl/pe.sc
-@@ -230,6 +230,7 @@ SECTIONS
-     ${RELOCATING+ *(.drectve)}
-     ${RELOCATING+ *(.note.GNU-stack)}
-     ${RELOCATING+ *(.gnu.lto_*)}
-+    ${RELOCATING+ *(.gnu_object_only)}
-   }
- 
-   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
-diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
-index d9ba2be49d9..e2c6c2cedd2 100644
---- a/ld/scripttempl/pep.sc
-+++ b/ld/scripttempl/pep.sc
-@@ -237,6 +237,7 @@ SECTIONS
-     ${RELOCATING+ *(.drectve)}
-     ${RELOCATING+ *(.note.GNU-stack)}
-     ${RELOCATING+ *(.gnu.lto_*)}
-+    ${RELOCATING+ *(.gnu_object_only)}
-   }
- 
-   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
-diff --git a/ld/testsuite/ld-plugin/lto-10.out b/ld/testsuite/ld-plugin/lto-10.out
-new file mode 100644
-index 00000000000..ce013625030
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-10.out
-@@ -0,0 +1 @@
-+hello
-diff --git a/ld/testsuite/ld-plugin/lto-10a.c b/ld/testsuite/ld-plugin/lto-10a.c
-new file mode 100644
-index 00000000000..93d57b520cb
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-10a.c
-@@ -0,0 +1,6 @@
-+extern int foo(void);
-+
-+int main(void)
-+{
-+  return foo();
-+}
-diff --git a/ld/testsuite/ld-plugin/lto-10b.c b/ld/testsuite/ld-plugin/lto-10b.c
-new file mode 100644
-index 00000000000..507055be341
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-10b.c
-@@ -0,0 +1,7 @@
-+#include <stdio.h>
-+
-+int foo(void)
-+{
-+  printf ("hello\n");
-+  return 0;
-+}
-diff --git a/ld/testsuite/ld-plugin/lto-10r.d b/ld/testsuite/ld-plugin/lto-10r.d
-new file mode 100644
-index 00000000000..3502056153d
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-10r.d
-@@ -0,0 +1,9 @@
-+#ld: -r tmpdir/lto-10a.o tmpdir/lto-10b.o
-+#source: dummy.s
-+#objdump: -h
-+
-+#...
-+ *[0-9]+ +\.gnu\.lto_\.[0-9a-zA-Z_\.]+ +[0-9a-f]+ +[0-9a-f]+  +[0-9a-f]+ +[0-9a-f]+ .*
-+#...
-+ *[0-9]+ +\.gnu_object_only +[0-9a-f]+ +0+ +0+ +0+[1-9a-f][0-9a-f]+ +.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/lto-4.out b/ld/testsuite/ld-plugin/lto-4.out
-new file mode 100644
-index 00000000000..8d8cc9240c8
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4.out
-@@ -0,0 +1,2 @@
-+hello bar
-+hello foo
-diff --git a/ld/testsuite/ld-plugin/lto-4a.c b/ld/testsuite/ld-plugin/lto-4a.c
-new file mode 100644
-index 00000000000..2d07cf585da
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4a.c
-@@ -0,0 +1,7 @@
-+extern void foo(void);
-+
-+int main(void)
-+{
-+  foo();
-+  return 0;
-+}
-diff --git a/ld/testsuite/ld-plugin/lto-4b.c b/ld/testsuite/ld-plugin/lto-4b.c
-new file mode 100644
-index 00000000000..bb4a68bb986
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4b.c
-@@ -0,0 +1,9 @@
-+#include <stdio.h>
-+
-+extern void bar (void);
-+
-+void foo(void)
-+{
-+  bar ();
-+  printf ("hello foo\n");
-+}
-diff --git a/ld/testsuite/ld-plugin/lto-4c.c b/ld/testsuite/ld-plugin/lto-4c.c
-new file mode 100644
-index 00000000000..317e6fcdacd
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4c.c
-@@ -0,0 +1,6 @@
-+#include <stdio.h>
-+
-+void bar (void)
-+{
-+  printf ("hello bar\n");
-+}
-diff --git a/ld/testsuite/ld-plugin/lto-4r-a.d b/ld/testsuite/ld-plugin/lto-4r-a.d
-new file mode 100644
-index 00000000000..c618cffb028
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4r-a.d
-@@ -0,0 +1,7 @@
-+#ld: -r tmpdir/lto-4a.o tmpdir/lto-4b.o tmpdir/lto-4c.o
-+#source: dummy.s
-+#objdump: -h
-+
-+#...
-+.* .gnu_object_only.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/lto-4r-b.d b/ld/testsuite/ld-plugin/lto-4r-b.d
-new file mode 100644
-index 00000000000..07d71cb5328
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4r-b.d
-@@ -0,0 +1,7 @@
-+#ld: -r tmpdir/lto-4a.o tmpdir/lto-4b.o
-+#source: dummy.s
-+#objdump: -h
-+
-+#...
-+.* .gnu_object_only.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/lto-4r-c.d b/ld/testsuite/ld-plugin/lto-4r-c.d
-new file mode 100644
-index 00000000000..4e691ea01ac
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4r-c.d
-@@ -0,0 +1,7 @@
-+#ld: -r tmpdir/lto-4r-b.o tmpdir/lto-4c.o --no-warn-execstack --no-error-execstack
-+#source: dummy.s
-+#objdump: -h
-+
-+#...
-+.* .gnu_object_only.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/lto-4r-d.d b/ld/testsuite/ld-plugin/lto-4r-d.d
-new file mode 100644
-index 00000000000..d4c58526cc5
---- /dev/null
-+++ b/ld/testsuite/ld-plugin/lto-4r-d.d
-@@ -0,0 +1,7 @@
-+#ld: -r --whole-archive tmpdir/liblto-4.a
-+#source: dummy.s
-+#objdump: -h
-+
-+#...
-+.* .gnu_object_only.*
-+#pass
-diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
-index e36480aee78..e454b485ed9 100644
---- a/ld/testsuite/ld-plugin/lto.exp
-+++ b/ld/testsuite/ld-plugin/lto.exp
-@@ -72,6 +72,15 @@ set lto_link_tests [list \
-   [list "Build liblto-3.a" \
-    "" "-flto $lto_fat" \
-    {lto-3b.c} {} "liblto-3.a"] \
-+  [list "Compile 4a" \
-+   "" "-flto $lto_fat" \
-+   {lto-4a.c} {} ""] \
-+  [list "Compile 4b" \
-+   "" "-O2" \
-+   {lto-4b.c} {} ""] \
-+  [list "Compile 4c" \
-+   "" "-O2" \
-+   {lto-4c.c} {} ""] \
-   [list "Compile 5a" \
-    "" "-flto $lto_fat" \
-    {lto-5a.c} {} ""] \
-@@ -84,6 +93,12 @@ set lto_link_tests [list \
-   [list "Compile 9" \
-    "" "-O2 -finline -flto" \
-    {lto-9.cc} {} "" "c++"] \
-+  [list "Compile 10a" \
-+   "" "-O2" \
-+   {lto-10a.c} {} ""] \
-+  [list "Compile 10b" \
-+   "" "-O2 -flto $lto_fat" \
-+   {lto-10b.c} {} ""] \
-   [list "Compile 11a" \
-    "" "-O -flto" \
-    {lto-11a.c} {} ""] \
-@@ -711,9 +726,29 @@ set lto_run_tests [list \
-   [list "LTO 3c" \
-    "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
-    {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
-+  [list "LTO 4a" \
-+   "-O2 -flto -fuse-linker-plugin \
-+    -Wl,--no-warn-execstack,--no-error-execstack \
-+    tmpdir/lto-4r-a.o" "" \
-+   {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
-+  [list "LTO 4c" \
-+   "-O2 -flto -fuse-linker-plugin \
-+    -Wl,--no-warn-execstack,--no-error-execstack \
-+    tmpdir/lto-4r-c.o" "" \
-+   {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
-+  [list "LTO 4d" \
-+   "-O2 -flto -fuse-linker-plugin \
-+    -Wl,--no-warn-execstack,--no-error-execstack \
-+    tmpdir/lto-4r-d.o" "" \
-+   {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
-   [list "LTO 5" \
-    "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
-    {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
-+  [list "LTO 10" \
-+   "-O2 -flto -fuse-linker-plugin \
-+    -Wl,--no-warn-execstack,--no-error-execstack \
-+    tmpdir/lto-10.o" "" \
-+   {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
-   [list "LTO 11" \
-    "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
-    {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
-@@ -979,6 +1014,15 @@ if [string match "" $exec_output] then {
-     fail "PR ld/28138 (build only)"
- }
- 
-+set testname "Build liblto-4.a"
-+remote_file host delete "tmpdir/liblto-4.a"
-+set catch_output [run_host_cmd "$ar" "rc tmpdir/liblto-4.a tmpdir/lto-4a.o tmpdir/lto-4b.o tmpdir/lto-4c.o"]
-+if {![string match "" $catch_output]} {
-+    unresolved $testname
-+    restore_notify
-+    return
-+}
-+
- set testname "Build liblto-11.a"
- remote_file host delete "tmpdir/liblto-11.a"
- set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"]
-@@ -1091,8 +1135,30 @@ if { [at_least_gcc_version 4 7] } {
- # Run "ld -r" to generate inputs for complex LTO tests.
- run_dump_test "lto-3r"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
-+run_dump_test "lto-4r-a"
-+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
-+run_dump_test "lto-4r-b"
-+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
-+run_dump_test "lto-4r-c"
-+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
-+run_dump_test "lto-4r-d"
-+remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
- run_dump_test "lto-5r"
- remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
-+run_dump_test "lto-10r"
-+remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
-+set testname "nm mixed object"
-+set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
-+if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
-+    set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
-+    if { [ regexp "T main" $exec_output ] } {
-+	pass $testname
-+    } {
-+	fail $testname
-+    }
-+} {
-+    fail $testname
-+ }
- 
- run_cc_link_tests $lto_link_symbol_tests
- 
--- 
-2.48.0
-

diff --git a/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch b/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch
deleted file mode 100644
index 9c17dc9..0000000
--- a/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch
+++ /dev/null
@@ -1,42 +0,0 @@
-From 2c86c77dc5795a7f1e8f915c138c27893d8141d4 Mon Sep 17 00:00:00 2001
-Message-ID: <2c86c77dc5795a7f1e8f915c138c27893d8141d4.1736748624.git.sam@gentoo.org>
-In-Reply-To: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
-References: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Sat, 11 Jan 2025 07:23:27 +0800
-Subject: [PATCH 7/8] ld: Document mixing LTO and non-LTO objects for -r
-
-	* ld.texi: Document mixing LTO and non-LTO relocatable files for
-	"ld -r".
-
-Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
----
- ld/ld.texi | 12 ++++++++++++
- 1 file changed, 12 insertions(+)
-
-diff --git a/ld/ld.texi b/ld/ld.texi
-index da714a20855..d1787453f57 100644
---- a/ld/ld.texi
-+++ b/ld/ld.texi
-@@ -1126,6 +1126,18 @@ relocations.  Different output formats can have further restrictions; for
- example some @code{a.out}-based formats do not support partial linking
- with input files in other formats at all.
- 
-+On ELF platforms, when the relocatable output contains both contents
-+which require link-time optimization (LTO) and contents which don't
-+require LTO, a .gnu_object_only section will be created to contain a
-+relocatable object file, as if @samp{-r} is applied to all relocatable
-+inputs which don't require LTO.  When processing a relocatable input
-+with a .gnu_object_only section, the linker will extract the
-+.gnu_object_only section as a separate input.
-+
-+Note that since @samp{-r} groups some sections from different input files
-+together, there may be negative impacts on code size and locality in
-+final executable or shared library.
-+
- This option does the same thing as @samp{-i}.
- 
- @kindex -R @var{file}
--- 
-2.48.0
-

diff --git a/9999/0008-h8300-Handle-.gnu_object_only-section.patch b/9999/0008-h8300-Handle-.gnu_object_only-section.patch
deleted file mode 100644
index 1336250..0000000
--- a/9999/0008-h8300-Handle-.gnu_object_only-section.patch
+++ /dev/null
@@ -1,37 +0,0 @@
-From c5f942b863c660280535dac32586e64d45308550 Mon Sep 17 00:00:00 2001
-Message-ID: <c5f942b863c660280535dac32586e64d45308550.1736748624.git.sam@gentoo.org>
-In-Reply-To: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
-References: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
-From: "H.J. Lu" <hjl.tools@gmail.com>
-Date: Tue, 27 Oct 2020 06:39:59 -0700
-Subject: [PATCH 8/8] h8300: Handle .gnu_object_only section
-
-	PR ld/12291
-	PR ld/12430
-	PR ld/13298
-	* config/tc-h8300.c (h8300_elf_section): Handle .gnu_object_only
-	section.
----
- gas/config/tc-h8300.c | 6 ++++--
- 1 file changed, 4 insertions(+), 2 deletions(-)
-
-diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c
-index f8e54064166..105461da92b 100644
---- a/gas/config/tc-h8300.c
-+++ b/gas/config/tc-h8300.c
-@@ -146,8 +146,10 @@ pint (int arg ATTRIBUTE_UNUSED)
- static void
- h8300_elf_section (int push)
- {
--  static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
--  static const char * known_data_prefixes [] = { ".debug", ".zdebug", ".gnu.warning" };
-+  static const char * known_data_sections []
-+    = { ".rodata", ".tdata", ".tbss", ".gnu_object_only" };
-+  static const char * known_data_prefixes []
-+    = { ".debug", ".zdebug", ".gnu.warning" };
-   char * saved_ilp = input_line_pointer;
-   const char * name;
- 
--- 
-2.48.0
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-01-13  6:11 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-01-13  6:11 UTC (permalink / raw
  To: gentoo-commits

commit:     f46bcb376cd5e2a21d6fb9cbf98bcf02c666927c
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 13 06:10:39 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jan 13 06:11:29 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f46bcb37

9999: add H.J.'s LTO patches

This is needed for -ffat-lto-objects to work well. We are hoping
this will land in 2.44. Add it in binutils-patches for now to give it
some early testing for live.

Link: https://inbox.sourceware.org/binutils/20250112220244.597636-1-hjl.tools <AT> gmail.com/
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-LTO-and-none-LTO-output-support-for-ld-r.patch | 2928 ++++++++++++++++++++
 ...ment-mixing-LTO-and-non-LTO-objects-for-r.patch |   42 +
 ...008-h8300-Handle-.gnu_object_only-section.patch |   37 +
 3 files changed, 3007 insertions(+)

diff --git a/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch b/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch
new file mode 100644
index 0000000..b26d48f
--- /dev/null
+++ b/9999/0006-ld-Add-LTO-and-none-LTO-output-support-for-ld-r.patch
@@ -0,0 +1,2928 @@
+From 9f57274faacf1dbb6c2b56d29de150b5e79ecb3d Mon Sep 17 00:00:00 2001
+Message-ID: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Mon, 4 Nov 2013 09:17:45 -0800
+Subject: [PATCH 6/8] ld: Add LTO and none-LTO output support for ld -r
+
+Link with mixed IR/non-IR objects
+
+* 2 kinds of object files
+  o non-IR object file has
+    * non-IR sections
+  o IR object file has
+    * IR sections
+    * non-IR sections
+    * The output of "ld -r" with mixed IR/non-IR objects should work with:
+        o Compilers/linkers with IR support.
+	o Compilers/linkers without IR support.
+* Add the mixed object file which has
+  o IR sections
+  o non-IR sections:
+    * Object codes from IR sections.
+    * Object codes from non-IR object files.
+  o Object-only section:
+    * With section name ".gnu_object_only" and SHT_GNU_OBJECT_ONLY type
+    on ELF:
+    https://gitlab.com/x86-psABIs/Linux-ABI
+    #define SHT_GNU_OBJECT_ONLY 0x6ffffff8	/* Object only */
+    * Contain non-IR object file.
+    * Input is discarded after link.
+* Linker action:
+  o Classify each input object file:
+    * If there is a ".gnu_object_only" section, it is a mixed object file.
+    * If there is a IR section, it is an IR object file.
+    * Otherwise, it is a non-IR object file.
+  o Relocatable non-IR link:
+    * Prepare for an object-only output.
+    * Prepare for a regular output.
+    * For each mixed object file:
+      * Add IR and non-IR sections to the regular output.
+      * For object-only section:
+	* Extract object only file.
+	* Add it to the object-only output.
+	* Discard object-only section.
+    * For each IR object file:
+      * Add IR and non-IR sections to the regular output.
+    * For each non-IR object file:
+      * Add non-IR sections to the regular output.
+      * Add non-IR sections to the object-only output.
+    * Final output:
+      * If there are IR objects, non-IR objects and the object-only
+      output isn't empty:
+	* Put the object-only output into the object-only section.
+	* Add the object-only section to the regular output.
+	* Remove the object-only output.
+  o Normal link and relocatable IR link:
+    * Prepare for output.
+    * IR link:
+      * For each mixed object file:
+	* Compile and add IR sections to the output.
+	* Discard non-IR sections.
+	* Object-only section:
+	  * Extract object only file.
+	  * Add it to the output.
+	  * Discard object-only section.
+      * For each IR object file:
+        * Compile and add IR sections to the output.
+	* Discard non-IR sections.
+      * For each non-IR object file:
+	* Add non-IR sections to the output.
+    * Non-IR link:
+      * For each mixed object file:
+	* Add non-IR sections to the output.
+	* Discard IR sections and object-only section.
+      * For each IR object file:
+	* Add non-IR sections to the output.
+	* Discard IR sections.
+      * For each non-IR object file:
+	* Add non-IR sections to the output.
+
+This is useful for Linux kernel build with LTO.
+
+bfd/
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* bfd.c (bfd_lto_object_type): Add lto_mixed_object.
+	(bfd): Add object_only_section.
+	(bfd_group_signature): New.
+	* elf.c (special_sections_g): Add .gnu_object_only.
+	* format.c: Include "plugin-api.h" and "plugin.h" if
+	BFD_SUPPORTS_PLUGINS is defined.
+	(bfd_set_lto_type): Set type to lto_mixed_object for
+	GNU_OBJECT_ONLY_SECTION_NAME section.
+	(bfd_check_format_matches): Don't check the plugin target twice
+	if the plugin target is explicitly specified.
+	* opncls.c (bfd_extract_object_only_section): New.
+	* plugin.c (bfd_plugin_fake_text_section): New.
+	(bfd_plugin_fake_data_section): Likewise.
+	(bfd_plugin_fake_bss_section): Likewise.
+	(bfd_plugin_fake_common_section): Likewise.
+	(bfd_plugin_get_symbols_in_object_only): Likewise.
+	* plugin.c (add_symbols): Call
+	bfd_plugin_get_symbols_in_object_only and count
+	plugin_data->object_only_nsyms.
+	(bfd_plugin_get_symtab_upper_bound): Count
+	plugin_data->object_only_nsyms.
+	bfd_plugin_get_symbols_in_object_only and add symbols from
+	object only section.
+	(bfd_plugin_canonicalize_symtab): Remove fake_section,
+	fake_data_section, fake_bss_section and fake_common_section.
+	Set udata.p to NULL.  Use bfd_plugin_fake_text_section,
+	bfd_plugin_fake_data_section, bfd_plugin_fake_bss_section and
+	bfd_plugin_fake_common_section.
+	Set udata.p to NULL.
+	* plugin.h (plugin_data_struct): Add object_only_nsyms and
+	object_only_syms.
+	* section.c (GNU_OBJECT_ONLY_SECTION_NAME): New.
+	* bfd-in2.h: Regenerated.
+
+binutils/
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* objcopy.c (group_signature): Removed.
+	(is_strip_section): Replace group_signature with
+	bfd_group_signature.
+	(setup_section): Likewise.
+	* readelf.c (get_os_specific_section_type_name): Handle
+	SHT_GNU_OBJECT_ONLY.
+
+gas/
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* testsuite/gas/elf/section9.s: Add the .gnu_object_only test.
+	* testsuite/gas/elf/section9.d: Updated.
+
+include/
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* elf/common.h (SHT_GNU_OBJECT_ONLY): New.
+
+ld/
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* ld.h (ld_config_type): Add emit_gnu_object_only and
+	emitting_gnu_object_only.
+	* ldelf.c (orphan_init_done): Make it file scope.
+	(ldelf_place_orphan): Rename hold to orig_hold.  Initialize hold
+	from orig_hold at run-time.
+	(ldelf_finish): New.
+	* ldelf.h (ldelf_finish): New.
+	* ldexp.c (ldexp_init): Take a bfd_boolean argument to supprt
+	object-only output.
+	(ldexp_finish): Likewise.
+	* ldexp.h (ldexp_init): Take a bfd_boolean argument.
+	(ldexp_finish): Likewise.
+	* ldfile.c (ldfile_try_open_bfd): Call
+	cmdline_check_object_only_section.
+	* ldlang.c: Include "ldwrite.h" and elf-bfd.h.
+	* ldlang.c (cmdline_object_only_file_list): New.
+	(cmdline_object_only_archive_list): Likewise.
+	(cmdline_temp_object_only_list): Likewise.
+	(cmdline_lists_init): Likewise.
+	(cmdline_list_new): Likewise.
+	(cmdline_list_append): Likewise.
+	(print_cmdline_list): Likewise.
+	(cmdline_on_object_only_archive_list_p): Likewise.
+	(cmdline_object_only_list_append): Likewise.
+	(cmdline_get_object_only_input_files): Likewise.
+	(cmdline_arg): Likewise.
+	(setup_section): Likewise.
+	(copy_section): Likewise.
+	(cmdline_fopen_temp): Likewise.
+	(cmdline_add_object_only_section): Likewise.
+	(cmdline_emit_object_only_section): Likewise.
+	(cmdline_extract_object_only_section): Likewise.
+	(cmdline_check_object_only_section): Likewise.
+	(cmdline_remove_object_only_files): Likewise.
+	(lang_init): Take a bfd_boolean argument to supprt object-only
+	output.  Call cmdline_lists_init.
+	(load_symbols): Call cmdline_on_object_only_archive_list_p
+	to check if an archive member should be loaded.
+	(lang_process): Handle object-only link.
+	* ldlang.h (lang_init): Take a bfd_boolean argument.
+	(cmdline_enum_type): New.
+	(cmdline_header_type): Likewise.
+	(cmdline_file_type): Likewise.
+	(cmdline_bfd_type): Likewise.
+	(cmdline_union_type): Likewise.
+	(cmdline_list_type): Likewise.
+	(cmdline_emit_object_only_section): Likewise.
+	(cmdline_check_object_only_section): Likewise.
+	(cmdline_remove_object_only_files): Likewise.
+	* ldmain.c (main): Call xatexit with
+	cmdline_remove_object_only_files.  Pass FALSE to lang_init,
+	ldexp_init and ldexp_finish.  Use ld_parse_linker_script.
+	Set link_info.output_bfd to NULL after close.  Call
+	cmdline_emit_object_only_section if needed.
+	(add_archive_element): Call cmdline_check_object_only_section.
+	(ld_parse_linker_script): New.
+	* ldmain.h (ld_parse_linker_script): New.
+	* plugin.c (plugin_maybe_claim): Call
+	cmdline_check_object_only_section on claimed IR files.
+	* scripttempl/elf.sc: Also discard .gnu_object_only sections.
+	* scripttempl/elf64hppa.sc: Likewise.
+	* scripttempl/elfxtensa.sc: Likewise.
+	* scripttempl/mep.sc: Likewise.
+	* scripttempl/pe.sc: Likewise.
+	* scripttempl/pep.sc: Likewise.
+	* emultempl/aarch64elf.em (gld${EMULATION_NAME}_finish): Replace
+	finish_default with ldelf_finish.
+	* emultempl/alphaelf.em (alpha_finish): Likewise.
+	* emultempl/avrelf.em (avr_finish): Likewise.
+	* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
+	* emultempl/ppc32elf.em (ppc_finish): Likewise.
+	* emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Likewise.
+	* emultempl/spuelf.em (gld${EMULATION_NAME}_finish): Likewise.
+	* testsuite/ld-plugin/lto-10.out: New file.
+	* testsuite/ld-plugin/lto-10a.c: Likewise.
+	* testsuite/ld-plugin/lto-10b.c: Likewise.
+	* testsuite/ld-plugin/lto-10r.d: Likewise.
+	* testsuite/ld-plugin/lto-4.out: Likewise.
+	* testsuite/ld-plugin/lto-4a.c: Likewise.
+	* testsuite/ld-plugin/lto-4b.c: Likewise.
+	* testsuite/ld-plugin/lto-4c.c: Likewise.
+	* testsuite/ld-plugin/lto-4r-a.d: Likewise.
+	* testsuite/ld-plugin/lto-4r-b.d: Likewise.
+	* testsuite/ld-plugin/lto-4r-c.d: Likewise.
+	* testsuite/ld-plugin/lto-4r-d.d: Likewise.
+	* testsuite/ld-plugin/lto.exp (lto_link_tests): Prepare for
+	"LTO 4[acd]", "lto-4r-[abcd]" and "LTO 10" tests.
+	(lto_run_tests): Add "LTO 4[acd]" and "LTO 10" tests.
+	Build liblto-4.a.  Run "lto-4r-[abcd]" tests.
+	Run lto-10r and create tmpdir/lto-10.o.
+	Add test for nm on mixed LTO/non-LTO object.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ bfd/bfd-in2.h                     |   16 +-
+ bfd/bfd.c                         |   46 +-
+ bfd/elf.c                         |    1 +
+ bfd/format.c                      |   37 +-
+ bfd/opncls.c                      |   66 ++
+ bfd/plugin.c                      |  193 +++++-
+ bfd/plugin.h                      |    2 +
+ bfd/section.c                     |    3 +
+ binutils/objcopy.c                |   32 +-
+ binutils/readelf.c                |    1 +
+ gas/testsuite/gas/elf/section9.d  |    1 +
+ gas/testsuite/gas/elf/section9.s  |    2 +
+ include/elf/common.h              |    1 +
+ ld/emultempl/aarch64elf.em        |    2 +-
+ ld/emultempl/alphaelf.em          |    2 +-
+ ld/emultempl/armelf.em            |    2 +-
+ ld/emultempl/avrelf.em            |    2 +-
+ ld/emultempl/elf.em               |    1 +
+ ld/emultempl/ppc32elf.em          |    2 +-
+ ld/emultempl/ppc64elf.em          |    2 +-
+ ld/emultempl/spuelf.em            |    2 +-
+ ld/ld.h                           |    6 +
+ ld/ldelf.c                        |   26 +-
+ ld/ldelf.h                        |    1 +
+ ld/ldexp.c                        |   16 +-
+ ld/ldexp.h                        |    4 +-
+ ld/ldfile.c                       |    2 +
+ ld/ldlang.c                       | 1027 ++++++++++++++++++++++++++++-
+ ld/ldlang.h                       |   44 +-
+ ld/ldmain.c                       |   80 ++-
+ ld/ldmain.h                       |    2 +
+ ld/plugin.c                       |    3 +
+ ld/scripttempl/elf.sc             |    2 +-
+ ld/scripttempl/elf64hppa.sc       |    2 +-
+ ld/scripttempl/elfxtensa.sc       |    2 +-
+ ld/scripttempl/mep.sc             |    2 +-
+ ld/scripttempl/pe.sc              |    1 +
+ ld/scripttempl/pep.sc             |    1 +
+ ld/testsuite/ld-plugin/lto-10.out |    1 +
+ ld/testsuite/ld-plugin/lto-10a.c  |    6 +
+ ld/testsuite/ld-plugin/lto-10b.c  |    7 +
+ ld/testsuite/ld-plugin/lto-10r.d  |    9 +
+ ld/testsuite/ld-plugin/lto-4.out  |    2 +
+ ld/testsuite/ld-plugin/lto-4a.c   |    7 +
+ ld/testsuite/ld-plugin/lto-4b.c   |    9 +
+ ld/testsuite/ld-plugin/lto-4c.c   |    6 +
+ ld/testsuite/ld-plugin/lto-4r-a.d |    7 +
+ ld/testsuite/ld-plugin/lto-4r-b.d |    7 +
+ ld/testsuite/ld-plugin/lto-4r-c.d |    7 +
+ ld/testsuite/ld-plugin/lto-4r-d.d |    7 +
+ ld/testsuite/ld-plugin/lto.exp    |   66 ++
+ 51 files changed, 1653 insertions(+), 125 deletions(-)
+ create mode 100644 ld/testsuite/ld-plugin/lto-10.out
+ create mode 100644 ld/testsuite/ld-plugin/lto-10a.c
+ create mode 100644 ld/testsuite/ld-plugin/lto-10b.c
+ create mode 100644 ld/testsuite/ld-plugin/lto-10r.d
+ create mode 100644 ld/testsuite/ld-plugin/lto-4.out
+ create mode 100644 ld/testsuite/ld-plugin/lto-4a.c
+ create mode 100644 ld/testsuite/ld-plugin/lto-4b.c
+ create mode 100644 ld/testsuite/ld-plugin/lto-4c.c
+ create mode 100644 ld/testsuite/ld-plugin/lto-4r-a.d
+ create mode 100644 ld/testsuite/ld-plugin/lto-4r-b.d
+ create mode 100644 ld/testsuite/ld-plugin/lto-4r-c.d
+ create mode 100644 ld/testsuite/ld-plugin/lto-4r-d.d
+
+diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
+index 3a5a6dd8a5f..1b82b6bcc99 100644
+--- a/bfd/bfd-in2.h
++++ b/bfd/bfd-in2.h
+@@ -925,6 +925,9 @@ extern asection _bfd_std_section[4];
+ #define BFD_COM_SECTION_NAME "*COM*"
+ #define BFD_IND_SECTION_NAME "*IND*"
+ 
++/* GNU object-only section name.  */
++#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
++
+ /* Pointer to the common section.  */
+ #define bfd_com_section_ptr (&_bfd_std_section[0])
+ /* Pointer to the undefined section.  */
+@@ -1962,7 +1965,8 @@ enum bfd_lto_object_type
+     lto_non_object,            /* Not an LTO object.  */
+     lto_non_ir_object,         /* An object without LTO IR.  */
+     lto_slim_ir_object,        /* A slim LTO IR object.  */
+-    lto_fat_ir_object          /* A fat LTO IR object.  */
++    lto_fat_ir_object,         /* A fat LTO IR object.  */
++    lto_mixed_object           /* A mixed LTO IR object.  */
+   };
+ 
+ struct bfd_mmapped_entry
+@@ -2185,7 +2189,7 @@ struct bfd
+   unsigned int read_only : 1;
+ 
+   /* LTO object type.  */
+-  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
++  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 3;
+ 
+   /* Set if this BFD is currently being processed by
+      bfd_check_format_matches.  This is checked by the cache to
+@@ -2217,6 +2221,9 @@ struct bfd
+   /* The last section on the section list.  */
+   struct bfd_section *section_last;
+ 
++  /* The object-only section on the section list.  */
++  struct bfd_section *object_only_section;
++
+   /* The number of sections.  */
+   unsigned int section_count;
+ 
+@@ -2790,6 +2797,8 @@ bfd_vma bfd_emul_get_commonpagesize (const char *);
+ 
+ char *bfd_demangle (bfd *, const char *, int);
+ 
++asymbol *bfd_group_signature (asection *group, asymbol **isympp);
++
+ /* Extracted from bfdio.c.  */
+ bfd_size_type bfd_read (void *, bfd_size_type, bfd *)
+ ATTRIBUTE_WARN_UNUSED_RESULT;
+@@ -3073,6 +3082,9 @@ char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir);
+ 
+ const char *bfd_set_filename (bfd *abfd, const char *filename);
+ 
++const char *bfd_extract_object_only_section
++   (bfd *abfd);
++
+ /* Extracted from reloc.c.  */
+ typedef enum bfd_reloc_status
+ {
+diff --git a/bfd/bfd.c b/bfd/bfd.c
+index 194f24179fd..a8d1314b83f 100644
+--- a/bfd/bfd.c
++++ b/bfd/bfd.c
+@@ -80,7 +80,8 @@ EXTERNAL
+ .    lto_non_object,		{* Not an LTO object.  *}
+ .    lto_non_ir_object,		{* An object without LTO IR.  *}
+ .    lto_slim_ir_object,	{* A slim LTO IR object.  *}
+-.    lto_fat_ir_object		{* A fat LTO IR object.  *}
++.    lto_fat_ir_object,		{* A fat LTO IR object.  *}
++.    lto_mixed_object		{* A mixed LTO IR object.  *}
+ .  };
+ .
+ .struct bfd_mmapped_entry
+@@ -306,7 +307,7 @@ CODE_FRAGMENT
+ .  unsigned int read_only : 1;
+ .
+ .  {* LTO object type.  *}
+-.  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 2;
++.  ENUM_BITFIELD (bfd_lto_object_type) lto_type : 3;
+ .
+ .  {* Set if this BFD is currently being processed by
+ .     bfd_check_format_matches.  This is checked by the cache to
+@@ -338,6 +339,9 @@ CODE_FRAGMENT
+ .  {* The last section on the section list.  *}
+ .  struct bfd_section *section_last;
+ .
++.  {* The object-only section on the section list.  *}
++.  struct bfd_section *object_only_section;
++.
+ .  {* The number of sections.  *}
+ .  unsigned int section_count;
+ .
+@@ -3034,3 +3038,41 @@ _bfd_get_link_info (bfd *abfd)
+ 
+   return elf_link_info (abfd);
+ }
++
++/*
++FUNCTION
++	bfd_group_signature
++
++SYNOPSIS
++	asymbol *bfd_group_signature (asection *group, asymbol **isympp);
++
++DESCRIPTION
++	Return a pointer to the symbol used as a signature for GROUP.
++*/
++
++asymbol *
++bfd_group_signature (asection *group, asymbol **isympp)
++{
++  bfd *abfd = group->owner;
++  Elf_Internal_Shdr *ghdr;
++
++  /* PR 20089: An earlier error may have prevented us from loading the
++     symbol table.  */
++  if (isympp == NULL)
++    return NULL;
++
++  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
++    return NULL;
++
++  ghdr = &elf_section_data (group)->this_hdr;
++  if (ghdr->sh_link == elf_onesymtab (abfd))
++    {
++      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
++      Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd);
++
++      if (ghdr->sh_info > 0
++	  && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
++	return isympp[ghdr->sh_info - 1];
++    }
++  return NULL;
++}
+diff --git a/bfd/elf.c b/bfd/elf.c
+index 218d58df8be..30bbdc662af 100644
+--- a/bfd/elf.c
++++ b/bfd/elf.c
+@@ -3014,6 +3014,7 @@ static const struct bfd_elf_special_section special_sections_g[] =
+   { STRING_COMMA_LEN (".gnu.linkonce.p"), -2, SHT_PROGBITS,    SHF_ALLOC + SHF_WRITE },
+   { STRING_COMMA_LEN (".gnu.lto_"),	  -1, SHT_PROGBITS,    SHF_EXCLUDE },
+   { STRING_COMMA_LEN (".got"),		   0, SHT_PROGBITS,    SHF_ALLOC + SHF_WRITE },
++  { STRING_COMMA_LEN (".gnu_object_only"), 0, SHT_GNU_OBJECT_ONLY, SHF_EXCLUDE },
+   { STRING_COMMA_LEN (".gnu.version"),	   0, SHT_GNU_versym,  0 },
+   { STRING_COMMA_LEN (".gnu.version_d"),   0, SHT_GNU_verdef,  0 },
+   { STRING_COMMA_LEN (".gnu.version_r"),   0, SHT_GNU_verneed, 0 },
+diff --git a/bfd/format.c b/bfd/format.c
+index 125815935f6..7769ad095f6 100644
+--- a/bfd/format.c
++++ b/bfd/format.c
+@@ -46,6 +46,10 @@ SUBSECTION
+ #include "sysdep.h"
+ #include "bfd.h"
+ #include "libbfd.h"
++#if BFD_SUPPORTS_PLUGINS
++#include "plugin-api.h"
++#include "plugin.h"
++#endif
+ 
+ /* IMPORT from targets.c.  */
+ extern const size_t _bfd_target_vector_entries;
+@@ -349,23 +353,32 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
+ #if BFD_SUPPORTS_PLUGINS
+   if (abfd->format == bfd_object
+       && abfd->lto_type == lto_non_object
+-      && (abfd->flags & (DYNAMIC | EXEC_P)) == 0)
++      && (abfd->flags
++	  & (DYNAMIC
++	     | (bfd_get_flavour (abfd) == bfd_target_elf_flavour
++		? EXEC_P : 0))) == 0)
+     {
+       asection *sec;
+       enum bfd_lto_object_type type = lto_non_ir_object;
+-      struct lto_section lsection;
++      struct lto_section lsection = { 0, 0, 0, 0 };
+       /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
+ 	 section.  */
+       for (sec = abfd->sections; sec != NULL; sec = sec->next)
+-	if (startswith (sec->name, ".gnu.lto_.lto.")
+-	    && bfd_get_section_contents (abfd, sec, &lsection, 0,
+-					 sizeof (struct lto_section)))
++	if (strcmp (sec->name, GNU_OBJECT_ONLY_SECTION_NAME) == 0)
++	  {
++	    type = lto_mixed_object;
++	    abfd->object_only_section = sec;
++	    break;
++	  }
++	else if (lsection.major_version == 0
++		 && startswith (sec->name, ".gnu.lto_.lto.")
++		 && bfd_get_section_contents (abfd, sec, &lsection, 0,
++					      sizeof (struct lto_section)))
+ 	  {
+ 	    if (lsection.slim_object)
+ 	      type = lto_slim_ir_object;
+ 	    else
+ 	      type = lto_fat_ir_object;
+-	    break;
+ 	  }
+ 
+       abfd->lto_type = type;
+@@ -397,9 +410,6 @@ bool
+ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+ {
+   extern const bfd_target binary_vec;
+-#if BFD_SUPPORTS_PLUGINS
+-  extern const bfd_target plugin_vec;
+-#endif
+   const bfd_target * const *target;
+   const bfd_target **matching_vector = NULL;
+   const bfd_target *save_targ, *right_targ, *ar_right_targ, *match_targ;
+@@ -507,11 +517,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
+ 	 check the default target twice.  */
+       if (*target == &binary_vec
+ #if BFD_SUPPORTS_PLUGINS
+-	  || (match_count != 0 && *target == &plugin_vec)
++	  || (match_count != 0 && bfd_plugin_target_p (*target))
+ #endif
+ 	  || (!abfd->target_defaulted && *target == save_targ))
+ 	continue;
+ 
++#if BFD_SUPPORTS_PLUGINS
++      /* If the plugin target is explicitly specified when a BFD file
++	 is opened, don't check it twice.  */
++      if (bfd_plugin_specified_p () && bfd_plugin_target_p (*target))
++	continue;
++#endif
++
+       /* If we already tried a match, the bfd is modified and may
+ 	 have sections attached, which will confuse the next
+ 	 _bfd_check_format call.  */
+diff --git a/bfd/opncls.c b/bfd/opncls.c
+index 93adbf117f0..ca7dbf23aa6 100644
+--- a/bfd/opncls.c
++++ b/bfd/opncls.c
+@@ -2054,3 +2054,69 @@ bfd_set_filename (bfd *abfd, const char *filename)
+ 
+   return n;
+ }
++
++/*
++FUNCTION
++	bfd_extract_object_only_section
++
++SYNOPSIS
++	const char *bfd_extract_object_only_section
++	  (bfd *abfd);
++
++DESCRIPTION
++
++	Takes a @var{ABFD} and extract the .gnu_object_only section into
++	a temporary file.
++
++RETURNS
++	The name of the temporary file is returned if all is ok.
++	Otherwise <<NULL>> is returned and bfd_error is set.
++*/
++
++const char *
++bfd_extract_object_only_section (bfd *abfd)
++{
++  asection *sec = abfd->object_only_section;
++  const char *name;
++  FILE *file;
++  bfd_byte *memhunk = NULL;
++  size_t off, size;
++  bfd_error_type err;
++
++  /* Get a temporary object-only file.  */
++  name = make_temp_file (".obj-only.o");
++
++  /* Open the object-only file.  */
++  file = _bfd_real_fopen (name, FOPEN_WB);
++  if (!bfd_get_full_section_contents (abfd, sec, &memhunk))
++    {
++      err = bfd_get_error ();
++
++loser:
++      free (memhunk);
++      fclose (file);
++      unlink (name);
++      bfd_set_error (err);
++      return NULL;
++    }
++
++  off = 0;
++  size = sec->size;
++  while (off != size)
++    {
++      size_t written, nwrite = size - off;
++
++      written = fwrite (memhunk + off, 1, nwrite, file);
++      if (written < nwrite && ferror (file))
++	{
++	  err = bfd_error_system_call;
++	  goto loser;
++	}
++
++      off += written;
++    }
++
++  free (memhunk);
++  fclose (file);
++  return name;
++}
+diff --git a/bfd/plugin.c b/bfd/plugin.c
+index 67454adffb9..d57ae593e78 100644
+--- a/bfd/plugin.c
++++ b/bfd/plugin.c
+@@ -160,6 +160,158 @@ register_claim_file (ld_plugin_claim_file_handler handler)
+   return LDPS_OK;
+ }
+ 
++static asection bfd_plugin_fake_text_section
++  = BFD_FAKE_SECTION (bfd_plugin_fake_text_section, NULL, "plug", 0,
++		      SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS);
++static asection bfd_plugin_fake_data_section
++  = BFD_FAKE_SECTION (bfd_plugin_fake_data_section, NULL, "plug", 0,
++		      SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS);
++static asection bfd_plugin_fake_bss_section
++  = BFD_FAKE_SECTION (bfd_plugin_fake_bss_section, NULL, "plug", 0,
++		      SEC_ALLOC);
++static asection bfd_plugin_fake_common_section
++  = BFD_FAKE_SECTION (bfd_plugin_fake_common_section, NULL, NULL,
++		      0, SEC_IS_COMMON);
++
++/* Get symbols from object only section.  */
++
++static void
++bfd_plugin_get_symbols_in_object_only (bfd *abfd)
++{
++  struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
++  const char *object_only_file;
++  bfd *nbfd;
++  long storage;
++  long object_only_nsyms, added_nsyms, i;
++  asymbol **object_only_syms, **added_syms;
++
++  plugin_data->object_only_syms = NULL;
++  plugin_data->object_only_nsyms = 0;
++
++  if (abfd->sections == NULL && abfd->my_archive == NULL)
++    {
++      nbfd = bfd_openr (abfd->filename, NULL);
++      if (nbfd == NULL)
++	{
++	  (*_bfd_error_handler)
++	    (_("%s: failed to open to extract object only section: %s"),
++	     abfd->filename, bfd_errmsg (bfd_get_error ()));
++	  return;
++	}
++      else if (!bfd_check_format (nbfd, bfd_object))
++	{
++	  /* There is no object only section if it isn't a bfd_object
++	     file.  */
++	  bfd_close (nbfd);
++	  return;
++	}
++    }
++  else
++    {
++      if (!bfd_check_format (abfd, bfd_object))
++	{
++	  (*_bfd_error_handler)
++	    (_("%pB: invalid file to extract object only section: %s"),
++	     abfd, bfd_errmsg (bfd_get_error ()));
++	  return;
++	}
++      nbfd = abfd;
++    }
++
++  if (nbfd->lto_type == lto_mixed_object
++      && (nbfd->flags & HAS_SYMS) != 0)
++    {
++      object_only_file = bfd_extract_object_only_section (nbfd);
++      if (object_only_file == NULL)
++	(*_bfd_error_handler)
++	  (_("%pB: failed to extract object only section: %s"),
++	   abfd, bfd_errmsg (bfd_get_error ()));
++    }
++  else
++    object_only_file = NULL;
++
++  /* Close the new bfd we just opened.  */
++  if (nbfd != abfd)
++    bfd_close (nbfd);
++
++  /* Return if there is no object only section or there is no
++     symbol in object only section.  */
++  if (!object_only_file)
++    return;
++
++  /* Open the file containing object only section.  */
++  nbfd = bfd_openr (object_only_file, NULL);
++  if (!bfd_check_format (nbfd, bfd_object))
++    {
++      (*_bfd_error_handler)
++	(_("%pB: failed to open object only section: %s"),
++	 abfd, bfd_errmsg (bfd_get_error ()));
++      goto quit;
++    }
++
++  storage = bfd_get_symtab_upper_bound (nbfd);
++  if (storage <= 0)
++    {
++      if (storage < 0)
++	(*_bfd_error_handler)
++	  (_("%pB: failed to get symbol table in object only section: %s"),
++	   abfd, bfd_errmsg (bfd_get_error ()));
++
++      goto quit;
++    }
++
++  object_only_syms = (asymbol **) bfd_malloc (storage);
++  object_only_nsyms = bfd_canonicalize_symtab (nbfd, object_only_syms);
++
++  /* FIXME: We waste some spaces if not all symbols are copied.  */
++  added_syms = (asymbol **) bfd_alloc (abfd, storage);
++  added_nsyms = 0;
++
++  /* Copy only global symbols from object only section.  */
++  for (i = 0; i < object_only_nsyms; i++)
++    {
++      asection *sec = object_only_syms[i]->section;
++      flagword flags = object_only_syms[i]->flags;
++      asymbol *s;
++
++      if (bfd_is_com_section (sec))
++	sec = &bfd_plugin_fake_common_section;
++      else if (bfd_is_und_section (sec))
++	;
++      else if ((flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE)) != 0)
++	{
++	  if ((sec->flags & SEC_CODE) != 0)
++	    sec = &bfd_plugin_fake_text_section;
++	  else if ((sec->flags & SEC_LOAD) != 0)
++	    sec = &bfd_plugin_fake_data_section;
++	  else
++	    sec = &bfd_plugin_fake_bss_section;
++	}
++      else
++	continue;
++
++      s = bfd_alloc (abfd, sizeof (asymbol));
++      BFD_ASSERT (s);
++      added_syms[added_nsyms++] = s;
++
++      s->section = sec;
++      s->the_bfd = abfd;
++      s->name = xstrdup (object_only_syms[i]->name);
++      s->value = 0;
++      s->flags = flags;
++      s->udata.p = NULL;
++    }
++
++  plugin_data->object_only_syms = added_syms;
++  plugin_data->object_only_nsyms = added_nsyms;
++
++  free (object_only_syms);
++
++quit:
++  /* Close and remove the object only section file.  */
++  bfd_close (nbfd);
++  unlink (object_only_file);
++}
+ 
+ /* Register a claim-file handler, version 2. */
+ 
+@@ -185,10 +337,13 @@ add_symbols (void * handle,
+   plugin_data->nsyms = nsyms;
+   plugin_data->syms = syms;
+ 
+-  if (nsyms != 0)
++  abfd->tdata.plugin_data = plugin_data;
++
++  bfd_plugin_get_symbols_in_object_only (abfd);
++
++  if ((nsyms + plugin_data->object_only_nsyms) != 0)
+     abfd->flags |= HAS_SYMS;
+ 
+-  abfd->tdata.plugin_data = plugin_data;
+   return LDPS_OK;
+ }
+ 
+@@ -678,7 +833,8 @@ static long
+ bfd_plugin_get_symtab_upper_bound (bfd *abfd)
+ {
+   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
+-  long nsyms = plugin_data->nsyms;
++  /* Add symbols from object only section.  */
++  long nsyms = plugin_data->nsyms + plugin_data->object_only_nsyms;
+ 
+   BFD_ASSERT (nsyms >= 0);
+ 
+@@ -712,18 +868,7 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
+   struct plugin_data_struct *plugin_data = abfd->tdata.plugin_data;
+   long nsyms = plugin_data->nsyms;
+   const struct ld_plugin_symbol *syms = plugin_data->syms;
+-  static asection fake_text_section
+-    = BFD_FAKE_SECTION (fake_text_section, NULL, "plug", 0,
+-			SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS);
+-  static asection fake_data_section
+-    = BFD_FAKE_SECTION (fake_data_section, NULL, "plug", 0,
+-			SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_HAS_CONTENTS);
+-  static asection fake_bss_section
+-    = BFD_FAKE_SECTION (fake_bss_section, NULL, "plug", 0,
+-			SEC_ALLOC);
+-  static asection fake_common_section
+-    = BFD_FAKE_SECTION (fake_common_section, NULL, "plug", 0, SEC_IS_COMMON);
+-  int i;
++  int i, j;
+ 
+   for (i = 0; i < nsyms; i++)
+     {
+@@ -736,10 +881,11 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
+       s->name = syms[i].name;
+       s->value = 0;
+       s->flags = convert_flags (&syms[i]);
++      s->udata.p = NULL;
+       switch (syms[i].def)
+ 	{
+ 	case LDPK_COMMON:
+-	  s->section = &fake_common_section;
++	  s->section = &bfd_plugin_fake_common_section;
+ 	  break;
+ 	case LDPK_UNDEF:
+ 	case LDPK_WEAKUNDEF:
+@@ -755,25 +901,28 @@ bfd_plugin_canonicalize_symtab (bfd *abfd,
+ 	      case LDST_UNKNOWN:
+ 		/* What is the best fake section for LDST_UNKNOWN?  */
+ 	      case LDST_FUNCTION:
+-		s->section = &fake_text_section;
++		s->section = &bfd_plugin_fake_text_section;
+ 		break;
+ 	      case LDST_VARIABLE:
+ 		if (syms[i].section_kind == LDSSK_BSS)
+-		  s->section = &fake_bss_section;
++		  s->section = &bfd_plugin_fake_bss_section;
+ 		else
+-		  s->section = &fake_data_section;
++		  s->section = &bfd_plugin_fake_data_section;
+ 		break;
+ 	      }
+ 	  else
+-	    s->section = &fake_text_section;
++	    s->section = &bfd_plugin_fake_text_section;
+ 	  break;
+ 	default:
+ 	  BFD_ASSERT (0);
+ 	}
+-
+-      s->udata.p = (void *) &syms[i];
+     }
+ 
++  /* Copy symbols from object only section.  */
++  nsyms += plugin_data->object_only_nsyms;
++  for (j = 0; j < plugin_data->object_only_nsyms; j++, i++)
++    alocation[i] = plugin_data->object_only_syms[j];
++
+   return nsyms;
+ }
+ 
+diff --git a/bfd/plugin.h b/bfd/plugin.h
+index 510689c96ba..f61e6168e2b 100644
+--- a/bfd/plugin.h
++++ b/bfd/plugin.h
+@@ -34,6 +34,8 @@ typedef struct plugin_data_struct
+ {
+   int nsyms;
+   const struct ld_plugin_symbol *syms;
++  int object_only_nsyms;
++  asymbol **object_only_syms;
+ }
+ plugin_data_struct;
+ 
+diff --git a/bfd/section.c b/bfd/section.c
+index 8456c73e8d0..e7674c9dc1a 100644
+--- a/bfd/section.c
++++ b/bfd/section.c
+@@ -661,6 +661,9 @@ EXTERNAL
+ .#define BFD_COM_SECTION_NAME "*COM*"
+ .#define BFD_IND_SECTION_NAME "*IND*"
+ .
++.{* GNU object-only section name.  *}
++.#define GNU_OBJECT_ONLY_SECTION_NAME ".gnu_object_only"
++.
+ .{* Pointer to the common section.  *}
+ .#define bfd_com_section_ptr (&_bfd_std_section[0])
+ .{* Pointer to the undefined section.  *}
+diff --git a/binutils/objcopy.c b/binutils/objcopy.c
+index f64417697cb..e2e6bd7ee83 100644
+--- a/binutils/objcopy.c
++++ b/binutils/objcopy.c
+@@ -1266,34 +1266,6 @@ is_specified_symbol (const char *name, htab_t htab)
+   return htab_find (htab, name) != NULL;
+ }
+ 
+-/* Return a pointer to the symbol used as a signature for GROUP.  */
+-
+-static asymbol *
+-group_signature (asection *group)
+-{
+-  bfd *abfd = group->owner;
+-  Elf_Internal_Shdr *ghdr;
+-
+-  /* PR 20089: An earlier error may have prevented us from loading the symbol table.  */
+-  if (isympp == NULL)
+-    return NULL;
+-
+-  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+-    return NULL;
+-
+-  ghdr = &elf_section_data (group)->this_hdr;
+-  if (ghdr->sh_link == elf_onesymtab (abfd))
+-    {
+-      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+-      Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd);
+-
+-      if (ghdr->sh_info > 0
+-	  && ghdr->sh_info < symhdr->sh_size / bed->s->sizeof_sym)
+-	return isympp[ghdr->sh_info - 1];
+-    }
+-  return NULL;
+-}
+-
+ /* Return TRUE if the section is a DWO section.  */
+ 
+ static bool
+@@ -1438,7 +1410,7 @@ is_strip_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
+       const char *gname;
+       asection *elt, *first;
+ 
+-      gsym = group_signature (sec);
++      gsym = bfd_group_signature (sec, isympp);
+       /* Strip groups without a valid signature.  */
+       if (gsym == NULL)
+ 	return true;
+@@ -4398,7 +4370,7 @@ setup_section (bfd *ibfd, sec_ptr isection, bfd *obfd)
+ 
+   if ((isection->flags & SEC_GROUP) != 0)
+     {
+-      asymbol *gsym = group_signature (isection);
++      asymbol *gsym = bfd_group_signature (isection, isympp);
+ 
+       if (gsym != NULL)
+ 	{
+diff --git a/binutils/readelf.c b/binutils/readelf.c
+index 4f8f879cf91..949395483bb 100644
+--- a/binutils/readelf.c
++++ b/binutils/readelf.c
+@@ -5941,6 +5941,7 @@ get_os_specific_section_type_name (Filedata * filedata, unsigned int sh_type)
+     case SHT_GNU_ATTRIBUTES:          return "GNU_ATTRIBUTES";
+     case SHT_GNU_HASH:                return "GNU_HASH";
+     case SHT_GNU_LIBLIST:             return "GNU_LIBLIST";
++    case SHT_GNU_OBJECT_ONLY:	      return "GNU_OBJECT_ONLY";
+ 
+     case SHT_SUNW_move:               return "SUNW_MOVE";
+     case SHT_SUNW_COMDAT:             return "SUNW_COMDAT";
+diff --git a/gas/testsuite/gas/elf/section9.d b/gas/testsuite/gas/elf/section9.d
+index 63152fe4b4d..d7e97c014ac 100644
+--- a/gas/testsuite/gas/elf/section9.d
++++ b/gas/testsuite/gas/elf/section9.d
+@@ -4,4 +4,5 @@
+ #...
+ [ 	]*\[.*\][ 	]+\.gnu\.lto_main[ 	]+PROGBITS.*[ 	]+E[   ]+.*
+ [ 	]*\[.*\][ 	]+\.gnu\.lto_\.pureconst[ 	]+PROGBITS.*[ 	]+E[   ]+.*
++[ 	]*\[.*\][ 	]+\.gnu_object_only[ 	]+GNU_OBJECT_ONLY.*[ 	]+E[   ]+.*
+ #pass
+diff --git a/gas/testsuite/gas/elf/section9.s b/gas/testsuite/gas/elf/section9.s
+index 6b8b1074ca3..abcdea10aad 100644
+--- a/gas/testsuite/gas/elf/section9.s
++++ b/gas/testsuite/gas/elf/section9.s
+@@ -2,3 +2,5 @@
+ 	.byte 0,0,0,0
+ 	.section .gnu.lto_.pureconst,"",%progbits
+ 	.byte 0,0,0,0
++	.section .gnu_object_only
++	.byte 0,0,0,0
+diff --git a/include/elf/common.h b/include/elf/common.h
+index 6077db7a8b7..b0b54d87ab4 100644
+--- a/include/elf/common.h
++++ b/include/elf/common.h
+@@ -572,6 +572,7 @@
+ #define SHT_GNU_HASH	             0x6ffffff6	/* GNU style symbol hash table */
+ #define SHT_GNU_LIBLIST	             0x6ffffff7	/* List of prelink dependencies */
+ #define SHT_CHECKSUM	             0x6ffffff8	/* Checksum for DSO content.  */
++#define SHT_GNU_OBJECT_ONLY	     0x6ffffff9	/* Object only */
+ 
+ #define SHT_SUNW_move	             0x6ffffffa
+ #define SHT_SUNW_COMDAT              0x6ffffffb
+diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
+index faa0d3ecd79..ae79961ada1 100644
+--- a/ld/emultempl/aarch64elf.em
++++ b/ld/emultempl/aarch64elf.em
+@@ -309,7 +309,7 @@ gld${EMULATION_NAME}_finish (void)
+ 	}
+     }
+ 
+-  finish_default ();
++  ldelf_finish ();
+ }
+ 
+ /* This is a convenient point to tell BFD about target specific flags.
+diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
+index 6ecacb76a10..5ae2587a653 100644
+--- a/ld/emultempl/alphaelf.em
++++ b/ld/emultempl/alphaelf.em
+@@ -104,7 +104,7 @@ alpha_finish (void)
+   if (limit_32bit)
+     elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
+ 
+-  finish_default ();
++  ldelf_finish ();
+ }
+ EOF
+ 
+diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
+index dc2cd9f1139..02a97e7c1ff 100644
+--- a/ld/emultempl/armelf.em
++++ b/ld/emultempl/armelf.em
+@@ -456,7 +456,7 @@ gld${EMULATION_NAME}_finish (void)
+ 	}
+     }
+ 
+-  finish_default ();
++  ldelf_finish ();
+ 
+   if (params.thumb_entry_symbol)
+     {
+diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
+index 7696a9050d9..0945702bfb6 100644
+--- a/ld/emultempl/avrelf.em
++++ b/ld/emultempl/avrelf.em
+@@ -227,7 +227,7 @@ avr_finish (void)
+ 	elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
+     }
+ 
+-  finish_default ();
++  ldelf_finish ();
+ }
+ EOF
+ 
+diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
+index 4d431995d2e..0bad25d3a46 100644
+--- a/ld/emultempl/elf.em
++++ b/ld/emultempl/elf.em
+@@ -1173,6 +1173,7 @@ LDEMUL_BEFORE_PLACE_ORPHANS=${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orp
+ LDEMUL_AFTER_ALLOCATION=${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}
+ LDEMUL_SET_OUTPUT_ARCH=${LDEMUL_SET_OUTPUT_ARCH-ldelf_set_output_arch}
+ LDEMUL_BEFORE_ALLOCATION=${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}
++LDEMUL_FINISH=${LDEMUL_FINISH-ldelf_finish}
+ LDEMUL_OPEN_DYNAMIC_ARCHIVE=${LDEMUL_OPEN_DYNAMIC_ARCHIVE-ldelf_open_dynamic_archive}
+ LDEMUL_PLACE_ORPHAN=${LDEMUL_PLACE_ORPHAN-ldelf_place_orphan}
+ LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
+diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
+index acd673a7b84..529a5920920 100644
+--- a/ld/emultempl/ppc32elf.em
++++ b/ld/emultempl/ppc32elf.em
+@@ -238,7 +238,7 @@ ppc_finish (void)
+     lang_for_each_statement (no_zero_padding);
+   if (!ppc_finish_symbols (&link_info))
+     einfo (_("%X%P: ppc_finish_symbols problem %E\n"));
+-  finish_default ();
++  ldelf_finish ();
+ }
+ 
+ EOF
+diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
+index f9ace66a5b2..1e6ae7af738 100644
+--- a/ld/emultempl/ppc64elf.em
++++ b/ld/emultempl/ppc64elf.em
+@@ -616,7 +616,7 @@ gld${EMULATION_NAME}_finish (void)
+   fflush (stderr);
+   free (msg);
+ 
+-  finish_default ();
++  ldelf_finish ();
+ }
+ 
+ 
+diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em
+index dd8d259a31f..76776ba2555 100644
+--- a/ld/emultempl/spuelf.em
++++ b/ld/emultempl/spuelf.em
+@@ -432,7 +432,7 @@ gld${EMULATION_NAME}_finish (void)
+ 	einfo (_("%P: --auto-overlay ignored with zero local store range\n"));
+     }
+ 
+-  finish_default ();
++  ldelf_finish ();
+ }
+ 
+ static char *
+diff --git a/ld/ld.h b/ld/ld.h
+index 48d34bc6acd..254f0a097bb 100644
+--- a/ld/ld.h
++++ b/ld/ld.h
+@@ -306,6 +306,12 @@ typedef struct
+   /* If set, store plugin intermediate files permanently.  */
+   bool plugin_save_temps;
+ 
++  /* If set, if the .gnu_object_only section should be created.  */
++  bool emit_gnu_object_only;
++
++  /* If set, if the .gnu_object_only section is being created.  */
++  bool emitting_gnu_object_only;
++
+   /* If set, print discarded sections in map file output.  */
+   bool print_map_discarded;
+ 
+diff --git a/ld/ldelf.c b/ld/ldelf.c
+index 4cbfc19c161..a66d1d21394 100644
+--- a/ld/ldelf.c
++++ b/ld/ldelf.c
+@@ -63,6 +63,7 @@ static lang_input_statement_type *global_found;
+ static struct stat global_stat;
+ static struct bfd_link_needed_list *global_vercheck_needed;
+ static bool global_vercheck_failed;
++static bool orphan_init_done;
+ 
+ void
+ ldelf_after_parse (void)
+@@ -2101,7 +2102,7 @@ elf_orphan_compatible (asection *in, asection *out)
+ lang_output_section_statement_type *
+ ldelf_place_orphan (asection *s, const char *secname, int constraint)
+ {
+-  static struct orphan_save hold[] =
++  static struct orphan_save orig_hold[] =
+     {
+       { ".text",
+ 	SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
+@@ -2131,6 +2132,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
+ 	SEC_HAS_CONTENTS,
+ 	0, 0, 0, 0 },
+     };
++  static struct orphan_save hold[ARRAY_SIZE (orig_hold)];
+   enum orphan_save_index
+     {
+       orphan_text = 0,
+@@ -2143,7 +2145,6 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
+       orphan_sdata,
+       orphan_nonalloc
+     };
+-  static int orphan_init_done = 0;
+   struct orphan_save *place;
+   lang_output_section_statement_type *after;
+   lang_output_section_statement_type *os;
+@@ -2272,16 +2273,23 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint)
+ 
+   if (!orphan_init_done)
+     {
+-      struct orphan_save *ho;
++      struct orphan_save *ho, *horig;
+ 
+       for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
++      for (ho = hold, horig = orig_hold;
++	   ho < hold + ARRAY_SIZE (hold);
++	   ++ho, ++horig)
++	{
++	  *ho = *horig;
++	  if (ho->name != NULL)
+ 	if (ho->name != NULL)
+ 	  {
+ 	    ho->os = lang_output_section_find (ho->name);
+ 	    if (ho->os != NULL && ho->os->flags == 0)
+ 	      ho->os->flags = ho->flags;
+ 	  }
+-      orphan_init_done = 1;
++	}
++      orphan_init_done = true;
+     }
+ 
+   /* If this is a final link, then always put .gnu.warning.SYMBOL
+@@ -2428,3 +2436,13 @@ ldelf_set_output_arch (void)
+   if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour)
+     elf_link_info (link_info.output_bfd) = &link_info;
+ }
++
++void
++ldelf_finish (void)
++{
++  /* Support the object-only output.  */
++  if (config.emit_gnu_object_only)
++    orphan_init_done = false;
++
++  finish_default ();
++}
+diff --git a/ld/ldelf.h b/ld/ldelf.h
+index 96fb1e5b6a8..a6498cf2758 100644
+--- a/ld/ldelf.h
++++ b/ld/ldelf.h
+@@ -21,6 +21,7 @@
+ extern const char *ldelf_emit_note_gnu_build_id;
+ extern const char *ldelf_emit_note_fdo_package_metadata;
+ 
++extern void ldelf_finish (void);
+ extern void ldelf_after_parse (void);
+ extern bool ldelf_load_symbols (lang_input_statement_type *);
+ extern void ldelf_before_plugin_all_symbols_read (int, int, int, int,
+diff --git a/ld/ldexp.c b/ld/ldexp.c
+index f0b8d7cb748..035cef60448 100644
+--- a/ld/ldexp.c
++++ b/ld/ldexp.c
+@@ -1699,14 +1699,15 @@ align_n (bfd_vma value, bfd_vma align)
+ }
+ 
+ void
+-ldexp_init (void)
++ldexp_init (bool object_only)
+ {
+   /* The value "13" is ad-hoc, somewhat related to the expected number of
+      assignments in a linker script.  */
+-  if (!bfd_hash_table_init_n (&definedness_table,
+-			      definedness_newfunc,
+-			      sizeof (struct definedness_hash_entry),
+-			      13))
++  if (!object_only
++      && !bfd_hash_table_init_n (&definedness_table,
++				 definedness_newfunc,
++				 sizeof (struct definedness_hash_entry),
++				 13))
+     einfo (_("%F%P: can not create hash table: %E\n"));
+ }
+ 
+@@ -1763,7 +1764,8 @@ ldexp_is_final_sym_absolute (const struct bfd_link_hash_entry *h)
+ }
+ 
+ void
+-ldexp_finish (void)
++ldexp_finish (bool object_only)
+ {
+-  bfd_hash_table_free (&definedness_table);
++  if (!object_only)
++    bfd_hash_table_free (&definedness_table);
+ }
+diff --git a/ld/ldexp.h b/ld/ldexp.h
+index f7d2cba4f4c..16953caf7cd 100644
+--- a/ld/ldexp.h
++++ b/ld/ldexp.h
+@@ -250,9 +250,9 @@ fill_type *exp_get_fill
+   (etree_type *, fill_type *, char *);
+ bfd_vma exp_get_abs_int
+   (etree_type *, int, char *);
+-void ldexp_init (void);
++void ldexp_init (bool);
+ void ldexp_finalize_syms (void);
+ bool ldexp_is_final_sym_absolute (const struct bfd_link_hash_entry *);
+-void ldexp_finish (void);
++void ldexp_finish (bool);
+ 
+ #endif
+diff --git a/ld/ldfile.c b/ld/ldfile.c
+index 9bf5014ad95..530a5fef5e3 100644
+--- a/ld/ldfile.c
++++ b/ld/ldfile.c
+@@ -532,7 +532,9 @@ ldfile_try_open_bfd (const char *attempt,
+       && !no_more_claiming
+       && bfd_check_format (entry->the_bfd, bfd_object))
+     plugin_maybe_claim (entry);
++  else
+ #endif /* BFD_SUPPORTS_PLUGINS */
++    cmdline_check_object_only_section (entry->the_bfd, false);
+ 
+   /* It opened OK, the format checked out, and the plugins have had
+      their chance to claim it, so this is success.  */
+diff --git a/ld/ldlang.c b/ld/ldlang.c
+index 4c8d4e7a7fc..e1e491732a9 100644
+--- a/ld/ldlang.c
++++ b/ld/ldlang.c
+@@ -37,6 +37,7 @@
+ #include "ldctor.h"
+ #include "ldfile.h"
+ #include "ldemul.h"
++#include "ldwrite.h"
+ #include "fnmatch.h"
+ #include "demangle.h"
+ #include "hashtab.h"
+@@ -47,6 +48,9 @@
+ #include "plugin.h"
+ #endif
+ 
++/* FIXME: Put it here to avoid NAME conflict from ldgram.h.  */
++#include "elf-bfd.h"
++
+ #ifndef offsetof
+ #define offsetof(TYPE, MEMBER) ((size_t) & (((TYPE*) 0)->MEMBER))
+ #endif
+@@ -76,6 +80,9 @@ static lang_statement_list_type **stat_save_ptr = &stat_save[0];
+ static struct unique_sections *unique_section_list;
+ static struct asneeded_minfo *asneeded_list_head;
+ static unsigned int opb_shift = 0;
++static cmdline_list_type cmdline_object_only_file_list;
++static cmdline_list_type cmdline_object_only_archive_list;
++static cmdline_list_type cmdline_temp_object_only_list;
+ 
+ /* Forward declarations.  */
+ static void exp_init_os (etree_type *);
+@@ -99,6 +106,10 @@ static void lang_do_version_exports_section (void);
+ static void lang_finalize_version_expr_head
+   (struct bfd_elf_version_expr_head *);
+ static void lang_do_memory_regions (bool);
++static void cmdline_lists_init (void);
++static void cmdline_get_object_only_input_files (void);
++static void print_cmdline_list (cmdline_union_type *);
++static bool cmdline_on_object_only_archive_list_p (bfd *);
+ 
+ /* Exported variables.  */
+ const char *output_target;
+@@ -1353,15 +1364,20 @@ output_section_statement_table_free (void)
+ /* Build enough state so that the parser can build its tree.  */
+ 
+ void
+-lang_init (void)
++lang_init (bool object_only)
+ {
+-  obstack_begin (&stat_obstack, 1000);
+-  obstack_init (&pt_obstack);
++  if (!object_only)
++    {
++      obstack_begin (&stat_obstack, 1000);
++      obstack_init (&pt_obstack);
++    }
+ 
+   stat_ptr = &statement_list;
+ 
+   output_section_statement_table_init ();
+ 
++  cmdline_lists_init ();
++
+   lang_list_init (stat_ptr);
+ 
+   lang_list_init (&input_file_chain);
+@@ -3142,6 +3158,12 @@ load_symbols (lang_input_statement_type *entry,
+ 		  loaded = false;
+ 		}
+ 
++	      if (config.emitting_gnu_object_only)
++		{
++		  if (!cmdline_on_object_only_archive_list_p (member))
++		    continue;
++		}
++
+ 	      subsbfd = member;
+ 	      if (!(*link_info.callbacks
+ 		    ->add_archive_element) (&link_info, member,
+@@ -8343,7 +8365,42 @@ lang_process (void)
+ 	    }
+ 	}
+     }
++  else
+ #endif /* BFD_SUPPORTS_PLUGINS */
++    if (bfd_link_relocatable (&link_info))
++    {
++      /* Check if .gnu_object_only section should be created.  */
++      bfd *p;
++      int object_type;
++
++      object_type = 0;
++      for (p = link_info.input_bfds; p != (bfd *) NULL; p = p->link.next)
++	{
++	  enum bfd_lto_object_type lto_type = bfd_get_lto_type (p);
++	  /* NB: Treat fat IR object as IR object here.  */
++	  if (lto_type == lto_fat_ir_object)
++	    lto_type = lto_slim_ir_object;
++	  object_type |= 1 << lto_type;
++	  if ((object_type & (1 << lto_mixed_object)) != 0
++	      || ((object_type
++		   & (1 << lto_non_ir_object
++		      | 1 << lto_slim_ir_object))
++		  == (1 << lto_non_ir_object | 1 << lto_slim_ir_object)))
++	    {
++	      config.emit_gnu_object_only = true;
++	      break;
++	    }
++	}
++
++      if (verbose
++	  && (cmdline_object_only_file_list.head
++	      || cmdline_object_only_archive_list.head))
++	{
++	  info_msg (_("Object-only input files:\n "));
++	  print_cmdline_list (cmdline_object_only_file_list.head);
++	  print_cmdline_list (cmdline_object_only_archive_list.head);
++	}
++    }
+ 
+   struct bfd_sym_chain **sym = &link_info.gc_sym_list;
+   while (*sym)
+@@ -10022,3 +10079,967 @@ lang_print_memory_usage (void)
+       printf ("\n");
+     }
+ }
++
++static void
++cmdline_lists_init (void)
++{
++  cmdline_object_only_file_list.tail
++    = &cmdline_object_only_file_list.head;
++  cmdline_object_only_archive_list.tail
++    = &cmdline_object_only_archive_list.head;
++  cmdline_temp_object_only_list.tail
++    = &cmdline_temp_object_only_list.head;
++}
++
++/* Allocate an item with TYPE and DATA.  */
++
++static cmdline_union_type *
++cmdline_list_new (cmdline_enum_type type, void *data)
++{
++  cmdline_union_type *new_opt;
++
++  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
++  new_opt->header.type = type;
++  switch (type)
++    {
++    default:
++      break;
++    case cmdline_is_file_enum:
++      new_opt->file.filename = (const char *) data;
++      break;
++    case cmdline_is_bfd_enum:
++      new_opt->abfd.abfd = (bfd *) data;
++      break;
++    }
++  return new_opt;
++}
++
++/* Append an item with TYPE and DATA to LIST.  */
++
++static void
++cmdline_list_append (cmdline_list_type *list, cmdline_enum_type type,
++		     void *data)
++{
++  cmdline_union_type *new_opt = cmdline_list_new (type, data);
++  new_opt->header.next = NULL;
++  *list->tail = new_opt;
++  list->tail = &new_opt->header.next;
++}
++
++static void
++print_cmdline_list (cmdline_union_type *c)
++{
++  for (; c != NULL; c = c->header.next)
++    switch (c->header.type)
++      {
++      default:
++	abort ();
++      case cmdline_is_file_enum:
++	info_msg (" %s", c->file.filename);
++	break;
++      case cmdline_is_bfd_enum:
++	info_msg (" [%B]", c->abfd.abfd);
++	break;
++      }
++
++  info_msg ("\n");
++}
++
++/* Return TRUE if ABFD is on cmdline_object_only_archive_list.  */
++
++static bool
++cmdline_on_object_only_archive_list_p (bfd *abfd)
++{
++  cmdline_union_type *c, *next;
++  bfd *archive, *obfd, *oarchive;
++  ufile_ptr origin = abfd->origin;
++
++  archive = abfd->my_archive;
++  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
++    {
++      if (c->header.type != cmdline_is_bfd_enum)
++	abort ();
++
++      next = c->header.next;
++      obfd = c->abfd.abfd;
++      oarchive = obfd->my_archive;
++
++      /* The list is grouped by archive file name and sorted by member
++	 origin.  */
++      if (strcmp (archive->filename, oarchive->filename) != 0)
++	continue;
++
++      if (origin == obfd->origin)
++	return true;
++      else if (origin < obfd->origin)
++	return false;
++    }
++
++  return false;
++}
++
++/* Append an item with TYPE and DATA to cmdline_object_only_file_list
++   or cmdline_object_only_archive_list if needed.  */
++
++static void
++cmdline_object_only_list_append (cmdline_enum_type type, void *data)
++{
++  cmdline_union_type *c;
++  cmdline_union_type *new_opt, *next, **prev;
++  bfd *abfd, *archive;
++  bfd *obfd, *oarchive;
++  bfd *nbfd, *narchive;
++  ufile_ptr origin, norigin;
++
++  /* Put it on cmdline_object_only_file_list if it isn't an archive
++     member.  */
++  switch (type)
++    {
++    default:
++      abort ();
++    case cmdline_is_bfd_enum:
++      abfd = (bfd *) data;
++      archive = abfd->my_archive;
++      if (archive)
++	break;
++      /* Fallthru */
++    case cmdline_is_file_enum:
++      cmdline_list_append (&cmdline_object_only_file_list, type, data);
++      return;
++    }
++
++  /* Put archive member on cmdline_object_only_archive_list and sort
++     the list by archive name and archive member origin.  */
++  new_opt = (cmdline_union_type *) stat_alloc (sizeof (*new_opt));
++  new_opt->header.type = cmdline_is_bfd_enum;
++  new_opt->header.next = NULL;
++  new_opt->abfd.abfd = (bfd *) data;
++
++  c = cmdline_object_only_archive_list.head;
++  if (c == NULL)
++    {
++      cmdline_object_only_archive_list.head = new_opt;
++      cmdline_object_only_archive_list.tail = &new_opt->header.next;
++      return;
++    }
++
++  prev = NULL;
++  origin = abfd->origin;
++  for (; c != NULL; c = next)
++    {
++      if (c->header.type != cmdline_is_bfd_enum)
++	abort ();
++
++      next = c->header.next;
++
++      obfd = c->abfd.abfd;
++      oarchive = obfd->my_archive;
++
++      if (strcmp (archive->filename, oarchive->filename) == 0)
++	{
++	  bool after;
++
++	  if (origin < obfd->origin)
++	    {
++	      /* Insert it before the current.  */
++	      new_opt->header.next = c;
++	      if (prev)
++		*prev = new_opt;
++	      else
++		cmdline_object_only_archive_list.head = new_opt;
++	      return;
++	    }
++
++	  after = true;
++
++	  /* Check origin.  */
++	  while (next)
++	    {
++	      if (next->header.type != cmdline_is_bfd_enum)
++		abort ();
++
++	      nbfd = next->abfd.abfd;
++	      norigin = nbfd->origin;
++	      if (origin > norigin)
++		{
++		  /* Insert it after NEXT.  */
++		  break;
++		}
++
++	      narchive = nbfd->my_archive;
++	      if (strcmp (archive->filename, narchive->filename) != 0)
++		{
++		  /* Insert it befor NEXT.  */
++		  after = false;
++		  break;
++		}
++
++	      c = next;
++	      next = next->header.next;
++	    }
++
++	  if (after && next)
++	    {
++	      c = next;
++	      next = next->header.next;
++	    }
++
++	  if (*cmdline_object_only_archive_list.tail == c->header.next)
++	    cmdline_object_only_archive_list.tail
++	      = &new_opt->header.next;
++
++	  prev = &c->header.next;
++	  new_opt->header.next = next;
++	  *prev = new_opt;
++	  return;
++	}
++
++      prev = &c->header.next;
++    }
++
++  *cmdline_object_only_archive_list.tail = new_opt;
++  cmdline_object_only_archive_list.tail = &new_opt->header.next;
++}
++
++/* Get object-only input files.  */
++
++static void
++cmdline_get_object_only_input_files (void)
++{
++  cmdline_union_type *c, *next;
++  bfd *abfd, *archive;
++  bfd *nbfd, *narchive;
++
++  /* Add files first.  */
++  for (c = cmdline_object_only_file_list.head;
++       c != NULL; c = c->header.next)
++    switch (c->header.type)
++      {
++      default:
++	abort ();
++      case cmdline_is_file_enum:
++	lang_add_input_file (c->file.filename,
++			     lang_input_file_is_file_enum, NULL);
++	break;
++      case cmdline_is_bfd_enum:
++	abfd = c->abfd.abfd;
++	if (abfd->my_archive)
++	  abort ();
++	lang_add_input_file (abfd->filename,
++			     lang_input_file_is_file_enum, NULL);
++	break;
++      }
++
++  /* Add archive members next.  */
++  for (c = cmdline_object_only_archive_list.head; c != NULL; c = next)
++    {
++      if (c->header.type != cmdline_is_bfd_enum)
++	abort ();
++
++      next = c->header.next;
++
++      abfd = c->abfd.abfd;
++      archive = abfd->my_archive;
++
++      /* Add the first archive of the archive member group.  */
++      lang_add_input_file (archive->filename,
++			   lang_input_file_is_file_enum, NULL);
++
++      /* Skip the rest members in the archive member group.  */
++      do
++	{
++	  if (!next)
++	    break;
++
++	  if (next->header.type != cmdline_is_bfd_enum)
++	    abort ();
++
++	  next = next->header.next;
++	  if (!next)
++	    break;
++	  nbfd = next->abfd.abfd;
++	  narchive = nbfd->my_archive;
++	}
++      while (strcmp (archive->filename, narchive->filename) == 0);
++    }
++}
++
++struct cmdline_arg
++{
++  bfd *obfd;
++  asymbol **isympp;
++  int status;
++};
++
++/* Create a section in OBFD with the same
++   name and attributes as ISECTION in IBFD.  */
++
++static void
++setup_section (bfd *ibfd, sec_ptr isection, void *p)
++{
++  struct cmdline_arg *arg = (struct cmdline_arg *) p;
++  bfd *obfd = arg->obfd;
++  asymbol **isympp = arg->isympp;
++  const char *name = isection->name;
++  sec_ptr osection;
++  const char *err;
++
++  /* Skip the object-only section.  */
++  if (ibfd->object_only_section == isection)
++    return;
++
++  /* If we have already failed earlier on, do not keep on generating
++     complaints now.  */
++  if (arg->status)
++    return;
++
++  osection = bfd_make_section_anyway_with_flags (obfd, name,
++						 isection->flags);
++
++  if (osection == NULL)
++    {
++      err = _("failed to create output section");
++      goto loser;
++    }
++
++  osection->size = isection->size;
++  osection->vma = isection->vma;
++  osection->lma = isection->lma;
++  osection->alignment_power = isection->alignment_power;
++
++  /* Copy merge entity size.  */
++  osection->entsize = isection->entsize;
++
++  /* This used to be mangle_section; we do here to avoid using
++     bfd_get_section_by_name since some formats allow multiple
++     sections with the same name.  */
++  isection->output_section = osection;
++  isection->output_offset = 0;
++
++  if ((isection->flags & SEC_GROUP) != 0)
++    {
++      asymbol *gsym = bfd_group_signature (isection, isympp);
++
++      if (gsym != NULL)
++	{
++	  gsym->flags |= BSF_KEEP;
++	  if (ibfd->xvec->flavour == bfd_target_elf_flavour)
++	    elf_group_id (isection) = gsym;
++	}
++    }
++
++  /* Allow the BFD backend to copy any private data it understands
++     from the input section to the output section.  */
++  if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
++    {
++      err = _("failed to copy private data");
++      goto loser;
++    }
++
++  /* All went well.  */
++  return;
++
++loser:
++  arg->status = 1;
++  einfo (_("%P%F: setup_section: %s: %s\n"), err, name);
++}
++
++/* Copy the data of input section ISECTION of IBFD
++   to an output section with the same name in OBFD.
++   If stripping then don't copy any relocation info.  */
++
++static void
++copy_section (bfd *ibfd, sec_ptr isection, void *p)
++{
++  struct cmdline_arg *arg = (struct cmdline_arg *) p;
++  bfd *obfd = arg->obfd;
++  asymbol **isympp = arg->isympp;
++  arelent **relpp;
++  long relcount;
++  sec_ptr osection;
++  bfd_size_type size;
++  long relsize;
++  flagword flags;
++  const char *err;
++
++  /* Skip the object-only section.  */
++  if (ibfd->object_only_section == isection)
++    return;
++
++  /* If we have already failed earlier on, do not keep on generating
++     complaints now.  */
++  if (arg->status)
++    return;
++
++  flags = bfd_section_flags (isection);
++  if ((flags & SEC_GROUP) != 0)
++    return;
++
++  osection = isection->output_section;
++  size = bfd_section_size (isection);
++
++  if (size == 0 || osection == 0)
++    return;
++
++  relsize = bfd_get_reloc_upper_bound (ibfd, isection);
++
++  if (relsize < 0)
++    {
++      /* Do not complain if the target does not support relocations.  */
++      if (relsize == -1
++	  && bfd_get_error () == bfd_error_invalid_operation)
++	relsize = 0;
++      else
++	{
++	  err = bfd_errmsg (bfd_get_error ());
++	  goto loser;
++	}
++    }
++
++  if (relsize == 0)
++    bfd_set_reloc (obfd, osection, NULL, 0);
++  else
++    {
++      relpp = (arelent **) xmalloc (relsize);
++      relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
++      if (relcount < 0)
++	{
++	  err = _("relocation count is negative");
++	  goto loser;
++	}
++
++      bfd_set_reloc (obfd, osection,
++		     relcount == 0 ? NULL : relpp, relcount);
++      if (relcount == 0)
++	free (relpp);
++    }
++
++  if (bfd_section_flags (isection) & SEC_HAS_CONTENTS)
++    {
++      bfd_byte *memhunk = NULL;
++
++      if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
++	{
++	  err = bfd_errmsg (bfd_get_error ());
++	  goto loser;
++	}
++
++      if (!bfd_set_section_contents (obfd, osection, memhunk, 0, size))
++	{
++	  err = bfd_errmsg (bfd_get_error ());
++	  goto loser;
++	}
++      free (memhunk);
++    }
++
++  /* All went well.  */
++  return;
++
++loser:
++  einfo (_("%P%F: copy_section: %s: %s\n"), err, isection->name);
++}
++/* Open the temporary bfd created in the same directory as PATH.  */
++
++static bfd *
++cmdline_fopen_temp (const char *path, const char *target,
++		    const char *mode)
++{
++#define template "ldXXXXXX"
++  const char *slash = strrchr (path, '/');
++  char *tmpname;
++  size_t len;
++  int fd;
++
++#ifdef HAVE_DOS_BASED_FILE_SYSTEM
++  {
++    /* We could have foo/bar\\baz, or foo\\bar, or d:bar.  */
++    char *bslash = strrchr (path, '\\');
++
++    if (slash == NULL || (bslash != NULL && bslash > slash))
++      slash = bslash;
++    if (slash == NULL && path[0] != '\0' && path[1] == ':')
++      slash = path + 1;
++  }
++#endif
++
++  if (slash != (char *) NULL)
++    {
++      len = slash - path;
++      tmpname = (char *) xmalloc (len + sizeof (template) + 2);
++      memcpy (tmpname, path, len);
++
++#ifdef HAVE_DOS_BASED_FILE_SYSTEM
++      /* If tmpname is "X:", appending a slash will make it a root
++	 directory on drive X, which is NOT the same as the current
++	 directory on drive X.  */
++      if (len == 2 && tmpname[1] == ':')
++	tmpname[len++] = '.';
++#endif
++      tmpname[len++] = '/';
++    }
++  else
++    {
++      tmpname = (char *) xmalloc (sizeof (template));
++      len = 0;
++    }
++
++  memcpy (tmpname + len, template, sizeof (template));
++#undef template
++
++#ifdef HAVE_MKSTEMP
++  fd = mkstemp (tmpname);
++#else
++  tmpname = mktemp (tmpname);
++  if (tmpname == NULL)
++    return NULL;
++  fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
++#endif
++  if (fd == -1)
++    return NULL;
++  return bfd_fopen (tmpname, target, mode, fd);
++}
++
++/* Add the object-only section.  */
++
++static void
++cmdline_add_object_only_section (bfd_byte *contents, size_t size)
++{
++  bfd_vma start;
++  flagword flags;
++  enum bfd_architecture iarch;
++  unsigned int imach;
++  long symcount;
++  long symsize;
++  asymbol **isympp = NULL;
++  asymbol **osympp = NULL;
++  bfd *obfd = NULL, *ibfd;
++  const char *err;
++  struct arg
++    {
++      bfd *obfd;
++      asymbol **isympp;
++      int status;
++    } arg;
++  char **matching;
++  char *ofilename = NULL;
++  asection *sec;
++
++  ibfd = bfd_openr (output_filename, output_target);
++  if (!ibfd)
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  if (!bfd_check_format_matches (ibfd, bfd_object, &matching))
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  obfd = cmdline_fopen_temp (output_filename, output_target, FOPEN_WB);
++  if (!obfd)
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++  /* To be used after bfd_close ().  */
++  ofilename = xstrdup (bfd_get_filename (obfd));
++
++  if (!bfd_set_format (obfd, bfd_object))
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  /* Copy the start address, flags and architecture of input file to
++     output file.  */
++  flags = bfd_get_file_flags (ibfd);
++  start = bfd_get_start_address (ibfd);
++  iarch = bfd_get_arch (ibfd);
++  imach = bfd_get_mach (ibfd);
++  if (!bfd_set_start_address (obfd, start)
++      || !bfd_set_file_flags (obfd, flags)
++      || !bfd_set_arch_mach (obfd, iarch, imach))
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  symsize = bfd_get_symtab_upper_bound (ibfd);
++  if (symsize < 0)
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  isympp = (asymbol **) xmalloc (symsize);
++  symcount = bfd_canonicalize_symtab (ibfd, isympp);
++  if (symcount < 0)
++    {
++      err = bfd_errmsg (bfd_get_error ());
++      goto loser;
++    }
++
++  arg.obfd = obfd;
++  arg.isympp = isympp;
++  arg.status = 0;
++
++  /* BFD mandates that all output sections be created and sizes set before
++     any output is done.  Thus, we traverse all sections multiple times.  */
++  bfd_map_over_sections (ibfd, setup_section, &arg);
++
++  if (arg.status)
++    {
++      err = _("error setting up sections");
++      goto loser;
++    }
++
++  /* Allow the BFD backend to copy any private data it understands
++     from the input section to the output section.  */
++  if (! bfd_copy_private_header_data (ibfd, obfd))
++    {
++      err = _("error copying private header data");
++      goto loser;
++    }
++
++  /* Create the object-only section.  */
++  sec = bfd_make_section_with_flags (obfd,
++				     GNU_OBJECT_ONLY_SECTION_NAME,
++				     (SEC_HAS_CONTENTS
++				      | SEC_READONLY
++				      | SEC_DATA
++				      | SEC_LINKER_CREATED));
++  if (sec == NULL)
++    {
++      err = _("can't create object-only section");
++      goto loser;
++    }
++
++  if (! bfd_set_section_size (sec, size))
++    {
++      err = _("can't set object-only section size");
++      goto loser;
++    }
++
++  if (ibfd->object_only_section)
++    {
++      /* Filter out the object-only section symbol.  */
++      long src_count = 0, dst_count = 0;
++      asymbol **from, **to;
++
++      osympp = (asymbol **) xmalloc (symcount * sizeof (asymbol *));
++      from = isympp;
++      to = osympp;
++      for (; src_count < symcount; src_count++)
++	{
++	  asymbol *sym = from[src_count];
++	  if (bfd_asymbol_section (sym) != ibfd->object_only_section)
++	    to[dst_count++] = sym;
++	}
++      to[dst_count] = NULL;
++      symcount = dst_count;
++      bfd_set_symtab (obfd, osympp, symcount);
++    }
++  else
++    bfd_set_symtab (obfd, isympp, symcount);
++
++  /* This has to happen after the symbol table has been set.  */
++  bfd_map_over_sections (ibfd, copy_section, &arg);
++
++  if (arg.status)
++    {
++      err = _("error copying sections");
++      goto loser;
++    }
++
++  /* Copy the object-only section to the output.  */
++  if (! bfd_set_section_contents (obfd, sec, contents, 0, size))
++    {
++      err = _("error adding object-only section");
++      goto loser;
++    }
++
++  /* Allow the BFD backend to copy any private data it understands
++     from the input BFD to the output BFD.  This is done last to
++     permit the routine to look at the filtered symbol table, which is
++     important for the ECOFF code at least.  */
++  if (! bfd_copy_private_bfd_data (ibfd, obfd))
++    {
++      err = _("error copying private BFD data");
++      goto loser;
++    }
++
++  if (!bfd_close (obfd))
++    {
++      unlink (ofilename);
++      einfo (_("%P%F: failed to finish output with object-only section\n"));
++    }
++
++  /* Must be freed after bfd_close ().  */
++  free (isympp);
++  if (osympp)
++    free (osympp);
++
++  if (rename (ofilename, output_filename))
++    {
++      unlink (ofilename);
++      einfo (_("%P%F: failed to rename output with object-only section\n"));
++    }
++
++  free (ofilename);
++  return;
++
++loser:
++  if (isympp)
++    free (isympp);
++  if (osympp)
++    free (osympp);
++  if (obfd)
++    bfd_close (obfd);
++  if (ofilename)
++    unlink (ofilename);
++  einfo (_("%P%F: failed to add object-only section: %s\n"), err);
++}
++
++/* Emit the final output with object-only section.  */
++
++void
++cmdline_emit_object_only_section (void)
++{
++  const char *saved_output_filename = output_filename;
++  int fd;
++  size_t size, off;
++  bfd_byte *contents;
++  struct stat st;
++
++  /* Get a temporary object-only file.  */
++  output_filename = make_temp_file (".obj-only.o");
++
++  had_output_filename = false;
++  link_info.input_bfds = NULL;
++  link_info.input_bfds_tail = &link_info.input_bfds;
++
++  lang_init (true);
++  ldexp_init (true);
++
++  ld_parse_linker_script ();
++
++  /* Set up the object-only output. */
++  lang_final ();
++
++  /* Open the object-only file for output.  */
++  lang_for_each_statement (ldlang_open_output);
++
++  ldemul_create_output_section_statements ();
++
++  if (!bfd_section_already_linked_table_init ())
++    einfo (_("%P%F: Failed to create hash table\n"));
++
++  /* Call cmdline_on_object_only_archive_list_p to check which member
++     should be loaded.  */
++  input_flags.whole_archive = true;
++
++  /* Set it to avoid adding more to cmdline lists.  */
++  config.emitting_gnu_object_only = true;
++
++  /* Get object-only input files.  */
++  cmdline_get_object_only_input_files ();
++
++  /* Open object-only input files.  */
++  open_input_bfds (statement_list.head, NULL, OPEN_BFD_NORMAL);
++
++  ldemul_after_open ();
++
++  bfd_section_already_linked_table_free ();
++
++  /* Make sure that we're not mixing architectures.  We call this
++     after all the input files have been opened, but before we do any
++     other processing, so that any operations merge_private_bfd_data
++     does on the output file will be known during the rest of the
++     link.  */
++  lang_check ();
++
++  /* Size up the common data.  */
++  lang_common ();
++
++  /* Update wild statements.  */
++  update_wild_statements (statement_list.head);
++
++  /* Run through the contours of the script and attach input sections
++     to the correct output sections.  */
++  map_input_to_output_sections (statement_list.head, NULL, NULL);
++
++  /* Find any sections not attached explicitly and handle them.  */
++  lang_place_orphans ();
++
++  /* Do anything special before sizing sections.  This is where ELF
++     and other back-ends size dynamic sections.  */
++  ldemul_before_allocation ();
++
++  /* Size up the sections.  */
++  lang_size_sections (NULL, ! RELAXATION_ENABLED);
++
++  /* See if anything special should be done now we know how big
++     everything is.  This is where relaxation is done.  */
++  ldemul_after_allocation ();
++
++  ldemul_finish ();
++
++  /* Make sure that the section addresses make sense.  */
++  if (command_line.check_section_addresses)
++    lang_check_section_addresses ();
++
++  lang_end ();
++
++  ldwrite ();
++
++  ldexp_finish (true);
++  lang_finish ();
++
++  if (! bfd_close (link_info.output_bfd))
++    einfo (_("%P%F:%s: final close failed on object-only output: %E\n"),
++	   output_filename);
++
++  link_info.output_bfd = NULL;
++
++  /* Read in the object-only file.  */
++  fd = open (output_filename, O_RDONLY | O_BINARY);
++  if (fd < 0)
++    {
++      bfd_set_error (bfd_error_system_call);
++      einfo (_("%P%F:%s: cannot open object-only output: %E\n"),
++	     output_filename);
++    }
++
++  /* Get the object-only file size.  */
++  if (fstat (fd, &st) != 0)
++    {
++      bfd_set_error (bfd_error_system_call);
++      einfo (_("%P%F:%s: cannot stat object-only output: %E\n"),
++	     output_filename);
++    }
++
++  size = st.st_size;
++  off = 0;
++  contents = (bfd_byte *) xmalloc (size);
++  while (off != size)
++    {
++      ssize_t got;
++
++      got = read (fd, contents + off, size - off);
++      if (got < 0)
++	{
++	  bfd_set_error (bfd_error_system_call);
++	  einfo (_("%P%F:%s: read failed on object-only output: %E\n"),
++		 output_filename);
++	}
++
++      off += got;
++    }
++
++  close (fd);
++
++  /* Remove the temporary object-only file.  */
++  unlink (output_filename);
++
++  output_filename = saved_output_filename;
++
++  cmdline_add_object_only_section (contents, size);
++
++  free (contents);
++}
++
++/* Extract the object-only section.  */
++
++static const char *
++cmdline_extract_object_only_section (bfd *abfd)
++{
++  const char *name = bfd_extract_object_only_section (abfd);
++
++  if (name == NULL)
++    einfo (_("%P%F: cannot extract object-only section from %B: %E\n"),
++	   abfd);
++
++  /* It should be removed after it is done.  */
++  cmdline_list_append (&cmdline_temp_object_only_list,
++		       cmdline_is_file_enum, (void *) name);
++
++  return name;
++}
++
++/* Check and handle the object-only section.   */
++
++void
++cmdline_check_object_only_section (bfd *abfd, bool lto)
++{
++  const char *filename;
++
++  if (config.emitting_gnu_object_only || abfd->format != bfd_object)
++    return;
++
++  if (lto)
++    {
++      /* For LTO link, we only need to extract object-only section
++	 from the mixed object, add it to input, and put it on LTO
++	 claimed output.  */
++      switch (bfd_get_lto_type (abfd))
++	{
++	default:
++	  abort ();
++	case lto_mixed_object:
++	  filename = cmdline_extract_object_only_section (abfd);
++	  lang_add_input_file (filename,
++			       lang_input_file_is_file_enum, NULL);
++	  break;
++	case lto_non_ir_object:
++	case lto_slim_ir_object:
++	case lto_fat_ir_object:
++	  break;
++	}
++    }
++  else if (bfd_link_relocatable (&link_info))
++    {
++      /* For non-LTO relocatable link, we need to append non-IR object
++	 file and the object file in object-only section to the object
++	 only list.  */
++      switch (bfd_get_lto_type (abfd))
++	{
++	default:
++	  abort ();
++	case lto_mixed_object:
++	  filename = cmdline_extract_object_only_section (abfd);
++	  cmdline_object_only_list_append (cmdline_is_file_enum,
++					  (void *) filename);
++	  break;
++	case lto_non_ir_object:
++	  cmdline_object_only_list_append (cmdline_is_bfd_enum, abfd);
++	  break;
++	case lto_slim_ir_object:
++	case lto_fat_ir_object:
++	  break;
++	}
++    }
++}
++
++/* Remove temporary object-only files.  */
++
++void
++cmdline_remove_object_only_files (void)
++{
++  cmdline_union_type *c;
++
++  if (config.plugin_save_temps)
++    return;
++
++  c = cmdline_temp_object_only_list.head;
++  for (; c != NULL; c = c->header.next)
++    switch (c->header.type)
++      {
++      default:
++	abort ();
++      case cmdline_is_file_enum:
++	unlink (c->file.filename);
++	break;
++      }
++}
+diff --git a/ld/ldlang.h b/ld/ldlang.h
+index e32c5acaaca..91779a584b4 100644
+--- a/ld/ldlang.h
++++ b/ld/ldlang.h
+@@ -552,7 +552,7 @@ extern struct asneeded_minfo **asneeded_list_tail;
+ extern void (*output_bfd_hash_table_free_fn) (struct bfd_link_hash_table *);
+ 
+ extern void lang_init
+-  (void);
++  (bool);
+ extern void lang_finish
+   (void);
+ extern lang_memory_region_type * lang_memory_region_lookup
+@@ -746,4 +746,46 @@ print_one_symbol (struct bfd_link_hash_entry *, void *);
+ 
+ extern void lang_add_version_string
+   (void);
++
++typedef enum
++{
++  cmdline_is_file_enum,
++  cmdline_is_bfd_enum
++} cmdline_enum_type;
++
++typedef struct cmdline_header_struct
++{
++  union cmdline_union *next;
++  cmdline_enum_type type;
++} cmdline_header_type;
++
++typedef struct cmdline_file_struct
++{
++  cmdline_header_type header;
++  const char *filename;
++} cmdline_file_type;
++
++typedef struct cmdline_bfd_struct
++{
++  cmdline_header_type header;
++  bfd *abfd;
++} cmdline_bfd_type;
++
++typedef union cmdline_union
++{
++  cmdline_header_type header;
++  cmdline_file_type file;
++  cmdline_bfd_type abfd;
++} cmdline_union_type;
++
++typedef struct cmdline_list
++{
++  cmdline_union_type *head;
++  cmdline_union_type **tail;
++} cmdline_list_type;
++
++extern void cmdline_emit_object_only_section (void);
++extern void cmdline_check_object_only_section (bfd *, bool);
++extern void cmdline_remove_object_only_files (void);
++
+ #endif
+diff --git a/ld/ldmain.c b/ld/ldmain.c
+index 64c4cce8371..dcef7bb9278 100644
+--- a/ld/ldmain.c
++++ b/ld/ldmain.c
+@@ -302,6 +302,9 @@ main (int argc, char **argv)
+ 
+   xatexit (ld_cleanup);
+ 
++  /* Remove temporary object-only files.  */
++  xatexit (cmdline_remove_object_only_files);
++
+   /* Set up the sysroot directory.  */
+   ld_sysroot = get_sysroot (argc, argv);
+   if (*ld_sysroot)
+@@ -391,8 +394,8 @@ main (int argc, char **argv)
+   emulation = get_emulation (argc, argv);
+   ldemul_choose_mode (emulation);
+   default_target = ldemul_choose_target (argc, argv);
+-  lang_init ();
+-  ldexp_init ();
++  lang_init (false);
++  ldexp_init (false);
+   ldemul_before_parse ();
+   lang_has_input_file = false;
+   parse_args (argc, argv);
+@@ -407,34 +410,7 @@ main (int argc, char **argv)
+ 
+   ldemul_set_symbols ();
+ 
+-  /* If we have not already opened and parsed a linker script,
+-     try the default script from command line first.  */
+-  if (saved_script_handle == NULL
+-      && command_line.default_script != NULL)
+-    {
+-      ldfile_open_script_file (command_line.default_script);
+-      parser_input = input_script;
+-      yyparse ();
+-    }
+-
+-  /* If we have not already opened and parsed a linker script
+-     read the emulation's appropriate default script.  */
+-  if (saved_script_handle == NULL)
+-    {
+-      int isfile;
+-      char *s = ldemul_get_script (&isfile);
+-
+-      if (isfile)
+-	ldfile_open_default_command_file (s);
+-      else
+-	{
+-	  lex_string = s;
+-	  lex_redirect (s, _("built in linker script"), 1);
+-	}
+-      parser_input = input_script;
+-      yyparse ();
+-      lex_string = NULL;
+-    }
++  ld_parse_linker_script ();
+ 
+   if (verbose)
+     {
+@@ -572,7 +548,7 @@ main (int argc, char **argv)
+     fprintf (stderr, "lookup = %p val %lx\n", h, h ? h->u.def.value : 1);
+   }
+ #endif
+-  ldexp_finish ();
++  ldexp_finish (false);
+   lang_finish ();
+ 
+   if (config.dependency_file != NULL)
+@@ -597,6 +573,8 @@ main (int argc, char **argv)
+       if (!bfd_close (obfd))
+ 	einfo (_("%F%P: %s: final close failed: %E\n"), output_filename);
+ 
++      link_info.output_bfd = NULL;
++
+       /* If the --force-exe-suffix is enabled, and we're making an
+ 	 executable file and it doesn't end in .exe, copy it to one
+ 	 which does.  */
+@@ -644,6 +622,9 @@ main (int argc, char **argv)
+ 	}
+     }
+ 
++  if (config.emit_gnu_object_only)
++    cmdline_emit_object_only_section ();
++
+   if (config.stats)
+     {
+       long run_time = get_run_time () - start_time;
+@@ -951,7 +932,9 @@ add_archive_element (struct bfd_link_info *info,
+ 	  *subsbfd = input->the_bfd;
+ 	}
+     }
++  else
+ #endif /* BFD_SUPPORTS_PLUGINS */
++    cmdline_check_object_only_section (input->the_bfd, false);
+ 
+   if (link_info.input_bfds_tail == &input->the_bfd->link.next
+       || input->the_bfd->link.next != NULL)
+@@ -1694,3 +1677,38 @@ notice (struct bfd_link_info *info,
+ 
+   return true;
+ }
++
++/* Parse the linker script.   */
++
++void
++ld_parse_linker_script (void)
++{
++  /* If we have not already opened and parsed a linker script,
++     try the default script from command line first.  */
++  if (saved_script_handle == NULL
++      && command_line.default_script != NULL)
++    {
++      ldfile_open_script_file (command_line.default_script);
++      parser_input = input_script;
++      yyparse ();
++    }
++
++  /* If we have not already opened and parsed a linker script
++     read the emulation's appropriate default script.  */
++  if (saved_script_handle == NULL)
++    {
++      int isfile;
++      char *s = ldemul_get_script (&isfile);
++
++      if (isfile)
++	ldfile_open_default_command_file (s);
++      else
++	{
++	  lex_string = s;
++	  lex_redirect (s, _("built in linker script"), 1);
++	}
++      parser_input = input_script;
++      yyparse ();
++      lex_string = NULL;
++    }
++}
+diff --git a/ld/ldmain.h b/ld/ldmain.h
+index 0baa3c305c3..34770762f1c 100644
+--- a/ld/ldmain.h
++++ b/ld/ldmain.h
+@@ -63,4 +63,6 @@ extern void add_ignoresym (struct bfd_link_info *, const char *);
+ extern void add_keepsyms_file (const char *);
+ extern void track_dependency_files (const char *);
+ 
++extern void ld_parse_linker_script (void);
++
+ #endif
+diff --git a/ld/plugin.c b/ld/plugin.c
+index ecced25bd9b..ea0c6fcdd67 100644
+--- a/ld/plugin.c
++++ b/ld/plugin.c
+@@ -1341,6 +1341,9 @@ plugin_maybe_claim (lang_input_statement_type *entry)
+     {
+       bfd *abfd = entry->the_bfd->plugin_dummy_bfd;
+ 
++      /* Check object only section.  */
++      cmdline_check_object_only_section (entry->the_bfd, true);
++
+       /* Discard the real file's BFD and substitute the dummy one.  */
+ 
+       /* We can't call bfd_close on archives.  BFD archive handling
+diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
+index ccecc1088b8..deb69dde543 100644
+--- a/ld/scripttempl/elf.sc
++++ b/ld/scripttempl/elf.sc
+@@ -244,7 +244,7 @@ RELA_IPLT=".rela.iplt    ${RELOCATING-0} :
+ DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
+ RODATA=".${RODATA_NAME}       ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
+ DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
+-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
++DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
+ if test -z "${NO_SMALL_DATA}"; then
+   SBSS=".${SBSS_NAME}         ${RELOCATING-0} :
+   {
+diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc
+index c468453d79d..b6701bf1d26 100644
+--- a/ld/scripttempl/elf64hppa.sc
++++ b/ld/scripttempl/elf64hppa.sc
+@@ -132,7 +132,7 @@ fi
+ DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
+ RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
+ DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
+-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
++DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
+ if test -z "${NO_SMALL_DATA}"; then
+   SBSS=".sbss         ${RELOCATING-0} :
+   {
+diff --git a/ld/scripttempl/elfxtensa.sc b/ld/scripttempl/elfxtensa.sc
+index fcda83c4dc9..2f62c2dbc54 100644
+--- a/ld/scripttempl/elfxtensa.sc
++++ b/ld/scripttempl/elfxtensa.sc
+@@ -145,7 +145,7 @@ fi
+ DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
+ RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
+ DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
+-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
++DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
+ INIT_LIT=".init.literal 0 : { *(.init.literal)	}"
+ INIT=".init         0 : { KEEP (*(SORT_NONE(.init))) }"
+ FINI_LIT=".fini.literal 0 : { *(.fini.literal)	}"
+diff --git a/ld/scripttempl/mep.sc b/ld/scripttempl/mep.sc
+index 7f0f46ae8e9..8fdf3117a40 100644
+--- a/ld/scripttempl/mep.sc
++++ b/ld/scripttempl/mep.sc
+@@ -119,7 +119,7 @@ fi
+ DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
+ RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
+ DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
+-DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink)  *(.gnu.lto_*) }"
++DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.gnu_object_only) }"
+ if test -z "${NO_SMALL_DATA}"; then
+   SBSS=".sbss         ${RELOCATING-0} :
+   {
+diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
+index 6ca5f040a36..96a47515444 100644
+--- a/ld/scripttempl/pe.sc
++++ b/ld/scripttempl/pe.sc
+@@ -230,6 +230,7 @@ SECTIONS
+     ${RELOCATING+ *(.drectve)}
+     ${RELOCATING+ *(.note.GNU-stack)}
+     ${RELOCATING+ *(.gnu.lto_*)}
++    ${RELOCATING+ *(.gnu_object_only)}
+   }
+ 
+   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
+diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
+index d9ba2be49d9..e2c6c2cedd2 100644
+--- a/ld/scripttempl/pep.sc
++++ b/ld/scripttempl/pep.sc
+@@ -237,6 +237,7 @@ SECTIONS
+     ${RELOCATING+ *(.drectve)}
+     ${RELOCATING+ *(.note.GNU-stack)}
+     ${RELOCATING+ *(.gnu.lto_*)}
++    ${RELOCATING+ *(.gnu_object_only)}
+   }
+ 
+   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
+diff --git a/ld/testsuite/ld-plugin/lto-10.out b/ld/testsuite/ld-plugin/lto-10.out
+new file mode 100644
+index 00000000000..ce013625030
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-10.out
+@@ -0,0 +1 @@
++hello
+diff --git a/ld/testsuite/ld-plugin/lto-10a.c b/ld/testsuite/ld-plugin/lto-10a.c
+new file mode 100644
+index 00000000000..93d57b520cb
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-10a.c
+@@ -0,0 +1,6 @@
++extern int foo(void);
++
++int main(void)
++{
++  return foo();
++}
+diff --git a/ld/testsuite/ld-plugin/lto-10b.c b/ld/testsuite/ld-plugin/lto-10b.c
+new file mode 100644
+index 00000000000..507055be341
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-10b.c
+@@ -0,0 +1,7 @@
++#include <stdio.h>
++
++int foo(void)
++{
++  printf ("hello\n");
++  return 0;
++}
+diff --git a/ld/testsuite/ld-plugin/lto-10r.d b/ld/testsuite/ld-plugin/lto-10r.d
+new file mode 100644
+index 00000000000..3502056153d
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-10r.d
+@@ -0,0 +1,9 @@
++#ld: -r tmpdir/lto-10a.o tmpdir/lto-10b.o
++#source: dummy.s
++#objdump: -h
++
++#...
++ *[0-9]+ +\.gnu\.lto_\.[0-9a-zA-Z_\.]+ +[0-9a-f]+ +[0-9a-f]+  +[0-9a-f]+ +[0-9a-f]+ .*
++#...
++ *[0-9]+ +\.gnu_object_only +[0-9a-f]+ +0+ +0+ +0+[1-9a-f][0-9a-f]+ +.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/lto-4.out b/ld/testsuite/ld-plugin/lto-4.out
+new file mode 100644
+index 00000000000..8d8cc9240c8
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4.out
+@@ -0,0 +1,2 @@
++hello bar
++hello foo
+diff --git a/ld/testsuite/ld-plugin/lto-4a.c b/ld/testsuite/ld-plugin/lto-4a.c
+new file mode 100644
+index 00000000000..2d07cf585da
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4a.c
+@@ -0,0 +1,7 @@
++extern void foo(void);
++
++int main(void)
++{
++  foo();
++  return 0;
++}
+diff --git a/ld/testsuite/ld-plugin/lto-4b.c b/ld/testsuite/ld-plugin/lto-4b.c
+new file mode 100644
+index 00000000000..bb4a68bb986
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4b.c
+@@ -0,0 +1,9 @@
++#include <stdio.h>
++
++extern void bar (void);
++
++void foo(void)
++{
++  bar ();
++  printf ("hello foo\n");
++}
+diff --git a/ld/testsuite/ld-plugin/lto-4c.c b/ld/testsuite/ld-plugin/lto-4c.c
+new file mode 100644
+index 00000000000..317e6fcdacd
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4c.c
+@@ -0,0 +1,6 @@
++#include <stdio.h>
++
++void bar (void)
++{
++  printf ("hello bar\n");
++}
+diff --git a/ld/testsuite/ld-plugin/lto-4r-a.d b/ld/testsuite/ld-plugin/lto-4r-a.d
+new file mode 100644
+index 00000000000..c618cffb028
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4r-a.d
+@@ -0,0 +1,7 @@
++#ld: -r tmpdir/lto-4a.o tmpdir/lto-4b.o tmpdir/lto-4c.o
++#source: dummy.s
++#objdump: -h
++
++#...
++.* .gnu_object_only.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/lto-4r-b.d b/ld/testsuite/ld-plugin/lto-4r-b.d
+new file mode 100644
+index 00000000000..07d71cb5328
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4r-b.d
+@@ -0,0 +1,7 @@
++#ld: -r tmpdir/lto-4a.o tmpdir/lto-4b.o
++#source: dummy.s
++#objdump: -h
++
++#...
++.* .gnu_object_only.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/lto-4r-c.d b/ld/testsuite/ld-plugin/lto-4r-c.d
+new file mode 100644
+index 00000000000..4e691ea01ac
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4r-c.d
+@@ -0,0 +1,7 @@
++#ld: -r tmpdir/lto-4r-b.o tmpdir/lto-4c.o --no-warn-execstack --no-error-execstack
++#source: dummy.s
++#objdump: -h
++
++#...
++.* .gnu_object_only.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/lto-4r-d.d b/ld/testsuite/ld-plugin/lto-4r-d.d
+new file mode 100644
+index 00000000000..d4c58526cc5
+--- /dev/null
++++ b/ld/testsuite/ld-plugin/lto-4r-d.d
+@@ -0,0 +1,7 @@
++#ld: -r --whole-archive tmpdir/liblto-4.a
++#source: dummy.s
++#objdump: -h
++
++#...
++.* .gnu_object_only.*
++#pass
+diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
+index e36480aee78..e454b485ed9 100644
+--- a/ld/testsuite/ld-plugin/lto.exp
++++ b/ld/testsuite/ld-plugin/lto.exp
+@@ -72,6 +72,15 @@ set lto_link_tests [list \
+   [list "Build liblto-3.a" \
+    "" "-flto $lto_fat" \
+    {lto-3b.c} {} "liblto-3.a"] \
++  [list "Compile 4a" \
++   "" "-flto $lto_fat" \
++   {lto-4a.c} {} ""] \
++  [list "Compile 4b" \
++   "" "-O2" \
++   {lto-4b.c} {} ""] \
++  [list "Compile 4c" \
++   "" "-O2" \
++   {lto-4c.c} {} ""] \
+   [list "Compile 5a" \
+    "" "-flto $lto_fat" \
+    {lto-5a.c} {} ""] \
+@@ -84,6 +93,12 @@ set lto_link_tests [list \
+   [list "Compile 9" \
+    "" "-O2 -finline -flto" \
+    {lto-9.cc} {} "" "c++"] \
++  [list "Compile 10a" \
++   "" "-O2" \
++   {lto-10a.c} {} ""] \
++  [list "Compile 10b" \
++   "" "-O2 -flto $lto_fat" \
++   {lto-10b.c} {} ""] \
+   [list "Compile 11a" \
+    "" "-O -flto" \
+    {lto-11a.c} {} ""] \
+@@ -711,9 +726,29 @@ set lto_run_tests [list \
+   [list "LTO 3c" \
+    "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
+    {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
++  [list "LTO 4a" \
++   "-O2 -flto -fuse-linker-plugin \
++    -Wl,--no-warn-execstack,--no-error-execstack \
++    tmpdir/lto-4r-a.o" "" \
++   {dummy.c} "lto-4a.exe" "lto-4.out" "" "c"] \
++  [list "LTO 4c" \
++   "-O2 -flto -fuse-linker-plugin \
++    -Wl,--no-warn-execstack,--no-error-execstack \
++    tmpdir/lto-4r-c.o" "" \
++   {dummy.c} "lto-4c.exe" "lto-4.out" "" "c"] \
++  [list "LTO 4d" \
++   "-O2 -flto -fuse-linker-plugin \
++    -Wl,--no-warn-execstack,--no-error-execstack \
++    tmpdir/lto-4r-d.o" "" \
++   {dummy.c} "lto-4d.exe" "lto-4.out" "" "c"] \
+   [list "LTO 5" \
+    "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
+    {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
++  [list "LTO 10" \
++   "-O2 -flto -fuse-linker-plugin \
++    -Wl,--no-warn-execstack,--no-error-execstack \
++    tmpdir/lto-10.o" "" \
++   {dummy.c} "lto-10.exe" "lto-10.out" "" "c"] \
+   [list "LTO 11" \
+    "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
+    {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
+@@ -979,6 +1014,15 @@ if [string match "" $exec_output] then {
+     fail "PR ld/28138 (build only)"
+ }
+ 
++set testname "Build liblto-4.a"
++remote_file host delete "tmpdir/liblto-4.a"
++set catch_output [run_host_cmd "$ar" "rc tmpdir/liblto-4.a tmpdir/lto-4a.o tmpdir/lto-4b.o tmpdir/lto-4c.o"]
++if {![string match "" $catch_output]} {
++    unresolved $testname
++    restore_notify
++    return
++}
++
+ set testname "Build liblto-11.a"
+ remote_file host delete "tmpdir/liblto-11.a"
+ set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"]
+@@ -1091,8 +1135,30 @@ if { [at_least_gcc_version 4 7] } {
+ # Run "ld -r" to generate inputs for complex LTO tests.
+ run_dump_test "lto-3r"
+ remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
++run_dump_test "lto-4r-a"
++remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-a.o"
++run_dump_test "lto-4r-b"
++remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-b.o"
++run_dump_test "lto-4r-c"
++remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-c.o"
++run_dump_test "lto-4r-d"
++remote_exec host "mv" "tmpdir/dump tmpdir/lto-4r-d.o"
+ run_dump_test "lto-5r"
+ remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
++run_dump_test "lto-10r"
++remote_exec host "mv" "tmpdir/dump tmpdir/lto-10.o"
++set testname "nm mixed object"
++set lto_plugin [string trim [run_host_cmd "$CC_FOR_TARGET" "-print-prog-name=liblto_plugin.so"]]
++if { [ regexp "liblto_plugin.so" $lto_plugin ] } {
++    set exec_output [run_host_cmd "$NM" "--plugin $lto_plugin tmpdir/lto-10.o"]
++    if { [ regexp "T main" $exec_output ] } {
++	pass $testname
++    } {
++	fail $testname
++    }
++} {
++    fail $testname
++ }
+ 
+ run_cc_link_tests $lto_link_symbol_tests
+ 
+-- 
+2.48.0
+

diff --git a/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch b/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch
new file mode 100644
index 0000000..9c17dc9
--- /dev/null
+++ b/9999/0007-ld-Document-mixing-LTO-and-non-LTO-objects-for-r.patch
@@ -0,0 +1,42 @@
+From 2c86c77dc5795a7f1e8f915c138c27893d8141d4 Mon Sep 17 00:00:00 2001
+Message-ID: <2c86c77dc5795a7f1e8f915c138c27893d8141d4.1736748624.git.sam@gentoo.org>
+In-Reply-To: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
+References: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Sat, 11 Jan 2025 07:23:27 +0800
+Subject: [PATCH 7/8] ld: Document mixing LTO and non-LTO objects for -r
+
+	* ld.texi: Document mixing LTO and non-LTO relocatable files for
+	"ld -r".
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ ld/ld.texi | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/ld/ld.texi b/ld/ld.texi
+index da714a20855..d1787453f57 100644
+--- a/ld/ld.texi
++++ b/ld/ld.texi
+@@ -1126,6 +1126,18 @@ relocations.  Different output formats can have further restrictions; for
+ example some @code{a.out}-based formats do not support partial linking
+ with input files in other formats at all.
+ 
++On ELF platforms, when the relocatable output contains both contents
++which require link-time optimization (LTO) and contents which don't
++require LTO, a .gnu_object_only section will be created to contain a
++relocatable object file, as if @samp{-r} is applied to all relocatable
++inputs which don't require LTO.  When processing a relocatable input
++with a .gnu_object_only section, the linker will extract the
++.gnu_object_only section as a separate input.
++
++Note that since @samp{-r} groups some sections from different input files
++together, there may be negative impacts on code size and locality in
++final executable or shared library.
++
+ This option does the same thing as @samp{-i}.
+ 
+ @kindex -R @var{file}
+-- 
+2.48.0
+

diff --git a/9999/0008-h8300-Handle-.gnu_object_only-section.patch b/9999/0008-h8300-Handle-.gnu_object_only-section.patch
new file mode 100644
index 0000000..1336250
--- /dev/null
+++ b/9999/0008-h8300-Handle-.gnu_object_only-section.patch
@@ -0,0 +1,37 @@
+From c5f942b863c660280535dac32586e64d45308550 Mon Sep 17 00:00:00 2001
+Message-ID: <c5f942b863c660280535dac32586e64d45308550.1736748624.git.sam@gentoo.org>
+In-Reply-To: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
+References: <9f57274faacf1dbb6c2b56d29de150b5e79ecb3d.1736748624.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 27 Oct 2020 06:39:59 -0700
+Subject: [PATCH 8/8] h8300: Handle .gnu_object_only section
+
+	PR ld/12291
+	PR ld/12430
+	PR ld/13298
+	* config/tc-h8300.c (h8300_elf_section): Handle .gnu_object_only
+	section.
+---
+ gas/config/tc-h8300.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c
+index f8e54064166..105461da92b 100644
+--- a/gas/config/tc-h8300.c
++++ b/gas/config/tc-h8300.c
+@@ -146,8 +146,10 @@ pint (int arg ATTRIBUTE_UNUSED)
+ static void
+ h8300_elf_section (int push)
+ {
+-  static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
+-  static const char * known_data_prefixes [] = { ".debug", ".zdebug", ".gnu.warning" };
++  static const char * known_data_sections []
++    = { ".rodata", ".tdata", ".tbss", ".gnu_object_only" };
++  static const char * known_data_prefixes []
++    = { ".debug", ".zdebug", ".gnu.warning" };
+   char * saved_ilp = input_line_pointer;
+   const char * name;
+ 
+-- 
+2.48.0
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-01-02 13:48 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-01-02 13:48 UTC (permalink / raw
  To: gentoo-commits

commit:     58f7f7f524284de1cbbacdc6403021b1d33a720b
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  2 13:48:12 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Jan  2 13:48:12 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=58f7f7f5

9999: drop macro reverts

H.J. landed it upstream now.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-Revert-PR-32391-memory-leak.patch        |  28 -
 ...7-Revert-macro.c-871-heap-buffer-overflow.patch |  38 -
 9999/0008-Revert-PR-32391-testcase.patch           | 185 -----
 ...Fix-error-macro-may-be-used-uninitialized.patch |  39 -
 ...the-handling-or-arguments-and-macro-pseud.patch | 900 ---------------------
 5 files changed, 1190 deletions(-)

diff --git a/9999/0006-Revert-PR-32391-memory-leak.patch b/9999/0006-Revert-PR-32391-memory-leak.patch
deleted file mode 100644
index a20c54d..0000000
--- a/9999/0006-Revert-PR-32391-memory-leak.patch
+++ /dev/null
@@ -1,28 +0,0 @@
-From 4bed21d47f9d838dc6b55ce026989ede4eacc789 Mon Sep 17 00:00:00 2001
-Message-ID: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Wed, 1 Jan 2025 14:03:43 +0000
-Subject: [PATCH 06/10] Revert "PR 32391 memory leak"
-
-This reverts commit 599739cc1c5d70ac958583130b4b5413aa101d8e.
----
- gas/macro.c | 1 -
- 1 file changed, 1 deletion(-)
-
-diff --git a/gas/macro.c b/gas/macro.c
-index 9eefc8360b1..9670b38c152 100644
---- a/gas/macro.c
-+++ b/gas/macro.c
-@@ -878,7 +878,6 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
- 	      (void) macro_expand_body (add, &newadd, NULL, NULL,
- 					orig_macro, orig_macro->count);
- 	      sb_add_sb (out, &newadd);
--	      sb_kill (&newadd);
- 	    }
- 	  else
- 	    {
-
-base-commit: 94e2b2a770fc49e42c9baec80f4fb88f63391a4e
--- 
-2.47.1
-

diff --git a/9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch b/9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch
deleted file mode 100644
index b461443..0000000
--- a/9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From 7daa5da3eab39e733f40eccbf4f6cd2078e3335e Mon Sep 17 00:00:00 2001
-Message-ID: <7daa5da3eab39e733f40eccbf4f6cd2078e3335e.1735740264.git.sam@gentoo.org>
-In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Wed, 1 Jan 2025 14:03:44 +0000
-Subject: [PATCH 07/10] Revert "macro.c:871 heap-buffer-overflow"
-
-This reverts commit 6d9b7667974372357fed1f02c54a805f8c21dcde.
----
- gas/macro.c | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/gas/macro.c b/gas/macro.c
-index 9670b38c152..5fa2011ab7a 100644
---- a/gas/macro.c
-+++ b/gas/macro.c
-@@ -868,7 +868,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
- 	  /* The parent's FORMALs might contain parameters that need further
- 	     substitution.  See gas/testsuite/gas/arm/macro-vld1.s for an
- 	     example of this.  */
--	  if (memchr (add->ptr, '\\', add->len))
-+	  if (strchr (add->ptr, '\\'))
- 	    {
- 	      sb newadd;
- 
-@@ -1485,7 +1485,7 @@ delete_macro (const char *name)
- 	}
-     }
- 
--  if (j < 0)
-+  if (macro == NULL)
-     as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
- 
-   free (copy);
--- 
-2.47.1
-

diff --git a/9999/0008-Revert-PR-32391-testcase.patch b/9999/0008-Revert-PR-32391-testcase.patch
deleted file mode 100644
index 4376e58..0000000
--- a/9999/0008-Revert-PR-32391-testcase.patch
+++ /dev/null
@@ -1,185 +0,0 @@
-From da631c6ce21783acebd2dc44b834fd17c84a0381 Mon Sep 17 00:00:00 2001
-Message-ID: <da631c6ce21783acebd2dc44b834fd17c84a0381.1735740264.git.sam@gentoo.org>
-In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Wed, 1 Jan 2025 14:03:45 +0000
-Subject: [PATCH 08/10] Revert "PR 32391 testcase"
-
-This reverts commit c8fcfa9aad211dfd8296ae6e978a356797936c61.
----
- gas/testsuite/gas/macros/nesting.s | 120 ++++++++++++++---------------
- 1 file changed, 60 insertions(+), 60 deletions(-)
-
-diff --git a/gas/testsuite/gas/macros/nesting.s b/gas/testsuite/gas/macros/nesting.s
-index 9746ca183ef..438d5af8d00 100644
---- a/gas/testsuite/gas/macros/nesting.s
-+++ b/gas/testsuite/gas/macros/nesting.s
-@@ -1,104 +1,104 @@
-- .text
-+
-+	.text
- /* PR 32391: Automatic counters inside macros should increment when nested
--   macros finish execution.  */
-- .macro o1
-- .global before_at_\@
-+	macros finish execution.  */
-+.macro o1
-+.global before_at_\@
- before_at_\@:
-- .global before_plus_\+
-+.global before_plus_\+
- before_plus_\+:
- 
-- .macro i1
-- .global inside_at_\@
-+	.macro i1
-+.global inside_at_\@
- inside_at_\@:
-- .global inside_plus_\+
-+.global inside_plus_\+
- inside_plus_\+:
-- .endm
-+	.endm
- 
-- i1
-- i1
-+	i1
-+	i1
- 
-- .global after_at_\@
-+.global after_at_\@
- after_at_\@:
-- .global after_plus_\+
-+.global after_plus_\+
- after_plus_\+:
- 
-- .endm
-+.endm
- 
- /* Invoking o1 should produce these symbols in this order:
- 
--   before_at_0
--   before_plus_0
--   inside_at_1
--   inside_plus_0
--   inside_at_2
--   inside_plus_1
--   after_at_0
--   after_plus_0  */
-- o1
--
-+	before_at_0
-+	before_plus_0
-+	inside_at_1
-+	inside_plus_0
-+	inside_at_2
-+	inside_plus_1
-+	after_at_0
-+	after_plus_0  */
-+o1
-+	
- /* A second invocation of o1 should not produce any errors about
--   symbols or macros being redefined.  */
-- o1
--
-+	symbols or macros being redefined.  */
-+o1
-+	
- /* This definition should not collide with the definition inside o1.  */
-- .macro i1
-- .global other_inner_\@
-+.macro i1
-+.global other_inner_\@
- other_inner_\@:
-- .endm
-+.endm 
- 
--/* And invoking it should invoke the second defintion of i1, not the first.  */
-- i1
--
-- .macro o2
-- .global _m\@_
-+/* And invoking it should invoke the second defintion of i1, not the first.  */	
-+i1
-+		
-+.macro o2
-+.global _m\@_
- _m\@_:
-- .macro i2
-- .global _m\@_
-+.macro i2
-+.global _m\@_
- _m\@_:
-- .endm
-- i2
-- .endm
-+.endm
-+i2
-+.endm
- 
- /* This should not generate conflicting symbols because the assembler
-    inserts the contents of o2 into the input buffer as pure text (ie
-    without evaluating i2).  The first use of \@ is evaluated at this
-    time, creating _m4_.  But the second use is not evaluated because
-    it is inside a .macro definition.
--
-+	
-    This finishes the evaluation of o2, so the \@ counter is incremented.
--
-+	
-    Next the input buffer is re-evaluated and the i2 macro definition
-    and invocation are encounterd.  The text from i2 are inserted into
-    the input buffer and at this point the second use of \@ is evaluated
-    resulting in the creation of a symbol called _m5_.  */
-- o2
-+o2
- 
- /* Macro arguments should be independent of nesting.  */
-- .macro O3 arg
-- .global o3_\arg
-+.macro O3 arg
-+.global o3_\arg
- o3_\arg:
- 
-- .macro I3 arg
-- .global i3_\arg
-+	.macro I3 arg
-+.global i3_\arg
- i3_\arg:
-- .endm
-+       .endm
- 
-- i3 bar		/* Macro names are case insensitive.  */
-- .endm
-+	i3 bar		/* Macro names are case insensitive.  */
-+.endm
- 
-- o3 foo		/* Should produce two labels: o3_foo and i3_bar.  */
-+o3 foo	/* Should produce two labels: o3_foo and i3_bar.  */
- 
- /* Nested macros can access the arguments of their parents.
-    In addition their arguments can be substituted into the arguments
-    that are substited from their parents:  */
-- .macro OUTER arg1, arg2, arg3:vararg
-- .macro INNER arg4 arg2
-+.macro OUTER arg1, arg2, arg3:vararg
-+     .macro INNER arg4 arg2
-         .dc.a \arg2
-- .dc.a \arg3
-- .endm
-- INNER \arg1 bert
-- .dc.a \arg2
-- .endm
-+	.dc.a \arg3
-+     .endm
-+     INNER \arg1 bert
-+	.dc.a \arg2
-+.endm
- 
--/* This produces references to "jim", "bert" and "harryfred".  */
-- OUTER fred, jim, harry\arg4
-+OUTER fred, jim, harry\arg4 /* This produces references to "jim", "bert" and "harryfred".  */
--- 
-2.47.1
-

diff --git a/9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch b/9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch
deleted file mode 100644
index dd6ff9a..0000000
--- a/9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch
+++ /dev/null
@@ -1,39 +0,0 @@
-From 44100045e8d1df5df3578d60206df94498bcd236 Mon Sep 17 00:00:00 2001
-Message-ID: <44100045e8d1df5df3578d60206df94498bcd236.1735740264.git.sam@gentoo.org>
-In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Wed, 1 Jan 2025 14:03:46 +0000
-Subject: [PATCH 09/10] Revert "Fix error: macro may be used uninitialized"
-
-This reverts commit f404dc565a4ccfe6922b45cf5526c319aedf75d6.
----
- gas/macro.c | 5 +++--
- 1 file changed, 3 insertions(+), 2 deletions(-)
-
-diff --git a/gas/macro.c b/gas/macro.c
-index 5fa2011ab7a..c1b43e76a61 100644
---- a/gas/macro.c
-+++ b/gas/macro.c
-@@ -1411,6 +1411,7 @@ check_macro (const char *line, sb *expand,
- {
-   const char *s;
-   char *copy, *cls;
-+  macro_entry *macro;
-   sb line_sb;
- 
-   if (! macros_defined)
-@@ -1430,8 +1431,8 @@ check_macro (const char *line, sb *expand,
-   for (cls = copy; *cls != '\0'; cls ++)
-     *cls = TOLOWER (*cls);
- 
--  macro_entry *macro = NULL;
--  for (int i = macro_nesting_depth; i >= 0; i--)
-+  int i;
-+  for (i = macro_nesting_depth; i >= 0; i--)
-     {
-       macro = str_hash_find (macro_hash[i], copy);
-       if (macro != NULL)
--- 
-2.47.1
-

diff --git a/9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch b/9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
deleted file mode 100644
index 3a3b6c0..0000000
--- a/9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
+++ /dev/null
@@ -1,900 +0,0 @@
-From cfb2c161d55d2a4ab5ab3729b16ad364c8ec1c3f Mon Sep 17 00:00:00 2001
-Message-ID: <cfb2c161d55d2a4ab5ab3729b16ad364c8ec1c3f.1735740264.git.sam@gentoo.org>
-In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
-From: Sam James <sam@gentoo.org>
-Date: Wed, 1 Jan 2025 14:03:46 +0000
-Subject: [PATCH 10/10] Revert "Fix the handling or arguments and macro
- pseudo-variables inside nested assembler macros."
-
-This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.
----
- gas/config/tc-iq2000.c              |   6 +-
- gas/doc/as.texi                     |  60 +------
- gas/input-scrub.c                   |   7 +-
- gas/macro.c                         | 270 +++++-----------------------
- gas/macro.h                         |  17 +-
- gas/read.c                          |  15 +-
- gas/testsuite/gas/macros/macros.exp |   1 -
- gas/testsuite/gas/macros/nesting.d  |  28 ---
- gas/testsuite/gas/macros/nesting.s  | 104 -----------
- 9 files changed, 64 insertions(+), 444 deletions(-)
- delete mode 100644 gas/testsuite/gas/macros/nesting.d
- delete mode 100644 gas/testsuite/gas/macros/nesting.s
-
-diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c
-index 8dc3b768e3a..c65f264528f 100644
---- a/gas/config/tc-iq2000.c
-+++ b/gas/config/tc-iq2000.c
-@@ -105,6 +105,8 @@ struct iq2000_hi_fixup
- /* The list of unmatched HI relocs.  */
- static struct iq2000_hi_fixup * iq2000_hi_fixup_list;
- 
-+/* Macro hash table, which we will add to.  */
-+extern struct htab *macro_hash;
- \f
- const char md_shortopts[] = "";
- const struct option md_longopts[] =
-@@ -277,7 +279,9 @@ iq2000_add_macro (const char *  name,
- 	}
-     }
- 
--  (void) add_macro (macro, true);
-+  str_hash_insert (macro_hash, macro->name, macro, 1);
-+
-+  macro_defined = 1;
- }
- 
- static void
-diff --git a/gas/doc/as.texi b/gas/doc/as.texi
-index 69d6d3c88b0..c9f65a47125 100644
---- a/gas/doc/as.texi
-+++ b/gas/doc/as.texi
-@@ -6215,12 +6215,7 @@ With that definition, @samp{SUM 0,5} is equivalent to this assembly input:
- @item .macro @var{macname}
- @itemx .macro @var{macname} @var{macargs} @dots{}
- @cindex @code{macro} directive
--Begin the definition of a macro called @var{macname}.  Macro names are case
--insensitive.  Macro definitions can be nested, although their behaviour is
--sometimes counter intuitive.  Nested macros only have scope within their
--defining macro.
--
--If your macro
-+Begin the definition of a macro called @var{macname}.  If your macro
- definition requires arguments, specify their names after the macro name,
- separated by commas or spaces.  You can qualify the macro argument to
- indicate whether all invocations must specify a non-blank value (through
-@@ -6385,29 +6380,6 @@ adjacent string literals - even if separated only by a blank - will not be
- concatenated when determining macro arguments, even if they're only separated
- by white space.  This is unlike certain other pseudo ops, e.g. @code{.ascii}.
- 
--Nested macros can access the arguments of their parents.  But also if their
--argument names clash with those of their parents, their versions are used.  So
--for example:
--
--@smallexample
--.macro OUTER arg1, arg2, arg3:vararg
--     .macro INNER arg4 arg2
--        .dc.a \arg2
--	.dc.a \arg3
--     .endm
--     INNER \arg1 bert
--	.dc.a \arg2
--.endm
--
--OUTER fred, jim, harry\arg4
--@end smallexample
--
--This will generate references to symbols called @samp{jim} - from the
--definition of the OUTER macro, @samp{bert} - from the definition in INNER
--where arg2 has been overridden and @samp{harryfred} - from the definition in
--INNER where the value of arg3 from OUTER is used, but with the value of arg4
--substituted into the symbol.
--
- @item .endm
- @cindex @code{endm} directive
- Mark the end of a macro definition.
-@@ -6423,33 +6395,6 @@ Exit early from the current macro definition.
- executed in this pseudo-variable; you can copy that number to your
- output with @samp{\@@}, but @emph{only within a macro definition}.
- 
--Note - the @samp{\@@} counter is incremented at the end of the expansion of a
--macro, but before the contents of any nested macros are evaluated.  This can
--lead to counter-intuitive behaviour when nested macros are used.  For example:
--
--@smallexample
--  .macro o
--    .macro i
--    _i\@@_:
--    .endm
--    i
--    _o\@@_:
--  .endm
--  o
--@end smallexample
--
--Produces two symbols @samp{_o0_} and @samp{_i1_}.  This happens because the
--@samp{o} macro executes entirely first, putting the definition and invocation
--of the @samp{i} macro into the input buffer.  It also puts the definition of
--the @samp{_o\@@_} symbol into the input buffer, evaluating the @samp{\@@}
--counter in the process and so generating a symbol called @samp{_o0_}.
--
--That finishes the invocation of @samp{o} so the @samp{\@@} counter is
--incremented.  Then the input buffer is re-evaluated and the definition and
--invocation of macro @samp{i} is found.  This results in @samp{_i\@@_} being put
--into the input buffer and this time @samp{\@@} evaluates to 1, so the symbol
--created is @samp{_i1_}.
--
- @cindex number of times a macro has been executed
- @cindex macro, execution count
- @item \+
-@@ -6736,9 +6681,6 @@ those explicitly specified with @code{.eject}.
- Undefine the macro @var{name}, so that later uses of the string will not be
- expanded.  @xref{Macro}.
- 
--Note - nested macros are automatically purged at the end of the macro that
--defines them.
--
- @ifset ELF
- @node PushSection
- @section @code{.pushsection @var{name} [, @var{subsection}] [, "@var{flags}"[, @@@var{type}[,@var{arguments}]]]}
-diff --git a/gas/input-scrub.c b/gas/input-scrub.c
-index 3433bc6472d..2e0ce832b2b 100644
---- a/gas/input-scrub.c
-+++ b/gas/input-scrub.c
-@@ -23,7 +23,6 @@
- #include "input-file.h"
- #include "sb.h"
- #include "listing.h"
--#include "macro.h"
- 
- /*
-  * O/S independent module to supply buffers of sanitised source code
-@@ -291,13 +290,12 @@ input_scrub_include_sb (sb *from, char *position, enum expansion expansion)
-       ++macro_nest;
-     }
- 
-+#ifdef md_macro_start
-   if (expansion == expanding_macro)
-     {
--#ifdef md_macro_start
-       md_macro_start ();
--#endif
--      increment_macro_nesting_depth ();
-     }
-+#endif
- 
-   next_saved_file = input_scrub_push (position);
- 
-@@ -352,7 +350,6 @@ input_scrub_next_buffer (char **bufp)
- 	         data.  */
- 	      md_macro_end ();
- #endif
--	      decrement_macro_nesting_depth ();
- 	    }
- 	  if (from_sb_expansion != expanding_app)
- 	    --macro_nest;
-diff --git a/gas/macro.c b/gas/macro.c
-index c1b43e76a61..5ae76c6e661 100644
---- a/gas/macro.c
-+++ b/gas/macro.c
-@@ -44,24 +44,11 @@
- 
- /* The macro hash table.  */
- 
--/* Macro nesting depth.  Similar to macro_nest defined in sb.c, but this
--   counter is specific to macros, whereas macro_nest also counts repeated
--   string blocks.  */
--static unsigned int macro_nesting_depth;
-+htab_t macro_hash;
- 
--/* Maximum nesting depth.  Ideally the same as the value of max_macro_nest
--   as defined in as.c (ie 100).  But there is one test in the assembler
--   testsuite (bfin/allinsn16.s) that nests macros to a depth of 8192.  So
--   we have a ridiculously large number here.  */
--#define MAX_MACRO_DEPTH 8193
-+/* Whether any macros have been defined.  */
- 
--static htab_t macro_hash[MAX_MACRO_DEPTH];
--
--/* Whether any macros have been defined.
--   FIXME:  This could be a counter that is incremented
--   with .macro and decremented with .purgem.  */
--
--static bool macros_defined = false;
-+int macro_defined;
- 
- /* Whether we should strip '@' characters.  */
- 
-@@ -73,18 +60,6 @@ static unsigned int macro_number;
- 
- static void free_macro (macro_entry *);
- 
--bool
--add_macro (macro_entry * macro, bool replace)
--{
--  if (str_hash_insert (macro_hash [macro_nesting_depth],
--		       macro->name, macro, replace) == NULL)
--    {
--      macros_defined = true;
--      return true;
--    }
--  return false;
--}
--
- static void
- macro_del_f (void *ent)
- {
-@@ -97,23 +72,15 @@ macro_del_f (void *ent)
- void
- macro_init (void)
- {
--  int i;
--
--  for (i = 0; i < MAX_MACRO_DEPTH; i++)
--    macro_hash[i] = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
--				       macro_del_f, notes_calloc, NULL);
--  macros_defined = false;
-+  macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
-+				  macro_del_f, notes_calloc, NULL);
-+  macro_defined = 0;
- }
- 
- void
- macro_end (void)
- {
--  int i;
--
--  for (i = MAX_MACRO_DEPTH; i--;)
--    htab_delete (macro_hash[i]);
--
--  macros_defined = false;
-+  htab_delete (macro_hash);
- }
- 
- /* Read input lines till we get to a TO string.
-@@ -688,13 +655,6 @@ free_macro (macro_entry *macro)
-   free (macro);
- }
- 
--static macro_entry * last_recorded_macro = NULL;
--void
--macro_record_invocation (macro_entry * macro)
--{
--  last_recorded_macro = macro;
--}
--
- /* Define a new macro.  */
- 
- macro_entry *
-@@ -758,19 +718,15 @@ define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
-   /* And stick it in the macro hash table.  */
-   for (idx = 0; idx < name.len; idx++)
-     name.ptr[idx] = TOLOWER (name.ptr[idx]);
--
--  if (macro_nesting_depth > 0)
--    macro->parent = last_recorded_macro;
--  else
--    macro->parent = NULL;
--
-   if (!error)
-     {
--      if (! add_macro (macro, false))
-+      if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL)
- 	error = _("Macro `%s' was already defined");
-     }
- 
--  if (error != NULL)
-+  if (!error)
-+    macro_defined = 1;
-+  else
-     {
-       as_bad_where (macro->file, macro->line, error, macro->name);
-       free_macro (macro);
-@@ -794,25 +750,11 @@ get_apost_token (size_t idx, sb *in, sb *name, int kind)
-   return idx;
- }
- 
--static const char *
--macro_expand_body (sb *, sb *, formal_entry *, struct htab *,
--		   const macro_entry *, unsigned int);
--
--/* Find the actual value for a formal parameter starting at START inside IN.
--    Appends the value of parameter onto OUT.
--   The hash table of formal parameters is provided by FORMAL_HASH.
--   The character that indicated the presense of a formal parameter is passed
--    in KIND.
--   If COPYIFNOTTHERE is true and the parameter is not found in the hash table
--    then it is appended as plain text onto OUT.
--   The macro containing the formal parameters is passed in MACRO.
--    This can be empty.
--   Returns the offset inside IN after advanceing past the parameter.
--   Also stores the parameter's name into T.  */
-+/* Substitute the actual value for a formal parameter.  */
- 
- static size_t
- sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
--	    int kind, sb *out, int copyifnotthere, const macro_entry * macro)
-+	    int kind, sb *out, int copyifnotthere)
- {
-   size_t src;
-   formal_entry *ptr;
-@@ -826,12 +768,16 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
-     ptr = NULL;
-   else
-     ptr = str_hash_find (formal_hash, sb_terminate (t));
--  
-   if (ptr)
-     {
--      sb * add = ptr->actual.len ? &ptr->actual : &ptr->def;
--
--      sb_add_sb (out, add);
-+      if (ptr->actual.len)
-+	{
-+	  sb_add_sb (out, &ptr->actual);
-+	}
-+      else
-+	{
-+	  sb_add_sb (out, &ptr->def);
-+	}
-     }
-   else if (kind == '&')
-     {
-@@ -845,55 +791,6 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
-     {
-       sb_add_sb (out, t);
-     }
--  else if (!macro_strip_at
--	   && macro_nesting_depth > 0
--	   && macro != NULL
--	   && macro->parent != NULL)
--    {
--      const macro_entry * orig_macro = macro;
--      bool success = false;
--
--      /* We have failed to find T, but we are inside nested macros.  So check
--	 the parent macros so see if they have a FORMAL that matches T.  */
--      while (macro->parent != NULL)
--	{
--	  macro = macro->parent;
--
--	  ptr = str_hash_find (macro->formal_hash, t->ptr);
--	  if (ptr == NULL)
--	    continue;
--
--	  sb * add = ptr->actual.len ? &ptr->actual : &ptr->def;
--
--	  /* The parent's FORMALs might contain parameters that need further
--	     substitution.  See gas/testsuite/gas/arm/macro-vld1.s for an
--	     example of this.  */
--	  if (strchr (add->ptr, '\\'))
--	    {
--	      sb newadd;
--
--	      sb_new (&newadd);
--	      /* FIXME: Should we do something if the call to
--		 macro_expand_body returns an error message ?  */
--	      (void) macro_expand_body (add, &newadd, NULL, NULL,
--					orig_macro, orig_macro->count);
--	      sb_add_sb (out, &newadd);
--	    }
--	  else
--	    {
--	      sb_add_sb (out, add);
--	    }
--	  success = true;
--	  break;
--	}
--      if (! success)
--	{
--	  /* We reached the outermost macro and failed to find T, so
--	     just copy the entire parameter as is.  */
--	  sb_add_char (out, '\\');
--	  sb_add_sb (out, t);
--	}
--    }
-   else
-     {
-       sb_add_char (out, '\\');
-@@ -902,12 +799,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
-   return src;
- }
- 
--/* Expands the body of a macro / block of text IN, copying it into OUT.
--   Parameters for substitution are found in FORMALS and FORMAL_HASH or
--   MACRO.
--   The number of times that this macro / block of text have already been
--   copied into the output is held in INSTANCE.
--   Returns NULL upon success or an error message otherwise.  */
-+/* Expand the body of a macro.  */
- 
- static const char *
- macro_expand_body (sb *in, sb *out, formal_entry *formals,
-@@ -919,38 +811,18 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
-   int inquote = 0, macro_line = 0;
-   formal_entry *loclist = NULL;
-   const char *err = NULL;
--  int nesting = 0;
- 
--  if (formals == NULL && macro != NULL)
--    formals = macro->formals;
--
--  if (formal_hash == NULL && macro != NULL)
--    formal_hash = macro->formal_hash;
--  
-   sb_new (&t);
- 
-   while (src < in->len && !err)
-     {
--      if (in->ptr[src] == '.')
--	{
--	  /* Check to see if we have encountered ".macro" or ".endm" */
--	  if (in->len > src + 5
--	      && strncmp (in->ptr + src, ".macro", 6) == 0)
--	    ++ nesting;
--
--	  else if (in->len > src + 4
--		   && strncmp (in->ptr + src, ".endm", 5) == 0)
--	    -- nesting;
--	}
--
-       if (in->ptr[src] == '&')
- 	{
- 	  sb_reset (&t);
- 	  if (flag_mri)
- 	    {
- 	      if (src + 1 < in->len && in->ptr[src + 1] == '&')
--		src = sub_actual (src + 2, in, &t, formal_hash,
--				  '\'', out, 1, macro);
-+		src = sub_actual (src + 2, in, &t, formal_hash, '\'', out, 1);
- 	      else
- 		sb_add_char (out, in->ptr[src++]);
- 	    }
-@@ -958,8 +830,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 	    {
- 	      /* Permit macro parameter substitution delineated with
- 		 an '&' prefix and optional '&' suffix.  */
--	      src = sub_actual (src + 1, in, &t, formal_hash,
--				'&', out, 0, macro);
-+	      src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
- 	    }
- 	}
-       else if (in->ptr[src] == '\\')
-@@ -980,12 +851,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 	      else
- 		as_bad_where (macro->file, macro->line + macro_line, _("missing `)'"));
- 	    }
--	  else if (src < in->len
--		   && in->ptr[src] == '@'
--		   /* PR 32391: Do not perform the substition inside nested
--		      macros.  Instead wait until they are re-evaluated and
--		      perform the substition then.  */
--		   && ! nesting)
-+	  else if (src < in->len && in->ptr[src] == '@')
- 	    {
- 	      /* Sub in the total macro invocation number.  */
- 
-@@ -994,12 +860,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 	      sprintf (buffer, "%u", macro_number);
- 	      sb_add_string (out, buffer);
- 	    }
--	  else if (src < in->len
--		   && in->ptr[src] == '+'
--		   /* PR 32391: Do not perform the substition inside nested
--		      macros.  Instead wait until they are re-evaluated and
--		      perform the substition then.  */
--		   && ! nesting)
-+	  else if (src < in->len && in->ptr[src] == '+')
- 	    {
- 	      /* Sub in the current macro invocation number.  */
- 
-@@ -1043,18 +904,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 	  else
- 	    {
- 	      sb_reset (&t);
--
--	      if (nesting)
--		{
--		  src = get_apost_token (src, in, &t, '\'');
--		  sb_add_char (out, '\\');
--		  sb_add_sb (out, &t);
--		}
--	      else
--		{
--		  src = sub_actual (src, in, &t, formal_hash,
--				    '\'', out, 0, macro);
--		}
-+	      src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
- 	    }
- 	}
-       else if ((flag_macro_alternate || flag_mri)
-@@ -1073,7 +923,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 	      sb_reset (&t);
- 	      src = sub_actual (src, in, &t, formal_hash,
- 				(macro_strip_at && inquote) ? '@' : '\'',
--				out, 1, macro);
-+				out, 1);
- 	    }
- 	  else
- 	    {
-@@ -1185,7 +1035,6 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
- 
-   if (!err && (out->len == 0 || out->ptr[out->len - 1] != '\n'))
-     sb_add_char (out, '\n');
--
-   return err;
- }
- 
-@@ -1370,7 +1219,8 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
- 	    }
- 	}
- 
--      err = macro_expand_body (&m->sub, out, NULL, NULL, m, m->count);
-+      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
-+			       m->count);
-     }
- 
-   /* Discard any unnamed formal arguments.  */
-@@ -1403,9 +1253,9 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
- }
- 
- /* Check for a macro.  If one is found, put the expansion into
--   *EXPAND.  Return TRUE if a macro is found, FALSE otherwise.  */
-+   *EXPAND.  Return 1 if a macro is found, 0 otherwise.  */
- 
--bool
-+int
- check_macro (const char *line, sb *expand,
- 	     const char **error, macro_entry **info)
- {
-@@ -1414,12 +1264,9 @@ check_macro (const char *line, sb *expand,
-   macro_entry *macro;
-   sb line_sb;
- 
--  if (! macros_defined)
--    return false;
--
-   if (! is_name_beginner (*line)
-       && (! flag_mri || *line != '.'))
--    return false;
-+    return 0;
- 
-   s = line + 1;
-   while (is_part_of_name (*s))
-@@ -1431,17 +1278,11 @@ check_macro (const char *line, sb *expand,
-   for (cls = copy; *cls != '\0'; cls ++)
-     *cls = TOLOWER (*cls);
- 
--  int i;
--  for (i = macro_nesting_depth; i >= 0; i--)
--    {
--      macro = str_hash_find (macro_hash[i], copy);
--      if (macro != NULL)
--	break;
--    }
-+  macro = str_hash_find (macro_hash, copy);
-   free (copy);
- 
-   if (macro == NULL)
--    return false;
-+    return 0;
- 
-   /* Wrap the line up in an sb.  */
-   sb_new (&line_sb);
-@@ -1457,7 +1298,7 @@ check_macro (const char *line, sb *expand,
-   if (info)
-     *info = macro;
- 
--  return true;
-+  return 1;
- }
- 
- /* Delete a macro.  */
-@@ -1475,20 +1316,11 @@ delete_macro (const char *name)
-     copy[i] = TOLOWER (name[i]);
-   copy[i] = '\0';
- 
--  int j;
--  for (j = macro_nesting_depth; j >= 0; j--)
--    {
--      macro = str_hash_find (macro_hash [j], copy);
--      if (macro != NULL)
--	{
--	  str_hash_delete (macro_hash[j], copy);
--	  break;
--	}
--    }
--
--  if (macro == NULL)
-+  macro = str_hash_find (macro_hash, copy);
-+  if (macro != NULL)
-+    str_hash_delete (macro_hash, copy);
-+  else
-     as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
--
-   free (copy);
- }
- 
-@@ -1590,25 +1422,3 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
- 
-   return err;
- }
--
--void
--increment_macro_nesting_depth (void)
--{
-- if (macro_nesting_depth >= (MAX_MACRO_DEPTH - 1))
--    as_fatal (_("macros nested too deeply"));
--  else
--    ++macro_nesting_depth;
--}
--
--void
--decrement_macro_nesting_depth (void)
--{
--  if (macro_nesting_depth == 0)
--    as_fatal (_("too much macro un-nesting"));
--  else
--    {
--      /* FIXME: Potential memory leak here.  */
--      htab_empty (macro_hash [macro_nesting_depth]);
--      --macro_nesting_depth;
--    }
--}
-diff --git a/gas/macro.h b/gas/macro.h
-index 55b28b2f82a..3ebcfe8c8fd 100644
---- a/gas/macro.h
-+++ b/gas/macro.h
-@@ -64,28 +64,31 @@ typedef struct macro_struct
-   int             formal_count;		/* Number of formal args.  */
-   formal_entry *  formals;		/* List of formal_structs.  */
-   htab_t          formal_hash;		/* Hash table of formals.  */
--  struct macro_struct * parent;         /* Parent of nested macros.  */
-   const char *    name;			/* Macro name.  */
-   const char *    file;			/* File the macro was defined in.  */
-   unsigned int    line;			/* Line number of definition.  */
-   unsigned int    count;                /* Invocation count.  */
- } macro_entry;
- 
--/* The macro/text block nesting level.  */
-+/* Whether any macros have been defined.  */
-+
-+extern int macro_defined;
-+
-+/* The macro nesting level.  */
- 
- extern int macro_nest;
- 
-+/* The macro hash table.  */
-+
-+extern htab_t macro_hash;
-+
- extern int buffer_and_nest (const char *, const char *, sb *,
- 			    size_t (*) (sb *));
- extern void macro_init (void);
- extern void macro_end (void);
- extern macro_entry *define_macro (sb *, sb *, size_t (*) (sb *));
--extern bool check_macro (const char *, sb *, const char **, macro_entry **);
-+extern int check_macro (const char *, sb *, const char **, macro_entry **);
- extern void delete_macro (const char *);
- extern const char *expand_irp (int, size_t, sb *, sb *, size_t (*) (sb *));
--extern void increment_macro_nesting_depth (void);
--extern void decrement_macro_nesting_depth (void);
--extern void macro_record_invocation (macro_entry *);
--extern bool add_macro (macro_entry *, bool);
- 
- #endif
-diff --git a/gas/read.c b/gas/read.c
-index 5be2686822d..6d0d4b5e31a 100644
---- a/gas/read.c
-+++ b/gas/read.c
-@@ -656,8 +656,7 @@ poend (void)
-     }
- 
- /* Helper function of read_a_source_file, which tries to expand a macro.  */
--
--static bool
-+static int
- try_macro (char term, const char *line)
- {
-   sb out;
-@@ -674,14 +673,12 @@ try_macro (char term, const char *line)
-       sb_kill (&out);
-       buffer_limit =
- 	input_scrub_next_buffer (&input_line_pointer);
--
--      macro_record_invocation (macro);
- #ifdef md_macro_info
-       md_macro_info (macro);
- #endif
--      return true;
-+      return 1;
-     }
--  return false;
-+  return 0;
- }
- 
- #ifdef HANDLE_BUNDLE
-@@ -1273,7 +1270,7 @@ read_a_source_file (const char *name)
- 			  s_ignore (0);
- 			  nul_char = next_char = *--input_line_pointer;
- 			  *input_line_pointer = '\0';
--			  if (! try_macro (next_char, s))
-+			  if (! macro_defined || ! try_macro (next_char, s))
- 			    {
- 			      *end = '\0';
- 			      as_bad (_("unknown pseudo-op: `%s'"), s);
-@@ -1310,7 +1307,7 @@ read_a_source_file (const char *name)
- 
- 		      generate_lineno_debug ();
- 
--		      if (try_macro (next_char, s))
-+		      if (macro_defined && try_macro (next_char, s))
- 			continue;
- 
- 		      if (mri_pending_align)
-@@ -2820,7 +2817,7 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
- 	  as_warn_where (macro->file, macro->line,
- 			 _("attempt to redefine pseudo-op `%s' ignored"),
- 			 macro->name);
--	  delete_macro (macro->name);
-+	  str_hash_delete (macro_hash, macro->name);
- 	}
-     }
- 
-diff --git a/gas/testsuite/gas/macros/macros.exp b/gas/testsuite/gas/macros/macros.exp
-index de3df4d803d..278cf405225 100644
---- a/gas/testsuite/gas/macros/macros.exp
-+++ b/gas/testsuite/gas/macros/macros.exp
-@@ -112,4 +112,3 @@ run_list_test count
- run_list_test irp-count
- run_list_test irpc-quote
- run_list_test rept-count
--run_dump_test nesting
-diff --git a/gas/testsuite/gas/macros/nesting.d b/gas/testsuite/gas/macros/nesting.d
-deleted file mode 100644
-index 2f44aedb2dc..00000000000
---- a/gas/testsuite/gas/macros/nesting.d
-+++ /dev/null
-@@ -1,28 +0,0 @@
--#nm: -j 
--#name: Nested macros (PR 32391)
--# Sone targets do not support macros used like this.
--#skip: tic*-*-* mmix-*
--
--#...
--_m7_
--_m8_
--after_at_0
--after_at_3
--after_plus_0
--after_plus_1
--before_at_0
--before_at_3
--before_plus_0
--before_plus_1
--bert
--harryfred
--i3_bar
--inside_at_1
--inside_at_2
--inside_at_4
--inside_at_5
--inside_plus_0
--inside_plus_1
--jim
--o3_foo
--other_inner_6
-diff --git a/gas/testsuite/gas/macros/nesting.s b/gas/testsuite/gas/macros/nesting.s
-deleted file mode 100644
-index 438d5af8d00..00000000000
---- a/gas/testsuite/gas/macros/nesting.s
-+++ /dev/null
-@@ -1,104 +0,0 @@
--
--	.text
--/* PR 32391: Automatic counters inside macros should increment when nested
--	macros finish execution.  */
--.macro o1
--.global before_at_\@
--before_at_\@:
--.global before_plus_\+
--before_plus_\+:
--
--	.macro i1
--.global inside_at_\@
--inside_at_\@:
--.global inside_plus_\+
--inside_plus_\+:
--	.endm
--
--	i1
--	i1
--
--.global after_at_\@
--after_at_\@:
--.global after_plus_\+
--after_plus_\+:
--
--.endm
--
--/* Invoking o1 should produce these symbols in this order:
--
--	before_at_0
--	before_plus_0
--	inside_at_1
--	inside_plus_0
--	inside_at_2
--	inside_plus_1
--	after_at_0
--	after_plus_0  */
--o1
--	
--/* A second invocation of o1 should not produce any errors about
--	symbols or macros being redefined.  */
--o1
--	
--/* This definition should not collide with the definition inside o1.  */
--.macro i1
--.global other_inner_\@
--other_inner_\@:
--.endm 
--
--/* And invoking it should invoke the second defintion of i1, not the first.  */	
--i1
--		
--.macro o2
--.global _m\@_
--_m\@_:
--.macro i2
--.global _m\@_
--_m\@_:
--.endm
--i2
--.endm
--
--/* This should not generate conflicting symbols because the assembler
--   inserts the contents of o2 into the input buffer as pure text (ie
--   without evaluating i2).  The first use of \@ is evaluated at this
--   time, creating _m4_.  But the second use is not evaluated because
--   it is inside a .macro definition.
--	
--   This finishes the evaluation of o2, so the \@ counter is incremented.
--	
--   Next the input buffer is re-evaluated and the i2 macro definition
--   and invocation are encounterd.  The text from i2 are inserted into
--   the input buffer and at this point the second use of \@ is evaluated
--   resulting in the creation of a symbol called _m5_.  */
--o2
--
--/* Macro arguments should be independent of nesting.  */
--.macro O3 arg
--.global o3_\arg
--o3_\arg:
--
--	.macro I3 arg
--.global i3_\arg
--i3_\arg:
--       .endm
--
--	i3 bar		/* Macro names are case insensitive.  */
--.endm
--
--o3 foo	/* Should produce two labels: o3_foo and i3_bar.  */
--
--/* Nested macros can access the arguments of their parents.
--   In addition their arguments can be substituted into the arguments
--   that are substited from their parents:  */
--.macro OUTER arg1, arg2, arg3:vararg
--     .macro INNER arg4 arg2
--        .dc.a \arg2
--	.dc.a \arg3
--     .endm
--     INNER \arg1 bert
--	.dc.a \arg2
--.endm
--
--OUTER fred, jim, harry\arg4 /* This produces references to "jim", "bert" and "harryfred".  */
--- 
-2.47.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2025-01-01 14:05 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2025-01-01 14:05 UTC (permalink / raw
  To: gentoo-commits

commit:     6832c5a8fb253c080d9fb43ba83210c67bcbe2a2
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Jan  1 14:04:51 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jan  1 14:04:51 2025 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=6832c5a8

9999: add more more macro reverts

Bug: https://sourceware.org/PR32484
Bug: https://sourceware.org/PR32486
Bug: https://sourceware.org/PR32487
Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-Revert-PR-32391-memory-leak.patch        | 28 +++++++++++++++++
 ...-Revert-macro.c-871-heap-buffer-overflow.patch} | 14 ++++-----
 ...e.patch => 0008-Revert-PR-32391-testcase.patch} | 12 ++++----
 ...ix-error-macro-may-be-used-uninitialized.patch} | 14 ++++-----
 ...he-handling-or-arguments-and-macro-pseud.patch} | 36 +++++++++++-----------
 5 files changed, 66 insertions(+), 38 deletions(-)

diff --git a/9999/0006-Revert-PR-32391-memory-leak.patch b/9999/0006-Revert-PR-32391-memory-leak.patch
new file mode 100644
index 0000000..a20c54d
--- /dev/null
+++ b/9999/0006-Revert-PR-32391-memory-leak.patch
@@ -0,0 +1,28 @@
+From 4bed21d47f9d838dc6b55ce026989ede4eacc789 Mon Sep 17 00:00:00 2001
+Message-ID: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Wed, 1 Jan 2025 14:03:43 +0000
+Subject: [PATCH 06/10] Revert "PR 32391 memory leak"
+
+This reverts commit 599739cc1c5d70ac958583130b4b5413aa101d8e.
+---
+ gas/macro.c | 1 -
+ 1 file changed, 1 deletion(-)
+
+diff --git a/gas/macro.c b/gas/macro.c
+index 9eefc8360b1..9670b38c152 100644
+--- a/gas/macro.c
++++ b/gas/macro.c
+@@ -878,7 +878,6 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+ 	      (void) macro_expand_body (add, &newadd, NULL, NULL,
+ 					orig_macro, orig_macro->count);
+ 	      sb_add_sb (out, &newadd);
+-	      sb_kill (&newadd);
+ 	    }
+ 	  else
+ 	    {
+
+base-commit: 94e2b2a770fc49e42c9baec80f4fb88f63391a4e
+-- 
+2.47.1
+

diff --git a/9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch b/9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch
similarity index 65%
rename from 9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch
rename to 9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch
index 4d0ac10..b461443 100644
--- a/9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch
+++ b/9999/0007-Revert-macro.c-871-heap-buffer-overflow.patch
@@ -1,8 +1,10 @@
-From a6aac087c94bab6335335e24aa9ab58ce0682859 Mon Sep 17 00:00:00 2001
-Message-ID: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+From 7daa5da3eab39e733f40eccbf4f6cd2078e3335e Mon Sep 17 00:00:00 2001
+Message-ID: <7daa5da3eab39e733f40eccbf4f6cd2078e3335e.1735740264.git.sam@gentoo.org>
+In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
+References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
-Date: Thu, 26 Dec 2024 01:15:13 +0000
-Subject: [PATCH 1/4] Revert "macro.c:871 heap-buffer-overflow"
+Date: Wed, 1 Jan 2025 14:03:44 +0000
+Subject: [PATCH 07/10] Revert "macro.c:871 heap-buffer-overflow"
 
 This reverts commit 6d9b7667974372357fed1f02c54a805f8c21dcde.
 ---
@@ -10,7 +12,7 @@ This reverts commit 6d9b7667974372357fed1f02c54a805f8c21dcde.
  1 file changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/gas/macro.c b/gas/macro.c
-index ded0645be8d..3d5a9f14341 100644
+index 9670b38c152..5fa2011ab7a 100644
 --- a/gas/macro.c
 +++ b/gas/macro.c
 @@ -868,7 +868,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
@@ -31,8 +33,6 @@ index ded0645be8d..3d5a9f14341 100644
      as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
  
    free (copy);
-
-base-commit: fa93e88f754e10dfb60dd4c9bf9cef858d4c7e4a
 -- 
 2.47.1
 

diff --git a/9999/0007-Revert-PR-32391-testcase.patch b/9999/0008-Revert-PR-32391-testcase.patch
similarity index 91%
rename from 9999/0007-Revert-PR-32391-testcase.patch
rename to 9999/0008-Revert-PR-32391-testcase.patch
index 5cfdeec..4376e58 100644
--- a/9999/0007-Revert-PR-32391-testcase.patch
+++ b/9999/0008-Revert-PR-32391-testcase.patch
@@ -1,10 +1,10 @@
-From bf07b8ac6f4c0ffe4977951d099c09c50fbe0c29 Mon Sep 17 00:00:00 2001
-Message-ID: <bf07b8ac6f4c0ffe4977951d099c09c50fbe0c29.1735175975.git.sam@gentoo.org>
-In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
-References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+From da631c6ce21783acebd2dc44b834fd17c84a0381 Mon Sep 17 00:00:00 2001
+Message-ID: <da631c6ce21783acebd2dc44b834fd17c84a0381.1735740264.git.sam@gentoo.org>
+In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
+References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
-Date: Tue, 24 Dec 2024 06:25:51 +0000
-Subject: [PATCH 2/4] Revert "PR 32391 testcase"
+Date: Wed, 1 Jan 2025 14:03:45 +0000
+Subject: [PATCH 08/10] Revert "PR 32391 testcase"
 
 This reverts commit c8fcfa9aad211dfd8296ae6e978a356797936c61.
 ---

diff --git a/9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch b/9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch
similarity index 66%
rename from 9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch
rename to 9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch
index 52cbc39..dd6ff9a 100644
--- a/9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch
+++ b/9999/0009-Revert-Fix-error-macro-may-be-used-uninitialized.patch
@@ -1,10 +1,10 @@
-From cc2fcd3f83d79ca491c61654b94e267386cdab3a Mon Sep 17 00:00:00 2001
-Message-ID: <cc2fcd3f83d79ca491c61654b94e267386cdab3a.1735175975.git.sam@gentoo.org>
-In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
-References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+From 44100045e8d1df5df3578d60206df94498bcd236 Mon Sep 17 00:00:00 2001
+Message-ID: <44100045e8d1df5df3578d60206df94498bcd236.1735740264.git.sam@gentoo.org>
+In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
+References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
-Date: Tue, 24 Dec 2024 06:25:57 +0000
-Subject: [PATCH 3/4] Revert "Fix error: macro may be used uninitialized"
+Date: Wed, 1 Jan 2025 14:03:46 +0000
+Subject: [PATCH 09/10] Revert "Fix error: macro may be used uninitialized"
 
 This reverts commit f404dc565a4ccfe6922b45cf5526c319aedf75d6.
 ---
@@ -12,7 +12,7 @@ This reverts commit f404dc565a4ccfe6922b45cf5526c319aedf75d6.
  1 file changed, 3 insertions(+), 2 deletions(-)
 
 diff --git a/gas/macro.c b/gas/macro.c
-index 3d5a9f14341..a0f2a5c764c 100644
+index 5fa2011ab7a..c1b43e76a61 100644
 --- a/gas/macro.c
 +++ b/gas/macro.c
 @@ -1411,6 +1411,7 @@ check_macro (const char *line, sb *expand,

diff --git a/9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch b/9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
similarity index 96%
rename from 9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
rename to 9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
index e24e8d2..3a3b6c0 100644
--- a/9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
+++ b/9999/0010-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
@@ -1,10 +1,10 @@
-From 499b2dbc38cbd668b62704165ee572c6ab784a4e Mon Sep 17 00:00:00 2001
-Message-ID: <499b2dbc38cbd668b62704165ee572c6ab784a4e.1735175975.git.sam@gentoo.org>
-In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
-References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+From cfb2c161d55d2a4ab5ab3729b16ad364c8ec1c3f Mon Sep 17 00:00:00 2001
+Message-ID: <cfb2c161d55d2a4ab5ab3729b16ad364c8ec1c3f.1735740264.git.sam@gentoo.org>
+In-Reply-To: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
+References: <4bed21d47f9d838dc6b55ce026989ede4eacc789.1735740264.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
-Date: Tue, 24 Dec 2024 06:26:16 +0000
-Subject: [PATCH 4/4] Revert "Fix the handling or arguments and macro
+Date: Wed, 1 Jan 2025 14:03:46 +0000
+Subject: [PATCH 10/10] Revert "Fix the handling or arguments and macro
  pseudo-variables inside nested assembler macros."
 
 This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.
@@ -23,7 +23,7 @@ This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.
  delete mode 100644 gas/testsuite/gas/macros/nesting.s
 
 diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c
-index 1cbc578281f..2198ffda2b9 100644
+index 8dc3b768e3a..c65f264528f 100644
 --- a/gas/config/tc-iq2000.c
 +++ b/gas/config/tc-iq2000.c
 @@ -105,6 +105,8 @@ struct iq2000_hi_fixup
@@ -47,7 +47,7 @@ index 1cbc578281f..2198ffda2b9 100644
  
  static void
 diff --git a/gas/doc/as.texi b/gas/doc/as.texi
-index 1683594a0bb..6be54b57599 100644
+index 69d6d3c88b0..c9f65a47125 100644
 --- a/gas/doc/as.texi
 +++ b/gas/doc/as.texi
 @@ -6215,12 +6215,7 @@ With that definition, @samp{SUM 0,5} is equivalent to this assembly input:
@@ -139,7 +139,7 @@ index 1683594a0bb..6be54b57599 100644
  @node PushSection
  @section @code{.pushsection @var{name} [, @var{subsection}] [, "@var{flags}"[, @@@var{type}[,@var{arguments}]]]}
 diff --git a/gas/input-scrub.c b/gas/input-scrub.c
-index 25fac879a56..878edc8fd36 100644
+index 3433bc6472d..2e0ce832b2b 100644
 --- a/gas/input-scrub.c
 +++ b/gas/input-scrub.c
 @@ -23,7 +23,6 @@
@@ -175,7 +175,7 @@ index 25fac879a56..878edc8fd36 100644
  	  if (from_sb_expansion != expanding_app)
  	    --macro_nest;
 diff --git a/gas/macro.c b/gas/macro.c
-index a0f2a5c764c..8b376f7f490 100644
+index c1b43e76a61..5ae76c6e661 100644
 --- a/gas/macro.c
 +++ b/gas/macro.c
 @@ -44,24 +44,11 @@
@@ -642,7 +642,7 @@ index a0f2a5c764c..8b376f7f490 100644
 -    }
 -}
 diff --git a/gas/macro.h b/gas/macro.h
-index 97f2a5a4066..e87f64e70ca 100644
+index 55b28b2f82a..3ebcfe8c8fd 100644
 --- a/gas/macro.h
 +++ b/gas/macro.h
 @@ -64,28 +64,31 @@ typedef struct macro_struct
@@ -685,10 +685,10 @@ index 97f2a5a4066..e87f64e70ca 100644
  
  #endif
 diff --git a/gas/read.c b/gas/read.c
-index e5185f4ba26..589c7b080c2 100644
+index 5be2686822d..6d0d4b5e31a 100644
 --- a/gas/read.c
 +++ b/gas/read.c
-@@ -655,8 +655,7 @@ poend (void)
+@@ -656,8 +656,7 @@ poend (void)
      }
  
  /* Helper function of read_a_source_file, which tries to expand a macro.  */
@@ -698,7 +698,7 @@ index e5185f4ba26..589c7b080c2 100644
  try_macro (char term, const char *line)
  {
    sb out;
-@@ -673,14 +672,12 @@ try_macro (char term, const char *line)
+@@ -674,14 +673,12 @@ try_macro (char term, const char *line)
        sb_kill (&out);
        buffer_limit =
  	input_scrub_next_buffer (&input_line_pointer);
@@ -715,7 +715,7 @@ index e5185f4ba26..589c7b080c2 100644
  }
  
  #ifdef HANDLE_BUNDLE
-@@ -1272,7 +1269,7 @@ read_a_source_file (const char *name)
+@@ -1273,7 +1270,7 @@ read_a_source_file (const char *name)
  			  s_ignore (0);
  			  nul_char = next_char = *--input_line_pointer;
  			  *input_line_pointer = '\0';
@@ -724,7 +724,7 @@ index e5185f4ba26..589c7b080c2 100644
  			    {
  			      *end = '\0';
  			      as_bad (_("unknown pseudo-op: `%s'"), s);
-@@ -1309,7 +1306,7 @@ read_a_source_file (const char *name)
+@@ -1310,7 +1307,7 @@ read_a_source_file (const char *name)
  
  		      generate_lineno_debug ();
  
@@ -733,7 +733,7 @@ index e5185f4ba26..589c7b080c2 100644
  			continue;
  
  		      if (mri_pending_align)
-@@ -2819,7 +2816,7 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
+@@ -2820,7 +2817,7 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
  	  as_warn_where (macro->file, macro->line,
  			 _("attempt to redefine pseudo-op `%s' ignored"),
  			 macro->name);
@@ -743,7 +743,7 @@ index e5185f4ba26..589c7b080c2 100644
      }
  
 diff --git a/gas/testsuite/gas/macros/macros.exp b/gas/testsuite/gas/macros/macros.exp
-index 94ac37cdb8b..3ac199feaa5 100644
+index de3df4d803d..278cf405225 100644
 --- a/gas/testsuite/gas/macros/macros.exp
 +++ b/gas/testsuite/gas/macros/macros.exp
 @@ -112,4 +112,3 @@ run_list_test count


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-12-26  1:21 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2024-12-26  1:21 UTC (permalink / raw
  To: gentoo-commits

commit:     d3feed6f35091e1269b51b59ecb1c406dc497e5d
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 26 01:20:33 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Dec 26 01:20:33 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=d3feed6f

9999: add more more macro reverts

Bug: https://sourceware.org/PR32484
Bug: https://sourceware.org/PR32486
Bug: https://sourceware.org/PR32487
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...6-Revert-macro.c-871-heap-buffer-overflow.patch | 38 ++++++++++++++++++++++
 ...e.patch => 0007-Revert-PR-32391-testcase.patch} |  8 +++--
 ...ix-error-macro-may-be-used-uninitialized.patch} | 10 +++---
 ...he-handling-or-arguments-and-macro-pseud.patch} | 10 +++---
 4 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch b/9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch
new file mode 100644
index 0000000..4d0ac10
--- /dev/null
+++ b/9999/0006-Revert-macro.c-871-heap-buffer-overflow.patch
@@ -0,0 +1,38 @@
+From a6aac087c94bab6335335e24aa9ab58ce0682859 Mon Sep 17 00:00:00 2001
+Message-ID: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Thu, 26 Dec 2024 01:15:13 +0000
+Subject: [PATCH 1/4] Revert "macro.c:871 heap-buffer-overflow"
+
+This reverts commit 6d9b7667974372357fed1f02c54a805f8c21dcde.
+---
+ gas/macro.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/gas/macro.c b/gas/macro.c
+index ded0645be8d..3d5a9f14341 100644
+--- a/gas/macro.c
++++ b/gas/macro.c
+@@ -868,7 +868,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+ 	  /* The parent's FORMALs might contain parameters that need further
+ 	     substitution.  See gas/testsuite/gas/arm/macro-vld1.s for an
+ 	     example of this.  */
+-	  if (memchr (add->ptr, '\\', add->len))
++	  if (strchr (add->ptr, '\\'))
+ 	    {
+ 	      sb newadd;
+ 
+@@ -1485,7 +1485,7 @@ delete_macro (const char *name)
+ 	}
+     }
+ 
+-  if (j < 0)
++  if (macro == NULL)
+     as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
+ 
+   free (copy);
+
+base-commit: fa93e88f754e10dfb60dd4c9bf9cef858d4c7e4a
+-- 
+2.47.1
+

diff --git a/9999/0006-Revert-PR-32391-testcase.patch b/9999/0007-Revert-PR-32391-testcase.patch
similarity index 92%
rename from 9999/0006-Revert-PR-32391-testcase.patch
rename to 9999/0007-Revert-PR-32391-testcase.patch
index d847d98..5cfdeec 100644
--- a/9999/0006-Revert-PR-32391-testcase.patch
+++ b/9999/0007-Revert-PR-32391-testcase.patch
@@ -1,8 +1,10 @@
-From 423c670c7d80a334fb9f10b71dcc68c022c2a2a5 Mon Sep 17 00:00:00 2001
-Message-ID: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+From bf07b8ac6f4c0ffe4977951d099c09c50fbe0c29 Mon Sep 17 00:00:00 2001
+Message-ID: <bf07b8ac6f4c0ffe4977951d099c09c50fbe0c29.1735175975.git.sam@gentoo.org>
+In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
 Date: Tue, 24 Dec 2024 06:25:51 +0000
-Subject: [PATCH 1/3] Revert "PR 32391 testcase"
+Subject: [PATCH 2/4] Revert "PR 32391 testcase"
 
 This reverts commit c8fcfa9aad211dfd8296ae6e978a356797936c61.
 ---

diff --git a/9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch b/9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch
similarity index 72%
rename from 9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch
rename to 9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch
index 410cf76..52cbc39 100644
--- a/9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch
+++ b/9999/0008-Revert-Fix-error-macro-may-be-used-uninitialized.patch
@@ -1,10 +1,10 @@
-From bbdfc672d363ee12f00ce6fc6c7660032cdf4f88 Mon Sep 17 00:00:00 2001
-Message-ID: <bbdfc672d363ee12f00ce6fc6c7660032cdf4f88.1735021582.git.sam@gentoo.org>
-In-Reply-To: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
-References: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+From cc2fcd3f83d79ca491c61654b94e267386cdab3a Mon Sep 17 00:00:00 2001
+Message-ID: <cc2fcd3f83d79ca491c61654b94e267386cdab3a.1735175975.git.sam@gentoo.org>
+In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
 Date: Tue, 24 Dec 2024 06:25:57 +0000
-Subject: [PATCH 2/3] Revert "Fix error: macro may be used uninitialized"
+Subject: [PATCH 3/4] Revert "Fix error: macro may be used uninitialized"
 
 This reverts commit f404dc565a4ccfe6922b45cf5526c319aedf75d6.
 ---

diff --git a/9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch b/9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
similarity index 98%
rename from 9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
rename to 9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
index ab3210d..e24e8d2 100644
--- a/9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
+++ b/9999/0009-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
@@ -1,10 +1,10 @@
-From 6bb8e5ad25557fc476ccc64ee925d9c1d199a39a Mon Sep 17 00:00:00 2001
-Message-ID: <6bb8e5ad25557fc476ccc64ee925d9c1d199a39a.1735021582.git.sam@gentoo.org>
-In-Reply-To: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
-References: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+From 499b2dbc38cbd668b62704165ee572c6ab784a4e Mon Sep 17 00:00:00 2001
+Message-ID: <499b2dbc38cbd668b62704165ee572c6ab784a4e.1735175975.git.sam@gentoo.org>
+In-Reply-To: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
+References: <a6aac087c94bab6335335e24aa9ab58ce0682859.1735175975.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
 Date: Tue, 24 Dec 2024 06:26:16 +0000
-Subject: [PATCH 3/3] Revert "Fix the handling or arguments and macro
+Subject: [PATCH 4/4] Revert "Fix the handling or arguments and macro
  pseudo-variables inside nested assembler macros."
 
 This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-12-24  6:27 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2024-12-24  6:27 UTC (permalink / raw
  To: gentoo-commits

commit:     43f28a46d9f3ea14979b20a23d05eadf76b76d14
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Dec 24 06:27:14 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Dec 24 06:27:14 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=43f28a46

9999: add more macro reverts

Bug: https://sourceware.org/PR32484
Bug: https://sourceware.org/PR32486
Bug: https://sourceware.org/PR32487
Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0006-Revert-PR-32391-testcase.patch           | 183 +++++++++++++++++++++
 ...Fix-error-macro-may-be-used-uninitialized.patch |  39 +++++
 ...he-handling-or-arguments-and-macro-pseud.patch} |  20 +--
 3 files changed, 228 insertions(+), 14 deletions(-)

diff --git a/9999/0006-Revert-PR-32391-testcase.patch b/9999/0006-Revert-PR-32391-testcase.patch
new file mode 100644
index 0000000..d847d98
--- /dev/null
+++ b/9999/0006-Revert-PR-32391-testcase.patch
@@ -0,0 +1,183 @@
+From 423c670c7d80a334fb9f10b71dcc68c022c2a2a5 Mon Sep 17 00:00:00 2001
+Message-ID: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Tue, 24 Dec 2024 06:25:51 +0000
+Subject: [PATCH 1/3] Revert "PR 32391 testcase"
+
+This reverts commit c8fcfa9aad211dfd8296ae6e978a356797936c61.
+---
+ gas/testsuite/gas/macros/nesting.s | 120 ++++++++++++++---------------
+ 1 file changed, 60 insertions(+), 60 deletions(-)
+
+diff --git a/gas/testsuite/gas/macros/nesting.s b/gas/testsuite/gas/macros/nesting.s
+index 9746ca183ef..438d5af8d00 100644
+--- a/gas/testsuite/gas/macros/nesting.s
++++ b/gas/testsuite/gas/macros/nesting.s
+@@ -1,104 +1,104 @@
+- .text
++
++	.text
+ /* PR 32391: Automatic counters inside macros should increment when nested
+-   macros finish execution.  */
+- .macro o1
+- .global before_at_\@
++	macros finish execution.  */
++.macro o1
++.global before_at_\@
+ before_at_\@:
+- .global before_plus_\+
++.global before_plus_\+
+ before_plus_\+:
+ 
+- .macro i1
+- .global inside_at_\@
++	.macro i1
++.global inside_at_\@
+ inside_at_\@:
+- .global inside_plus_\+
++.global inside_plus_\+
+ inside_plus_\+:
+- .endm
++	.endm
+ 
+- i1
+- i1
++	i1
++	i1
+ 
+- .global after_at_\@
++.global after_at_\@
+ after_at_\@:
+- .global after_plus_\+
++.global after_plus_\+
+ after_plus_\+:
+ 
+- .endm
++.endm
+ 
+ /* Invoking o1 should produce these symbols in this order:
+ 
+-   before_at_0
+-   before_plus_0
+-   inside_at_1
+-   inside_plus_0
+-   inside_at_2
+-   inside_plus_1
+-   after_at_0
+-   after_plus_0  */
+- o1
+-
++	before_at_0
++	before_plus_0
++	inside_at_1
++	inside_plus_0
++	inside_at_2
++	inside_plus_1
++	after_at_0
++	after_plus_0  */
++o1
++	
+ /* A second invocation of o1 should not produce any errors about
+-   symbols or macros being redefined.  */
+- o1
+-
++	symbols or macros being redefined.  */
++o1
++	
+ /* This definition should not collide with the definition inside o1.  */
+- .macro i1
+- .global other_inner_\@
++.macro i1
++.global other_inner_\@
+ other_inner_\@:
+- .endm
++.endm 
+ 
+-/* And invoking it should invoke the second defintion of i1, not the first.  */
+- i1
+-
+- .macro o2
+- .global _m\@_
++/* And invoking it should invoke the second defintion of i1, not the first.  */	
++i1
++		
++.macro o2
++.global _m\@_
+ _m\@_:
+- .macro i2
+- .global _m\@_
++.macro i2
++.global _m\@_
+ _m\@_:
+- .endm
+- i2
+- .endm
++.endm
++i2
++.endm
+ 
+ /* This should not generate conflicting symbols because the assembler
+    inserts the contents of o2 into the input buffer as pure text (ie
+    without evaluating i2).  The first use of \@ is evaluated at this
+    time, creating _m4_.  But the second use is not evaluated because
+    it is inside a .macro definition.
+-
++	
+    This finishes the evaluation of o2, so the \@ counter is incremented.
+-
++	
+    Next the input buffer is re-evaluated and the i2 macro definition
+    and invocation are encounterd.  The text from i2 are inserted into
+    the input buffer and at this point the second use of \@ is evaluated
+    resulting in the creation of a symbol called _m5_.  */
+- o2
++o2
+ 
+ /* Macro arguments should be independent of nesting.  */
+- .macro O3 arg
+- .global o3_\arg
++.macro O3 arg
++.global o3_\arg
+ o3_\arg:
+ 
+- .macro I3 arg
+- .global i3_\arg
++	.macro I3 arg
++.global i3_\arg
+ i3_\arg:
+- .endm
++       .endm
+ 
+- i3 bar		/* Macro names are case insensitive.  */
+- .endm
++	i3 bar		/* Macro names are case insensitive.  */
++.endm
+ 
+- o3 foo		/* Should produce two labels: o3_foo and i3_bar.  */
++o3 foo	/* Should produce two labels: o3_foo and i3_bar.  */
+ 
+ /* Nested macros can access the arguments of their parents.
+    In addition their arguments can be substituted into the arguments
+    that are substited from their parents:  */
+- .macro OUTER arg1, arg2, arg3:vararg
+- .macro INNER arg4 arg2
++.macro OUTER arg1, arg2, arg3:vararg
++     .macro INNER arg4 arg2
+         .dc.a \arg2
+- .dc.a \arg3
+- .endm
+- INNER \arg1 bert
+- .dc.a \arg2
+- .endm
++	.dc.a \arg3
++     .endm
++     INNER \arg1 bert
++	.dc.a \arg2
++.endm
+ 
+-/* This produces references to "jim", "bert" and "harryfred".  */
+- OUTER fred, jim, harry\arg4
++OUTER fred, jim, harry\arg4 /* This produces references to "jim", "bert" and "harryfred".  */
+-- 
+2.47.1
+

diff --git a/9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch b/9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch
new file mode 100644
index 0000000..410cf76
--- /dev/null
+++ b/9999/0007-Revert-Fix-error-macro-may-be-used-uninitialized.patch
@@ -0,0 +1,39 @@
+From bbdfc672d363ee12f00ce6fc6c7660032cdf4f88 Mon Sep 17 00:00:00 2001
+Message-ID: <bbdfc672d363ee12f00ce6fc6c7660032cdf4f88.1735021582.git.sam@gentoo.org>
+In-Reply-To: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+References: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Tue, 24 Dec 2024 06:25:57 +0000
+Subject: [PATCH 2/3] Revert "Fix error: macro may be used uninitialized"
+
+This reverts commit f404dc565a4ccfe6922b45cf5526c319aedf75d6.
+---
+ gas/macro.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/gas/macro.c b/gas/macro.c
+index 3d5a9f14341..a0f2a5c764c 100644
+--- a/gas/macro.c
++++ b/gas/macro.c
+@@ -1411,6 +1411,7 @@ check_macro (const char *line, sb *expand,
+ {
+   const char *s;
+   char *copy, *cls;
++  macro_entry *macro;
+   sb line_sb;
+ 
+   if (! macros_defined)
+@@ -1430,8 +1431,8 @@ check_macro (const char *line, sb *expand,
+   for (cls = copy; *cls != '\0'; cls ++)
+     *cls = TOLOWER (*cls);
+ 
+-  macro_entry *macro = NULL;
+-  for (int i = macro_nesting_depth; i >= 0; i--)
++  int i;
++  for (i = macro_nesting_depth; i >= 0; i--)
+     {
+       macro = str_hash_find (macro_hash[i], copy);
+       if (macro != NULL)
+-- 
+2.47.1
+

diff --git a/9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch b/9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
similarity index 98%
rename from 9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
rename to 9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
index 3eff67e..ab3210d 100644
--- a/9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
+++ b/9999/0008-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
@@ -1,19 +1,13 @@
-From 35123215fe882c439955a644a715b23d31c4174d Mon Sep 17 00:00:00 2001
-Message-ID: <35123215fe882c439955a644a715b23d31c4174d.1734739720.git.sam@gentoo.org>
+From 6bb8e5ad25557fc476ccc64ee925d9c1d199a39a Mon Sep 17 00:00:00 2001
+Message-ID: <6bb8e5ad25557fc476ccc64ee925d9c1d199a39a.1735021582.git.sam@gentoo.org>
+In-Reply-To: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
+References: <423c670c7d80a334fb9f10b71dcc68c022c2a2a5.1735021582.git.sam@gentoo.org>
 From: Sam James <sam@gentoo.org>
-Date: Sat, 21 Dec 2024 00:07:29 +0000
-Subject: [PATCH] Revert "Fix the handling or arguments and macro
+Date: Tue, 24 Dec 2024 06:26:16 +0000
+Subject: [PATCH 3/3] Revert "Fix the handling or arguments and macro
  pseudo-variables inside nested assembler macros."
 
 This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.
-
-Breaks kernel build on amd64 and some multimedia bits on arm*, revert
-for now.
-
-Bug: https://sourceware.org/PR32484
-Bug: https://sourceware.org/PR32486
-Bug: https://sourceware.org/PR32487
-Signed-off-by: Sam James <sam@gentoo.org>
 ---
  gas/config/tc-iq2000.c              |   6 +-
  gas/doc/as.texi                     |  60 +------
@@ -901,8 +895,6 @@ index 438d5af8d00..00000000000
 -.endm
 -
 -OUTER fred, jim, harry\arg4 /* This produces references to "jim", "bert" and "harryfred".  */
-
-base-commit: 14848fc2b22e6e718abadcfbcc0491688df19a8e
 -- 
 2.47.1
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-12-21  0:09 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2024-12-21  0:09 UTC (permalink / raw
  To: gentoo-commits

commit:     8338985dde30f332b85aa008f1ff932941c2583e
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 21 00:09:16 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 21 00:09:16 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=8338985d

9999: Revert patch breaking kernel build

Revert "Fix the handling or arguments and macro pseudo-variables inside
nested assembler macros."

This reverts upstream commit 9f2e3c21f6506f081f1360f02b847606e0e00995.

Breaks kernel build on amd64 and some multimedia bits on arm*, revert
for now.

Bug: https://sourceware.org/PR32484
Bug: https://sourceware.org/PR32486
Bug: https://sourceware.org/PR32487
Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...the-handling-or-arguments-and-macro-pseud.patch | 908 +++++++++++++++++++++
 1 file changed, 908 insertions(+)

diff --git a/9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch b/9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
new file mode 100644
index 0000000..3eff67e
--- /dev/null
+++ b/9999/0006-Revert-Fix-the-handling-or-arguments-and-macro-pseud.patch
@@ -0,0 +1,908 @@
+From 35123215fe882c439955a644a715b23d31c4174d Mon Sep 17 00:00:00 2001
+Message-ID: <35123215fe882c439955a644a715b23d31c4174d.1734739720.git.sam@gentoo.org>
+From: Sam James <sam@gentoo.org>
+Date: Sat, 21 Dec 2024 00:07:29 +0000
+Subject: [PATCH] Revert "Fix the handling or arguments and macro
+ pseudo-variables inside nested assembler macros."
+
+This reverts commit 9f2e3c21f6506f081f1360f02b847606e0e00995.
+
+Breaks kernel build on amd64 and some multimedia bits on arm*, revert
+for now.
+
+Bug: https://sourceware.org/PR32484
+Bug: https://sourceware.org/PR32486
+Bug: https://sourceware.org/PR32487
+Signed-off-by: Sam James <sam@gentoo.org>
+---
+ gas/config/tc-iq2000.c              |   6 +-
+ gas/doc/as.texi                     |  60 +------
+ gas/input-scrub.c                   |   7 +-
+ gas/macro.c                         | 270 +++++-----------------------
+ gas/macro.h                         |  17 +-
+ gas/read.c                          |  15 +-
+ gas/testsuite/gas/macros/macros.exp |   1 -
+ gas/testsuite/gas/macros/nesting.d  |  28 ---
+ gas/testsuite/gas/macros/nesting.s  | 104 -----------
+ 9 files changed, 64 insertions(+), 444 deletions(-)
+ delete mode 100644 gas/testsuite/gas/macros/nesting.d
+ delete mode 100644 gas/testsuite/gas/macros/nesting.s
+
+diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c
+index 1cbc578281f..2198ffda2b9 100644
+--- a/gas/config/tc-iq2000.c
++++ b/gas/config/tc-iq2000.c
+@@ -105,6 +105,8 @@ struct iq2000_hi_fixup
+ /* The list of unmatched HI relocs.  */
+ static struct iq2000_hi_fixup * iq2000_hi_fixup_list;
+ 
++/* Macro hash table, which we will add to.  */
++extern struct htab *macro_hash;
+ \f
+ const char md_shortopts[] = "";
+ const struct option md_longopts[] =
+@@ -277,7 +279,9 @@ iq2000_add_macro (const char *  name,
+ 	}
+     }
+ 
+-  (void) add_macro (macro, true);
++  str_hash_insert (macro_hash, macro->name, macro, 1);
++
++  macro_defined = 1;
+ }
+ 
+ static void
+diff --git a/gas/doc/as.texi b/gas/doc/as.texi
+index 1683594a0bb..6be54b57599 100644
+--- a/gas/doc/as.texi
++++ b/gas/doc/as.texi
+@@ -6215,12 +6215,7 @@ With that definition, @samp{SUM 0,5} is equivalent to this assembly input:
+ @item .macro @var{macname}
+ @itemx .macro @var{macname} @var{macargs} @dots{}
+ @cindex @code{macro} directive
+-Begin the definition of a macro called @var{macname}.  Macro names are case
+-insensitive.  Macro definitions can be nested, although their behaviour is
+-sometimes counter intuitive.  Nested macros only have scope within their
+-defining macro.
+-
+-If your macro
++Begin the definition of a macro called @var{macname}.  If your macro
+ definition requires arguments, specify their names after the macro name,
+ separated by commas or spaces.  You can qualify the macro argument to
+ indicate whether all invocations must specify a non-blank value (through
+@@ -6385,29 +6380,6 @@ adjacent string literals - even if separated only by a blank - will not be
+ concatenated when determining macro arguments, even if they're only separated
+ by white space.  This is unlike certain other pseudo ops, e.g. @code{.ascii}.
+ 
+-Nested macros can access the arguments of their parents.  But also if their
+-argument names clash with those of their parents, their versions are used.  So
+-for example:
+-
+-@smallexample
+-.macro OUTER arg1, arg2, arg3:vararg
+-     .macro INNER arg4 arg2
+-        .dc.a \arg2
+-	.dc.a \arg3
+-     .endm
+-     INNER \arg1 bert
+-	.dc.a \arg2
+-.endm
+-
+-OUTER fred, jim, harry\arg4
+-@end smallexample
+-
+-This will generate references to symbols called @samp{jim} - from the
+-definition of the OUTER macro, @samp{bert} - from the definition in INNER
+-where arg2 has been overridden and @samp{harryfred} - from the definition in
+-INNER where the value of arg3 from OUTER is used, but with the value of arg4
+-substituted into the symbol.
+-
+ @item .endm
+ @cindex @code{endm} directive
+ Mark the end of a macro definition.
+@@ -6423,33 +6395,6 @@ Exit early from the current macro definition.
+ executed in this pseudo-variable; you can copy that number to your
+ output with @samp{\@@}, but @emph{only within a macro definition}.
+ 
+-Note - the @samp{\@@} counter is incremented at the end of the expansion of a
+-macro, but before the contents of any nested macros are evaluated.  This can
+-lead to counter-intuitive behaviour when nested macros are used.  For example:
+-
+-@smallexample
+-  .macro o
+-    .macro i
+-    _i\@@_:
+-    .endm
+-    i
+-    _o\@@_:
+-  .endm
+-  o
+-@end smallexample
+-
+-Produces two symbols @samp{_o0_} and @samp{_i1_}.  This happens because the
+-@samp{o} macro executes entirely first, putting the definition and invocation
+-of the @samp{i} macro into the input buffer.  It also puts the definition of
+-the @samp{_o\@@_} symbol into the input buffer, evaluating the @samp{\@@}
+-counter in the process and so generating a symbol called @samp{_o0_}.
+-
+-That finishes the invocation of @samp{o} so the @samp{\@@} counter is
+-incremented.  Then the input buffer is re-evaluated and the definition and
+-invocation of macro @samp{i} is found.  This results in @samp{_i\@@_} being put
+-into the input buffer and this time @samp{\@@} evaluates to 1, so the symbol
+-created is @samp{_i1_}.
+-
+ @cindex number of times a macro has been executed
+ @cindex macro, execution count
+ @item \+
+@@ -6736,9 +6681,6 @@ those explicitly specified with @code{.eject}.
+ Undefine the macro @var{name}, so that later uses of the string will not be
+ expanded.  @xref{Macro}.
+ 
+-Note - nested macros are automatically purged at the end of the macro that
+-defines them.
+-
+ @ifset ELF
+ @node PushSection
+ @section @code{.pushsection @var{name} [, @var{subsection}] [, "@var{flags}"[, @@@var{type}[,@var{arguments}]]]}
+diff --git a/gas/input-scrub.c b/gas/input-scrub.c
+index 25fac879a56..878edc8fd36 100644
+--- a/gas/input-scrub.c
++++ b/gas/input-scrub.c
+@@ -23,7 +23,6 @@
+ #include "input-file.h"
+ #include "sb.h"
+ #include "listing.h"
+-#include "macro.h"
+ 
+ /*
+  * O/S independent module to supply buffers of sanitised source code
+@@ -291,13 +290,12 @@ input_scrub_include_sb (sb *from, char *position, enum expansion expansion)
+       ++macro_nest;
+     }
+ 
++#ifdef md_macro_start
+   if (expansion == expanding_macro)
+     {
+-#ifdef md_macro_start
+       md_macro_start ();
+-#endif
+-      increment_macro_nesting_depth ();
+     }
++#endif
+ 
+   next_saved_file = input_scrub_push (position);
+ 
+@@ -352,7 +350,6 @@ input_scrub_next_buffer (char **bufp)
+ 	         data.  */
+ 	      md_macro_end ();
+ #endif
+-	      decrement_macro_nesting_depth ();
+ 	    }
+ 	  if (from_sb_expansion != expanding_app)
+ 	    --macro_nest;
+diff --git a/gas/macro.c b/gas/macro.c
+index a0f2a5c764c..8b376f7f490 100644
+--- a/gas/macro.c
++++ b/gas/macro.c
+@@ -44,24 +44,11 @@
+ 
+ /* The macro hash table.  */
+ 
+-/* Macro nesting depth.  Similar to macro_nest defined in sb.c, but this
+-   counter is specific to macros, whereas macro_nest also counts repeated
+-   string blocks.  */
+-static unsigned int macro_nesting_depth;
++htab_t macro_hash;
+ 
+-/* Maximum nesting depth.  Ideally the same as the value of max_macro_nest
+-   as defined in as.c (ie 100).  But there is one test in the assembler
+-   testsuite (bfin/allinsn16.s) that nests macros to a depth of 8192.  So
+-   we have a ridiculously large number here.  */
+-#define MAX_MACRO_DEPTH 8193
++/* Whether any macros have been defined.  */
+ 
+-static htab_t macro_hash[MAX_MACRO_DEPTH];
+-
+-/* Whether any macros have been defined.
+-   FIXME:  This could be a counter that is incremented
+-   with .macro and decremented with .purgem.  */
+-
+-static bool macros_defined = false;
++int macro_defined;
+ 
+ /* Whether we should strip '@' characters.  */
+ 
+@@ -73,18 +60,6 @@ static unsigned int macro_number;
+ 
+ static void free_macro (macro_entry *);
+ 
+-bool
+-add_macro (macro_entry * macro, bool replace)
+-{
+-  if (str_hash_insert (macro_hash [macro_nesting_depth],
+-		       macro->name, macro, replace) == NULL)
+-    {
+-      macros_defined = true;
+-      return true;
+-    }
+-  return false;
+-}
+-
+ static void
+ macro_del_f (void *ent)
+ {
+@@ -97,23 +72,15 @@ macro_del_f (void *ent)
+ void
+ macro_init (void)
+ {
+-  int i;
+-
+-  for (i = 0; i < MAX_MACRO_DEPTH; i++)
+-    macro_hash[i] = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
+-				       macro_del_f, notes_calloc, NULL);
+-  macros_defined = false;
++  macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
++				  macro_del_f, notes_calloc, NULL);
++  macro_defined = 0;
+ }
+ 
+ void
+ macro_end (void)
+ {
+-  int i;
+-
+-  for (i = MAX_MACRO_DEPTH; i--;)
+-    htab_delete (macro_hash[i]);
+-
+-  macros_defined = false;
++  htab_delete (macro_hash);
+ }
+ 
+ /* Read input lines till we get to a TO string.
+@@ -688,13 +655,6 @@ free_macro (macro_entry *macro)
+   free (macro);
+ }
+ 
+-static macro_entry * last_recorded_macro = NULL;
+-void
+-macro_record_invocation (macro_entry * macro)
+-{
+-  last_recorded_macro = macro;
+-}
+-
+ /* Define a new macro.  */
+ 
+ macro_entry *
+@@ -758,19 +718,15 @@ define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
+   /* And stick it in the macro hash table.  */
+   for (idx = 0; idx < name.len; idx++)
+     name.ptr[idx] = TOLOWER (name.ptr[idx]);
+-
+-  if (macro_nesting_depth > 0)
+-    macro->parent = last_recorded_macro;
+-  else
+-    macro->parent = NULL;
+-
+   if (!error)
+     {
+-      if (! add_macro (macro, false))
++      if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL)
+ 	error = _("Macro `%s' was already defined");
+     }
+ 
+-  if (error != NULL)
++  if (!error)
++    macro_defined = 1;
++  else
+     {
+       as_bad_where (macro->file, macro->line, error, macro->name);
+       free_macro (macro);
+@@ -794,25 +750,11 @@ get_apost_token (size_t idx, sb *in, sb *name, int kind)
+   return idx;
+ }
+ 
+-static const char *
+-macro_expand_body (sb *, sb *, formal_entry *, struct htab *,
+-		   const macro_entry *, unsigned int);
+-
+-/* Find the actual value for a formal parameter starting at START inside IN.
+-    Appends the value of parameter onto OUT.
+-   The hash table of formal parameters is provided by FORMAL_HASH.
+-   The character that indicated the presense of a formal parameter is passed
+-    in KIND.
+-   If COPYIFNOTTHERE is true and the parameter is not found in the hash table
+-    then it is appended as plain text onto OUT.
+-   The macro containing the formal parameters is passed in MACRO.
+-    This can be empty.
+-   Returns the offset inside IN after advanceing past the parameter.
+-   Also stores the parameter's name into T.  */
++/* Substitute the actual value for a formal parameter.  */
+ 
+ static size_t
+ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+-	    int kind, sb *out, int copyifnotthere, const macro_entry * macro)
++	    int kind, sb *out, int copyifnotthere)
+ {
+   size_t src;
+   formal_entry *ptr;
+@@ -826,12 +768,16 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+     ptr = NULL;
+   else
+     ptr = str_hash_find (formal_hash, sb_terminate (t));
+-  
+   if (ptr)
+     {
+-      sb * add = ptr->actual.len ? &ptr->actual : &ptr->def;
+-
+-      sb_add_sb (out, add);
++      if (ptr->actual.len)
++	{
++	  sb_add_sb (out, &ptr->actual);
++	}
++      else
++	{
++	  sb_add_sb (out, &ptr->def);
++	}
+     }
+   else if (kind == '&')
+     {
+@@ -845,55 +791,6 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+     {
+       sb_add_sb (out, t);
+     }
+-  else if (!macro_strip_at
+-	   && macro_nesting_depth > 0
+-	   && macro != NULL
+-	   && macro->parent != NULL)
+-    {
+-      const macro_entry * orig_macro = macro;
+-      bool success = false;
+-
+-      /* We have failed to find T, but we are inside nested macros.  So check
+-	 the parent macros so see if they have a FORMAL that matches T.  */
+-      while (macro->parent != NULL)
+-	{
+-	  macro = macro->parent;
+-
+-	  ptr = str_hash_find (macro->formal_hash, t->ptr);
+-	  if (ptr == NULL)
+-	    continue;
+-
+-	  sb * add = ptr->actual.len ? &ptr->actual : &ptr->def;
+-
+-	  /* The parent's FORMALs might contain parameters that need further
+-	     substitution.  See gas/testsuite/gas/arm/macro-vld1.s for an
+-	     example of this.  */
+-	  if (strchr (add->ptr, '\\'))
+-	    {
+-	      sb newadd;
+-
+-	      sb_new (&newadd);
+-	      /* FIXME: Should we do something if the call to
+-		 macro_expand_body returns an error message ?  */
+-	      (void) macro_expand_body (add, &newadd, NULL, NULL,
+-					orig_macro, orig_macro->count);
+-	      sb_add_sb (out, &newadd);
+-	    }
+-	  else
+-	    {
+-	      sb_add_sb (out, add);
+-	    }
+-	  success = true;
+-	  break;
+-	}
+-      if (! success)
+-	{
+-	  /* We reached the outermost macro and failed to find T, so
+-	     just copy the entire parameter as is.  */
+-	  sb_add_char (out, '\\');
+-	  sb_add_sb (out, t);
+-	}
+-    }
+   else
+     {
+       sb_add_char (out, '\\');
+@@ -902,12 +799,7 @@ sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
+   return src;
+ }
+ 
+-/* Expands the body of a macro / block of text IN, copying it into OUT.
+-   Parameters for substitution are found in FORMALS and FORMAL_HASH or
+-   MACRO.
+-   The number of times that this macro / block of text have already been
+-   copied into the output is held in INSTANCE.
+-   Returns NULL upon success or an error message otherwise.  */
++/* Expand the body of a macro.  */
+ 
+ static const char *
+ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+@@ -919,38 +811,18 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+   int inquote = 0, macro_line = 0;
+   formal_entry *loclist = NULL;
+   const char *err = NULL;
+-  int nesting = 0;
+ 
+-  if (formals == NULL && macro != NULL)
+-    formals = macro->formals;
+-
+-  if (formal_hash == NULL && macro != NULL)
+-    formal_hash = macro->formal_hash;
+-  
+   sb_new (&t);
+ 
+   while (src < in->len && !err)
+     {
+-      if (in->ptr[src] == '.')
+-	{
+-	  /* Check to see if we have encountered ".macro" or ".endm" */
+-	  if (in->len > src + 5
+-	      && strncmp (in->ptr + src, ".macro", 6) == 0)
+-	    ++ nesting;
+-
+-	  else if (in->len > src + 4
+-		   && strncmp (in->ptr + src, ".endm", 5) == 0)
+-	    -- nesting;
+-	}
+-
+       if (in->ptr[src] == '&')
+ 	{
+ 	  sb_reset (&t);
+ 	  if (flag_mri)
+ 	    {
+ 	      if (src + 1 < in->len && in->ptr[src + 1] == '&')
+-		src = sub_actual (src + 2, in, &t, formal_hash,
+-				  '\'', out, 1, macro);
++		src = sub_actual (src + 2, in, &t, formal_hash, '\'', out, 1);
+ 	      else
+ 		sb_add_char (out, in->ptr[src++]);
+ 	    }
+@@ -958,8 +830,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 	    {
+ 	      /* Permit macro parameter substitution delineated with
+ 		 an '&' prefix and optional '&' suffix.  */
+-	      src = sub_actual (src + 1, in, &t, formal_hash,
+-				'&', out, 0, macro);
++	      src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
+ 	    }
+ 	}
+       else if (in->ptr[src] == '\\')
+@@ -980,12 +851,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 	      else
+ 		as_bad_where (macro->file, macro->line + macro_line, _("missing `)'"));
+ 	    }
+-	  else if (src < in->len
+-		   && in->ptr[src] == '@'
+-		   /* PR 32391: Do not perform the substition inside nested
+-		      macros.  Instead wait until they are re-evaluated and
+-		      perform the substition then.  */
+-		   && ! nesting)
++	  else if (src < in->len && in->ptr[src] == '@')
+ 	    {
+ 	      /* Sub in the total macro invocation number.  */
+ 
+@@ -994,12 +860,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 	      sprintf (buffer, "%u", macro_number);
+ 	      sb_add_string (out, buffer);
+ 	    }
+-	  else if (src < in->len
+-		   && in->ptr[src] == '+'
+-		   /* PR 32391: Do not perform the substition inside nested
+-		      macros.  Instead wait until they are re-evaluated and
+-		      perform the substition then.  */
+-		   && ! nesting)
++	  else if (src < in->len && in->ptr[src] == '+')
+ 	    {
+ 	      /* Sub in the current macro invocation number.  */
+ 
+@@ -1043,18 +904,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 	  else
+ 	    {
+ 	      sb_reset (&t);
+-
+-	      if (nesting)
+-		{
+-		  src = get_apost_token (src, in, &t, '\'');
+-		  sb_add_char (out, '\\');
+-		  sb_add_sb (out, &t);
+-		}
+-	      else
+-		{
+-		  src = sub_actual (src, in, &t, formal_hash,
+-				    '\'', out, 0, macro);
+-		}
++	      src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
+ 	    }
+ 	}
+       else if ((flag_macro_alternate || flag_mri)
+@@ -1073,7 +923,7 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 	      sb_reset (&t);
+ 	      src = sub_actual (src, in, &t, formal_hash,
+ 				(macro_strip_at && inquote) ? '@' : '\'',
+-				out, 1, macro);
++				out, 1);
+ 	    }
+ 	  else
+ 	    {
+@@ -1185,7 +1035,6 @@ macro_expand_body (sb *in, sb *out, formal_entry *formals,
+ 
+   if (!err && (out->len == 0 || out->ptr[out->len - 1] != '\n'))
+     sb_add_char (out, '\n');
+-
+   return err;
+ }
+ 
+@@ -1370,7 +1219,8 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
+ 	    }
+ 	}
+ 
+-      err = macro_expand_body (&m->sub, out, NULL, NULL, m, m->count);
++      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
++			       m->count);
+     }
+ 
+   /* Discard any unnamed formal arguments.  */
+@@ -1403,9 +1253,9 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
+ }
+ 
+ /* Check for a macro.  If one is found, put the expansion into
+-   *EXPAND.  Return TRUE if a macro is found, FALSE otherwise.  */
++   *EXPAND.  Return 1 if a macro is found, 0 otherwise.  */
+ 
+-bool
++int
+ check_macro (const char *line, sb *expand,
+ 	     const char **error, macro_entry **info)
+ {
+@@ -1414,12 +1264,9 @@ check_macro (const char *line, sb *expand,
+   macro_entry *macro;
+   sb line_sb;
+ 
+-  if (! macros_defined)
+-    return false;
+-
+   if (! is_name_beginner (*line)
+       && (! flag_mri || *line != '.'))
+-    return false;
++    return 0;
+ 
+   s = line + 1;
+   while (is_part_of_name (*s))
+@@ -1431,17 +1278,11 @@ check_macro (const char *line, sb *expand,
+   for (cls = copy; *cls != '\0'; cls ++)
+     *cls = TOLOWER (*cls);
+ 
+-  int i;
+-  for (i = macro_nesting_depth; i >= 0; i--)
+-    {
+-      macro = str_hash_find (macro_hash[i], copy);
+-      if (macro != NULL)
+-	break;
+-    }
++  macro = str_hash_find (macro_hash, copy);
+   free (copy);
+ 
+   if (macro == NULL)
+-    return false;
++    return 0;
+ 
+   /* Wrap the line up in an sb.  */
+   sb_new (&line_sb);
+@@ -1457,7 +1298,7 @@ check_macro (const char *line, sb *expand,
+   if (info)
+     *info = macro;
+ 
+-  return true;
++  return 1;
+ }
+ 
+ /* Delete a macro.  */
+@@ -1475,20 +1316,11 @@ delete_macro (const char *name)
+     copy[i] = TOLOWER (name[i]);
+   copy[i] = '\0';
+ 
+-  int j;
+-  for (j = macro_nesting_depth; j >= 0; j--)
+-    {
+-      macro = str_hash_find (macro_hash [j], copy);
+-      if (macro != NULL)
+-	{
+-	  str_hash_delete (macro_hash[j], copy);
+-	  break;
+-	}
+-    }
+-
+-  if (macro == NULL)
++  macro = str_hash_find (macro_hash, copy);
++  if (macro != NULL)
++    str_hash_delete (macro_hash, copy);
++  else
+     as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
+-
+   free (copy);
+ }
+ 
+@@ -1590,25 +1422,3 @@ expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
+ 
+   return err;
+ }
+-
+-void
+-increment_macro_nesting_depth (void)
+-{
+- if (macro_nesting_depth >= (MAX_MACRO_DEPTH - 1))
+-    as_fatal (_("macros nested too deeply"));
+-  else
+-    ++macro_nesting_depth;
+-}
+-
+-void
+-decrement_macro_nesting_depth (void)
+-{
+-  if (macro_nesting_depth == 0)
+-    as_fatal (_("too much macro un-nesting"));
+-  else
+-    {
+-      /* FIXME: Potential memory leak here.  */
+-      htab_empty (macro_hash [macro_nesting_depth]);
+-      --macro_nesting_depth;
+-    }
+-}
+diff --git a/gas/macro.h b/gas/macro.h
+index 97f2a5a4066..e87f64e70ca 100644
+--- a/gas/macro.h
++++ b/gas/macro.h
+@@ -64,28 +64,31 @@ typedef struct macro_struct
+   int             formal_count;		/* Number of formal args.  */
+   formal_entry *  formals;		/* List of formal_structs.  */
+   htab_t          formal_hash;		/* Hash table of formals.  */
+-  struct macro_struct * parent;         /* Parent of nested macros.  */
+   const char *    name;			/* Macro name.  */
+   const char *    file;			/* File the macro was defined in.  */
+   unsigned int    line;			/* Line number of definition.  */
+   unsigned int    count;                /* Invocation count.  */
+ } macro_entry;
+ 
+-/* The macro/text block nesting level.  */
++/* Whether any macros have been defined.  */
++
++extern int macro_defined;
++
++/* The macro nesting level.  */
+ 
+ extern int macro_nest;
+ 
++/* The macro hash table.  */
++
++extern htab_t macro_hash;
++
+ extern int buffer_and_nest (const char *, const char *, sb *,
+ 			    size_t (*) (sb *));
+ extern void macro_init (void);
+ extern void macro_end (void);
+ extern macro_entry *define_macro (sb *, sb *, size_t (*) (sb *));
+-extern bool check_macro (const char *, sb *, const char **, macro_entry **);
++extern int check_macro (const char *, sb *, const char **, macro_entry **);
+ extern void delete_macro (const char *);
+ extern const char *expand_irp (int, size_t, sb *, sb *, size_t (*) (sb *));
+-extern void increment_macro_nesting_depth (void);
+-extern void decrement_macro_nesting_depth (void);
+-extern void macro_record_invocation (macro_entry *);
+-extern bool add_macro (macro_entry *, bool);
+ 
+ #endif
+diff --git a/gas/read.c b/gas/read.c
+index e5185f4ba26..589c7b080c2 100644
+--- a/gas/read.c
++++ b/gas/read.c
+@@ -655,8 +655,7 @@ poend (void)
+     }
+ 
+ /* Helper function of read_a_source_file, which tries to expand a macro.  */
+-
+-static bool
++static int
+ try_macro (char term, const char *line)
+ {
+   sb out;
+@@ -673,14 +672,12 @@ try_macro (char term, const char *line)
+       sb_kill (&out);
+       buffer_limit =
+ 	input_scrub_next_buffer (&input_line_pointer);
+-
+-      macro_record_invocation (macro);
+ #ifdef md_macro_info
+       md_macro_info (macro);
+ #endif
+-      return true;
++      return 1;
+     }
+-  return false;
++  return 0;
+ }
+ 
+ #ifdef HANDLE_BUNDLE
+@@ -1272,7 +1269,7 @@ read_a_source_file (const char *name)
+ 			  s_ignore (0);
+ 			  nul_char = next_char = *--input_line_pointer;
+ 			  *input_line_pointer = '\0';
+-			  if (! try_macro (next_char, s))
++			  if (! macro_defined || ! try_macro (next_char, s))
+ 			    {
+ 			      *end = '\0';
+ 			      as_bad (_("unknown pseudo-op: `%s'"), s);
+@@ -1309,7 +1306,7 @@ read_a_source_file (const char *name)
+ 
+ 		      generate_lineno_debug ();
+ 
+-		      if (try_macro (next_char, s))
++		      if (macro_defined && try_macro (next_char, s))
+ 			continue;
+ 
+ 		      if (mri_pending_align)
+@@ -2819,7 +2816,7 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
+ 	  as_warn_where (macro->file, macro->line,
+ 			 _("attempt to redefine pseudo-op `%s' ignored"),
+ 			 macro->name);
+-	  delete_macro (macro->name);
++	  str_hash_delete (macro_hash, macro->name);
+ 	}
+     }
+ 
+diff --git a/gas/testsuite/gas/macros/macros.exp b/gas/testsuite/gas/macros/macros.exp
+index 94ac37cdb8b..3ac199feaa5 100644
+--- a/gas/testsuite/gas/macros/macros.exp
++++ b/gas/testsuite/gas/macros/macros.exp
+@@ -112,4 +112,3 @@ run_list_test count
+ run_list_test irp-count
+ run_list_test irpc-quote
+ run_list_test rept-count
+-run_dump_test nesting
+diff --git a/gas/testsuite/gas/macros/nesting.d b/gas/testsuite/gas/macros/nesting.d
+deleted file mode 100644
+index 2f44aedb2dc..00000000000
+--- a/gas/testsuite/gas/macros/nesting.d
++++ /dev/null
+@@ -1,28 +0,0 @@
+-#nm: -j 
+-#name: Nested macros (PR 32391)
+-# Sone targets do not support macros used like this.
+-#skip: tic*-*-* mmix-*
+-
+-#...
+-_m7_
+-_m8_
+-after_at_0
+-after_at_3
+-after_plus_0
+-after_plus_1
+-before_at_0
+-before_at_3
+-before_plus_0
+-before_plus_1
+-bert
+-harryfred
+-i3_bar
+-inside_at_1
+-inside_at_2
+-inside_at_4
+-inside_at_5
+-inside_plus_0
+-inside_plus_1
+-jim
+-o3_foo
+-other_inner_6
+diff --git a/gas/testsuite/gas/macros/nesting.s b/gas/testsuite/gas/macros/nesting.s
+deleted file mode 100644
+index 438d5af8d00..00000000000
+--- a/gas/testsuite/gas/macros/nesting.s
++++ /dev/null
+@@ -1,104 +0,0 @@
+-
+-	.text
+-/* PR 32391: Automatic counters inside macros should increment when nested
+-	macros finish execution.  */
+-.macro o1
+-.global before_at_\@
+-before_at_\@:
+-.global before_plus_\+
+-before_plus_\+:
+-
+-	.macro i1
+-.global inside_at_\@
+-inside_at_\@:
+-.global inside_plus_\+
+-inside_plus_\+:
+-	.endm
+-
+-	i1
+-	i1
+-
+-.global after_at_\@
+-after_at_\@:
+-.global after_plus_\+
+-after_plus_\+:
+-
+-.endm
+-
+-/* Invoking o1 should produce these symbols in this order:
+-
+-	before_at_0
+-	before_plus_0
+-	inside_at_1
+-	inside_plus_0
+-	inside_at_2
+-	inside_plus_1
+-	after_at_0
+-	after_plus_0  */
+-o1
+-	
+-/* A second invocation of o1 should not produce any errors about
+-	symbols or macros being redefined.  */
+-o1
+-	
+-/* This definition should not collide with the definition inside o1.  */
+-.macro i1
+-.global other_inner_\@
+-other_inner_\@:
+-.endm 
+-
+-/* And invoking it should invoke the second defintion of i1, not the first.  */	
+-i1
+-		
+-.macro o2
+-.global _m\@_
+-_m\@_:
+-.macro i2
+-.global _m\@_
+-_m\@_:
+-.endm
+-i2
+-.endm
+-
+-/* This should not generate conflicting symbols because the assembler
+-   inserts the contents of o2 into the input buffer as pure text (ie
+-   without evaluating i2).  The first use of \@ is evaluated at this
+-   time, creating _m4_.  But the second use is not evaluated because
+-   it is inside a .macro definition.
+-	
+-   This finishes the evaluation of o2, so the \@ counter is incremented.
+-	
+-   Next the input buffer is re-evaluated and the i2 macro definition
+-   and invocation are encounterd.  The text from i2 are inserted into
+-   the input buffer and at this point the second use of \@ is evaluated
+-   resulting in the creation of a symbol called _m5_.  */
+-o2
+-
+-/* Macro arguments should be independent of nesting.  */
+-.macro O3 arg
+-.global o3_\arg
+-o3_\arg:
+-
+-	.macro I3 arg
+-.global i3_\arg
+-i3_\arg:
+-       .endm
+-
+-	i3 bar		/* Macro names are case insensitive.  */
+-.endm
+-
+-o3 foo	/* Should produce two labels: o3_foo and i3_bar.  */
+-
+-/* Nested macros can access the arguments of their parents.
+-   In addition their arguments can be substituted into the arguments
+-   that are substited from their parents:  */
+-.macro OUTER arg1, arg2, arg3:vararg
+-     .macro INNER arg4 arg2
+-        .dc.a \arg2
+-	.dc.a \arg3
+-     .endm
+-     INNER \arg1 bert
+-	.dc.a \arg2
+-.endm
+-
+-OUTER fred, jim, harry\arg4 /* This produces references to "jim", "bert" and "harryfred".  */
+
+base-commit: 14848fc2b22e6e718abadcfbcc0491688df19a8e
+-- 
+2.47.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-08-03 22:43 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2024-08-03 22:43 UTC (permalink / raw
  To: gentoo-commits

commit:     ec95ccad4a4802e2b375af024d901863444b8ecc
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Aug  3 22:43:00 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Aug  3 22:43:00 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=ec95ccad

Trivial rebase

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch | 4 ++--
 9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch       | 6 +++---
 .../0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch | 4 ++--
 9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch                | 4 ++--
 .../0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch | 6 +++---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index a36bb51..34afb9b 100644
--- a/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,7 +1,7 @@
-From 1594a93229b13d3c34c679e5991e64663cace1b9 Mon Sep 17 00:00:00 2001
+From a40f75efe4a34fbb447a026a52202b415013a984 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
-Subject: [PATCH 2/7] Gentoo: libiberty: install PIC version of libiberty.a
+Subject: [PATCH 1/5] Gentoo: libiberty: install PIC version of libiberty.a
 
 This will install a PIC version of libiberty.a by overwriting the non-PIC
 version of libiberty.a while compiling.  We do this because there is no

diff --git a/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
index 3694049..e7e4ae8 100644
--- a/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,7 +1,7 @@
-From 6d6cbf2ede96fd65bd7a9382c3364aaa9d0ac3bb Mon Sep 17 00:00:00 2001
+From 87a5dd82a8e08967694943e866aa9b26c4fc6a63 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
-Subject: [PATCH 3/7] Gentoo: add --with-extra-soversion-suffix= option
+Subject: [PATCH 2/5] Gentoo: add --with-extra-soversion-suffix= option
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit
@@ -79,7 +79,7 @@ index b3d97d478ea..38209d1b234 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 6458974951e..b43789851cd 100755
+index 83cb19c7015..a60c76319b9 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -701,6 +701,7 @@ WARN_CFLAGS

diff --git a/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 6964aab..70c605a 100644
--- a/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,7 +1,7 @@
-From a8cf14f5ea0a210928250fd1c47b4e45c39974c5 Mon Sep 17 00:00:00 2001
+From 225a5f5b9f40c1f335146ec882bd5517e4573f62 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
-Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
+Subject: [PATCH 3/5] Gentoo: Give also libctf optionally a gentoo-specific
  soversion
 
 ---

diff --git a/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index fe6da95..943d079 100644
--- a/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,7 +1,7 @@
-From d826b80fe902aefd77465be3650ab2d62af5e099 Mon Sep 17 00:00:00 2001
+From 942b4489226184460d46eb9e7450eb63a1885621 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
-Subject: [PATCH 6/7] Gentoo: XFAIL 15 broken ld.gold tests
+Subject: [PATCH 4/5] Gentoo: XFAIL 15 broken ld.gold tests
 
 It seems like either the tests or ld.gold in general cannot handle
 compilers built with --enable-default-pie. No fix yet, so let's ignore

diff --git a/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index 6eebb98..54c7ba8 100644
--- a/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,7 +1,7 @@
-From bbaa9fafb08385e5ad836bc30a2db3af47d1cc5a Mon Sep 17 00:00:00 2001
+From 24694fe84ea1ac172f709bd1b079ebb996e4feb9 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
-Subject: [PATCH 7/7] Apply a similar libiberty fix as in 7d53105d for
+Subject: [PATCH 5/5] Apply a similar libiberty fix as in 7d53105d for
  libopcodes and libgprofng
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
@@ -46,7 +46,7 @@ index cef4b275305..295fd3ee2df 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index 050fd5ff0ff..4b68211dea6 100755
+index 0075b6dc0ef..76fca3e9246 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
 @@ -14379,10 +14379,10 @@ if test "$enable_shared" = "yes"; then


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-06-29 17:05 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2024-06-29 17:05 UTC (permalink / raw
  To: gentoo-commits

commit:     1fec9188faca01b3a679ec42cf74c638d4b34ebd
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 29 17:05:16 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jun 29 17:05:16 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=1fec9188

Renumber patches

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...tch => 0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch} | 0
 ...ion.patch => 0002-Gentoo-add-with-extra-soversion-suffix-option.patch} | 0
 ...ch => 0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch} | 0
 ...d.gold-tests.patch => 0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch} | 0
 ...ch => 0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch} | 0
 5 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
similarity index 100%
rename from 9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
rename to 9999/0001-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch
similarity index 100%
rename from 9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
rename to 9999/0002-Gentoo-add-with-extra-soversion-suffix-option.patch

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
similarity index 100%
rename from 9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
rename to 9999/0003-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
similarity index 100%
rename from 9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
rename to 9999/0004-Gentoo-XFAIL-15-broken-ld.gold-tests.patch

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
similarity index 100%
rename from 9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
rename to 9999/0005-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch


^ permalink raw reply	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-06-29 16:32 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2024-06-29 16:32 UTC (permalink / raw
  To: gentoo-commits

commit:     1c1fe5a0f79546d17321568bcb07825552c53979
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 29 16:31:59 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jun 29 16:31:59 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=1c1fe5a0

Let's try without poison

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 338 ---------------------
 1 file changed, 338 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
deleted file mode 100644
index f11678e..0000000
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ /dev/null
@@ -1,338 +0,0 @@
-From 68b26b5bf2047d71fac89ee321c0f9231c85903e Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@gentoo.org>
-Date: Tue, 20 Jul 2021 21:08:31 +0200
-Subject: [PATCH 1/7] Gentoo: gold/ld: add support for poisoned system
- directories
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-This is based on the old CodeSourcery patch written by Joseph Myers to add
-support to the link for detecting & rejecting bad -L paths when using a
-cross-compiler.  The differences here:
-* The command line flags are always available.
-* We can turn on & off the warning via the command line.
-* The configure option controls the default warning behavior.
-* Add support for gold.
-
-It is not currently upstream, nor has it been submitted at all.  There are
-no plans to do so currently either.
-
-BUG=chromium:488360
-TEST=`cbuildbot chromiumos-sdk` passes  # tests arm/amd64/mipsel/x86
-TEST=`cbuildbot panther_moblab-full whirlwind-release` pass
-TEST=`cbuildbot {x32,arm64}-generic-full` has no new failures
-TEST=x86_64-cros-linux-gnu-ld throws warnings when using -L/lib (gold & bfd)
-
-Reviewed-on: https://chromium-review.googlesource.com/272083
-(cherry picked from commit f92dbf35c00ab13cee36f6be8ae5ca46454d9000)
-
-Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
-Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
----
- gold/options.cc | 33 +++++++++++++++++++++++++++++++++
- gold/options.h  |  7 +++++++
- ld/config.in    |  3 +++
- ld/configure    | 16 ++++++++++++++++
- ld/configure.ac | 10 ++++++++++
- ld/ld.h         |  7 +++++++
- ld/ld.texi      | 18 ++++++++++++++++++
- ld/ldfile.c     | 20 ++++++++++++++++++++
- ld/ldlex.h      |  3 +++
- ld/ldmain.c     |  7 +++++++
- ld/lexsup.c     | 24 ++++++++++++++++++++++++
- 11 files changed, 148 insertions(+)
-
-diff --git a/gold/options.cc b/gold/options.cc
-index 46f067fa72f..a07ba1c82ed 100644
---- a/gold/options.cc
-+++ b/gold/options.cc
-@@ -1355,6 +1355,39 @@ General_options::finalize()
-   // in the path, as appropriate.
-   this->add_sysroot();
- 
-+  // Now check if library_path is poisoned.
-+  if (this->warn_poison_system_directories())
-+    {
-+      std::vector<std::string> bad_paths;
-+
-+      bad_paths.push_back("/lib");
-+      // TODO: This check is disabled for now due to a bunch of packages that
-+      // use libtool and relink with -L/usr/lib paths (albeit after the right
-+      // sysroot path).  Once those are fixed we can enable.
-+      // We also need to adjust it so it only rejects one or two levels deep.
-+      // Gcc's internal paths also live below /usr/lib.
-+      // http://crbug.com/488360
-+      // bad_paths.push_back("/usr/lib");
-+      bad_paths.push_back("/usr/local/lib");
-+      bad_paths.push_back("/usr/X11R6/lib");
-+
-+      for (std::vector<std::string>::const_iterator b = bad_paths.begin();
-+	   b != bad_paths.end();
-+	   ++b)
-+	for (Dir_list::iterator p = this->library_path_.value.begin();
-+	     p != this->library_path_.value.end();
-+	     ++p)
-+	  if (!p->name().compare(0, b->size(), *b))
-+	    {
-+	      if (this->error_poison_system_directories())
-+		gold_fatal(_("library search path \"%s\" is unsafe for "
-+			     "cross-compilation"), p->name().c_str());
-+	      else
-+		gold_warning(_("library search path \"%s\" is unsafe for "
-+			       "cross-compilation"), p->name().c_str());
-+	    }
-+    }
-+
-   // Now that we've normalized the options, check for contradictory ones.
-   if (this->shared() && this->is_static())
-     gold_fatal(_("-shared and -static are incompatible"));
-diff --git a/gold/options.h b/gold/options.h
-index 446e8d42614..464863b45fa 100644
---- a/gold/options.h
-+++ b/gold/options.h
-@@ -1402,6 +1402,13 @@ class General_options
-   DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
- 	      N_("Ignored"), NULL);
- 
-+  DEFINE_bool(warn_poison_system_directories, options::TWO_DASHES, '\0', false,
-+	      N_("Warn for -L options using system directories"),
-+	      N_("Do not warn for -L options using system directories"));
-+  DEFINE_bool(error_poison_system_directories, options::TWO_DASHES, '\0', false,
-+	      N_("Give an error for -L options using system directories"),
-+	      NULL);
-+
-   DEFINE_bool(warn_search_mismatch, options::TWO_DASHES, '\0', true,
- 	      N_("Warn when skipping an incompatible library"),
- 	      N_("Don't warn when skipping an incompatible library"));
-diff --git a/ld/config.in b/ld/config.in
-index f7c9da3d02a..e4fdbf6db5b 100644
---- a/ld/config.in
-+++ b/ld/config.in
-@@ -74,6 +74,9 @@
-    language is requested. */
- #undef ENABLE_NLS
- 
-+/* Define to warn for use of native system library directories */
-+#undef ENABLE_POISON_SYSTEM_DIRECTORIES
-+
- /* Additional extension a shared object might have. */
- #undef EXTRA_SHLIB_EXTENSION
- 
-diff --git a/ld/configure b/ld/configure
-index 4e8de840418..f6d3069133e 100755
---- a/ld/configure
-+++ b/ld/configure
-@@ -844,6 +844,7 @@ with_lib_path
- enable_targets
- enable_64_bit_bfd
- with_sysroot
-+enable_poison_system_directories
- enable_gold
- enable_got
- enable_compressed_debug_sections
-@@ -1535,6 +1536,8 @@ Optional Features:
-   --enable-checking       enable run-time checks
-   --enable-targets        alternative target configurations
-   --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
-+  --enable-poison-system-directories
-+                          warn for use of native system library directories
-   --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
-   --enable-got=<type>     GOT handling scheme (target, single, negative,
-                           multigot)
-@@ -15566,6 +15569,19 @@ fi
- 
- 
- 
-+# Check whether --enable-poison-system-directories was given.
-+if test "${enable_poison_system_directories+set}" = set; then :
-+  enableval=$enable_poison_system_directories;
-+else
-+  enable_poison_system_directories=no
-+fi
-+
-+if test "x${enable_poison_system_directories}" = "xyes"; then
-+
-+$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
-+
-+fi
-+
- # Check whether --enable-gold was given.
- if test "${enable_gold+set}" = set; then :
-   enableval=$enable_gold; case "${enableval}" in
-diff --git a/ld/configure.ac b/ld/configure.ac
-index bdf51a062fa..3d370ff92ce 100644
---- a/ld/configure.ac
-+++ b/ld/configure.ac
-@@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
- AC_SUBST(TARGET_SYSTEM_ROOT)
- AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
- 
-+AC_ARG_ENABLE([poison-system-directories],
-+         AS_HELP_STRING([--enable-poison-system-directories],
-+                [warn for use of native system library directories]),,
-+         [enable_poison_system_directories=no])
-+if test "x${enable_poison_system_directories}" = "xyes"; then
-+  AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
-+       [1],
-+       [Define to warn for use of native system library directories])
-+fi
-+
- dnl Use --enable-gold to decide if this linker should be the default.
- dnl "install_as_default" is set to false if gold is the default linker.
- dnl "installed_linker" is the installed BFD linker name.
-diff --git a/ld/ld.h b/ld/ld.h
-index 0dee944cf2a..a2bb9a10993 100644
---- a/ld/ld.h
-+++ b/ld/ld.h
-@@ -166,6 +166,13 @@ typedef struct
-      in the linker script.  */
-   bool force_group_allocation;
- 
-+  /* If true warn for uses of system directories when cross linking.  */
-+  bool warn_poison_system_directories;
-+
-+  /* If true (default false) give an error for uses of system
-+     directories when cross linking instead of a warning.  */
-+  bool error_poison_system_directories;
-+
-   /* Big or little endian as set on command line.  */
-   enum endian_enum endian;
- 
-diff --git a/ld/ld.texi b/ld/ld.texi
-index 89e3913317a..cd16eb9685e 100644
---- a/ld/ld.texi
-+++ b/ld/ld.texi
-@@ -3245,6 +3245,24 @@ creation of the metadata note, if one had been enabled by an earlier
- occurrence of the --package-metadata option.
- If the linker has been built with libjansson, then the JSON string
- will be validated.
-+
-+@kindex --warn-poison-system-directories
-+@item --warn-poison-system-directories
-+Warn for @option{-L} options using system directories such as
-+@file{/usr/lib} when cross linking.  This option is intended for use
-+in environments that want to detect and reject incorrect link settings.
-+
-+@kindex --no-warn-poison-system-directories
-+@item --no-warn-poison-system-directories
-+Do not warn for @option{-L} options using system directories such as
-+@file{/usr/lib} when cross linking.  This option is intended for use
-+in chroot environments when such directories contain the correct
-+libraries for the target system rather than the host.
-+
-+@kindex --error-poison-system-directories
-+@item --error-poison-system-directories
-+Give an error instead of a warning for @option{-L} options using
-+system directories when cross linking.
- @end table
- 
- @c man end
-diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 87be885d31a..469ab52f985 100644
---- a/ld/ldfile.c
-+++ b/ld/ldfile.c
-@@ -344,6 +344,26 @@ ldfile_add_library_path (const char *name, enum search_dir_source source)
-       search_tail_ptr = &new_dirs->next;
-     }
- 
-+ if (command_line.warn_poison_system_directories
-+      && (!strncmp (name, "/lib", 4)
-+      /* TODO: This check is disabled for now due to a bunch of packages that
-+       * use libtool and relink with -L/usr/lib paths (albeit after the right
-+       * sysroot path).  Once those are fixed we can enable.
-+       * We also need to adjust it so it only rejects one or two levels deep.
-+       * Gcc's internal paths also live below /usr/lib.
-+       * http://crbug.com/488360  */
-+       /* || !strncmp (name, "/usr/lib", 8) */
-+          || !strncmp (name, "/usr/local/lib", 14)
-+          || !strncmp (name, "/usr/X11R6/lib", 14)))
-+    {
-+      if (command_line.error_poison_system_directories)
-+        einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
-+                 "cross-compilation\n"), name);
-+      else
-+        einfo (_("%P: warning: library search path \"%s\" is unsafe for "
-+                 "cross-compilation\n"), name);
-+    }
-+
-   return new_dirs;
- }
- 
-diff --git a/ld/ldlex.h b/ld/ldlex.h
-index defe3fcbbb9..ab94487edc6 100644
---- a/ld/ldlex.h
-+++ b/ld/ldlex.h
-@@ -153,6 +153,9 @@ enum option_values
-   OPTION_PRINT_OUTPUT_FORMAT,
-   OPTION_PRINT_SYSROOT,
-   OPTION_IGNORE_UNRESOLVED_SYMBOL,
-+  OPTION_WARN_POISON_SYSTEM_DIRECTORIES,
-+  OPTION_NO_WARN_POISON_SYSTEM_DIRECTORIES,
-+  OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
-   OPTION_PUSH_STATE,
-   OPTION_POP_STATE,
-   OPTION_DISABLE_MULTIPLE_DEFS_ABS,
-diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 037099b9d37..552a191a857 100644
---- a/ld/ldmain.c
-+++ b/ld/ldmain.c
-@@ -347,6 +347,13 @@ main (int argc, char **argv)
-   command_line.warn_mismatch = true;
-   command_line.warn_search_mismatch = true;
-   command_line.check_section_addresses = -1;
-+  command_line.warn_poison_system_directories =
-+#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
-+    true;
-+#else
-+    false;
-+#endif
-+  command_line.error_poison_system_directories = false;
- 
-   /* We initialize DEMANGLING based on the environment variable
-      COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
-diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 4aa0124ce2f..e8e28ac7ea4 100644
---- a/ld/lexsup.c
-+++ b/ld/lexsup.c
-@@ -613,6 +613,18 @@ static const struct ld_option ld_options[] =
-     OPTION_IGNORE_UNRESOLVED_SYMBOL},
-     '\0', N_("SYMBOL"),
-     N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
-+  { {"warn-poison-system-directories", no_argument, NULL,
-+     OPTION_WARN_POISON_SYSTEM_DIRECTORIES},
-+    '\0', NULL, N_("Warn for -L options using system directories"),
-+    TWO_DASHES },
-+  { {"no-warn-poison-system-directories", no_argument, NULL,
-+     OPTION_NO_WARN_POISON_SYSTEM_DIRECTORIES},
-+    '\0', NULL, N_("Do not warn for -L options using system directories"),
-+    TWO_DASHES },
-+  { {"error-poison-system-directories", no_argument, NULL,
-+     OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
-+    '\0', NULL, N_("Give an error for -L options using system directories"),
-+    TWO_DASHES },
-   { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
-     '\0', NULL, N_("Push state of flags governing input file handling"),
-     TWO_DASHES },
-@@ -1785,6 +1797,18 @@ parse_args (unsigned argc, char **argv)
- 	  }
- 	  break;
- 
-+   case OPTION_WARN_POISON_SYSTEM_DIRECTORIES:
-+     command_line.warn_poison_system_directories = true;
-+     break;
-+
-+   case OPTION_NO_WARN_POISON_SYSTEM_DIRECTORIES:
-+     command_line.warn_poison_system_directories = false;
-+     break;
-+
-+   case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
-+     command_line.error_poison_system_directories = true;
-+     break;
-+
- 	case OPTION_PUSH_STATE:
- 	  input_flags.pushed = xmemdup (&input_flags,
- 					sizeof (input_flags),
--- 
-2.44.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-06-29 16:32 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2024-06-29 16:32 UTC (permalink / raw
  To: gentoo-commits

commit:     ef75bb26c983c91db82996224bf38e0feefd94c3
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 29 16:31:33 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jun 29 16:31:33 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=ef75bb26

Not needed anymore

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch | 61 ----------------------
 1 file changed, 61 deletions(-)

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
deleted file mode 100644
index 4cfd1da..0000000
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ /dev/null
@@ -1,61 +0,0 @@
-From b706ce22cbea4edb8ba06ef1b64f6b20f3502d0c Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Tue, 20 Jul 2021 21:15:24 +0200
-Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
-
----
- binutils/testsuite/lib/binutils-common.exp |  2 +-
- ld/testsuite/lib/ld-lib.exp                | 16 ++++++++++++++--
- 2 files changed, 15 insertions(+), 3 deletions(-)
-
-diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index f0136577b6c..afb6f7cc9c3 100644
---- a/binutils/testsuite/lib/binutils-common.exp
-+++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1394,7 +1394,7 @@ proc run_dump_test { name {extra_options {}} } {
- 
- 	    # Add -L$srcdir/$subdir so that the linker command can use
- 	    # linker scripts in the source directory.
--	    set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+	    set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
- 		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
- 
- 	    # If needed then check for, or add a -Map option.
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index e6e643ca3ca..b1164e9a96f 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
-     global HOSTING_EMU
- 
-     remote_file host delete $target
--    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
-+    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv -o $target -r $objects"]
- }
- 
- # Check to see if ld is being invoked with a non-endian output format
-@@ -202,8 +202,20 @@ proc default_ld_link { ld target objects } {
- 	set flags [big_or_little_endian]
-     }
- 
-+    # Hilariously, this procedure is called sometimes with $CC and sometimes
-+    # with $ld as parameter. If we want to change the default behaviour, we
-+    # need to take the different option formats into account.
-+    # We check the $ld parameter for
-+    # - ld-new         -> we're working with the new linker
-+    # - otherwise      -> we're likely working with the system compiler
-+    if {[regexp {ld-new$} $ld]} {
-+      set gentoosysv "--hash-style=sysv"
-+    } else {
-+      set gentoosysv "-Wl,--hash-style=sysv"
-+    }
-+
-     remote_file host delete $target
--    set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"]
-+    set exec_output [run_host_cmd "$ld" "$gentoosysv $flags -o $target $objects"]
-     set exec_output [prune_warnings $exec_output]
- 
-     # We don't care if we get a warning about a non-existent start
--- 
-2.44.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2024-06-28 21:48 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2024-06-28 21:48 UTC (permalink / raw
  To: gentoo-commits

commit:     cf4082117e6e8e456dd2e4d92b3d1a50d38ce2c5
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 28 21:48:16 2024 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Fri Jun 28 21:48:16 2024 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=cf408211

Rebase patches for master

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 76 +++++++++++-----------
 ...iberty-install-PIC-version-of-libiberty.a.patch |  6 +-
 ...oo-add-with-extra-soversion-suffix-option.patch | 28 ++++----
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch | 10 +--
 ...-also-libctf-optionally-a-gentoo-specific.patch | 32 ++++-----
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch | 10 +--
 ...ilar-libiberty-fix-as-in-7d53105d-for-lib.patch | 16 ++---
 7 files changed, 89 insertions(+), 89 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index e054415..f11678e 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From 7b47d0be518ef97bb5259a5dbb70d6b3f22011f6 Mon Sep 17 00:00:00 2001
+From 68b26b5bf2047d71fac89ee321c0f9231c85903e Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/7] Gentoo: gold/ld: add support for poisoned system
@@ -44,7 +44,7 @@ Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
  11 files changed, 148 insertions(+)
 
 diff --git a/gold/options.cc b/gold/options.cc
-index c9834b66159..bd3e948a61b 100644
+index 46f067fa72f..a07ba1c82ed 100644
 --- a/gold/options.cc
 +++ b/gold/options.cc
 @@ -1355,6 +1355,39 @@ General_options::finalize()
@@ -88,7 +88,7 @@ index c9834b66159..bd3e948a61b 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index 46f658f23ea..8f9b8c177ad 100644
+index 446e8d42614..464863b45fa 100644
 --- a/gold/options.h
 +++ b/gold/options.h
 @@ -1402,6 +1402,13 @@ class General_options
@@ -106,10 +106,10 @@ index 46f658f23ea..8f9b8c177ad 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index a453c7f7241..a0bc2a56013 100644
+index f7c9da3d02a..e4fdbf6db5b 100644
 --- a/ld/config.in
 +++ b/ld/config.in
-@@ -58,6 +58,9 @@
+@@ -74,6 +74,9 @@
     language is requested. */
  #undef ENABLE_NLS
  
@@ -120,10 +120,10 @@ index a453c7f7241..a0bc2a56013 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index d2cdf256b89..0f32e98bc34 100755
+index 4e8de840418..f6d3069133e 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -838,6 +838,7 @@ with_lib_path
+@@ -844,6 +844,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -131,7 +131,7 @@ index d2cdf256b89..0f32e98bc34 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1520,6 +1521,8 @@ Optional Features:
+@@ -1535,6 +1536,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -140,7 +140,7 @@ index d2cdf256b89..0f32e98bc34 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -15538,6 +15541,19 @@ fi
+@@ -15566,6 +15569,19 @@ fi
  
  
  
@@ -161,10 +161,10 @@ index d2cdf256b89..0f32e98bc34 100755
  if test "${enable_gold+set}" = set; then :
    enableval=$enable_gold; case "${enableval}" in
 diff --git a/ld/configure.ac b/ld/configure.ac
-index c3ebd3ec7e4..71790d7640f 100644
+index bdf51a062fa..3d370ff92ce 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
-@@ -103,6 +103,16 @@ AC_SUBST(use_sysroot)
+@@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
  AC_SUBST(TARGET_SYSTEM_ROOT)
  AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
  
@@ -182,10 +182,10 @@ index c3ebd3ec7e4..71790d7640f 100644
  dnl "install_as_default" is set to false if gold is the default linker.
  dnl "installed_linker" is the installed BFD linker name.
 diff --git a/ld/ld.h b/ld/ld.h
-index a0f8a15c7a9..69420b6673a 100644
+index 0dee944cf2a..a2bb9a10993 100644
 --- a/ld/ld.h
 +++ b/ld/ld.h
-@@ -163,6 +163,13 @@ typedef struct
+@@ -166,6 +166,13 @@ typedef struct
       in the linker script.  */
    bool force_group_allocation;
  
@@ -200,10 +200,10 @@ index a0f8a15c7a9..69420b6673a 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index 1f56ded1041..1fa6bf7b225 100644
+index 89e3913317a..cd16eb9685e 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -3070,6 +3070,24 @@ creation of the metadata note, if one had been enabled by an earlier
+@@ -3245,6 +3245,24 @@ creation of the metadata note, if one had been enabled by an earlier
  occurrence of the --package-metadata option.
  If the linker has been built with libjansson, then the JSON string
  will be validated.
@@ -229,15 +229,14 @@ index 1f56ded1041..1fa6bf7b225 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 8f869c1f19e..ee9d4bccee2 100644
+index 87be885d31a..469ab52f985 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
-@@ -327,6 +327,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
-     new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
-   else
-     new_dirs->name = xstrdup (name);
-+
-+  if (command_line.warn_poison_system_directories
+@@ -344,6 +344,26 @@ ldfile_add_library_path (const char *name, enum search_dir_source source)
+       search_tail_ptr = &new_dirs->next;
+     }
+ 
++ if (command_line.warn_poison_system_directories
 +      && (!strncmp (name, "/lib", 4)
 +      /* TODO: This check is disabled for now due to a bunch of packages that
 +       * use libtool and relink with -L/usr/lib paths (albeit after the right
@@ -245,25 +244,26 @@ index 8f869c1f19e..ee9d4bccee2 100644
 +       * We also need to adjust it so it only rejects one or two levels deep.
 +       * Gcc's internal paths also live below /usr/lib.
 +       * http://crbug.com/488360  */
-+	  /* || !strncmp (name, "/usr/lib", 8) */
-+	  || !strncmp (name, "/usr/local/lib", 14)
-+	  || !strncmp (name, "/usr/X11R6/lib", 14)))
++       /* || !strncmp (name, "/usr/lib", 8) */
++          || !strncmp (name, "/usr/local/lib", 14)
++          || !strncmp (name, "/usr/X11R6/lib", 14)))
 +    {
 +      if (command_line.error_poison_system_directories)
-+	einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
-+	         "cross-compilation\n"), name);
++        einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
++                 "cross-compilation\n"), name);
 +      else
-+	einfo (_("%P: warning: library search path \"%s\" is unsafe for "
-+	         "cross-compilation\n"), name);
++        einfo (_("%P: warning: library search path \"%s\" is unsafe for "
++                 "cross-compilation\n"), name);
 +    }
++
+   return new_dirs;
  }
  
- /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 87cac02141d..d79ec8faa15 100644
+index defe3fcbbb9..ab94487edc6 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
-@@ -151,6 +151,9 @@ enum option_values
+@@ -153,6 +153,9 @@ enum option_values
    OPTION_PRINT_OUTPUT_FORMAT,
    OPTION_PRINT_SYSROOT,
    OPTION_IGNORE_UNRESOLVED_SYMBOL,
@@ -274,10 +274,10 @@ index 87cac02141d..d79ec8faa15 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 06ac2c64fa8..5ec931a0255 100644
+index 037099b9d37..552a191a857 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
-@@ -325,6 +325,13 @@ main (int argc, char **argv)
+@@ -347,6 +347,13 @@ main (int argc, char **argv)
    command_line.warn_mismatch = true;
    command_line.warn_search_mismatch = true;
    command_line.check_section_addresses = -1;
@@ -292,10 +292,10 @@ index 06ac2c64fa8..5ec931a0255 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 49dfc13382a..b2d1d967aa0 100644
+index 4aa0124ce2f..e8e28ac7ea4 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -594,6 +594,18 @@ static const struct ld_option ld_options[] =
+@@ -613,6 +613,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -314,7 +314,7 @@ index 49dfc13382a..b2d1d967aa0 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1738,6 +1750,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1785,6 +1797,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -334,5 +334,5 @@ index 49dfc13382a..b2d1d967aa0 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index d428c20..a36bb51 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 1156f7b2f690654cf5810ef1e34791d18d207a9f Mon Sep 17 00:00:00 2001
+From 1594a93229b13d3c34c679e5991e64663cace1b9 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/7] Gentoo: libiberty: install PIC version of libiberty.a
@@ -18,7 +18,7 @@ general are fairly low, and we'd rather have things work for all of them.
  1 file changed, 1 insertion(+)
 
 diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
-index f9fbba23e2c..d37488d1bf8 100644
+index b77a41c781c..5e3725d16ff 100644
 --- a/libiberty/Makefile.in
 +++ b/libiberty/Makefile.in
 @@ -258,6 +258,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
@@ -30,5 +30,5 @@ index f9fbba23e2c..d37488d1bf8 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index d4d4571..3694049 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 411d52402227b6e1a9c779988f6f0fc1e17c6620 Mon Sep 17 00:00:00 2001
+From 6d6cbf2ede96fd65bd7a9382c3364aaa9d0ac3bb Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/7] Gentoo: add --with-extra-soversion-suffix= option
@@ -34,7 +34,7 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 378c13198d6..e0fa379ca8e 100644
+index 0dc733eaba9..5bd636d931a 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 378c13198d6..e0fa379ca8e 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -991,6 +993,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -999,6 +1001,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index 378c13198d6..e0fa379ca8e 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index 8d09f6fa4af..d397502bb4d 100644
+index b3d97d478ea..38209d1b234 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -342,6 +342,7 @@ ECHO_T = @ECHO_T@
+@@ -348,6 +348,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index 8d09f6fa4af..d397502bb4d 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2454,6 +2455,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2471,6 +2472,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,10 +79,10 @@ index 8d09f6fa4af..d397502bb4d 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index f0a07ff675f..2322e9b61cf 100755
+index 6458974951e..b43789851cd 100755
 --- a/bfd/configure
 +++ b/bfd/configure
-@@ -695,6 +695,7 @@ WARN_CFLAGS
+@@ -701,6 +701,7 @@ WARN_CFLAGS
  REPORT_BUGS_TEXI
  REPORT_BUGS_TO
  PKGVERSION
@@ -90,7 +90,7 @@ index f0a07ff675f..2322e9b61cf 100755
  DEBUGDIR
  ENABLE_BFD_64_BIT_FALSE
  ENABLE_BFD_64_BIT_TRUE
-@@ -836,6 +837,7 @@ enable_secureplt
+@@ -842,6 +843,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -98,7 +98,7 @@ index f0a07ff675f..2322e9b61cf 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1518,6 +1520,8 @@ Optional Packages:
+@@ -1530,6 +1532,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
@@ -107,7 +107,7 @@ index f0a07ff675f..2322e9b61cf 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12064,6 +12068,15 @@ fi
+@@ -12082,6 +12086,15 @@ fi
  
  
  
@@ -124,10 +124,10 @@ index f0a07ff675f..2322e9b61cf 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index d1e7e3a4bf3..48f2d69991c 100644
+index 6bcfd1b7368..dde0a3af03e 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
-@@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
+@@ -167,6 +167,13 @@ AC_ARG_WITH(separate-debug-dir,
  [DEBUGDIR="${withval}"])
  AC_SUBST(DEBUGDIR)
  
@@ -142,5 +142,5 @@ index d1e7e3a4bf3..48f2d69991c 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 6d820fe..4cfd1da 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From 722482c5057cc921d1ab96266da29be4dc7d1354 Mon Sep 17 00:00:00 2001
+From b706ce22cbea4edb8ba06ef1b64f6b20f3502d0c Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -9,10 +9,10 @@ Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index f89ac8a6108..2be9383b49e 100644
+index f0136577b6c..afb6f7cc9c3 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1340,7 +1340,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1394,7 +1394,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,7 +22,7 @@ index f89ac8a6108..2be9383b49e 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index aca303e0728..44f2865116f 100644
+index e6e643ca3ca..b1164e9a96f 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
 @@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
@@ -57,5 +57,5 @@ index aca303e0728..44f2865116f 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index ab34ef9..6964aab 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From a0e9a882db04d45bf878b746a8a30c5e51619d8b Mon Sep 17 00:00:00 2001
+From a8cf14f5ea0a210928250fd1c47b4e45c39974c5 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
@@ -12,10 +12,10 @@ Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
  4 files changed, 62 insertions(+), 2 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index b1dbc2f6ba4..d282ceb619a 100644
+index fb1a306c888..5fcc73bd04e 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
-@@ -26,6 +26,9 @@ info_TEXINFOS =
+@@ -31,6 +31,9 @@ info_TEXINFOS =
  DISTCLEANFILES =
  MAINTAINERCLEANFILES =
  
@@ -25,7 +25,7 @@ index b1dbc2f6ba4..d282ceb619a 100644
  # This is where we get zlib from.  zlibdir is -L../zlib and zlibinc is
  # -I../zlib, unless we were configured with --with-system-zlib, in which
  # case both are empty.
-@@ -46,8 +49,17 @@ include_HEADERS =
+@@ -51,8 +54,17 @@ include_HEADERS =
  noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
  endif
  
@@ -45,10 +45,10 @@ index b1dbc2f6ba4..d282ceb619a 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 3d2696bcc47..664d6360c47 100644
+index 54f5daa79ee..b7a80edfab6 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -380,6 +380,7 @@ AUTOCONF = @AUTOCONF@
+@@ -430,6 +430,7 @@ AUTOCONF = @AUTOCONF@
  AUTOHEADER = @AUTOHEADER@
  AUTOMAKE = @AUTOMAKE@
  AWK = @AWK@
@@ -56,7 +56,7 @@ index 3d2696bcc47..664d6360c47 100644
  CATALOGS = @CATALOGS@
  CATOBJEXT = @CATOBJEXT@
  CC = @CC@
-@@ -402,6 +403,7 @@ EXEEXT = @EXEEXT@
+@@ -452,6 +453,7 @@ EXEEXT = @EXEEXT@
  
  # Setup the testing framework, if you have one
  EXPECT = expect
@@ -64,7 +64,7 @@ index 3d2696bcc47..664d6360c47 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -540,8 +542,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+@@ -603,8 +605,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
  @INSTALL_LIBBFD_FALSE@include_HEADERS = 
  @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/ctf.h $(INCDIR)/ctf-api.h
  @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
@@ -80,10 +80,10 @@ index 3d2696bcc47..664d6360c47 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index 4c01c022837..07778d52be4 100755
+index 7466d56a18b..54c86592b70 100755
 --- a/libctf/configure
 +++ b/libctf/configure
-@@ -645,6 +645,10 @@ BUILD_INFO_FALSE
+@@ -646,6 +646,10 @@ BUILD_INFO_FALSE
  BUILD_INFO_TRUE
  NEED_CTF_QSORT_R_FALSE
  NEED_CTF_QSORT_R_TRUE
@@ -94,7 +94,7 @@ index 4c01c022837..07778d52be4 100755
  ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
  ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
  zlibinc
-@@ -806,6 +810,7 @@ enable_maintainer_mode
+@@ -821,6 +825,7 @@ enable_maintainer_mode
  enable_install_libbfd
  with_system_zlib
  enable_libctf_hash_debugging
@@ -102,7 +102,7 @@ index 4c01c022837..07778d52be4 100755
  '
        ac_precious_vars='build_alias
  host_alias
-@@ -1463,6 +1468,8 @@ Optional Packages:
+@@ -1487,6 +1492,8 @@ Optional Packages:
                            both]
    --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
    --with-system-zlib      use installed libz
@@ -111,7 +111,7 @@ index 4c01c022837..07778d52be4 100755
  
  Some influential environment variables:
    CC          C compiler command
-@@ -14335,6 +14342,26 @@ else
+@@ -16274,6 +16281,26 @@ else
  fi
  
  
@@ -138,7 +138,7 @@ index 4c01c022837..07778d52be4 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -15227,6 +15254,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -17177,6 +17204,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -150,7 +150,7 @@ index 4c01c022837..07778d52be4 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index 6a5eade1855..a0e65a4aeda 100644
+index 64544b83a9f..1ce43327c25 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
 @@ -76,6 +76,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
@@ -171,5 +171,5 @@ index 6a5eade1855..a0e65a4aeda 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 2934cd3..fe6da95 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 9bf3571ddf788d8986d1e45d54df356867bd23d9 Mon Sep 17 00:00:00 2001
+From d826b80fe902aefd77465be3650ab2d62af5e099 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/7] Gentoo: XFAIL 15 broken ld.gold tests
@@ -16,7 +16,7 @@ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27303
  2 files changed, 18 insertions(+), 4 deletions(-)
 
 diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
-index df9405c1aac..749921633b2 100644
+index 2f1348fd6e2..1206460f191 100644
 --- a/gold/testsuite/Makefile.am
 +++ b/gold/testsuite/Makefile.am
 @@ -1,5 +1,11 @@
@@ -32,7 +32,7 @@ index df9405c1aac..749921633b2 100644
  # system and the host system are the same.  So these tests will not
  # work when building with a cross-compiler.
 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
-index fb0eb12553b..b506a7f8da7 100644
+index 9cf21df8d7d..df14333c558 100644
 --- a/gold/testsuite/Makefile.in
 +++ b/gold/testsuite/Makefile.in
 @@ -15,10 +15,6 @@
@@ -61,7 +61,7 @@ index fb0eb12553b..b506a7f8da7 100644
  check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
  	$(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
  	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
-@@ -2759,6 +2763,10 @@ top_srcdir = @top_srcdir@
+@@ -2782,6 +2786,10 @@ top_srcdir = @top_srcdir@
  zlibdir = @zlibdir@
  zlibinc = @zlibinc@
  
@@ -73,5 +73,5 @@ index fb0eb12553b..b506a7f8da7 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.42.0
+2.44.2
 

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index 2331b5c..6eebb98 100644
--- a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,4 +1,4 @@
-From 51b418fda84420da6d2c0e830435ad61409daffb Mon Sep 17 00:00:00 2001
+From bbaa9fafb08385e5ad836bc30a2db3af47d1cc5a Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
 Subject: [PATCH 7/7] Apply a similar libiberty fix as in 7d53105d for
@@ -18,7 +18,7 @@ Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 8 insertions(+), 6 deletions(-)
 
 diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
-index 20c8b0022e4..96dbc8e0e94 100644
+index fb4b8a0fafa..3d7cb18ff71 100644
 --- a/gprofng/src/Makefile.am
 +++ b/gprofng/src/Makefile.am
 @@ -144,7 +144,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -32,7 +32,7 @@ index 20c8b0022e4..96dbc8e0e94 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
-index 47da873b80c..52a22279cf7 100644
+index cef4b275305..295fd3ee2df 100644
 --- a/gprofng/src/Makefile.in
 +++ b/gprofng/src/Makefile.in
 @@ -552,7 +552,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -46,10 +46,10 @@ index 47da873b80c..52a22279cf7 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index a65b0a2f95b..f412c1a6c96 100755
+index 050fd5ff0ff..4b68211dea6 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
-@@ -12479,10 +12479,10 @@ if test "$enable_shared" = "yes"; then
+@@ -14379,10 +14379,10 @@ if test "$enable_shared" = "yes"; then
    case "${host}" in
      *-*-cygwin*)
        SHARED_LDFLAGS="-no-undefined"
@@ -63,10 +63,10 @@ index a65b0a2f95b..f412c1a6c96 100755
        ;;
    esac
 diff --git a/opcodes/configure.ac b/opcodes/configure.ac
-index cae2a67ff10..5cb194779e9 100644
+index 4d918e3ef9b..9692e69693e 100644
 --- a/opcodes/configure.ac
 +++ b/opcodes/configure.ac
-@@ -196,10 +196,10 @@ if test "$enable_shared" = "yes"; then
+@@ -195,10 +195,10 @@ if test "$enable_shared" = "yes"; then
    case "${host}" in
      *-*-cygwin*)
        SHARED_LDFLAGS="-no-undefined"
@@ -80,5 +80,5 @@ index cae2a67ff10..5cb194779e9 100644
        ;;
    esac
 -- 
-2.42.0
+2.44.2
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-10-27  0:44 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2023-10-27  0:44 UTC (permalink / raw
  To: gentoo-commits

commit:     100720f399389f6fec20dcc98064db336e56c5b2
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 27 00:44:00 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Oct 27 00:44:00 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=100720f3

9999: rebase patches

Signed-off-by: Sam James <sam <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch |  48 ++----
 ...iberty-install-PIC-version-of-libiberty.a.patch |   4 +-
 ...oo-add-with-extra-soversion-suffix-option.patch |  18 +--
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch |  10 +-
 ...-also-libctf-optionally-a-gentoo-specific.patch |  32 +---
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch |   4 +-
 ...ilar-libiberty-fix-as-in-7d53105d-for-lib.patch |  18 +--
 ...-failures-with-enable-textrel-check-error.patch | 139 -----------------
 9999/0009-tests-objcopy-keep-debug.patch           |  36 -----
 9999/0010-tests-pr23169b.patch                     |  21 ---
 9999/0011-tests-gprofng.patch                      | 164 ---------------------
 9999/0012-lto-type-mismatch.patch                  |  20 ---
 12 files changed, 49 insertions(+), 465 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index a724494..e054415 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From 930c326fd4f16299f06610cf3ff3ee94b13130e0 Mon Sep 17 00:00:00 2001
+From 7b47d0be518ef97bb5259a5dbb70d6b3f22011f6 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/7] Gentoo: gold/ld: add support for poisoned system
@@ -33,7 +33,7 @@ Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
  gold/options.cc | 33 +++++++++++++++++++++++++++++++++
  gold/options.h  |  7 +++++++
  ld/config.in    |  3 +++
- ld/configure    | 20 ++++++++++++++++++--
+ ld/configure    | 16 ++++++++++++++++
  ld/configure.ac | 10 ++++++++++
  ld/ld.h         |  7 +++++++
  ld/ld.texi      | 18 ++++++++++++++++++
@@ -41,7 +41,7 @@ Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
  ld/ldlex.h      |  3 +++
  ld/ldmain.c     |  7 +++++++
  ld/lexsup.c     | 24 ++++++++++++++++++++++++
- 11 files changed, 150 insertions(+), 2 deletions(-)
+ 11 files changed, 148 insertions(+)
 
 diff --git a/gold/options.cc b/gold/options.cc
 index c9834b66159..bd3e948a61b 100644
@@ -106,7 +106,7 @@ index 46f658f23ea..8f9b8c177ad 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index ad0dc6a106c..d21edaddce7 100644
+index a453c7f7241..a0bc2a56013 100644
 --- a/ld/config.in
 +++ b/ld/config.in
 @@ -58,6 +58,9 @@
@@ -120,10 +120,10 @@ index ad0dc6a106c..d21edaddce7 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index 0c32b16241a..549b8d49f5e 100755
+index d2cdf256b89..0f32e98bc34 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -839,6 +839,7 @@ with_lib_path
+@@ -838,6 +838,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -131,7 +131,7 @@ index 0c32b16241a..549b8d49f5e 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1521,6 +1522,8 @@ Optional Features:
+@@ -1520,6 +1521,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -140,25 +140,7 @@ index 0c32b16241a..549b8d49f5e 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -11625,7 +11628,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11628 "configure"
-+#line 11626 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -11731,7 +11734,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11734 "configure"
-+#line 11732 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -15483,6 +15486,19 @@ fi
+@@ -15538,6 +15541,19 @@ fi
  
  
  
@@ -179,7 +161,7 @@ index 0c32b16241a..549b8d49f5e 100755
  if test "${enable_gold+set}" = set; then :
    enableval=$enable_gold; case "${enableval}" in
 diff --git a/ld/configure.ac b/ld/configure.ac
-index 77edac3258c..a74dac63038 100644
+index c3ebd3ec7e4..71790d7640f 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
 @@ -103,6 +103,16 @@ AC_SUBST(use_sysroot)
@@ -218,11 +200,11 @@ index a0f8a15c7a9..69420b6673a 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index aa8b1aa86eb..b57b0d5c9f5 100644
+index 1f56ded1041..1fa6bf7b225 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -3059,6 +3059,24 @@ creation of the metadata note, if one had been enabled by an earlier
- occurrence of the --package-metdata option.
+@@ -3070,6 +3070,24 @@ creation of the metadata note, if one had been enabled by an earlier
+ occurrence of the --package-metadata option.
  If the linker has been built with libjansson, then the JSON string
  will be validated.
 +
@@ -247,7 +229,7 @@ index aa8b1aa86eb..b57b0d5c9f5 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index df7c9cbd65e..ed15262e0bc 100644
+index 8f869c1f19e..ee9d4bccee2 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
 @@ -327,6 +327,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
@@ -310,7 +292,7 @@ index 06ac2c64fa8..5ec931a0255 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index fe8722313fe..5fd7350efc5 100644
+index 49dfc13382a..b2d1d967aa0 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
 @@ -594,6 +594,18 @@ static const struct ld_option ld_options[] =
@@ -352,5 +334,5 @@ index fe8722313fe..5fd7350efc5 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index a0bffea..d428c20 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 68b7e6f60dd42159af779d5b475b7df553655d1f Mon Sep 17 00:00:00 2001
+From 1156f7b2f690654cf5810ef1e34791d18d207a9f Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/7] Gentoo: libiberty: install PIC version of libiberty.a
@@ -30,5 +30,5 @@ index f9fbba23e2c..d37488d1bf8 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 3c08be6..d4d4571 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 3a489acb4547c320ba43858ead3586fed34c92b4 Mon Sep 17 00:00:00 2001
+From 411d52402227b6e1a9c779988f6f0fc1e17c6620 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/7] Gentoo: add --with-extra-soversion-suffix= option
@@ -34,7 +34,7 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 5c5fdefd3b8..fe26bbf4f0f 100644
+index 378c13198d6..e0fa379ca8e 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 5c5fdefd3b8..fe26bbf4f0f 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -976,6 +978,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -991,6 +993,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,7 +57,7 @@ index 5c5fdefd3b8..fe26bbf4f0f 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index 4edfedee924..70a2442957e 100644
+index 8d09f6fa4af..d397502bb4d 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
 @@ -342,6 +342,7 @@ ECHO_T = @ECHO_T@
@@ -68,7 +68,7 @@ index 4edfedee924..70a2442957e 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2435,6 +2436,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2454,6 +2455,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,7 +79,7 @@ index 4edfedee924..70a2442957e 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index dcb10317390..94a4e39d691 100755
+index f0a07ff675f..2322e9b61cf 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -695,6 +695,7 @@ WARN_CFLAGS
@@ -107,7 +107,7 @@ index dcb10317390..94a4e39d691 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12033,6 +12037,15 @@ fi
+@@ -12064,6 +12068,15 @@ fi
  
  
  
@@ -124,7 +124,7 @@ index dcb10317390..94a4e39d691 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index f044616f4d9..f22a87f8f54 100644
+index d1e7e3a4bf3..48f2d69991c 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
 @@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
@@ -142,5 +142,5 @@ index f044616f4d9..f22a87f8f54 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 59c18ef..6d820fe 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From eb585240ae3079a2cdc081a2cd96e09db95947ef Mon Sep 17 00:00:00 2001
+From 722482c5057cc921d1ab96266da29be4dc7d1354 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -9,10 +9,10 @@ Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index 7e6bf16ee6e..0491fff2883 100644
+index f89ac8a6108..2be9383b49e 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1354,7 +1354,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1340,7 +1340,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,7 +22,7 @@ index 7e6bf16ee6e..0491fff2883 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 918464069a9..7d22ee70b27 100644
+index aca303e0728..44f2865116f 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
 @@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
@@ -57,5 +57,5 @@ index 918464069a9..7d22ee70b27 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 192fa4f..ab34ef9 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From 1de1744597aa5b2e29ddedfea42cd7f99796b0ec Mon Sep 17 00:00:00 2001
+From a0e9a882db04d45bf878b746a8a30c5e51619d8b Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
@@ -7,9 +7,9 @@ Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
 ---
  libctf/Makefile.am  | 14 +++++++++++++-
  libctf/Makefile.in  |  9 ++++++++-
- libctf/configure    | 35 +++++++++++++++++++++++++++++++++--
+ libctf/configure    | 31 +++++++++++++++++++++++++++++++
  libctf/configure.ac | 10 ++++++++++
- 4 files changed, 64 insertions(+), 4 deletions(-)
+ 4 files changed, 62 insertions(+), 2 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
 index b1dbc2f6ba4..d282ceb619a 100644
@@ -80,7 +80,7 @@ index 3d2696bcc47..664d6360c47 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index a0e40f49a80..356503f689f 100755
+index 4c01c022837..07778d52be4 100755
 --- a/libctf/configure
 +++ b/libctf/configure
 @@ -645,6 +645,10 @@ BUILD_INFO_FALSE
@@ -111,25 +111,7 @@ index a0e40f49a80..356503f689f 100755
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11631,7 +11638,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11634 "configure"
-+#line 11641 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -11737,7 +11744,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11740 "configure"
-+#line 11747 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -14304,6 +14311,26 @@ else
+@@ -14335,6 +14342,26 @@ else
  fi
  
  
@@ -156,7 +138,7 @@ index a0e40f49a80..356503f689f 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -15196,6 +15223,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -15227,6 +15254,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -189,5 +171,5 @@ index 6a5eade1855..a0e65a4aeda 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 210563c..2934cd3 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 4718611dc4145a8d8de7534f150053c5accf96a1 Mon Sep 17 00:00:00 2001
+From 9bf3571ddf788d8986d1e45d54df356867bd23d9 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/7] Gentoo: XFAIL 15 broken ld.gold tests
@@ -73,5 +73,5 @@ index fb0eb12553b..b506a7f8da7 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index 8d7acd1..2331b5c 100644
--- a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,4 +1,4 @@
-From 7fbdb5f138dccdd3b65a0bd048802662c6302ea1 Mon Sep 17 00:00:00 2001
+From 51b418fda84420da6d2c0e830435ad61409daffb Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
 Subject: [PATCH 7/7] Apply a similar libiberty fix as in 7d53105d for
@@ -18,10 +18,10 @@ Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 8 insertions(+), 6 deletions(-)
 
 diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
-index 219367fb9ce..d9365260e8d 100644
+index 20c8b0022e4..96dbc8e0e94 100644
 --- a/gprofng/src/Makefile.am
 +++ b/gprofng/src/Makefile.am
-@@ -131,7 +131,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
+@@ -144,7 +144,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
  # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
  # when -nostdlib is passed to libtool.
  # See bug 29364 - libgprofng.so: needs to link against -pthread
@@ -32,7 +32,7 @@ index 219367fb9ce..d9365260e8d 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
-index b881268b0d9..0e8b707f7d7 100644
+index 47da873b80c..52a22279cf7 100644
 --- a/gprofng/src/Makefile.in
 +++ b/gprofng/src/Makefile.in
 @@ -552,7 +552,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -46,10 +46,10 @@ index b881268b0d9..0e8b707f7d7 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index 71504e10c51..cb669ed994f 100755
+index a65b0a2f95b..f412c1a6c96 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
-@@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
+@@ -12479,10 +12479,10 @@ if test "$enable_shared" = "yes"; then
    case "${host}" in
      *-*-cygwin*)
        SHARED_LDFLAGS="-no-undefined"
@@ -63,10 +63,10 @@ index 71504e10c51..cb669ed994f 100755
        ;;
    esac
 diff --git a/opcodes/configure.ac b/opcodes/configure.ac
-index 1beb72e87e0..79310916f7d 100644
+index cae2a67ff10..5cb194779e9 100644
 --- a/opcodes/configure.ac
 +++ b/opcodes/configure.ac
-@@ -193,10 +193,10 @@ if test "$enable_shared" = "yes"; then
+@@ -196,10 +196,10 @@ if test "$enable_shared" = "yes"; then
    case "${host}" in
      *-*-cygwin*)
        SHARED_LDFLAGS="-no-undefined"
@@ -80,5 +80,5 @@ index 1beb72e87e0..79310916f7d 100644
        ;;
    esac
 -- 
-2.41.0
+2.42.0
 

diff --git a/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch b/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch
deleted file mode 100644
index 7bf6a47..0000000
--- a/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch
+++ /dev/null
@@ -1,139 +0,0 @@
-From mboxrd@z Thu Jan  1 00:00:00 1970
-Return-Path: <SRS0=Su1r=DO=gentoo.org=sam@sourceware.org>
-Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
-	by sourceware.org (Postfix) with ESMTP id 3725A3858D20
-	for <binutils@sourceware.org>; Fri, 28 Jul 2023 15:20:56 +0000 (GMT)
-DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3725A3858D20
-Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org
-Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org
-From: Sam James <sam@gentoo.org>
-To: binutils@sourceware.org
-Cc: nickc@redhat.com,
-	Sam James <sam@gentoo.org>
-Subject: [PATCH] ld: Fix test failures with --enable-textrel-check=error
-Date: Fri, 28 Jul 2023 16:20:34 +0100
-Message-ID: <20230728152042.401562-1-sam@gentoo.org>
-X-Mailer: git-send-email 2.41.0
-MIME-Version: 1.0
-Content-Transfer-Encoding: 8bit
-X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
-X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org
-List-Id: <binutils.sourceware.org>
-
-Tested with the following:
-* --enable-textrel-check=error
-* --enable-warn-execstack=yes
-* --enable-warn-rwx-segments=yes
-* --enable-default-execstack=no
-in preparation for hopefully toggling these in Gentoo Hardened
-at least.
-
-This is similar in nature to 0ab7005043ee404dabfd690952efc25c399995ae
-and 340640f710e690b37c885166949595cde5f827b2.
-
-This fixes the following test failures:
-* FAIL: ld-x86-64/pr18801a
-* FAIL: ld-x86-64/pr18801b
-* FAIL: ld-x86-64/ifunc-textrel-1a
-* FAIL: ld-x86-64/ifunc-textrel-1b
-* FAIL: ld-i386/pr18801a
-* FAIL: ld-i386/pr18801b
-* FAIL: ld-i386/ifunc-textrel-1a
-* FAIL: ld-i386/ifunc-textrel-1b
-
-Signed-off-by: Sam James <sam@gentoo.org>
----
- ld/testsuite/ld-i386/ifunc-textrel-1a.d   | 2 +-
- ld/testsuite/ld-i386/ifunc-textrel-1b.d   | 2 +-
- ld/testsuite/ld-i386/pr18801a.d           | 2 +-
- ld/testsuite/ld-i386/pr18801b.d           | 2 +-
- ld/testsuite/ld-x86-64/ifunc-textrel-1a.d | 2 +-
- ld/testsuite/ld-x86-64/ifunc-textrel-1b.d | 2 +-
- ld/testsuite/ld-x86-64/pr18801a.d         | 2 +-
- ld/testsuite/ld-x86-64/pr18801b.d         | 2 +-
- 8 files changed, 8 insertions(+), 8 deletions(-)
-
-diff --git a/ld/testsuite/ld-i386/ifunc-textrel-1a.d b/ld/testsuite/ld-i386/ifunc-textrel-1a.d
-index 15f545db03d..aad77e7d230 100644
---- a/ld/testsuite/ld-i386/ifunc-textrel-1a.d
-+++ b/ld/testsuite/ld-i386/ifunc-textrel-1a.d
-@@ -1,4 +1,4 @@
- #source: ../ld-x86-64/ifunc-textrel-1.s
- #as: --32
--#ld: -m elf_i386 -pie
-+#ld: -m elf_i386 -pie -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
-diff --git a/ld/testsuite/ld-i386/ifunc-textrel-1b.d b/ld/testsuite/ld-i386/ifunc-textrel-1b.d
-index 6e4a67c48f0..bf0f2ac5df9 100644
---- a/ld/testsuite/ld-i386/ifunc-textrel-1b.d
-+++ b/ld/testsuite/ld-i386/ifunc-textrel-1b.d
-@@ -1,4 +1,4 @@
- #source: ../ld-x86-64/ifunc-textrel-1.s
- #as: --32
--#ld: -m elf_i386 -shared
-+#ld: -m elf_i386 -shared -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
-diff --git a/ld/testsuite/ld-i386/pr18801a.d b/ld/testsuite/ld-i386/pr18801a.d
-index 73cb5d17beb..b1ef145a882 100644
---- a/ld/testsuite/ld-i386/pr18801a.d
-+++ b/ld/testsuite/ld-i386/pr18801a.d
-@@ -1,4 +1,4 @@
- #source: pr18801.s
- #as: --32
--#ld: -m elf_i386 -pie
-+#ld: -m elf_i386 -pie -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
-diff --git a/ld/testsuite/ld-i386/pr18801b.d b/ld/testsuite/ld-i386/pr18801b.d
-index 0bf7fb729cb..983346ca248 100644
---- a/ld/testsuite/ld-i386/pr18801b.d
-+++ b/ld/testsuite/ld-i386/pr18801b.d
-@@ -1,4 +1,4 @@
- #source: pr18801.s
- #as: --32
--#ld: -m elf_i386 -shared
-+#ld: -m elf_i386 -shared -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
-diff --git a/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d b/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
-index 64a1e7021fd..667366091b9 100644
---- a/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
-+++ b/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
-@@ -1,4 +1,4 @@
- #source: ifunc-textrel-1.s
- #as: --64 -defsym __x86_64__=1
--#ld: -m elf_x86_64 -pie
-+#ld: -m elf_x86_64 -pie -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
-diff --git a/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d b/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
-index aeb31fdb3dc..f7b8e02a72c 100644
---- a/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
-+++ b/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
-@@ -1,4 +1,4 @@
- #source: ifunc-textrel-1.s
- #as: --64 -defsym __x86_64__=1
--#ld: -m elf_x86_64 -shared
-+#ld: -m elf_x86_64 -shared -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
-diff --git a/ld/testsuite/ld-x86-64/pr18801a.d b/ld/testsuite/ld-x86-64/pr18801a.d
-index 2b4159d3044..61f9d991185 100644
---- a/ld/testsuite/ld-x86-64/pr18801a.d
-+++ b/ld/testsuite/ld-x86-64/pr18801a.d
-@@ -1,4 +1,4 @@
- #source: pr18801.s
- #as: --64
--#ld: -melf_x86_64 -pie
-+#ld: -melf_x86_64 -pie -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
-diff --git a/ld/testsuite/ld-x86-64/pr18801b.d b/ld/testsuite/ld-x86-64/pr18801b.d
-index 34dab1aa6cb..967a339f90b 100644
---- a/ld/testsuite/ld-x86-64/pr18801b.d
-+++ b/ld/testsuite/ld-x86-64/pr18801b.d
-@@ -1,4 +1,4 @@
- #source: pr18801.s
- #as: --64
--#ld: -melf_x86_64 -shared
-+#ld: -melf_x86_64 -shared -z notext
- #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
--- 
-2.41.0
-
-

diff --git a/9999/0009-tests-objcopy-keep-debug.patch b/9999/0009-tests-objcopy-keep-debug.patch
deleted file mode 100644
index dbe2a63..0000000
--- a/9999/0009-tests-objcopy-keep-debug.patch
+++ /dev/null
@@ -1,36 +0,0 @@
-https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b99a9693430a9f04165b1b868f890b622bb1b46c
-https://sourceware.org/PR30699
-
-From b99a9693430a9f04165b1b868f890b622bb1b46c Mon Sep 17 00:00:00 2001
-From: Nick Clifton <nickc@redhat.com>
-Date: Tue, 1 Aug 2023 14:37:04 +0100
-Subject: [PATCH] Fix "--only-keep-debug for ELF relocatables" binutils test
- for compilers which add .debug_macro sections to object files.
-
-  PR 30699
-  * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.
---- a/binutils/testsuite/binutils-all/objcopy.exp
-+++ b/binutils/testsuite/binutils-all/objcopy.exp
-@@ -1028,7 +1028,11 @@ proc keep_debug_symbols_for_elf_relocatable { prog flags test } {
- 	    {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+([A-Z]*)[ \t]+[0-9]+(.*)} \
- 	    $got all name type flag rest] } {
- 	if { $type != "NOTE" && [regexp {[AG]} $flag] } {
--	    lappend non_debug_sections $name
-+	    # PR 30699: Some debug sections can be in a group, so
-+	    # exclude sections whose name includes "debug_"
-+	    if { ! [regexp {debug_} $name] } {
-+		lappend non_debug_sections $name
-+	    }
- 	}
- 	set got $rest
-     }
-@@ -1086,6 +1090,7 @@ switch [copy_setup] {
- 	untested $test5
- 	if [is_elf_format] {
- 	    untested $test6
-+	    untested $test7
- 	}
-     }
-     "3" {
--- 
-2.39.3

diff --git a/9999/0010-tests-pr23169b.patch b/9999/0010-tests-pr23169b.patch
deleted file mode 100644
index 5f75b02..0000000
--- a/9999/0010-tests-pr23169b.patch
+++ /dev/null
@@ -1,21 +0,0 @@
-https://sourceware.org/PR30698
---- a/ld/testsuite/ld-ifunc/ifunc.exp
-+++ b/ld/testsuite/ld-ifunc/ifunc.exp
-@@ -604,7 +604,7 @@ run_cc_link_tests [list \
-     ] \
-     [list \
- 	"Build libpr23169a.so" \
--	"-shared" \
-+	"-shared -Wl,-z,lazy" \
- 	"-fPIC -O2 -g" \
- 	{ pr23169a.c } \
- 	{} \
-@@ -751,7 +751,7 @@ run_ld_link_exec_tests [list \
-     ] \
-     [list \
- 	"Run pr23169b" \
--	"-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \
-+	"-pie -Wl,--no-as-needed,-z,lazy tmpdir/libpr23169a.so" \
- 	"" \
- 	{ pr23169b.c pr23169c.c } \
- 	"pr23169b" \

diff --git a/9999/0011-tests-gprofng.patch b/9999/0011-tests-gprofng.patch
deleted file mode 100644
index b95afda..0000000
--- a/9999/0011-tests-gprofng.patch
+++ /dev/null
@@ -1,164 +0,0 @@
-https://inbox.sourceware.org/binutils/20230803203339.822435-1-vladimir.mezentsev@oracle.com/
-https://sourceware.org/PR30700
-
-From mboxrd@z Thu Jan  1 00:00:00 1970
-Return-Path: <SRS0=V8/R=DU=oracle.com=vladimir.mezentsev@sourceware.org>
-Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32])
-	by sourceware.org (Postfix) with ESMTPS id 7F83B3858D38
-	for <binutils@sourceware.org>; Thu,  3 Aug 2023 20:33:54 +0000 (GMT)
-DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F83B3858D38
-Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com
-Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com
-Received: from pps.filterd (m0246632.ppops.net [127.0.0.1])
-	by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 373JJDB5001450
-	for <binutils@sourceware.org>; Thu, 3 Aug 2023 20:33:54 GMT
-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc :
- subject : date : message-id : content-transfer-encoding : content-type :
- mime-version; s=corp-2023-03-30;
- bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
- b=QXr05CxWU/hJ4gUV/hT+wrN4h0vjtTB48pepEU1M7MHli0ttn5Skv54tilAVfVKI/4cd
- 1XlcEgN90YOHmnidsmH50z0NQ4NlFvezd1MYrs2+24ay2kIbeHKrOhDQ/EVJIvNLfpt7
- pdZHkHpNkxl+glRpf9puwFHCFLe5Gqx6sSoz7C28I+5FMDB9/Rc3EQXtovTz90vIYSmO
- A1PsW5C3AJG373lrpoUVxpbcxbOsH1fygEdsB4le8DRv2Pgya2WMWz3T2zL7t2gEtFCZ
- XRbuIv+y4xYE2Q+aOJ4p5uxMbc4z3akRNes4LMwZ5U6NPRpwpOM3WFQw5x5jL6Wr6UXw zA== 
-Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20])
-	by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s4tcu2fek-1
-	(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK)
-	for <binutils@sourceware.org>; Thu, 03 Aug 2023 20:33:53 +0000
-Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1])
-	by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 373K58qp003980
-	for <binutils@sourceware.org>; Thu, 3 Aug 2023 20:33:51 GMT
-Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170])
-	by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3s856rypc5-1
-	(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK)
-	for <binutils@sourceware.org>; Thu, 03 Aug 2023 20:33:51 +0000
-ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
- b=kZLU5BLuqIUtYWeeq/p3fogSPj1DwGv5PNeVj8xjEepBlQWfzC0ad+4n0znV8bSy0v8FqBxF1sCEZFns3lhzblg1Go5psyG/nJAvlrJ7BZQFBvNmPGwAuX2cxp49Ea7lxFwwhGUmGE1BkxanejSE0fy1gnQqGZzgbiuJfYt6lUnejJOnNTmqxI34DIAaJibRkTj/gD+rLI0k7qwgZGMslll/9ZfKz+Bpzs/oQFGA9ZY9q9xkBVGgRPVIzHHC+9V2Y2vJvbOoHa6njxS0RHCmLL9gXh0kK4rJruYUesbu3T+jOy7Kno/6uqG08NdwBrUIFaPEQUoxVXVOijvXQHr5Zw==
-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
- s=arcselector9901;
- h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
- bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
- b=ejmYk7X1Z7pY0al9fEFi1vg5hSm/VA0h9l09UExzqmPiotIxFvI639eDwaNWiylM73bCWqtKbbROnZRB3rV1iDj/U2UqBWxfHxB2rGfK5CwLFcX+em4U8F9J1gNZyOAT5HcITq6SUTQ+X2qCh7l/xyQeCp1EEiDqr6Go9U5Fgm8rtFZGEC0LQ8XHKYm33P6FBXJCxpKYv69RPQFkTnZbOf1ZOdhnbOCYBslZIivjDMTsg5nqDZkNF6Hu0CxPPDafAKxoLzBiUSgf8Uf7Eu6hCs6zmDrKqeYvPfv1KqtmivuuTvsoaqks0xCCZko6Nd2GnU1sKTotkumAXfO6Zi5BOQ==
-ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
- smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com;
- dkim=pass header.d=oracle.com; arc=none
-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
- d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com;
- h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
- bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
- b=R6vVOn08a3k+gcCdUObb97WwvDSXIzBkR1ReaZ1dnUqS3ZyElhaRikL5Lyc3Q04w6vKd8PN7h2gkGnwA82Cm+hFEccHGB6blNJNEjOhvFX2Mg6XjMjwPNZ5xQ+rzTiGp2I765cpVdXH7qk0ObwPiTR2WhuXcK/dtWIdU4To6ADk=
-Received: from SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10)
- by SN7PR10MB6473.namprd10.prod.outlook.com (2603:10b6:806:2a0::18) with
- Microsoft SMTP Server (version=TLS1_2,
- cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug
- 2023 20:33:49 +0000
-Received: from SA2PR10MB4636.namprd10.prod.outlook.com
- ([fe80::a15b:c87d:10e3:5765]) by SA2PR10MB4636.namprd10.prod.outlook.com
- ([fe80::a15b:c87d:10e3:5765%7]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023
- 20:33:49 +0000
-From: vladimir.mezentsev@oracle.com
-To: binutils@sourceware.org
-Cc: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
-Subject: [PATCH] gprofng: 30700 tmpdir/gp-collect-app_F test fails
-Date: Thu,  3 Aug 2023 13:33:39 -0700
-Message-Id: <20230803203339.822435-1-vladimir.mezentsev@oracle.com>
-X-Mailer: git-send-email 2.31.1
-Content-Transfer-Encoding: 8bit
-Content-Type: text/plain
-X-ClientProxiedBy: LO6P123CA0031.GBRP123.PROD.OUTLOOK.COM
- (2603:10a6:600:2fe::11) To SA2PR10MB4636.namprd10.prod.outlook.com
- (2603:10b6:806:11e::10)
-MIME-Version: 1.0
-X-MS-PublicTrafficType: Email
-X-MS-TrafficTypeDiagnostic: SA2PR10MB4636:EE_|SN7PR10MB6473:EE_
-X-MS-Office365-Filtering-Correlation-Id: 32d2aa61-d0f0-4bf7-c7e5-08db9460f18b
-X-MS-Exchange-SenderADCheck: 1
-X-MS-Exchange-AntiSpam-Relay: 0
-X-Microsoft-Antispam: BCL:0;
-X-Microsoft-Antispam-Message-Info: 
-	FtlSjDlfJ9H/HjBEUbcrniNfavhoIJJwMeiHr/7PhA98yEcoC1q9zylXvVp7m0JPVj/gnTmS4z69ouHzfKuVWqLENJB9dmRnMv+od0/AsNTwOXFrvlmWYd5TyqhBuIjoG+WuwwuwkVmmUPiKLKfNRwxTpG1gXLDhTN6Psviul8nKELjewe5C+S5mzpY5NhVwJVp4JxnsES3HmWgBTO8OvnLss+/Sr0bLQY4nYfOpHvUtWdRvrqw9S26LGlFE8Z65FJP9STwGKbuGMBerRcHqeCIXIhyGKBwV9H9CdXLn9gOkhlXmjhNzu4x8H4oSCzfo/67bC8JNYZxemIRfHR/MttqTtpBYGCgeTcVeA1rc5U89DUdc3eCf8CSP59iJgpEKWHjEsZlEeb7bcFM1MHgnOnXuWgV3Z9m5hESVpQS3AsXUVQLKvRBYny8REC27NXsUyAZ5/SJ04aJGaSQ9AIUORqw1Kky1OGzYGQocDr4CxduZ1hac+X+8bRiSCjv74qsIe6nb3TtA1AkITgFbX8gH7UOwDwRmS5b6YEARR6BshFys26Xn/ktn/opathwyrZhN
-X-Forefront-Antispam-Report: 
-	CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4636.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(366004)(376002)(136003)(396003)(39860400002)(451199021)(66476007)(66556008)(66946007)(2616005)(316002)(4326008)(6916009)(5660300002)(107886003)(41300700001)(186003)(6506007)(8676002)(1076003)(8936002)(86362001)(9686003)(6512007)(6666004)(478600001)(6486002)(38100700002)(2906002)(36756003)(83380400001);DIR:OUT;SFP:1101;
-X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
-X-MS-Exchange-AntiSpam-MessageData-0: 
-	=?us-ascii?Q?2vVQXnKygJyQd+tHtgSFfe014vrOKhj7QtnqPMa5sAkBUzF4FJTFNTsO/pC4?=
- =?us-ascii?Q?gbe82wLSPsQ5xjf3KK41AKConilQU9fCfKMhaBEFVxH33ZS2DURmSf+gjSsJ?=
- =?us-ascii?Q?UAf/zzFrAaUhLIdqP4Tkz6g+0SiqXyTlJOodWIvT3V6JMuKqQA9D1xHbZXF0?=
- =?us-ascii?Q?0py1g7VYW0jYGcVzeCAq2lJsAHran5yjaHNDrR4SmoM4F9uNg2KNGw75ylRd?=
- =?us-ascii?Q?6jbbaGKhUrlHyB9CeTNkvz71c7NH28AuAci6B5fzwuWJkcgNbLOIx41Bq/ZX?=
- =?us-ascii?Q?Zgq4LF5BY80VuzfBGES1sjy2jFmuAsdvjYcBlnJGVcooG7qt9N6Fl/f8HUyu?=
- =?us-ascii?Q?P1rRJB4pgLWC3egtg8vS5Lh4K0KQi0XKs7ks46aVjAiGY/IfHVIzb1L2nD+G?=
- =?us-ascii?Q?RgCwy2Ubx//WcCBiTOQS5yjNxSFt4KZByQp99anrtZfJ8xiE6mghQyusbfWu?=
- =?us-ascii?Q?g1AyKl5aCp8FHXW/vb906djTCM2opRpwR1GmBxXIaMpO/v8j9/eRSQ1R/niB?=
- =?us-ascii?Q?YVZluKsc6R/xTJ2cZNeMJUcQafEYByOAik33U7t5Q9HNMWZ91jiWYsMWKVrj?=
- =?us-ascii?Q?8fibDL3u05AmgiaNeXbYjK7ISPXHOjIRThWj+ILCkdR9Wfmlv5D1svssgxeL?=
- =?us-ascii?Q?EFi3hdvD3shR2mvssmsOGWut6ZWbSEND49EhDnOS1nK6nvGRryfvIc8eAU9K?=
- =?us-ascii?Q?tEujniv2fU6TygAo+5qcav55Dd1ng19ndQFZNMle7b/w9bEA9jXH7mqLpPyd?=
- =?us-ascii?Q?nrNH8S3GeRmb9GCsePQApFOiwgv9gHDa18eSoOTBRlpltPb3HHmPCmaDZLWJ?=
- =?us-ascii?Q?dXB+SI80yXLZCQhiR6u6wHplpH+d5GjZGjFxk3aNFtCb2EhaFq6OHz/f4R34?=
- =?us-ascii?Q?FvutRMk+qKmCJ1/jop1nfn6tM6vFajL0AvOG6XVU9m24DxRAKd8AUDFVM/rO?=
- =?us-ascii?Q?FI1KBQs7oEMN0dSzxl6C4pPmhQx6JXDgZoIN1e42hk2xt4bptYUZAzjKDSxw?=
- =?us-ascii?Q?3CZ9+2dM0MjmLwaQkA9bmdGJNmK+UlBSIa2I+/iJeihktlMtgt0zQk+mUqCd?=
- =?us-ascii?Q?+/IsDmOj9RMecwrIMFUhbUPzCUlns3ZrK9TbBxcqpK5Z1tNOF3lIlcUGnOSw?=
- =?us-ascii?Q?I38m5CXSt4JAMsPpu379MT3JE+oVTrAjgPCOml29osBxGw/mPilKfqSfMJxi?=
- =?us-ascii?Q?8ZesU2hceSc6WFr+kgfbZTDNqQIQKwNPVphs2w566wP8Ae66Gu9qLp6Bk5HQ?=
- =?us-ascii?Q?cwZsfHa00oFB9vgkynYZ+mPu4dG9zV7WftOxsKEl59E/cORj3vQ24ZGMlUHG?=
- =?us-ascii?Q?LB0jLAznZgOQmkUqVmmsqxvtD1/skR3r5CGlJ/K9FN82gYMuVRUT79ppg/r9?=
- =?us-ascii?Q?e1JOgVXvnqlf4s2jYxQw3bi9QlyiFFy7MR9xMNLt7UdOV7+GdtALZXx+uOh3?=
- =?us-ascii?Q?9/9DT7Pt4hWzZuKZc8kZGCrrZRBcpK753R/j7RlyFtGC9glPHkNaV5aQBJ6+?=
- =?us-ascii?Q?Fwkt6CX12BvWW5krg2dy5ZCWkH+MBwS8/PxPbU5Z3bjW40j9fb2tTF8WUFVw?=
- =?us-ascii?Q?NOkA45fBWCbMM84rbOEjN9VJElsbua90fGNcuLYEAxRCve6My1paBT4jV+k5?=
- =?us-ascii?Q?pJraM4gq2jxgfMe/3re6+fc=3D?=
-X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1
-X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 
-	5BKKV4T41EwJkqBWXCUBtKfSc0Kqk+2boYpd3LY1KKydGovf7vMEW8cZdK7DpnPReGtLMTe22G8WEdn+eueR59691BC3vrpoNVoYEMczhSi6Rf9TqO5yp8jgE/YufRIst16yC1oF14s88TE0rlftBH2NAVnB/7vKVBrmDa6SSwJyRcGyF1JIB8TKCuUj2m2a/aO9nNBSNZgl1xOBWfPKt3yBwe5hvrsmAQGm8H5Ms2bT4yhwxhA4M6f9bfj2BxBSHvDuCoJx4z7WCMycJJtY37+wT070rAkDGW6u7BTQfSdoup1NNo22gp74EJGxcn0jBDf6A0Oa6mVTe8SBy8SHFkhTwShvYYuj3R6PqqcUV8d0fvtXsNWbCydtFkZSwOugpE1y3RNtvvgtVHLdRSziiPl3CsW0cQEA0aQNdDec9xQV9uYmnQAQvHYQdMB8tGyV0viNsuIae7PaDF4fl0RJsz2Cj2EeuVwQP7txJ7YoU/qLVZLeVL9kk1F7ZCFD4L7tTjxH4/DN/AUWwpMq1U6yAiL6/ByELdB+ttlOTnbtHMN7HuNlJUosjFm59yldZZgz0nM8aiK8uZbcObBcmaHok0j11xKEKl/z3BjVuqKqtOfZs4HmKOCdLSr1cmf1JcnvvCFhjW5XCZySIqechbKUidMlivSQcIPvibERILfG3c+uU26pPEAZLwos3BWiBXFdBaN+nn2bjbrD85QjpnNUg7TF5YJOEXnodgzSvwrp9vD1SiT8sx3g4YD7kKy0E7YO
-X-OriginatorOrg: oracle.com
-X-MS-Exchange-CrossTenant-Network-Message-Id: 32d2aa61-d0f0-4bf7-c7e5-08db9460f18b
-X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4636.namprd10.prod.outlook.com
-X-MS-Exchange-CrossTenant-AuthAs: Internal
-X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 20:33:49.4380
- (UTC)
-X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
-X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b
-X-MS-Exchange-CrossTenant-MailboxType: HOSTED
-X-MS-Exchange-CrossTenant-UserPrincipalName: mt6TZSKYv+lnLPXlQj7hP3NQSiJDZFEbIztaEFvS4u/Ey+jTQS21+Nywl1vdY7TPbl8qS+F2xjqerIF6YU3aJrJY+tEZOUTu7AfUUD4pUl8=
-X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6473
-X-Proofpoint-Virus-Version: vendor=baseguard
- engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26
- definitions=2023-08-03_22,2023-08-03_01,2023-05-22_02
-X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 spamscore=0
- adultscore=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999
- classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000
- definitions=main-2308030184
-X-Proofpoint-GUID: Ai1oZyaQBQimnED3Xzjh2Aq6NHTga79T
-X-Proofpoint-ORIG-GUID: Ai1oZyaQBQimnED3Xzjh2Aq6NHTga79T
-X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
-X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org
-List-Id: <binutils.sourceware.org>
-
-From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
-
-gprofng/ChangeLog
-2023-08-03  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
-
-	PR gprofng/30700
-	* testsuite/gprofng.display/gp-collect-app_F.exp: Fix -name argument
-	for sub-experiment filtering.
---- a/gprofng/testsuite/gprofng.display/gp-collect-app_F.exp
-+++ b/gprofng/testsuite/gprofng.display/gp-collect-app_F.exp
-@@ -46,11 +46,11 @@ proc run_gp_collect_app { subExpCnt F_opt } {
-     return -code break
-   }
- 
--  set output [run_native_host_cmd "find $tdir -name '*x1.er' | wc -l"]
-+  set output [run_native_host_cmd "find $tdir -name '*_x?.er' | wc -l"]
-   set subExp [lindex $output 1]
-   if { $subExp != $subExpCnt } then {
-     set out [lindex $output 1]
--    send_log "Test failed for -F $F_opt. subExp=$subExp. Shold be $subExpCnt\n"
-+    send_log "Test failed for -F $F_opt. subExp=$subExp. Should be $subExpCnt\n"
-     fail $tdir
-     return -code break
-   }
--- 
-2.31.1

diff --git a/9999/0012-lto-type-mismatch.patch b/9999/0012-lto-type-mismatch.patch
deleted file mode 100644
index dbb6958..0000000
--- a/9999/0012-lto-type-mismatch.patch
+++ /dev/null
@@ -1,20 +0,0 @@
-https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e34acfce343d53290e72c317213a28327bc52fb0
-
-From e34acfce343d53290e72c317213a28327bc52fb0 Mon Sep 17 00:00:00 2001
-From: Tom de Vries <tdevries@suse.de>
-Date: Thu, 3 Aug 2023 09:48:39 +0100
-Subject: [PATCH]  Fix Wlto-type-mismatch in opcodes/ft32-dis.c
-
---- a/opcodes/ft32-dis.c
-+++ b/opcodes/ft32-dis.c
-@@ -27,7 +27,7 @@
- #include "opcode/ft32.h"
- #include "disassemble.h"
- 
--extern const ft32_opc_info_t ft32_opc_info[128];
-+extern const ft32_opc_info_t ft32_opc_info[];
- 
- static fprintf_ftype fpr;
- static void *stream;
--- 
-2.39.3


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-10-27  0:44 Sam James
  0 siblings, 0 replies; 102+ messages in thread
From: Sam James @ 2023-10-27  0:44 UTC (permalink / raw
  To: gentoo-commits

commit:     b7d242c5f8087d074f9caceb71d463cb6be264b3
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  7 23:28:19 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Aug  7 23:28:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=b7d242c5

9999: Add various test suite patches, as well as an LTO warning fix

All of these are upstream and will be in 2.42.

Signed-off-by: Sam James <sam <AT> gentoo.org>

 9999/0009-tests-objcopy-keep-debug.patch |  36 +++++++
 9999/0010-tests-pr23169b.patch           |  21 ++++
 9999/0011-tests-gprofng.patch            | 164 +++++++++++++++++++++++++++++++
 9999/0012-lto-type-mismatch.patch        |  20 ++++
 4 files changed, 241 insertions(+)

diff --git a/9999/0009-tests-objcopy-keep-debug.patch b/9999/0009-tests-objcopy-keep-debug.patch
new file mode 100644
index 0000000..dbe2a63
--- /dev/null
+++ b/9999/0009-tests-objcopy-keep-debug.patch
@@ -0,0 +1,36 @@
+https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=b99a9693430a9f04165b1b868f890b622bb1b46c
+https://sourceware.org/PR30699
+
+From b99a9693430a9f04165b1b868f890b622bb1b46c Mon Sep 17 00:00:00 2001
+From: Nick Clifton <nickc@redhat.com>
+Date: Tue, 1 Aug 2023 14:37:04 +0100
+Subject: [PATCH] Fix "--only-keep-debug for ELF relocatables" binutils test
+ for compilers which add .debug_macro sections to object files.
+
+  PR 30699
+  * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.
+--- a/binutils/testsuite/binutils-all/objcopy.exp
++++ b/binutils/testsuite/binutils-all/objcopy.exp
+@@ -1028,7 +1028,11 @@ proc keep_debug_symbols_for_elf_relocatable { prog flags test } {
+ 	    {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+([A-Z]*)[ \t]+[0-9]+(.*)} \
+ 	    $got all name type flag rest] } {
+ 	if { $type != "NOTE" && [regexp {[AG]} $flag] } {
+-	    lappend non_debug_sections $name
++	    # PR 30699: Some debug sections can be in a group, so
++	    # exclude sections whose name includes "debug_"
++	    if { ! [regexp {debug_} $name] } {
++		lappend non_debug_sections $name
++	    }
+ 	}
+ 	set got $rest
+     }
+@@ -1086,6 +1090,7 @@ switch [copy_setup] {
+ 	untested $test5
+ 	if [is_elf_format] {
+ 	    untested $test6
++	    untested $test7
+ 	}
+     }
+     "3" {
+-- 
+2.39.3

diff --git a/9999/0010-tests-pr23169b.patch b/9999/0010-tests-pr23169b.patch
new file mode 100644
index 0000000..5f75b02
--- /dev/null
+++ b/9999/0010-tests-pr23169b.patch
@@ -0,0 +1,21 @@
+https://sourceware.org/PR30698
+--- a/ld/testsuite/ld-ifunc/ifunc.exp
++++ b/ld/testsuite/ld-ifunc/ifunc.exp
+@@ -604,7 +604,7 @@ run_cc_link_tests [list \
+     ] \
+     [list \
+ 	"Build libpr23169a.so" \
+-	"-shared" \
++	"-shared -Wl,-z,lazy" \
+ 	"-fPIC -O2 -g" \
+ 	{ pr23169a.c } \
+ 	{} \
+@@ -751,7 +751,7 @@ run_ld_link_exec_tests [list \
+     ] \
+     [list \
+ 	"Run pr23169b" \
+-	"-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \
++	"-pie -Wl,--no-as-needed,-z,lazy tmpdir/libpr23169a.so" \
+ 	"" \
+ 	{ pr23169b.c pr23169c.c } \
+ 	"pr23169b" \

diff --git a/9999/0011-tests-gprofng.patch b/9999/0011-tests-gprofng.patch
new file mode 100644
index 0000000..b95afda
--- /dev/null
+++ b/9999/0011-tests-gprofng.patch
@@ -0,0 +1,164 @@
+https://inbox.sourceware.org/binutils/20230803203339.822435-1-vladimir.mezentsev@oracle.com/
+https://sourceware.org/PR30700
+
+From mboxrd@z Thu Jan  1 00:00:00 1970
+Return-Path: <SRS0=V8/R=DU=oracle.com=vladimir.mezentsev@sourceware.org>
+Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32])
+	by sourceware.org (Postfix) with ESMTPS id 7F83B3858D38
+	for <binutils@sourceware.org>; Thu,  3 Aug 2023 20:33:54 +0000 (GMT)
+DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F83B3858D38
+Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com
+Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com
+Received: from pps.filterd (m0246632.ppops.net [127.0.0.1])
+	by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 373JJDB5001450
+	for <binutils@sourceware.org>; Thu, 3 Aug 2023 20:33:54 GMT
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc :
+ subject : date : message-id : content-transfer-encoding : content-type :
+ mime-version; s=corp-2023-03-30;
+ bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
+ b=QXr05CxWU/hJ4gUV/hT+wrN4h0vjtTB48pepEU1M7MHli0ttn5Skv54tilAVfVKI/4cd
+ 1XlcEgN90YOHmnidsmH50z0NQ4NlFvezd1MYrs2+24ay2kIbeHKrOhDQ/EVJIvNLfpt7
+ pdZHkHpNkxl+glRpf9puwFHCFLe5Gqx6sSoz7C28I+5FMDB9/Rc3EQXtovTz90vIYSmO
+ A1PsW5C3AJG373lrpoUVxpbcxbOsH1fygEdsB4le8DRv2Pgya2WMWz3T2zL7t2gEtFCZ
+ XRbuIv+y4xYE2Q+aOJ4p5uxMbc4z3akRNes4LMwZ5U6NPRpwpOM3WFQw5x5jL6Wr6UXw zA== 
+Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20])
+	by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s4tcu2fek-1
+	(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK)
+	for <binutils@sourceware.org>; Thu, 03 Aug 2023 20:33:53 +0000
+Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1])
+	by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 373K58qp003980
+	for <binutils@sourceware.org>; Thu, 3 Aug 2023 20:33:51 GMT
+Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170])
+	by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3s856rypc5-1
+	(version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK)
+	for <binutils@sourceware.org>; Thu, 03 Aug 2023 20:33:51 +0000
+ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
+ b=kZLU5BLuqIUtYWeeq/p3fogSPj1DwGv5PNeVj8xjEepBlQWfzC0ad+4n0znV8bSy0v8FqBxF1sCEZFns3lhzblg1Go5psyG/nJAvlrJ7BZQFBvNmPGwAuX2cxp49Ea7lxFwwhGUmGE1BkxanejSE0fy1gnQqGZzgbiuJfYt6lUnejJOnNTmqxI34DIAaJibRkTj/gD+rLI0k7qwgZGMslll/9ZfKz+Bpzs/oQFGA9ZY9q9xkBVGgRPVIzHHC+9V2Y2vJvbOoHa6njxS0RHCmLL9gXh0kK4rJruYUesbu3T+jOy7Kno/6uqG08NdwBrUIFaPEQUoxVXVOijvXQHr5Zw==
+ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
+ s=arcselector9901;
+ h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
+ bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
+ b=ejmYk7X1Z7pY0al9fEFi1vg5hSm/VA0h9l09UExzqmPiotIxFvI639eDwaNWiylM73bCWqtKbbROnZRB3rV1iDj/U2UqBWxfHxB2rGfK5CwLFcX+em4U8F9J1gNZyOAT5HcITq6SUTQ+X2qCh7l/xyQeCp1EEiDqr6Go9U5Fgm8rtFZGEC0LQ8XHKYm33P6FBXJCxpKYv69RPQFkTnZbOf1ZOdhnbOCYBslZIivjDMTsg5nqDZkNF6Hu0CxPPDafAKxoLzBiUSgf8Uf7Eu6hCs6zmDrKqeYvPfv1KqtmivuuTvsoaqks0xCCZko6Nd2GnU1sKTotkumAXfO6Zi5BOQ==
+ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
+ smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com;
+ dkim=pass header.d=oracle.com; arc=none
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
+ d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com;
+ h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
+ bh=aBWH9303Y8NcOBnrwOK3V46ZpHc2uMbEHRXIxE2Mg8U=;
+ b=R6vVOn08a3k+gcCdUObb97WwvDSXIzBkR1ReaZ1dnUqS3ZyElhaRikL5Lyc3Q04w6vKd8PN7h2gkGnwA82Cm+hFEccHGB6blNJNEjOhvFX2Mg6XjMjwPNZ5xQ+rzTiGp2I765cpVdXH7qk0ObwPiTR2WhuXcK/dtWIdU4To6ADk=
+Received: from SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10)
+ by SN7PR10MB6473.namprd10.prod.outlook.com (2603:10b6:806:2a0::18) with
+ Microsoft SMTP Server (version=TLS1_2,
+ cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug
+ 2023 20:33:49 +0000
+Received: from SA2PR10MB4636.namprd10.prod.outlook.com
+ ([fe80::a15b:c87d:10e3:5765]) by SA2PR10MB4636.namprd10.prod.outlook.com
+ ([fe80::a15b:c87d:10e3:5765%7]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023
+ 20:33:49 +0000
+From: vladimir.mezentsev@oracle.com
+To: binutils@sourceware.org
+Cc: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
+Subject: [PATCH] gprofng: 30700 tmpdir/gp-collect-app_F test fails
+Date: Thu,  3 Aug 2023 13:33:39 -0700
+Message-Id: <20230803203339.822435-1-vladimir.mezentsev@oracle.com>
+X-Mailer: git-send-email 2.31.1
+Content-Transfer-Encoding: 8bit
+Content-Type: text/plain
+X-ClientProxiedBy: LO6P123CA0031.GBRP123.PROD.OUTLOOK.COM
+ (2603:10a6:600:2fe::11) To SA2PR10MB4636.namprd10.prod.outlook.com
+ (2603:10b6:806:11e::10)
+MIME-Version: 1.0
+X-MS-PublicTrafficType: Email
+X-MS-TrafficTypeDiagnostic: SA2PR10MB4636:EE_|SN7PR10MB6473:EE_
+X-MS-Office365-Filtering-Correlation-Id: 32d2aa61-d0f0-4bf7-c7e5-08db9460f18b
+X-MS-Exchange-SenderADCheck: 1
+X-MS-Exchange-AntiSpam-Relay: 0
+X-Microsoft-Antispam: BCL:0;
+X-Microsoft-Antispam-Message-Info: 
+	FtlSjDlfJ9H/HjBEUbcrniNfavhoIJJwMeiHr/7PhA98yEcoC1q9zylXvVp7m0JPVj/gnTmS4z69ouHzfKuVWqLENJB9dmRnMv+od0/AsNTwOXFrvlmWYd5TyqhBuIjoG+WuwwuwkVmmUPiKLKfNRwxTpG1gXLDhTN6Psviul8nKELjewe5C+S5mzpY5NhVwJVp4JxnsES3HmWgBTO8OvnLss+/Sr0bLQY4nYfOpHvUtWdRvrqw9S26LGlFE8Z65FJP9STwGKbuGMBerRcHqeCIXIhyGKBwV9H9CdXLn9gOkhlXmjhNzu4x8H4oSCzfo/67bC8JNYZxemIRfHR/MttqTtpBYGCgeTcVeA1rc5U89DUdc3eCf8CSP59iJgpEKWHjEsZlEeb7bcFM1MHgnOnXuWgV3Z9m5hESVpQS3AsXUVQLKvRBYny8REC27NXsUyAZ5/SJ04aJGaSQ9AIUORqw1Kky1OGzYGQocDr4CxduZ1hac+X+8bRiSCjv74qsIe6nb3TtA1AkITgFbX8gH7UOwDwRmS5b6YEARR6BshFys26Xn/ktn/opathwyrZhN
+X-Forefront-Antispam-Report: 
+	CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4636.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(366004)(376002)(136003)(396003)(39860400002)(451199021)(66476007)(66556008)(66946007)(2616005)(316002)(4326008)(6916009)(5660300002)(107886003)(41300700001)(186003)(6506007)(8676002)(1076003)(8936002)(86362001)(9686003)(6512007)(6666004)(478600001)(6486002)(38100700002)(2906002)(36756003)(83380400001);DIR:OUT;SFP:1101;
+X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
+X-MS-Exchange-AntiSpam-MessageData-0: 
+	=?us-ascii?Q?2vVQXnKygJyQd+tHtgSFfe014vrOKhj7QtnqPMa5sAkBUzF4FJTFNTsO/pC4?=
+ =?us-ascii?Q?gbe82wLSPsQ5xjf3KK41AKConilQU9fCfKMhaBEFVxH33ZS2DURmSf+gjSsJ?=
+ =?us-ascii?Q?UAf/zzFrAaUhLIdqP4Tkz6g+0SiqXyTlJOodWIvT3V6JMuKqQA9D1xHbZXF0?=
+ =?us-ascii?Q?0py1g7VYW0jYGcVzeCAq2lJsAHran5yjaHNDrR4SmoM4F9uNg2KNGw75ylRd?=
+ =?us-ascii?Q?6jbbaGKhUrlHyB9CeTNkvz71c7NH28AuAci6B5fzwuWJkcgNbLOIx41Bq/ZX?=
+ =?us-ascii?Q?Zgq4LF5BY80VuzfBGES1sjy2jFmuAsdvjYcBlnJGVcooG7qt9N6Fl/f8HUyu?=
+ =?us-ascii?Q?P1rRJB4pgLWC3egtg8vS5Lh4K0KQi0XKs7ks46aVjAiGY/IfHVIzb1L2nD+G?=
+ =?us-ascii?Q?RgCwy2Ubx//WcCBiTOQS5yjNxSFt4KZByQp99anrtZfJ8xiE6mghQyusbfWu?=
+ =?us-ascii?Q?g1AyKl5aCp8FHXW/vb906djTCM2opRpwR1GmBxXIaMpO/v8j9/eRSQ1R/niB?=
+ =?us-ascii?Q?YVZluKsc6R/xTJ2cZNeMJUcQafEYByOAik33U7t5Q9HNMWZ91jiWYsMWKVrj?=
+ =?us-ascii?Q?8fibDL3u05AmgiaNeXbYjK7ISPXHOjIRThWj+ILCkdR9Wfmlv5D1svssgxeL?=
+ =?us-ascii?Q?EFi3hdvD3shR2mvssmsOGWut6ZWbSEND49EhDnOS1nK6nvGRryfvIc8eAU9K?=
+ =?us-ascii?Q?tEujniv2fU6TygAo+5qcav55Dd1ng19ndQFZNMle7b/w9bEA9jXH7mqLpPyd?=
+ =?us-ascii?Q?nrNH8S3GeRmb9GCsePQApFOiwgv9gHDa18eSoOTBRlpltPb3HHmPCmaDZLWJ?=
+ =?us-ascii?Q?dXB+SI80yXLZCQhiR6u6wHplpH+d5GjZGjFxk3aNFtCb2EhaFq6OHz/f4R34?=
+ =?us-ascii?Q?FvutRMk+qKmCJ1/jop1nfn6tM6vFajL0AvOG6XVU9m24DxRAKd8AUDFVM/rO?=
+ =?us-ascii?Q?FI1KBQs7oEMN0dSzxl6C4pPmhQx6JXDgZoIN1e42hk2xt4bptYUZAzjKDSxw?=
+ =?us-ascii?Q?3CZ9+2dM0MjmLwaQkA9bmdGJNmK+UlBSIa2I+/iJeihktlMtgt0zQk+mUqCd?=
+ =?us-ascii?Q?+/IsDmOj9RMecwrIMFUhbUPzCUlns3ZrK9TbBxcqpK5Z1tNOF3lIlcUGnOSw?=
+ =?us-ascii?Q?I38m5CXSt4JAMsPpu379MT3JE+oVTrAjgPCOml29osBxGw/mPilKfqSfMJxi?=
+ =?us-ascii?Q?8ZesU2hceSc6WFr+kgfbZTDNqQIQKwNPVphs2w566wP8Ae66Gu9qLp6Bk5HQ?=
+ =?us-ascii?Q?cwZsfHa00oFB9vgkynYZ+mPu4dG9zV7WftOxsKEl59E/cORj3vQ24ZGMlUHG?=
+ =?us-ascii?Q?LB0jLAznZgOQmkUqVmmsqxvtD1/skR3r5CGlJ/K9FN82gYMuVRUT79ppg/r9?=
+ =?us-ascii?Q?e1JOgVXvnqlf4s2jYxQw3bi9QlyiFFy7MR9xMNLt7UdOV7+GdtALZXx+uOh3?=
+ =?us-ascii?Q?9/9DT7Pt4hWzZuKZc8kZGCrrZRBcpK753R/j7RlyFtGC9glPHkNaV5aQBJ6+?=
+ =?us-ascii?Q?Fwkt6CX12BvWW5krg2dy5ZCWkH+MBwS8/PxPbU5Z3bjW40j9fb2tTF8WUFVw?=
+ =?us-ascii?Q?NOkA45fBWCbMM84rbOEjN9VJElsbua90fGNcuLYEAxRCve6My1paBT4jV+k5?=
+ =?us-ascii?Q?pJraM4gq2jxgfMe/3re6+fc=3D?=
+X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1
+X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 
+	5BKKV4T41EwJkqBWXCUBtKfSc0Kqk+2boYpd3LY1KKydGovf7vMEW8cZdK7DpnPReGtLMTe22G8WEdn+eueR59691BC3vrpoNVoYEMczhSi6Rf9TqO5yp8jgE/YufRIst16yC1oF14s88TE0rlftBH2NAVnB/7vKVBrmDa6SSwJyRcGyF1JIB8TKCuUj2m2a/aO9nNBSNZgl1xOBWfPKt3yBwe5hvrsmAQGm8H5Ms2bT4yhwxhA4M6f9bfj2BxBSHvDuCoJx4z7WCMycJJtY37+wT070rAkDGW6u7BTQfSdoup1NNo22gp74EJGxcn0jBDf6A0Oa6mVTe8SBy8SHFkhTwShvYYuj3R6PqqcUV8d0fvtXsNWbCydtFkZSwOugpE1y3RNtvvgtVHLdRSziiPl3CsW0cQEA0aQNdDec9xQV9uYmnQAQvHYQdMB8tGyV0viNsuIae7PaDF4fl0RJsz2Cj2EeuVwQP7txJ7YoU/qLVZLeVL9kk1F7ZCFD4L7tTjxH4/DN/AUWwpMq1U6yAiL6/ByELdB+ttlOTnbtHMN7HuNlJUosjFm59yldZZgz0nM8aiK8uZbcObBcmaHok0j11xKEKl/z3BjVuqKqtOfZs4HmKOCdLSr1cmf1JcnvvCFhjW5XCZySIqechbKUidMlivSQcIPvibERILfG3c+uU26pPEAZLwos3BWiBXFdBaN+nn2bjbrD85QjpnNUg7TF5YJOEXnodgzSvwrp9vD1SiT8sx3g4YD7kKy0E7YO
+X-OriginatorOrg: oracle.com
+X-MS-Exchange-CrossTenant-Network-Message-Id: 32d2aa61-d0f0-4bf7-c7e5-08db9460f18b
+X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4636.namprd10.prod.outlook.com
+X-MS-Exchange-CrossTenant-AuthAs: Internal
+X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 20:33:49.4380
+ (UTC)
+X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
+X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b
+X-MS-Exchange-CrossTenant-MailboxType: HOSTED
+X-MS-Exchange-CrossTenant-UserPrincipalName: mt6TZSKYv+lnLPXlQj7hP3NQSiJDZFEbIztaEFvS4u/Ey+jTQS21+Nywl1vdY7TPbl8qS+F2xjqerIF6YU3aJrJY+tEZOUTu7AfUUD4pUl8=
+X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6473
+X-Proofpoint-Virus-Version: vendor=baseguard
+ engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26
+ definitions=2023-08-03_22,2023-08-03_01,2023-05-22_02
+X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 spamscore=0
+ adultscore=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=999
+ classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000
+ definitions=main-2308030184
+X-Proofpoint-GUID: Ai1oZyaQBQimnED3Xzjh2Aq6NHTga79T
+X-Proofpoint-ORIG-GUID: Ai1oZyaQBQimnED3Xzjh2Aq6NHTga79T
+X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
+X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org
+List-Id: <binutils.sourceware.org>
+
+From: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
+
+gprofng/ChangeLog
+2023-08-03  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>
+
+	PR gprofng/30700
+	* testsuite/gprofng.display/gp-collect-app_F.exp: Fix -name argument
+	for sub-experiment filtering.
+--- a/gprofng/testsuite/gprofng.display/gp-collect-app_F.exp
++++ b/gprofng/testsuite/gprofng.display/gp-collect-app_F.exp
+@@ -46,11 +46,11 @@ proc run_gp_collect_app { subExpCnt F_opt } {
+     return -code break
+   }
+ 
+-  set output [run_native_host_cmd "find $tdir -name '*x1.er' | wc -l"]
++  set output [run_native_host_cmd "find $tdir -name '*_x?.er' | wc -l"]
+   set subExp [lindex $output 1]
+   if { $subExp != $subExpCnt } then {
+     set out [lindex $output 1]
+-    send_log "Test failed for -F $F_opt. subExp=$subExp. Shold be $subExpCnt\n"
++    send_log "Test failed for -F $F_opt. subExp=$subExp. Should be $subExpCnt\n"
+     fail $tdir
+     return -code break
+   }
+-- 
+2.31.1

diff --git a/9999/0012-lto-type-mismatch.patch b/9999/0012-lto-type-mismatch.patch
new file mode 100644
index 0000000..dbb6958
--- /dev/null
+++ b/9999/0012-lto-type-mismatch.patch
@@ -0,0 +1,20 @@
+https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e34acfce343d53290e72c317213a28327bc52fb0
+
+From e34acfce343d53290e72c317213a28327bc52fb0 Mon Sep 17 00:00:00 2001
+From: Tom de Vries <tdevries@suse.de>
+Date: Thu, 3 Aug 2023 09:48:39 +0100
+Subject: [PATCH]  Fix Wlto-type-mismatch in opcodes/ft32-dis.c
+
+--- a/opcodes/ft32-dis.c
++++ b/opcodes/ft32-dis.c
+@@ -27,7 +27,7 @@
+ #include "opcode/ft32.h"
+ #include "disassemble.h"
+ 
+-extern const ft32_opc_info_t ft32_opc_info[128];
++extern const ft32_opc_info_t ft32_opc_info[];
+ 
+ static fprintf_ftype fpr;
+ static void *stream;
+-- 
+2.39.3


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-07-30 14:49 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-07-30 14:49 UTC (permalink / raw
  To: gentoo-commits

commit:     60851e7be32d7d3014de98b85bd5b58b1ad6fdd3
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 30 14:49:36 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sun Jul 30 14:49:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=60851e7b

Add Sam's textrel patch

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-failures-with-enable-textrel-check-error.patch | 139 +++++++++++++++++++++
 1 file changed, 139 insertions(+)

diff --git a/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch b/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch
new file mode 100644
index 0000000..7bf6a47
--- /dev/null
+++ b/9999/0008-ld-Fix-test-failures-with-enable-textrel-check-error.patch
@@ -0,0 +1,139 @@
+From mboxrd@z Thu Jan  1 00:00:00 1970
+Return-Path: <SRS0=Su1r=DO=gentoo.org=sam@sourceware.org>
+Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
+	by sourceware.org (Postfix) with ESMTP id 3725A3858D20
+	for <binutils@sourceware.org>; Fri, 28 Jul 2023 15:20:56 +0000 (GMT)
+DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3725A3858D20
+Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org
+Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org
+From: Sam James <sam@gentoo.org>
+To: binutils@sourceware.org
+Cc: nickc@redhat.com,
+	Sam James <sam@gentoo.org>
+Subject: [PATCH] ld: Fix test failures with --enable-textrel-check=error
+Date: Fri, 28 Jul 2023 16:20:34 +0100
+Message-ID: <20230728152042.401562-1-sam@gentoo.org>
+X-Mailer: git-send-email 2.41.0
+MIME-Version: 1.0
+Content-Transfer-Encoding: 8bit
+X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
+X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org
+List-Id: <binutils.sourceware.org>
+
+Tested with the following:
+* --enable-textrel-check=error
+* --enable-warn-execstack=yes
+* --enable-warn-rwx-segments=yes
+* --enable-default-execstack=no
+in preparation for hopefully toggling these in Gentoo Hardened
+at least.
+
+This is similar in nature to 0ab7005043ee404dabfd690952efc25c399995ae
+and 340640f710e690b37c885166949595cde5f827b2.
+
+This fixes the following test failures:
+* FAIL: ld-x86-64/pr18801a
+* FAIL: ld-x86-64/pr18801b
+* FAIL: ld-x86-64/ifunc-textrel-1a
+* FAIL: ld-x86-64/ifunc-textrel-1b
+* FAIL: ld-i386/pr18801a
+* FAIL: ld-i386/pr18801b
+* FAIL: ld-i386/ifunc-textrel-1a
+* FAIL: ld-i386/ifunc-textrel-1b
+
+Signed-off-by: Sam James <sam@gentoo.org>
+---
+ ld/testsuite/ld-i386/ifunc-textrel-1a.d   | 2 +-
+ ld/testsuite/ld-i386/ifunc-textrel-1b.d   | 2 +-
+ ld/testsuite/ld-i386/pr18801a.d           | 2 +-
+ ld/testsuite/ld-i386/pr18801b.d           | 2 +-
+ ld/testsuite/ld-x86-64/ifunc-textrel-1a.d | 2 +-
+ ld/testsuite/ld-x86-64/ifunc-textrel-1b.d | 2 +-
+ ld/testsuite/ld-x86-64/pr18801a.d         | 2 +-
+ ld/testsuite/ld-x86-64/pr18801b.d         | 2 +-
+ 8 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/ld/testsuite/ld-i386/ifunc-textrel-1a.d b/ld/testsuite/ld-i386/ifunc-textrel-1a.d
+index 15f545db03d..aad77e7d230 100644
+--- a/ld/testsuite/ld-i386/ifunc-textrel-1a.d
++++ b/ld/testsuite/ld-i386/ifunc-textrel-1a.d
+@@ -1,4 +1,4 @@
+ #source: ../ld-x86-64/ifunc-textrel-1.s
+ #as: --32
+-#ld: -m elf_i386 -pie
++#ld: -m elf_i386 -pie -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
+diff --git a/ld/testsuite/ld-i386/ifunc-textrel-1b.d b/ld/testsuite/ld-i386/ifunc-textrel-1b.d
+index 6e4a67c48f0..bf0f2ac5df9 100644
+--- a/ld/testsuite/ld-i386/ifunc-textrel-1b.d
++++ b/ld/testsuite/ld-i386/ifunc-textrel-1b.d
+@@ -1,4 +1,4 @@
+ #source: ../ld-x86-64/ifunc-textrel-1.s
+ #as: --32
+-#ld: -m elf_i386 -shared
++#ld: -m elf_i386 -shared -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
+diff --git a/ld/testsuite/ld-i386/pr18801a.d b/ld/testsuite/ld-i386/pr18801a.d
+index 73cb5d17beb..b1ef145a882 100644
+--- a/ld/testsuite/ld-i386/pr18801a.d
++++ b/ld/testsuite/ld-i386/pr18801a.d
+@@ -1,4 +1,4 @@
+ #source: pr18801.s
+ #as: --32
+-#ld: -m elf_i386 -pie
++#ld: -m elf_i386 -pie -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
+diff --git a/ld/testsuite/ld-i386/pr18801b.d b/ld/testsuite/ld-i386/pr18801b.d
+index 0bf7fb729cb..983346ca248 100644
+--- a/ld/testsuite/ld-i386/pr18801b.d
++++ b/ld/testsuite/ld-i386/pr18801b.d
+@@ -1,4 +1,4 @@
+ #source: pr18801.s
+ #as: --32
+-#ld: -m elf_i386 -shared
++#ld: -m elf_i386 -shared -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
+diff --git a/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d b/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
+index 64a1e7021fd..667366091b9 100644
+--- a/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
++++ b/ld/testsuite/ld-x86-64/ifunc-textrel-1a.d
+@@ -1,4 +1,4 @@
+ #source: ifunc-textrel-1.s
+ #as: --64 -defsym __x86_64__=1
+-#ld: -m elf_x86_64 -pie
++#ld: -m elf_x86_64 -pie -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
+diff --git a/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d b/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
+index aeb31fdb3dc..f7b8e02a72c 100644
+--- a/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
++++ b/ld/testsuite/ld-x86-64/ifunc-textrel-1b.d
+@@ -1,4 +1,4 @@
+ #source: ifunc-textrel-1.s
+ #as: --64 -defsym __x86_64__=1
+-#ld: -m elf_x86_64 -shared
++#ld: -m elf_x86_64 -shared -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
+diff --git a/ld/testsuite/ld-x86-64/pr18801a.d b/ld/testsuite/ld-x86-64/pr18801a.d
+index 2b4159d3044..61f9d991185 100644
+--- a/ld/testsuite/ld-x86-64/pr18801a.d
++++ b/ld/testsuite/ld-x86-64/pr18801a.d
+@@ -1,4 +1,4 @@
+ #source: pr18801.s
+ #as: --64
+-#ld: -melf_x86_64 -pie
++#ld: -melf_x86_64 -pie -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
+diff --git a/ld/testsuite/ld-x86-64/pr18801b.d b/ld/testsuite/ld-x86-64/pr18801b.d
+index 34dab1aa6cb..967a339f90b 100644
+--- a/ld/testsuite/ld-x86-64/pr18801b.d
++++ b/ld/testsuite/ld-x86-64/pr18801b.d
+@@ -1,4 +1,4 @@
+ #source: pr18801.s
+ #as: --64
+-#ld: -melf_x86_64 -shared
++#ld: -melf_x86_64 -shared -z notext
+ #warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIC
+-- 
+2.41.0
+
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-07-28 16:23 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-07-28 16:23 UTC (permalink / raw
  To: gentoo-commits

commit:     8a47acd3d764114d0fa52bf76e079d6afc0e0c45
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 28 16:23:07 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Fri Jul 28 16:23:07 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=8a47acd3

Rebase for upcoming 2.41

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch | 10 +++++-----
 ...2-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch |  4 ++--
 9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch  |  6 +++---
 ...04-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch |  4 ++--
 ...-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch |  4 ++--
 9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch           |  4 ++--
 ...-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch |  6 +++---
 7 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 716fa9b..a724494 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From 38cf5d1565c113e64a5cdfc9d55d554919bc10d7 Mon Sep 17 00:00:00 2001
+From 930c326fd4f16299f06610cf3ff3ee94b13130e0 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/7] Gentoo: gold/ld: add support for poisoned system
@@ -120,7 +120,7 @@ index ad0dc6a106c..d21edaddce7 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index 03b9e46f56d..091d5913ee4 100755
+index 0c32b16241a..549b8d49f5e 100755
 --- a/ld/configure
 +++ b/ld/configure
 @@ -839,6 +839,7 @@ with_lib_path
@@ -247,7 +247,7 @@ index aa8b1aa86eb..b57b0d5c9f5 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index c8a6874978b..6ba20992b66 100644
+index df7c9cbd65e..ed15262e0bc 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
 @@ -327,6 +327,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
@@ -292,7 +292,7 @@ index 87cac02141d..d79ec8faa15 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 25cc89b72f9..9c81fd6f539 100644
+index 06ac2c64fa8..5ec931a0255 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
 @@ -325,6 +325,13 @@ main (int argc, char **argv)
@@ -352,5 +352,5 @@ index fe8722313fe..5fd7350efc5 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 550f0a1..a0bffea 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 0486446fa828245f0ac260d170ebe3e7123932c4 Mon Sep 17 00:00:00 2001
+From 68b7e6f60dd42159af779d5b475b7df553655d1f Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/7] Gentoo: libiberty: install PIC version of libiberty.a
@@ -30,5 +30,5 @@ index f9fbba23e2c..d37488d1bf8 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 0597531..3c08be6 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 36fef3463cc9273249699cf372bf9cb59744df36 Mon Sep 17 00:00:00 2001
+From 3a489acb4547c320ba43858ead3586fed34c92b4 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/7] Gentoo: add --with-extra-soversion-suffix= option
@@ -79,7 +79,7 @@ index 4edfedee924..70a2442957e 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 41d280ef461..18e7e3acdbd 100755
+index dcb10317390..94a4e39d691 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -695,6 +695,7 @@ WARN_CFLAGS
@@ -142,5 +142,5 @@ index f044616f4d9..f22a87f8f54 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 4242ba8..59c18ef 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From 50af4f7750d537ada9cdb9946804f12e19bb6842 Mon Sep 17 00:00:00 2001
+From eb585240ae3079a2cdc081a2cd96e09db95947ef Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -57,5 +57,5 @@ index 918464069a9..7d22ee70b27 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index e5342b3..192fa4f 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From c7ff4b542556d68004ccc30e2da25c56380dcea2 Mon Sep 17 00:00:00 2001
+From 1de1744597aa5b2e29ddedfea42cd7f99796b0ec Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
@@ -189,5 +189,5 @@ index 6a5eade1855..a0e65a4aeda 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index eb2c2b0..210563c 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 15971356d40e17c2409f729d376237a6d1a980c6 Mon Sep 17 00:00:00 2001
+From 4718611dc4145a8d8de7534f150053c5accf96a1 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/7] Gentoo: XFAIL 15 broken ld.gold tests
@@ -73,5 +73,5 @@ index fb0eb12553b..b506a7f8da7 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.40.0
+2.41.0
 

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index 808d877..8d7acd1 100644
--- a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,4 +1,4 @@
-From d76981d4b7bb9bc31825a3ccf5a075ac2694a4c0 Mon Sep 17 00:00:00 2001
+From 7fbdb5f138dccdd3b65a0bd048802662c6302ea1 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
 Subject: [PATCH 7/7] Apply a similar libiberty fix as in 7d53105d for
@@ -46,7 +46,7 @@ index b881268b0d9..0e8b707f7d7 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index 8717d99ca26..fbdf41f87be 100755
+index 71504e10c51..cb669ed994f 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
 @@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
@@ -80,5 +80,5 @@ index 1beb72e87e0..79310916f7d 100644
        ;;
    esac
 -- 
-2.40.0
+2.41.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-06-30  9:21 WANG Xuerui
  0 siblings, 0 replies; 102+ messages in thread
From: WANG Xuerui @ 2023-06-30  9:21 UTC (permalink / raw
  To: gentoo-commits

commit:     73a506ab573568d06b30206258b2d4875b5450fb
Author:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 30 09:19:42 2023 +0000
Commit:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
CommitDate: Fri Jun 30 09:19:50 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=73a506ab

Rebase on top of upstream commit 6637ae9232f0ba44

Signed-off-by: WANG Xuerui <xen0n <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 32 ++++++++---------
 ...iberty-install-PIC-version-of-libiberty.a.patch |  6 ++--
 ...oo-add-with-extra-soversion-suffix-option.patch | 20 +++++------
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch | 12 +++----
 ...-also-libctf-optionally-a-gentoo-specific.patch | 40 +++++++++++-----------
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch |  6 ++--
 ...ilar-libiberty-fix-as-in-7d53105d-for-lib.patch | 16 ++++-----
 7 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index c9a15e1..716fa9b 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,7 +1,7 @@
-From febeab1e92e6aaf19a3a67a8729cbe0a444ddf59 Mon Sep 17 00:00:00 2001
+From 38cf5d1565c113e64a5cdfc9d55d554919bc10d7 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
-Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system
+Subject: [PATCH 1/7] Gentoo: gold/ld: add support for poisoned system
  directories
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
@@ -88,10 +88,10 @@ index c9834b66159..bd3e948a61b 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index 1aa451c7711..524c7c859df 100644
+index 46f658f23ea..8f9b8c177ad 100644
 --- a/gold/options.h
 +++ b/gold/options.h
-@@ -1398,6 +1398,13 @@ class General_options
+@@ -1402,6 +1402,13 @@ class General_options
    DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
  	      N_("Ignored"), NULL);
  
@@ -200,7 +200,7 @@ index 77edac3258c..a74dac63038 100644
  dnl "install_as_default" is set to false if gold is the default linker.
  dnl "installed_linker" is the installed BFD linker name.
 diff --git a/ld/ld.h b/ld/ld.h
-index 05649ff61b8..ce9e8229ac5 100644
+index a0f8a15c7a9..69420b6673a 100644
 --- a/ld/ld.h
 +++ b/ld/ld.h
 @@ -163,6 +163,13 @@ typedef struct
@@ -218,10 +218,10 @@ index 05649ff61b8..ce9e8229ac5 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index db3a9f09b45..5b543914e67 100644
+index aa8b1aa86eb..b57b0d5c9f5 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2960,6 +2960,24 @@ creation of the metadata note, if one had been enabled by an earlier
+@@ -3059,6 +3059,24 @@ creation of the metadata note, if one had been enabled by an earlier
  occurrence of the --package-metdata option.
  If the linker has been built with libjansson, then the JSON string
  will be validated.
@@ -247,10 +247,10 @@ index db3a9f09b45..5b543914e67 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index b8fd4e5d8e0..639204f4c29 100644
+index c8a6874978b..6ba20992b66 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
-@@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
+@@ -327,6 +327,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
      new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
    else
      new_dirs->name = xstrdup (name);
@@ -278,7 +278,7 @@ index b8fd4e5d8e0..639204f4c29 100644
  
  /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 0538f0a06a1..82685348055 100644
+index 87cac02141d..d79ec8faa15 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
 @@ -151,6 +151,9 @@ enum option_values
@@ -292,10 +292,10 @@ index 0538f0a06a1..82685348055 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 9290a189b0d..da25dbb13b7 100644
+index 25cc89b72f9..9c81fd6f539 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
-@@ -321,6 +321,13 @@ main (int argc, char **argv)
+@@ -325,6 +325,13 @@ main (int argc, char **argv)
    command_line.warn_mismatch = true;
    command_line.warn_search_mismatch = true;
    command_line.check_section_addresses = -1;
@@ -310,10 +310,10 @@ index 9290a189b0d..da25dbb13b7 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index c5960385572..950b6969cb8 100644
+index fe8722313fe..5fd7350efc5 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -584,6 +584,18 @@ static const struct ld_option ld_options[] =
+@@ -594,6 +594,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -332,7 +332,7 @@ index c5960385572..950b6969cb8 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1692,6 +1704,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1738,6 +1750,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -352,5 +352,5 @@ index c5960385572..950b6969cb8 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index f5936c6..550f0a1 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,7 +1,7 @@
-From 041fec351bca1ec30fa639ee80c0810a413b2d89 Mon Sep 17 00:00:00 2001
+From 0486446fa828245f0ac260d170ebe3e7123932c4 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
-Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
+Subject: [PATCH 2/7] Gentoo: libiberty: install PIC version of libiberty.a
 
 This will install a PIC version of libiberty.a by overwriting the non-PIC
 version of libiberty.a while compiling.  We do this because there is no
@@ -30,5 +30,5 @@ index f9fbba23e2c..d37488d1bf8 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 8921582..0597531 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,7 +1,7 @@
-From b1e693934cde0f00e0b2fea50753e0f965bf7f88 Mon Sep 17 00:00:00 2001
+From 36fef3463cc9273249699cf372bf9cb59744df36 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
-Subject: [PATCH 3/6] Gentoo: add --with-extra-soversion-suffix= option
+Subject: [PATCH 3/7] Gentoo: add --with-extra-soversion-suffix= option
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit
@@ -34,7 +34,7 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 75d21db88d1..9137f025b87 100644
+index 5c5fdefd3b8..fe26bbf4f0f 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 75d21db88d1..9137f025b87 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -994,6 +996,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -976,6 +978,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index 75d21db88d1..9137f025b87 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index 0b0bb1a950e..0ee27ecc111 100644
+index 4edfedee924..70a2442957e 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -355,6 +355,7 @@ ECHO_T = @ECHO_T@
+@@ -342,6 +342,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index 0b0bb1a950e..0ee27ecc111 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2474,6 +2475,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2435,6 +2436,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,7 +79,7 @@ index 0b0bb1a950e..0ee27ecc111 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 5af8af2ee37..42bd8f32145 100755
+index 41d280ef461..18e7e3acdbd 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -695,6 +695,7 @@ WARN_CFLAGS
@@ -124,7 +124,7 @@ index 5af8af2ee37..42bd8f32145 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index 82a3d1f832e..2b882c735d4 100644
+index f044616f4d9..f22a87f8f54 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
 @@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
@@ -142,5 +142,5 @@ index 82a3d1f832e..2b882c735d4 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 4411e88..4242ba8 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,7 +1,7 @@
-From c45749c4cc5750db631e16b301133f15adfb94c7 Mon Sep 17 00:00:00 2001
+From 50af4f7750d537ada9cdb9946804f12e19bb6842 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
-Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
+Subject: [PATCH 4/7] Gentoo: Pass --hash-style=sysv to ld in the testsuite
 
 ---
  binutils/testsuite/lib/binutils-common.exp |  2 +-
@@ -9,10 +9,10 @@ Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b0190ac51ac..aeef8e55b87 100644
+index 7e6bf16ee6e..0491fff2883 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1308,7 +1308,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1354,7 +1354,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,7 +22,7 @@ index b0190ac51ac..aeef8e55b87 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 47e86a7b27c..55192a05f35 100644
+index 918464069a9..7d22ee70b27 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
 @@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
@@ -57,5 +57,5 @@ index 47e86a7b27c..55192a05f35 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 3ac7217..e5342b3 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,7 +1,7 @@
-From ffb569acc3bfa5a22cc6581338108f79fd3d8c55 Mon Sep 17 00:00:00 2001
+From c7ff4b542556d68004ccc30e2da25c56380dcea2 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
-Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
+Subject: [PATCH 5/7] Gentoo: Give also libctf optionally a gentoo-specific
  soversion
 
 ---
@@ -12,7 +12,7 @@ Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
  4 files changed, 64 insertions(+), 4 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index c4809f70bae..5571eef8aa1 100644
+index b1dbc2f6ba4..d282ceb619a 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
 @@ -26,6 +26,9 @@ info_TEXINFOS =
@@ -45,10 +45,10 @@ index c4809f70bae..5571eef8aa1 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index f2b852e3fae..14fc79bf5a9 100644
+index 3d2696bcc47..664d6360c47 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -381,6 +381,7 @@ AUTOCONF = @AUTOCONF@
+@@ -380,6 +380,7 @@ AUTOCONF = @AUTOCONF@
  AUTOHEADER = @AUTOHEADER@
  AUTOMAKE = @AUTOMAKE@
  AWK = @AWK@
@@ -56,7 +56,7 @@ index f2b852e3fae..14fc79bf5a9 100644
  CATALOGS = @CATALOGS@
  CATOBJEXT = @CATOBJEXT@
  CC = @CC@
-@@ -403,6 +404,7 @@ EXEEXT = @EXEEXT@
+@@ -402,6 +403,7 @@ EXEEXT = @EXEEXT@
  
  # Setup the testing framework, if you have one
  EXPECT = expect
@@ -80,10 +80,10 @@ index f2b852e3fae..14fc79bf5a9 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index 17463a74cca..b0b5c78a7a6 100755
+index a0e40f49a80..356503f689f 100755
 --- a/libctf/configure
 +++ b/libctf/configure
-@@ -646,6 +646,10 @@ BUILD_INFO_FALSE
+@@ -645,6 +645,10 @@ BUILD_INFO_FALSE
  BUILD_INFO_TRUE
  NEED_CTF_QSORT_R_FALSE
  NEED_CTF_QSORT_R_TRUE
@@ -94,7 +94,7 @@ index 17463a74cca..b0b5c78a7a6 100755
  ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
  ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
  zlibinc
-@@ -807,6 +811,7 @@ enable_maintainer_mode
+@@ -806,6 +810,7 @@ enable_maintainer_mode
  enable_install_libbfd
  with_system_zlib
  enable_libctf_hash_debugging
@@ -102,7 +102,7 @@ index 17463a74cca..b0b5c78a7a6 100755
  '
        ac_precious_vars='build_alias
  host_alias
-@@ -1464,6 +1469,8 @@ Optional Packages:
+@@ -1463,6 +1468,8 @@ Optional Packages:
                            both]
    --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
    --with-system-zlib      use installed libz
@@ -111,25 +111,25 @@ index 17463a74cca..b0b5c78a7a6 100755
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11632,7 +11639,7 @@ else
+@@ -11631,7 +11638,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11635 "configure"
-+#line 11665 "configure"
+-#line 11634 "configure"
++#line 11641 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11738,7 +11745,7 @@ else
+@@ -11737,7 +11744,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11741 "configure"
-+#line 11771 "configure"
+-#line 11740 "configure"
++#line 11747 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -14305,6 +14312,26 @@ else
+@@ -14304,6 +14311,26 @@ else
  fi
  
  
@@ -156,7 +156,7 @@ index 17463a74cca..b0b5c78a7a6 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -15199,6 +15226,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -15196,6 +15223,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -168,7 +168,7 @@ index 17463a74cca..b0b5c78a7a6 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index a0148a4c328..1901ade381d 100644
+index 6a5eade1855..a0e65a4aeda 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
 @@ -76,6 +76,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
@@ -189,5 +189,5 @@ index a0148a4c328..1901ade381d 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 303942b..eb2c2b0 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,7 +1,7 @@
-From a5ae5bca2b691999092655fe0df9b6c22e76ffaa Mon Sep 17 00:00:00 2001
+From 15971356d40e17c2409f729d376237a6d1a980c6 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
-Subject: [PATCH 6/6] Gentoo: XFAIL 15 broken ld.gold tests
+Subject: [PATCH 6/7] Gentoo: XFAIL 15 broken ld.gold tests
 
 It seems like either the tests or ld.gold in general cannot handle
 compilers built with --enable-default-pie. No fix yet, so let's ignore
@@ -73,5 +73,5 @@ index fb0eb12553b..b506a7f8da7 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.38.2
+2.40.0
 

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
index d915528..808d877 100644
--- a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
+++ b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -1,8 +1,8 @@
-From afc5e9fab399c9164f7355b69d0e23318d0559a5 Mon Sep 17 00:00:00 2001
+From d76981d4b7bb9bc31825a3ccf5a075ac2694a4c0 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 22 Feb 2023 20:05:35 +0100
-Subject: [PATCH] Apply a similar libiberty fix as in 7d53105d for libopcodes
- and libgprofng
+Subject: [PATCH 7/7] Apply a similar libiberty fix as in 7d53105d for
+ libopcodes and libgprofng
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit
@@ -18,7 +18,7 @@ Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 8 insertions(+), 6 deletions(-)
 
 diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
-index ab90bb08c5f..96256faf788 100644
+index 219367fb9ce..d9365260e8d 100644
 --- a/gprofng/src/Makefile.am
 +++ b/gprofng/src/Makefile.am
 @@ -131,7 +131,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
@@ -32,10 +32,10 @@ index ab90bb08c5f..96256faf788 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
-index 605fa4f6fd4..f968d8d6e59 100644
+index b881268b0d9..0e8b707f7d7 100644
 --- a/gprofng/src/Makefile.in
 +++ b/gprofng/src/Makefile.in
-@@ -555,7 +555,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
+@@ -552,7 +552,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
  # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
  # when -nostdlib is passed to libtool.
  # See bug 29364 - libgprofng.so: needs to link against -pthread
@@ -46,7 +46,7 @@ index 605fa4f6fd4..f968d8d6e59 100644
  	$(GPROFNG_LIBADD) \
  	-lpthread -ldl
 diff --git a/opcodes/configure b/opcodes/configure
-index d2364991ee8..1f483e37fc9 100755
+index 8717d99ca26..fbdf41f87be 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
 @@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
@@ -80,5 +80,5 @@ index 1beb72e87e0..79310916f7d 100644
        ;;
    esac
 -- 
-2.39.2
+2.40.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-04-02 11:44 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-04-02 11:44 UTC (permalink / raw
  To: gentoo-commits

commit:     b359e23310a3269a6b25f49fa0c962364ece0fc5
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sun Apr  2 11:43:34 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sun Apr  2 11:43:34 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=b359e233

Apply build fix for libiberty to libopcodes and libgprofng

To be upstreamed properly

Bug: https://bugs.gentoo.org/834720
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...ilar-libiberty-fix-as-in-7d53105d-for-lib.patch | 84 ++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
new file mode 100644
index 0000000..d915528
--- /dev/null
+++ b/9999/0007-Apply-a-similar-libiberty-fix-as-in-7d53105d-for-lib.patch
@@ -0,0 +1,84 @@
+From afc5e9fab399c9164f7355b69d0e23318d0559a5 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Wed, 22 Feb 2023 20:05:35 +0100
+Subject: [PATCH] Apply a similar libiberty fix as in 7d53105d for libopcodes
+ and libgprofng
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29042
+Bug: https://bugs.gentoo.org/834720
+Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
+---
+ gprofng/src/Makefile.am | 3 ++-
+ gprofng/src/Makefile.in | 3 ++-
+ opcodes/configure       | 4 ++--
+ opcodes/configure.ac    | 4 ++--
+ 4 files changed, 8 insertions(+), 6 deletions(-)
+
+diff --git a/gprofng/src/Makefile.am b/gprofng/src/Makefile.am
+index ab90bb08c5f..96256faf788 100644
+--- a/gprofng/src/Makefile.am
++++ b/gprofng/src/Makefile.am
+@@ -131,7 +131,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
+ # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
+ # when -nostdlib is passed to libtool.
+ # See bug 29364 - libgprofng.so: needs to link against -pthread
+-libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
++libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
++	$(top_builddir)/../opcodes/libopcodes.la \
+ 	$(top_builddir)/../bfd/libbfd.la \
+ 	$(GPROFNG_LIBADD) \
+ 	-lpthread -ldl
+diff --git a/gprofng/src/Makefile.in b/gprofng/src/Makefile.in
+index 605fa4f6fd4..f968d8d6e59 100644
+--- a/gprofng/src/Makefile.in
++++ b/gprofng/src/Makefile.in
+@@ -555,7 +555,8 @@ libgprofng_la_LDFLAGS = -version-info 0:0:0
+ # Pass -lpthread instead of $(PTHREAD_LIBS) due to $(PTHREAD_LIBS) being empty
+ # when -nostdlib is passed to libtool.
+ # See bug 29364 - libgprofng.so: needs to link against -pthread
+-libgprofng_la_LIBADD = $(top_builddir)/../opcodes/libopcodes.la \
++libgprofng_la_LIBADD = $(GPROFNG_LIBADD) \
++	$(top_builddir)/../opcodes/libopcodes.la \
+ 	$(top_builddir)/../bfd/libbfd.la \
+ 	$(GPROFNG_LIBADD) \
+ 	-lpthread -ldl
+diff --git a/opcodes/configure b/opcodes/configure
+index d2364991ee8..1f483e37fc9 100755
+--- a/opcodes/configure
++++ b/opcodes/configure
+@@ -12445,10 +12445,10 @@ if test "$enable_shared" = "yes"; then
+   case "${host}" in
+     *-*-cygwin*)
+       SHARED_LDFLAGS="-no-undefined"
+-      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
++      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
+       ;;
+     *)
+-      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
++      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
+       SHARED_DEPENDENCIES="../bfd/libbfd.la"
+       ;;
+   esac
+diff --git a/opcodes/configure.ac b/opcodes/configure.ac
+index 1beb72e87e0..79310916f7d 100644
+--- a/opcodes/configure.ac
++++ b/opcodes/configure.ac
+@@ -193,10 +193,10 @@ if test "$enable_shared" = "yes"; then
+   case "${host}" in
+     *-*-cygwin*)
+       SHARED_LDFLAGS="-no-undefined"
+-      SHARED_LIBADD="-L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
++      SHARED_LIBADD="$SHARED_LIBADD -L`pwd`/../bfd -lbfd -L`pwd`/../libiberty -liberty $SHARED_LIBADD"
+       ;;
+     *)
+-      SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
++      SHARED_LIBADD="${SHARED_LIBADD} ../bfd/libbfd.la ${SHARED_LIBADD}"
+       SHARED_DEPENDENCIES="../bfd/libbfd.la"
+       ;;
+   esac
+-- 
+2.39.2
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-01-05 16:22 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-01-05 16:22 UTC (permalink / raw
  To: gentoo-commits

commit:     39d3e22103c9b44afb5c9b6eba4298a9f3394c9f
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  5 16:22:01 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Thu Jan  5 16:22:01 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=39d3e221

Patch 0008 pushed upstream

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...e-un-xfail-pr19719-tests-on-aarch64-seems.patch | 26 ----------------------
 1 file changed, 26 deletions(-)

diff --git a/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch b/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch
deleted file mode 100644
index 7168d7e..0000000
--- a/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From 0564593ab415665b6de8089debf4a0205582d8ef Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Tue, 3 Jan 2023 22:39:24 +0100
-Subject: [PATCH 2/2] ld testsuite: un-xfail pr19719 tests on aarch64, seems to
- succeed now
-
----
- ld/testsuite/ld-elf/shared.exp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
-index 6dd99bb5c9d..db9d71398de 100644
---- a/ld/testsuite/ld-elf/shared.exp
-+++ b/ld/testsuite/ld-elf/shared.exp
-@@ -1656,7 +1656,7 @@ proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
-     }
- }
- 
--mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
-+mix_pic_and_non_pic [list "arm*-*-*"] "" "" "pr19719"
- mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
- 
- set AFLAGS_PIE ""
--- 
-2.38.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-01-05 16:21 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-01-05 16:21 UTC (permalink / raw
  To: gentoo-commits

commit:     701c5749a5548f5fb002477ad33e9379889a77c4
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  5 16:21:05 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Thu Jan  5 16:21:05 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=701c5749

Patch 0007 pushed upstream

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...e-relax-regexps-to-make-tests-pass-on-aar.patch | 52 ----------------------
 1 file changed, 52 deletions(-)

diff --git a/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch b/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch
deleted file mode 100644
index d129d85..0000000
--- a/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch
+++ /dev/null
@@ -1,52 +0,0 @@
-From 80c4388424197f5994fa71646fe81ba77b69d996 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Tue, 3 Jan 2023 22:23:02 +0100
-Subject: [PATCH 1/2] ld testsuite: relax regexps to make tests pass on
- aarch64, bug 29843
-
----
- ld/testsuite/ld-aarch64/bti-plt-5.d              | 8 ++++----
- ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d | 2 +-
- 2 files changed, 5 insertions(+), 5 deletions(-)
-
-diff --git a/ld/testsuite/ld-aarch64/bti-plt-5.d b/ld/testsuite/ld-aarch64/bti-plt-5.d
-index 12abbc2e055..ed0029b8de1 100644
---- a/ld/testsuite/ld-aarch64/bti-plt-5.d
-+++ b/ld/testsuite/ld-aarch64/bti-plt-5.d
-@@ -13,8 +13,8 @@ Disassembly of section \.plt:
- .*:	d503245f 	bti	c
- .*:	a9bf7bf0 	stp	x16, x30, \[sp, #-16\]!
- .*:	90000090 	adrp	x16, 410000 <.*>
--.*:	f9421611 	ldr	x17, \[x16, #1064\]
--.*:	9110a210 	add	x16, x16, #0x428
-+.*:	f9...... 	ldr	x17, \[x16, #....\]
-+.*:	91...... 	add	x16, x16, #0x...
- .*:	d61f0220 	br	x17
- .*:	d503201f 	nop
- .*:	d503201f 	nop
-@@ -22,7 +22,7 @@ Disassembly of section \.plt:
- [0-9a-f]+ <.*>:
- .*:	d503245f 	bti	c
- .*:	90000090 	adrp	x16, 410000 <.*>
--.*:	f9421a11 	ldr	x17, \[x16, #1072\]
--.*:	9110c210 	add	x16, x16, #0x430
-+.*:	f9...... 	ldr	x17, \[x16, #....\]
-+.*:	91...... 	add	x16, x16, #0x...
- .*:	d61f0220 	br	x17
- .*:	d503201f 	nop
-diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
-index 8b6dceff81b..dcf913428fb 100644
---- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
-+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
-@@ -11,7 +11,7 @@
-  0x.+ \(PLTRELSZ\) \s+.+ \(bytes\)
-  0x.+ \(PLTREL\)   \s+RELA
-  0x.+ \(JMPREL\)   \s+0x.+
-- 0x.+ \(BIND_NOW\) \s+
-+ 0x.+ (\(BIND_NOW\) \s+|\(FLAGS\)  \s+   BIND_NOW)
-  0x.+ \(FLAGS_1\)  \s+   Flags: NOW
-  0x.+ \(NULL\)     \s+   0x0
- 
--- 
-2.38.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-01-03 23:03 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-01-03 23:03 UTC (permalink / raw
  To: gentoo-commits

commit:     c0ada7cf5326b17ffd2a4f8e6e9699f83e8e9b04
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Tue Jan  3 23:02:41 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Tue Jan  3 23:02:41 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=c0ada7cf

Fix tests on aarch64 (submitted upstream)

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...e-relax-regexps-to-make-tests-pass-on-aar.patch | 52 ++++++++++++++++++++++
 ...e-un-xfail-pr19719-tests-on-aarch64-seems.patch | 26 +++++++++++
 2 files changed, 78 insertions(+)

diff --git a/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch b/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch
new file mode 100644
index 0000000..d129d85
--- /dev/null
+++ b/9999/0007-ld-testsuite-relax-regexps-to-make-tests-pass-on-aar.patch
@@ -0,0 +1,52 @@
+From 80c4388424197f5994fa71646fe81ba77b69d996 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Tue, 3 Jan 2023 22:23:02 +0100
+Subject: [PATCH 1/2] ld testsuite: relax regexps to make tests pass on
+ aarch64, bug 29843
+
+---
+ ld/testsuite/ld-aarch64/bti-plt-5.d              | 8 ++++----
+ ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d | 2 +-
+ 2 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/ld/testsuite/ld-aarch64/bti-plt-5.d b/ld/testsuite/ld-aarch64/bti-plt-5.d
+index 12abbc2e055..ed0029b8de1 100644
+--- a/ld/testsuite/ld-aarch64/bti-plt-5.d
++++ b/ld/testsuite/ld-aarch64/bti-plt-5.d
+@@ -13,8 +13,8 @@ Disassembly of section \.plt:
+ .*:	d503245f 	bti	c
+ .*:	a9bf7bf0 	stp	x16, x30, \[sp, #-16\]!
+ .*:	90000090 	adrp	x16, 410000 <.*>
+-.*:	f9421611 	ldr	x17, \[x16, #1064\]
+-.*:	9110a210 	add	x16, x16, #0x428
++.*:	f9...... 	ldr	x17, \[x16, #....\]
++.*:	91...... 	add	x16, x16, #0x...
+ .*:	d61f0220 	br	x17
+ .*:	d503201f 	nop
+ .*:	d503201f 	nop
+@@ -22,7 +22,7 @@ Disassembly of section \.plt:
+ [0-9a-f]+ <.*>:
+ .*:	d503245f 	bti	c
+ .*:	90000090 	adrp	x16, 410000 <.*>
+-.*:	f9421a11 	ldr	x17, \[x16, #1072\]
+-.*:	9110c210 	add	x16, x16, #0x430
++.*:	f9...... 	ldr	x17, \[x16, #....\]
++.*:	91...... 	add	x16, x16, #0x...
+ .*:	d61f0220 	br	x17
+ .*:	d503201f 	nop
+diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
+index 8b6dceff81b..dcf913428fb 100644
+--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
++++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-le-now.d
+@@ -11,7 +11,7 @@
+  0x.+ \(PLTRELSZ\) \s+.+ \(bytes\)
+  0x.+ \(PLTREL\)   \s+RELA
+  0x.+ \(JMPREL\)   \s+0x.+
+- 0x.+ \(BIND_NOW\) \s+
++ 0x.+ (\(BIND_NOW\) \s+|\(FLAGS\)  \s+   BIND_NOW)
+  0x.+ \(FLAGS_1\)  \s+   Flags: NOW
+  0x.+ \(NULL\)     \s+   0x0
+ 
+-- 
+2.38.2
+

diff --git a/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch b/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch
new file mode 100644
index 0000000..7168d7e
--- /dev/null
+++ b/9999/0008-ld-testsuite-un-xfail-pr19719-tests-on-aarch64-seems.patch
@@ -0,0 +1,26 @@
+From 0564593ab415665b6de8089debf4a0205582d8ef Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Tue, 3 Jan 2023 22:39:24 +0100
+Subject: [PATCH 2/2] ld testsuite: un-xfail pr19719 tests on aarch64, seems to
+ succeed now
+
+---
+ ld/testsuite/ld-elf/shared.exp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
+index 6dd99bb5c9d..db9d71398de 100644
+--- a/ld/testsuite/ld-elf/shared.exp
++++ b/ld/testsuite/ld-elf/shared.exp
+@@ -1656,7 +1656,7 @@ proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
+     }
+ }
+ 
+-mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
++mix_pic_and_non_pic [list "arm*-*-*"] "" "" "pr19719"
+ mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
+ 
+ set AFLAGS_PIE ""
+-- 
+2.38.2
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2023-01-02 23:50 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2023-01-02 23:50 UTC (permalink / raw
  To: gentoo-commits

commit:     af2d7885363daa305cf4840cb7fe72e3ada04122
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  2 23:49:51 2023 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Mon Jan  2 23:49:51 2023 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=af2d7885

Rebase patches onto master

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 52 +++++++++++-----------
 ...iberty-install-PIC-version-of-libiberty.a.patch |  6 +--
 ...oo-add-with-extra-soversion-suffix-option.patch | 16 +++----
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch | 10 ++---
 ...-also-libctf-optionally-a-gentoo-specific.patch | 44 +++++++++---------
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch | 10 ++---
 6 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 1a03757..c9a15e1 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From eaf58344eafc9b9943a0bd7e9e00130965b10274 Mon Sep 17 00:00:00 2001
+From febeab1e92e6aaf19a3a67a8729cbe0a444ddf59 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system
@@ -44,7 +44,7 @@ Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
  11 files changed, 150 insertions(+), 2 deletions(-)
 
 diff --git a/gold/options.cc b/gold/options.cc
-index 04be98a3e39..64439f8af7a 100644
+index c9834b66159..bd3e948a61b 100644
 --- a/gold/options.cc
 +++ b/gold/options.cc
 @@ -1355,6 +1355,39 @@ General_options::finalize()
@@ -88,7 +88,7 @@ index 04be98a3e39..64439f8af7a 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index 17236eb9cb9..dad649870bf 100644
+index 1aa451c7711..524c7c859df 100644
 --- a/gold/options.h
 +++ b/gold/options.h
 @@ -1398,6 +1398,13 @@ class General_options
@@ -106,10 +106,10 @@ index 17236eb9cb9..dad649870bf 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index 3916740eee4..7e70b0179ea 100644
+index ad0dc6a106c..d21edaddce7 100644
 --- a/ld/config.in
 +++ b/ld/config.in
-@@ -55,6 +55,9 @@
+@@ -58,6 +58,9 @@
     language is requested. */
  #undef ENABLE_NLS
  
@@ -120,10 +120,10 @@ index 3916740eee4..7e70b0179ea 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index 9dd3ed5f1e7..a9a67a8babe 100755
+index 03b9e46f56d..091d5913ee4 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -838,6 +838,7 @@ with_lib_path
+@@ -839,6 +839,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -131,7 +131,7 @@ index 9dd3ed5f1e7..a9a67a8babe 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1519,6 +1520,8 @@ Optional Features:
+@@ -1521,6 +1522,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -140,25 +140,25 @@ index 9dd3ed5f1e7..a9a67a8babe 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -11620,7 +11623,7 @@ else
+@@ -11625,7 +11628,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11623 "configure"
+-#line 11628 "configure"
 +#line 11626 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11726,7 +11729,7 @@ else
+@@ -11731,7 +11734,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11729 "configure"
+-#line 11734 "configure"
 +#line 11732 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -15478,6 +15481,19 @@ fi
+@@ -15483,6 +15486,19 @@ fi
  
  
  
@@ -179,7 +179,7 @@ index 9dd3ed5f1e7..a9a67a8babe 100755
  if test "${enable_gold+set}" = set; then :
    enableval=$enable_gold; case "${enableval}" in
 diff --git a/ld/configure.ac b/ld/configure.ac
-index f1b2f9897f8..1927d79e728 100644
+index 77edac3258c..a74dac63038 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
 @@ -103,6 +103,16 @@ AC_SUBST(use_sysroot)
@@ -200,10 +200,10 @@ index f1b2f9897f8..1927d79e728 100644
  dnl "install_as_default" is set to false if gold is the default linker.
  dnl "installed_linker" is the installed BFD linker name.
 diff --git a/ld/ld.h b/ld/ld.h
-index f3086bf30de..90cf1ca51e5 100644
+index 05649ff61b8..ce9e8229ac5 100644
 --- a/ld/ld.h
 +++ b/ld/ld.h
-@@ -162,6 +162,13 @@ typedef struct
+@@ -163,6 +163,13 @@ typedef struct
       in the linker script.  */
    bool force_group_allocation;
  
@@ -218,10 +218,10 @@ index f3086bf30de..90cf1ca51e5 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index 9daed2e7e9f..d76b534a456 100644
+index db3a9f09b45..5b543914e67 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2952,6 +2952,24 @@ creation of the metadata note, if one had been enabled by an earlier
+@@ -2960,6 +2960,24 @@ creation of the metadata note, if one had been enabled by an earlier
  occurrence of the --package-metdata option.
  If the linker has been built with libjansson, then the JSON string
  will be validated.
@@ -247,7 +247,7 @@ index 9daed2e7e9f..d76b534a456 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 731ae5f7aed..6b67e29041b 100644
+index b8fd4e5d8e0..639204f4c29 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
 @@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
@@ -278,10 +278,10 @@ index 731ae5f7aed..6b67e29041b 100644
  
  /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 57ade1f754b..b35a6122e09 100644
+index 0538f0a06a1..82685348055 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
-@@ -149,6 +149,9 @@ enum option_values
+@@ -151,6 +151,9 @@ enum option_values
    OPTION_PRINT_OUTPUT_FORMAT,
    OPTION_PRINT_SYSROOT,
    OPTION_IGNORE_UNRESOLVED_SYMBOL,
@@ -292,7 +292,7 @@ index 57ade1f754b..b35a6122e09 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index d63002c994a..55364ef5773 100644
+index 9290a189b0d..da25dbb13b7 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
 @@ -321,6 +321,13 @@ main (int argc, char **argv)
@@ -310,10 +310,10 @@ index d63002c994a..55364ef5773 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 299371fb775..02816ebb1b6 100644
+index c5960385572..950b6969cb8 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -579,6 +579,18 @@ static const struct ld_option ld_options[] =
+@@ -584,6 +584,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -332,7 +332,7 @@ index 299371fb775..02816ebb1b6 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1679,6 +1691,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1692,6 +1704,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -352,5 +352,5 @@ index 299371fb775..02816ebb1b6 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.38.0
+2.38.2
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 9a5590e..f5936c6 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 14210956fa30806c5316ede3db67cac94420bb96 Mon Sep 17 00:00:00 2001
+From 041fec351bca1ec30fa639ee80c0810a413b2d89 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
@@ -18,7 +18,7 @@ general are fairly low, and we'd rather have things work for all of them.
  1 file changed, 1 insertion(+)
 
 diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
-index abef3c4601b..9dfb6b6d2b0 100644
+index f9fbba23e2c..d37488d1bf8 100644
 --- a/libiberty/Makefile.in
 +++ b/libiberty/Makefile.in
 @@ -258,6 +258,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
@@ -30,5 +30,5 @@ index abef3c4601b..9dfb6b6d2b0 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.38.0
+2.38.2
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 81265e4..8921582 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 96aa5434285fe8006fd671634fe753cf69451043 Mon Sep 17 00:00:00 2001
+From b1e693934cde0f00e0b2fea50753e0f965bf7f88 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/6] Gentoo: add --with-extra-soversion-suffix= option
@@ -34,7 +34,7 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 794d992310d..34b71212d75 100644
+index 75d21db88d1..9137f025b87 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 794d992310d..34b71212d75 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -992,6 +994,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -994,6 +996,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,7 +57,7 @@ index 794d992310d..34b71212d75 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index bdf12c99cfd..e4c613d7406 100644
+index 0b0bb1a950e..0ee27ecc111 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
 @@ -355,6 +355,7 @@ ECHO_T = @ECHO_T@
@@ -68,7 +68,7 @@ index bdf12c99cfd..e4c613d7406 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2471,6 +2472,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2474,6 +2475,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,7 +79,7 @@ index bdf12c99cfd..e4c613d7406 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index b72e885f711..b464614592d 100755
+index 5af8af2ee37..42bd8f32145 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -695,6 +695,7 @@ WARN_CFLAGS
@@ -124,7 +124,7 @@ index b72e885f711..b464614592d 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index 7a0ad0ffe33..2910cc9121f 100644
+index 82a3d1f832e..2b882c735d4 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
 @@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
@@ -142,5 +142,5 @@ index 7a0ad0ffe33..2910cc9121f 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.38.0
+2.38.2
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 484c657..4411e88 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From eeb95d2a0cda143dad4d905429ced8a339c486e3 Mon Sep 17 00:00:00 2001
+From c45749c4cc5750db631e16b301133f15adfb94c7 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -9,10 +9,10 @@ Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index ccc33a827b4..f7aecf7edc2 100644
+index b0190ac51ac..aeef8e55b87 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1310,7 +1310,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1308,7 +1308,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,7 +22,7 @@ index ccc33a827b4..f7aecf7edc2 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index ec27388a72e..fc7292a40a7 100644
+index 47e86a7b27c..55192a05f35 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
 @@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
@@ -57,5 +57,5 @@ index ec27388a72e..fc7292a40a7 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.38.0
+2.38.2
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 2133994..3ac7217 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From ee4de1adb09cbfcad39e544e2f05392b210b550a Mon Sep 17 00:00:00 2001
+From ffb569acc3bfa5a22cc6581338108f79fd3d8c55 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
@@ -12,7 +12,7 @@ Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
  4 files changed, 64 insertions(+), 4 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index 27e90f0ba36..4990a20efa3 100644
+index c4809f70bae..5571eef8aa1 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
 @@ -26,6 +26,9 @@ info_TEXINFOS =
@@ -45,10 +45,10 @@ index 27e90f0ba36..4990a20efa3 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 036a63fa720..e971f0b31bb 100644
+index f2b852e3fae..14fc79bf5a9 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -383,6 +383,7 @@ AUTOCONF = @AUTOCONF@
+@@ -381,6 +381,7 @@ AUTOCONF = @AUTOCONF@
  AUTOHEADER = @AUTOHEADER@
  AUTOMAKE = @AUTOMAKE@
  AWK = @AWK@
@@ -56,7 +56,7 @@ index 036a63fa720..e971f0b31bb 100644
  CATALOGS = @CATALOGS@
  CATOBJEXT = @CATOBJEXT@
  CC = @CC@
-@@ -405,6 +406,7 @@ EXEEXT = @EXEEXT@
+@@ -403,6 +404,7 @@ EXEEXT = @EXEEXT@
  
  # Setup the testing framework, if you have one
  EXPECT = expect
@@ -64,7 +64,7 @@ index 036a63fa720..e971f0b31bb 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -547,8 +549,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+@@ -540,8 +542,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
  @INSTALL_LIBBFD_FALSE@include_HEADERS = 
  @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/ctf.h $(INCDIR)/ctf-api.h
  @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
@@ -80,7 +80,7 @@ index 036a63fa720..e971f0b31bb 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index 176b3d6b918..31fe5f72a90 100755
+index 17463a74cca..b0b5c78a7a6 100755
 --- a/libctf/configure
 +++ b/libctf/configure
 @@ -646,6 +646,10 @@ BUILD_INFO_FALSE
@@ -93,43 +93,43 @@ index 176b3d6b918..31fe5f72a90 100755
 +EXTRA_SOVERSION_SUFFIX
  ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
  ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
- ZSTD_LIBS
-@@ -813,6 +817,7 @@ enable_install_libbfd
+ zlibinc
+@@ -807,6 +811,7 @@ enable_maintainer_mode
+ enable_install_libbfd
  with_system_zlib
- with_zstd
  enable_libctf_hash_debugging
 +with_extra_soversion_suffix
  '
        ac_precious_vars='build_alias
  host_alias
-@@ -1477,6 +1482,8 @@ Optional Packages:
+@@ -1464,6 +1469,8 @@ Optional Packages:
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
    --with-system-zlib      use installed libz
-   --with-zstd             support zstd compressed debug sections
-                           (default=auto)
 +  --with-extra-soversion-suffix=SUFFIX
 +                          Append '.SUFFIX' to SONAME [[default=]]
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11655,7 +11662,7 @@ else
+@@ -11632,7 +11639,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11658 "configure"
+-#line 11635 "configure"
 +#line 11665 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11761,7 +11768,7 @@ else
+@@ -11738,7 +11745,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11764 "configure"
+-#line 11741 "configure"
 +#line 11771 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -13209,6 +13216,26 @@ else
+@@ -14305,6 +14312,26 @@ else
  fi
  
  
@@ -156,7 +156,7 @@ index 176b3d6b918..31fe5f72a90 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -14101,6 +14128,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -15199,6 +15226,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -168,10 +168,10 @@ index 176b3d6b918..31fe5f72a90 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index 2e2ccf4b624..fbe5f27241b 100644
+index a0148a4c328..1901ade381d 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
-@@ -79,6 +79,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
+@@ -76,6 +76,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
  fi
  AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
  
@@ -189,5 +189,5 @@ index 2e2ccf4b624..fbe5f27241b 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.38.0
+2.38.2
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 23e7576..303942b 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 85c162be0eea0006c9d73fae243d771f7d0c9756 Mon Sep 17 00:00:00 2001
+From a5ae5bca2b691999092655fe0df9b6c22e76ffaa Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/6] Gentoo: XFAIL 15 broken ld.gold tests
@@ -16,7 +16,7 @@ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27303
  2 files changed, 18 insertions(+), 4 deletions(-)
 
 diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
-index 843fd0d197c..4940119c190 100644
+index df9405c1aac..749921633b2 100644
 --- a/gold/testsuite/Makefile.am
 +++ b/gold/testsuite/Makefile.am
 @@ -1,5 +1,11 @@
@@ -32,7 +32,7 @@ index 843fd0d197c..4940119c190 100644
  # system and the host system are the same.  So these tests will not
  # work when building with a cross-compiler.
 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
-index 21804df6573..6a4e2b5c5bb 100644
+index fb0eb12553b..b506a7f8da7 100644
 --- a/gold/testsuite/Makefile.in
 +++ b/gold/testsuite/Makefile.in
 @@ -15,10 +15,6 @@
@@ -61,7 +61,7 @@ index 21804df6573..6a4e2b5c5bb 100644
  check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
  	$(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
  	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
-@@ -2757,6 +2761,10 @@ top_srcdir = @top_srcdir@
+@@ -2759,6 +2763,10 @@ top_srcdir = @top_srcdir@
  zlibdir = @zlibdir@
  zlibinc = @zlibinc@
  
@@ -73,5 +73,5 @@ index 21804df6573..6a4e2b5c5bb 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.38.0
+2.38.2
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2022-10-08 12:15 WANG Xuerui
  0 siblings, 0 replies; 102+ messages in thread
From: WANG Xuerui @ 2022-10-08 12:15 UTC (permalink / raw
  To: gentoo-commits

commit:     0420678a87bef8c743a278e5a7a2d60a23e513cf
Author:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
AuthorDate: Sat Oct  8 12:14:29 2022 +0000
Commit:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
CommitDate: Sat Oct  8 12:14:29 2022 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=0420678a

Rebase on top of upstream commit 4cbfd0daabd6851

Signed-off-by: WANG Xuerui <xen0n <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 42 ++++++++++----------
 ...iberty-install-PIC-version-of-libiberty.a.patch |  4 +-
 ...oo-add-with-extra-soversion-suffix-option.patch | 26 ++++++------
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch |  4 +-
 ...-also-libctf-optionally-a-gentoo-specific.patch | 46 +++++++++++-----------
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch | 10 ++---
 6 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 8e2e947..1a03757 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From 6ad35e463cbd086b4d4e7bb5aca1da6b73e614c8 Mon Sep 17 00:00:00 2001
+From eaf58344eafc9b9943a0bd7e9e00130965b10274 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system
@@ -88,10 +88,10 @@ index 04be98a3e39..64439f8af7a 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index 9509a445e8e..a3d76b294cd 100644
+index 17236eb9cb9..dad649870bf 100644
 --- a/gold/options.h
 +++ b/gold/options.h
-@@ -1394,6 +1394,13 @@ class General_options
+@@ -1398,6 +1398,13 @@ class General_options
    DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
  	      N_("Ignored"), NULL);
  
@@ -106,7 +106,7 @@ index 9509a445e8e..a3d76b294cd 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index 0ccd79d59cd..5e39814bce0 100644
+index 3916740eee4..7e70b0179ea 100644
 --- a/ld/config.in
 +++ b/ld/config.in
 @@ -55,6 +55,9 @@
@@ -120,10 +120,10 @@ index 0ccd79d59cd..5e39814bce0 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index 1c2b64870b1..46b5789c77e 100755
+index 9dd3ed5f1e7..a9a67a8babe 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -836,6 +836,7 @@ with_lib_path
+@@ -838,6 +838,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -131,7 +131,7 @@ index 1c2b64870b1..46b5789c77e 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1514,6 +1515,8 @@ Optional Features:
+@@ -1519,6 +1520,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -140,25 +140,25 @@ index 1c2b64870b1..46b5789c77e 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -11491,7 +11494,7 @@ else
+@@ -11620,7 +11623,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11494 "configure"
-+#line 11497 "configure"
+-#line 11623 "configure"
++#line 11626 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11597,7 +11600,7 @@ else
+@@ -11726,7 +11729,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11600 "configure"
-+#line 11603 "configure"
+-#line 11729 "configure"
++#line 11732 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -15349,6 +15352,19 @@ fi
+@@ -15478,6 +15481,19 @@ fi
  
  
  
@@ -179,10 +179,10 @@ index 1c2b64870b1..46b5789c77e 100755
  if test "${enable_gold+set}" = set; then :
    enableval=$enable_gold; case "${enableval}" in
 diff --git a/ld/configure.ac b/ld/configure.ac
-index eb55904c090..0844c2364c5 100644
+index f1b2f9897f8..1927d79e728 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
-@@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
+@@ -103,6 +103,16 @@ AC_SUBST(use_sysroot)
  AC_SUBST(TARGET_SYSTEM_ROOT)
  AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
  
@@ -218,10 +218,10 @@ index f3086bf30de..90cf1ca51e5 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index eabbec8faa9..45f4858526c 100644
+index 9daed2e7e9f..d76b534a456 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2947,6 +2947,24 @@ creation of the metadata note, if one had been enabled by an earlier
+@@ -2952,6 +2952,24 @@ creation of the metadata note, if one had been enabled by an earlier
  occurrence of the --package-metdata option.
  If the linker has been built with libjansson, then the JSON string
  will be validated.
@@ -292,7 +292,7 @@ index 57ade1f754b..b35a6122e09 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index ea72b14a301..706ec9ce26e 100644
+index d63002c994a..55364ef5773 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
 @@ -321,6 +321,13 @@ main (int argc, char **argv)
@@ -310,7 +310,7 @@ index ea72b14a301..706ec9ce26e 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 9225f71b3ce..db5b170bc7c 100644
+index 299371fb775..02816ebb1b6 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
 @@ -579,6 +579,18 @@ static const struct ld_option ld_options[] =
@@ -352,5 +352,5 @@ index 9225f71b3ce..db5b170bc7c 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.35.1
+2.38.0
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 34462cc..9a5590e 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 4bd606f5945ea94b1ea0db8fba206cfe67959cde Mon Sep 17 00:00:00 2001
+From 14210956fa30806c5316ede3db67cac94420bb96 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
@@ -30,5 +30,5 @@ index abef3c4601b..9dfb6b6d2b0 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.35.1
+2.38.0
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 9328241..81265e4 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 2d3d27e6c5ad343a524a117dc02358ad7cb06e0d Mon Sep 17 00:00:00 2001
+From 96aa5434285fe8006fd671634fe753cf69451043 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/6] Gentoo: add --with-extra-soversion-suffix= option
@@ -34,7 +34,7 @@ Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 670e0598f55..18d6eef60bb 100644
+index 794d992310d..34b71212d75 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index 670e0598f55..18d6eef60bb 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -983,6 +985,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -992,6 +994,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index 670e0598f55..18d6eef60bb 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index d3ef4c2524b..56fac1bb94d 100644
+index bdf12c99cfd..e4c613d7406 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -354,6 +354,7 @@ ECHO_T = @ECHO_T@
+@@ -355,6 +355,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index d3ef4c2524b..56fac1bb94d 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2453,6 +2454,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2471,6 +2472,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,10 +79,10 @@ index d3ef4c2524b..56fac1bb94d 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 590986efb61..299f7bb0244 100755
+index b72e885f711..b464614592d 100755
 --- a/bfd/configure
 +++ b/bfd/configure
-@@ -691,6 +691,7 @@ WARN_CFLAGS
+@@ -695,6 +695,7 @@ WARN_CFLAGS
  REPORT_BUGS_TEXI
  REPORT_BUGS_TO
  PKGVERSION
@@ -90,7 +90,7 @@ index 590986efb61..299f7bb0244 100755
  DEBUGDIR
  ENABLE_BFD_64_BIT_FALSE
  ENABLE_BFD_64_BIT_TRUE
-@@ -832,6 +833,7 @@ enable_secureplt
+@@ -836,6 +837,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -98,7 +98,7 @@ index 590986efb61..299f7bb0244 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1508,6 +1510,8 @@ Optional Packages:
+@@ -1518,6 +1520,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
@@ -107,7 +107,7 @@ index 590986efb61..299f7bb0244 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12014,6 +12018,15 @@ fi
+@@ -12033,6 +12037,15 @@ fi
  
  
  
@@ -124,7 +124,7 @@ index 590986efb61..299f7bb0244 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index aad4f3c83a5..e9158315bf1 100644
+index 7a0ad0ffe33..2910cc9121f 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
 @@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
@@ -142,5 +142,5 @@ index aad4f3c83a5..e9158315bf1 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.35.1
+2.38.0
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index caaf9c7..484c657 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From 19d0d0a3fca319b6a14888ce709a75d9b0765561 Mon Sep 17 00:00:00 2001
+From eeb95d2a0cda143dad4d905429ced8a339c486e3 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -57,5 +57,5 @@ index ec27388a72e..fc7292a40a7 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.35.1
+2.38.0
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 4788ee0..2133994 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From ebc2d6f6c6d46a7fe77a37612ea0e12dccc467cf Mon Sep 17 00:00:00 2001
+From ee4de1adb09cbfcad39e544e2f05392b210b550a Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
@@ -45,10 +45,10 @@ index 27e90f0ba36..4990a20efa3 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 1984f50867a..55772ba94b3 100644
+index 036a63fa720..e971f0b31bb 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -381,6 +381,7 @@ AUTOCONF = @AUTOCONF@
+@@ -383,6 +383,7 @@ AUTOCONF = @AUTOCONF@
  AUTOHEADER = @AUTOHEADER@
  AUTOMAKE = @AUTOMAKE@
  AWK = @AWK@
@@ -56,7 +56,7 @@ index 1984f50867a..55772ba94b3 100644
  CATALOGS = @CATALOGS@
  CATOBJEXT = @CATOBJEXT@
  CC = @CC@
-@@ -403,6 +404,7 @@ EXEEXT = @EXEEXT@
+@@ -405,6 +406,7 @@ EXEEXT = @EXEEXT@
  
  # Setup the testing framework, if you have one
  EXPECT = expect
@@ -64,7 +64,7 @@ index 1984f50867a..55772ba94b3 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -540,8 +542,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+@@ -547,8 +549,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
  @INSTALL_LIBBFD_FALSE@include_HEADERS = 
  @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/ctf.h $(INCDIR)/ctf-api.h
  @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
@@ -80,7 +80,7 @@ index 1984f50867a..55772ba94b3 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index 8704bc215f4..de99d1714d7 100755
+index 176b3d6b918..31fe5f72a90 100755
 --- a/libctf/configure
 +++ b/libctf/configure
 @@ -646,6 +646,10 @@ BUILD_INFO_FALSE
@@ -93,43 +93,43 @@ index 8704bc215f4..de99d1714d7 100755
 +EXTRA_SOVERSION_SUFFIX
  ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
  ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
- zlibinc
-@@ -807,6 +811,7 @@ enable_maintainer_mode
- enable_install_libbfd
+ ZSTD_LIBS
+@@ -813,6 +817,7 @@ enable_install_libbfd
  with_system_zlib
+ with_zstd
  enable_libctf_hash_debugging
 +with_extra_soversion_suffix
  '
        ac_precious_vars='build_alias
  host_alias
-@@ -1464,6 +1469,8 @@ Optional Packages:
-                           both]
-   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -1477,6 +1482,8 @@ Optional Packages:
    --with-system-zlib      use installed libz
+   --with-zstd             support zstd compressed debug sections
+                           (default=auto)
 +  --with-extra-soversion-suffix=SUFFIX
 +                          Append '.SUFFIX' to SONAME [[default=]]
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11635,7 +11642,7 @@ else
+@@ -11655,7 +11662,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11638 "configure"
-+#line 11645 "configure"
+-#line 11658 "configure"
++#line 11665 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11741,7 +11748,7 @@ else
+@@ -11761,7 +11768,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11744 "configure"
-+#line 11751 "configure"
+-#line 11764 "configure"
++#line 11771 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -12948,6 +12955,26 @@ else
+@@ -13209,6 +13216,26 @@ else
  fi
  
  
@@ -156,7 +156,7 @@ index 8704bc215f4..de99d1714d7 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -13840,6 +13867,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -14101,6 +14128,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -168,10 +168,10 @@ index 8704bc215f4..de99d1714d7 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index 4996edd5b70..103fc8b9d33 100644
+index 2e2ccf4b624..fbe5f27241b 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
-@@ -78,6 +78,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
+@@ -79,6 +79,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
  fi
  AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
  
@@ -189,5 +189,5 @@ index 4996edd5b70..103fc8b9d33 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.35.1
+2.38.0
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 318552c..23e7576 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 7eefd99e98a9396f0ce2e98e9bd86bfeb53a84dc Mon Sep 17 00:00:00 2001
+From 85c162be0eea0006c9d73fae243d771f7d0c9756 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/6] Gentoo: XFAIL 15 broken ld.gold tests
@@ -16,7 +16,7 @@ Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27303
  2 files changed, 18 insertions(+), 4 deletions(-)
 
 diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
-index 38e54818f48..85c94d40660 100644
+index 843fd0d197c..4940119c190 100644
 --- a/gold/testsuite/Makefile.am
 +++ b/gold/testsuite/Makefile.am
 @@ -1,5 +1,11 @@
@@ -32,7 +32,7 @@ index 38e54818f48..85c94d40660 100644
  # system and the host system are the same.  So these tests will not
  # work when building with a cross-compiler.
 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
-index 7b4b7832d38..765c2b73140 100644
+index 21804df6573..6a4e2b5c5bb 100644
 --- a/gold/testsuite/Makefile.in
 +++ b/gold/testsuite/Makefile.in
 @@ -15,10 +15,6 @@
@@ -61,7 +61,7 @@ index 7b4b7832d38..765c2b73140 100644
  check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
  	$(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
  	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
-@@ -2742,6 +2746,10 @@ top_srcdir = @top_srcdir@
+@@ -2757,6 +2761,10 @@ top_srcdir = @top_srcdir@
  zlibdir = @zlibdir@
  zlibinc = @zlibinc@
  
@@ -73,5 +73,5 @@ index 7b4b7832d38..765c2b73140 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.35.1
+2.38.0
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2022-07-29  7:55 WANG Xuerui
  0 siblings, 0 replies; 102+ messages in thread
From: WANG Xuerui @ 2022-07-29  7:55 UTC (permalink / raw
  To: gentoo-commits

commit:     2fcd49180d8c27c14b56a5fb9fee3c26e4317dac
Author:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 29 07:54:56 2022 +0000
Commit:     WANG Xuerui <xen0n <AT> gentoo <DOT> org>
CommitDate: Fri Jul 29 07:54:56 2022 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=2fcd4918

Update patches for binutils 2.39

Signed-off-by: WANG Xuerui <xen0n <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 72 ++++++++++++++--------
 ...iberty-install-PIC-version-of-libiberty.a.patch |  4 +-
 ...oo-add-with-extra-soversion-suffix-option.patch | 30 ++++-----
 ...ss-hash-style-sysv-to-ld-in-the-testsuite.patch | 10 +--
 ...-also-libctf-optionally-a-gentoo-specific.patch | 24 ++++----
 ...0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch |  4 +-
 6 files changed, 82 insertions(+), 62 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 0dc4cf1..8e2e947 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,4 +1,4 @@
-From 322deede0713506f899ee7f284a7c82ba1ec1cf7 Mon Sep 17 00:00:00 2001
+From 6ad35e463cbd086b4d4e7bb5aca1da6b73e614c8 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
 Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system
@@ -27,12 +27,13 @@ TEST=x86_64-cros-linux-gnu-ld throws warnings when using -L/lib (gold & bfd)
 Reviewed-on: https://chromium-review.googlesource.com/272083
 (cherry picked from commit f92dbf35c00ab13cee36f6be8ae5ca46454d9000)
 
-Ported to binutils 2.37 Andreas K. Hütte <dilfridge@gentoo.org>
+Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
+Ported to binutils 2.39 by WANG Xuerui <xen0n@gentoo.org>
 ---
  gold/options.cc | 33 +++++++++++++++++++++++++++++++++
  gold/options.h  |  7 +++++++
  ld/config.in    |  3 +++
- ld/configure    | 14 ++++++++++++++
+ ld/configure    | 20 ++++++++++++++++++--
  ld/configure.ac | 10 ++++++++++
  ld/ld.h         |  7 +++++++
  ld/ld.texi      | 18 ++++++++++++++++++
@@ -40,7 +41,7 @@ Ported to binutils 2.37 Andreas K. Hütte <dilfridge@gentoo.org>
  ld/ldlex.h      |  3 +++
  ld/ldmain.c     |  7 +++++++
  ld/lexsup.c     | 24 ++++++++++++++++++++++++
- 11 files changed, 146 insertions(+)
+ 11 files changed, 150 insertions(+), 2 deletions(-)
 
 diff --git a/gold/options.cc b/gold/options.cc
 index 04be98a3e39..64439f8af7a 100644
@@ -105,10 +106,10 @@ index 9509a445e8e..a3d76b294cd 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index 26d55a00d47..ffad464783c 100644
+index 0ccd79d59cd..5e39814bce0 100644
 --- a/ld/config.in
 +++ b/ld/config.in
-@@ -43,6 +43,9 @@
+@@ -55,6 +55,9 @@
     language is requested. */
  #undef ENABLE_NLS
  
@@ -119,10 +120,10 @@ index 26d55a00d47..ffad464783c 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index f5c329c1f12..41ec6ca73ac 100755
+index 1c2b64870b1..46b5789c77e 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -831,6 +831,7 @@ with_lib_path
+@@ -836,6 +836,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -130,7 +131,7 @@ index f5c329c1f12..41ec6ca73ac 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1500,6 +1501,8 @@ Optional Features:
+@@ -1514,6 +1515,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -139,8 +140,26 @@ index f5c329c1f12..41ec6ca73ac 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -15333,7 +15336,18 @@ else
- fi
+@@ -11491,7 +11494,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11494 "configure"
++#line 11497 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11597,7 +11600,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11600 "configure"
++#line 11603 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -15349,6 +15352,19 @@ fi
+ 
  
  
 +# Check whether --enable-poison-system-directories was given.
@@ -151,15 +170,16 @@ index f5c329c1f12..41ec6ca73ac 100755
 +fi
 +
 +if test "x${enable_poison_system_directories}" = "xyes"; then
- 
++
 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
 +
 +fi
- 
- # Check whether --enable-got was given.
- if test "${enable_got+set}" = set; then :
++
+ # Check whether --enable-gold was given.
+ if test "${enable_gold+set}" = set; then :
+   enableval=$enable_gold; case "${enableval}" in
 diff --git a/ld/configure.ac b/ld/configure.ac
-index 7f4cff079b7..57d1abff870 100644
+index eb55904c090..0844c2364c5 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
 @@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
@@ -198,13 +218,13 @@ index f3086bf30de..90cf1ca51e5 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index fc75e9b3625..f7d46117bab 100644
+index eabbec8faa9..45f4858526c 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2892,6 +2892,24 @@ string identifying the original linked file does not change.
- 
- Passing @code{none} for @var{style} disables the setting from any
- @code{--build-id} options earlier on the command line.
+@@ -2947,6 +2947,24 @@ creation of the metadata note, if one had been enabled by an earlier
+ occurrence of the --package-metdata option.
+ If the linker has been built with libjansson, then the JSON string
+ will be validated.
 +
 +@kindex --warn-poison-system-directories
 +@item --warn-poison-system-directories
@@ -258,7 +278,7 @@ index 731ae5f7aed..6b67e29041b 100644
  
  /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index bc58fea73cc..cf1b015a420 100644
+index 57ade1f754b..b35a6122e09 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
 @@ -149,6 +149,9 @@ enum option_values
@@ -290,10 +310,10 @@ index ea72b14a301..706ec9ce26e 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 5acc47ed5a0..e78df2daf29 100644
+index 9225f71b3ce..db5b170bc7c 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -571,6 +571,18 @@ static const struct ld_option ld_options[] =
+@@ -579,6 +579,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -312,7 +332,7 @@ index 5acc47ed5a0..e78df2daf29 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1659,6 +1671,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1679,6 +1691,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -332,5 +352,5 @@ index 5acc47ed5a0..e78df2daf29 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.34.1
+2.35.1
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 72b99c0..34462cc 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 887d52771263fc6b8260b873e104bc57d54b3f5c Mon Sep 17 00:00:00 2001
+From 4bd606f5945ea94b1ea0db8fba206cfe67959cde Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
@@ -30,5 +30,5 @@ index abef3c4601b..9dfb6b6d2b0 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.34.1
+2.35.1
 

diff --git a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index b2b0bb5..9328241 100644
--- a/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,4 +1,4 @@
-From 820a68dff1ec2eb3836727ced1b5b74bd31daa28 Mon Sep 17 00:00:00 2001
+From 2d3d27e6c5ad343a524a117dc02358ad7cb06e0d Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
 Subject: [PATCH 3/6] Gentoo: add --with-extra-soversion-suffix= option
@@ -25,7 +25,7 @@ built with different flags (see https://bugs.gentoo.org/663690).
 Bug: https://bugs.gentoo.org/666100
 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
 
-Ported to binutils 2.37 Andreas K. Hüttel <dilfridge@gentoo.org>
+Ported to binutils 2.37 by Andreas K. Hüttel <dilfridge@gentoo.org>
 ---
  bfd/Makefile.am  |  5 +++++
  bfd/Makefile.in  |  4 ++++
@@ -34,10 +34,10 @@ Ported to binutils 2.37 Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index 10dd765bec8..e3d97adfbb3 100644
+index 670e0598f55..18d6eef60bb 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
-@@ -59,6 +59,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
+@@ -64,6 +64,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
  LIBDL = @lt_cv_dlopen_libs@
  endif
  
@@ -46,7 +46,7 @@ index 10dd765bec8..e3d97adfbb3 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -987,6 +989,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -983,6 +985,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index 10dd765bec8..e3d97adfbb3 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index f5313a2ad6f..c8cfc0474f2 100644
+index d3ef4c2524b..56fac1bb94d 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -319,6 +319,7 @@ ECHO_T = @ECHO_T@
+@@ -354,6 +354,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index f5313a2ad6f..c8cfc0474f2 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2104,6 +2105,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2453,6 +2454,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,10 +79,10 @@ index f5313a2ad6f..c8cfc0474f2 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index b09702f26e1..7a7c1229c99 100755
+index 590986efb61..299f7bb0244 100755
 --- a/bfd/configure
 +++ b/bfd/configure
-@@ -696,6 +696,7 @@ WARN_CFLAGS
+@@ -691,6 +691,7 @@ WARN_CFLAGS
  REPORT_BUGS_TEXI
  REPORT_BUGS_TO
  PKGVERSION
@@ -90,7 +90,7 @@ index b09702f26e1..7a7c1229c99 100755
  DEBUGDIR
  ENABLE_BFD_64_BIT_FALSE
  ENABLE_BFD_64_BIT_TRUE
-@@ -837,6 +838,7 @@ enable_secureplt
+@@ -832,6 +833,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -98,7 +98,7 @@ index b09702f26e1..7a7c1229c99 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1513,6 +1515,8 @@ Optional Packages:
+@@ -1508,6 +1510,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
@@ -107,7 +107,7 @@ index b09702f26e1..7a7c1229c99 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12013,6 +12017,15 @@ fi
+@@ -12014,6 +12018,15 @@ fi
  
  
  
@@ -124,7 +124,7 @@ index b09702f26e1..7a7c1229c99 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index a9078965c40..3406c071fe7 100644
+index aad4f3c83a5..e9158315bf1 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
 @@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
@@ -142,5 +142,5 @@ index a9078965c40..3406c071fe7 100644
  ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.34.1
+2.35.1
 

diff --git a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 2ac5053..caaf9c7 100644
--- a/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,4 +1,4 @@
-From 6e5bb8fa8e5f409e12098a922de72f6bdcc99603 Mon Sep 17 00:00:00 2001
+From 19d0d0a3fca319b6a14888ce709a75d9b0765561 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
 Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
@@ -9,10 +9,10 @@ Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index 93603b0be68..83ae1307f2a 100644
+index ccc33a827b4..f7aecf7edc2 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1303,7 +1303,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1310,7 +1310,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,7 +22,7 @@ index 93603b0be68..83ae1307f2a 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 5c7771f7221..ff9ee6a425c 100644
+index ec27388a72e..fc7292a40a7 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
 @@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
@@ -57,5 +57,5 @@ index 5c7771f7221..ff9ee6a425c 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.34.1
+2.35.1
 

diff --git a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 871812a..4788ee0 100644
--- a/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,4 +1,4 @@
-From f4db43e58d2f3a6e66b15ff2b25ac6850199399b Mon Sep 17 00:00:00 2001
+From ebc2d6f6c6d46a7fe77a37612ea0e12dccc467cf Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
 Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
@@ -45,7 +45,7 @@ index 27e90f0ba36..4990a20efa3 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 3b5ab73324e..10029107a05 100644
+index 1984f50867a..55772ba94b3 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
 @@ -381,6 +381,7 @@ AUTOCONF = @AUTOCONF@
@@ -80,7 +80,7 @@ index 3b5ab73324e..10029107a05 100644
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
 diff --git a/libctf/configure b/libctf/configure
-index c56ac218213..623e71477b3 100755
+index 8704bc215f4..de99d1714d7 100755
 --- a/libctf/configure
 +++ b/libctf/configure
 @@ -646,6 +646,10 @@ BUILD_INFO_FALSE
@@ -111,25 +111,25 @@ index c56ac218213..623e71477b3 100755
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11629,7 +11636,7 @@ else
+@@ -11635,7 +11642,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11632 "configure"
-+#line 11639 "configure"
+-#line 11638 "configure"
++#line 11645 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11735,7 +11742,7 @@ else
+@@ -11741,7 +11748,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11738 "configure"
-+#line 11745 "configure"
+-#line 11744 "configure"
++#line 11751 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -12942,6 +12949,26 @@ else
+@@ -12948,6 +12955,26 @@ else
  fi
  
  
@@ -156,7 +156,7 @@ index c56ac218213..623e71477b3 100755
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -13834,6 +13861,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -13840,6 +13867,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -189,5 +189,5 @@ index 4996edd5b70..103fc8b9d33 100644
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.34.1
+2.35.1
 

diff --git a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index b9435e9..318552c 100644
--- a/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,4 +1,4 @@
-From 66686e75515c742e573d25b74ce324e3d1acad08 Mon Sep 17 00:00:00 2001
+From 7eefd99e98a9396f0ce2e98e9bd86bfeb53a84dc Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
 Subject: [PATCH 6/6] Gentoo: XFAIL 15 broken ld.gold tests
@@ -73,5 +73,5 @@ index 7b4b7832d38..765c2b73140 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.34.1
+2.35.1
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2022-01-15 22:27 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2022-01-15 22:27 UTC (permalink / raw
  To: gentoo-commits

commit:     09d59da43630e66d4f7ae7145e121d06c81a2fdc
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 15 22:19:42 2022 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jan 15 22:26:47 2022 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=09d59da4

Update patches for binutils 2.38

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch |  42 ++++----
 ...iberty-install-PIC-version-of-libiberty.a.patch |   8 +-
 ...o-add-with-extra-soversion-suffix-option.patch} |  34 +++----
 ...des-link-against-libbfd.la-for-rpath-deps.patch |  49 ---------
 ...s-hash-style-sysv-to-ld-in-the-testsuite.patch} |  16 +--
 ...also-libctf-optionally-a-gentoo-specific.patch} |  94 +++++++++--------
 ...006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch} |   6 +-
 ...-soversion-suffix-then-we-also-use-the-bd.patch | 111 ---------------------
 8 files changed, 108 insertions(+), 252 deletions(-)

diff --git a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index f7443bf..0dc4cf1 100644
--- a/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,7 +1,7 @@
-From 8a82f64de912f26e840b20eec9d8a463fd0e242b Mon Sep 17 00:00:00 2001
+From 322deede0713506f899ee7f284a7c82ba1ec1cf7 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 20 Jul 2021 21:08:31 +0200
-Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system 
+Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system
  directories
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
@@ -43,7 +43,7 @@ Ported to binutils 2.37 Andreas K. Hütte <dilfridge@gentoo.org>
  11 files changed, 146 insertions(+)
 
 diff --git a/gold/options.cc b/gold/options.cc
-index 5a55bd8ba6d..f7940c75f5a 100644
+index 04be98a3e39..64439f8af7a 100644
 --- a/gold/options.cc
 +++ b/gold/options.cc
 @@ -1355,6 +1355,39 @@ General_options::finalize()
@@ -87,7 +87,7 @@ index 5a55bd8ba6d..f7940c75f5a 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index 757ebf18fec..490b4cbd7d4 100644
+index 9509a445e8e..a3d76b294cd 100644
 --- a/gold/options.h
 +++ b/gold/options.h
 @@ -1394,6 +1394,13 @@ class General_options
@@ -119,10 +119,10 @@ index 26d55a00d47..ffad464783c 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index c197aaef3cb..882263aa43f 100755
+index f5c329c1f12..41ec6ca73ac 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -829,6 +829,7 @@ with_lib_path
+@@ -831,6 +831,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -130,7 +130,7 @@ index c197aaef3cb..882263aa43f 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1498,6 +1499,8 @@ Optional Features:
+@@ -1500,6 +1501,8 @@ Optional Features:
    --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
@@ -139,7 +139,7 @@ index c197aaef3cb..882263aa43f 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -15236,7 +15239,18 @@ else
+@@ -15333,7 +15336,18 @@ else
  fi
  
  
@@ -159,10 +159,10 @@ index c197aaef3cb..882263aa43f 100755
  # Check whether --enable-got was given.
  if test "${enable_got+set}" = set; then :
 diff --git a/ld/configure.ac b/ld/configure.ac
-index 8ea97c43cd4..0f246db67d8 100644
+index 7f4cff079b7..57d1abff870 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
-@@ -106,6 +106,16 @@ AC_SUBST(use_sysroot)
+@@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
  AC_SUBST(TARGET_SYSTEM_ROOT)
  AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
  
@@ -180,7 +180,7 @@ index 8ea97c43cd4..0f246db67d8 100644
  dnl "install_as_default" is set to false if gold is the default linker.
  dnl "installed_linker" is the installed BFD linker name.
 diff --git a/ld/ld.h b/ld/ld.h
-index 35fafebfaed..4152278b8f4 100644
+index f3086bf30de..90cf1ca51e5 100644
 --- a/ld/ld.h
 +++ b/ld/ld.h
 @@ -162,6 +162,13 @@ typedef struct
@@ -198,10 +198,10 @@ index 35fafebfaed..4152278b8f4 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index dd8f571d4e4..0aee4a4e9f1 100644
+index fc75e9b3625..f7d46117bab 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2863,6 +2863,24 @@ string identifying the original linked file does not change.
+@@ -2892,6 +2892,24 @@ string identifying the original linked file does not change.
  
  Passing @code{none} for @var{style} disables the setting from any
  @code{--build-id} options earlier on the command line.
@@ -227,7 +227,7 @@ index dd8f571d4e4..0aee4a4e9f1 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 9d0af06f1f6..f4a83acca93 100644
+index 731ae5f7aed..6b67e29041b 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
 @@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
@@ -258,10 +258,10 @@ index 9d0af06f1f6..f4a83acca93 100644
  
  /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 9e8bf5fb835..3baed822a22 100644
+index bc58fea73cc..cf1b015a420 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
-@@ -148,6 +148,9 @@ enum option_values
+@@ -149,6 +149,9 @@ enum option_values
    OPTION_PRINT_OUTPUT_FORMAT,
    OPTION_PRINT_SYSROOT,
    OPTION_IGNORE_UNRESOLVED_SYMBOL,
@@ -272,7 +272,7 @@ index 9e8bf5fb835..3baed822a22 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 42660eb9a3c..c78009b760c 100644
+index ea72b14a301..706ec9ce26e 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
 @@ -321,6 +321,13 @@ main (int argc, char **argv)
@@ -290,10 +290,10 @@ index 42660eb9a3c..c78009b760c 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index 00274c500d0..a19cce9967c 100644
+index 5acc47ed5a0..e78df2daf29 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -566,6 +566,18 @@ static const struct ld_option ld_options[] =
+@@ -571,6 +571,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -312,7 +312,7 @@ index 00274c500d0..a19cce9967c 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1643,6 +1655,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1659,6 +1671,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -332,5 +332,5 @@ index 00274c500d0..a19cce9967c 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 4d5ed11..72b99c0 100644
--- a/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,4 +1,4 @@
-From 6536761c1e2756ec39fdc33c400757be3744510c Mon Sep 17 00:00:00 2001
+From 887d52771263fc6b8260b873e104bc57d54b3f5c Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
 Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
@@ -18,10 +18,10 @@ general are fairly low, and we'd rather have things work for all of them.
  1 file changed, 1 insertion(+)
 
 diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
-index d19e14a2aca..cd02be1c2fb 100644
+index abef3c4601b..9dfb6b6d2b0 100644
 --- a/libiberty/Makefile.in
 +++ b/libiberty/Makefile.in
-@@ -257,6 +257,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+@@ -258,6 +258,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
  	  $(AR) $(AR_FLAGS) $(TARGETLIB) \
  	    $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \
  	  $(RANLIB) $(TARGETLIB); \
@@ -30,5 +30,5 @@ index d19e14a2aca..cd02be1c2fb 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0004-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
similarity index 85%
rename from 9999/0004-Gentoo-add-with-extra-soversion-suffix-option.patch
rename to 9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
index 1051543..b2b0bb5 100644
--- a/9999/0004-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0003-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,7 +1,7 @@
-From 235f1f862fb9bf77e2b9f62c24db0ca801c4a057 Mon Sep 17 00:00:00 2001
+From 820a68dff1ec2eb3836727ced1b5b74bd31daa28 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Tue, 20 Jul 2021 21:12:38 +0200
-Subject: [PATCH 4/6] Gentoo: add --with-extra-soversion-suffix= option
+Subject: [PATCH 3/6] Gentoo: add --with-extra-soversion-suffix= option
 MIME-Version: 1.0
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit
@@ -34,7 +34,7 @@ Ported to binutils 2.37 Andreas K. Hüttel <dilfridge@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index ed2f701805d..dab3bfc8ed7 100644
+index 10dd765bec8..e3d97adfbb3 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -59,6 +59,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -46,7 +46,7 @@ index ed2f701805d..dab3bfc8ed7 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -952,6 +954,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -987,6 +989,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -57,10 +57,10 @@ index ed2f701805d..dab3bfc8ed7 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index 12807d99760..572df143487 100644
+index f5313a2ad6f..c8cfc0474f2 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
-@@ -318,6 +318,7 @@ ECHO_T = @ECHO_T@
+@@ -319,6 +319,7 @@ ECHO_T = @ECHO_T@
  EGREP = @EGREP@
  EXEEXT = @EXEEXT@
  EXEEXT_FOR_BUILD = @EXEEXT_FOR_BUILD@
@@ -68,7 +68,7 @@ index 12807d99760..572df143487 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2063,6 +2064,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2104,6 +2105,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -79,7 +79,7 @@ index 12807d99760..572df143487 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 41586f00f93..f0acf160913 100755
+index b09702f26e1..7a7c1229c99 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -696,6 +696,7 @@ WARN_CFLAGS
@@ -88,9 +88,9 @@ index 41586f00f93..f0acf160913 100755
  PKGVERSION
 +EXTRA_SOVERSION_SUFFIX
  DEBUGDIR
- PLUGINS_FALSE
- PLUGINS_TRUE
-@@ -835,6 +836,7 @@ enable_secureplt
+ ENABLE_BFD_64_BIT_FALSE
+ ENABLE_BFD_64_BIT_TRUE
+@@ -837,6 +838,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -98,7 +98,7 @@ index 41586f00f93..f0acf160913 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1511,6 +1513,8 @@ Optional Packages:
+@@ -1513,6 +1515,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
@@ -107,7 +107,7 @@ index 41586f00f93..f0acf160913 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -11913,6 +11917,15 @@ fi
+@@ -12013,6 +12017,15 @@ fi
  
  
  
@@ -124,10 +124,10 @@ index 41586f00f93..f0acf160913 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index fec067b2135..8c9ef9a04c0 100644
+index a9078965c40..3406c071fe7 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
-@@ -169,6 +169,13 @@ AC_ARG_WITH(separate-debug-dir,
+@@ -168,6 +168,13 @@ AC_ARG_WITH(separate-debug-dir,
  [DEBUGDIR="${withval}"])
  AC_SUBST(DEBUGDIR)
  
@@ -139,8 +139,8 @@ index fec067b2135..8c9ef9a04c0 100644
 +AC_SUBST(EXTRA_SOVERSION_SUFFIX)
 +
  ACX_PKGVERSION([GNU Binutils])
- ACX_BUGURL([https://www.sourceware.org/bugzilla/])
+ ACX_BUGURL([https://sourceware.org/bugzilla/])
  
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch b/9999/0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
deleted file mode 100644
index f3c9f8e..0000000
--- a/9999/0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
+++ /dev/null
@@ -1,49 +0,0 @@
-From c55536c61ec7e4c2e983e15f51f56f7a7c340889 Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@gentoo.org>
-Date: Tue, 5 Jul 2016 20:24:00 +0545
-Subject: [PATCH 3/6] Gentoo: opcodes: link against libbfd.la for rpath deps
-
-The reason opcodes doesn't link against libbfd.la is to workaround a
-libtool bug where it uses installed -L paths ahead of DESTDIR paths.
-The downside is that the library itself lacks rpath tags to find the
-right version of libbfd.so.
-
-Since Gentoo has patched the libtool bug for a while, we don't need
-the workaround.  Use the .la file so we get the rpath tags.
-
-URL: https://bugs.gentoo.org/563934
-(cherry picked from commit 662586237b0b00ee881e79b56f6234ff36e8bfe6)
----
- opcodes/configure    | 2 +-
- opcodes/configure.ac | 2 +-
- 2 files changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/opcodes/configure b/opcodes/configure
-index a3da5987f1b..22a05245286 100755
---- a/opcodes/configure
-+++ b/opcodes/configure
-@@ -12142,7 +12142,7 @@ if test "$enable_shared" = "yes"; then
-           SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.sl ${SHARED_LIBADD}"
- 	  ;;
- 	*)
--          SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.so ${SHARED_LIBADD}"
-+          SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
- 	  ;;
-       esac
-       SHARED_DEPENDENCIES="../bfd/libbfd.la"
-diff --git a/opcodes/configure.ac b/opcodes/configure.ac
-index e564f067334..fb6254cd69d 100644
---- a/opcodes/configure.ac
-+++ b/opcodes/configure.ac
-@@ -203,7 +203,7 @@ if test "$enable_shared" = "yes"; then
-           SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.sl ${SHARED_LIBADD}"
- 	  ;;
- 	*)
--          SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.so ${SHARED_LIBADD}"
-+          SHARED_LIBADD="../bfd/libbfd.la ${SHARED_LIBADD}"
- 	  ;;
-       esac
-       SHARED_DEPENDENCIES="../bfd/libbfd.la"
--- 
-2.31.1
-

diff --git a/9999/0006-Gentoo-Pass-hash-style-sysv.patch b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
similarity index 84%
rename from 9999/0006-Gentoo-Pass-hash-style-sysv.patch
rename to 9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
index 41b6a33..2ac5053 100644
--- a/9999/0006-Gentoo-Pass-hash-style-sysv.patch
+++ b/9999/0004-Gentoo-Pass-hash-style-sysv-to-ld-in-the-testsuite.patch
@@ -1,7 +1,7 @@
-From 905bf3c180f4f7fd07024eb9ff7851898593f3f8 Mon Sep 17 00:00:00 2001
+From 6e5bb8fa8e5f409e12098a922de72f6bdcc99603 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Tue, 20 Jul 2021 21:15:24 +0200
-Subject: [PATCH 6/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
+Subject: [PATCH 4/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
 
 ---
  binutils/testsuite/lib/binutils-common.exp |  2 +-
@@ -9,10 +9,10 @@ Subject: [PATCH 6/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index 59e25df99b0..401a05b5c32 100644
+index 93603b0be68..83ae1307f2a 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1279,7 +1279,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1303,7 +1303,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -22,10 +22,10 @@ index 59e25df99b0..401a05b5c32 100644
  
  	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 8fd14afc63e..adbeaa3bd08 100644
+index 5c7771f7221..ff9ee6a425c 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
-@@ -167,7 +167,7 @@ proc default_ld_relocate { ld target objects } {
+@@ -171,7 +171,7 @@ proc default_ld_relocate { ld target objects } {
      global HOSTING_EMU
  
      remote_file host delete $target
@@ -34,7 +34,7 @@ index 8fd14afc63e..adbeaa3bd08 100644
  }
  
  # Check to see if ld is being invoked with a non-endian output format
-@@ -198,8 +198,20 @@ proc default_ld_link { ld target objects } {
+@@ -202,8 +202,20 @@ proc default_ld_link { ld target objects } {
  	set flags [big_or_little_endian]
      }
  
@@ -57,5 +57,5 @@ index 8fd14afc63e..adbeaa3bd08 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
similarity index 68%
rename from 9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch
rename to 9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
index 6f1c6b3..871812a 100644
--- a/9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch
+++ b/9999/0005-Gentoo-Give-also-libctf-optionally-a-gentoo-specific.patch
@@ -1,29 +1,31 @@
-From d3cd41f5c7e405a8db5e85a7be9dfc42d44ef1b8 Mon Sep 17 00:00:00 2001
+From f4db43e58d2f3a6e66b15ff2b25ac6850199399b Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 24 Jul 2021 15:20:16 +0200
-Subject: [PATCH 1/2] Give also libctf optionally a gentoo-specific soversion
+Subject: [PATCH 5/6] Gentoo: Give also libctf optionally a gentoo-specific
+ soversion
 
 ---
- libctf/Makefile.am  | 13 ++++++++++++-
- libctf/Makefile.in  |  8 +++++++-
- libctf/configure    | 31 +++++++++++++++++++++++++++++--
- libctf/configure.ac |  8 ++++++++
- 4 files changed, 56 insertions(+), 4 deletions(-)
+ libctf/Makefile.am  | 14 +++++++++++++-
+ libctf/Makefile.in  |  9 ++++++++-
+ libctf/configure    | 35 +++++++++++++++++++++++++++++++++--
+ libctf/configure.ac | 10 ++++++++++
+ 4 files changed, 64 insertions(+), 4 deletions(-)
 
 diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index e586d25fb37..eabc7fa8394 100644
+index 27e90f0ba36..4990a20efa3 100644
 --- a/libctf/Makefile.am
 +++ b/libctf/Makefile.am
-@@ -21,6 +21,8 @@ ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
- 
- AUTOMAKE_OPTIONS = dejagnu foreign no-texinfo.tex
+@@ -26,6 +26,9 @@ info_TEXINFOS =
+ DISTCLEANFILES =
+ MAINTAINERCLEANFILES =
  
 +EXTRA_SOVERSION_SUFFIX = @EXTRA_SOVERSION_SUFFIX@
++BFD_VERSION = @BFD_VERSION@
 +
  # This is where we get zlib from.  zlibdir is -L../zlib and zlibinc is
  # -I../zlib, unless we were configured with --with-system-zlib, in which
  # case both are empty.
-@@ -41,8 +43,17 @@ include_HEADERS =
+@@ -46,8 +49,17 @@ include_HEADERS =
  noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
  endif
  
@@ -31,22 +33,30 @@ index e586d25fb37..eabc7fa8394 100644
 +# a supplement to the soversion. So we need to switch tracks and be creative.
 +
 +if HAVE_EXTRA_SOVERSION_SUFFIX
-+gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
++gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
 +else
 +gentoo_ctf_soversion = 0.0.0
 +endif
 +
  libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
--libctf_nobfd_la_LDFLAGS = -version-info 0:0:0 @SHARED_LDFLAGS@ @VERSION_FLAGS@
-+libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
+-libctf_ldflags_nover = -version-info 0:0:0 @SHARED_LDFLAGS@
++libctf_ldflags_nover = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@
+ libctf_nobfd_la_LDFLAGS = $(libctf_ldflags_nover) @VERSION_FLAGS_NOBFD@
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
- 			  ctf-hash.c ctf-labels.c ctf-dedup.c ctf-link.c ctf-lookup.c \
 diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index 5cfa100f9cc..b528781af97 100644
+index 3b5ab73324e..10029107a05 100644
 --- a/libctf/Makefile.in
 +++ b/libctf/Makefile.in
-@@ -338,6 +338,7 @@ EXEEXT = @EXEEXT@
+@@ -381,6 +381,7 @@ AUTOCONF = @AUTOCONF@
+ AUTOHEADER = @AUTOHEADER@
+ AUTOMAKE = @AUTOMAKE@
+ AWK = @AWK@
++BFD_VERSION = @BFD_VERSION@
+ CATALOGS = @CATALOGS@
+ CATOBJEXT = @CATOBJEXT@
+ CC = @CC@
+@@ -403,6 +404,7 @@ EXEEXT = @EXEEXT@
  
  # Setup the testing framework, if you have one
  EXPECT = expect
@@ -54,7 +64,7 @@ index 5cfa100f9cc..b528781af97 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -469,8 +470,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+@@ -540,8 +542,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
  @INSTALL_LIBBFD_FALSE@include_HEADERS = 
  @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/ctf.h $(INCDIR)/ctf-api.h
  @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
@@ -62,28 +72,29 @@ index 5cfa100f9cc..b528781af97 100644
 +
 +# libctf by default uses libtool versioning. Unfortunately that keeps us from adding
 +# a supplement to the soversion. So we need to switch tracks and be creative.
-+@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
++@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
  libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
--libctf_nobfd_la_LDFLAGS = -version-info 0:0:0 @SHARED_LDFLAGS@ @VERSION_FLAGS@
-+libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
+-libctf_ldflags_nover = -version-info 0:0:0 @SHARED_LDFLAGS@
++libctf_ldflags_nover = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@
+ libctf_nobfd_la_LDFLAGS = $(libctf_ldflags_nover) @VERSION_FLAGS_NOBFD@
  libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
  libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
- 	ctf-decl.c ctf-error.c ctf-hash.c ctf-labels.c ctf-dedup.c \
 diff --git a/libctf/configure b/libctf/configure
-index 82bcf13a606..e961f637a69 100755
+index c56ac218213..623e71477b3 100755
 --- a/libctf/configure
 +++ b/libctf/configure
-@@ -643,6 +643,9 @@ CTF_LIBADD
- SHARED_LDFLAGS
+@@ -646,6 +646,10 @@ BUILD_INFO_FALSE
+ BUILD_INFO_TRUE
  NEED_CTF_QSORT_R_FALSE
  NEED_CTF_QSORT_R_TRUE
++BFD_VERSION
 +HAVE_EXTRA_SOVERSION_SUFFIX_FALSE
 +HAVE_EXTRA_SOVERSION_SUFFIX_TRUE
 +EXTRA_SOVERSION_SUFFIX
  ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
  ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
  zlibinc
-@@ -804,6 +807,7 @@ enable_maintainer_mode
+@@ -807,6 +811,7 @@ enable_maintainer_mode
  enable_install_libbfd
  with_system_zlib
  enable_libctf_hash_debugging
@@ -91,7 +102,7 @@ index 82bcf13a606..e961f637a69 100755
  '
        ac_precious_vars='build_alias
  host_alias
-@@ -1461,6 +1465,8 @@ Optional Packages:
+@@ -1464,6 +1469,8 @@ Optional Packages:
                            both]
    --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
    --with-system-zlib      use installed libz
@@ -100,25 +111,25 @@ index 82bcf13a606..e961f637a69 100755
  
  Some influential environment variables:
    CC          C compiler command
-@@ -11586,7 +11592,7 @@ else
+@@ -11629,7 +11636,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11589 "configure"
-+#line 11607 "configure"
+-#line 11632 "configure"
++#line 11639 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -11692,7 +11698,7 @@ else
+@@ -11735,7 +11742,7 @@ else
    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    lt_status=$lt_dlunknown
    cat > conftest.$ac_ext <<_LT_EOF
--#line 11695 "configure"
-+#line 11713 "configure"
+-#line 11738 "configure"
++#line 11745 "configure"
  #include "confdefs.h"
  
  #if HAVE_DLFCN_H
-@@ -12899,6 +12905,23 @@ else
+@@ -12942,6 +12949,26 @@ else
  fi
  
  
@@ -138,11 +149,14 @@ index 82bcf13a606..e961f637a69 100755
 +  HAVE_EXTRA_SOVERSION_SUFFIX_FALSE=
 +fi
 +
++
++BFD_VERSION=$(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p')
++
 +
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
-@@ -13657,6 +13680,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+@@ -13834,6 +13861,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
    as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
  Usually this means the macro was only invoked conditionally." "$LINENO" 5
  fi
@@ -154,10 +168,10 @@ index 82bcf13a606..e961f637a69 100755
  if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
    as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
 diff --git a/libctf/configure.ac b/libctf/configure.ac
-index 80644b89d67..f7e6180afd8 100644
+index 4996edd5b70..103fc8b9d33 100644
 --- a/libctf/configure.ac
 +++ b/libctf/configure.ac
-@@ -77,6 +77,14 @@ if test "${enable_libctf_hash_debugging}" = yes; then
+@@ -78,6 +78,16 @@ if test "${enable_libctf_hash_debugging}" = yes; then
  fi
  AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
  
@@ -168,10 +182,12 @@ index 80644b89d67..f7e6180afd8 100644
 +[EXTRA_SOVERSION_SUFFIX="${withval}"])
 +AC_SUBST(EXTRA_SOVERSION_SUFFIX)
 +AM_CONDITIONAL([HAVE_EXTRA_SOVERSION_SUFFIX], [test -n "${with_extra_soversion_suffix}"])
++
++AC_SUBST(BFD_VERSION, $(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p'), [Version of the accompanying bfd linker])
 +
  # Similar to GDB_AC_CHECK_BFD.
  OLD_CFLAGS=$CFLAGS
  OLD_LDFLAGS=$LDFLAGS
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0020-XFAIL-15-broken-ld.gold-tests.patch b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
similarity index 95%
rename from 9999/0020-XFAIL-15-broken-ld.gold-tests.patch
rename to 9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
index 777390f..b9435e9 100644
--- a/9999/0020-XFAIL-15-broken-ld.gold-tests.patch
+++ b/9999/0006-Gentoo-XFAIL-15-broken-ld.gold-tests.patch
@@ -1,7 +1,7 @@
-From 6f9a3d6ffa2bcf91bc047055848591dab77c0f11 Mon Sep 17 00:00:00 2001
+From 66686e75515c742e573d25b74ce324e3d1acad08 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sat, 31 Jul 2021 01:18:18 +0200
-Subject: [PATCH] Gentoo: XFAIL 15 broken ld.gold tests
+Subject: [PATCH 6/6] Gentoo: XFAIL 15 broken ld.gold tests
 
 It seems like either the tests or ld.gold in general cannot handle
 compilers built with --enable-default-pie. No fix yet, so let's ignore
@@ -73,5 +73,5 @@ index 7b4b7832d38..765c2b73140 100644
  AUTOMAKE_OPTIONS = foreign -Wno-portability
  
 -- 
-2.31.1
+2.34.1
 

diff --git a/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch b/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch
deleted file mode 100644
index b88f50e..0000000
--- a/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch
+++ /dev/null
@@ -1,111 +0,0 @@
-From 235448cc5c53641417e17fd39ced95a21053c8ca Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sat, 24 Jul 2021 19:25:32 +0200
-Subject: [PATCH 2/2] If we use a soversion suffix, then we also use the bdf
- version as soversion
-
----
- libctf/Makefile.am  | 3 ++-
- libctf/Makefile.in  | 3 ++-
- libctf/configure    | 8 ++++++--
- libctf/configure.ac | 2 ++
- 4 files changed, 12 insertions(+), 4 deletions(-)
-
-diff --git a/libctf/Makefile.am b/libctf/Makefile.am
-index eabc7fa8394..e1304e8e89b 100644
---- a/libctf/Makefile.am
-+++ b/libctf/Makefile.am
-@@ -22,6 +22,7 @@ ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
- AUTOMAKE_OPTIONS = dejagnu foreign no-texinfo.tex
- 
- EXTRA_SOVERSION_SUFFIX = @EXTRA_SOVERSION_SUFFIX@
-+BFD_VERSION = @BFD_VERSION@
- 
- # This is where we get zlib from.  zlibdir is -L../zlib and zlibinc is
- # -I../zlib, unless we were configured with --with-system-zlib, in which
-@@ -47,7 +48,7 @@ endif
- # a supplement to the soversion. So we need to switch tracks and be creative.
- 
- if HAVE_EXTRA_SOVERSION_SUFFIX
--gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
-+gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
- else
- gentoo_ctf_soversion = 0.0.0
- endif
-diff --git a/libctf/Makefile.in b/libctf/Makefile.in
-index b528781af97..18d482411e8 100644
---- a/libctf/Makefile.in
-+++ b/libctf/Makefile.in
-@@ -316,6 +316,7 @@ AUTOCONF = @AUTOCONF@
- AUTOHEADER = @AUTOHEADER@
- AUTOMAKE = @AUTOMAKE@
- AWK = @AWK@
-+BFD_VERSION = @BFD_VERSION@
- CATALOGS = @CATALOGS@
- CATOBJEXT = @CATOBJEXT@
- CC = @CC@
-@@ -474,7 +475,7 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
- 
- # libctf by default uses libtool versioning. Unfortunately that keeps us from adding
- # a supplement to the soversion. So we need to switch tracks and be creative.
--@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
-+@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
- libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
- libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
- libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
-diff --git a/libctf/configure b/libctf/configure
-index e961f637a69..520d3a5cb3e 100755
---- a/libctf/configure
-+++ b/libctf/configure
-@@ -643,6 +643,7 @@ CTF_LIBADD
- SHARED_LDFLAGS
- NEED_CTF_QSORT_R_FALSE
- NEED_CTF_QSORT_R_TRUE
-+BFD_VERSION
- HAVE_EXTRA_SOVERSION_SUFFIX_FALSE
- HAVE_EXTRA_SOVERSION_SUFFIX_TRUE
- EXTRA_SOVERSION_SUFFIX
-@@ -11592,7 +11593,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11607 "configure"
-+#line 11608 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -11698,7 +11699,7 @@ else
-   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-   lt_status=$lt_dlunknown
-   cat > conftest.$ac_ext <<_LT_EOF
--#line 11713 "configure"
-+#line 11714 "configure"
- #include "confdefs.h"
- 
- #if HAVE_DLFCN_H
-@@ -12922,6 +12923,9 @@ else
- fi
- 
- 
-+BFD_VERSION=$(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p')
-+
-+
- # Similar to GDB_AC_CHECK_BFD.
- OLD_CFLAGS=$CFLAGS
- OLD_LDFLAGS=$LDFLAGS
-diff --git a/libctf/configure.ac b/libctf/configure.ac
-index f7e6180afd8..5306e5499ec 100644
---- a/libctf/configure.ac
-+++ b/libctf/configure.ac
-@@ -85,6 +85,8 @@ AC_ARG_WITH(extra-soversion-suffix,
- AC_SUBST(EXTRA_SOVERSION_SUFFIX)
- AM_CONDITIONAL([HAVE_EXTRA_SOVERSION_SUFFIX], [test -n "${with_extra_soversion_suffix}"])
- 
-+AC_SUBST(BFD_VERSION, $(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p'), [Version of the accompanying bfd linker])
-+
- # Similar to GDB_AC_CHECK_BFD.
- OLD_CFLAGS=$CFLAGS
- OLD_LDFLAGS=$LDFLAGS
--- 
-2.31.1
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-30 23:25 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2021-07-30 23:25 UTC (permalink / raw
  To: gentoo-commits

commit:     7d4ad0cdad6d8eda51cc091f9357fe9d13c3f1e2
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 30 23:25:06 2021 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Fri Jul 30 23:25:06 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=7d4ad0cd

XFAIL 15 broken ld.gold tests

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 9999/0020-XFAIL-15-broken-ld.gold-tests.patch | 77 +++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/9999/0020-XFAIL-15-broken-ld.gold-tests.patch b/9999/0020-XFAIL-15-broken-ld.gold-tests.patch
new file mode 100644
index 0000000..777390f
--- /dev/null
+++ b/9999/0020-XFAIL-15-broken-ld.gold-tests.patch
@@ -0,0 +1,77 @@
+From 6f9a3d6ffa2bcf91bc047055848591dab77c0f11 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Sat, 31 Jul 2021 01:18:18 +0200
+Subject: [PATCH] Gentoo: XFAIL 15 broken ld.gold tests
+
+It seems like either the tests or ld.gold in general cannot handle
+compilers built with --enable-default-pie. No fix yet, so let's ignore
+these test failures for the moment. For details see the linked bugs.
+
+Bug: https://bugs.gentoo.org/684046
+Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22755
+Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27303
+---
+ gold/testsuite/Makefile.am |  6 ++++++
+ gold/testsuite/Makefile.in | 16 ++++++++++++----
+ 2 files changed, 18 insertions(+), 4 deletions(-)
+
+diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
+index 38e54818f48..85c94d40660 100644
+--- a/gold/testsuite/Makefile.am
++++ b/gold/testsuite/Makefile.am
+@@ -1,5 +1,11 @@
+ # Process this file with automake to generate Makefile.in
+ 
++# Gentoo, https://bugs.gentoo.org/684046
++XFAIL_TESTS = exception_separate_shared_12_test exception_separate_shared_21_test \
++	weak_undef_test initpri3a justsyms_exec script_test_2 script_test_1 \
++	justsyms binary_test script_test_3 tls_phdrs_script_test script_test_12i \
++	dynamic_list_2 incremental_test_2 incremental_test_5
++
+ # As far as I can tell automake testing support assumes that the build
+ # system and the host system are the same.  So these tests will not
+ # work when building with a cross-compiler.
+diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
+index 7b4b7832d38..765c2b73140 100644
+--- a/gold/testsuite/Makefile.in
++++ b/gold/testsuite/Makefile.in
+@@ -15,10 +15,6 @@
+ @SET_MAKE@
+ 
+ # Process this file with automake to generate Makefile.in
+-
+-# As far as I can tell automake testing support assumes that the build
+-# system and the host system are the same.  So these tests will not
+-# work when building with a cross-compiler.
+ VPATH = @srcdir@
+ am__is_gnu_make = { \
+   if test -z '$(MAKELEVEL)'; then \
+@@ -94,6 +90,14 @@ POST_UNINSTALL = :
+ build_triplet = @build@
+ host_triplet = @host@
+ target_triplet = @target@
++XFAIL_TESTS = exception_separate_shared_12_test$(EXEEXT) \
++	exception_separate_shared_21_test$(EXEEXT) \
++	weak_undef_test$(EXEEXT) initpri3a$(EXEEXT) \
++	justsyms_exec$(EXEEXT) script_test_2$(EXEEXT) \
++	script_test_1$(EXEEXT) justsyms$(EXEEXT) binary_test$(EXEEXT) \
++	script_test_3$(EXEEXT) tls_phdrs_script_test$(EXEEXT) \
++	script_test_12i$(EXEEXT) dynamic_list_2$(EXEEXT) \
++	incremental_test_2$(EXEEXT) incremental_test_5$(EXEEXT)
+ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
+ 	$(am__EXEEXT_4) $(am__EXEEXT_5) $(am__EXEEXT_6) \
+ 	$(am__EXEEXT_7) $(am__EXEEXT_8) $(am__EXEEXT_9) \
+@@ -2742,6 +2746,10 @@ top_srcdir = @top_srcdir@
+ zlibdir = @zlibdir@
+ zlibinc = @zlibinc@
+ 
++# As far as I can tell automake testing support assumes that the build
++# system and the host system are the same.  So these tests will not
++# work when building with a cross-compiler.
++
+ # Ignore warning about AM_PROG_CC_C_O due to large_CFLAGS
+ AUTOMAKE_OPTIONS = foreign -Wno-portability
+ 
+-- 
+2.31.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-24 20:57 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2021-07-24 20:57 UTC (permalink / raw
  To: gentoo-commits

commit:     bc2a10f35b091063cf84b9cfd5300b6c0f0cf428
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 24 19:40:41 2021 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jul 24 19:40:41 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=bc2a10f3

Add libctf soversion patches

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...ibctf-optionally-a-gentoo-specific-sovers.patch | 177 +++++++++++++++++++++
 ...-soversion-suffix-then-we-also-use-the-bd.patch | 111 +++++++++++++
 2 files changed, 288 insertions(+)

diff --git a/9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch b/9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch
new file mode 100644
index 0000000..6f1c6b3
--- /dev/null
+++ b/9999/0007-Give-also-libctf-optionally-a-gentoo-specific-sovers.patch
@@ -0,0 +1,177 @@
+From d3cd41f5c7e405a8db5e85a7be9dfc42d44ef1b8 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Sat, 24 Jul 2021 15:20:16 +0200
+Subject: [PATCH 1/2] Give also libctf optionally a gentoo-specific soversion
+
+---
+ libctf/Makefile.am  | 13 ++++++++++++-
+ libctf/Makefile.in  |  8 +++++++-
+ libctf/configure    | 31 +++++++++++++++++++++++++++++--
+ libctf/configure.ac |  8 ++++++++
+ 4 files changed, 56 insertions(+), 4 deletions(-)
+
+diff --git a/libctf/Makefile.am b/libctf/Makefile.am
+index e586d25fb37..eabc7fa8394 100644
+--- a/libctf/Makefile.am
++++ b/libctf/Makefile.am
+@@ -21,6 +21,8 @@ ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
+ 
+ AUTOMAKE_OPTIONS = dejagnu foreign no-texinfo.tex
+ 
++EXTRA_SOVERSION_SUFFIX = @EXTRA_SOVERSION_SUFFIX@
++
+ # This is where we get zlib from.  zlibdir is -L../zlib and zlibinc is
+ # -I../zlib, unless we were configured with --with-system-zlib, in which
+ # case both are empty.
+@@ -41,8 +43,17 @@ include_HEADERS =
+ noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
+ endif
+ 
++# libctf by default uses libtool versioning. Unfortunately that keeps us from adding
++# a supplement to the soversion. So we need to switch tracks and be creative.
++
++if HAVE_EXTRA_SOVERSION_SUFFIX
++gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
++else
++gentoo_ctf_soversion = 0.0.0
++endif
++
+ libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
+-libctf_nobfd_la_LDFLAGS = -version-info 0:0:0 @SHARED_LDFLAGS@ @VERSION_FLAGS@
++libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
+ libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
+ libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c ctf-decl.c ctf-error.c \
+ 			  ctf-hash.c ctf-labels.c ctf-dedup.c ctf-link.c ctf-lookup.c \
+diff --git a/libctf/Makefile.in b/libctf/Makefile.in
+index 5cfa100f9cc..b528781af97 100644
+--- a/libctf/Makefile.in
++++ b/libctf/Makefile.in
+@@ -338,6 +338,7 @@ EXEEXT = @EXEEXT@
+ 
+ # Setup the testing framework, if you have one
+ EXPECT = expect
++EXTRA_SOVERSION_SUFFIX = @EXTRA_SOVERSION_SUFFIX@
+ FGREP = @FGREP@
+ GENCAT = @GENCAT@
+ GMSGFMT = @GMSGFMT@
+@@ -469,8 +470,13 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+ @INSTALL_LIBBFD_FALSE@include_HEADERS = 
+ @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/ctf.h $(INCDIR)/ctf-api.h
+ @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libctf.la libctf-nobfd.la
++@HAVE_EXTRA_SOVERSION_SUFFIX_FALSE@gentoo_ctf_soversion = 0.0.0
++
++# libctf by default uses libtool versioning. Unfortunately that keeps us from adding
++# a supplement to the soversion. So we need to switch tracks and be creative.
++@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
+ libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
+-libctf_nobfd_la_LDFLAGS = -version-info 0:0:0 @SHARED_LDFLAGS@ @VERSION_FLAGS@
++libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
+ libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
+ libctf_nobfd_la_SOURCES = ctf-archive.c ctf-dump.c ctf-create.c \
+ 	ctf-decl.c ctf-error.c ctf-hash.c ctf-labels.c ctf-dedup.c \
+diff --git a/libctf/configure b/libctf/configure
+index 82bcf13a606..e961f637a69 100755
+--- a/libctf/configure
++++ b/libctf/configure
+@@ -643,6 +643,9 @@ CTF_LIBADD
+ SHARED_LDFLAGS
+ NEED_CTF_QSORT_R_FALSE
+ NEED_CTF_QSORT_R_TRUE
++HAVE_EXTRA_SOVERSION_SUFFIX_FALSE
++HAVE_EXTRA_SOVERSION_SUFFIX_TRUE
++EXTRA_SOVERSION_SUFFIX
+ ENABLE_LIBCTF_HASH_DEBUGGING_FALSE
+ ENABLE_LIBCTF_HASH_DEBUGGING_TRUE
+ zlibinc
+@@ -804,6 +807,7 @@ enable_maintainer_mode
+ enable_install_libbfd
+ with_system_zlib
+ enable_libctf_hash_debugging
++with_extra_soversion_suffix
+ '
+       ac_precious_vars='build_alias
+ host_alias
+@@ -1461,6 +1465,8 @@ Optional Packages:
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+   --with-system-zlib      use installed libz
++  --with-extra-soversion-suffix=SUFFIX
++                          Append '.SUFFIX' to SONAME [[default=]]
+ 
+ Some influential environment variables:
+   CC          C compiler command
+@@ -11586,7 +11592,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11589 "configure"
++#line 11607 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11692,7 +11698,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11695 "configure"
++#line 11713 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12899,6 +12905,23 @@ else
+ fi
+ 
+ 
++EXTRA_SOVERSION_SUFFIX=
++
++# Check whether --with-extra-soversion-suffix was given.
++if test "${with_extra_soversion_suffix+set}" = set; then :
++  withval=$with_extra_soversion_suffix; EXTRA_SOVERSION_SUFFIX="${withval}"
++fi
++
++
++ if test -n "${with_extra_soversion_suffix}"; then
++  HAVE_EXTRA_SOVERSION_SUFFIX_TRUE=
++  HAVE_EXTRA_SOVERSION_SUFFIX_FALSE='#'
++else
++  HAVE_EXTRA_SOVERSION_SUFFIX_TRUE='#'
++  HAVE_EXTRA_SOVERSION_SUFFIX_FALSE=
++fi
++
++
+ # Similar to GDB_AC_CHECK_BFD.
+ OLD_CFLAGS=$CFLAGS
+ OLD_LDFLAGS=$LDFLAGS
+@@ -13657,6 +13680,10 @@ if test -z "${ENABLE_LIBCTF_HASH_DEBUGGING_TRUE}" && test -z "${ENABLE_LIBCTF_HA
+   as_fn_error $? "conditional \"ENABLE_LIBCTF_HASH_DEBUGGING\" was never defined.
+ Usually this means the macro was only invoked conditionally." "$LINENO" 5
+ fi
++if test -z "${HAVE_EXTRA_SOVERSION_SUFFIX_TRUE}" && test -z "${HAVE_EXTRA_SOVERSION_SUFFIX_FALSE}"; then
++  as_fn_error $? "conditional \"HAVE_EXTRA_SOVERSION_SUFFIX\" was never defined.
++Usually this means the macro was only invoked conditionally." "$LINENO" 5
++fi
+ 
+ if test -z "${NEED_CTF_QSORT_R_TRUE}" && test -z "${NEED_CTF_QSORT_R_FALSE}"; then
+   as_fn_error $? "conditional \"NEED_CTF_QSORT_R\" was never defined.
+diff --git a/libctf/configure.ac b/libctf/configure.ac
+index 80644b89d67..f7e6180afd8 100644
+--- a/libctf/configure.ac
++++ b/libctf/configure.ac
+@@ -77,6 +77,14 @@ if test "${enable_libctf_hash_debugging}" = yes; then
+ fi
+ AM_CONDITIONAL(ENABLE_LIBCTF_HASH_DEBUGGING, test "${enable_libctf_hash_debugging}" = yes)
+ 
++EXTRA_SOVERSION_SUFFIX=
++AC_ARG_WITH(extra-soversion-suffix,
++  AS_HELP_STRING([--with-extra-soversion-suffix=SUFFIX],
++                 [Append '.SUFFIX' to SONAME [[default=]]]),
++[EXTRA_SOVERSION_SUFFIX="${withval}"])
++AC_SUBST(EXTRA_SOVERSION_SUFFIX)
++AM_CONDITIONAL([HAVE_EXTRA_SOVERSION_SUFFIX], [test -n "${with_extra_soversion_suffix}"])
++
+ # Similar to GDB_AC_CHECK_BFD.
+ OLD_CFLAGS=$CFLAGS
+ OLD_LDFLAGS=$LDFLAGS
+-- 
+2.31.1
+

diff --git a/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch b/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch
new file mode 100644
index 0000000..b88f50e
--- /dev/null
+++ b/9999/0008-If-we-use-a-soversion-suffix-then-we-also-use-the-bd.patch
@@ -0,0 +1,111 @@
+From 235448cc5c53641417e17fd39ced95a21053c8ca Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Sat, 24 Jul 2021 19:25:32 +0200
+Subject: [PATCH 2/2] If we use a soversion suffix, then we also use the bdf
+ version as soversion
+
+---
+ libctf/Makefile.am  | 3 ++-
+ libctf/Makefile.in  | 3 ++-
+ libctf/configure    | 8 ++++++--
+ libctf/configure.ac | 2 ++
+ 4 files changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/libctf/Makefile.am b/libctf/Makefile.am
+index eabc7fa8394..e1304e8e89b 100644
+--- a/libctf/Makefile.am
++++ b/libctf/Makefile.am
+@@ -22,6 +22,7 @@ ACLOCAL_AMFLAGS = -I .. -I ../config -I ../bfd
+ AUTOMAKE_OPTIONS = dejagnu foreign no-texinfo.tex
+ 
+ EXTRA_SOVERSION_SUFFIX = @EXTRA_SOVERSION_SUFFIX@
++BFD_VERSION = @BFD_VERSION@
+ 
+ # This is where we get zlib from.  zlibdir is -L../zlib and zlibinc is
+ # -I../zlib, unless we were configured with --with-system-zlib, in which
+@@ -47,7 +48,7 @@ endif
+ # a supplement to the soversion. So we need to switch tracks and be creative.
+ 
+ if HAVE_EXTRA_SOVERSION_SUFFIX
+-gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
++gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
+ else
+ gentoo_ctf_soversion = 0.0.0
+ endif
+diff --git a/libctf/Makefile.in b/libctf/Makefile.in
+index b528781af97..18d482411e8 100644
+--- a/libctf/Makefile.in
++++ b/libctf/Makefile.in
+@@ -316,6 +316,7 @@ AUTOCONF = @AUTOCONF@
+ AUTOHEADER = @AUTOHEADER@
+ AUTOMAKE = @AUTOMAKE@
+ AWK = @AWK@
++BFD_VERSION = @BFD_VERSION@
+ CATALOGS = @CATALOGS@
+ CATOBJEXT = @CATOBJEXT@
+ CC = @CC@
+@@ -474,7 +475,7 @@ AM_CFLAGS = -std=gnu99 @ac_libctf_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC@ @
+ 
+ # libctf by default uses libtool versioning. Unfortunately that keeps us from adding
+ # a supplement to the soversion. So we need to switch tracks and be creative.
+-@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = 0.0.0.$(EXTRA_SOVERSION_SUFFIX)
++@HAVE_EXTRA_SOVERSION_SUFFIX_TRUE@gentoo_ctf_soversion = "$(BFD_VERSION).$(EXTRA_SOVERSION_SUFFIX)"
+ libctf_nobfd_la_LIBADD = @CTF_LIBADD@ $(ZLIB)
+ libctf_nobfd_la_LDFLAGS = -release $(gentoo_ctf_soversion) @SHARED_LDFLAGS@ @VERSION_FLAGS@
+ libctf_nobfd_la_CPPFLAGS = $(AM_CPPFLAGS) -DNOBFD=1
+diff --git a/libctf/configure b/libctf/configure
+index e961f637a69..520d3a5cb3e 100755
+--- a/libctf/configure
++++ b/libctf/configure
+@@ -643,6 +643,7 @@ CTF_LIBADD
+ SHARED_LDFLAGS
+ NEED_CTF_QSORT_R_FALSE
+ NEED_CTF_QSORT_R_TRUE
++BFD_VERSION
+ HAVE_EXTRA_SOVERSION_SUFFIX_FALSE
+ HAVE_EXTRA_SOVERSION_SUFFIX_TRUE
+ EXTRA_SOVERSION_SUFFIX
+@@ -11592,7 +11593,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11607 "configure"
++#line 11608 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11698,7 +11699,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11713 "configure"
++#line 11714 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12922,6 +12923,9 @@ else
+ fi
+ 
+ 
++BFD_VERSION=$(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p')
++
++
+ # Similar to GDB_AC_CHECK_BFD.
+ OLD_CFLAGS=$CFLAGS
+ OLD_LDFLAGS=$LDFLAGS
+diff --git a/libctf/configure.ac b/libctf/configure.ac
+index f7e6180afd8..5306e5499ec 100644
+--- a/libctf/configure.ac
++++ b/libctf/configure.ac
+@@ -85,6 +85,8 @@ AC_ARG_WITH(extra-soversion-suffix,
+ AC_SUBST(EXTRA_SOVERSION_SUFFIX)
+ AM_CONDITIONAL([HAVE_EXTRA_SOVERSION_SUFFIX], [test -n "${with_extra_soversion_suffix}"])
+ 
++AC_SUBST(BFD_VERSION, $(${srcdir}/../bfd/configure --version | sed -n -e '1s,.* ,,p'), [Version of the accompanying bfd linker])
++
+ # Similar to GDB_AC_CHECK_BFD.
+ OLD_CFLAGS=$CFLAGS
+ OLD_LDFLAGS=$LDFLAGS
+-- 
+2.31.1
+


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-20 19:53 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2021-07-20 19:53 UTC (permalink / raw
  To: gentoo-commits

commit:     c32b45b7537a82b63613ea95e00f8468d31a25d9
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 20 19:52:55 2021 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Tue Jul 20 19:52:55 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=c32b45b7

Renumber patches

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...ch => 0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch} | 0
 ...tch => 0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch} | 0
 ...ch => 0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch} | 0
 ...ion.patch => 0004-Gentoo-add-with-extra-soversion-suffix-option.patch} | 0
 ...ch => 0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch} | 0
 ...-Pass-hash-style-sysv.patch => 0006-Gentoo-Pass-hash-style-sysv.patch} | 0
 6 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
similarity index 100%
rename from 9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
rename to 9999/0001-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch

diff --git a/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
similarity index 100%
rename from 9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
rename to 9999/0002-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch

diff --git a/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch b/9999/0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
similarity index 100%
rename from 9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
rename to 9999/0003-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch

diff --git a/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0004-Gentoo-add-with-extra-soversion-suffix-option.patch
similarity index 100%
rename from 9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
rename to 9999/0004-Gentoo-add-with-extra-soversion-suffix-option.patch

diff --git a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
similarity index 100%
rename from 9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
rename to 9999/0005-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch

diff --git a/9999/0009-Gentoo-Pass-hash-style-sysv.patch b/9999/0006-Gentoo-Pass-hash-style-sysv.patch
similarity index 100%
rename from 9999/0009-Gentoo-Pass-hash-style-sysv.patch
rename to 9999/0006-Gentoo-Pass-hash-style-sysv.patch


^ permalink raw reply	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-20 19:50 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2021-07-20 19:50 UTC (permalink / raw
  To: gentoo-commits

commit:     3aebcafb84cf90109ca2b1b942ed0b71f30b8bd2
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 20 19:22:10 2021 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Tue Jul 20 19:22:10 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=3aebcafb

9999: Refresh patches at 2.37 release

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 63 ++++++++++++----------
 ...iberty-install-PIC-version-of-libiberty.a.patch | 10 ++--
 ...des-link-against-libbfd.la-for-rpath-deps.patch | 14 ++---
 ...oo-add-with-extra-soversion-suffix-option.patch | 35 ++++++------
 ...nable-new-dtags-by-default-for-linux-gnu-.patch |  9 ++--
 9999/0009-Gentoo-Pass-hash-style-sysv.patch        | 20 +++----
 6 files changed, 81 insertions(+), 70 deletions(-)

diff --git a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 964946c..f7443bf 100644
--- a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,8 +1,11 @@
-From c251ab646d98b3f0e8f8b1ae5e94c672325477e2 Mon Sep 17 00:00:00 2001
+From 8a82f64de912f26e840b20eec9d8a463fd0e242b Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
-Date: Tue, 10 Oct 2017 22:53:53 +0200
-Subject: [PATCH 3/9] Gentoo: gold/ld: add support for poisoned system
+Date: Tue, 20 Jul 2021 21:08:31 +0200
+Subject: [PATCH 1/6] Gentoo: gold/ld: add support for poisoned system 
  directories
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
 
 This is based on the old CodeSourcery patch written by Joseph Myers to add
 support to the link for detecting & rejecting bad -L paths when using a
@@ -23,6 +26,8 @@ TEST=x86_64-cros-linux-gnu-ld throws warnings when using -L/lib (gold & bfd)
 
 Reviewed-on: https://chromium-review.googlesource.com/272083
 (cherry picked from commit f92dbf35c00ab13cee36f6be8ae5ca46454d9000)
+
+Ported to binutils 2.37 Andreas K. Hütte <dilfridge@gentoo.org>
 ---
  gold/options.cc | 33 +++++++++++++++++++++++++++++++++
  gold/options.h  |  7 +++++++
@@ -38,10 +43,10 @@ Reviewed-on: https://chromium-review.googlesource.com/272083
  11 files changed, 146 insertions(+)
 
 diff --git a/gold/options.cc b/gold/options.cc
-index 94867b361a..704d5d089e 100644
+index 5a55bd8ba6d..f7940c75f5a 100644
 --- a/gold/options.cc
 +++ b/gold/options.cc
-@@ -1290,6 +1290,39 @@ General_options::finalize()
+@@ -1355,6 +1355,39 @@ General_options::finalize()
    // in the path, as appropriate.
    this->add_sysroot();
  
@@ -82,10 +87,10 @@ index 94867b361a..704d5d089e 100644
    if (this->shared() && this->is_static())
      gold_fatal(_("-shared and -static are incompatible"));
 diff --git a/gold/options.h b/gold/options.h
-index b2059d984c..b60f802754 100644
+index 757ebf18fec..490b4cbd7d4 100644
 --- a/gold/options.h
 +++ b/gold/options.h
-@@ -1375,6 +1375,13 @@ class General_options
+@@ -1394,6 +1394,13 @@ class General_options
    DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
  	      N_("Ignored"), NULL);
  
@@ -100,10 +105,10 @@ index b2059d984c..b60f802754 100644
  	      N_("Warn when skipping an incompatible library"),
  	      N_("Don't warn when skipping an incompatible library"));
 diff --git a/ld/config.in b/ld/config.in
-index d93c9b0830..5da2742bea 100644
+index 26d55a00d47..ffad464783c 100644
 --- a/ld/config.in
 +++ b/ld/config.in
-@@ -31,6 +31,9 @@
+@@ -43,6 +43,9 @@
     language is requested. */
  #undef ENABLE_NLS
  
@@ -114,10 +119,10 @@ index d93c9b0830..5da2742bea 100644
  #undef EXTRA_SHLIB_EXTENSION
  
 diff --git a/ld/configure b/ld/configure
-index e1dbc95747..460078f6e8 100755
+index c197aaef3cb..882263aa43f 100755
 --- a/ld/configure
 +++ b/ld/configure
-@@ -826,6 +826,7 @@ with_lib_path
+@@ -829,6 +829,7 @@ with_lib_path
  enable_targets
  enable_64_bit_bfd
  with_sysroot
@@ -125,8 +130,8 @@ index e1dbc95747..460078f6e8 100755
  enable_gold
  enable_got
  enable_compressed_debug_sections
-@@ -1491,6 +1492,8 @@ Optional Features:
-   --disable-largefile     omit support for large files
+@@ -1498,6 +1499,8 @@ Optional Features:
+   --enable-checking       enable run-time checks
    --enable-targets        alternative target configurations
    --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
 +  --enable-poison-system-directories
@@ -134,7 +139,7 @@ index e1dbc95747..460078f6e8 100755
    --enable-gold[=ARG]     build gold [ARG={default,yes,no}]
    --enable-got=<type>     GOT handling scheme (target, single, negative,
                            multigot)
-@@ -15809,7 +15812,18 @@ else
+@@ -15236,7 +15239,18 @@ else
  fi
  
  
@@ -154,10 +159,10 @@ index e1dbc95747..460078f6e8 100755
  # Check whether --enable-got was given.
  if test "${enable_got+set}" = set; then :
 diff --git a/ld/configure.ac b/ld/configure.ac
-index b5e849d84a..22e022ec03 100644
+index 8ea97c43cd4..0f246db67d8 100644
 --- a/ld/configure.ac
 +++ b/ld/configure.ac
-@@ -94,6 +94,16 @@ AC_SUBST(use_sysroot)
+@@ -106,6 +106,16 @@ AC_SUBST(use_sysroot)
  AC_SUBST(TARGET_SYSTEM_ROOT)
  AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
  
@@ -175,10 +180,10 @@ index b5e849d84a..22e022ec03 100644
  dnl "install_as_default" is set to false if gold is the default linker.
  dnl "installed_linker" is the installed BFD linker name.
 diff --git a/ld/ld.h b/ld/ld.h
-index 71fd781267..a6ea2ae69e 100644
+index 35fafebfaed..4152278b8f4 100644
 --- a/ld/ld.h
 +++ b/ld/ld.h
-@@ -166,6 +166,13 @@ typedef struct
+@@ -162,6 +162,13 @@ typedef struct
       in the linker script.  */
    bool force_group_allocation;
  
@@ -193,10 +198,10 @@ index 71fd781267..a6ea2ae69e 100644
    enum endian_enum endian;
  
 diff --git a/ld/ld.texi b/ld/ld.texi
-index 621d05dc05..cbbbc687d0 100644
+index dd8f571d4e4..0aee4a4e9f1 100644
 --- a/ld/ld.texi
 +++ b/ld/ld.texi
-@@ -2609,6 +2609,24 @@ string identifying the original linked file does not change.
+@@ -2863,6 +2863,24 @@ string identifying the original linked file does not change.
  
  Passing @code{none} for @var{style} disables the setting from any
  @code{--build-id} options earlier on the command line.
@@ -222,7 +227,7 @@ index 621d05dc05..cbbbc687d0 100644
  
  @c man end
 diff --git a/ld/ldfile.c b/ld/ldfile.c
-index 53112c8694..eb357e66a9 100644
+index 9d0af06f1f6..f4a83acca93 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
 @@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
@@ -253,10 +258,10 @@ index 53112c8694..eb357e66a9 100644
  
  /* Try to open a BFD for a lang_input_statement.  */
 diff --git a/ld/ldlex.h b/ld/ldlex.h
-index aeaea4dfee..b8d43da37f 100644
+index 9e8bf5fb835..3baed822a22 100644
 --- a/ld/ldlex.h
 +++ b/ld/ldlex.h
-@@ -142,6 +142,9 @@ enum option_values
+@@ -148,6 +148,9 @@ enum option_values
    OPTION_PRINT_OUTPUT_FORMAT,
    OPTION_PRINT_SYSROOT,
    OPTION_IGNORE_UNRESOLVED_SYMBOL,
@@ -267,10 +272,10 @@ index aeaea4dfee..b8d43da37f 100644
    OPTION_POP_STATE,
    OPTION_DISABLE_MULTIPLE_DEFS_ABS,
 diff --git a/ld/ldmain.c b/ld/ldmain.c
-index c3f473f661..c45012dbbd 100644
+index 42660eb9a3c..c78009b760c 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
-@@ -273,6 +273,13 @@ main (int argc, char **argv)
+@@ -321,6 +321,13 @@ main (int argc, char **argv)
    command_line.warn_mismatch = true;
    command_line.warn_search_mismatch = true;
    command_line.check_section_addresses = -1;
@@ -285,10 +290,10 @@ index c3f473f661..c45012dbbd 100644
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
 diff --git a/ld/lexsup.c b/ld/lexsup.c
-index c5edc25793..c20c0bb0d8 100644
+index 00274c500d0..a19cce9967c 100644
 --- a/ld/lexsup.c
 +++ b/ld/lexsup.c
-@@ -540,6 +540,18 @@ static const struct ld_option ld_options[] =
+@@ -566,6 +566,18 @@ static const struct ld_option ld_options[] =
      OPTION_IGNORE_UNRESOLVED_SYMBOL},
      '\0', N_("SYMBOL"),
      N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
@@ -307,7 +312,7 @@ index c5edc25793..c20c0bb0d8 100644
    { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
      '\0', NULL, N_("Push state of flags governing input file handling"),
      TWO_DASHES },
-@@ -1563,6 +1575,18 @@ parse_args (unsigned argc, char **argv)
+@@ -1643,6 +1655,18 @@ parse_args (unsigned argc, char **argv)
  	  }
  	  break;
  
@@ -327,5 +332,5 @@ index c5edc25793..c20c0bb0d8 100644
  	  input_flags.pushed = xmemdup (&input_flags,
  					sizeof (input_flags),
 -- 
-2.26.2
+2.31.1
 

diff --git a/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index a7f8448..4d5ed11 100644
--- a/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,7 +1,7 @@
-From c11463f5dbeb53c2a600a5b4a3982368ad149ba1 Mon Sep 17 00:00:00 2001
+From 6536761c1e2756ec39fdc33c400757be3744510c Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
-Subject: [PATCH 4/9] Gentoo: libiberty: install PIC version of libiberty.a
+Subject: [PATCH 2/6] Gentoo: libiberty: install PIC version of libiberty.a
 
 This will install a PIC version of libiberty.a by overwriting the non-PIC
 version of libiberty.a while compiling.  We do this because there is no
@@ -18,10 +18,10 @@ general are fairly low, and we'd rather have things work for all of them.
  1 file changed, 1 insertion(+)
 
 diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
-index d6b302e02f..8d84a09f1d 100644
+index d19e14a2aca..cd02be1c2fb 100644
 --- a/libiberty/Makefile.in
 +++ b/libiberty/Makefile.in
-@@ -256,6 +256,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
+@@ -257,6 +257,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS)
  	  $(AR) $(AR_FLAGS) $(TARGETLIB) \
  	    $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \
  	  $(RANLIB) $(TARGETLIB); \
@@ -30,5 +30,5 @@ index d6b302e02f..8d84a09f1d 100644
  	else true; fi; \
  	if [ x"$(NOASANFLAG)" != x ]; then \
 -- 
-2.26.2
+2.31.1
 

diff --git a/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch b/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
index d236727..f3c9f8e 100644
--- a/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
+++ b/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
@@ -1,7 +1,7 @@
-From b4c9e06c3fb0ede497bcc51dde6c9756efe124ad Mon Sep 17 00:00:00 2001
+From c55536c61ec7e4c2e983e15f51f56f7a7c340889 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 5 Jul 2016 20:24:00 +0545
-Subject: [PATCH 5/9] Gentoo: opcodes: link against libbfd.la for rpath deps
+Subject: [PATCH 3/6] Gentoo: opcodes: link against libbfd.la for rpath deps
 
 The reason opcodes doesn't link against libbfd.la is to workaround a
 libtool bug where it uses installed -L paths ahead of DESTDIR paths.
@@ -19,10 +19,10 @@ URL: https://bugs.gentoo.org/563934
  2 files changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/opcodes/configure b/opcodes/configure
-index 42be5febad..7b8ee51cc3 100755
+index a3da5987f1b..22a05245286 100755
 --- a/opcodes/configure
 +++ b/opcodes/configure
-@@ -12797,7 +12797,7 @@ if test "$enable_shared" = "yes"; then
+@@ -12142,7 +12142,7 @@ if test "$enable_shared" = "yes"; then
            SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.sl ${SHARED_LIBADD}"
  	  ;;
  	*)
@@ -32,10 +32,10 @@ index 42be5febad..7b8ee51cc3 100755
        esac
        SHARED_DEPENDENCIES="../bfd/libbfd.la"
 diff --git a/opcodes/configure.ac b/opcodes/configure.ac
-index 00be9c88be..b7a511ac58 100644
+index e564f067334..fb6254cd69d 100644
 --- a/opcodes/configure.ac
 +++ b/opcodes/configure.ac
-@@ -188,7 +188,7 @@ changequote([,])dnl
+@@ -203,7 +203,7 @@ if test "$enable_shared" = "yes"; then
            SHARED_LIBADD="-Wl,`pwd`/../bfd/.libs/libbfd.sl ${SHARED_LIBADD}"
  	  ;;
  	*)
@@ -45,5 +45,5 @@ index 00be9c88be..b7a511ac58 100644
        esac
        SHARED_DEPENDENCIES="../bfd/libbfd.la"
 -- 
-2.26.2
+2.31.1
 

diff --git a/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
index d7f696c..1051543 100644
--- a/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,7 +1,10 @@
-From eefafabed03c163287326afaadc4cc0e5840ea7b Mon Sep 17 00:00:00 2001
+From 235f1f862fb9bf77e2b9f62c24db0ca801c4a057 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
-Date: Wed, 12 Sep 2018 23:44:29 +0100
-Subject: [PATCH 6/9] Gentoo: add --with-extra-soversion-suffix= option
+Date: Tue, 20 Jul 2021 21:12:38 +0200
+Subject: [PATCH 4/6] Gentoo: add --with-extra-soversion-suffix= option
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
 
 --with-extra-soversion-suffix= will allow Gentoo to
 distinct libbfd.so and libopcodes.so to have more precise
@@ -21,6 +24,8 @@ built with different flags (see https://bugs.gentoo.org/663690).
 
 Bug: https://bugs.gentoo.org/666100
 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+Ported to binutils 2.37 Andreas K. Hüttel <dilfridge@gentoo.org>
 ---
  bfd/Makefile.am  |  5 +++++
  bfd/Makefile.in  |  4 ++++
@@ -29,7 +34,7 @@ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  4 files changed, 29 insertions(+)
 
 diff --git a/bfd/Makefile.am b/bfd/Makefile.am
-index b6088a3c4a..3f5cf81ca4 100644
+index ed2f701805d..dab3bfc8ed7 100644
 --- a/bfd/Makefile.am
 +++ b/bfd/Makefile.am
 @@ -59,6 +59,8 @@ bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
@@ -41,7 +46,7 @@ index b6088a3c4a..3f5cf81ca4 100644
  # bfd.h goes here, for now
  BFD_H = bfd.h
  
-@@ -958,6 +960,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -952,6 +954,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -52,7 +57,7 @@ index b6088a3c4a..3f5cf81ca4 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/Makefile.in b/bfd/Makefile.in
-index dd3474d92b..911232212b 100644
+index 12807d99760..572df143487 100644
 --- a/bfd/Makefile.in
 +++ b/bfd/Makefile.in
 @@ -318,6 +318,7 @@ ECHO_T = @ECHO_T@
@@ -63,7 +68,7 @@ index dd3474d92b..911232212b 100644
  FGREP = @FGREP@
  GENCAT = @GENCAT@
  GMSGFMT = @GMSGFMT@
-@@ -2071,6 +2072,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
+@@ -2063,6 +2064,9 @@ bfdver.h: $(srcdir)/version.h $(srcdir)/development.sh $(srcdir)/Makefile.in
  	  bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
  	  bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
  	fi ;\
@@ -74,7 +79,7 @@ index dd3474d92b..911232212b 100644
  	    -e "s,@bfd_version_string@,$$bfd_version_string," \
  	    -e "s,@bfd_version_package@,$$bfd_version_package," \
 diff --git a/bfd/configure b/bfd/configure
-index 59b867bbbf..fa34069f2a 100755
+index 41586f00f93..f0acf160913 100755
 --- a/bfd/configure
 +++ b/bfd/configure
 @@ -696,6 +696,7 @@ WARN_CFLAGS
@@ -85,7 +90,7 @@ index 59b867bbbf..fa34069f2a 100755
  DEBUGDIR
  PLUGINS_FALSE
  PLUGINS_TRUE
-@@ -833,6 +834,7 @@ enable_secureplt
+@@ -835,6 +836,7 @@ enable_secureplt
  enable_separate_code
  enable_leading_mingw64_underscores
  with_separate_debug_dir
@@ -93,7 +98,7 @@ index 59b867bbbf..fa34069f2a 100755
  with_pkgversion
  with_bugurl
  enable_werror
-@@ -1508,6 +1510,8 @@ Optional Packages:
+@@ -1511,6 +1513,8 @@ Optional Packages:
    --with-separate-debug-dir=DIR
                            Look for global separate debug info in DIR
                            [[default=LIBDIR/debug]]
@@ -102,7 +107,7 @@ index 59b867bbbf..fa34069f2a 100755
    --with-pkgversion=PKG   Use PKG in the version string in place of "GNU
                            Binutils"
    --with-bugurl=URL       Direct users to URL to report a bug
-@@ -12516,6 +12520,15 @@ fi
+@@ -11913,6 +11917,15 @@ fi
  
  
  
@@ -119,10 +124,10 @@ index 59b867bbbf..fa34069f2a 100755
  
  # Check whether --with-pkgversion was given.
 diff --git a/bfd/configure.ac b/bfd/configure.ac
-index 0528e54c3b..50b2b4e06e 100644
+index fec067b2135..8c9ef9a04c0 100644
 --- a/bfd/configure.ac
 +++ b/bfd/configure.ac
-@@ -133,6 +133,13 @@ AC_ARG_WITH(separate-debug-dir,
+@@ -169,6 +169,13 @@ AC_ARG_WITH(separate-debug-dir,
  [DEBUGDIR="${withval}"])
  AC_SUBST(DEBUGDIR)
  
@@ -134,8 +139,8 @@ index 0528e54c3b..50b2b4e06e 100644
 +AC_SUBST(EXTRA_SOVERSION_SUFFIX)
 +
  ACX_PKGVERSION([GNU Binutils])
- ACX_BUGURL([http://www.sourceware.org/bugzilla/])
+ ACX_BUGURL([https://www.sourceware.org/bugzilla/])
  
 -- 
-2.26.2
+2.31.1
 

diff --git a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
index f16e13d..c6e5299 100644
--- a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
+++ b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
@@ -1,7 +1,8 @@
-From 7cefac2aa8ff79d6e2eff1fb4c94346314563fc8 Mon Sep 17 00:00:00 2001
+From f4ecba77ec1eb0576b8731c749336ea3889eba73 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sun, 13 Oct 2019 05:25:28 +0200
-Subject: [PATCH] Gentoo: ld: enable new dtags by default for linux/gnu targets
+Subject: [PATCH 5/6] Gentoo: ld: enable new dtags by default for linux/gnu
+ targets
 
 Original author: Mike Frysinger <vapier@gentoo.org>
 
@@ -23,7 +24,7 @@ and GNU targets, enable them by default.
  1 file changed, 10 insertions(+)
 
 diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
-index 356f34538b..579e52253e 100644
+index bfaf8130a3e..c4c42b7371a 100644
 --- a/ld/emultempl/elf.em
 +++ b/ld/emultempl/elf.em
 @@ -81,6 +81,16 @@ gld${EMULATION_NAME}_before_parse (void)
@@ -44,5 +45,5 @@ index 356f34538b..579e52253e 100644
  EOF
  if test -n "$COMMONPAGESIZE"; then
 -- 
-2.26.2
+2.31.1
 

diff --git a/9999/0009-Gentoo-Pass-hash-style-sysv.patch b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
index 7610d78..41b6a33 100644
--- a/9999/0009-Gentoo-Pass-hash-style-sysv.patch
+++ b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
@@ -1,7 +1,7 @@
-From 2055e278cb6e984760dbf8627efef2158e215449 Mon Sep 17 00:00:00 2001
+From 905bf3c180f4f7fd07024eb9ff7851898593f3f8 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Wed, 18 Oct 2017 00:44:49 +0200
-Subject: Gentoo: Pass --hash-style=sysv to ld in the testsuite
+Date: Tue, 20 Jul 2021 21:15:24 +0200
+Subject: [PATCH 6/6] Gentoo: Pass --hash-style=sysv to ld in the testsuite
 
 ---
  binutils/testsuite/lib/binutils-common.exp |  2 +-
@@ -9,10 +9,10 @@ Subject: Gentoo: Pass --hash-style=sysv to ld in the testsuite
  2 files changed, 15 insertions(+), 3 deletions(-)
 
 diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b9e3c6d817..bb4ef987b3 100644
+index 59e25df99b0..401a05b5c32 100644
 --- a/binutils/testsuite/lib/binutils-common.exp
 +++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1125,7 +1125,7 @@ proc run_dump_test { name {extra_options {}} } {
+@@ -1279,7 +1279,7 @@ proc run_dump_test { name {extra_options {}} } {
  
  	    # Add -L$srcdir/$subdir so that the linker command can use
  	    # linker scripts in the source directory.
@@ -20,12 +20,12 @@ index b9e3c6d817..bb4ef987b3 100644
 +	    set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
  		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
  
-	    # If needed then check for, or add a -Map option.
+ 	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 015eda6eb9..0b945b539d 100644
+index 8fd14afc63e..adbeaa3bd08 100644
 --- a/ld/testsuite/lib/ld-lib.exp
 +++ b/ld/testsuite/lib/ld-lib.exp
-@@ -165,7 +165,7 @@ proc default_ld_relocate { ld target objects } {
+@@ -167,7 +167,7 @@ proc default_ld_relocate { ld target objects } {
      global HOSTING_EMU
  
      remote_file host delete $target
@@ -34,7 +34,7 @@ index 015eda6eb9..0b945b539d 100644
  }
  
  # Check to see if ld is being invoked with a non-endian output format
-@@ -196,8 +196,20 @@ proc default_ld_link { ld target objects } {
+@@ -198,8 +198,20 @@ proc default_ld_link { ld target objects } {
  	set flags [big_or_little_endian]
      }
  
@@ -57,5 +57,5 @@ index 015eda6eb9..0b945b539d 100644
  
      # We don't care if we get a warning about a non-existent start
 -- 
-2.26.2
+2.31.1
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-06  7:04 Sergei Trofimovich
  0 siblings, 0 replies; 102+ messages in thread
From: Sergei Trofimovich @ 2021-07-06  7:04 UTC (permalink / raw
  To: gentoo-commits

commit:     1e1ee03c239f2b763a1a37f864f6cb420a5487f0
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Tue Jul  6 06:56:04 2021 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Tue Jul  6 07:02:43 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=1e1ee03c

9999: refresh 0009-...-Pass-hash-style-sysv-...patch

Closes: https://bugs.gentoo.org/800254
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 9999/0009-Gentoo-Pass-hash-style-sysv.patch | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/9999/0009-Gentoo-Pass-hash-style-sysv.patch b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
index 8ebb911..7610d78 100644
--- a/9999/0009-Gentoo-Pass-hash-style-sysv.patch
+++ b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
@@ -14,13 +14,13 @@ index b9e3c6d817..bb4ef987b3 100644
 +++ b/binutils/testsuite/lib/binutils-common.exp
 @@ -1125,7 +1125,7 @@ proc run_dump_test { name {extra_options {}} } {
  
-             # Add -L$srcdir/$subdir so that the linker command can use
-             # linker scripts in the source directory.
--            set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+            set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
+ 	    # Add -L$srcdir/$subdir so that the linker command can use
+ 	    # linker scripts in the source directory.
+-	    set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
++	    set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
  		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
  
-             # If needed then check for, or add a -Map option.
+	    # If needed then check for, or add a -Map option.
 diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
 index 015eda6eb9..0b945b539d 100644
 --- a/ld/testsuite/lib/ld-lib.exp


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-06  7:04 Sergei Trofimovich
  0 siblings, 0 replies; 102+ messages in thread
From: Sergei Trofimovich @ 2021-07-06  7:04 UTC (permalink / raw
  To: gentoo-commits

commit:     da0c7a071390e6bda1d5fb8c31ce3ff37671db7e
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Tue Jul  6 07:00:56 2021 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Tue Jul  6 07:02:43 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=da0c7a07

9999: refresh 0003-...-poisoned-system-direc-...patch

Closes: https://bugs.gentoo.org/800254
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 ...-ld-add-support-for-poisoned-system-direc.patch | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 1446352..964946c 100644
--- a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -180,14 +180,14 @@ index 71fd781267..a6ea2ae69e 100644
 +++ b/ld/ld.h
 @@ -166,6 +166,13 @@ typedef struct
       in the linker script.  */
-   bfd_boolean force_group_allocation;
+   bool force_group_allocation;
  
-+  /* If TRUE warn for uses of system directories when cross linking.  */
-+  bfd_boolean warn_poison_system_directories;
++  /* If true warn for uses of system directories when cross linking.  */
++  bool warn_poison_system_directories;
 +
-+  /* If TRUE (default FALSE) give an error for uses of system
++  /* If true (default false) give an error for uses of system
 +     directories when cross linking instead of a warning.  */
-+  bfd_boolean error_poison_system_directories;
++  bool error_poison_system_directories;
 +
    /* Big or little endian as set on command line.  */
    enum endian_enum endian;
@@ -225,7 +225,7 @@ diff --git a/ld/ldfile.c b/ld/ldfile.c
 index 53112c8694..eb357e66a9 100644
 --- a/ld/ldfile.c
 +++ b/ld/ldfile.c
-@@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bfd_boolean cmdline)
+@@ -117,6 +117,26 @@ ldfile_add_library_path (const char *name, bool cmdline)
      new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
    else
      new_dirs->name = xstrdup (name);
@@ -271,16 +271,16 @@ index c3f473f661..c45012dbbd 100644
 --- a/ld/ldmain.c
 +++ b/ld/ldmain.c
 @@ -273,6 +273,13 @@ main (int argc, char **argv)
-   command_line.warn_mismatch = TRUE;
-   command_line.warn_search_mismatch = TRUE;
+   command_line.warn_mismatch = true;
+   command_line.warn_search_mismatch = true;
    command_line.check_section_addresses = -1;
 +  command_line.warn_poison_system_directories =
 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
-+    TRUE;
++    true;
 +#else
-+    FALSE;
++    false;
 +#endif
-+  command_line.error_poison_system_directories = FALSE;
++  command_line.error_poison_system_directories = false;
  
    /* We initialize DEMANGLING based on the environment variable
       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
@@ -312,15 +312,15 @@ index c5edc25793..c20c0bb0d8 100644
  	  break;
  
 +   case OPTION_WARN_POISON_SYSTEM_DIRECTORIES:
-+     command_line.warn_poison_system_directories = TRUE;
++     command_line.warn_poison_system_directories = true;
 +     break;
 +
 +   case OPTION_NO_WARN_POISON_SYSTEM_DIRECTORIES:
-+     command_line.warn_poison_system_directories = FALSE;
++     command_line.warn_poison_system_directories = false;
 +     break;
 +
 +   case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
-+     command_line.error_poison_system_directories = TRUE;
++     command_line.error_poison_system_directories = true;
 +     break;
 +
  	case OPTION_PUSH_STATE:


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2021-07-06  7:04 Sergei Trofimovich
  0 siblings, 0 replies; 102+ messages in thread
From: Sergei Trofimovich @ 2021-07-06  7:04 UTC (permalink / raw
  To: gentoo-commits

commit:     2fb3fe47ca8e417f56687d05fc91a112ae08b813
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Tue Jul  6 06:50:56 2021 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Tue Jul  6 07:02:43 2021 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=2fb3fe47

9999: refresh 0007-...-ld-enable-new-dtags-...patch

Closes: https://bugs.gentoo.org/800254
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 ...-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
index b4c5a74..f16e13d 100644
--- a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
+++ b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
@@ -27,20 +27,20 @@ index 356f34538b..579e52253e 100644
 --- a/ld/emultempl/elf.em
 +++ b/ld/emultempl/elf.em
 @@ -81,6 +81,16 @@ gld${EMULATION_NAME}_before_parse (void)
-   input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
-   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
-   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
+   input_flags.dynamic = ${DYNAMIC_LINK-true};
+   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
+   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
 +EOF
 +
 +case ${target} in
 +  *-*-linux-* | *-*-k*bsd*-* | *-*-gnu* | *-*-nacl*)
 +    fragment <<EOF
-+  link_info.new_dtags = TRUE;
++  link_info.new_dtags = true;
 +EOF
 +    ;;
 +esac
 +fragment <<EOF
-   link_info.check_relocs_after_open_input = TRUE;
+   link_info.check_relocs_after_open_input = true;
  EOF
  if test -n "$COMMONPAGESIZE"; then
 -- 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2020-07-25 17:27 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2020-07-25 17:27 UTC (permalink / raw
  To: gentoo-commits

commit:     f9c7687232df3334a7191920915e2d9ab27b133b
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 25 17:26:51 2020 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jul 25 17:26:51 2020 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=f9c76872

Update patch for zero fuzz

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
index 0b0cbfe..b4c5a74 100644
--- a/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
+++ b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
@@ -1,8 +1,7 @@
-From cf8983d602c56eb31ee0e356df670d9c2876ce15 Mon Sep 17 00:00:00 2001
+From 7cefac2aa8ff79d6e2eff1fb4c94346314563fc8 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sun, 13 Oct 2019 05:25:28 +0200
-Subject: [PATCH 7/9] Gentoo: ld: enable new dtags by default for linux/gnu
- targets
+Subject: [PATCH] Gentoo: ld: enable new dtags by default for linux/gnu targets
 
 Original author: Mike Frysinger <vapier@gentoo.org>
 
@@ -24,7 +23,7 @@ and GNU targets, enable them by default.
  1 file changed, 10 insertions(+)
 
 diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
-index eac2ce2f4c..7f92134070 100644
+index 356f34538b..579e52253e 100644
 --- a/ld/emultempl/elf.em
 +++ b/ld/emultempl/elf.em
 @@ -81,6 +81,16 @@ gld${EMULATION_NAME}_before_parse (void)
@@ -42,8 +41,8 @@ index eac2ce2f4c..7f92134070 100644
 +esac
 +fragment <<EOF
    link_info.check_relocs_after_open_input = TRUE;
-   link_info.relro = DEFAULT_LD_Z_RELRO;
-   link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
+ EOF
+ if test -n "$COMMONPAGESIZE"; then
 -- 
 2.26.2
 


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2020-07-25 12:26 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2020-07-25 12:26 UTC (permalink / raw
  To: gentoo-commits

commit:     a74c34d8ec1f197f9c80861e0d6271ac63403993
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 25 12:25:51 2020 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jul 25 12:25:51 2020 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=a74c34d8

Textrel warnings have been enabled upstream, drop patches (3)

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...red-textr.patch => 0009-Gentoo-Pass-hash-style-sysv.patch} | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
similarity index 85%
rename from 9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch
rename to 9999/0009-Gentoo-Pass-hash-style-sysv.patch
index 4ff406f..8ebb911 100644
--- a/9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch
+++ b/9999/0009-Gentoo-Pass-hash-style-sysv.patch
@@ -1,8 +1,7 @@
 From 2055e278cb6e984760dbf8627efef2158e215449 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Wed, 18 Oct 2017 00:44:49 +0200
-Subject: [PATCH 9/9] Gentoo: Pass --hash-style=sysv and
- --no-warn-shared-textrel to ld in the testsuite
+Subject: Gentoo: Pass --hash-style=sysv to ld in the testsuite
 
 ---
  binutils/testsuite/lib/binutils-common.exp |  2 +-
@@ -18,7 +17,7 @@ index b9e3c6d817..bb4ef987b3 100644
              # Add -L$srcdir/$subdir so that the linker command can use
              # linker scripts in the source directory.
 -            set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+            set cmd "$LD --hash-style=sysv --no-warn-shared-textrel $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
++            set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
  		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
  
              # If needed then check for, or add a -Map option.
@@ -31,7 +30,7 @@ index 015eda6eb9..0b945b539d 100644
  
      remote_file host delete $target
 -    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
-+    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv --no-warn-shared-textrel -o $target -r $objects"]
++    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv -o $target -r $objects"]
  }
  
  # Check to see if ld is being invoked with a non-endian output format
@@ -46,9 +45,9 @@ index 015eda6eb9..0b945b539d 100644
 +    # - ld-new         -> we're working with the new linker
 +    # - otherwise      -> we're likely working with the system compiler
 +    if {[regexp {ld-new$} $ld]} {
-+      set gentoosysv "--hash-style=sysv --no-warn-shared-textrel"
++      set gentoosysv "--hash-style=sysv"
 +    } else {
-+      set gentoosysv "-Wl,--hash-style=sysv -Wl,--no-warn-shared-textrel"
++      set gentoosysv "-Wl,--hash-style=sysv"
 +    }
 +
      remote_file host delete $target


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2020-07-25 12:23 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2020-07-25 12:23 UTC (permalink / raw
  To: gentoo-commits

commit:     e4b8746852919960969944904c59334cecddfe25
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 25 12:23:12 2020 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jul 25 12:23:12 2020 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=e4b87468

Textrel warnings have been enabled upstream, drop patches (2)

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...ore-TEXTREL-warnings-for-non-shared-objec.patch | 45 ----------------------
 1 file changed, 45 deletions(-)

diff --git a/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch b/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch
deleted file mode 100644
index 8e0e091..0000000
--- a/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-From 74afb38257f4a35d681883348ef54317674827e3 Mon Sep 17 00:00:00 2001
-From: Sergei Trofimovich <slyfox@gentoo.org>
-Date: Thu, 1 Mar 2018 12:35:03 +0100
-Subject: [PATCH 8/9] Gentoo: Restore TEXTREL warnings for non-shared objects
-
----
- bfd/elflink.c                | 4 ++--
- ld/testsuite/ld-i386/warn1.d | 2 +-
- 2 files changed, 3 insertions(+), 3 deletions(-)
-
-diff --git a/bfd/elflink.c b/bfd/elflink.c
-index 90ada7a1cc..b4636885aa 100644
---- a/bfd/elflink.c
-+++ b/bfd/elflink.c
-@@ -12934,7 +12934,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 	goto error_return;
- 
-       /* Check for DT_TEXTREL (late, in case the backend removes it).  */
--      if (((info->warn_shared_textrel && bfd_link_pic (info))
-+      if ((info->warn_shared_textrel
- 	   || info->error_textrel)
- 	  && (o = bfd_get_linker_section (dynobj, ".dynamic")) != NULL)
- 	{
-@@ -12955,7 +12955,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
- 		      (_("%P%X: read-only segment has dynamic relocations\n"));
- 		  else
- 		    info->callbacks->einfo
--		      (_("%P: warning: creating a DT_TEXTREL in a shared object\n"));
-+		      (_("%P: warning: creating a DT_TEXTREL in object\n"));
- 		  break;
- 		}
- 	    }
-diff --git a/ld/testsuite/ld-i386/warn1.d b/ld/testsuite/ld-i386/warn1.d
-index 3c78f31efd..49bcb5171f 100644
---- a/ld/testsuite/ld-i386/warn1.d
-+++ b/ld/testsuite/ld-i386/warn1.d
-@@ -1,4 +1,4 @@
- #name: --warn-shared-textrel --fatal-warnings
- #as: --32
- #ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
--#error: .*warning: creating a DT_TEXTREL in a shared object
-+#error: .*warning: creating a DT_TEXTREL in object
--- 
-2.26.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2020-07-25 12:20 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2020-07-25 12:20 UTC (permalink / raw
  To: gentoo-commits

commit:     47b8db23ff55dd29992198dfbadda53984a4ab2d
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 25 12:20:24 2020 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Sat Jul 25 12:20:24 2020 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=47b8db23

Textrel warnings have been enabled upstream, drop patches

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...oo-ld-always-warn-about-textrels-in-files.patch | 30 ----------
 ...an-option-no-warn-shared-textrel-self-exp.patch | 66 ----------------------
 2 files changed, 96 deletions(-)

diff --git a/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch b/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch
deleted file mode 100644
index d60b0a1..0000000
--- a/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-From 5e2144e41600a83f6127eb44d739ed170d78ac7f Mon Sep 17 00:00:00 2001
-From: Mike Frysinger <vapier@gentoo.org>
-Date: Mon, 16 May 2005 22:10:19 -0400
-Subject: [PATCH 1/9] Gentoo: ld: always warn about textrels in files
-
-textrels are bad for forcing copy-on-write (this affects everyone), and for
-security/runtime code generation, this affects security ppl.  But in either
-case, it doesn't matter who needs textrels, it's the very fact that they're
-needed at all.
-
-(cherry picked from commit cd6411ad57aab78686f67cbbc1ed70ee810ad335)
----
- ld/ldmain.c | 1 +
- 1 file changed, 1 insertion(+)
-
-diff --git a/ld/ldmain.c b/ld/ldmain.c
-index 04a3f7a511..c3f473f661 100644
---- a/ld/ldmain.c
-+++ b/ld/ldmain.c
-@@ -299,6 +299,7 @@ main (int argc, char **argv)
-   link_info.dynamic_undefined_weak = -1;
-   link_info.pei386_auto_import = -1;
-   link_info.spare_dynamic_tags = 5;
-+  link_info.warn_shared_textrel = TRUE;
-   link_info.path_separator = ':';
- #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
-   link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
--- 
-2.26.2
-

diff --git a/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch b/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch
deleted file mode 100644
index 5457b83..0000000
--- a/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch
+++ /dev/null
@@ -1,66 +0,0 @@
-From 19ecd671bddd33f3afff169f26c55101c90c4afc Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 3 Jun 2018 21:12:16 +0200
-Subject: [PATCH 2/9] Gentoo: Add an option --no-warn-shared-textrel
- (self-explanatory)
-
----
- ld/ld.texi  | 4 ++++
- ld/ldlex.h  | 1 +
- ld/lexsup.c | 6 ++++++
- 3 files changed, 11 insertions(+)
-
-diff --git a/ld/ld.texi b/ld/ld.texi
-index 4dc78e65fa..621d05dc05 100644
---- a/ld/ld.texi
-+++ b/ld/ld.texi
-@@ -2408,6 +2408,10 @@ the section (@pxref{SECTIONS}).
- @item --warn-shared-textrel
- Warn if the linker adds a DT_TEXTREL to a shared object.
- 
-+@kindex --no-warn-shared-textrel
-+@item --no-warn-shared-textrel
-+Do not warn if the linker adds a DT_TEXTREL to a shared object.
-+
- @kindex --warn-alternate-em
- @item --warn-alternate-em
- Warn if an object has alternate ELF machine code.
-diff --git a/ld/ldlex.h b/ld/ldlex.h
-index 22b928d2d9..aeaea4dfee 100644
---- a/ld/ldlex.h
-+++ b/ld/ldlex.h
-@@ -131,6 +131,7 @@ enum option_values
-   OPTION_WARN_UNRESOLVED_SYMBOLS,
-   OPTION_ERROR_UNRESOLVED_SYMBOLS,
-   OPTION_WARN_SHARED_TEXTREL,
-+  OPTION_NO_WARN_SHARED_TEXTREL,
-   OPTION_WARN_ALTERNATE_EM,
-   OPTION_REDUCE_MEMORY_OVERHEADS,
- #ifdef ENABLE_PLUGINS
-diff --git a/ld/lexsup.c b/ld/lexsup.c
-index c02041d5f1..c5edc25793 100644
---- a/ld/lexsup.c
-+++ b/ld/lexsup.c
-@@ -519,6 +519,9 @@ static const struct ld_option ld_options[] =
-   { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
-     '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
-     TWO_DASHES },
-+  { {"no-warn-shared-textrel", no_argument, NULL, OPTION_NO_WARN_SHARED_TEXTREL},
-+    '\0', NULL, N_("Do not warn if shared object has DT_TEXTREL"),
-+    TWO_DASHES },
-   { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
-     '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
-     TWO_DASHES },
-@@ -1449,6 +1452,9 @@ parse_args (unsigned argc, char **argv)
- 	case OPTION_WARN_SHARED_TEXTREL:
- 	  link_info.warn_shared_textrel = TRUE;
- 	  break;
-+	case OPTION_NO_WARN_SHARED_TEXTREL:
-+	  link_info.warn_shared_textrel = FALSE;
-+	  break;
- 	case OPTION_WARN_ALTERNATE_EM:
- 	  link_info.warn_alternate_em = TRUE;
- 	  break;
--- 
-2.26.2
-


^ permalink raw reply related	[flat|nested] 102+ messages in thread
* [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/
@ 2020-05-19 21:12 Andreas K. Hüttel
  0 siblings, 0 replies; 102+ messages in thread
From: Andreas K. Hüttel @ 2020-05-19 21:12 UTC (permalink / raw
  To: gentoo-commits

commit:     b3b149f3d1d004f29ce9b3fdf1a636aae92c5d6f
Author:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Tue May 19 21:10:06 2020 +0000
Commit:     Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
CommitDate: Tue May 19 21:11:57 2020 +0000
URL:        https://gitweb.gentoo.org/proj/toolchain/binutils-patches.git/commit/?id=b3b149f3

Consolidate patches

Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>

 ...oo-ld-always-warn-about-textrels-in-files.patch |   2 +-
 ...an-option-no-warn-shared-textrel-self-exp.patch |   2 +-
 ...-ld-add-support-for-poisoned-system-direc.patch |   2 +-
 ...iberty-install-PIC-version-of-libiberty.a.patch |   2 +-
 ...des-link-against-libbfd.la-for-rpath-deps.patch |   2 +-
 ...ss-hash-style-sysv-to-ld-in-its-testsuite.patch | 807 ---------------------
 ...o-add-with-extra-soversion-suffix-option.patch} |   4 +-
 ...-no-warn-shared-textrel-to-ld-in-its-test.patch |  47 --
 ...able-new-dtags-by-default-for-linux-gnu-.patch} |   4 +-
 ...ore-TEXTREL-warnings-for-non-shared-objec.patch |  19 +-
 ...test-for-precise-textrel-warning-message-.patch |  24 -
 ...-hash-style-sysv-and-no-warn-shared-textr.patch |  62 ++
 ...10-Gentoo-Fix-textrel-warning-format-test.patch |  22 -
 ...entoo-Add-patch-tarball-generation-script.patch | 217 ------
 ...ve-block-mistakenly-duplicated-in-1222895.patch | 777 --------------------
 ...t-generic-test-library-to-our-linker-sett.patch |  26 -
 ...regexp-of-hilarious-ld-detection-heuristi.patch |  30 -
 17 files changed, 86 insertions(+), 1963 deletions(-)

diff --git a/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch b/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch
index 83377a5..d60b0a1 100644
--- a/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch
+++ b/9999/0001-Gentoo-ld-always-warn-about-textrels-in-files.patch
@@ -1,7 +1,7 @@
 From 5e2144e41600a83f6127eb44d739ed170d78ac7f Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Mon, 16 May 2005 22:10:19 -0400
-Subject: [PATCH 01/16] Gentoo: ld: always warn about textrels in files
+Subject: [PATCH 1/9] Gentoo: ld: always warn about textrels in files
 
 textrels are bad for forcing copy-on-write (this affects everyone), and for
 security/runtime code generation, this affects security ppl.  But in either

diff --git a/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch b/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch
index 7786ab3..5457b83 100644
--- a/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch
+++ b/9999/0002-Gentoo-Add-an-option-no-warn-shared-textrel-self-exp.patch
@@ -1,7 +1,7 @@
 From 19ecd671bddd33f3afff169f26c55101c90c4afc Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sun, 3 Jun 2018 21:12:16 +0200
-Subject: [PATCH 02/16] Gentoo: Add an option --no-warn-shared-textrel
+Subject: [PATCH 2/9] Gentoo: Add an option --no-warn-shared-textrel
  (self-explanatory)
 
 ---

diff --git a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
index 3349c0e..1446352 100644
--- a/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
+++ b/9999/0003-Gentoo-gold-ld-add-support-for-poisoned-system-direc.patch
@@ -1,7 +1,7 @@
 From c251ab646d98b3f0e8f8b1ae5e94c672325477e2 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 10 Oct 2017 22:53:53 +0200
-Subject: [PATCH 03/16] Gentoo: gold/ld: add support for poisoned system
+Subject: [PATCH 3/9] Gentoo: gold/ld: add support for poisoned system
  directories
 
 This is based on the old CodeSourcery patch written by Joseph Myers to add

diff --git a/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch b/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
index 54e5fdf..a7f8448 100644
--- a/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
+++ b/9999/0004-Gentoo-libiberty-install-PIC-version-of-libiberty.a.patch
@@ -1,7 +1,7 @@
 From c11463f5dbeb53c2a600a5b4a3982368ad149ba1 Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Fri, 7 Jan 2005 00:15:53 -0500
-Subject: [PATCH 04/16] Gentoo: libiberty: install PIC version of libiberty.a
+Subject: [PATCH 4/9] Gentoo: libiberty: install PIC version of libiberty.a
 
 This will install a PIC version of libiberty.a by overwriting the non-PIC
 version of libiberty.a while compiling.  We do this because there is no

diff --git a/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch b/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
index 2ec1013..d236727 100644
--- a/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
+++ b/9999/0005-Gentoo-opcodes-link-against-libbfd.la-for-rpath-deps.patch
@@ -1,7 +1,7 @@
 From b4c9e06c3fb0ede497bcc51dde6c9756efe124ad Mon Sep 17 00:00:00 2001
 From: Mike Frysinger <vapier@gentoo.org>
 Date: Tue, 5 Jul 2016 20:24:00 +0545
-Subject: [PATCH 05/16] Gentoo: opcodes: link against libbfd.la for rpath deps
+Subject: [PATCH 5/9] Gentoo: opcodes: link against libbfd.la for rpath deps
 
 The reason opcodes doesn't link against libbfd.la is to workaround a
 libtool bug where it uses installed -L paths ahead of DESTDIR paths.

diff --git a/9999/0006-Gentoo-Pass-hash-style-sysv-to-ld-in-its-testsuite.patch b/9999/0006-Gentoo-Pass-hash-style-sysv-to-ld-in-its-testsuite.patch
deleted file mode 100644
index 30f207b..0000000
--- a/9999/0006-Gentoo-Pass-hash-style-sysv-to-ld-in-its-testsuite.patch
+++ /dev/null
@@ -1,807 +0,0 @@
-From 65535cdfae964cce89a7c03ad720f80c61e09217 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Wed, 18 Oct 2017 00:44:49 +0200
-Subject: [PATCH 06/16] Gentoo: Pass --hash-style=sysv to ld in its testsuite
-
----
- ld/testsuite/lib/ld-lib.exp | 769 +++++++++++++++++++++++++++++++++++-
- 1 file changed, 767 insertions(+), 2 deletions(-)
-
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 015eda6eb9..853a4d87e6 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -165,7 +165,7 @@ proc default_ld_relocate { ld target objects } {
-     global HOSTING_EMU
- 
-     remote_file host delete $target
--    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
-+    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv -o $target -r $objects"]
- }
- 
- # Check to see if ld is being invoked with a non-endian output format
-@@ -196,8 +196,20 @@ proc default_ld_link { ld target objects } {
- 	set flags [big_or_little_endian]
-     }
- 
-+    # Hilariously, this procedure is called sometimes with $CC and sometimes
-+    # with $ld as parameter. If we want to change the default behaviour, we
-+    # need to take the different option formats into account.
-+    # We check the $ld parameter for
-+    # - .*ld/ld-new    -> we're working with the new linker
-+    # - otherwise      -> we're likely working with the system compiler
-+    if {[regexp {ld/ld-new$} $ld]} {
-+      set gentoosysv "--hash-style=sysv"
-+    } else {
-+      set gentoosysv "-Wl,--hash-style=sysv"
-+    }
-+
-     remote_file host delete $target
--    set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"]
-+    set exec_output [run_host_cmd "$ld" "$gentoosysv $flags -o $target $objects"]
-     set exec_output [prune_warnings $exec_output]
- 
-     # We don't care if we get a warning about a non-existent start
-@@ -409,6 +421,759 @@ proc ld_link_defsyms {} {
-     return $flags
- }
- 
-+# run_dump_test FILE (optional:) EXTRA_OPTIONS
-+# Copied from gas testsuite, tweaked and further extended.
-+#
-+# Assemble a .s file, then run some utility on it and check the output.
-+#
-+# There should be an assembly language file named FILE.s in the test
-+# suite directory, and a pattern file called FILE.d.  `run_dump_test'
-+# will assemble FILE.s, run some tool like `objdump', `objcopy', or
-+# `nm' on the .o file to produce textual output, and then analyze that
-+# with regexps.  The FILE.d file specifies what program to run, and
-+# what to expect in its output.
-+#
-+# The FILE.d file begins with zero or more option lines, which specify
-+# flags to pass to the assembler, the program to run to dump the
-+# assembler's output, and the options it wants.  The option lines have
-+# the syntax:
-+#
-+#         # OPTION: VALUE
-+#
-+# OPTION is the name of some option, like "name" or "objdump", and
-+# VALUE is OPTION's value.  The valid options are described below.
-+# Whitespace is ignored everywhere, except within VALUE.  The option
-+# list ends with the first line that doesn't match the above syntax
-+# (hmm, not great for error detection).
-+#
-+# The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
-+# two-element lists.  The first element of each is an option name, and
-+# the second additional arguments to be added on to the end of the
-+# option list as given in FILE.d.  (If omitted, no additional options
-+# are added.)
-+#
-+# The interesting options are:
-+#
-+#   name: TEST-NAME
-+#	The name of this test, passed to DejaGNU's `pass' and `fail'
-+#       commands.  If omitted, this defaults to FILE, the root of the
-+#       .s and .d files' names.
-+#
-+#   as: FLAGS
-+#	When assembling, pass FLAGS to the assembler.
-+#       If assembling several files, you can pass different assembler
-+#       options in the "source" directives.  See below.
-+#
-+#   ld: FLAGS
-+#       Link assembled files using FLAGS, in the order of the "source"
-+#       directives, when using multiple files.
-+#
-+#   ld_after_inputfiles: FLAGS
-+#       Similar to "ld", but put after all input files.
-+#
-+#   objcopy_objects: FLAGS
-+#	Run objcopy with the specified flags after assembling any source
-+#	that has the special marker RUN_OBJCOPY in the source specific
-+#	flags.
-+#
-+#   objcopy_linked_file: FLAGS
-+#	Run objcopy on the linked file with the specified flags.
-+#	This lets you transform the linked file using objcopy, before the
-+#	result is analyzed by an analyzer program specified below (which
-+#	may in turn *also* be objcopy).
-+#
-+#   PROG: PROGRAM-NAME
-+#       The name of the program to run to analyze the .o file produced
-+#       by the assembler or the linker output.  This can be omitted;
-+#       run_dump_test will guess which program to run by seeing which of
-+#       the flags options below is present.
-+#
-+#   readelf: FLAGS
-+#   objdump: FLAGS
-+#   nm: FLAGS
-+#   objcopy: FLAGS
-+#	Use the specified program to analyze the assembler or linker
-+#       output file, and pass it FLAGS, in addition to the output name.
-+#	Note that they are run with LC_ALL=C in the environment to give
-+#	consistent sorting of symbols.
-+#
-+#   source: SOURCE [FLAGS]
-+#	Assemble the file SOURCE.s using the flags in the "as" directive
-+#       and the (optional) FLAGS.  If omitted, the source defaults to
-+#       FILE.s.
-+#       This is useful if several .d files want to share a .s file.
-+#       More than one "source" directive can be given, which is useful
-+#       when testing linking.
-+#
-+#   dump: DUMP
-+#	Match against DUMP.d.  If omitted, this defaults to FILE.d.  This
-+#	is useful if several .d files differ by options only.  Options are
-+#	always read from FILE.d.
-+#
-+#   xfail: TARGET
-+#       The test is expected to fail on TARGET.  This may occur more than
-+#       once.
-+#
-+#   target: TARGET
-+#	Only run the test for TARGET.
-+#	You may provide target name "cfi" for any target supporting the
-+#	CFI statements.  You may provide target name "shared" for any
-+#	target supporting shared libraries.  Otherwise TARGET is called
-+#	as a TCL procedure if surrounded by square brackets, or passed
-+#	to "istarget" if not.
-+#	This may occur more than once; the target being tested must match
-+#	at least one.  Otherwise the test will be marked unsupported.
-+#
-+#   alltargets: TARGET
-+#	Only run the test for TARGET.
-+#	The syntax for TARGET is as with 'target'.
-+#	This may occur more than once; the target being tested must match
-+#	all of them.  Otherwise the test will be marked unsupported.
-+#
-+#   notarget: TARGET
-+#	Do not run the test for TARGET.
-+#	The syntax for TARGET is as with 'target'.
-+#	This may occur more than once; the target being tested must not
-+#	match any of them.  Otherwise the test will be marked unsupported.
-+#
-+#   skip: TARGET
-+#   anyskip: TARGET
-+#   noskip: TARGET
-+#	These are exactly the same as "notarget", "alltargets" and
-+#	"target" respectively, except that they do nothing at all if the
-+#	check fails.  They should only be used in groups, to construct a
-+#	single test which is run on all targets but with variant options
-+#	or expected output on some targets.  (For example, see
-+#	gas/arm/inst.d and gas/arm/wince_inst.d.)
-+#
-+#   error: REGEX
-+#	An error with message matching REGEX must be emitted for the test
-+#	to pass.  The PROG, readelf, objdump, nm and objcopy options have
-+#	no meaning and need not be supplied if this is present.  Multiple
-+#	"error" directives append to the expected linker error message.
-+#
-+#   error_output: FILE
-+#       Means the same as 'error', except the regular expression lines
-+#       are contains in FILE.
-+#
-+#   warning: REGEX
-+#	Expect a linker warning matching REGEX.  It is an error to issue
-+#	both "error" and "warning".  Multiple "warning" directives
-+#	append to the expected linker warning message.
-+#
-+#   warning_output: FILE
-+#       Means the same as 'warning', except the regular expression
-+#       lines are contains in FILE.
-+#
-+#   map: FILE
-+#       Adding this option will cause the linker to generate a linker
-+#       map file, using the -Map=MAPFILE command line option.  If
-+#       there is no -Map=MAPFILE in the 'ld: FLAGS' then one will be
-+#       added to the linker command line.  The contents of the
-+#       generated MAPFILE are then compared against the regexp lines
-+#       in FILE using `regexp_diff' (see below for details).
-+#
-+# Each option may occur at most once unless otherwise mentioned.
-+#
-+# After the option lines come regexp lines.  `run_dump_test' calls
-+# `regexp_diff' to compare the output of the dumping tool against the
-+# regexps in FILE.d.  `regexp_diff' is defined in binutils-common.exp;
-+# see further comments there.
-+#
-+proc run_dump_test { name {extra_options {}} } {
-+    global subdir srcdir
-+    global OBJDUMP NM AS OBJCOPY READELF LD
-+    global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
-+    global host_triplet runtests
-+    global env verbose
-+    global ld_elf_shared_opt
-+
-+    if { [is_elf_format] && [check_shared_lib_support] } {
-+	set ld_extra_opt "$ld_elf_shared_opt"
-+    } else {
-+	set ld_extra_opt ""
-+    }
-+
-+    if [string match "*/*" $name] {
-+	set file $name
-+	set name [file tail $name]
-+    } else {
-+	set file "$srcdir/$subdir/$name"
-+    }
-+
-+    if ![runtest_file_p $runtests $name] then {
-+	return
-+    }
-+
-+    set opt_array [slurp_options "${file}.d"]
-+    if { $opt_array == -1 } {
-+	perror "error reading options from $file.d"
-+	unresolved $subdir/$name
-+	return
-+    }
-+    set dumpfile tmpdir/dump.out
-+    set run_ld 0
-+    set run_objcopy 0
-+    set objfile_names {}
-+    set opts(as) {}
-+    set opts(ld) {}
-+    set opts(ld_after_inputfiles) {}
-+    set opts(xfail) {}
-+    set opts(target) {}
-+    set opts(alltargets) {}
-+    set opts(notarget) {}
-+    set opts(skip) {}
-+    set opts(anyskip) {}
-+    set opts(noskip) {}
-+    set opts(objdump) {}
-+    set opts(nm) {}
-+    set opts(objcopy) {}
-+    set opts(readelf) {}
-+    set opts(name) {}
-+    set opts(PROG) {}
-+    set opts(source) {}
-+    set opts(dump) {}
-+    set opts(error) {}
-+    set opts(warning) {}
-+    set opts(error_output) {}
-+    set opts(warning_output) {}
-+    set opts(objcopy_linked_file) {}
-+    set opts(objcopy_objects) {}
-+    set opts(map) {}
-+
-+    foreach i $opt_array {
-+	set opt_name [lindex $i 0]
-+	set opt_val [lindex $i 1]
-+	if ![info exists opts($opt_name)] {
-+	    perror "unknown option $opt_name in file $file.d"
-+	    unresolved $subdir/$name
-+	    return
-+	}
-+
-+	switch -- $opt_name {
-+	    xfail {}
-+	    target {}
-+	    alltargets {}
-+	    notarget {}
-+	    skip {}
-+	    anyskip {}
-+	    noskip {}
-+	    warning {}
-+	    error {}
-+	    source {
-+		# Move any source-specific as-flags to a separate list to
-+		# simplify processing.
-+		if { [llength $opt_val] > 1 } {
-+		    lappend asflags [lrange $opt_val 1 end]
-+		    set opt_val [lindex $opt_val 0]
-+		} else {
-+		    lappend asflags {}
-+		}
-+
-+                # Create the object file name based on nothing but the source
-+                # file name.
-+                set new_objfile \
-+                    [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o]
-+                # But, sometimes, we have the exact same source filename in
-+                # different directories (foo/src.s bar/src.s) which would lead
-+                # us to try and create two src.o files.  We detect this
-+                # conflict here, and instead create src.o and src1.o.
-+                set j 0
-+                while { [lsearch $objfile_names $new_objfile] != -1 } {
-+                    incr j
-+                    set new_objfile \
-+                        [concat tmpdir/[file rootname [file tail  [lindex $opt_val 0]]]${j}.o]
-+                }
-+		lappend objfile_names $new_objfile
-+	    }
-+	    default {
-+		if [string length $opts($opt_name)] {
-+		    perror "option $opt_name multiply set in $file.d"
-+		    unresolved $subdir/$name
-+		    return
-+		}
-+
-+		# A single "# ld:" with no options should do the right thing.
-+		if { $opt_name == "ld" } {
-+		    set run_ld 1
-+		}
-+		# Likewise objcopy_linked_file.
-+		if { $opt_name == "objcopy_linked_file" } {
-+		    set run_objcopy 1
-+		}
-+	    }
-+	}
-+	if { $opt_name == "as" || $opt_name == "ld" } {
-+	    set opt_val [subst $opt_val]
-+	}
-+
-+	# Append differently whether it's a message (without space) or
-+	# an option or list (with space).
-+	switch -- $opt_name {
-+	    warning -
-+	    error {
-+		append opts($opt_name) $opt_val
-+	    }
-+	    default {
-+		set opts($opt_name) [concat $opts($opt_name) $opt_val]
-+	    }
-+	}
-+    }
-+
-+    foreach i $extra_options {
-+	set opt_name [lindex $i 0]
-+	set opt_val [lindex $i 1]
-+	if ![info exists opts($opt_name)] {
-+	    perror "unknown option $opt_name given in extra_opts"
-+	    unresolved $subdir/$name
-+	    return
-+	}
-+	# Add extra option to end of existing option, adding space
-+	# if necessary.
-+	if { ![regexp "warning|error" $opt_name]
-+	     && [string length $opts($opt_name)] } {
-+	    append opts($opt_name) " "
-+	}
-+	append opts($opt_name) $opt_val
-+    }
-+
-+    foreach opt { as ld } {
-+	regsub {\[big_or_little_endian\]} $opts($opt) \
-+	    [big_or_little_endian] opts($opt)
-+    }
-+
-+    if { $opts(name) == "" } {
-+	set testname "$subdir/$name"
-+    } else {
-+	set testname $opts(name)
-+    }
-+
-+    # Decide early whether we should run the test for this target.
-+    if { [llength $opts(noskip)] > 0 } {
-+	set targmatch 0
-+	foreach targ $opts(noskip) {
-+	    if [match_target $targ] {
-+		set targmatch 1
-+		break
-+	    }
-+	}
-+	if { $targmatch == 0 } {
-+	    return
-+	}
-+    }
-+    foreach targ $opts(anyskip) {
-+	if ![match_target $targ] {
-+	    return
-+	}
-+    }
-+    foreach targ $opts(skip) {
-+	if [match_target $targ] {
-+	    return
-+	}
-+    }
-+    if { [llength $opts(target)] > 0 } {
-+	set targmatch 0
-+	foreach targ $opts(target) {
-+	    if [match_target $targ] {
-+		set targmatch 1
-+		break
-+	    }
-+	}
-+	if { $targmatch == 0 } {
-+	    unsupported $testname
-+	    return
-+	}
-+    }
-+    foreach targ $opts(alltargets) {
-+	if ![match_target $targ] {
-+	    unsupported $testname
-+	    return
-+	}
-+    }
-+    foreach targ $opts(notarget) {
-+	if [match_target $targ] {
-+	    unsupported $testname
-+	    return
-+	}
-+    }
-+
-+    set program ""
-+    # It's meaningless to require an output-testing method when we
-+    # expect an error.
-+    if { $opts(error) == "" && $opts(error_output) == "" } {
-+	if {$opts(PROG) != ""} {
-+	    switch -- $opts(PROG) {
-+		objdump	{ set program objdump }
-+		nm	{ set program nm }
-+		objcopy	{ set program objcopy }
-+		readelf	{ set program readelf }
-+		default
-+		{ perror "unrecognized program option $opts(PROG) in $file.d"
-+		  unresolved $testname
-+		  return }
-+	    }
-+	} else {
-+	# Guess which program to run, by seeing which option was specified.
-+	    foreach p {objdump objcopy nm readelf} {
-+		if {$opts($p) != ""} {
-+		    if {$program != ""} {
-+			perror "ambiguous dump program in $file.d"
-+			unresolved $testname
-+			return
-+		    } else {
-+			set program $p
-+		    }
-+		}
-+	    }
-+	}
-+	if { $program == "" \
-+                 && $opts(map) == "" \
-+                 && $opts(warning) == "" \
-+                 && $opts(warning_output) == "" \
-+                 && $opts(error) == "" \
-+                 && $opts(error_output) == "" } {
-+	    perror "dump program unspecified in $file.d"
-+	    unresolved $testname
-+	    return
-+	}
-+    }
-+
-+    if { $opts(source) == "" } {
-+	set sourcefiles [list ${file}.s]
-+	set asflags [list ""]
-+	set objfile_names [list tmpdir/[file tail ${file}].o]
-+    } else {
-+	set sourcefiles {}
-+	foreach sf $opts(source) {
-+	    if { [string match "/*" $sf] } {
-+		lappend sourcefiles "$sf"
-+	    } else {
-+		lappend sourcefiles "$srcdir/$subdir/$sf"
-+	    }
-+	}
-+    }
-+
-+    if { $opts(dump) == "" } {
-+	set dfile ${file}.d
-+    } else {
-+	set dfile $srcdir/$subdir/$opts(dump)
-+    }
-+
-+    # Time to setup xfailures.
-+    foreach targ $opts(xfail) {
-+	setup_xfail $targ
-+    }
-+
-+    # Assemble each file.
-+    set objfiles {}
-+    for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
-+	set sourcefile [lindex $sourcefiles $i]
-+	set sourceasflags [lindex $asflags $i]
-+	set run_objcopy_objects 0
-+
-+	if { [string match "*RUN_OBJCOPY*" $sourceasflags] } {
-+	    set run_objcopy_objects 1
-+	}
-+	regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags
-+
-+	set objfile [lindex $objfile_names $i]
-+	catch "exec rm -f $objfile" exec_output
-+	lappend objfiles $objfile
-+	set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile"
-+
-+	send_log "$cmd\n"
-+	set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
-+	remote_upload host "ld.tmp"
-+	set comp_output [prune_warnings [file_contents "ld.tmp"]]
-+	remote_file host delete "ld.tmp"
-+	remote_file build delete "ld.tmp"
-+
-+	if { [lindex $cmdret 0] != 0 || ![string match "" $comp_output] } then {
-+	    send_log -- "$comp_output\n"
-+	    verbose "$comp_output" 3
-+
-+	    set exitstat "succeeded"
-+	    if { $cmdret != 0 } { set exitstat "failed" }
-+	    verbose -log "$exitstat with: <$comp_output>"
-+	    fail $testname
-+	    return
-+	}
-+
-+	if { $run_objcopy_objects } {
-+	    set cmd "$OBJCOPY $opts(objcopy_objects) $objfile"
-+
-+	    send_log "$cmd\n"
-+	    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \
-+			"" "/dev/null" "objcopy.tmp"]
-+	    remote_upload host "objcopy.tmp"
-+	    set comp_output [prune_warnings [file_contents "objcopy.tmp"]]
-+	    remote_file host delete "objcopy.tmp"
-+	    remote_file build delete "objcopy.tmp"
-+
-+	    if { [lindex $cmdret 0] != 0 \
-+		  || ![string match "" $comp_output] } {
-+		send_log -- "$comp_output\n"
-+		verbose "$comp_output" 3
-+
-+		set exitstat "succeeded"
-+		if { $cmdret != 0 } { set exitstat "failed" }
-+		verbose -log "$exitstat with: <$comp_output>"
-+		fail $testname
-+		return
-+	    }
-+	}
-+    }
-+
-+    if { (($opts(warning) != "") && ($opts(error) != "")) \
-+	 || (($opts(warning) != "") && ($opts(error_output) != "")) \
-+	 || (($opts(warning) != "") && ($opts(warning_output) != "")) \
-+	 || (($opts(error) != "") && ($opts(warning_output) != "")) \
-+	 || (($opts(error) != "") && ($opts(error_output) != "")) \
-+	 || (($opts(warning_output) != "") && ($opts(error_output) != "")) } {
-+	perror "$testname: bad mix of warning, error, warning_output, and error_output test-directives"
-+	unresolved $testname
-+	return
-+    }
-+
-+    set check_ld(source) ""
-+    set check_ld(terminal) 0
-+    if { $opts(error) != "" \
-+         || $opts(warning) != "" \
-+         || $opts(error_output) != "" \
-+         || $opts(warning_output) != "" } {
-+
-+        if { $opts(error) != "" || $opts(error_output) != "" } {
-+            set check_ld(terminal) 1
-+        } else {
-+            set check_ld(terminal) 0
-+        }
-+
-+        if { $opts(error) != "" || $opts(warning) != "" } {
-+            set check_ld(source) "regex"
-+            if { $opts(error) != "" } {
-+                set check_ld(regex) $opts(error)
-+            } else {
-+                set check_ld(regex) $opts(warning)
-+            }
-+        } else {
-+            set check_ld(source) "file"
-+            if { $opts(error_output) != "" } {
-+                set check_ld(file) $opts(error_output)
-+            } else {
-+                set check_ld(file) $opts(warning_output)
-+            }
-+        }
-+    }
-+
-+    # Perhaps link the file(s).
-+    if { $run_ld } {
-+	set objfile "tmpdir/dump"
-+	catch "exec rm -f $objfile" exec_output
-+
-+	# Add -L$srcdir/$subdir so that the linker command can use
-+	# linker scripts in the source directory.
-+	set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
-+
-+        # If needed then check for, or add a -Map option.
-+        set mapfile ""
-+        if { $opts(map) != "" } then {
-+            if { [regexp -- "-Map=(\[^ \]+)" $cmd all mapfile] } then {
-+                # Found existing mapfile option
-+                verbose -log "Existing mapfile '$mapfile' found"
-+            } else {
-+                # No mapfile option.
-+                set mapfile "tmpdir/dump.map"
-+                verbose -log "Adding mapfile '$mapfile'"
-+                set cmd "$cmd -Map=$mapfile"
-+            }
-+        }
-+
-+	send_log "$cmd\n"
-+	set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
-+	remote_upload host "ld.tmp"
-+	set comp_output [file_contents "ld.tmp"]
-+	remote_file host delete "ld.tmp"
-+	remote_file build delete "ld.tmp"
-+	set cmdret [lindex $cmdret 0]
-+
-+	if { $cmdret == 0 && $run_objcopy } {
-+	    set infile $objfile
-+	    set objfile "tmpdir/dump1"
-+	    remote_file host delete $objfile
-+
-+	    # Note that we don't use OBJCOPYFLAGS here; any flags must be
-+	    # explicitly specified.
-+	    set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile"
-+
-+	    send_log "$cmd\n"
-+	    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
-+	    remote_upload host "ld.tmp"
-+	    append comp_output [file_contents "ld.tmp"]
-+	    remote_file host delete "ld.tmp"
-+	    remote_file build delete "ld.tmp"
-+	    set cmdret [lindex $cmdret 0]
-+	}
-+
-+	regsub "\n$" $comp_output "" comp_output
-+	if { $cmdret != 0 || $comp_output != "" || $check_ld(source) != "" } then {
-+	    set exitstat "succeeded"
-+	    if { $cmdret != 0 } { set exitstat "failed" }
-+
-+            if { $check_ld(source) == "regex" } {
-+                verbose -log "$exitstat with: <$comp_output>, expected: <$check_ld(regex)>"
-+            } elseif { $check_ld(source) == "file" } {
-+                verbose -log "$exitstat with: <$comp_output>, expected in file $check_ld(file)"
-+                set_file_contents "tmpdir/ld.messages" "$comp_output"
-+            } else {
-+                verbose -log "$exitstat with: <$comp_output>, no expected output"
-+            }
-+	    send_log -- "$comp_output\n"
-+	    verbose "$comp_output" 3
-+
-+	    if { (($check_ld(source) == "") == ($comp_output == "")) \
-+                 && (($cmdret == 0) == ($check_ld(terminal) == 0)) \
-+                 && ((($check_ld(source) == "regex") \
-+                      && ($check_ld(regex) == "") == ($comp_output == "") \
-+                      && [regexp -- $check_ld(regex) $comp_output]) \
-+                     || (($check_ld(source) == "file") \
-+                         && (![regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$check_ld(file)"]))) } {
-+                # We have the expected output from ld.
-+		if { $check_ld(terminal) || $program == "" } {
-+		    pass $testname
-+		    return
-+		}
-+	    } else {
-+		fail $testname
-+		return
-+	    }
-+	}
-+
-+        if { $opts(map) != "" } then {
-+            # Check the map file matches.
-+            set map_pattern_file $srcdir/$subdir/$opts(map)
-+            verbose -log "Compare '$mapfile' against '$map_pattern_file'"
-+            if { [regexp_diff $mapfile $map_pattern_file] } then {
-+                fail "$testname (map file check)"
-+            } else {
-+                pass "$testname (map file check)"
-+            }
-+
-+            if { $program == "" } then {
-+                return
-+            }
-+        }
-+    } else {
-+	set objfile [lindex $objfiles 0]
-+    }
-+
-+    # We must not have expected failure if we get here.
-+    if { $opts(error) != "" } {
-+	fail $testname
-+	return
-+    }
-+
-+    set progopts1 $opts($program)
-+    eval set progopts \$[string toupper $program]FLAGS
-+    eval set binary \$[string toupper $program]
-+
-+    if { ![is_remote host] && [which $binary] == 0 } {
-+	untested $testname
-+	return
-+    }
-+
-+    if { $progopts1 == "" } { set $progopts1 "-r" }
-+    verbose "running $binary $progopts $progopts1" 3
-+
-+    # Objcopy, unlike the other two, won't send its output to stdout,
-+    # so we have to run it specially.
-+    set cmd "$binary $progopts $progopts1 $objfile > $dumpfile"
-+    if { $program == "objcopy" } {
-+	set cmd "$binary $progopts $progopts1 $objfile $dumpfile"
-+    }
-+
-+    # Ensure consistent sorting of symbols
-+    if {[info exists env(LC_ALL)]} {
-+	set old_lc_all $env(LC_ALL)
-+    }
-+    set env(LC_ALL) "C"
-+    send_log "$cmd\n"
-+    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
-+    set cmdret [lindex $cmdret 0]
-+    remote_upload host "ld.tmp"
-+    set comp_output [prune_warnings [file_contents "ld.tmp"]]
-+    remote_file host delete "ld.tmp"
-+    remote_file build delete "ld.tmp"
-+    if {[info exists old_lc_all]} {
-+	set env(LC_ALL) $old_lc_all
-+    } else {
-+	unset env(LC_ALL)
-+    }
-+    if { $cmdret != 0 || $comp_output != "" } {
-+	send_log "exited abnormally with $cmdret, output:$comp_output\n"
-+	fail $testname
-+	return
-+    }
-+
-+    if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
-+    if { [regexp_diff $dumpfile "${dfile}"] } then {
-+	fail $testname
-+	if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
-+	return
-+    }
-+
-+    pass $testname
-+}
-+
-+proc slurp_options { file } {
-+    # If options_regsub(foo) is set to {a b}, then the contents of a
-+    # "#foo:" line will have regsub -all applied to replace a with b.
-+    global options_regsub
-+
-+    if [catch { set f [open $file r] } x] {
-+	#perror "couldn't open `$file': $x"
-+	perror "$x"
-+	return -1
-+    }
-+    set opt_array {}
-+    # whitespace expression
-+    set ws  {[ 	]*}
-+    set nws {[^ 	]*}
-+    # whitespace is ignored anywhere except within the options list;
-+    # option names are alphabetic plus underscore only.
-+    set pat "^#${ws}(\[a-zA-Z_\]*)$ws:${ws}(.*)$ws\$"
-+    while { [gets $f line] != -1 } {
-+	set line [string trim $line]
-+	# Whitespace here is space-tab.
-+	if [regexp $pat $line xxx opt_name opt_val] {
-+	    # match!
-+	    if [info exists options_regsub($opt_name)] {
-+		set subst $options_regsub($opt_name)
-+		regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \
-+		    opt_val
-+	    }
-+	    lappend opt_array [list $opt_name $opt_val]
-+	} else {
-+	    break
-+	}
-+    }
-+    close $f
-+    return $opt_array
-+}
-+
-+proc file_contents { filename } {
-+    set file [open $filename r]
-+    set contents [read $file]
-+    close $file
-+    return $contents
-+}
-+
-+proc set_file_contents { filename contents } {
-+    set file [open $filename w]
-+    puts $file "$contents"
-+    close $file
-+}
-+
- # Create an archive using ar
- #
- proc ar_simple_create { ar aropts target objects } {
--- 
-2.26.2
-

diff --git a/9999/0011-Gentoo-add-with-extra-soversion-suffix-option.patch b/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
similarity index 97%
rename from 9999/0011-Gentoo-add-with-extra-soversion-suffix-option.patch
rename to 9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
index cc9f0cc..d7f696c 100644
--- a/9999/0011-Gentoo-add-with-extra-soversion-suffix-option.patch
+++ b/9999/0006-Gentoo-add-with-extra-soversion-suffix-option.patch
@@ -1,7 +1,7 @@
-From f1d34965ce140071bb77313bbca01914ace59e27 Mon Sep 17 00:00:00 2001
+From eefafabed03c163287326afaadc4cc0e5840ea7b Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Wed, 12 Sep 2018 23:44:29 +0100
-Subject: [PATCH 11/16] Gentoo: add --with-extra-soversion-suffix= option
+Subject: [PATCH 6/9] Gentoo: add --with-extra-soversion-suffix= option
 
 --with-extra-soversion-suffix= will allow Gentoo to
 distinct libbfd.so and libopcodes.so to have more precise

diff --git a/9999/0007-Gentoo-Pass-no-warn-shared-textrel-to-ld-in-its-test.patch b/9999/0007-Gentoo-Pass-no-warn-shared-textrel-to-ld-in-its-test.patch
deleted file mode 100644
index 74f96cf..0000000
--- a/9999/0007-Gentoo-Pass-no-warn-shared-textrel-to-ld-in-its-test.patch
+++ /dev/null
@@ -1,47 +0,0 @@
-From 221b8f6dfdfcb5e9d04069fdc2fb1aa6a881cb60 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 3 Jun 2018 21:40:36 +0200
-Subject: [PATCH 07/16] Gentoo: Pass --no-warn-shared-textrel to ld in its
- testsuite
-
----
- ld/testsuite/lib/ld-lib.exp | 8 ++++----
- 1 file changed, 4 insertions(+), 4 deletions(-)
-
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index 853a4d87e6..ec123e2fc1 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -165,7 +165,7 @@ proc default_ld_relocate { ld target objects } {
-     global HOSTING_EMU
- 
-     remote_file host delete $target
--    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv -o $target -r $objects"]
-+    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv --no-warn-shared-textrel -o $target -r $objects"]
- }
- 
- # Check to see if ld is being invoked with a non-endian output format
-@@ -203,9 +203,9 @@ proc default_ld_link { ld target objects } {
-     # - .*ld/ld-new    -> we're working with the new linker
-     # - otherwise      -> we're likely working with the system compiler
-     if {[regexp {ld/ld-new$} $ld]} {
--      set gentoosysv "--hash-style=sysv"
-+      set gentoosysv "--hash-style=sysv --no-warn-shared-textrel"
-     } else {
--      set gentoosysv "-Wl,--hash-style=sysv"
-+      set gentoosysv "-Wl,--hash-style=sysv -Wl,--no-warn-shared-textrel"
-     }
- 
-     remote_file host delete $target
-@@ -972,7 +972,7 @@ proc run_dump_test { name {extra_options {}} } {
- 
- 	# Add -L$srcdir/$subdir so that the linker command can use
- 	# linker scripts in the source directory.
--	set cmd "$LD --hash-style=sysv $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+	set cmd "$LD --hash-style=sysv --no-warn-shared-textrel $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
- 		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
- 
-         # If needed then check for, or add a -Map option.
--- 
-2.26.2
-

diff --git a/9999/0013-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
similarity index 91%
rename from 9999/0013-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
rename to 9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
index 713a0a9..0b0cbfe 100644
--- a/9999/0013-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
+++ b/9999/0007-Gentoo-ld-enable-new-dtags-by-default-for-linux-gnu-.patch
@@ -1,7 +1,7 @@
-From 14ba11502cbc93e938e0b43e9648aedb7462ddeb Mon Sep 17 00:00:00 2001
+From cf8983d602c56eb31ee0e356df670d9c2876ce15 Mon Sep 17 00:00:00 2001
 From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
 Date: Sun, 13 Oct 2019 05:25:28 +0200
-Subject: [PATCH 13/16] Gentoo: ld: enable new dtags by default for linux/gnu
+Subject: [PATCH 7/9] Gentoo: ld: enable new dtags by default for linux/gnu
  targets
 
 Original author: Mike Frysinger <vapier@gentoo.org>

diff --git a/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch b/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch
index e54ccd1..8e0e091 100644
--- a/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch
+++ b/9999/0008-Gentoo-Restore-TEXTREL-warnings-for-non-shared-objec.patch
@@ -1,11 +1,12 @@
-From 3439646abc93066af8cc651940f30fd0f9b99760 Mon Sep 17 00:00:00 2001
+From 74afb38257f4a35d681883348ef54317674827e3 Mon Sep 17 00:00:00 2001
 From: Sergei Trofimovich <slyfox@gentoo.org>
 Date: Thu, 1 Mar 2018 12:35:03 +0100
-Subject: [PATCH 08/16] Gentoo: Restore TEXTREL warnings for non-shared objects
+Subject: [PATCH 8/9] Gentoo: Restore TEXTREL warnings for non-shared objects
 
 ---
- bfd/elflink.c | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
+ bfd/elflink.c                | 4 ++--
+ ld/testsuite/ld-i386/warn1.d | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/bfd/elflink.c b/bfd/elflink.c
 index 90ada7a1cc..b4636885aa 100644
@@ -29,6 +30,16 @@ index 90ada7a1cc..b4636885aa 100644
  		  break;
  		}
  	    }
+diff --git a/ld/testsuite/ld-i386/warn1.d b/ld/testsuite/ld-i386/warn1.d
+index 3c78f31efd..49bcb5171f 100644
+--- a/ld/testsuite/ld-i386/warn1.d
++++ b/ld/testsuite/ld-i386/warn1.d
+@@ -1,4 +1,4 @@
+ #name: --warn-shared-textrel --fatal-warnings
+ #as: --32
+ #ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
+-#error: .*warning: creating a DT_TEXTREL in a shared object
++#error: .*warning: creating a DT_TEXTREL in object
 -- 
 2.26.2
 

diff --git a/9999/0009-Gentoo-Fix-test-for-precise-textrel-warning-message-.patch b/9999/0009-Gentoo-Fix-test-for-precise-textrel-warning-message-.patch
deleted file mode 100644
index e87a82d..0000000
--- a/9999/0009-Gentoo-Fix-test-for-precise-textrel-warning-message-.patch
+++ /dev/null
@@ -1,24 +0,0 @@
-From 61cc50292e7cc3f8871946f0720ff039ddf7a2be Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 3 Jun 2018 22:36:40 +0200
-Subject: [PATCH 09/16] Gentoo: Fix test for precise textrel warning message,
- after non-shared object change
-
-(Broken by "Gentoo: Restore TEXTREL warnings for non-shared objects")
----
- ld/testsuite/ld-i386/warn1.d | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/ld/testsuite/ld-i386/warn1.d b/ld/testsuite/ld-i386/warn1.d
-index 3c78f31efd..3319308d33 100644
---- a/ld/testsuite/ld-i386/warn1.d
-+++ b/ld/testsuite/ld-i386/warn1.d
-@@ -1,4 +1,4 @@
- #name: --warn-shared-textrel --fatal-warnings
- #as: --32
- #ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
--#error: .*warning: creating a DT_TEXTREL in a shared object
-+#error: .*warning: creating a DT_TEXTREL in object.
--- 
-2.26.2
-

diff --git a/9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch b/9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch
new file mode 100644
index 0000000..4ff406f
--- /dev/null
+++ b/9999/0009-Gentoo-Pass-hash-style-sysv-and-no-warn-shared-textr.patch
@@ -0,0 +1,62 @@
+From 2055e278cb6e984760dbf8627efef2158e215449 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
+Date: Wed, 18 Oct 2017 00:44:49 +0200
+Subject: [PATCH 9/9] Gentoo: Pass --hash-style=sysv and
+ --no-warn-shared-textrel to ld in the testsuite
+
+---
+ binutils/testsuite/lib/binutils-common.exp |  2 +-
+ ld/testsuite/lib/ld-lib.exp                | 16 ++++++++++++++--
+ 2 files changed, 15 insertions(+), 3 deletions(-)
+
+diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
+index b9e3c6d817..bb4ef987b3 100644
+--- a/binutils/testsuite/lib/binutils-common.exp
++++ b/binutils/testsuite/lib/binutils-common.exp
+@@ -1125,7 +1125,7 @@ proc run_dump_test { name {extra_options {}} } {
+ 
+             # Add -L$srcdir/$subdir so that the linker command can use
+             # linker scripts in the source directory.
+-            set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
++            set cmd "$LD --hash-style=sysv --no-warn-shared-textrel $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
+ 		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
+ 
+             # If needed then check for, or add a -Map option.
+diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
+index 015eda6eb9..0b945b539d 100644
+--- a/ld/testsuite/lib/ld-lib.exp
++++ b/ld/testsuite/lib/ld-lib.exp
+@@ -165,7 +165,7 @@ proc default_ld_relocate { ld target objects } {
+     global HOSTING_EMU
+ 
+     remote_file host delete $target
+-    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU -o $target -r $objects"]
++    return [run_host_cmd_yesno "$ld" "$HOSTING_EMU --hash-style=sysv --no-warn-shared-textrel -o $target -r $objects"]
+ }
+ 
+ # Check to see if ld is being invoked with a non-endian output format
+@@ -196,8 +196,20 @@ proc default_ld_link { ld target objects } {
+ 	set flags [big_or_little_endian]
+     }
+ 
++    # Hilariously, this procedure is called sometimes with $CC and sometimes
++    # with $ld as parameter. If we want to change the default behaviour, we
++    # need to take the different option formats into account.
++    # We check the $ld parameter for
++    # - ld-new         -> we're working with the new linker
++    # - otherwise      -> we're likely working with the system compiler
++    if {[regexp {ld-new$} $ld]} {
++      set gentoosysv "--hash-style=sysv --no-warn-shared-textrel"
++    } else {
++      set gentoosysv "-Wl,--hash-style=sysv -Wl,--no-warn-shared-textrel"
++    }
++
+     remote_file host delete $target
+-    set exec_output [run_host_cmd "$ld" "$flags -o $target $objects"]
++    set exec_output [run_host_cmd "$ld" "$gentoosysv $flags -o $target $objects"]
+     set exec_output [prune_warnings $exec_output]
+ 
+     # We don't care if we get a warning about a non-existent start
+-- 
+2.26.2
+

diff --git a/9999/0010-Gentoo-Fix-textrel-warning-format-test.patch b/9999/0010-Gentoo-Fix-textrel-warning-format-test.patch
deleted file mode 100644
index f29ae7f..0000000
--- a/9999/0010-Gentoo-Fix-textrel-warning-format-test.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-From fab9a66210e065ff5a14d4bc70841406cdecc62e Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Mon, 16 Jul 2018 12:20:37 +0200
-Subject: [PATCH 10/16] Gentoo: Fix textrel warning format test
-
----
- ld/testsuite/ld-i386/warn1.d | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/ld/testsuite/ld-i386/warn1.d b/ld/testsuite/ld-i386/warn1.d
-index 3319308d33..49bcb5171f 100644
---- a/ld/testsuite/ld-i386/warn1.d
-+++ b/ld/testsuite/ld-i386/warn1.d
-@@ -1,4 +1,4 @@
- #name: --warn-shared-textrel --fatal-warnings
- #as: --32
- #ld: -shared -melf_i386 --warn-shared-textrel --fatal-warnings
--#error: .*warning: creating a DT_TEXTREL in object.
-+#error: .*warning: creating a DT_TEXTREL in object
--- 
-2.26.2
-

diff --git a/9999/0012-no-patch-Gentoo-Add-patch-tarball-generation-script.patch b/9999/0012-no-patch-Gentoo-Add-patch-tarball-generation-script.patch
deleted file mode 100644
index a60bb9c..0000000
--- a/9999/0012-no-patch-Gentoo-Add-patch-tarball-generation-script.patch
+++ /dev/null
@@ -1,217 +0,0 @@
-From 7343f154ae6bc08bd2c3c051f039824af3d917e5 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Wed, 11 Oct 2017 21:56:53 +0200
-Subject: [PATCH 12/16] [no patch] Gentoo: Add patch tarball generation script
-
-(cherry picked from commit 90427abb2aac0cc4ebcb73397cc3ad574c6fec5d)
----
- scripts/gentoo/0000-Gentoo-Git-is-development |  12 ++
- scripts/gentoo/9999-Gentoo-We-make-a-release  |  12 ++
- scripts/gentoo/README.Gentoo.patches          |  31 +++++
- scripts/gentoo/make-tarball.sh                | 118 ++++++++++++++++++
- 4 files changed, 173 insertions(+)
- create mode 100644 scripts/gentoo/0000-Gentoo-Git-is-development
- create mode 100644 scripts/gentoo/9999-Gentoo-We-make-a-release
- create mode 100644 scripts/gentoo/README.Gentoo.patches
- create mode 100755 scripts/gentoo/make-tarball.sh
-
-diff --git a/scripts/gentoo/0000-Gentoo-Git-is-development b/scripts/gentoo/0000-Gentoo-Git-is-development
-new file mode 100644
-index 0000000000..2b9482d033
---- /dev/null
-+++ b/scripts/gentoo/0000-Gentoo-Git-is-development
-@@ -0,0 +1,12 @@
-+Gentoo: Git is development
-+
-+--- a/bfd/development.sh
-++++ b/bfd/development.sh
-+@@ -16,5 +16,5 @@
-+ # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+ 
-+ # Controls whether to enable development-mode features by default.
-+-development=false
-++development=true
-+ 
-+
-diff --git a/scripts/gentoo/9999-Gentoo-We-make-a-release b/scripts/gentoo/9999-Gentoo-We-make-a-release
-new file mode 100644
-index 0000000000..fea66d97b4
---- /dev/null
-+++ b/scripts/gentoo/9999-Gentoo-We-make-a-release
-@@ -0,0 +1,12 @@
-+Gentoo: We make a release, so switch development flag off
-+
-+--- a/bfd/development.sh
-++++ b/bfd/development.sh
-+@@ -16,5 +16,5 @@
-+ # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-+ 
-+ # Controls whether to enable development-mode features by default.
-+-development=true
-++development=false
-+ 
-+
-diff --git a/scripts/gentoo/README.Gentoo.patches b/scripts/gentoo/README.Gentoo.patches
-new file mode 100644
-index 0000000000..504dc67127
---- /dev/null
-+++ b/scripts/gentoo/README.Gentoo.patches
-@@ -0,0 +1,31 @@
-+ ============
-+ === What ===
-+ ============
-+
-+Gentoo patchsets for binutils are maintained as vendor branches of the upstream
-+binutils-glb git repository. From there, we bundle all the commits into a tarball
-+and distribute it via our public mirroring system.
-+
-+If you want specific info about a patch (like what it does or whose great idea 
-+it was to change the code), read the patch!  We try to fill out the commit
-+messages with useful info such as what it does, why it's needed, bug reports, 
-+original creators, etc...  
-+
-+ =============
-+ === Where ===
-+ =============
-+
-+Currently, https://github.com/gentoo/binutils-gdb
-+
-+ ===========
-+ === How ===
-+ ===========
-+ 
-+The patch naming convention is precisely as generated by "git format-patch".
-+
-+All patches should apply with -p1 (so they can be used both with the legacy
-+epatch function and the new, more strict eapply function).
-+
-+Commits where the commit message starts with "[no patch]" will not be included
-+in the patch tarball. This is useful for changes to the tarball generation
-+script, or for the addition of extra files that are not patches.
-diff --git a/scripts/gentoo/make-tarball.sh b/scripts/gentoo/make-tarball.sh
-new file mode 100755
-index 0000000000..575f48bf6a
---- /dev/null
-+++ b/scripts/gentoo/make-tarball.sh
-@@ -0,0 +1,118 @@
-+#!/bin/bash
-+
-+PN="binutils"
-+PV=$1
-+pver=$2
-+
-+if [[ -z ${PV} ]] ; then
-+	echo "Usage: $0 binutils-version patchset-version-to-be-created"
-+	echo "Please read the script before trying to use it :)"
-+	exit 1
-+fi
-+
-+# check that we're in the root of a binutils-gdb git repo
-+
-+if [[ ! -f COPYING.LIBGLOSS ]] || [[ ! -d .git ]] ; then
-+	echo "Error: You need to call this script in the main directory of a Gentoo binutils-gdb git clone"
-+	exit 1
-+fi
-+
-+# check that we're on a branch gentoo/${PV}
-+
-+mybranchinfo=$(git status --porcelain -b|grep '^##')
-+mybranch=$(echo ${mybranchinfo}|sed -e 's:^## ::' -e 's:\.\.\..*$::')
-+if [[ ! "gentoo/binutils-${PV}" == "${mybranch}" ]] ; then
-+	echo "Error: Your git repository is on the incorrect branch ${mybranch}; should be gentoo/binutils-${PV}"
-+	exit 1
-+fi
-+
-+# check that the working directory is clean
-+
-+mystatusinfo=$(git status --porcelain)
-+if [[ ! -z "${mystatusinfo}" ]] ; then
-+	echo "Error: Your working directory is not clean"
-+	exit 1
-+fi
-+
-+# check if the tag already exists
-+
-+mytaginfo=$(git tag -l|grep "gentoo/binutils-${PV}-${pver}")
-+if [[ ! -z "${mytaginfo}" ]] ; then
-+	echo "Error: A tag corresponding to this patch level already exists (gentoo/binutils-${PV}-${pver})"
-+	exit 1
-+fi
-+
-+# luckily binutils git has no /tmp dir and no tar.xz files, but let's better check and be pathologically careful
-+
-+if [[ -e tmp ]] || [[ -e ${PN}-${PV}-patches-${pver}.tar.xz ]] ; then
-+	echo "Error: tmp or ${PN}-${PV}-patches-${pver}.tar.xz exists in git"
-+	exit 1
-+fi
-+rm -rf tmp
-+rm -f ${PN}-${PV}-*.tar.bz2
-+
-+for myname in 0*.patch ; do
-+	if [[ -e "${myname}" ]]; then
-+		echo "Error: ${myname} exists in git"
-+		exit 1
-+	fi
-+done
-+rm -f 0*.patch
-+
-+# check if we have to override the upstream tag
-+
-+mytaginfo=$(git tag -l|grep "gentoo/binutils-${PV}-upstream")
-+if [[ ! -z "${mytaginfo}" ]] ; then
-+	starttag="gentoo/binutils-${PV}-upstream"
-+else
-+	starttag="binutils-${PV//./_}"
-+fi
-+if [[ "${PV}" == "9999" ]]; then
-+	starttag="master"
-+fi
-+echo "Starting from tag ${starttag}"
-+
-+mkdir -p tmp/patch
-+
-+# copy README.Gentoo.patches
-+
-+cp scripts/gentoo/README.Gentoo.patches tmp/ || exit 1
-+
-+# create and rename patches
-+
-+git format-patch ${starttag}..HEAD > /dev/null || exit 1
-+
-+# remove all patches where the summary line starts with:
-+# - [no-tarball]: not related to upstream tarball
-+# - [no-patch]: not related to upstream patches
-+# - "Automatic date update in version.in": daily bumps
-+rm -f 0???-no-tarball-*.patch
-+rm -f 0???-no-patch-*.patch
-+rm -f 0???-Automatic-date-update-in-version.in.patch
-+
-+for myname in 0*.patch ; do
-+	mv ${myname} tmp/patch/ || exit 1
-+done
-+
-+# add the extra patch if needed
-+
-+if [[ "${PV}" != "9999" ]]; then
-+	cp scripts/gentoo/0000-Gentoo-Git-is-development tmp/patch/0000-Gentoo-Git-is-development.patch || exit 1
-+	cp scripts/gentoo/9999-Gentoo-We-make-a-release tmp/patch/9999-Gentoo-We-make-a-release.patch || exit 1
-+fi
-+
-+# add a history file
-+
-+git log --stat --decorate ${starttag}..HEAD > tmp/patch/README.history || exit 1
-+
-+# package everything up
-+
-+tar -Jcf ${PN}-${PV}-patches-${pver}.tar.xz \
-+	-C tmp patch README.Gentoo.patches || exit 1
-+rm -r tmp
-+
-+du -b *.tar.xz
-+
-+# tag the commit
-+
-+git tag -s -m "Gentoo patchset binutils-${PV}-${pver}" "gentoo/binutils-${PV}-${pver}"
--- 
-2.26.2
-

diff --git a/9999/0014-Gentoo-Remove-block-mistakenly-duplicated-in-1222895.patch b/9999/0014-Gentoo-Remove-block-mistakenly-duplicated-in-1222895.patch
deleted file mode 100644
index 20dbdd1..0000000
--- a/9999/0014-Gentoo-Remove-block-mistakenly-duplicated-in-1222895.patch
+++ /dev/null
@@ -1,777 +0,0 @@
-From e54cd834e32160ac588add78a2990648328c2f06 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 10 May 2020 20:13:43 +0300
-Subject: [PATCH 14/16] Gentoo: Remove block mistakenly duplicated in
- 1222895ec55f34a97fb2cbcd80d421e24308f618
-
----
- ld/testsuite/lib/ld-lib.exp | 753 ------------------------------------
- 1 file changed, 753 deletions(-)
-
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index ec123e2fc1..ae72f21d72 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -421,759 +421,6 @@ proc ld_link_defsyms {} {
-     return $flags
- }
- 
--# run_dump_test FILE (optional:) EXTRA_OPTIONS
--# Copied from gas testsuite, tweaked and further extended.
--#
--# Assemble a .s file, then run some utility on it and check the output.
--#
--# There should be an assembly language file named FILE.s in the test
--# suite directory, and a pattern file called FILE.d.  `run_dump_test'
--# will assemble FILE.s, run some tool like `objdump', `objcopy', or
--# `nm' on the .o file to produce textual output, and then analyze that
--# with regexps.  The FILE.d file specifies what program to run, and
--# what to expect in its output.
--#
--# The FILE.d file begins with zero or more option lines, which specify
--# flags to pass to the assembler, the program to run to dump the
--# assembler's output, and the options it wants.  The option lines have
--# the syntax:
--#
--#         # OPTION: VALUE
--#
--# OPTION is the name of some option, like "name" or "objdump", and
--# VALUE is OPTION's value.  The valid options are described below.
--# Whitespace is ignored everywhere, except within VALUE.  The option
--# list ends with the first line that doesn't match the above syntax
--# (hmm, not great for error detection).
--#
--# The optional EXTRA_OPTIONS argument to `run_dump_test' is a list of
--# two-element lists.  The first element of each is an option name, and
--# the second additional arguments to be added on to the end of the
--# option list as given in FILE.d.  (If omitted, no additional options
--# are added.)
--#
--# The interesting options are:
--#
--#   name: TEST-NAME
--#	The name of this test, passed to DejaGNU's `pass' and `fail'
--#       commands.  If omitted, this defaults to FILE, the root of the
--#       .s and .d files' names.
--#
--#   as: FLAGS
--#	When assembling, pass FLAGS to the assembler.
--#       If assembling several files, you can pass different assembler
--#       options in the "source" directives.  See below.
--#
--#   ld: FLAGS
--#       Link assembled files using FLAGS, in the order of the "source"
--#       directives, when using multiple files.
--#
--#   ld_after_inputfiles: FLAGS
--#       Similar to "ld", but put after all input files.
--#
--#   objcopy_objects: FLAGS
--#	Run objcopy with the specified flags after assembling any source
--#	that has the special marker RUN_OBJCOPY in the source specific
--#	flags.
--#
--#   objcopy_linked_file: FLAGS
--#	Run objcopy on the linked file with the specified flags.
--#	This lets you transform the linked file using objcopy, before the
--#	result is analyzed by an analyzer program specified below (which
--#	may in turn *also* be objcopy).
--#
--#   PROG: PROGRAM-NAME
--#       The name of the program to run to analyze the .o file produced
--#       by the assembler or the linker output.  This can be omitted;
--#       run_dump_test will guess which program to run by seeing which of
--#       the flags options below is present.
--#
--#   readelf: FLAGS
--#   objdump: FLAGS
--#   nm: FLAGS
--#   objcopy: FLAGS
--#	Use the specified program to analyze the assembler or linker
--#       output file, and pass it FLAGS, in addition to the output name.
--#	Note that they are run with LC_ALL=C in the environment to give
--#	consistent sorting of symbols.
--#
--#   source: SOURCE [FLAGS]
--#	Assemble the file SOURCE.s using the flags in the "as" directive
--#       and the (optional) FLAGS.  If omitted, the source defaults to
--#       FILE.s.
--#       This is useful if several .d files want to share a .s file.
--#       More than one "source" directive can be given, which is useful
--#       when testing linking.
--#
--#   dump: DUMP
--#	Match against DUMP.d.  If omitted, this defaults to FILE.d.  This
--#	is useful if several .d files differ by options only.  Options are
--#	always read from FILE.d.
--#
--#   xfail: TARGET
--#       The test is expected to fail on TARGET.  This may occur more than
--#       once.
--#
--#   target: TARGET
--#	Only run the test for TARGET.
--#	You may provide target name "cfi" for any target supporting the
--#	CFI statements.  You may provide target name "shared" for any
--#	target supporting shared libraries.  Otherwise TARGET is called
--#	as a TCL procedure if surrounded by square brackets, or passed
--#	to "istarget" if not.
--#	This may occur more than once; the target being tested must match
--#	at least one.  Otherwise the test will be marked unsupported.
--#
--#   alltargets: TARGET
--#	Only run the test for TARGET.
--#	The syntax for TARGET is as with 'target'.
--#	This may occur more than once; the target being tested must match
--#	all of them.  Otherwise the test will be marked unsupported.
--#
--#   notarget: TARGET
--#	Do not run the test for TARGET.
--#	The syntax for TARGET is as with 'target'.
--#	This may occur more than once; the target being tested must not
--#	match any of them.  Otherwise the test will be marked unsupported.
--#
--#   skip: TARGET
--#   anyskip: TARGET
--#   noskip: TARGET
--#	These are exactly the same as "notarget", "alltargets" and
--#	"target" respectively, except that they do nothing at all if the
--#	check fails.  They should only be used in groups, to construct a
--#	single test which is run on all targets but with variant options
--#	or expected output on some targets.  (For example, see
--#	gas/arm/inst.d and gas/arm/wince_inst.d.)
--#
--#   error: REGEX
--#	An error with message matching REGEX must be emitted for the test
--#	to pass.  The PROG, readelf, objdump, nm and objcopy options have
--#	no meaning and need not be supplied if this is present.  Multiple
--#	"error" directives append to the expected linker error message.
--#
--#   error_output: FILE
--#       Means the same as 'error', except the regular expression lines
--#       are contains in FILE.
--#
--#   warning: REGEX
--#	Expect a linker warning matching REGEX.  It is an error to issue
--#	both "error" and "warning".  Multiple "warning" directives
--#	append to the expected linker warning message.
--#
--#   warning_output: FILE
--#       Means the same as 'warning', except the regular expression
--#       lines are contains in FILE.
--#
--#   map: FILE
--#       Adding this option will cause the linker to generate a linker
--#       map file, using the -Map=MAPFILE command line option.  If
--#       there is no -Map=MAPFILE in the 'ld: FLAGS' then one will be
--#       added to the linker command line.  The contents of the
--#       generated MAPFILE are then compared against the regexp lines
--#       in FILE using `regexp_diff' (see below for details).
--#
--# Each option may occur at most once unless otherwise mentioned.
--#
--# After the option lines come regexp lines.  `run_dump_test' calls
--# `regexp_diff' to compare the output of the dumping tool against the
--# regexps in FILE.d.  `regexp_diff' is defined in binutils-common.exp;
--# see further comments there.
--#
--proc run_dump_test { name {extra_options {}} } {
--    global subdir srcdir
--    global OBJDUMP NM AS OBJCOPY READELF LD
--    global OBJDUMPFLAGS NMFLAGS ASFLAGS OBJCOPYFLAGS READELFFLAGS LDFLAGS
--    global host_triplet runtests
--    global env verbose
--    global ld_elf_shared_opt
--
--    if { [is_elf_format] && [check_shared_lib_support] } {
--	set ld_extra_opt "$ld_elf_shared_opt"
--    } else {
--	set ld_extra_opt ""
--    }
--
--    if [string match "*/*" $name] {
--	set file $name
--	set name [file tail $name]
--    } else {
--	set file "$srcdir/$subdir/$name"
--    }
--
--    if ![runtest_file_p $runtests $name] then {
--	return
--    }
--
--    set opt_array [slurp_options "${file}.d"]
--    if { $opt_array == -1 } {
--	perror "error reading options from $file.d"
--	unresolved $subdir/$name
--	return
--    }
--    set dumpfile tmpdir/dump.out
--    set run_ld 0
--    set run_objcopy 0
--    set objfile_names {}
--    set opts(as) {}
--    set opts(ld) {}
--    set opts(ld_after_inputfiles) {}
--    set opts(xfail) {}
--    set opts(target) {}
--    set opts(alltargets) {}
--    set opts(notarget) {}
--    set opts(skip) {}
--    set opts(anyskip) {}
--    set opts(noskip) {}
--    set opts(objdump) {}
--    set opts(nm) {}
--    set opts(objcopy) {}
--    set opts(readelf) {}
--    set opts(name) {}
--    set opts(PROG) {}
--    set opts(source) {}
--    set opts(dump) {}
--    set opts(error) {}
--    set opts(warning) {}
--    set opts(error_output) {}
--    set opts(warning_output) {}
--    set opts(objcopy_linked_file) {}
--    set opts(objcopy_objects) {}
--    set opts(map) {}
--
--    foreach i $opt_array {
--	set opt_name [lindex $i 0]
--	set opt_val [lindex $i 1]
--	if ![info exists opts($opt_name)] {
--	    perror "unknown option $opt_name in file $file.d"
--	    unresolved $subdir/$name
--	    return
--	}
--
--	switch -- $opt_name {
--	    xfail {}
--	    target {}
--	    alltargets {}
--	    notarget {}
--	    skip {}
--	    anyskip {}
--	    noskip {}
--	    warning {}
--	    error {}
--	    source {
--		# Move any source-specific as-flags to a separate list to
--		# simplify processing.
--		if { [llength $opt_val] > 1 } {
--		    lappend asflags [lrange $opt_val 1 end]
--		    set opt_val [lindex $opt_val 0]
--		} else {
--		    lappend asflags {}
--		}
--
--                # Create the object file name based on nothing but the source
--                # file name.
--                set new_objfile \
--                    [concat tmpdir/[file rootname [file tail [lindex $opt_val 0]]].o]
--                # But, sometimes, we have the exact same source filename in
--                # different directories (foo/src.s bar/src.s) which would lead
--                # us to try and create two src.o files.  We detect this
--                # conflict here, and instead create src.o and src1.o.
--                set j 0
--                while { [lsearch $objfile_names $new_objfile] != -1 } {
--                    incr j
--                    set new_objfile \
--                        [concat tmpdir/[file rootname [file tail  [lindex $opt_val 0]]]${j}.o]
--                }
--		lappend objfile_names $new_objfile
--	    }
--	    default {
--		if [string length $opts($opt_name)] {
--		    perror "option $opt_name multiply set in $file.d"
--		    unresolved $subdir/$name
--		    return
--		}
--
--		# A single "# ld:" with no options should do the right thing.
--		if { $opt_name == "ld" } {
--		    set run_ld 1
--		}
--		# Likewise objcopy_linked_file.
--		if { $opt_name == "objcopy_linked_file" } {
--		    set run_objcopy 1
--		}
--	    }
--	}
--	if { $opt_name == "as" || $opt_name == "ld" } {
--	    set opt_val [subst $opt_val]
--	}
--
--	# Append differently whether it's a message (without space) or
--	# an option or list (with space).
--	switch -- $opt_name {
--	    warning -
--	    error {
--		append opts($opt_name) $opt_val
--	    }
--	    default {
--		set opts($opt_name) [concat $opts($opt_name) $opt_val]
--	    }
--	}
--    }
--
--    foreach i $extra_options {
--	set opt_name [lindex $i 0]
--	set opt_val [lindex $i 1]
--	if ![info exists opts($opt_name)] {
--	    perror "unknown option $opt_name given in extra_opts"
--	    unresolved $subdir/$name
--	    return
--	}
--	# Add extra option to end of existing option, adding space
--	# if necessary.
--	if { ![regexp "warning|error" $opt_name]
--	     && [string length $opts($opt_name)] } {
--	    append opts($opt_name) " "
--	}
--	append opts($opt_name) $opt_val
--    }
--
--    foreach opt { as ld } {
--	regsub {\[big_or_little_endian\]} $opts($opt) \
--	    [big_or_little_endian] opts($opt)
--    }
--
--    if { $opts(name) == "" } {
--	set testname "$subdir/$name"
--    } else {
--	set testname $opts(name)
--    }
--
--    # Decide early whether we should run the test for this target.
--    if { [llength $opts(noskip)] > 0 } {
--	set targmatch 0
--	foreach targ $opts(noskip) {
--	    if [match_target $targ] {
--		set targmatch 1
--		break
--	    }
--	}
--	if { $targmatch == 0 } {
--	    return
--	}
--    }
--    foreach targ $opts(anyskip) {
--	if ![match_target $targ] {
--	    return
--	}
--    }
--    foreach targ $opts(skip) {
--	if [match_target $targ] {
--	    return
--	}
--    }
--    if { [llength $opts(target)] > 0 } {
--	set targmatch 0
--	foreach targ $opts(target) {
--	    if [match_target $targ] {
--		set targmatch 1
--		break
--	    }
--	}
--	if { $targmatch == 0 } {
--	    unsupported $testname
--	    return
--	}
--    }
--    foreach targ $opts(alltargets) {
--	if ![match_target $targ] {
--	    unsupported $testname
--	    return
--	}
--    }
--    foreach targ $opts(notarget) {
--	if [match_target $targ] {
--	    unsupported $testname
--	    return
--	}
--    }
--
--    set program ""
--    # It's meaningless to require an output-testing method when we
--    # expect an error.
--    if { $opts(error) == "" && $opts(error_output) == "" } {
--	if {$opts(PROG) != ""} {
--	    switch -- $opts(PROG) {
--		objdump	{ set program objdump }
--		nm	{ set program nm }
--		objcopy	{ set program objcopy }
--		readelf	{ set program readelf }
--		default
--		{ perror "unrecognized program option $opts(PROG) in $file.d"
--		  unresolved $testname
--		  return }
--	    }
--	} else {
--	# Guess which program to run, by seeing which option was specified.
--	    foreach p {objdump objcopy nm readelf} {
--		if {$opts($p) != ""} {
--		    if {$program != ""} {
--			perror "ambiguous dump program in $file.d"
--			unresolved $testname
--			return
--		    } else {
--			set program $p
--		    }
--		}
--	    }
--	}
--	if { $program == "" \
--                 && $opts(map) == "" \
--                 && $opts(warning) == "" \
--                 && $opts(warning_output) == "" \
--                 && $opts(error) == "" \
--                 && $opts(error_output) == "" } {
--	    perror "dump program unspecified in $file.d"
--	    unresolved $testname
--	    return
--	}
--    }
--
--    if { $opts(source) == "" } {
--	set sourcefiles [list ${file}.s]
--	set asflags [list ""]
--	set objfile_names [list tmpdir/[file tail ${file}].o]
--    } else {
--	set sourcefiles {}
--	foreach sf $opts(source) {
--	    if { [string match "/*" $sf] } {
--		lappend sourcefiles "$sf"
--	    } else {
--		lappend sourcefiles "$srcdir/$subdir/$sf"
--	    }
--	}
--    }
--
--    if { $opts(dump) == "" } {
--	set dfile ${file}.d
--    } else {
--	set dfile $srcdir/$subdir/$opts(dump)
--    }
--
--    # Time to setup xfailures.
--    foreach targ $opts(xfail) {
--	setup_xfail $targ
--    }
--
--    # Assemble each file.
--    set objfiles {}
--    for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
--	set sourcefile [lindex $sourcefiles $i]
--	set sourceasflags [lindex $asflags $i]
--	set run_objcopy_objects 0
--
--	if { [string match "*RUN_OBJCOPY*" $sourceasflags] } {
--	    set run_objcopy_objects 1
--	}
--	regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags
--
--	set objfile [lindex $objfile_names $i]
--	catch "exec rm -f $objfile" exec_output
--	lappend objfiles $objfile
--	set cmd "$AS $ASFLAGS $opts(as) $sourceasflags -o $objfile $sourcefile"
--
--	send_log "$cmd\n"
--	set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
--	remote_upload host "ld.tmp"
--	set comp_output [prune_warnings [file_contents "ld.tmp"]]
--	remote_file host delete "ld.tmp"
--	remote_file build delete "ld.tmp"
--
--	if { [lindex $cmdret 0] != 0 || ![string match "" $comp_output] } then {
--	    send_log -- "$comp_output\n"
--	    verbose "$comp_output" 3
--
--	    set exitstat "succeeded"
--	    if { $cmdret != 0 } { set exitstat "failed" }
--	    verbose -log "$exitstat with: <$comp_output>"
--	    fail $testname
--	    return
--	}
--
--	if { $run_objcopy_objects } {
--	    set cmd "$OBJCOPY $opts(objcopy_objects) $objfile"
--
--	    send_log "$cmd\n"
--	    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \
--			"" "/dev/null" "objcopy.tmp"]
--	    remote_upload host "objcopy.tmp"
--	    set comp_output [prune_warnings [file_contents "objcopy.tmp"]]
--	    remote_file host delete "objcopy.tmp"
--	    remote_file build delete "objcopy.tmp"
--
--	    if { [lindex $cmdret 0] != 0 \
--		  || ![string match "" $comp_output] } {
--		send_log -- "$comp_output\n"
--		verbose "$comp_output" 3
--
--		set exitstat "succeeded"
--		if { $cmdret != 0 } { set exitstat "failed" }
--		verbose -log "$exitstat with: <$comp_output>"
--		fail $testname
--		return
--	    }
--	}
--    }
--
--    if { (($opts(warning) != "") && ($opts(error) != "")) \
--	 || (($opts(warning) != "") && ($opts(error_output) != "")) \
--	 || (($opts(warning) != "") && ($opts(warning_output) != "")) \
--	 || (($opts(error) != "") && ($opts(warning_output) != "")) \
--	 || (($opts(error) != "") && ($opts(error_output) != "")) \
--	 || (($opts(warning_output) != "") && ($opts(error_output) != "")) } {
--	perror "$testname: bad mix of warning, error, warning_output, and error_output test-directives"
--	unresolved $testname
--	return
--    }
--
--    set check_ld(source) ""
--    set check_ld(terminal) 0
--    if { $opts(error) != "" \
--         || $opts(warning) != "" \
--         || $opts(error_output) != "" \
--         || $opts(warning_output) != "" } {
--
--        if { $opts(error) != "" || $opts(error_output) != "" } {
--            set check_ld(terminal) 1
--        } else {
--            set check_ld(terminal) 0
--        }
--
--        if { $opts(error) != "" || $opts(warning) != "" } {
--            set check_ld(source) "regex"
--            if { $opts(error) != "" } {
--                set check_ld(regex) $opts(error)
--            } else {
--                set check_ld(regex) $opts(warning)
--            }
--        } else {
--            set check_ld(source) "file"
--            if { $opts(error_output) != "" } {
--                set check_ld(file) $opts(error_output)
--            } else {
--                set check_ld(file) $opts(warning_output)
--            }
--        }
--    }
--
--    # Perhaps link the file(s).
--    if { $run_ld } {
--	set objfile "tmpdir/dump"
--	catch "exec rm -f $objfile" exec_output
--
--	# Add -L$srcdir/$subdir so that the linker command can use
--	# linker scripts in the source directory.
--	set cmd "$LD --hash-style=sysv --no-warn-shared-textrel $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
--		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
--
--        # If needed then check for, or add a -Map option.
--        set mapfile ""
--        if { $opts(map) != "" } then {
--            if { [regexp -- "-Map=(\[^ \]+)" $cmd all mapfile] } then {
--                # Found existing mapfile option
--                verbose -log "Existing mapfile '$mapfile' found"
--            } else {
--                # No mapfile option.
--                set mapfile "tmpdir/dump.map"
--                verbose -log "Adding mapfile '$mapfile'"
--                set cmd "$cmd -Map=$mapfile"
--            }
--        }
--
--	send_log "$cmd\n"
--	set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
--	remote_upload host "ld.tmp"
--	set comp_output [file_contents "ld.tmp"]
--	remote_file host delete "ld.tmp"
--	remote_file build delete "ld.tmp"
--	set cmdret [lindex $cmdret 0]
--
--	if { $cmdret == 0 && $run_objcopy } {
--	    set infile $objfile
--	    set objfile "tmpdir/dump1"
--	    remote_file host delete $objfile
--
--	    # Note that we don't use OBJCOPYFLAGS here; any flags must be
--	    # explicitly specified.
--	    set cmd "$OBJCOPY $opts(objcopy_linked_file) $infile $objfile"
--
--	    send_log "$cmd\n"
--	    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
--	    remote_upload host "ld.tmp"
--	    append comp_output [file_contents "ld.tmp"]
--	    remote_file host delete "ld.tmp"
--	    remote_file build delete "ld.tmp"
--	    set cmdret [lindex $cmdret 0]
--	}
--
--	regsub "\n$" $comp_output "" comp_output
--	if { $cmdret != 0 || $comp_output != "" || $check_ld(source) != "" } then {
--	    set exitstat "succeeded"
--	    if { $cmdret != 0 } { set exitstat "failed" }
--
--            if { $check_ld(source) == "regex" } {
--                verbose -log "$exitstat with: <$comp_output>, expected: <$check_ld(regex)>"
--            } elseif { $check_ld(source) == "file" } {
--                verbose -log "$exitstat with: <$comp_output>, expected in file $check_ld(file)"
--                set_file_contents "tmpdir/ld.messages" "$comp_output"
--            } else {
--                verbose -log "$exitstat with: <$comp_output>, no expected output"
--            }
--	    send_log -- "$comp_output\n"
--	    verbose "$comp_output" 3
--
--	    if { (($check_ld(source) == "") == ($comp_output == "")) \
--                 && (($cmdret == 0) == ($check_ld(terminal) == 0)) \
--                 && ((($check_ld(source) == "regex") \
--                      && ($check_ld(regex) == "") == ($comp_output == "") \
--                      && [regexp -- $check_ld(regex) $comp_output]) \
--                     || (($check_ld(source) == "file") \
--                         && (![regexp_diff "tmpdir/ld.messages" "$srcdir/$subdir/$check_ld(file)"]))) } {
--                # We have the expected output from ld.
--		if { $check_ld(terminal) || $program == "" } {
--		    pass $testname
--		    return
--		}
--	    } else {
--		fail $testname
--		return
--	    }
--	}
--
--        if { $opts(map) != "" } then {
--            # Check the map file matches.
--            set map_pattern_file $srcdir/$subdir/$opts(map)
--            verbose -log "Compare '$mapfile' against '$map_pattern_file'"
--            if { [regexp_diff $mapfile $map_pattern_file] } then {
--                fail "$testname (map file check)"
--            } else {
--                pass "$testname (map file check)"
--            }
--
--            if { $program == "" } then {
--                return
--            }
--        }
--    } else {
--	set objfile [lindex $objfiles 0]
--    }
--
--    # We must not have expected failure if we get here.
--    if { $opts(error) != "" } {
--	fail $testname
--	return
--    }
--
--    set progopts1 $opts($program)
--    eval set progopts \$[string toupper $program]FLAGS
--    eval set binary \$[string toupper $program]
--
--    if { ![is_remote host] && [which $binary] == 0 } {
--	untested $testname
--	return
--    }
--
--    if { $progopts1 == "" } { set $progopts1 "-r" }
--    verbose "running $binary $progopts $progopts1" 3
--
--    # Objcopy, unlike the other two, won't send its output to stdout,
--    # so we have to run it specially.
--    set cmd "$binary $progopts $progopts1 $objfile > $dumpfile"
--    if { $program == "objcopy" } {
--	set cmd "$binary $progopts $progopts1 $objfile $dumpfile"
--    }
--
--    # Ensure consistent sorting of symbols
--    if {[info exists env(LC_ALL)]} {
--	set old_lc_all $env(LC_ALL)
--    }
--    set env(LC_ALL) "C"
--    send_log "$cmd\n"
--    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>ld.tmp"]] "" "/dev/null"]
--    set cmdret [lindex $cmdret 0]
--    remote_upload host "ld.tmp"
--    set comp_output [prune_warnings [file_contents "ld.tmp"]]
--    remote_file host delete "ld.tmp"
--    remote_file build delete "ld.tmp"
--    if {[info exists old_lc_all]} {
--	set env(LC_ALL) $old_lc_all
--    } else {
--	unset env(LC_ALL)
--    }
--    if { $cmdret != 0 || $comp_output != "" } {
--	send_log "exited abnormally with $cmdret, output:$comp_output\n"
--	fail $testname
--	return
--    }
--
--    if { $verbose > 2 } then { verbose "output is [file_contents $dumpfile]" 3 }
--    if { [regexp_diff $dumpfile "${dfile}"] } then {
--	fail $testname
--	if { $verbose == 2 } then { verbose "output is [file_contents $dumpfile]" 2 }
--	return
--    }
--
--    pass $testname
--}
--
--proc slurp_options { file } {
--    # If options_regsub(foo) is set to {a b}, then the contents of a
--    # "#foo:" line will have regsub -all applied to replace a with b.
--    global options_regsub
--
--    if [catch { set f [open $file r] } x] {
--	#perror "couldn't open `$file': $x"
--	perror "$x"
--	return -1
--    }
--    set opt_array {}
--    # whitespace expression
--    set ws  {[ 	]*}
--    set nws {[^ 	]*}
--    # whitespace is ignored anywhere except within the options list;
--    # option names are alphabetic plus underscore only.
--    set pat "^#${ws}(\[a-zA-Z_\]*)$ws:${ws}(.*)$ws\$"
--    while { [gets $f line] != -1 } {
--	set line [string trim $line]
--	# Whitespace here is space-tab.
--	if [regexp $pat $line xxx opt_name opt_val] {
--	    # match!
--	    if [info exists options_regsub($opt_name)] {
--		set subst $options_regsub($opt_name)
--		regsub -all -- [lindex $subst 0] $opt_val [lindex $subst 1] \
--		    opt_val
--	    }
--	    lappend opt_array [list $opt_name $opt_val]
--	} else {
--	    break
--	}
--    }
--    close $f
--    return $opt_array
--}
--
--proc file_contents { filename } {
--    set file [open $filename r]
--    set contents [read $file]
--    close $file
--    return $contents
--}
--
--proc set_file_contents { filename contents } {
--    set file [open $filename w]
--    puts $file "$contents"
--    close $file
--}
--
- # Create an archive using ar
- #
- proc ar_simple_create { ar aropts target objects } {
--- 
-2.26.2
-

diff --git a/9999/0015-Gentoo-Adapt-generic-test-library-to-our-linker-sett.patch b/9999/0015-Gentoo-Adapt-generic-test-library-to-our-linker-sett.patch
deleted file mode 100644
index 8ac5654..0000000
--- a/9999/0015-Gentoo-Adapt-generic-test-library-to-our-linker-sett.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From 782c17148cc2a663778c03bb6f78412e79593df4 Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 10 May 2020 20:24:33 +0300
-Subject: [PATCH 15/16] Gentoo: Adapt generic test library to our linker
- settings
-
----
- binutils/testsuite/lib/binutils-common.exp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
-index b9e3c6d817..bb4ef987b3 100644
---- a/binutils/testsuite/lib/binutils-common.exp
-+++ b/binutils/testsuite/lib/binutils-common.exp
-@@ -1125,7 +1125,7 @@ proc run_dump_test { name {extra_options {}} } {
- 
-             # Add -L$srcdir/$subdir so that the linker command can use
-             # linker scripts in the source directory.
--            set cmd "$LD $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
-+            set cmd "$LD --hash-style=sysv --no-warn-shared-textrel $ld_extra_opt $LDFLAGS -L$srcdir/$subdir \
- 		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
- 
-             # If needed then check for, or add a -Map option.
--- 
-2.26.2
-

diff --git a/9999/0016-Gentoo-Fix-regexp-of-hilarious-ld-detection-heuristi.patch b/9999/0016-Gentoo-Fix-regexp-of-hilarious-ld-detection-heuristi.patch
deleted file mode 100644
index be9f677..0000000
--- a/9999/0016-Gentoo-Fix-regexp-of-hilarious-ld-detection-heuristi.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-From 6e0ff9dfef58d03eacc05ef381ef1d5fc7ad072d Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Andreas=20K=2E=20H=C3=BCttel?= <dilfridge@gentoo.org>
-Date: Sun, 10 May 2020 20:59:05 +0300
-Subject: [PATCH 16/16] Gentoo: Fix regexp of hilarious ld detection heuristic
-
-The new linker used to be called as "ld/ld-new" but is now called as "./ld-new"
-Test for just "ld-new" and hope that the compiler binary never looks like this.
----
- ld/testsuite/lib/ld-lib.exp | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
-index ae72f21d72..0b945b539d 100644
---- a/ld/testsuite/lib/ld-lib.exp
-+++ b/ld/testsuite/lib/ld-lib.exp
-@@ -200,9 +200,9 @@ proc default_ld_link { ld target objects } {
-     # with $ld as parameter. If we want to change the default behaviour, we
-     # need to take the different option formats into account.
-     # We check the $ld parameter for
--    # - .*ld/ld-new    -> we're working with the new linker
-+    # - ld-new         -> we're working with the new linker
-     # - otherwise      -> we're likely working with the system compiler
--    if {[regexp {ld/ld-new$} $ld]} {
-+    if {[regexp {ld-new$} $ld]} {
-       set gentoosysv "--hash-style=sysv --no-warn-shared-textrel"
-     } else {
-       set gentoosysv "-Wl,--hash-style=sysv -Wl,--no-warn-shared-textrel"
--- 
-2.26.2
-


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

end of thread, other threads:[~2025-10-11  6:41 UTC | newest]

Thread overview: 102+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-17 20:07 [gentoo-commits] proj/toolchain/binutils-patches:master commit in: 9999/ Andreas K. Hüttel
  -- strict thread matches above, loose matches on Subject: below --
2025-10-11  6:40 Sam James
2025-10-11  0:46 Sam James
2025-10-11  0:46 Sam James
2025-10-10  5:41 Sam James
2025-10-10  5:28 Sam James
2025-10-10  5:28 Sam James
2025-10-10  5:25 Sam James
2025-10-10  4:57 Sam James
2025-08-29 13:40 Sam James
2025-08-28 20:21 Sam James
2025-08-28 13:51 Sam James
2025-08-28  5:32 Sam James
2025-08-27 16:26 Sam James
2025-08-27  4:05 Sam James
2025-08-27  2:49 Sam James
2025-08-25  2:49 Sam James
2025-08-20 23:30 Sam James
2025-08-20 22:17 Sam James
2025-08-20 22:17 Sam James
2025-08-20 20:44 Sam James
2025-08-20  4:39 Sam James
2025-08-19 20:54 Sam James
2025-08-19 17:11 Sam James
2025-08-19 16:28 Sam James
2025-08-19 10:51 Sam James
2025-08-19  3:48 Sam James
2025-08-18 20:21 Sam James
2025-08-18 20:21 Sam James
2025-08-18 20:19 Sam James
2025-08-18 15:39 Sam James
2025-08-17 20:58 Sam James
2025-08-17 19:45 Sam James
2025-08-06 13:19 Sam James
2025-08-06  4:07 Sam James
2025-08-06  1:08 Sam James
2025-08-05 20:21 Sam James
2025-08-04 21:43 Sam James
2025-08-04 21:05 Sam James
2025-08-04 15:32 Sam James
2025-08-04 11:06 Sam James
2025-08-03 23:43 Sam James
2025-08-01 11:28 Sam James
2025-08-01  8:17 Sam James
2025-07-31 11:39 Sam James
2025-07-28 12:24 Andreas K. Hüttel
2025-07-24 17:25 Sam James
2025-07-24  4:03 Sam James
2025-07-24  3:46 Sam James
2025-07-23 22:37 Sam James
2025-06-14 21:52 Sam James
2025-06-13  8:00 Sam James
2025-05-14  7:14 Sam James
2025-05-14  3:59 Sam James
2025-05-05  9:46 Sam James
2025-05-05  3:06 Sam James
2025-05-04 10:15 Sam James
2025-04-10 17:35 Sam James
2025-04-09  2:24 Sam James
2025-04-08  0:36 Sam James
2025-03-29 14:18 Sam James
2025-03-12 20:21 Sam James
2025-03-06 12:54 Sam James
2025-03-06  4:54 Sam James
2025-02-03 18:02 Andreas K. Hüttel
2025-01-14  2:09 Sam James
2025-01-13  6:11 Sam James
2025-01-02 13:48 Sam James
2025-01-01 14:05 Sam James
2024-12-26  1:21 Sam James
2024-12-24  6:27 Sam James
2024-12-21  0:09 Sam James
2024-08-03 22:43 Andreas K. Hüttel
2024-06-29 17:05 Andreas K. Hüttel
2024-06-29 16:32 Andreas K. Hüttel
2024-06-29 16:32 Andreas K. Hüttel
2024-06-28 21:48 Andreas K. Hüttel
2023-10-27  0:44 Sam James
2023-10-27  0:44 Sam James
2023-07-30 14:49 Andreas K. Hüttel
2023-07-28 16:23 Andreas K. Hüttel
2023-06-30  9:21 WANG Xuerui
2023-04-02 11:44 Andreas K. Hüttel
2023-01-05 16:22 Andreas K. Hüttel
2023-01-05 16:21 Andreas K. Hüttel
2023-01-03 23:03 Andreas K. Hüttel
2023-01-02 23:50 Andreas K. Hüttel
2022-10-08 12:15 WANG Xuerui
2022-07-29  7:55 WANG Xuerui
2022-01-15 22:27 Andreas K. Hüttel
2021-07-30 23:25 Andreas K. Hüttel
2021-07-24 20:57 Andreas K. Hüttel
2021-07-20 19:53 Andreas K. Hüttel
2021-07-20 19:50 Andreas K. Hüttel
2021-07-06  7:04 Sergei Trofimovich
2021-07-06  7:04 Sergei Trofimovich
2021-07-06  7:04 Sergei Trofimovich
2020-07-25 17:27 Andreas K. Hüttel
2020-07-25 12:26 Andreas K. Hüttel
2020-07-25 12:23 Andreas K. Hüttel
2020-07-25 12:20 Andreas K. Hüttel
2020-05-19 21:12 Andreas K. Hüttel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox