summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-logging.cc38
-rw-r--r--src/binary-reader-logging.h18
-rw-r--r--src/binary-reader-nop.h26
-rw-r--r--src/binary-reader-objdump.cc143
-rw-r--r--src/binary-reader-objdump.h1
-rw-r--r--src/binary-reader.cc46
-rw-r--r--src/binary-reader.h18
-rw-r--r--src/common.h32
8 files changed, 284 insertions, 38 deletions
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index bbef9b57..2f11967e 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -456,10 +456,40 @@ Result BinaryReaderLogging::OnReloc(RelocType type,
return reader_->OnReloc(type, offset, index, addend);
}
-Result BinaryReaderLogging::OnSymbolInfo(string_view name, uint32_t flags) {
- LOGF("(OnSymbolInfo name: " PRIstringview ", flags: 0x%x)\n",
+Result BinaryReaderLogging::OnSymbol(Index symbol_index,
+ SymbolType type,
+ uint32_t flags) {
+ LOGF("(OnSymbol type: %s flags: 0x%x)\n", GetSymbolTypeName(type), flags);
+ return reader_->OnSymbol(symbol_index, type, flags);
+}
+
+Result BinaryReaderLogging::OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) {
+ LOGF("(OnDataSymbol name: " PRIstringview " flags: 0x%x)\n",
WABT_PRINTF_STRING_VIEW_ARG(name), flags);
- return reader_->OnSymbolInfo(name, flags);
+ return reader_->OnDataSymbol(index, flags, name, segment, offset, size);
+}
+
+Result BinaryReaderLogging::OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) {
+ LOGF("(OnFunctionSymbol name: " PRIstringview " flags: 0x%x)\n",
+ WABT_PRINTF_STRING_VIEW_ARG(name), flags);
+ return reader_->OnGlobalSymbol(index, flags, name, func_index);
+}
+
+Result BinaryReaderLogging::OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) {
+ LOGF("(OnGlobalSymbol name: " PRIstringview " flags: 0x%x)\n",
+ WABT_PRINTF_STRING_VIEW_ARG(name), flags);
+ return reader_->OnGlobalSymbol(index, flags, name, global_index);
}
Result BinaryReaderLogging::OnSegmentInfo(Index index,
@@ -640,7 +670,7 @@ DEFINE_END(EndRelocSection)
DEFINE_INDEX_INDEX(OnInitExprGetGlobalExpr, "index", "global_index")
DEFINE_BEGIN(BeginLinkingSection)
-DEFINE_INDEX(OnSymbolInfoCount)
+DEFINE_INDEX(OnSymbolCount)
DEFINE_INDEX(OnStackGlobal)
DEFINE_INDEX(OnDataSize)
DEFINE_INDEX(OnSegmentInfoCount)
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index d95e1a7a..dee30fd3 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -256,8 +256,22 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
Result BeginLinkingSection(Offset size) override;
Result OnStackGlobal(Index stack_global) override;
- Result OnSymbolInfoCount(Index count) override;
- Result OnSymbolInfo(string_view name, uint32_t flags) override;
+ Result OnSymbolCount(Index count) override;
+ Result OnSymbol(Index sybmol_index, SymbolType type, uint32_t flags) override;
+ Result OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) override;
+ Result OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) override;
+ Result OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) override;
Result OnDataSize(uint32_t data_size) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index b6dcc7b4..b99e297a 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -361,8 +361,30 @@ class BinaryReaderNop : public BinaryReaderDelegate {
/* Linking section */
Result BeginLinkingSection(Offset size) override { return Result::Ok; }
Result OnStackGlobal(Index stack_global) override { return Result::Ok; }
- Result OnSymbolInfoCount(Index count) override { return Result::Ok; }
- Result OnSymbolInfo(string_view name, uint32_t flags) override {
+ Result OnSymbolCount(Index count) override { return Result::Ok; }
+ Result OnSymbol(Index sybmol_index,
+ SymbolType type,
+ uint32_t flags) override {
+ return Result::Ok;
+ }
+ Result OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) override {
+ return Result::Ok;
+ }
+ Result OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) override {
+ return Result::Ok;
+ }
+ Result OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) override {
return Result::Ok;
}
Result OnDataSize(uint32_t data_size) override { return Result::Ok; }
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index b84a4691..dd01b7af 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -49,6 +49,7 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
protected:
const char* GetFunctionName(Index index) const;
+ const char* GetGlobalName(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)];
@@ -124,6 +125,15 @@ const char* BinaryReaderObjdumpBase::GetFunctionName(Index index) const {
return objdump_state_->function_names[index].c_str();
}
+const char* BinaryReaderObjdumpBase::GetGlobalName(Index index) const {
+ if (index >= objdump_state_->global_names.size() ||
+ objdump_state_->global_names[index].empty()) {
+ return nullptr;
+ }
+
+ return objdump_state_->global_names[index].c_str();
+}
+
void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc,
Offset offset) const {
printf(" %06" PRIzx ": %-18s %" PRIindex "", offset,
@@ -157,19 +167,43 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
public:
using BinaryReaderObjdumpBase::BinaryReaderObjdumpBase;
- Result OnFunctionName(Index function_index,
- string_view function_name) override;
+ Result OnFunctionName(Index index, string_view name) override {
+ SetFunctionName(index, name);
+ return Result::Ok;
+ }
+
+ Result OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) override {
+ if (!name.empty()) {
+ SetFunctionName(func_index, name);
+ }
+ return Result::Ok;
+ }
+
+ Result OnImportFunc(Index import_index,
+ string_view module_name,
+ string_view field_name,
+ Index func_index,
+ Index sig_index) override {
+ SetFunctionName(func_index, field_name);
+ return Result::Ok;
+ }
+
Result OnReloc(RelocType type,
Offset offset,
Index index,
uint32_t addend) override;
+
+ protected:
+ void SetFunctionName(Index index, string_view name);
};
-Result BinaryReaderObjdumpPrepass::OnFunctionName(Index index,
- string_view name) {
+void BinaryReaderObjdumpPrepass::SetFunctionName(Index index,
+ string_view name) {
objdump_state_->function_names.resize(index + 1);
objdump_state_->function_names[index] = name.to_string();
- return Result::Ok;
}
Result BinaryReaderObjdumpPrepass::OnReloc(RelocType type,
@@ -550,8 +584,21 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
uint32_t addend) override;
Result OnStackGlobal(Index stack_global) override;
- Result OnSymbolInfoCount(Index count) override;
- Result OnSymbolInfo(string_view name, uint32_t flags) override;
+ Result OnSymbolCount(Index count) override;
+ Result OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) override;
+ Result OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) override;
+ Result OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) override;
Result OnDataSize(uint32_t data_size) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
@@ -567,6 +614,7 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
private:
bool ShouldPrintDetails();
void PrintDetails(const char* fmt, ...);
+ void PrintSymbolFlags(uint32_t flags);
void PrintInitExpr(const InitExpr& expr);
Result OnCount(Index count);
@@ -1098,9 +1146,13 @@ Result BinaryReaderObjdump::OnReloc(RelocType type,
Index index,
uint32_t addend) {
Offset total_offset = GetSectionStart(reloc_section_) + offset;
- PrintDetails(" - %-18s offset=%#08" PRIoffset "(file=%#08" PRIoffset
- ") index=%" PRIindex,
- GetRelocTypeName(type), offset, total_offset, index);
+ PrintDetails(" - %-18s offset=%#08" PRIoffset "(file=%#08" PRIoffset ") ",
+ GetRelocTypeName(type), offset, total_offset);
+ if (type == RelocType::TypeIndexLEB)
+ PrintDetails("type=%" PRIindex, index);
+ else
+ PrintDetails("symbol=%" PRIindex, index);
+
if (addend) {
int32_t signed_addend = static_cast<int32_t>(addend);
if (signed_addend < 0) {
@@ -1120,28 +1172,81 @@ Result BinaryReaderObjdump::OnStackGlobal(Index stack_global) {
return Result::Ok;
}
-Result BinaryReaderObjdump::OnSymbolInfoCount(Index count) {
- PrintDetails(" - symbol info [count=%d]\n", count);
+Result BinaryReaderObjdump::OnSymbolCount(Index count) {
+ PrintDetails(" - symbol table [count=%d]\n", count);
return Result::Ok;
}
-Result BinaryReaderObjdump::OnSymbolInfo(string_view name, uint32_t flags) {
+void BinaryReaderObjdump::PrintSymbolFlags(uint32_t flags) {
const char* binding_name = nullptr;
- SymbolBinding binding = static_cast<SymbolBinding>(flags & 0x3);
+ SymbolBinding binding =
+ static_cast<SymbolBinding>(flags & WABT_SYMBOL_MASK_BINDING);
switch (binding) {
case SymbolBinding::Global:
- binding_name = "GLOBAL";
+ binding_name = "global";
break;
case SymbolBinding::Local:
- binding_name = "LOCAL ";
+ binding_name = "local";
break;
case SymbolBinding::Weak:
- binding_name = "WEAK ";
+ binding_name = "weak";
break;
}
- PrintDetails(" - %s <" PRIstringview ">\n", binding_name,
- WABT_PRINTF_STRING_VIEW_ARG(name));
+ const char* vis_name = nullptr;
+ SymbolVisibility vis =
+ static_cast<SymbolVisibility>(flags & WABT_SYMBOL_MASK_VISIBILITY);
+ switch (vis) {
+ case SymbolVisibility::Hidden:
+ vis_name = "hidden";
+ break;
+ case SymbolVisibility::Default:
+ vis_name = "default";
+ break;
+ }
+ PrintDetails(" binding=%s vis=%s\n", binding_name, vis_name);
+}
+
+Result BinaryReaderObjdump::OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) {
+ PrintDetails(" - sym[%d] <" PRIstringview "> segment=%" PRIindex
+ " offset=%d size=%d",
+ index, WABT_PRINTF_STRING_VIEW_ARG(name), segment, offset, size);
+ PrintSymbolFlags(flags);
+ return Result::Ok;
+}
+
+Result BinaryReaderObjdump::OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index func_index) {
+ std::string sym_name = name.to_string();
+ if (sym_name.empty()) {
+ sym_name = GetFunctionName(func_index);
+ }
+ assert(!sym_name.empty());
+ PrintDetails(" - sym[%d] <" PRIstringview "> func=%" PRIindex, index,
+ WABT_PRINTF_STRING_VIEW_ARG(sym_name), func_index);
+ PrintSymbolFlags(flags);
+ return Result::Ok;
+}
+
+Result BinaryReaderObjdump::OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) {
+ std::string sym_name = name.to_string();
+ if (sym_name.empty()) {
+ sym_name = GetGlobalName(global_index);
+ }
+ assert(!sym_name.empty());
+ PrintDetails(" - sym[%d] <" PRIstringview "> global=%" PRIindex, index,
+ WABT_PRINTF_STRING_VIEW_ARG(sym_name), global_index);
+ PrintSymbolFlags(flags);
return Result::Ok;
}
diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h
index d07696d2..6a485680 100644
--- a/src/binary-reader-objdump.h
+++ b/src/binary-reader-objdump.h
@@ -56,6 +56,7 @@ struct ObjdumpState {
std::vector<Reloc> code_relocations;
std::vector<Reloc> data_relocations;
std::vector<std::string> function_names;
+ std::vector<std::string> global_names;
};
Result ReadBinaryObjdump(const uint8_t* data,
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 8f6f627e..0f75eb7d 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -1399,15 +1399,45 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
CALLBACK(OnStackGlobal, stack_ptr);
break;
}
- case LinkingEntryType::SymbolInfo:
- CHECK_RESULT(ReadU32Leb128(&count, "info count"));
- CALLBACK(OnSymbolInfoCount, count);
- while (count--) {
+ case LinkingEntryType::SymbolTable:
+ CHECK_RESULT(ReadU32Leb128(&count, "sym count"));
+ CALLBACK(OnSymbolCount, count);
+ for (Index i = 0; i < count; ++i) {
string_view name;
- uint32_t info;
- CHECK_RESULT(ReadStr(&name, "symbol name"));
- CHECK_RESULT(ReadU32Leb128(&info, "sym flags"));
- CALLBACK(OnSymbolInfo, name, info);
+ uint32_t flags = 0;
+ uint32_t kind = 0;
+ CHECK_RESULT(ReadU32Leb128(&kind, "sym type"));
+ CHECK_RESULT(ReadU32Leb128(&flags, "sym flags"));
+ SymbolType sym_type = static_cast<SymbolType>(kind);
+ CALLBACK(OnSymbol, i, sym_type, flags);
+ switch (sym_type) {
+ case SymbolType::Function:
+ case SymbolType::Global: {
+ uint32_t index = 0;
+ CHECK_RESULT(ReadU32Leb128(&index, "index"));
+ if ((flags & WABT_SYMBOL_FLAG_UNDEFINED) == 0)
+ CHECK_RESULT(ReadStr(&name, "symbol name"));
+ if (sym_type == SymbolType::Function) {
+ CALLBACK(OnFunctionSymbol, i, flags, name, index);
+ } else {
+ CALLBACK(OnGlobalSymbol, i, flags, name, index);
+ }
+ break;
+ }
+ case SymbolType::Data: {
+ uint32_t segment = 0;
+ uint32_t offset = 0;
+ uint32_t size = 0;
+ CHECK_RESULT(ReadStr(&name, "symbol name"));
+ if ((flags & WABT_SYMBOL_FLAG_UNDEFINED) == 0) {
+ CHECK_RESULT(ReadU32Leb128(&segment, "segment"));
+ CHECK_RESULT(ReadU32Leb128(&offset, "offset"));
+ CHECK_RESULT(ReadU32Leb128(&size, "size"));
+ }
+ CALLBACK(OnDataSymbol, i, flags, name, segment, offset, size);
+ break;
+ }
+ }
}
break;
case LinkingEntryType::DataSize: {
diff --git a/src/binary-reader.h b/src/binary-reader.h
index c42154be..70a58ed0 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -307,8 +307,22 @@ class BinaryReaderDelegate {
/* Linking section */
virtual Result BeginLinkingSection(Offset size) = 0;
virtual Result OnStackGlobal(Index stack_global) = 0;
- virtual Result OnSymbolInfoCount(Index count) = 0;
- virtual Result OnSymbolInfo(string_view name, uint32_t flags) = 0;
+ virtual Result OnSymbolCount(Index count) = 0;
+ virtual Result OnSymbol(Index index, SymbolType type, uint32_t flags) = 0;
+ virtual Result OnDataSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index segment,
+ uint32_t offset,
+ uint32_t size) = 0;
+ virtual Result OnFunctionSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index function_index) = 0;
+ virtual Result OnGlobalSymbol(Index index,
+ uint32_t flags,
+ string_view name,
+ Index global_index) = 0;
virtual Result OnDataSize(uint32_t data_size) = 0;
virtual Result OnSegmentInfoCount(Index count) = 0;
virtual Result OnSegmentInfo(Index index,
diff --git a/src/common.h b/src/common.h
index 6a9b0f7e..009913b6 100644
--- a/src/common.h
+++ b/src/common.h
@@ -236,10 +236,26 @@ struct Reloc {
enum class LinkingEntryType {
StackPointer = 1,
- SymbolInfo = 2,
DataSize = 3,
SegmentInfo = 5,
InitFunctions = 6,
+ ComdatInfo = 7,
+ SymbolTable = 8,
+};
+
+enum class SymbolType {
+ Function = 0,
+ Data = 1,
+ Global = 2,
+};
+
+#define WABT_SYMBOL_FLAG_UNDEFINED 0x10
+#define WABT_SYMBOL_MASK_VISIBILITY 0x4
+#define WABT_SYMBOL_MASK_BINDING 0x3
+
+enum class SymbolVisibility {
+ Default = 0,
+ Hidden = 4,
};
enum class SymbolBinding {
@@ -292,6 +308,20 @@ static WABT_INLINE const char* GetRelocTypeName(RelocType reloc) {
return g_reloc_type_name[static_cast<size_t>(reloc)];
}
+/* symbol */
+
+static WABT_INLINE const char* GetSymbolTypeName(SymbolType type) {
+ switch (type) {
+ case SymbolType::Function:
+ return "func";
+ case SymbolType::Global:
+ return "global";
+ case SymbolType::Data:
+ return "data";
+ }
+ WABT_UNREACHABLE;
+}
+
/* type */
static WABT_INLINE const char* GetTypeName(Type type) {