Commit 8f1c526c authored by Jasper Chapman-Black's avatar Jasper Chapman-Black Committed by Commit Bot

SuperSize: Caspian: Calculate padding for symbols

Bug: 1011921
Change-Id: I591df9b3e68aced4de83d675df36c0553ec31c9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906643
Commit-Queue: Jasper Chapman-Black <jaspercb@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714567}
parent 7b991c5c
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <numeric> #include <numeric>
#include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -155,6 +156,56 @@ void CheckNoNonEmptyLinesRemain(char* rest) { ...@@ -155,6 +156,56 @@ void CheckNoNonEmptyLinesRemain(char* rest) {
namespace caspian { namespace caspian {
void CalculatePadding(std::vector<Symbol>* raw_symbols) {
std::set<const char*> seen_sections;
for (size_t i = 1; i < raw_symbols->size(); i++) {
const Symbol& prev_symbol = (*raw_symbols)[i - 1];
Symbol& symbol = (*raw_symbols)[i];
if (symbol.IsOverhead()) {
symbol.padding = symbol.size;
}
if (prev_symbol.section_name != symbol.section_name) {
if (seen_sections.count(symbol.section_name)) {
std::cerr << "Input symbols must be sorted by section, then address: "
<< prev_symbol << ", " << symbol << std::endl;
exit(1);
}
seen_sections.insert(symbol.section_name);
continue;
}
if (symbol.address <= 0 || prev_symbol.address <= 0 || !symbol.IsNative() ||
!prev_symbol.IsNative()) {
continue;
}
if (symbol.address == prev_symbol.address) {
if (symbol.aliases && symbol.aliases == prev_symbol.aliases) {
symbol.padding = prev_symbol.padding;
symbol.size = prev_symbol.size;
continue;
}
if (prev_symbol.SizeWithoutPadding() != 0) {
// Padding-only symbols happen for ** symbol gaps.
std::cerr << "Found duplicate symbols: " << prev_symbol << ", "
<< symbol << std::endl;
exit(1);
}
}
int32_t padding = symbol.address - prev_symbol.EndAddress();
symbol.padding = padding;
symbol.size += padding;
if (symbol.size < 0) {
std::cerr << "Symbol has negative size (likely not sorted properly):"
<< symbol << std::endl;
std::cerr << "prev symbol: " << prev_symbol << std::endl;
exit(1);
}
}
}
void ParseSizeInfo(const char* gzipped, void ParseSizeInfo(const char* gzipped,
unsigned long len, unsigned long len,
::caspian::SizeInfo* info) { ::caspian::SizeInfo* info) {
...@@ -300,6 +351,7 @@ void ParseSizeInfo(const char* gzipped, ...@@ -300,6 +351,7 @@ void ParseSizeInfo(const char* gzipped,
new_sym.sectionId = cur_section_id; new_sym.sectionId = cur_section_id;
new_sym.address = cur_addresses[i]; new_sym.address = cur_addresses[i];
new_sym.size = cur_sizes[i]; new_sym.size = cur_sizes[i];
new_sym.section_name = cur_section_name;
new_sym.object_path = info->object_paths[cur_path_indices[i]]; new_sym.object_path = info->object_paths[cur_path_indices[i]];
new_sym.source_path = info->source_paths[cur_path_indices[i]]; new_sym.source_path = info->source_paths[cur_path_indices[i]];
if (has_components) { if (has_components) {
...@@ -321,6 +373,9 @@ void ParseSizeInfo(const char* gzipped, ...@@ -321,6 +373,9 @@ void ParseSizeInfo(const char* gzipped,
} }
} }
} }
CalculatePadding(&info->raw_symbols);
for (caspian::Symbol& sym : info->raw_symbols) { for (caspian::Symbol& sym : info->raw_symbols) {
size_t alias_count = sym.aliases ? sym.aliases->size() : 1; size_t alias_count = sym.aliases ? sym.aliases->size() : 1;
sym.pss = static_cast<float>(sym.size) / alias_count; sym.pss = static_cast<float>(sym.size) / alias_count;
......
...@@ -90,6 +90,13 @@ TreeNode::~TreeNode() { ...@@ -90,6 +90,13 @@ TreeNode::~TreeNode() {
} }
} }
std::ostream& operator<<(std::ostream& os, const Symbol& sym) {
return os << "Symbol(full_name=" << sym.full_name
<< ", section=" << static_cast<char>(sym.sectionId)
<< ", address=" << sym.address << ", size=" << sym.size
<< ", flags=" << sym.flags << ", padding=" << sym.padding << ")";
}
BaseSizeInfo::BaseSizeInfo() = default; BaseSizeInfo::BaseSizeInfo() = default;
BaseSizeInfo::~BaseSizeInfo() = default; BaseSizeInfo::~BaseSizeInfo() = default;
......
...@@ -47,6 +47,31 @@ struct Symbol { ...@@ -47,6 +47,31 @@ struct Symbol {
Symbol& operator=(const Symbol& other); Symbol& operator=(const Symbol& other);
static Symbol DiffSymbolFrom(const Symbol* before, const Symbol* after); static Symbol DiffSymbolFrom(const Symbol* before, const Symbol* after);
bool IsOverhead() const { return full_name.substr(0, 10) == "Overhead: "; }
bool IsBss() const { return sectionId == SectionId::kBss; }
bool IsDex() const {
return sectionId == SectionId::kDex || sectionId == SectionId::kDexMethod;
}
bool IsOther() const { return sectionId == SectionId::kOther; }
bool IsPak() const {
return sectionId == SectionId::kPakNontranslated ||
sectionId == SectionId::kPakTranslations;
}
bool IsNative() const {
return (sectionId == SectionId::kBss || sectionId == SectionId::kData ||
sectionId == SectionId::kDataRelRo ||
sectionId == SectionId::kText || sectionId == SectionId::kRoData);
}
int32_t SizeWithoutPadding() const { return size - padding; }
int32_t EndAddress() const { return address + SizeWithoutPadding(); }
int32_t address = 0; int32_t address = 0;
int32_t size = 0; int32_t size = 0;
int32_t flags = 0; int32_t flags = 0;
...@@ -62,6 +87,8 @@ struct Symbol { ...@@ -62,6 +87,8 @@ struct Symbol {
std::vector<Symbol*>* aliases = nullptr; std::vector<Symbol*>* aliases = nullptr;
}; };
std::ostream& operator<<(std::ostream& os, const Symbol& sym);
struct BaseSizeInfo { struct BaseSizeInfo {
BaseSizeInfo(); BaseSizeInfo();
~BaseSizeInfo(); ~BaseSizeInfo();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment