summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-01-16 17:30:00 -0800
committerGitHub <noreply@github.com>2020-01-16 17:30:00 -0800
commite873e2a84db3fda3c8df5ed8e0b39578a1fb2f2d (patch)
tree8672d8e6bafa3e7551ce0e8aa2bd5129048c1798 /src
parent0ec999db121197d7da242dd4a1136997e02c67cc (diff)
downloadbinaryen-e873e2a84db3fda3c8df5ed8e0b39578a1fb2f2d.tar.gz
binaryen-e873e2a84db3fda3c8df5ed8e0b39578a1fb2f2d.tar.bz2
binaryen-e873e2a84db3fda3c8df5ed8e0b39578a1fb2f2d.zip
Use BinaryLocation instead of hardcoding uint32_t (#2598)
This will make it easier to switch to something else for offsets in wasm binaries if we get >4GB files.
Diffstat (limited to 'src')
-rw-r--r--src/wasm.h9
-rw-r--r--src/wasm/wasm-binary.cpp15
-rw-r--r--src/wasm/wasm-debug.cpp34
3 files changed, 32 insertions, 26 deletions
diff --git a/src/wasm.h b/src/wasm.h
index 99ea59728..9aafb7425 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -1160,12 +1160,17 @@ struct Importable {
class Function;
+// Represents an offset into a wasm binary file. This is used for debug info.
+// For now, assume this is 32 bits as that's the size limit of wasm files
+// anyhow.
+using BinaryLocation = uint32_t;
+
// Represents a mapping of wasm module elements to their location in the
// binary representation. This is used for general debugging info support.
// Offsets are relative to the beginning of the code section, as in DWARF.
struct BinaryLocations {
struct Span {
- uint32_t start, end;
+ BinaryLocation start, end;
};
std::unordered_map<Expression*, Span> expressions;
std::unordered_map<Function*, Span> functions;
@@ -1204,7 +1209,7 @@ public:
// Source maps debugging info: map expression nodes to their file, line, col.
struct DebugLocation {
- uint32_t fileIndex, lineNumber, columnNumber;
+ BinaryLocation fileIndex, lineNumber, columnNumber;
bool operator==(const DebugLocation& other) const {
return fileIndex == other.fileIndex && lineNumber == other.lineNumber &&
columnNumber == other.columnNumber;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 8d42fb9f4..a9b14dba3 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -346,8 +346,9 @@ void WasmBinaryWriter::writeFunctions() {
}
}
if (!binaryLocationTrackedExpressionsForFunc.empty()) {
- binaryLocations.functions[func] = BinaryLocations::Span{
- uint32_t(start - adjustmentForLEBShrinking), uint32_t(o.size())};
+ binaryLocations.functions[func] =
+ BinaryLocations::Span{BinaryLocation(start - adjustmentForLEBShrinking),
+ BinaryLocation(o.size())};
}
tableOfContents.functionBodies.emplace_back(
func->name, sizePos + sizeFieldSize, size);
@@ -712,7 +713,7 @@ void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
// binary locations tracked, then track it in the output as well.
if (func && !func->expressionLocations.empty()) {
binaryLocations.expressions[curr] =
- BinaryLocations::Span{uint32_t(o.size()), 0};
+ BinaryLocations::Span{BinaryLocation(o.size()), 0};
binaryLocationTrackedExpressionsForFunc.push_back(curr);
}
}
@@ -1383,8 +1384,8 @@ void WasmBinaryBuilder::readFunctions() {
if (DWARF) {
func->funcLocation =
- BinaryLocations::Span{uint32_t(pos - codeSectionLocation),
- uint32_t(pos - codeSectionLocation + size)};
+ BinaryLocations::Span{BinaryLocation(pos - codeSectionLocation),
+ BinaryLocation(pos - codeSectionLocation + size)};
}
readNextDebugLocation();
@@ -2306,8 +2307,8 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
}
if (DWARF && currFunction) {
currFunction->expressionLocations[curr] =
- BinaryLocations::Span{uint32_t(startPos - codeSectionLocation),
- uint32_t(pos - codeSectionLocation)};
+ BinaryLocations::Span{BinaryLocation(startPos - codeSectionLocation),
+ BinaryLocation(pos - codeSectionLocation)};
}
}
BYN_TRACE("zz recurse from " << depth-- << " at " << pos << std::endl);
diff --git a/src/wasm/wasm-debug.cpp b/src/wasm/wasm-debug.cpp
index 89082e8dd..a4d3b2641 100644
--- a/src/wasm/wasm-debug.cpp
+++ b/src/wasm/wasm-debug.cpp
@@ -334,8 +334,8 @@ private:
// to let us use contextual information (we may know we are looking up the end
// of an instruction).
struct AddrExprMap {
- std::unordered_map<uint32_t, Expression*> startMap;
- std::unordered_map<uint32_t, Expression*> endMap;
+ std::unordered_map<BinaryLocation, Expression*> startMap;
+ std::unordered_map<BinaryLocation, Expression*> endMap;
// Construct the map from the binaryLocations loaded from the wasm.
AddrExprMap(const Module& wasm) {
@@ -353,7 +353,7 @@ struct AddrExprMap {
}
}
- Expression* getStart(uint32_t addr) const {
+ Expression* getStart(BinaryLocation addr) const {
auto iter = startMap.find(addr);
if (iter != startMap.end()) {
return iter->second;
@@ -361,7 +361,7 @@ struct AddrExprMap {
return nullptr;
}
- Expression* getEnd(uint32_t addr) const {
+ Expression* getEnd(BinaryLocation addr) const {
auto iter = endMap.find(addr);
if (iter != endMap.end()) {
return iter->second;
@@ -382,7 +382,7 @@ private:
// map for the start and end addresses, since there is no chance of a function's
// start overlapping with another's end (there is the size LEB in the middle).
struct FuncAddrMap {
- std::unordered_map<uint32_t, Function*> map;
+ std::unordered_map<BinaryLocation, Function*> map;
// Construct the map from the binaryLocations loaded from the wasm.
FuncAddrMap(const Module& wasm) {
@@ -392,7 +392,7 @@ struct FuncAddrMap {
}
}
- Function* get(uint32_t addr) const {
+ Function* get(BinaryLocation addr) const {
auto iter = map.find(addr);
if (iter != map.end()) {
return iter->second;
@@ -436,29 +436,29 @@ struct LocationUpdater {
// Updates an expression's address. If there was never an instruction at that
// address, or if there was but if that instruction no longer exists, return
// 0. Otherwise, return the new updated location.
- uint32_t getNewExprAddr(uint32_t oldAddr) const {
+ BinaryLocation getNewExprAddr(BinaryLocation oldAddr) const {
if (auto* expr = oldExprAddrMap.getStart(oldAddr)) {
auto iter = newLocations.expressions.find(expr);
if (iter != newLocations.expressions.end()) {
- uint32_t newAddr = iter->second.start;
+ BinaryLocation newAddr = iter->second.start;
return newAddr;
}
}
return 0;
}
- uint32_t getNewExprEndAddr(uint32_t oldAddr) const {
+ BinaryLocation getNewExprEndAddr(BinaryLocation oldAddr) const {
if (auto* expr = oldExprAddrMap.getEnd(oldAddr)) {
auto iter = newLocations.expressions.find(expr);
if (iter != newLocations.expressions.end()) {
- uint32_t newAddr = iter->second.end;
+ BinaryLocation newAddr = iter->second.end;
return newAddr;
}
}
return 0;
}
- uint32_t getNewFuncAddr(uint32_t oldAddr) const {
+ BinaryLocation getNewFuncAddr(BinaryLocation oldAddr) const {
if (auto* func = oldFuncAddrMap.get(oldAddr)) {
// The function might have been optimized away, check.
auto iter = newLocations.functions.find(func);
@@ -482,8 +482,8 @@ static void updateDebugLines(llvm::DWARFYAML::Data& data,
// Parse the original opcodes and emit new ones.
LineState state(table);
// All the addresses we need to write out.
- std::vector<uint32_t> newAddrs;
- std::unordered_map<uint32_t, LineState> newAddrInfo;
+ std::vector<BinaryLocation> newAddrs;
+ std::unordered_map<BinaryLocation, LineState> newAddrInfo;
// If the address was zeroed out, we must omit the entire range (we could
// also leave it unchanged, so that the debugger ignores it based on the
// initial zero; but it's easier and better to just not emit it at all).
@@ -523,7 +523,7 @@ static void updateDebugLines(llvm::DWARFYAML::Data& data,
{
std::vector<llvm::DWARFYAML::LineTableOpcode> newOpcodes;
LineState state(table);
- for (uint32_t addr : newAddrs) {
+ for (BinaryLocation addr : newAddrs) {
LineState oldState(state);
state = newAddrInfo.at(addr);
if (state.needToEmit()) {
@@ -557,7 +557,7 @@ static void updateDIE(const llvm::DWARFDebugInfoEntry& DIE,
auto tag = DIE.getTag();
// Pairs of low/high_pc require some special handling, as the high
// may be an offset relative to the low. First, process the low_pcs.
- uint32_t oldLowPC = 0, newLowPC = 0;
+ BinaryLocation oldLowPC = 0, newLowPC = 0;
iterContextAndYAML(
abbrevDecl->attributes(),
yamlEntry.Values,
@@ -567,7 +567,7 @@ static void updateDIE(const llvm::DWARFDebugInfoEntry& DIE,
if (attr != llvm::dwarf::DW_AT_low_pc) {
return;
}
- uint32_t oldValue = yamlValue.Value, newValue = 0;
+ BinaryLocation oldValue = yamlValue.Value, newValue = 0;
if (tag == llvm::dwarf::DW_TAG_GNU_call_site ||
tag == llvm::dwarf::DW_TAG_inlined_subroutine ||
tag == llvm::dwarf::DW_TAG_lexical_block ||
@@ -596,7 +596,7 @@ static void updateDIE(const llvm::DWARFDebugInfoEntry& DIE,
if (attr != llvm::dwarf::DW_AT_high_pc) {
return;
}
- uint32_t oldValue = yamlValue.Value, newValue = 0;
+ BinaryLocation oldValue = yamlValue.Value, newValue = 0;
bool isRelative = attrSpec.Form == llvm::dwarf::DW_FORM_data4;
if (isRelative) {
oldValue += oldLowPC;