summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-logging.cc8
-rw-r--r--src/binary-reader-logging.h3
-rw-r--r--src/binary-reader-nop.h5
-rw-r--r--src/binary-reader-objdump.cc52
-rw-r--r--src/binary-reader-objdump.h1
-rw-r--r--src/binary-reader.cc8
-rw-r--r--src/binary-reader.h3
-rw-r--r--src/common.cc9
-rw-r--r--src/common.h7
9 files changed, 88 insertions, 8 deletions
diff --git a/src/binary-reader-logging.cc b/src/binary-reader-logging.cc
index 1ff0aea4..b1896c73 100644
--- a/src/binary-reader-logging.cc
+++ b/src/binary-reader-logging.cc
@@ -518,6 +518,14 @@ Result BinaryReaderLogging::OnGlobalSymbol(Index index,
return reader_->OnGlobalSymbol(index, flags, name, global_index);
}
+Result BinaryReaderLogging::OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) {
+ LOGF("OnSectionSymbol(flags: 0x%x index: %" PRIindex ")\n", flags,
+ section_index);
+ return reader_->OnSectionSymbol(index, flags, section_index);
+}
+
Result BinaryReaderLogging::OnSegmentInfo(Index index,
string_view name,
uint32_t alignment,
diff --git a/src/binary-reader-logging.h b/src/binary-reader-logging.h
index 87b13052..26b38506 100644
--- a/src/binary-reader-logging.h
+++ b/src/binary-reader-logging.h
@@ -272,6 +272,9 @@ class BinaryReaderLogging : public BinaryReaderDelegate {
uint32_t flags,
string_view name,
Index global_index) override;
+ Result OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
string_view name,
diff --git a/src/binary-reader-nop.h b/src/binary-reader-nop.h
index 671ae71d..37fa0ff5 100644
--- a/src/binary-reader-nop.h
+++ b/src/binary-reader-nop.h
@@ -396,6 +396,11 @@ class BinaryReaderNop : public BinaryReaderDelegate {
Index global_index) override {
return Result::Ok;
}
+ Result OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) override {
+ return Result::Ok;
+ }
Result OnSegmentInfoCount(Index count) override { return Result::Ok; }
Result OnSegmentInfo(Index index,
string_view name,
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc
index f0de5e1e..aa8cfd9f 100644
--- a/src/binary-reader-objdump.cc
+++ b/src/binary-reader-objdump.cc
@@ -48,6 +48,7 @@ class BinaryReaderObjdumpBase : public BinaryReaderNop {
protected:
const char* GetFunctionName(Index index) const;
const char* GetGlobalName(Index index) const;
+ const char* GetSectionName(Index index) const;
string_view GetSymbolName(Index symbol_index) const;
void PrintRelocation(const Reloc& reloc, Offset offset) const;
Offset GetSectionStart(BinarySection section_code) const {
@@ -138,6 +139,13 @@ const char* BinaryReaderObjdumpBase::GetGlobalName(Index index) const {
return objdump_state_->global_names[index].c_str();
}
+const char* BinaryReaderObjdumpBase::GetSectionName(Index index) const {
+ assert(index < objdump_state_->section_names.size() &&
+ !objdump_state_->section_names[index].empty());
+
+ return objdump_state_->section_names[index].c_str();
+}
+
string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const {
assert(symbol_index < objdump_state_->symtab.size());
ObjdumpSymbol& sym = objdump_state_->symtab[symbol_index];
@@ -148,13 +156,15 @@ string_view BinaryReaderObjdumpBase::GetSymbolName(Index symbol_index) const {
return sym.name;
case SymbolType::Global:
return GetGlobalName(sym.index);
+ case SymbolType::Section:
+ return GetSectionName(sym.index);
}
WABT_UNREACHABLE;
}
void BinaryReaderObjdumpBase::PrintRelocation(const Reloc& reloc,
Offset offset) const {
- printf(" %06" PRIzx ": %-18s %" PRIindex "", offset,
+ printf(" %06" PRIzx ": %-18s %" PRIindex, offset,
GetRelocTypeName(reloc.type), reloc.index);
if (reloc.addend) {
printf(" + %d", reloc.addend);
@@ -175,6 +185,20 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
public:
using BinaryReaderObjdumpBase::BinaryReaderObjdumpBase;
+ Result BeginSection(BinarySection section_code, Offset size) override {
+ BinaryReaderObjdumpBase::BeginSection(section_code, size);
+ if (section_code != BinarySection::Custom) {
+ objdump_state_->section_names.push_back(
+ wabt::GetSectionName(section_code));
+ }
+ return Result::Ok;
+ }
+
+ Result BeginCustomSection(Offset size, string_view section_name) override {
+ objdump_state_->section_names.push_back(section_name.to_string());
+ return Result::Ok;
+ }
+
Result OnFunctionName(Index index, string_view name) override {
SetFunctionName(index, name);
return Result::Ok;
@@ -219,6 +243,14 @@ class BinaryReaderObjdumpPrepass : public BinaryReaderObjdumpBase {
return Result::Ok;
}
+ Result OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) override {
+ objdump_state_->symtab[index] = {
+ SymbolType::Section, GetSectionName(section_index), section_index};
+ return Result::Ok;
+ }
+
Result OnImportFunc(Index import_index,
string_view module_name,
string_view field_name,
@@ -709,6 +741,9 @@ class BinaryReaderObjdump : public BinaryReaderObjdumpBase {
uint32_t flags,
string_view name,
Index global_index) override;
+ Result OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) override;
Result OnSegmentInfoCount(Index count) override;
Result OnSegmentInfo(Index index,
string_view name,
@@ -757,7 +792,7 @@ Result BinaryReaderObjdump::BeginSection(BinarySection section_code,
Offset size) {
BinaryReaderObjdumpBase::BeginSection(section_code, size);
- const char* name = GetSectionName(section_code);
+ const char* name = wabt::GetSectionName(section_code);
bool section_match =
!options_->section_name || !strcasecmp(options_->section_name, name);
@@ -1259,7 +1294,7 @@ Result BinaryReaderObjdump::OnDataSegmentData(Index index,
Result BinaryReaderObjdump::OnRelocCount(Index count, Index section_index) {
BinaryReaderObjdumpBase::OnRelocCount(count, section_index);
PrintDetails(" - relocations for section: %d (%s) [%d]\n", section_index,
- GetSectionName(section_types_[section_index]), count);
+ GetSectionName(section_index), count);
return Result::Ok;
}
@@ -1375,6 +1410,17 @@ Result BinaryReaderObjdump::OnGlobalSymbol(Index index,
return Result::Ok;
}
+Result BinaryReaderObjdump::OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) {
+ const char* sym_name = GetSectionName(section_index);
+ assert(sym_name);
+ PrintDetails(" - [%d] S <%s> section=%" PRIindex, index, sym_name,
+ section_index);
+ PrintSymbolFlags(flags);
+ return Result::Ok;
+}
+
Result BinaryReaderObjdump::OnSegmentInfoCount(Index count) {
PrintDetails(" - segment info [count=%d]\n", count);
return Result::Ok;
diff --git a/src/binary-reader-objdump.h b/src/binary-reader-objdump.h
index aeebd0b9..1b0483d7 100644
--- a/src/binary-reader-objdump.h
+++ b/src/binary-reader-objdump.h
@@ -63,6 +63,7 @@ struct ObjdumpState {
std::vector<Reloc> data_relocations;
std::vector<std::string> function_names;
std::vector<std::string> global_names;
+ std::vector<std::string> section_names;
std::vector<ObjdumpSymbol> symtab;
};
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index e8096efd..5c958f7e 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -1455,6 +1455,8 @@ Result BinaryReader::ReadRelocSection(Offset section_size) {
case RelocType::MemoryAddressLEB:
case RelocType::MemoryAddressSLEB:
case RelocType::MemoryAddressI32:
+ case RelocType::FunctionOffsetI32:
+ case RelocType::SectionOffsetI32:
CHECK_RESULT(ReadS32Leb128(&addend, "addend"));
break;
default:
@@ -1522,6 +1524,12 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) {
CALLBACK(OnDataSymbol, i, flags, name, segment, offset, size);
break;
}
+ case SymbolType::Section: {
+ uint32_t index = 0;
+ CHECK_RESULT(ReadU32Leb128(&index, "index"));
+ CALLBACK(OnSectionSymbol, i, flags, index);
+ break;
+ }
}
}
break;
diff --git a/src/binary-reader.h b/src/binary-reader.h
index a22b9e62..cf09ddba 100644
--- a/src/binary-reader.h
+++ b/src/binary-reader.h
@@ -332,6 +332,9 @@ class BinaryReaderDelegate {
uint32_t flags,
string_view name,
Index global_index) = 0;
+ virtual Result OnSectionSymbol(Index index,
+ uint32_t flags,
+ Index section_index) = 0;
virtual Result OnSegmentInfoCount(Index count) = 0;
virtual Result OnSegmentInfo(Index index,
string_view name,
diff --git a/src/common.cc b/src/common.cc
index 4516ec37..a3c3d4a5 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -38,10 +38,11 @@ const char* g_kind_name[] = {"func", "table", "memory", "global", "except"};
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(g_kind_name) == kExternalKindCount);
const char* g_reloc_type_name[] = {
- "R_WEBASSEMBLY_FUNCTION_INDEX_LEB", "R_WEBASSEMBLY_TABLE_INDEX_SLEB",
- "R_WEBASSEMBLY_TABLE_INDEX_I32", "R_WEBASSEMBLY_MEMORY_ADDR_LEB",
- "R_WEBASSEMBLY_MEMORY_ADDR_SLEB", "R_WEBASSEMBLY_MEMORY_ADDR_I32",
- "R_WEBASSEMBLY_TYPE_INDEX_LEB", "R_WEBASSEMBLY_GLOBAL_INDEX_LEB",
+ "R_WEBASSEMBLY_FUNCTION_INDEX_LEB", "R_WEBASSEMBLY_TABLE_INDEX_SLEB",
+ "R_WEBASSEMBLY_TABLE_INDEX_I32", "R_WEBASSEMBLY_MEMORY_ADDR_LEB",
+ "R_WEBASSEMBLY_MEMORY_ADDR_SLEB", "R_WEBASSEMBLY_MEMORY_ADDR_I32",
+ "R_WEBASSEMBLY_TYPE_INDEX_LEB", "R_WEBASSEMBLY_GLOBAL_INDEX_LEB",
+ "R_WEBASSEMBLY_FUNCTION_OFFSET_I32", "R_WEBASSEMBLY_SECTION_OFFSET_I32",
};
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(g_reloc_type_name) == kRelocTypeCount);
diff --git a/src/common.h b/src/common.h
index 8418fc77..f4c9f5ef 100644
--- a/src/common.h
+++ b/src/common.h
@@ -225,9 +225,11 @@ enum class RelocType {
MemoryAddressI32 = 5, // e.g. Memory address in DATA
TypeIndexLEB = 6, // e.g. Immediate type in call_indirect
GlobalIndexLEB = 7, // e.g. Immediate of get_global inst
+ FunctionOffsetI32 = 8, // e.g. Code offset in DWARF metadata
+ SectionOffsetI32 = 9, // e.g. Section offset in DWARF metadata
First = FuncIndexLEB,
- Last = GlobalIndexLEB,
+ Last = SectionOffsetI32,
};
static const int kRelocTypeCount = WABT_ENUM_COUNT(RelocType);
@@ -251,6 +253,7 @@ enum class SymbolType {
Function = 0,
Data = 1,
Global = 2,
+ Section = 3,
};
#define WABT_SYMBOL_FLAG_UNDEFINED 0x10
@@ -322,6 +325,8 @@ static WABT_INLINE const char* GetSymbolTypeName(SymbolType type) {
return "global";
case SymbolType::Data:
return "data";
+ case SymbolType::Section:
+ return "section";
}
WABT_UNREACHABLE;
}