Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6fb2a4a
Move SymbolTable out of binary writer
feedab1e Oct 5, 2025
30e3733
Add representation for relocations in instructions
feedab1e Oct 5, 2025
4aaed1e
Add support for relocations in the binary reader
feedab1e Oct 8, 2025
3c9615d
Add support for relocations in the text writer
feedab1e Oct 8, 2025
6d48401
Add a check for token contents in ParseCodeMetadataAnnotation
feedab1e Oct 8, 2025
aa75317
Small adjustments to reloc printing
feedab1e Oct 9, 2025
f15f4ce
Make fields of SymbolCommon public
feedab1e Oct 9, 2025
0475fb1
Add support for relocations in wast-parser
feedab1e Oct 9, 2025
f1b58e9
Add size output for data symbols
feedab1e Oct 10, 2025
f3c53e9
Remove 'export' in symbols as it doesn't make sense for data symbols
feedab1e Oct 10, 2025
88015ed
Clean up the implementation for symbol parser
feedab1e Oct 10, 2025
391e056
Fix binding generation with invalid indices
feedab1e Oct 10, 2025
ff37487
Add export symbol flags
feedab1e Oct 10, 2025
5e31c0d
Add name resolution for relocations
feedab1e Oct 10, 2025
4bcc959
Add name resolution for relocations in data segments
feedab1e Oct 10, 2025
40046a0
Fix parser setting invalid flags and types
feedab1e Oct 10, 2025
beb3e96
Add fixed 64 bit leb writers
feedab1e Oct 10, 2025
44d0f98
Adjust symbol table implementation to account for the fact that symbo…
feedab1e Oct 10, 2025
4aea26c
Adjust binary writer to output more relocations
feedab1e Oct 10, 2025
8588622
Prevent writing symbol metadata when no attributes need to be specified
feedab1e Oct 11, 2025
667ff47
Add handling for invalid symbol definitions and relocations
feedab1e Oct 11, 2025
c09b03a
Handle expressions appearing outside relocatable sections
feedab1e Oct 11, 2025
0f3b61e
Revert to older error message to pass more tests
feedab1e Oct 11, 2025
8b1afe0
Fix inverted assetion condition
feedab1e Oct 11, 2025
2f9a0d6
Always print at least an empty string in data segments
feedab1e Oct 11, 2025
52f74d3
Add validation for invalid init functions
feedab1e Oct 11, 2025
219584c
Fix global symbol handler using an inappropriate index
feedab1e Oct 11, 2025
a699ca7
Fix exports not being looked up correctly
feedab1e Oct 12, 2025
eb99d50
Imply no_strip when exporting
feedab1e Oct 12, 2025
3cbbf34
Set WASM_EXPLICIT_NAME when exporting [old behavior compat]
feedab1e Oct 12, 2025
4c25f78
Set WASM_EXPLICIT_NAME from variable name [old behavior compat]
feedab1e Oct 12, 2025
6fb2d45
Set WASM_EXPLICIT_NAME from import name [old behavior compat]
feedab1e Oct 12, 2025
9f89fd5
Add symbol annotation handling where I forgot them
feedab1e Oct 12, 2025
a69c8a5
Force symbols without a name to be local
feedab1e Oct 12, 2025
61b4ad9
Edit tests to reflect the fact that visibility is specified via an an…
feedab1e Oct 12, 2025
ffc7772
Ignore other symbols pointing to the same entity for the purposes of …
feedab1e Oct 12, 2025
5234197
Fix wrong index in OnTableSymbol
feedab1e Oct 12, 2025
118f866
Add an option to emit relocation annotations
feedab1e Oct 12, 2025
c1abb26
Fix warning
feedab1e Oct 13, 2025
96a44d6
Fix narrowing conversion error on 32-bit machines
feedab1e Oct 13, 2025
62fd9aa
Error instead of failing assert in OnRelocCount
feedab1e Oct 14, 2025
c01759f
Work around msvc SKILL ISSUE, take 1
feedab1e Oct 14, 2025
ddf521d
Work around msvc SKILL ISSUE, take 2
feedab1e Oct 14, 2025
87259c4
Exit early on invalid symtab
feedab1e Oct 14, 2025
5f7f384
Fix invalid treatment of data imports
feedab1e Oct 19, 2025
8c1da43
Assume all leb relocs of primary shapes are valid in the code section
feedab1e Oct 19, 2025
b61fa7a
Skip raw output of linking and reloc sections when outputting relocat…
feedab1e Oct 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions include/wabt/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ void Destruct(T& placement) {
placement.~T();
}

