Skip to content

Commit ffa02c2

Browse files
hoodmanegithub-actions[bot]
authored andcommitted
Automerge: [lld][WebAssembly] Add RUNTIME_PATH support to wasm-ld (#129050)
This finishes adding RPATH support for WebAssembly. See my previous PR which added RPATH support to yaml2obj and obj2yaml: llvm/llvm-project#126080 See corresponding update to the WebAssembly/tool-conventions repo on dynamic linking: WebAssembly/tool-conventions#246
2 parents e22ac1e + 80ea31c commit ffa02c2

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

Diff for: lld/test/wasm/rpath.s

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
2+
# RUN: wasm-ld -shared -o %t1.wasm %t.o -rpath /a/b/c -rpath /x/y/z --experimental-pic
3+
# RUN: obj2yaml %t1.wasm | FileCheck %s
4+
5+
# CHECK: - Type: CUSTOM
6+
# CHECK-NEXT: Name: dylink.0
7+
# CHECK-NEXT: MemorySize: 0
8+
# CHECK-NEXT: MemoryAlignment: 0
9+
# CHECK-NEXT: TableSize: 0
10+
# CHECK-NEXT: TableAlignment: 0
11+
# CHECK-NEXT: Needed: []
12+
# CHECK-NEXT: RuntimePath:
13+
# CHECK-NEXT: - '/a/b/c'
14+
# CHECK-NEXT: - '/x/y/z'

Diff for: lld/wasm/Config.h

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct Config {
120120
llvm::StringSet<> exportedSymbols;
121121
std::vector<llvm::StringRef> requiredExports;
122122
llvm::SmallVector<llvm::StringRef, 0> searchPaths;
123+
llvm::SmallVector<llvm::StringRef, 0> rpath;
123124
llvm::CachePruningPolicy thinLTOCachePolicy;
124125
std::optional<std::vector<std::string>> features;
125126
std::optional<std::vector<std::string>> extraFeatures;

Diff for: lld/wasm/Driver.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ static void readConfigs(opt::InputArgList &args) {
583583
ctx.arg.optimize = args::getInteger(args, OPT_O, 1);
584584
ctx.arg.outputFile = args.getLastArgValue(OPT_o);
585585
ctx.arg.relocatable = args.hasArg(OPT_relocatable);
586+
ctx.arg.rpath = args::getStrings(args, OPT_rpath);
586587
ctx.arg.gcSections =
587588
args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !ctx.arg.relocatable);
588589
for (auto *arg : args.filtered(OPT_keep_section))

Diff for: lld/wasm/Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
132132

133133
defm reproduce: EEq<"reproduce", "Dump linker invocation and input files for debugging">;
134134

135+
defm rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">;
136+
135137
defm rsp_quoting: Eq<"rsp-quoting", "Quoting style for response files">,
136138
MetaVarName<"[posix,windows]">;
137139

Diff for: lld/wasm/SyntheticSections.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "InputElement.h"
1717
#include "OutputSegment.h"
1818
#include "SymbolTable.h"
19+
#include "llvm/BinaryFormat/Wasm.h"
1920
#include "llvm/Support/Path.h"
2021
#include <optional>
2122

@@ -133,6 +134,14 @@ void DylinkSection::writeBody() {
133134

134135
sub.writeTo(os);
135136
}
137+
138+
if (!ctx.arg.rpath.empty()) {
139+
SubSection sub(WASM_DYLINK_RUNTIME_PATH);
140+
writeUleb128(sub.os, ctx.arg.rpath.size(), "num rpath entries");
141+
for (const auto ref : ctx.arg.rpath)
142+
writeStr(sub.os, ref, "rpath entry");
143+
sub.writeTo(os);
144+
}
136145
}
137146

138147
uint32_t TypeSection::registerType(const WasmSignature &sig) {

0 commit comments

Comments
 (0)