summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp7
-rw-r--r--src/wasm-binary.h2
-rw-r--r--src/wasm-io.h23
-rw-r--r--src/wasm/wasm-binary.cpp6
-rw-r--r--src/wasm/wasm-io.cpp1
5 files changed, 33 insertions, 6 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 8e37d60f4..eb475a73b 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -210,7 +210,12 @@ int main(int argc, const char* argv[]) {
Module wasm;
ModuleReader reader;
- reader.setDWARF(DWARF);
+ // If we are not writing output then we definitely don't need to read debug
+ // info, as it does not affect the metadata we will emit. (However, if we
+ // emit output then definitely load the names section so that we roundtrip
+ // names properly.)
+ reader.setDebugInfo(writeOutput);
+ reader.setDWARF(DWARF && writeOutput);
if (!writeOutput) {
// If we are not writing the output then all we are doing is simple parsing
// of metadata from global parts of the wasm such as imports and exports. In
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 453bcb9af..1cf8186f8 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1306,6 +1306,7 @@ class WasmBinaryBuilder {
const std::vector<char>& input;
std::istream* sourceMap;
std::pair<uint32_t, Function::DebugLocation> nextDebugLocation;
+ bool debugInfo = true;
bool DWARF = false;
bool skipFunctionBodies = false;
@@ -1324,6 +1325,7 @@ public:
: wasm(wasm), allocator(wasm.allocator), input(input), sourceMap(nullptr),
nextDebugLocation(0, {0, 0, 0}), debugLocation() {}
+ void setDebugInfo(bool value) { debugInfo = value; }
void setDWARF(bool value) { DWARF = value; }
void setSkipFunctionBodies(bool skipFunctionBodies_) {
skipFunctionBodies = skipFunctionBodies_;
diff --git a/src/wasm-io.h b/src/wasm-io.h
index 04fe90b51..036dc9c8c 100644
--- a/src/wasm-io.h
+++ b/src/wasm-io.h
@@ -27,8 +27,21 @@
namespace wasm {
-class ModuleReader {
+class ModuleIOBase {
+protected:
+ bool debugInfo;
+
+public:
+ // Whether we support debug info (the names section).
+ void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; }
+};
+
+class ModuleReader : public ModuleIOBase {
public:
+ // Reading defaults to loading the names section. Name section info is used in
+ // various internal ways that we do not opt-in to currently.
+ ModuleReader() { setDebugInfo(true); }
+
// If DWARF support is enabled, we track the locations of all IR nodes in
// the binary, so that we can update DWARF sections later when writing.
void setDWARF(bool DWARF_) { DWARF = DWARF_; }
@@ -67,16 +80,18 @@ private:
std::string sourceMapFilename);
};
-class ModuleWriter {
+class ModuleWriter : public ModuleIOBase {
bool binary = true;
- bool debugInfo = false;
std::string symbolMap;
std::string sourceMapFilename;
std::string sourceMapUrl;
public:
+ // Writing defaults to not storing the names section. Storing it is a user-
+ // observable fact that must be opted into.
+ ModuleWriter() { setDebugInfo(false); }
+
void setBinary(bool binary_) { binary = binary_; }
- void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; }
void setSymbolMap(std::string symbolMap_) { symbolMap = symbolMap_; }
void setSourceMapFilename(std::string sourceMapFilename_) {
sourceMapFilename = sourceMapFilename_;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 52aa4a6e0..c8568e469 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1424,7 +1424,11 @@ void WasmBinaryBuilder::readUserSection(size_t payloadLen) {
}
payloadLen -= read;
if (sectionName.equals(BinaryConsts::UserSections::Name)) {
- readNames(payloadLen);
+ if (debugInfo) {
+ readNames(payloadLen);
+ } else {
+ pos += payloadLen;
+ }
} else if (sectionName.equals(BinaryConsts::UserSections::TargetFeatures)) {
readFeatures(payloadLen);
} else if (sectionName.equals(BinaryConsts::UserSections::Dylink)) {
diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp
index f2c5af6db..42eb9ab46 100644
--- a/src/wasm/wasm-io.cpp
+++ b/src/wasm/wasm-io.cpp
@@ -50,6 +50,7 @@ void ModuleReader::readBinaryData(std::vector<char>& input,
std::string sourceMapFilename) {
std::unique_ptr<std::ifstream> sourceMapStream;
WasmBinaryBuilder parser(wasm, input);
+ parser.setDebugInfo(debugInfo);
parser.setDWARF(DWARF);
parser.setSkipFunctionBodies(skipFunctionBodies);
if (sourceMapFilename.size()) {