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