Skip to content

[lld][WebAssembly] Add RUNTIME_PATH support to wasm-ld #129050

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 3 commits into from
Feb 28, 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
14 changes: 14 additions & 0 deletions lld/test/wasm/rpath.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld -shared -o %t1.wasm %t.o -rpath /a/b/c -rpath /x/y/z --experimental-pic
# RUN: obj2yaml %t1.wasm | FileCheck %s

# CHECK: - Type: CUSTOM
# CHECK-NEXT: Name: dylink.0
# CHECK-NEXT: MemorySize: 0
# CHECK-NEXT: MemoryAlignment: 0
# CHECK-NEXT: TableSize: 0
# CHECK-NEXT: TableAlignment: 0
# CHECK-NEXT: Needed: []
# CHECK-NEXT: RuntimePath:
# CHECK-NEXT: - '/a/b/c'
# CHECK-NEXT: - '/x/y/z'
1 change: 1 addition & 0 deletions lld/wasm/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct Config {
llvm::StringSet<> exportedSymbols;
std::vector<llvm::StringRef> requiredExports;
llvm::SmallVector<llvm::StringRef, 0> searchPaths;
llvm::SmallVector<llvm::StringRef, 0> rpath;
llvm::CachePruningPolicy thinLTOCachePolicy;
std::optional<std::vector<std::string>> features;
std::optional<std::vector<std::string>> extraFeatures;
Expand Down
1 change: 1 addition & 0 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ static void readConfigs(opt::InputArgList &args) {
ctx.arg.optimize = args::getInteger(args, OPT_O, 1);
ctx.arg.outputFile = args.getLastArgValue(OPT_o);
ctx.arg.relocatable = args.hasArg(OPT_relocatable);
ctx.arg.rpath = args::getStrings(args, OPT_rpath);
ctx.arg.gcSections =
args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !ctx.arg.relocatable);
for (auto *arg : args.filtered(OPT_keep_section))
Expand Down
2 changes: 2 additions & 0 deletions lld/wasm/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;

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

defm rpath: Eq<"rpath", "Add a DT_RUNPATH to the output">;

defm rsp_quoting: Eq<"rsp-quoting", "Quoting style for response files">,
MetaVarName<"[posix,windows]">;

Expand Down
9 changes: 9 additions & 0 deletions lld/wasm/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "InputElement.h"
#include "OutputSegment.h"
#include "SymbolTable.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Support/Path.h"
#include <optional>

Expand Down Expand Up @@ -133,6 +134,14 @@ void DylinkSection::writeBody() {

sub.writeTo(os);
}

if (!ctx.arg.rpath.empty()) {
SubSection sub(WASM_DYLINK_RUNTIME_PATH);
writeUleb128(sub.os, ctx.arg.rpath.size(), "num rpath entries");
for (const auto ref : ctx.arg.rpath)
writeStr(sub.os, ref, "rpath entry");
sub.writeTo(os);
}
}

uint32_t TypeSection::registerType(const WasmSignature &sig) {
Expand Down