@@ -49,12 +49,30 @@ fn map_symbol(
49
49
{
50
50
let section_name = section. name ( ) . context ( "Failed to process section name" ) ?;
51
51
name = format ! ( "[{section_name}]" ) ;
52
- // For section symbols, set the size to zero. If the size is non-zero, it will be included
53
- // in the diff. Most of the time, this is duplicative, given that we'll have function or
54
- // object symbols that cover the same range. In the case of an empty section, the size
55
- // inference logic below will set the size back to the section size, thus acting as a
56
- // placeholder symbol.
57
- size = 0 ;
52
+
53
+ let section_kind = map_section_kind ( & section) ;
54
+ if section_kind == SectionKind :: Data {
55
+ // For section symbols, the size would normally be zero and excluded from the diff.
56
+ // Instead we make them the size of all the data in the section so that the user can diff
57
+ // entire sections by clicking on the section symbol at the top of the section.
58
+ // We only do this for data sections, as there would be no point for code or bss sections.
59
+ if let Some ( last_symbol) = file
60
+ . symbols ( )
61
+ . filter ( |s| {
62
+ s. section_index ( ) == Some ( section. index ( ) )
63
+ && s. kind ( ) == object:: SymbolKind :: Data
64
+ && s. size ( ) > 0
65
+ } )
66
+ . max_by_key ( |s| s. address ( ) )
67
+ {
68
+ // Use the address that the last symbol ends at as the section size.
69
+ size = last_symbol. address ( ) + last_symbol. size ( ) ;
70
+ } else {
71
+ // `section.size()` can include extra padding that doesn't correspond to any symbol,
72
+ // so only fall back to it if there are no symbols to look at.
73
+ size = section. size ( ) ;
74
+ }
75
+ }
58
76
}
59
77
60
78
let mut flags = arch. extra_symbol_flags ( symbol) ;
0 commit comments