From c5119b05ac8e0c9c9c85bf3e746af9d9d364080c Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 6 Feb 2025 16:06:37 +0100 Subject: [PATCH 1/2] [object][webassembly] Add support for RUNTIME_PATH to yaml2obj and obj2yaml --- llvm/include/llvm/BinaryFormat/Wasm.h | 2 ++ llvm/include/llvm/ObjectYAML/WasmYAML.h | 1 + llvm/lib/Object/WasmObjectFile.cpp | 4 ++++ llvm/lib/ObjectYAML/WasmEmitter.cpp | 6 ++++++ llvm/lib/ObjectYAML/WasmYAML.cpp | 1 + llvm/test/ObjectYAML/wasm/dylink_section.yaml | 2 ++ llvm/tools/obj2yaml/wasm2yaml.cpp | 1 + 7 files changed, 17 insertions(+) diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index ede2d692a5949..00782f53a8e13 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; + StringRef RuntimePath; }; struct WasmProducerInfo { diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h index 94ecc2fcfdb53..2285dd6564768 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; + StringRef RuntimePath; }; struct NameSection : CustomSection { diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 0f6fd5612f9d8..5c6b97e0acc8c 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -484,6 +484,10 @@ Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) { } break; } + case wasm::WASM_DYLINK_RUNTIME_PATH: { + DylinkInfo.RuntimePath = 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..c8c829ca73490 100644 --- a/llvm/lib/ObjectYAML/WasmEmitter.cpp +++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -180,6 +180,12 @@ 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(); + writeStringRef(Section.RuntimePath, 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..cdc094efc3456 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,5 @@ Sections: # CHECK: Needed: # CHECK: - libfoo.so # CHECK: - libbar.so +# CHECK: RuntimePath: '$ORIGIN/../lib:$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) From 8948673aa57a4809e112212a13ecb684d429ae47 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 6 Feb 2025 17:37:26 +0100 Subject: [PATCH 2/2] Switch RPATH from single string to vector of strings --- llvm/include/llvm/BinaryFormat/Wasm.h | 2 +- llvm/include/llvm/ObjectYAML/WasmYAML.h | 2 +- llvm/lib/Object/WasmObjectFile.cpp | 5 ++++- llvm/lib/ObjectYAML/WasmEmitter.cpp | 4 +++- llvm/test/ObjectYAML/wasm/dylink_section.yaml | 6 ++++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index 00782f53a8e13..de47d6c21d0ba 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -295,7 +295,7 @@ struct WasmDylinkInfo { std::vector Needed; // Shared library dependencies std::vector ImportInfo; std::vector ExportInfo; - StringRef RuntimePath; + std::vector RuntimePath; }; struct WasmProducerInfo { diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h index 2285dd6564768..fdcd8a280ee22 100644 --- a/llvm/include/llvm/ObjectYAML/WasmYAML.h +++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h @@ -230,7 +230,7 @@ struct DylinkSection : CustomSection { std::vector Needed; std::vector ImportInfo; std::vector ExportInfo; - StringRef RuntimePath; + std::vector RuntimePath; }; struct NameSection : CustomSection { diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 5c6b97e0acc8c..98c4b9d05a5e0 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -485,7 +485,10 @@ Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) { break; } case wasm::WASM_DYLINK_RUNTIME_PATH: { - DylinkInfo.RuntimePath = readString(Ctx); + Count = readVaruint32(Ctx); + while (Count--) { + DylinkInfo.RuntimePath.push_back(readString(Ctx)); + } break; } default: diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp index c8c829ca73490..9052b4342c8c2 100644 --- a/llvm/lib/ObjectYAML/WasmEmitter.cpp +++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -183,7 +183,9 @@ void WasmWriter::writeSectionContent(raw_ostream &OS, if (Section.RuntimePath.size()) { writeUint8(OS, wasm::WASM_DYLINK_RUNTIME_PATH); raw_ostream &SubOS = SubSection.getStream(); - writeStringRef(Section.RuntimePath, SubOS); + encodeULEB128(Section.RuntimePath.size(), SubOS); + for (StringRef Path : Section.RuntimePath) + writeStringRef(Path, SubOS); SubSection.done(); } } diff --git a/llvm/test/ObjectYAML/wasm/dylink_section.yaml b/llvm/test/ObjectYAML/wasm/dylink_section.yaml index cdc094efc3456..fa8d1d67bb397 100644 --- a/llvm/test/ObjectYAML/wasm/dylink_section.yaml +++ b/llvm/test/ObjectYAML/wasm/dylink_section.yaml @@ -11,7 +11,7 @@ Sections: TableSize: 1 TableAlignment: 0 Needed: [ libfoo.so, libbar.so ] - RuntimePath: $ORIGIN/../lib:$ORIGIN/../../.libs + RuntimePath: [ $ORIGIN/../lib, $ORIGIN/../../.libs] ... # CHECK: --- !WASM # CHECK: FileHeader: @@ -26,5 +26,7 @@ Sections: # CHECK: Needed: # CHECK: - libfoo.so # CHECK: - libbar.so -# CHECK: RuntimePath: '$ORIGIN/../lib:$ORIGIN/../../.libs' +# CHECK: RuntimePath: +# CHECK: - '$ORIGIN/../lib' +# CHECK: - '$ORIGIN/../../.libs' # CHECK: ...