Skip to content

[object][WebAssembly] Add support for RUNTIME_PATH to yaml2obj and obj2yaml #126080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,6 +295,7 @@ struct WasmDylinkInfo {
std::vector<StringRef> Needed; // Shared library dependencies
std::vector<WasmDylinkImportInfo> ImportInfo;
std::vector<WasmDylinkExportInfo> ExportInfo;
std::vector<StringRef> RuntimePath;
};

struct WasmProducerInfo {
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/ObjectYAML/WasmYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct DylinkSection : CustomSection {
std::vector<StringRef> Needed;
std::vector<DylinkImportInfo> ImportInfo;
std::vector<DylinkExportInfo> ExportInfo;
std::vector<StringRef> RuntimePath;
};

struct NameSection : CustomSection {
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Object/WasmObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/ObjectYAML/WasmEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/ObjectYAML/WasmYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/ObjectYAML/wasm/dylink_section.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Sections:
TableSize: 1
TableAlignment: 0
Needed: [ libfoo.so, libbar.so ]
RuntimePath: [ $ORIGIN/../lib, $ORIGIN/../../.libs]
...
# CHECK: --- !WASM
# CHECK: FileHeader:
Expand All @@ -25,4 +26,7 @@ Sections:
# CHECK: Needed:
# CHECK: - libfoo.so
# CHECK: - libbar.so
# CHECK: RuntimePath:
# CHECK: - '$ORIGIN/../lib'
# CHECK: - '$ORIGIN/../../.libs'
# CHECK: ...
1 change: 1 addition & 0 deletions llvm/tools/obj2yaml/wasm2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down