@@ -205,10 +205,18 @@ fn infer_symbol_sizes(symbols: &mut [Symbol], sections: &[Section]) {
205
205
}
206
206
iter_idx += 1 ;
207
207
} ;
208
- let next_address = next_symbol. map ( |s| s. address ) . unwrap_or_else ( || {
209
- let section = & sections[ section_idx] ;
210
- section. address + section. size
211
- } ) ;
208
+ let section = & sections[ section_idx] ;
209
+ let mut next_address =
210
+ next_symbol. map ( |s| s. address ) . unwrap_or_else ( || section. address + section. size ) ;
211
+ if section. kind == SectionKind :: Code {
212
+ // For functions, trim any trailing 4-byte zeroes from the end (padding, nops)
213
+ while next_address > symbol. address + 4
214
+ && let Some ( data) = section. data_range ( next_address - 4 , 4 )
215
+ && data == [ 0u8 ; 4 ]
216
+ {
217
+ next_address -= 4 ;
218
+ }
219
+ }
212
220
let new_size = next_address. saturating_sub ( symbol. address ) ;
213
221
if new_size > 0 {
214
222
let symbol = & mut symbols[ symbol_idx] ;
@@ -218,7 +226,7 @@ fn infer_symbol_sizes(symbols: &mut [Symbol], sections: &[Section]) {
218
226
}
219
227
// Set symbol kind if unknown and size is non-zero
220
228
if symbol. kind == SymbolKind :: Unknown {
221
- symbol. kind = match sections [ section_idx ] . kind {
229
+ symbol. kind = match section . kind {
222
230
SectionKind :: Code => SymbolKind :: Function ,
223
231
SectionKind :: Data | SectionKind :: Bss => SymbolKind :: Object ,
224
232
_ => SymbolKind :: Unknown ,
0 commit comments