Skip to content

Commit e869381

Browse files
committed
Support new dylink cusomt section format
This section is now based on sub-sections making it more extensible. (Also remove unused OnSymbol callback).
1 parent 5b6070d commit e869381

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

src/binary-reader.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class BinaryReader {
131131
Result ReadNameSection(Offset section_size) WABT_WARN_UNUSED;
132132
Result ReadRelocSection(Offset section_size) WABT_WARN_UNUSED;
133133
Result ReadDylinkSection(Offset section_size) WABT_WARN_UNUSED;
134+
Result ReadDylink0Section(Offset section_size) WABT_WARN_UNUSED;
134135
Result ReadLinkingSection(Offset section_size) WABT_WARN_UNUSED;
135136
Result ReadCustomSection(Index section_index,
136137
Offset section_size) WABT_WARN_UNUSED;
@@ -1954,6 +1955,59 @@ Result BinaryReader::ReadRelocSection(Offset section_size) {
19541955
return Result::Ok;
19551956
}
19561957

1958+
Result BinaryReader::ReadDylink0Section(Offset section_size) {
1959+
CALLBACK(BeginDylinkSection, section_size);
1960+
1961+
while (state_.offset < read_end_) {
1962+
uint32_t dylink_type;
1963+
Offset subsection_size;
1964+
CHECK_RESULT(ReadU32Leb128(&dylink_type, "type"));
1965+
CHECK_RESULT(ReadOffset(&subsection_size, "subsection size"));
1966+
size_t subsection_end = state_.offset + subsection_size;
1967+
ERROR_UNLESS(subsection_end <= read_end_,
1968+
"invalid sub-section size: extends past end");
1969+
ReadEndRestoreGuard guard(this);
1970+
read_end_ = subsection_end;
1971+
1972+
switch (static_cast<DylinkEntryType>(dylink_type)) {
1973+
case DylinkEntryType::MemInfo: {
1974+
uint32_t mem_size;
1975+
uint32_t mem_align;
1976+
uint32_t table_size;
1977+
uint32_t table_align;
1978+
1979+
CHECK_RESULT(ReadU32Leb128(&mem_size, "mem_size"));
1980+
CHECK_RESULT(ReadU32Leb128(&mem_align, "mem_align"));
1981+
CHECK_RESULT(ReadU32Leb128(&table_size, "table_size"));
1982+
CHECK_RESULT(ReadU32Leb128(&table_align, "table_align"));
1983+
CALLBACK(OnDylinkInfo, mem_size, mem_align, table_size, table_align);
1984+
break;
1985+
}
1986+
case DylinkEntryType::Needed: {
1987+
uint32_t count;
1988+
CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs"));
1989+
CALLBACK(OnDylinkNeededCount, count);
1990+
while (count--) {
1991+
string_view so_name;
1992+
CHECK_RESULT(ReadStr(&so_name, "dylib so_name"));
1993+
CALLBACK(OnDylinkNeeded, so_name);
1994+
}
1995+
break;
1996+
}
1997+
default:
1998+
// Unknown subsection, skip it.
1999+
state_.offset = subsection_end;
2000+
break;
2001+
}
2002+
ERROR_UNLESS(state_.offset == subsection_end,
2003+
"unfinished sub-section (expected end: 0x%" PRIzx ")",
2004+
subsection_end);
2005+
}
2006+
2007+
CALLBACK0(EndDylinkSection);
2008+
return Result::Ok;
2009+
}
2010+
19572011
Result BinaryReader::ReadDylinkSection(Offset section_size) {
19582012
CALLBACK(BeginDylinkSection, section_size);
19592013
uint32_t mem_size;
@@ -2153,6 +2207,8 @@ Result BinaryReader::ReadCustomSection(Index section_index,
21532207
if (options_.read_debug_names && section_name == WABT_BINARY_SECTION_NAME) {
21542208
CHECK_RESULT(ReadNameSection(section_size));
21552209
did_read_names_section_ = true;
2210+
} else if (section_name == WABT_BINARY_SECTION_DYLINK0) {
2211+
CHECK_RESULT(ReadDylink0Section(section_size));
21562212
} else if (section_name == WABT_BINARY_SECTION_DYLINK) {
21572213
CHECK_RESULT(ReadDylinkSection(section_size));
21582214
} else if (section_name.rfind(WABT_BINARY_SECTION_RELOC, 0) == 0) {

src/binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define WABT_BINARY_SECTION_RELOC "reloc"
3333
#define WABT_BINARY_SECTION_LINKING "linking"
3434
#define WABT_BINARY_SECTION_DYLINK "dylink"
35+
#define WABT_BINARY_SECTION_DYLINK0 "dylink.0"
3536

3637
#define WABT_FOREACH_BINARY_SECTION(V) \
3738
V(Custom, custom, 0) \

src/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ enum class LinkingEntryType {
336336
SymbolTable = 8,
337337
};
338338

339+
enum class DylinkEntryType {
340+
MemInfo = 1,
341+
Needed = 2,
342+
};
343+
339344
enum class SymbolType {
340345
Function = 0,
341346
Data = 1,

test/binary/dylink0-section.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;;; TOOL: run-objdump-gen-wasm
2+
;;; ARGS: -x
3+
magic
4+
version
5+
section("dylink.0") {
6+
section(DYLINK_MEM_INFO) {
7+
mem_size[5]
8+
mem_align[1]
9+
table_size[3]
10+
table_align[2]
11+
}
12+
13+
section(DYLINK_NEEDED) {
14+
needed_count[2]
15+
str("libfoo.so")
16+
str("libbar.so")
17+
}
18+
}
19+
(;; STDOUT ;;;
20+
21+
dylink0-section.wasm: file format wasm 0x1
22+
23+
Section Details:
24+
25+
Custom:
26+
- name: "dylink.0"
27+
- mem_size : 5
28+
- mem_p2align : 1
29+
- table_size : 3
30+
- table_p2align: 2
31+
- needed_dynlibs[2]:
32+
- libfoo.so
33+
- libbar.so
34+
35+
Code Disassembly:
36+
37+
;;; STDOUT ;;)

test/gen-wasm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
'LINKING_COMDAT_INFO': 7,
7878
'LINKING_SYMBOL_TABLE': 8,
7979

80+
# dylink.0 subsection codes
81+
'DYLINK_MEM_INFO': 1,
82+
'DYLINK_NEEDED': 2,
83+
8084
# external kinds
8185
'func_kind': 0,
8286
'table_kind': 1,

0 commit comments

Comments
 (0)