template<class... Fs>
struct Overload: Fs... {
using Fs::operator()...;
};
template<class... Fs>
Overload(Fs...)->Overload<Fs...>;

enum class LabelType {
Func,
InitExpr,
Expand Down Expand Up @@ -297,9 +304,162 @@ enum class RelocType {

First = FuncIndexLEB,
Last = FuncIndexI32,
None = -1, // Used internally as a sentinel value
};

enum class RelocDataType {
I32, I64,
LEB, LEB64,
SLEB, SLEB64,
};

constexpr size_t kRelocDataTypeSize[] {
4, 8,
5, 10,
5, 10
};

constexpr RelocDataType kRelocDataType[] {
RelocDataType::LEB, // FuncIndexLEB = 0
RelocDataType::SLEB, // TableIndexSLEB = 1
RelocDataType::I32, // TableIndexI32 = 2
RelocDataType::LEB, // MemoryAddressLEB = 3
RelocDataType::SLEB, // MemoryAddressSLEB = 4
RelocDataType::I32, // MemoryAddressI32 = 5
RelocDataType::LEB, // TypeIndexLEB = 6
RelocDataType::LEB, // GlobalIndexLEB = 7
RelocDataType::I32, // FunctionOffsetI32 = 8
RelocDataType::I32, // SectionOffsetI32 = 9
RelocDataType::LEB, // TagIndexLEB = 10
RelocDataType::SLEB, // MemoryAddressRelSLEB = 11
RelocDataType::SLEB, // TableIndexRelSLEB = 12
RelocDataType::I32, // GlobalIndexI32 = 13
RelocDataType::LEB64, // MemoryAddressLEB64 = 14
RelocDataType::SLEB64, // MemoryAddressSLEB64 = 15
RelocDataType::I64, // MemoryAddressI64 = 16
RelocDataType::SLEB64, // MemoryAddressRelSLEB64 = 17
RelocDataType::SLEB64, // TableIndexSLEB64 = 18
RelocDataType::I64, // TableIndexI64 = 19
RelocDataType::LEB, // TableNumberLEB = 20
RelocDataType::SLEB, // MemoryAddressTLSSLEB = 21
RelocDataType::I64, // FunctionOffsetI64 = 22
RelocDataType::I32, // MemoryAddressLocRelI32 = 23
RelocDataType::SLEB64, // TableIndexRelSLEB64 = 24
RelocDataType::SLEB64, // MemoryAddressTLSSLEB64 = 25
RelocDataType::I32, // FuncIndexI32 = 26
};

enum class RelocKind {
Function,
FunctionTbl,
Data,
Global,
Table,
Tag,
Type,
Section,
Text,
};

constexpr RelocKind kRelocSymbolType[] {
RelocKind::Function, // FuncIndexLEB = 0
RelocKind::FunctionTbl, // TableIndexSLEB = 1
RelocKind::FunctionTbl, // TableIndexI32 = 2
RelocKind::Data, // MemoryAddressLEB = 3
RelocKind::Data, // MemoryAddressSLEB = 4
RelocKind::Data, // MemoryAddressI32 = 5
RelocKind::Type, // TypeIndexLEB = 6
RelocKind::Global, // GlobalIndexLEB = 7
RelocKind::Text, // FunctionOffsetI32 = 8
RelocKind::Section, // SectionOffsetI32 = 9
RelocKind::Tag, // TagIndexLEB = 10
RelocKind::Data, // MemoryAddressRelSLEB = 11
RelocKind::Table, // TableIndexRelSLEB = 12
RelocKind::Global, // GlobalIndexI32 = 13
RelocKind::Data, // MemoryAddressLEB64 = 14
RelocKind::Data, // MemoryAddressSLEB64 = 15
RelocKind::Data, // MemoryAddressI64 = 16
RelocKind::Data, // MemoryAddressRelSLEB64 = 17
RelocKind::FunctionTbl, // TableIndexSLEB64 = 18
RelocKind::FunctionTbl, // TableIndexI64 = 19
RelocKind::Table, // TableNumberLEB = 20
RelocKind::Data, // MemoryAddressTLSSLEB = 21
RelocKind::Text, // FunctionOffsetI64 = 22
RelocKind::Data, // MemoryAddressLocRelI32 = 23
RelocKind::FunctionTbl, // TableIndexRelSLEB64 = 24
RelocKind::Data, // MemoryAddressTLSSLEB64 = 25
RelocKind::Function, // FuncIndexI32 = 26
};

enum class RelocModifiers {
None = 0,
TLS = 1,
PIC = 2,
};

inline RelocModifiers operator|(RelocModifiers a, RelocModifiers b) {
using U = std::underlying_type_t<RelocModifiers>;
return RelocModifiers(U(a) | U(b));
}

inline RelocModifiers operator&(RelocModifiers a, RelocModifiers b) {
using U = std::underlying_type_t<RelocModifiers>;
return RelocModifiers(U(a) & U(b));
}

inline RelocModifiers operator~(RelocModifiers a) {
using U = std::underlying_type_t<RelocModifiers>;
return RelocModifiers(~U(a));
}

constexpr RelocModifiers kRelocModifiers[] {
RelocModifiers::None, // FuncIndexLEB = 0
RelocModifiers::None, // TableIndexSLEB = 1
RelocModifiers::None, // TableIndexI32 = 2
RelocModifiers::None, // MemoryAddressLEB = 3
RelocModifiers::None, // MemoryAddressSLEB = 4
RelocModifiers::None, // MemoryAddressI32 = 5
RelocModifiers::None, // TypeIndexLEB = 6
RelocModifiers::None, // GlobalIndexLEB = 7
RelocModifiers::None, // FunctionOffsetI32 = 8
RelocModifiers::None, // SectionOffsetI32 = 9
RelocModifiers::None, // TagIndexLEB = 10
RelocModifiers::PIC, // MemoryAddressRelSLEB = 11
RelocModifiers::PIC, // TableIndexRelSLEB = 12
RelocModifiers::None, // GlobalIndexI32 = 13
RelocModifiers::None, // MemoryAddressLEB64 = 14
RelocModifiers::None, // MemoryAddressSLEB64 = 15
RelocModifiers::None, // MemoryAddressI64 = 16
RelocModifiers::PIC, // MemoryAddressRelSLEB64 = 17
RelocModifiers::None, // TableIndexSLEB64 = 18
RelocModifiers::None, // TableIndexI64 = 19
RelocModifiers::None, // TableNumberLEB = 20
RelocModifiers::TLS, // MemoryAddressTLSSLEB = 21
RelocModifiers::None, // FunctionOffsetI64 = 22
RelocModifiers::PIC, // MemoryAddressLocRelI32 = 23
RelocModifiers::PIC, // TableIndexRelSLEB64 = 24
RelocModifiers::TLS, // MemoryAddressTLSSLEB64 = 25
RelocModifiers::None, // FuncIndexI32 = 26
};


constexpr int kRelocTypeCount = WABT_ENUM_COUNT(RelocType);

constexpr RelocType RecognizeReloc(RelocKind kind,
RelocDataType type,
RelocModifiers mod) {
for (int i = 0; i < kRelocTypeCount; ++i) {
if (kind != kRelocSymbolType[i])
continue;
if (type != kRelocDataType[i])
continue;
if (mod != kRelocModifiers[i])
continue;
return RelocType(i);
}
return RelocType::None;
}

struct Reloc {
Reloc(RelocType, size_t offset, Index index, int32_t addend = 0);

Expand Down
Loading
Loading