diff --git a/src/webassembly.cc b/src/webassembly.cc index 5e2ab650..252ef30f 100644 --- a/src/webassembly.cc +++ b/src/webassembly.cc @@ -194,15 +194,19 @@ void ReadNames(const Section& section, IndexedNames* func_names, kElemSegment = 8, kDataSegment = 9 }; - + string_view header = section.data; string_view data = section.contents; while (!data.empty()) { NameType type = static_cast(ReadVarUInt7(&data)); uint32_t size = ReadVarUInt32(&data); + sink->AddFileRange("wasm_overhead", "[Wasm Section Headers]", + StrictSubstr(header, 0, data.data() - header.data())); + string_view section = ReadPiece(size, &data); - if (type == NameType::kFunction || type == NameType::kDataSegment) { + if (type == NameType::kFunction || type == NameType::kDataSegment + || type == NameType::kGlobal) { uint32_t count = ReadVarUInt32(§ion); for (uint32_t i = 0; i < count; i++) { string_view entry = section; @@ -210,11 +214,16 @@ void ReadNames(const Section& section, IndexedNames* func_names, uint32_t name_len = ReadVarUInt32(§ion); string_view name = ReadPiece(name_len, §ion); entry = StrictSubstr(entry, 0, name.data() - entry.data() + name.size()); - sink->AddFileRange("wasm_funcname", name, entry); + sink->AddFileRange("wasm_name", name, entry); + + // Global names aren't really functions or data, we don't track them yet. + if (type == NameType::kGlobal) + continue; IndexedNames *names = (type == NameType::kFunction ? func_names : dataseg_names); (*names)[index] = std::string(name); } } + header = data; } } @@ -287,8 +296,9 @@ uint32_t GetNumFunctionImports(const Section& section) { void ReadCodeSection(const Section& section, const IndexedNames& names, uint32_t num_imports, RangeSink* sink) { string_view data = section.contents; - uint32_t count = ReadVarUInt32(&data); + sink->AddFileRange("wasm_overhead", "[Wasm Section Headers]", + StrictSubstr(section.data, 0, data.data() - section.data.data())); for (uint32_t i = 0; i < count; i++) { string_view func = data; @@ -304,6 +314,7 @@ void ReadCodeSection(const Section& section, const IndexedNames& names, std::string name = "func[" + std::to_string(i) + "]"; sink->AddFileRange("wasm_function", name, func); } else { + printf("function %d, %s\n", i, iter->second.c_str()); sink->AddFileRange("wasm_function", ItaniumDemangle(iter->second, sink->data_source()), func); } } @@ -313,6 +324,9 @@ void ReadDataSection(const Section& section, const IndexedNames& names, RangeSink* sink) { string_view data = section.contents; uint32_t count = ReadVarUInt32(&data); + printf("Section.data: %p, contents: %p\n", section.data.data(), section.contents.data()); + sink->AddFileRange("wasm_overhead", "[Wasm Section Headers]", + StrictSubstr(section.data, 0, data.data() - section.data.data())); for (uint32_t i = 0; i < count; i++) { string_view segment = data; @@ -338,6 +352,7 @@ void ReadDataSection(const Section& section, const IndexedNames& names, std::string name = "data[" + std::to_string(i) + "]"; sink->AddFileRange("wasm_data", name, segment); } else { + printf("data %d, %s\n", i, iter->second.c_str()); sink->AddFileRange("wasm_data", iter->second, segment); } } diff --git a/tests/wasm/symbol_test.test b/tests/wasm/symbol_test.test index 60194f87..82a637ce 100644 --- a/tests/wasm/symbol_test.test +++ b/tests/wasm/symbol_test.test @@ -185,6 +185,7 @@ Sections: # Data section # FIXME: This is wrong, should be the data section header +# CHECK!!!!: 1c6-1c9 3 [Wasm Section Headers] # BUG: 1c6-1c9 3 main # CHECK: 1c9-1cf 6 .data.global2 # CHECK: 1cf-1d5 6 .data.global3 @@ -193,6 +194,7 @@ Sections: # Name section # FIXME: Name section header and subsection header is 1db-1e6 # BUG: 1db-1e6 11 .data.global4 +# CHECK!!: 1db-1e6 11 [Wasm Section Headers] # Function names # CHECK: 1e6-1f9 19 __wasm_call_ctors # CHECK: 1f9-20a 17 __wasm_init_tls @@ -200,9 +202,19 @@ Sections: # CHECK: 21e-225 7 func1 # CHECK: 225-22c 7 func2 # CHECK: 22c-23d 17 __original_main -# FIXME: Subsection headers and global names -# BUG: 23d-243 6 main -# BUG: 243-27f 60 [section name] + +# FIXME: this is the following: +# BUG: 23d-246 9 main +# But it should be: +# CHECK!!: 23d-243 6 main + + + +# Global names +# CHECK: 246-257 17 __stack_pointer +# CHECK: 257-263 12 __tls_base +# CHECK: 263-26f 12 __tls_size +# CHECK: 26f-27f 16 __tls_align # Data names # CHECK: 27f-28e 15 .data.global2 # CHECK: 28e-29d 15 .data.global3