@@ -9,7 +9,8 @@ use std::process::{Command, Stdio};
9
9
10
10
use object:: read:: archive:: { ArchiveFile , ArchiveMember } ;
11
11
use object:: {
12
- File as ObjFile , Object , ObjectSymbol , Symbol , SymbolKind , SymbolScope , SymbolSection ,
12
+ File as ObjFile , Object , ObjectSection , ObjectSymbol , Symbol , SymbolKind , SymbolScope ,
13
+ SymbolSection ,
13
14
} ;
14
15
use serde_json:: Value ;
15
16
@@ -155,6 +156,7 @@ struct SymInfo {
155
156
kind : SymbolKind ,
156
157
scope : SymbolScope ,
157
158
section : SymbolSection ,
159
+ section_name : String ,
158
160
is_undefined : bool ,
159
161
is_global : bool ,
160
162
is_local : bool ,
@@ -165,12 +167,22 @@ struct SymInfo {
165
167
}
166
168
167
169
impl SymInfo {
168
- fn new ( sym : & Symbol , member : & ArchiveMember ) -> Self {
170
+ fn new ( sym : & Symbol , obj : & ObjFile , member : & ArchiveMember ) -> Self {
171
+ let section = sym. section ( ) ;
172
+ // Include the section name if possible. Fall back to the `Section` debug impl if not.
173
+ let section_name = section
174
+ . index ( )
175
+ . and_then ( |idx| obj. section_by_index ( idx) . ok ( ) )
176
+ . and_then ( |sec| sec. name ( ) . ok ( ) )
177
+ . map ( ToString :: to_string)
178
+ . unwrap_or_else ( || format ! ( "{section:?}" ) ) ;
179
+
169
180
Self {
170
181
name : sym. name ( ) . expect ( "missing name" ) . to_owned ( ) ,
171
182
kind : sym. kind ( ) ,
172
183
scope : sym. scope ( ) ,
173
- section : sym. section ( ) ,
184
+ section,
185
+ section_name,
174
186
is_undefined : sym. is_undefined ( ) ,
175
187
is_global : sym. is_global ( ) ,
176
188
is_local : sym. is_local ( ) ,
@@ -192,13 +204,13 @@ fn verify_no_duplicates(archive: &Archive) {
192
204
let mut dups = Vec :: new ( ) ;
193
205
let mut found_any = false ;
194
206
195
- archive. for_each_symbol ( |symbol, member| {
207
+ archive. for_each_symbol ( |symbol, obj , member| {
196
208
// Only check defined globals
197
209
if !symbol. is_global ( ) || symbol. is_undefined ( ) {
198
210
return ;
199
211
}
200
212
201
- let sym = SymInfo :: new ( & symbol, member) ;
213
+ let sym = SymInfo :: new ( & symbol, obj , member) ;
202
214
203
215
// x86-32 includes multiple copies of thunk symbols
204
216
if sym. name . starts_with ( "__x86.get_pc_thunk" ) {
@@ -244,15 +256,15 @@ fn verify_core_symbols(archive: &Archive) {
244
256
let mut undefined = Vec :: new ( ) ;
245
257
let mut has_symbols = false ;
246
258
247
- archive. for_each_symbol ( |symbol, member| {
259
+ archive. for_each_symbol ( |symbol, obj , member| {
248
260
has_symbols = true ;
249
261
250
262
// Find only symbols from `core`
251
263
if !symbol. name ( ) . unwrap ( ) . contains ( "_ZN4core" ) {
252
264
return ;
253
265
}
254
266
255
- let sym = SymInfo :: new ( & symbol, member) ;
267
+ let sym = SymInfo :: new ( & symbol, obj , member) ;
256
268
if sym. is_undefined {
257
269
undefined. push ( sym) ;
258
270
} else {
@@ -304,9 +316,9 @@ impl Archive {
304
316
}
305
317
306
318
/// For a given archive, do something with each symbol.
307
- fn for_each_symbol ( & self , mut f : impl FnMut ( Symbol , & ArchiveMember ) ) {
319
+ fn for_each_symbol ( & self , mut f : impl FnMut ( Symbol , & ObjFile , & ArchiveMember ) ) {
308
320
self . for_each_object ( |obj, member| {
309
- obj. symbols ( ) . for_each ( |sym| f ( sym, member) ) ;
321
+ obj. symbols ( ) . for_each ( |sym| f ( sym, & obj , member) ) ;
310
322
} ) ;
311
323
}
312
324
}
0 commit comments