[WebAssembly] Write DWARF data into wasm object file
- Writes ".debug_XXX" into corresponding custom sections.
- Writes relocation records into "reloc.debug_XXX" sections.
Patch by Yury Delendik!
Differential Revision: https://reviews.llvm.org/D44184
llvm-svn: 330982
diff --git a/llvm/tools/llvm-readobj/WasmDumper.cpp b/llvm/tools/llvm-readobj/WasmDumper.cpp
index 3d2f4d4..63ec0b7 100644
--- a/llvm/tools/llvm-readobj/WasmDumper.cpp
+++ b/llvm/tools/llvm-readobj/WasmDumper.cpp
@@ -84,6 +84,8 @@
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
+ case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
+ case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
HasAddend = true;
break;
default:
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index 55fc2bf..dbaf1a2 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -106,6 +106,9 @@
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
Info.ElementIndex = Symbol.ElementIndex;
break;
+ case wasm::WASM_SYMBOL_TYPE_SECTION:
+ Info.ElementIndex = Symbol.ElementIndex;
+ break;
}
LinkingSec->SymbolTable.emplace_back(Info);
}
diff --git a/llvm/tools/yaml2obj/yaml2wasm.cpp b/llvm/tools/yaml2obj/yaml2wasm.cpp
index 9be2f09..9b8770f 100644
--- a/llvm/tools/yaml2obj/yaml2wasm.cpp
+++ b/llvm/tools/yaml2obj/yaml2wasm.cpp
@@ -165,6 +165,9 @@
encodeULEB128(Info.DataRef.Size, SubSection.GetStream());
}
break;
+ case wasm::WASM_SYMBOL_TYPE_SECTION:
+ encodeULEB128(Info.ElementIndex, SubSection.GetStream());
+ break;
default:
llvm_unreachable("unexpected kind");
}
@@ -424,20 +427,28 @@
int WasmWriter::writeRelocSection(raw_ostream &OS, WasmYAML::Section &Sec,
uint32_t SectionIndex) {
- StringRef Name;
switch (Sec.Type) {
case wasm::WASM_SEC_CODE:
- Name = "reloc.CODE";
+ writeStringRef("reloc.CODE", OS);
break;
case wasm::WASM_SEC_DATA:
- Name = "reloc.DATA";
+ writeStringRef("reloc.DATA", OS);
break;
+ case wasm::WASM_SEC_CUSTOM: {
+ auto CustomSection = dyn_cast<WasmYAML::CustomSection>(&Sec);
+ if (!CustomSection->Name.startswith(".debug_")) {
+ llvm_unreachable("not yet implemented (only for debug sections)");
+ return 1;
+ }
+
+ writeStringRef(("reloc." + CustomSection->Name).str(), OS);
+ break;
+ }
default:
llvm_unreachable("not yet implemented");
return 1;
}
- writeStringRef(Name, OS);
encodeULEB128(SectionIndex, OS);
encodeULEB128(Sec.Relocations.size(), OS);
@@ -449,6 +460,8 @@
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_LEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
case wasm::R_WEBASSEMBLY_MEMORY_ADDR_I32:
+ case wasm::R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
+ case wasm::R_WEBASSEMBLY_SECTION_OFFSET_I32:
encodeULEB128(Reloc.Addend, OS);
}
}