Skip to content

Support new dylink.0 custom section format #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 56 additions & 0 deletions src/binary-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class BinaryReader {
Result ReadNameSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadRelocSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadDylinkSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadDylink0Section(Offset section_size) WABT_WARN_UNUSED;
Result ReadLinkingSection(Offset section_size) WABT_WARN_UNUSED;
Result ReadCustomSection(Index section_index,
Offset section_size) WABT_WARN_UNUSED;
Expand Down Expand Up @@ -1954,6 +1955,59 @@ Result BinaryReader::ReadRelocSection(Offset section_size) {
return Result::Ok;
}

Result BinaryReader::ReadDylink0Section(Offset section_size) {
CALLBACK(BeginDylinkSection, section_size);

while (state_.offset < read_end_) {
uint32_t dylink_type;
Offset subsection_size;
CHECK_RESULT(ReadU32Leb128(&dylink_type, "type"));
CHECK_RESULT(ReadOffset(&subsection_size, "subsection size"));
size_t subsection_end = state_.offset + subsection_size;
ERROR_UNLESS(subsection_end <= read_end_,
"invalid sub-section size: extends past end");
ReadEndRestoreGuard guard(this);
read_end_ = subsection_end;

switch (static_cast<DylinkEntryType>(dylink_type)) {
case DylinkEntryType::MemInfo: {
uint32_t mem_size;
uint32_t mem_align;
uint32_t table_size;
uint32_t table_align;

CHECK_RESULT(ReadU32Leb128(&mem_size, "mem_size"));
CHECK_RESULT(ReadU32Leb128(&mem_align, "mem_align"));
CHECK_RESULT(ReadU32Leb128(&table_size, "table_size"));
CHECK_RESULT(ReadU32Leb128(&table_align, "table_align"));
CALLBACK(OnDylinkInfo, mem_size, mem_align, table_size, table_align);
break;
}
case DylinkEntryType::Needed: {
uint32_t count;
CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs"));
CALLBACK(OnDylinkNeededCount, count);
while (count--) {
string_view so_name;
CHECK_RESULT(ReadStr(&so_name, "dylib so_name"));
CALLBACK(OnDylinkNeeded, so_name);
}
break;
}
default:
// Unknown subsection, skip it.
state_.offset = subsection_end;
break;
}
ERROR_UNLESS(state_.offset == subsection_end,
"unfinished sub-section (expected end: 0x%" PRIzx ")",
subsection_end);
}

CALLBACK0(EndDylinkSection);
return Result::Ok;
}

Result BinaryReader::ReadDylinkSection(Offset section_size) {
CALLBACK(BeginDylinkSection, section_size);
uint32_t mem_size;
Expand Down Expand Up @@ -2153,6 +2207,8 @@ Result BinaryReader::ReadCustomSection(Index section_index,
if (options_.read_debug_names && section_name == WABT_BINARY_SECTION_NAME) {
CHECK_RESULT(ReadNameSection(section_size));
did_read_names_section_ = true;
} else if (section_name == WABT_BINARY_SECTION_DYLINK0) {
CHECK_RESULT(ReadDylink0Section(section_size));
} else if (section_name == WABT_BINARY_SECTION_DYLINK) {
CHECK_RESULT(ReadDylinkSection(section_size));
} else if (section_name.rfind(WABT_BINARY_SECTION_RELOC, 0) == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define WABT_BINARY_SECTION_RELOC "reloc"
#define WABT_BINARY_SECTION_LINKING "linking"
#define WABT_BINARY_SECTION_DYLINK "dylink"
#define WABT_BINARY_SECTION_DYLINK0 "dylink.0"

#define WABT_FOREACH_BINARY_SECTION(V) \
V(Custom, custom, 0) \
Expand Down
5 changes: 5 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ enum class LinkingEntryType {
SymbolTable = 8,
};

enum class DylinkEntryType {
MemInfo = 1,
Needed = 2,
};

enum class SymbolType {
Function = 0,
Data = 1,
Expand Down
37 changes: 37 additions & 0 deletions test/binary/dylink0-section.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
;;; TOOL: run-objdump-gen-wasm
;;; ARGS: -x
magic
version
section("dylink.0") {
section(DYLINK_MEM_INFO) {
mem_size[5]
mem_align[1]
table_size[3]
table_align[2]
}

section(DYLINK_NEEDED) {
needed_count[2]
str("libfoo.so")
str("libbar.so")
}
}
(;; STDOUT ;;;

dylink0-section.wasm: file format wasm 0x1

Section Details:

Custom:
- name: "dylink.0"
- mem_size : 5
- mem_p2align : 1
- table_size : 3
- table_p2align: 2
- needed_dynlibs[2]:
- libfoo.so
- libbar.so

Code Disassembly:

;;; STDOUT ;;)
4 changes: 4 additions & 0 deletions test/gen-wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
'LINKING_COMDAT_INFO': 7,
'LINKING_SYMBOL_TABLE': 8,

# dylink.0 subsection codes
'DYLINK_MEM_INFO': 1,
'DYLINK_NEEDED': 2,

# external kinds
'func_kind': 0,
'table_kind': 1,
Expand Down