1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
https://bugs.gentoo.org/957882
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=eee822a66066a17529d7af544b1be767517a6c72
From eee822a66066a17529d7af544b1be767517a6c72 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
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:
@@ -3744,6 +3768,12 @@ copy_archive (bfd *ibfd, bfd *obfd, const char
*output_target,
goto cleanup_and_exit;
}
+#if BFD_SUPPORTS_PLUGINS
+ /* Copy LTO IR file as unknown object. */
+ if (bfd_plugin_target_p (ibfd->xvec))
^^^^ A typo, should be this_element.
+ ok_object = false;
+ else
+#endif
if (ok_object)
{
ok = copy_object (this_element, output_element, input_arch);
to check if the archive element is a LTO IR file. "ibfd" is the archive
BFD. "this_element" should be used to check for LTO IR in the archive
element. Fix it by replacing "ibfd" with "this_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 | 81 +++++++++++++++++++++
2 files changed, 82 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..6aa6d2d9fe7 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -661,6 +661,87 @@ 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 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.43.5
|