const char WasmMagic[] = {'\0', 'a', 's', 'm'};
// Wasm binary format version
const uint32_t WasmVersion = 0x1;
+// Wasm linking metadata version
+const uint32_t WasmMetadataVersion = 0x1;
// Wasm uses a 64k page size
const uint32_t WasmPageSize = 65536;
};
struct WasmLinkingData {
+ uint32_t Version;
std::vector<WasmInitFunc> InitFunctions;
std::vector<StringRef> Comdats;
std::vector<WasmSymbolInfo> SymbolTable;
return C && C->Name == "linking";
}
+ uint32_t Version;
std::vector<SymbolInfo> SymbolTable;
std::vector<SegmentInfo> SegmentInfos;
std::vector<InitFunction> InitFunctions;
const std::map<StringRef, std::vector<WasmComdatEntry>> &Comdats) {
SectionBookkeeping Section;
startCustomSection(Section, "linking");
- SectionBookkeeping SubSection;
+ encodeULEB128(wasm::WasmMetadataVersion, getStream());
+ SectionBookkeeping SubSection;
if (SymbolInfos.size() != 0) {
startSection(SubSection, wasm::WASM_SYMBOL_TABLE);
encodeULEB128(SymbolInfos.size(), getStream());
"Linking data must come after code section", object_error::parse_failed);
}
+ LinkingData.Version = readVaruint32(Ptr);
+ if (LinkingData.Version != wasm::WasmMetadataVersion) {
+ return make_error<GenericBinaryError>(
+ "Unexpected metadata version: " + Twine(LinkingData.Version) +
+ " (Expected: " + Twine(wasm::WasmMetadataVersion) + ")",
+ object_error::parse_failed);
+ }
+
while (Ptr < End) {
uint8_t Type = readUint8(Ptr);
uint32_t Size = readVaruint32(Ptr);
static void sectionMapping(IO &IO, WasmYAML::LinkingSection &Section) {
commonSectionMapping(IO, Section);
IO.mapRequired("Name", Section.Name);
+ IO.mapRequired("Version", Section.Version);
IO.mapOptional("SymbolTable", Section.SymbolTable);
IO.mapOptional("SegmentInfo", Section.SegmentInfos);
IO.mapOptional("InitFunctions", Section.InitFunctions);
; CHECK: - Type: DATA
; CHECK: Content: '0102'
-; CHECK: - Type: CUSTOM
-; CHECK-NEXT: Name: linking
-; CHECK-NEXT: SymbolTable:
+; CHECK: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: DATA
; CHECK-NEXT: Name: gBd
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 8
; CHECK-NEXT: Content: ''
-; CHECK-NEXT: - Type: CUSTOM
-; CHECK-NEXT: Name: linking
-; CHECK-NEXT: SymbolTable:
+
+; CHECK: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: DATA
; CHECK-NEXT: Name: g0
; CHECK-NEXT: Content: '616263'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 1
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 24
; CHECK-NEXT: Content: '08000000'
-; CHECK-NEXT: - Type: CUSTOM
-; CHECK-NEXT: Name: linking
-; CHECK-NEXT: SymbolTable:
+
+; CHECK: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: DATA
; CHECK-NEXT: Name: global0
; CHECK-NEXT: Content: '01040000'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 1
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Content: '06000000'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 1
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: DATA
ret void
}
-; CHECK: - Type: CUSTOM
-; CHECK-NEXT: Name: linking
-; CHECK-NEXT: SymbolTable:
+; CHECK: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Name: defaultVis
; CHECK-NEXT: Content: '01000000'
; CHECK-NEXT: - Type: CUSTOM
; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 1
; CHECK-NEXT: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Field: __indirect_function_table
-; CHECK: - Type: CUSTOM
-; CHECK-NEXT: Name: linking
-; CHECK-NEXT: SymbolTable:
+; CHECK: SymbolTable:
; CHECK-NEXT: - Index: 0
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Name: weak_function
WASM-NEXT: Version: 0x00000001
WASM: - Type: CUSTOM
WASM-NEXT: Name: linking
+WASM-NEXT: Version: 1
WASM-NEXT: SymbolTable:
WASM-NEXT: - Index: 0
WASM-NEXT: Kind: FUNCTION
--- /dev/null
+# RUN: yaml2obj %s | not llvm-objdump -h - 2>&1 | FileCheck %s
+
+!WASM
+FileHeader:
+ Version: 0x00000001
+Sections:
+ - Type: CUSTOM
+ Name: linking
+ Version: 0
+
+# CHECK: {{.*}}: Unexpected metadata version: 0 (Expected: 1)
Body: 108180808000210020000F0B
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: FUNCTION
Addend: -6
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: DATA
GlobalMutable: false
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: GLOBAL
Content: '11110000'
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: FUNCTION
- Priority: 1
Symbol: 0
...
-# CHECK: - Type: CUSTOM
-# CHECK-NEXT: Name: linking
-# CHECK-NEXT: SymbolTable:
+# CHECK: SymbolTable:
# CHECK-NEXT: - Index: 0
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: Name: bar
Body: 00
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: FUNCTION
Content: '616263'
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: FUNCTION
GlobalMutable: false
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: FUNCTION
Content: '616263'
- Type: CUSTOM
Name: linking
+ Version: 1
SymbolTable:
- Index: 0
Kind: DATA
# CHECK-NEXT: 2 FUNCTION 00000002 0000000000000000
# CHECK-NEXT: 3 CODE 00000019 0000000000000000 TEXT
# CHECK-NEXT: 4 DATA 0000001c 0000000000000000 DATA
-# CHECK-NEXT: 5 linking 0000004d 0000000000000000
+# CHECK-NEXT: 5 linking 00000051 0000000000000000
# CHECK-NEXT: 6 reloc.CODE 0000000c 0000000000000000
# RUN: llvm-objdump -p %p/Inputs/trivial.obj.wasm | FileCheck %s -check-prefix CHECK-HEADER
WASM-NEXT: }
WASM-NEXT: Section {
WASM-NEXT: Type: CUSTOM (0x0)
-WASM-NEXT: Size: 57
+WASM-NEXT: Size: 61
WASM-NEXT: Offset: 191
WASM-NEXT: Name: linking
WASM-NEXT: }
WASM-NEXT: Section {
WASM-NEXT: Type: CUSTOM (0x0)
WASM-NEXT: Size: 12
-WASM-NEXT: Offset: 262
+WASM-NEXT: Offset: 266
WASM-NEXT: Name: reloc.CODE
WASM-NEXT: }
WASM-NEXT: ]
CustomSec = std::move(NameSec);
} else if (WasmSec.Name == "linking") {
std::unique_ptr<WasmYAML::LinkingSection> LinkingSec = make_unique<WasmYAML::LinkingSection>();
+ LinkingSec->Version = Obj.linkingData().Version;
+
ArrayRef<StringRef> Comdats = Obj.linkingData().Comdats;
for (StringRef ComdatName : Comdats)
LinkingSec->Comdats.emplace_back(WasmYAML::Comdat{ComdatName, {}});
WasmYAML::ComdatEntry{wasm::WASM_COMDAT_FUNCTION, Func.Index});
}
}
+
uint32_t SegmentIndex = 0;
for (const object::WasmSegment &Segment : Obj.dataSegments()) {
if (!Segment.Data.Name.empty()) {
}
SegmentIndex++;
}
+
uint32_t SymbolIndex = 0;
for (const wasm::WasmSymbolInfo &Symbol : Obj.linkingData().SymbolTable) {
WasmYAML::SymbolInfo Info;
}
LinkingSec->SymbolTable.emplace_back(Info);
}
+
for (const wasm::WasmInitFunc &Func : Obj.linkingData().InitFunctions) {
WasmYAML::InitFunction F{Func.Priority, Func.Symbol};
LinkingSec->InitFunctions.emplace_back(F);
}
+
CustomSec = std::move(LinkingSec);
} else {
CustomSec = make_unique<WasmYAML::CustomSection>(WasmSec.Name);
int WasmWriter::writeSectionContent(raw_ostream &OS, WasmYAML::LinkingSection &Section) {
writeStringRef(Section.Name, OS);
+ encodeULEB128(Section.Version, OS);
SubSectionWriter SubSection(OS);