@@ -9,7 +9,8 @@ use std::process::{Command, Stdio};
99
1010use object:: read:: archive:: { ArchiveFile , ArchiveMember } ;
1111use object:: {
12- File as ObjFile , Object , ObjectSymbol , Symbol , SymbolKind , SymbolScope , SymbolSection ,
12+ File as ObjFile , Object , ObjectSection , ObjectSymbol , Symbol , SymbolKind , SymbolScope ,
13+ SymbolSection ,
1314} ;
1415use serde_json:: Value ;
1516
@@ -155,6 +156,7 @@ struct SymInfo {
155156 kind : SymbolKind ,
156157 scope : SymbolScope ,
157158 section : SymbolSection ,
159+ section_name : String ,
158160 is_undefined : bool ,
159161 is_global : bool ,
160162 is_local : bool ,
@@ -165,12 +167,22 @@ struct SymInfo {
165167}
166168
167169impl 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+
169180 Self {
170181 name : sym. name ( ) . expect ( "missing name" ) . to_owned ( ) ,
171182 kind : sym. kind ( ) ,
172183 scope : sym. scope ( ) ,
173- section : sym. section ( ) ,
184+ section,
185+ section_name,
174186 is_undefined : sym. is_undefined ( ) ,
175187 is_global : sym. is_global ( ) ,
176188 is_local : sym. is_local ( ) ,
@@ -192,13 +204,13 @@ fn verify_no_duplicates(archive: &Archive) {
192204 let mut dups = Vec :: new ( ) ;
193205 let mut found_any = false ;
194206
195- archive. for_each_symbol ( |symbol, member| {
207+ archive. for_each_symbol ( |symbol, obj , member| {
196208 // Only check defined globals
197209 if !symbol. is_global ( ) || symbol. is_undefined ( ) {
198210 return ;
199211 }
200212
201- let sym = SymInfo :: new ( & symbol, member) ;
213+ let sym = SymInfo :: new ( & symbol, obj , member) ;
202214
203215 // x86-32 includes multiple copies of thunk symbols
204216 if sym. name . starts_with ( "__x86.get_pc_thunk" ) {
@@ -244,15 +256,15 @@ fn verify_core_symbols(archive: &Archive) {
244256 let mut undefined = Vec :: new ( ) ;
245257 let mut has_symbols = false ;
246258
247- archive. for_each_symbol ( |symbol, member| {
259+ archive. for_each_symbol ( |symbol, obj , member| {
248260 has_symbols = true ;
249261
250262 // Find only symbols from `core`
251263 if !symbol. name ( ) . unwrap ( ) . contains ( "_ZN4core" ) {
252264 return ;
253265 }
254266
255- let sym = SymInfo :: new ( & symbol, member) ;
267+ let sym = SymInfo :: new ( & symbol, obj , member) ;
256268 if sym. is_undefined {
257269 undefined. push ( sym) ;
258270 } else {
@@ -304,9 +316,9 @@ impl Archive {
304316 }
305317
306318 /// 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 ) ) {
308320 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) ) ;
310322 } ) ;
311323 }
312324}
0 commit comments