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" <[email protected]>
+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 <[email protected]>
+---
+ 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

Reply via email to