Skip to content

Commit cc7f22e

Browse files
authored
[object][WebAssembly] Add support for RUNTIME_PATH to yaml2obj and obj2yaml (#126080)
This is the first step of adding RPATH support for wasm. See corresponding update to the WebAssembly/tool-conventions repo on dynamic linking: WebAssembly/tool-conventions#246
1 parent f1252f5 commit cc7f22e

File tree

7 files changed

+24
-0
lines changed

7 files changed

+24
-0
lines changed

llvm/include/llvm/BinaryFormat/Wasm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ enum : unsigned {
201201
WASM_DYLINK_NEEDED = 0x2,
202202
WASM_DYLINK_EXPORT_INFO = 0x3,
203203
WASM_DYLINK_IMPORT_INFO = 0x4,
204+
WASM_DYLINK_RUNTIME_PATH = 0x5,
204205
};
205206

206207
// Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO
@@ -294,6 +295,7 @@ struct WasmDylinkInfo {
294295
std::vector<StringRef> Needed; // Shared library dependencies
295296
std::vector<WasmDylinkImportInfo> ImportInfo;
296297
std::vector<WasmDylinkExportInfo> ExportInfo;
298+
std::vector<StringRef> RuntimePath;
297299
};
298300

299301
struct WasmProducerInfo {

llvm/include/llvm/ObjectYAML/WasmYAML.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ struct DylinkSection : CustomSection {
230230
std::vector<StringRef> Needed;
231231
std::vector<DylinkImportInfo> ImportInfo;
232232
std::vector<DylinkExportInfo> ExportInfo;
233+
std::vector<StringRef> RuntimePath;
233234
};
234235

235236
struct NameSection : CustomSection {

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,13 @@ Error WasmObjectFile::parseDylink0Section(ReadContext &Ctx) {
484484
}
485485
break;
486486
}
487+
case wasm::WASM_DYLINK_RUNTIME_PATH: {
488+
Count = readVaruint32(Ctx);
489+
while (Count--) {
490+
DylinkInfo.RuntimePath.push_back(readString(Ctx));
491+
}
492+
break;
493+
}
487494
default:
488495
LLVM_DEBUG(dbgs() << "unknown dylink.0 sub-section: " << Type << "\n");
489496
Ctx.Ptr += Size;

llvm/lib/ObjectYAML/WasmEmitter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ void WasmWriter::writeSectionContent(raw_ostream &OS,
180180
writeStringRef(Needed, SubOS);
181181
SubSection.done();
182182
}
183+
if (Section.RuntimePath.size()) {
184+
writeUint8(OS, wasm::WASM_DYLINK_RUNTIME_PATH);
185+
raw_ostream &SubOS = SubSection.getStream();
186+
encodeULEB128(Section.RuntimePath.size(), SubOS);
187+
for (StringRef Path : Section.RuntimePath)
188+
writeStringRef(Path, SubOS);
189+
SubSection.done();
190+
}
183191
}
184192

185193
void WasmWriter::writeSectionContent(raw_ostream &OS,

llvm/lib/ObjectYAML/WasmYAML.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static void sectionMapping(IO &IO, WasmYAML::DylinkSection &Section) {
5959
IO.mapRequired("Needed", Section.Needed);
6060
IO.mapOptional("ImportInfo", Section.ImportInfo);
6161
IO.mapOptional("ExportInfo", Section.ExportInfo);
62+
IO.mapOptional("RuntimePath", Section.RuntimePath);
6263
}
6364

6465
static void sectionMapping(IO &IO, WasmYAML::NameSection &Section) {

llvm/test/ObjectYAML/wasm/dylink_section.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Sections:
1111
TableSize: 1
1212
TableAlignment: 0
1313
Needed: [ libfoo.so, libbar.so ]
14+
RuntimePath: [ $ORIGIN/../lib, $ORIGIN/../../.libs]
1415
...
1516
# CHECK: --- !WASM
1617
# CHECK: FileHeader:
@@ -25,4 +26,7 @@ Sections:
2526
# CHECK: Needed:
2627
# CHECK: - libfoo.so
2728
# CHECK: - libbar.so
29+
# CHECK: RuntimePath:
30+
# CHECK: - '$ORIGIN/../lib'
31+
# CHECK: - '$ORIGIN/../../.libs'
2832
# CHECK: ...

llvm/tools/obj2yaml/wasm2yaml.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
6161
DylinkSec->TableSize = Info.TableSize;
6262
DylinkSec->TableAlignment = Info.TableAlignment;
6363
DylinkSec->Needed = Info.Needed;
64+
DylinkSec->RuntimePath = Info.RuntimePath;
6465
for (const auto &Imp : Info.ImportInfo)
6566
DylinkSec->ImportInfo.push_back({Imp.Module, Imp.Field, Imp.Flags});
6667
for (const auto &Exp : Info.ExportInfo)

0 commit comments

Comments
 (0)