diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index ede2d692a5949..de47d6c21d0ba 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -201,6 +201,7 @@ enum : unsigned { WASM_DYLINK_NEEDED = 0x2, WASM_DYLINK_EXPORT_INFO = 0x3, WASM_DYLINK_IMPORT_INFO = 0x4, + WASM_DYLINK_RUNTIME_PATH = 0x5, }; // Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO @@ -294,6 +295,7 @@ struct WasmDylinkInfo { std::vector Needed; // Shared library dependencies std::vector ImportInfo; std::vector ExportInfo; + std::vector RuntimePath; }; struct WasmProducerInfo { diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h index 94ecc2fcfdb53..fdcd8a280ee22 100644 --- a/llvm/include/llvm/ObjectYAML/WasmYAML.h +++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h @@ -230,6 +230,7 @@ struct DylinkSection : CustomSection { std::vector Needed; std::vector ImportInfo; std::vector ExportInfo; + std::vector RuntimePath; }; struct NameSection : CustomSection { diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 0f6fd5612f9d8..98c4b9d05a5e0 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -484,6 +484,13 @@ Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) { } break; } + case wasm::WASM_DYLINK_RUNTIME_PATH: { + Count = readVaruint32(Ctx); + while (Count--) { + DylinkInfo.RuntimePath.push_back(readString(Ctx)); + } + break; + } default: LLVM_DEBUG(dbgs() << "unknown dylink.0 sub-section: " << Type << "\n"); Ctx.Ptr += Size; diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp index bd016764f5862..9052b4342c8c2 100644 --- a/llvm/lib/ObjectYAML/WasmEmitter.cpp +++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -180,6 +180,14 @@ void WasmWriter::writeSectionContent(raw_ostream &OS, writeStringRef(Needed, SubOS); SubSection.done(); } + if (Section.RuntimePath.size()) { + writeUint8(OS, wasm::WASM_DYLINK_RUNTIME_PATH); + raw_ostream &SubOS = SubSection.getStream(); + encodeULEB128(Section.RuntimePath.size(), SubOS); + for (StringRef Path : Section.RuntimePath) + writeStringRef(Path, SubOS); + SubSection.done(); + } } void WasmWriter::writeSectionContent(raw_ostream &OS, diff --git a/llvm/lib/ObjectYAML/WasmYAML.cpp b/llvm/lib/ObjectYAML/WasmYAML.cpp index 6af66ba62be18..d9e93d06dcf27 100644 --- a/llvm/lib/ObjectYAML/WasmYAML.cpp +++ b/llvm/lib/ObjectYAML/WasmYAML.cpp @@ -59,6 +59,7 @@ static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) { IO.mapRequired("Needed", Section.Needed); IO.mapOptional("ImportInfo", Section.ImportInfo); IO.mapOptional("ExportInfo", Section.ExportInfo); + IO.mapOptional("RuntimePath", Section.RuntimePath); } static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) { diff --git a/llvm/test/ObjectYAML/wasm/dylink_section.yaml b/llvm/test/ObjectYAML/wasm/dylink_section.yaml index a43f678c45194..fa8d1d67bb397 100644 --- a/llvm/test/ObjectYAML/wasm/dylink_section.yaml +++ b/llvm/test/ObjectYAML/wasm/dylink_section.yaml @@ -11,6 +11,7 @@ Sections: TableSize: 1 TableAlignment: 0 Needed: [ libfoo.so, libbar.so ] + RuntimePath: [ $ORIGIN/../lib, $ORIGIN/../../.libs] ... # CHECK: --- !WASM # CHECK: FileHeader: @@ -25,4 +26,7 @@ Sections: # CHECK: Needed: # CHECK: - libfoo.so # CHECK: - libbar.so +# CHECK: RuntimePath: +# CHECK: - '$ORIGIN/../lib' +# CHECK: - '$ORIGIN/../../.libs' # CHECK: ... diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp index 9aa7f5abe8dd4..5a9d9a88da227 100644 --- a/llvm/tools/obj2yaml/wasm2yaml.cpp +++ b/llvm/tools/obj2yaml/wasm2yaml.cpp @@ -61,6 +61,7 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) { DylinkSec->TableSize = Info.TableSize; DylinkSec->TableAlignment = Info.TableAlignment; DylinkSec->Needed = Info.Needed; + DylinkSec->RuntimePath = Info.RuntimePath; for (const auto &Imp : Info.ImportInfo) DylinkSec->ImportInfo.push_back({Imp.Module, Imp.Field, Imp.Flags}); for (const auto &Exp : Info.ExportInfo)