Skip to content

Commit 7d5d3ae

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[tools] Add sections without symbols into binary_size's treemap.
This makes the cost of especially unwind tables and relocation visible and gets the treemap's total much closer the stripped binary size. Change-Id: I1123e294b79b83cd709e7dc6e8e89c7a9545ef2c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423605 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Brian Quinlan <[email protected]>
1 parent 44c5813 commit 7d5d3ae

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

runtime/tools/binary_size

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ const filteredPathComponents = <String>[
7171
"ProductXARM64",
7272
];
7373

74+
const filteredSections = <String>[
75+
// Covered by symbols
76+
".data",
77+
".data.rel.ro",
78+
".rodata",
79+
".text",
80+
81+
// Does not contribute to file size
82+
".bss",
83+
".tbss",
84+
85+
// Debug info / stripped
86+
".debug_abbrev",
87+
".debug_aranges",
88+
".debug_info",
89+
".debug_line",
90+
".debug_line_str",
91+
".debug_loc",
92+
".debug_loclists",
93+
".debug_macro",
94+
".debug_ranges",
95+
".debug_rnglists",
96+
".debug_str",
97+
".strtab",
98+
".symtab",
99+
];
100+
74101
var cwd = Directory.current.path;
75102
String prettyPath(String path) {
76103
if (path.startsWith(cwd)) {
@@ -174,6 +201,46 @@ analyze(String binaryPath) {
174201
addToPath(s, path);
175202
}
176203

204+
var readExec = "readelf";
205+
var readArgs = ["--sections", binaryPath];
206+
var readResult = Process.runSync(readExec, readArgs);
207+
if (readResult.exitCode != 0) {
208+
print("+ ${readExec} ${readArgs.join(' ')}");
209+
print(readResult.exitCode);
210+
print(readResult.stdout);
211+
print(readResult.stderr);
212+
exit(1);
213+
}
214+
215+
lines = readResult.stdout.split("\n");
216+
var nameRegex = new RegExp("\\[([ 0-9a-f]+)\\] ([_0-9a-zA-Z.]+)");
217+
var sizeRegex = new RegExp("([_0-9a-f]+)");
218+
var sectionName = null;
219+
for (var line in lines) {
220+
print(line);
221+
var match = nameRegex.firstMatch(line);
222+
if (match != null) {
223+
sectionName = match[2];
224+
continue;
225+
}
226+
match = sizeRegex.firstMatch(line);
227+
if (match != null) {
228+
int size = int.parse(match[1]!, radix: 16);
229+
230+
if (sectionName != null && !filteredSections.contains(sectionName)) {
231+
var s = new Symbol();
232+
s.name = sectionName;
233+
s.type = "section";
234+
s.shallowSize = size;
235+
addToPath(s, "");
236+
}
237+
238+
sectionName = null;
239+
continue;
240+
}
241+
sectionName = null;
242+
}
243+
177244
root.compressTrivialPaths();
178245
root.computeRetainedSize();
179246

0 commit comments

Comments
 (0)