Skip to content

Commit

Permalink
Add the new relocation types
Browse files Browse the repository at this point in the history
  • Loading branch information
SingleAccretion committed Aug 29, 2024
1 parent 14af7df commit 095ec11
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/wabt/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,14 @@ enum class RelocType {
TableIndexI64 = 19, // Memory64: Like TableIndexI32
TableNumberLEB = 20, // e.g. Immediate of table.get
MemoryAddressTLSSLEB = 21, // Address relative to __tls_base
MemoryAddressTLSI32 = 22, // Address relative to __tls_base
FunctionOffsetI64 = 22, // Memory64: Like FunctionOffsetI32
MemoryAddressLocRelI32 = 23, // Address relative to the relocation's location
TableIndexRelSLEB64 = 24, // Memory64: TableIndexRelSLEB
MemoryAddressTLSSLEB64 = 25, // Memory64: MemoryAddressTLSSLEB
FuncIndexI32 = 26, // Function index as an I32

First = FuncIndexLEB,
Last = MemoryAddressTLSI32,
Last = FuncIndexI32,
};
constexpr int kRelocTypeCount = WABT_ENUM_COUNT(RelocType);

Expand Down
5 changes: 5 additions & 0 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2036,13 +2036,17 @@ Result BinaryReader::ReadRelocSection(Offset section_size) {
case RelocType::MemoryAddressRelSLEB64:
case RelocType::MemoryAddressI32:
case RelocType::MemoryAddressI64:
case RelocType::MemoryAddressLocRelI32:
case RelocType::FunctionOffsetI32:
case RelocType::FunctionOffsetI64:
case RelocType::SectionOffsetI32:
case RelocType::MemoryAddressTLSSLEB:
case RelocType::MemoryAddressTLSSLEB64:
CHECK_RESULT(ReadS32Leb128(&addend, "addend"));
break;

case RelocType::FuncIndexLEB:
case RelocType::FuncIndexI32:
case RelocType::TableIndexSLEB:
case RelocType::TableIndexSLEB64:
case RelocType::TableIndexI32:
Expand All @@ -2052,6 +2056,7 @@ Result BinaryReader::ReadRelocSection(Offset section_size) {
case RelocType::GlobalIndexI32:
case RelocType::TagIndexLEB:
case RelocType::TableIndexRelSLEB:
case RelocType::TableIndexRelSLEB64:
case RelocType::TableNumberLEB:
break;

Expand Down
5 changes: 5 additions & 0 deletions src/binary-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1197,12 +1197,16 @@ void BinaryWriter::WriteRelocSection(const RelocSection* reloc_section) {
case RelocType::MemoryAddressRelSLEB64:
case RelocType::MemoryAddressI32:
case RelocType::MemoryAddressI64:
case RelocType::MemoryAddressLocRelI32:
case RelocType::FunctionOffsetI32:
case RelocType::FunctionOffsetI64:
case RelocType::SectionOffsetI32:
case RelocType::MemoryAddressTLSSLEB:
case RelocType::MemoryAddressTLSSLEB64:
WriteU32Leb128(stream_, reloc.addend, "reloc addend");
break;
case RelocType::FuncIndexLEB:
case RelocType::FuncIndexI32:
case RelocType::TableIndexSLEB:
case RelocType::TableIndexSLEB64:
case RelocType::TableIndexI32:
Expand All @@ -1211,6 +1215,7 @@ void BinaryWriter::WriteRelocSection(const RelocSection* reloc_section) {
case RelocType::GlobalIndexLEB:
case RelocType::TagIndexLEB:
case RelocType::TableIndexRelSLEB:
case RelocType::TableIndexRelSLEB64:
case RelocType::TableNumberLEB:
break;
default:
Expand Down
5 changes: 5 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const char* g_reloc_type_name[] = {
"R_WASM_TABLE_INDEX_I64",
"R_WASM_TABLE_NUMBER_LEB",
"R_WASM_MEMORY_ADDR_TLS_SLEB",
"R_WASM_FUNCTION_OFFSET_I64",
"R_WASM_MEMORY_ADDR_LOCREL_I32",
"R_WASM_TABLE_INDEX_REL_SLEB64",
"R_WASM_MEMORY_ADDR_TLS_SLEB64",
"R_WASM_FUNCTION_INDEX_I32",
};
WABT_STATIC_ASSERT(WABT_ARRAY_SIZE(g_reloc_type_name) == kRelocTypeCount);
// clang-format on
Expand Down

0 comments on commit 095ec11

Please sign in to comment.