summaryrefslogtreecommitdiff
path: root/src/binary-reader-objdump.cc
diff options
context:
space:
mode:
authorAndy Wingo <wingo@igalia.com>2020-10-01 17:30:58 +0200
committerGitHub <noreply@github.com>2020-10-01 08:30:58 -0700
commitee87440dedb4335d5ca8ec25e86b36c27a5b3368 (patch)
tree522ec9766d5da42fd8b8ba6efa0c6e74fc370748 /src/binary-reader-objdump.cc
parentcd63243c5b3b2fa938f365edab30139f74549b51 (diff)
downloadwabt-ee87440dedb4335d5ca8ec25e86b36c27a5b3368.tar.gz
wabt-ee87440dedb4335d5ca8ec25e86b36c27a5b3368.tar.bz2
wabt-ee87440dedb4335d5ca8ec25e86b36c27a5b3368.zip
Add --relocatable support for tables (#1549) (#1549)
We add relocations for table numbers on each place where we reify a table number (call_indirect, table.get, table.set...), but only if reference types are enabled. Also, fix symbol table generation with unnamed definitions, to allow for relocating references to anonymous functions or tables. As tests, add variants of the relocations and symbol-tables dump tests, with and without all features enabled. Enabling reference types causes relocs to be emitted. We also add --details to the relocations dump tests, so that we can see the target symbols for the relocations.
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r--src/binary-reader-objdump.cc42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index 649358d6..0d3d1188 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -58,6 +58,7 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
string_view GetEventName(Index index) const;
string_view GetSymbolName(Index index) const;
string_view GetSegmentName(Index index) const;
+ string_view GetTableName(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)];
@@ -152,6 +153,10 @@ string_view BinaryReaderObjdumpBase::GetSegmentName(Index index) const {
return objdump_state_->segment_names.Get(index);
}
+string_view BinaryReaderObjdumpBase::GetTableName(Index index) const {
+ return objdump_state_->table_names.Get(index);
+}
+
string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const {
if (symbol_index >= objdump_state_->symtab.size())
return "<illegal_symbol_index>";
@@ -167,6 +172,8 @@ string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const {
return GetSectionName(sym.index);
case SymbolType::Event:
return GetEventName(sym.index);
+ case SymbolType::Table:
+ return GetTableName(sym.index);
}
WABT_UNREACHABLE;
}
@@ -283,6 +290,18 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
return Result::Ok;
}
+ Result OnTableSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index table_index) override {
+ if (!name.empty()) {
+ SetTableName(table_index, name);
+ }
+ objdump_state_->symtab[index] = {SymbolType::Table, name.to_string(),
+ table_index};
+ return Result::Ok;
+ }
+
Result OnImportFunc(Index import_index,
string_view module_name,
string_view field_name,
@@ -351,6 +370,7 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
void SetFunctionName(Index index, string_view name);
void SetGlobalName(Index index, string_view name);
void SetEventName(Index index, string_view name);
+ void SetTableName(Index index, string_view name);
void SetSegmentName(Index index, string_view name);
};
@@ -367,6 +387,10 @@ void BinaryReaderObjdumpPrepass::SetEventName(Index index, string_view name) {
objdump_state_->event_names.Set(index, name);
}
+void BinaryReaderObjdumpPrepass::SetTableName(Index index, string_view name) {
+ objdump_state_->table_names.Set(index, name);
+}
+
void BinaryReaderObjdumpPrepass::SetSegmentName(Index index, string_view name) {
objdump_state_->segment_names.Set(index, name);
}
@@ -891,6 +915,10 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
uint32_t flags,
string_view name,
Index event_index) override;
+ Result OnTableSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index table_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
string_view name,
@@ -1781,11 +1809,23 @@ Result BinaryReaderObjdump::OnEventSymbol(Index index,
if (name.empty()) {
name = GetEventName(event_index);
}
- PrintDetails(" - [%d] E <" PRIstringview "> event=%" PRIindex, index,
+ PrintDetails(" - %d: E <" PRIstringview "> event=%" PRIindex, index,
WABT_PRINTF_STRING_VIEW_ARG(name), event_index);
return PrintSymbolFlags(flags);
}
+Result BinaryReaderObjdump::OnTableSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index table_index) {
+ if (name.empty()) {
+ name = GetTableName(table_index);
+ }
+ PrintDetails(" - %d: T <" PRIstringview "> table=%" PRIindex, index,
+ WABT_PRINTF_STRING_VIEW_ARG(name), table_index);
+ return PrintSymbolFlags(flags);
+}
+
Result BinaryReaderObjdump::OnSegmentInfoCount(Index count) {
PrintDetails(" - segment info [count=%d]\n", count);
return Result::Ok;