diff options
-rw-r--r-- | src/binary-reader-logging.cc | 2 | ||||
-rw-r--r-- | src/binary-reader-objdump.cc | 42 | ||||
-rw-r--r-- | src/binary-reader-objdump.h | 1 | ||||
-rw-r--r-- | test/binary/linking-section.txt | 29 | ||||
-rw-r--r-- | test/binary/relocs.txt | 2 |
5 files changed, 64 insertions, 12 deletions
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc index 2a145cec..3755e343 100644 --- a/src/binary-reader-logging.cc +++ b/src/binary-reader-logging.cc @@ -552,7 +552,7 @@ Result BinaryReaderLogging::OnSegmentInfo(Index index, string_view name, uint32_t alignment, uint32_t flags) { - LOGF("OnSegmentInfos(%d name: " PRIstringview + LOGF("OnSegmentInfo(%d name: " PRIstringview ", alignment: %d, flags: 0x%x)\n", index, WABT_PRINTF_STRING_VIEW_ARG(name), alignment, flags); return reader_->OnSegmentInfo(index, name, alignment, flags); diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index d4d058d3..fc961ea7 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -50,7 +50,8 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop { string_view GetGlobalName(Index index) const; string_view GetSectionName(Index index) const; string_view GetEventName(Index index) const; - string_view GetSymbolName(Index symbol_index) const; + string_view GetSymbolName(Index index) const; + string_view GetSegmentName(Index index) const; void PrintRelocation(const Reloc& reloc, Offset offset) const; Offset GetSectionStart(BinarySection section_code) const { return section_starts_[static_cast<size_t>(section_code)]; @@ -155,6 +156,15 @@ string_view BinaryReaderObjdumpBase::GetEventName(Index index) const { return objdump_state_->event_names[index]; } +string_view BinaryReaderObjdumpBase::GetSegmentName(Index index) const { + if (index >= objdump_state_->segment_names.size() || + objdump_state_->segment_names[index].empty()) { + return {}; + } + + return objdump_state_->segment_names[index]; +} + string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const { assert(symbol_index < objdump_state_->symtab.size()); ObjdumpSymbol& sym = objdump_state_->symtab[symbol_index]; @@ -319,10 +329,19 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase { return Result::Ok; } + Result OnSegmentInfo(Index index, + string_view name, + uint32_t alignment_log2, + uint32_t flags) override { + SetSegmentName(index, name); + return Result::Ok; + } + protected: void SetFunctionName(Index index, string_view name); void SetGlobalName(Index index, string_view name); void SetEventName(Index index, string_view name); + void SetSegmentName(Index index, string_view name); }; void BinaryReaderObjdumpPrepass::SetFunctionName(Index index, @@ -344,6 +363,12 @@ void BinaryReaderObjdumpPrepass::SetEventName(Index index, string_view name) { objdump_state_->event_names[index] = name.to_string(); } +void BinaryReaderObjdumpPrepass::SetSegmentName(Index index, string_view name) { + if (objdump_state_->segment_names.size() <= index) + objdump_state_->segment_names.resize(index + 1); + objdump_state_->segment_names[index] = name.to_string(); +} + Result BinaryReaderObjdumpPrepass::OnReloc(RelocType type, Offset offset, Index index, @@ -1366,7 +1391,12 @@ Result BinaryReaderObjdump::OnDataSegmentData(Index index, return Result::Ok; } - PrintDetails(" - segment[%" PRIindex "] size=%" PRIaddress, index, size); + PrintDetails(" - segment[%" PRIindex "]", index); + auto name = GetSegmentName(index); + if (!name.empty()) { + PrintDetails(" <" PRIstringview ">", WABT_PRINTF_STRING_VIEW_ARG(name)); + } + PrintDetails(" size=%" PRIaddress, size); PrintInitExpr(data_init_expr_); out_stream_->WriteMemoryDump(src_data, size, data_offset_, PrintChars::Yes, @@ -1494,7 +1524,7 @@ Result BinaryReaderObjdump::OnDataSymbol(Index index, Index segment, uint32_t offset, uint32_t size) { - PrintDetails(" - [%d] D <" PRIstringview ">", index, + PrintDetails(" - %d: D <" PRIstringview ">", index, WABT_PRINTF_STRING_VIEW_ARG(name)); if (!(flags & WABT_SYMBOL_FLAG_UNDEFINED)) PrintDetails(" segment=%" PRIindex " offset=%d size=%d", segment, offset, @@ -1510,7 +1540,7 @@ Result BinaryReaderObjdump::OnFunctionSymbol(Index index, if (name.empty()) { name = GetFunctionName(func_index); } - PrintDetails(" - [%d] F <" PRIstringview "> func=%" PRIindex, index, + PrintDetails(" - %d: F <" PRIstringview "> func=%" PRIindex, index, WABT_PRINTF_STRING_VIEW_ARG(name), func_index); PrintSymbolFlags(flags); return Result::Ok; @@ -1523,7 +1553,7 @@ Result BinaryReaderObjdump::OnGlobalSymbol(Index index, if (name.empty()) { name = GetGlobalName(global_index); } - PrintDetails(" - [%d] G <" PRIstringview "> global=%" PRIindex, index, + PrintDetails(" - %d: G <" PRIstringview "> global=%" PRIindex, index, WABT_PRINTF_STRING_VIEW_ARG(name), global_index); PrintSymbolFlags(flags); return Result::Ok; @@ -1534,7 +1564,7 @@ Result BinaryReaderObjdump::OnSectionSymbol(Index index, Index section_index) { auto sym_name = GetSectionName(section_index); assert(!sym_name.empty()); - PrintDetails(" - [%d] S <" PRIstringview "> section=%" PRIindex, index, WABT_PRINTF_STRING_VIEW_ARG(sym_name), + PrintDetails(" - %d: S <" PRIstringview "> section=%" PRIindex, index, WABT_PRINTF_STRING_VIEW_ARG(sym_name), section_index); PrintSymbolFlags(flags); return Result::Ok; diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h index 190cd0de..3d5e1ebe 100644 --- a/src/binary-reader-objdump.h +++ b/src/binary-reader-objdump.h @@ -65,6 +65,7 @@ struct ObjdumpState { std::vector<std::string> global_names; std::vector<std::string> section_names; std::vector<std::string> event_names; + std::vector<std::string> segment_names; std::vector<ObjdumpSymbol> symtab; }; diff --git a/test/binary/linking-section.txt b/test/binary/linking-section.txt index d69aa39f..6598b616 100644 --- a/test/binary/linking-section.txt +++ b/test/binary/linking-section.txt @@ -2,6 +2,20 @@ ;;; ARGS: -x magic version +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section(DATA) { + count[2] + memory_index[0] + offset[i32.const 0 end] + data[str("foo")] + memory_index[0] + offset[i32.const 10 end] + data[str("bar")] +} section("linking") { metadata_version[2] @@ -54,6 +68,13 @@ linking-section.wasm: file format wasm 0x1 Section Details: +Memory[1]: + - memory[0] pages: initial=0 +Data[2]: + - segment[0] <data1> size=3 - init i32=0 + - 0000000: 666f 6f foo + - segment[1] <data2> size=3 - init i32=10 + - 000000a: 6261 72 bar Custom: - name: "linking" - segment info [count=2] @@ -63,10 +84,10 @@ Custom: - 1: priority=5 - 0: priority=6 - symbol table [count=4] - - [0] F <func_sym> func=0 binding=weak vis=default - - [1] G <global_sym> global=0 binding=local vis=default - - [2] D <data_sym> segment=1 offset=2 size=1 binding=global vis=hidden - - [3] F <func_sym> func=0 undefined binding=global vis=default + - 0: F <func_sym> func=0 binding=weak vis=default + - 1: G <global_sym> global=0 binding=local vis=default + - 2: D <data_sym> segment=1 offset=2 size=1 binding=global vis=hidden + - 3: F <func_sym> func=0 undefined binding=global vis=default Code Disassembly: diff --git a/test/binary/relocs.txt b/test/binary/relocs.txt index 147b4ce1..8559890d 100644 --- a/test/binary/relocs.txt +++ b/test/binary/relocs.txt @@ -41,7 +41,7 @@ Custom: Custom: - name: "linking" - symbol table [count=1] - - [0] S <mysection> section=1 binding=global vis=default + - 0: S <mysection> section=1 binding=global vis=default Custom: - name: "reloc.TYPE" - relocations for section: 0 (Type) [0] |