Skip to content

Commit 3c28a6d

Browse files
committed
[lld][WebAssembly] Add support for LLD_REPRODUCE
This is feature of the ELF and COFF linker that we were missing until now. Differential Revision: https://reviews.llvm.org/D137377
1 parent c072586 commit 3c28a6d

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

lld/test/wasm/reproduce.ll

Lines changed: 0 additions & 27 deletions
This file was deleted.

lld/test/wasm/reproduce.s

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# REQUIRES: shell
2+
# RUN: rm -rf %t.dir
3+
# RUN: mkdir -p %t.dir
4+
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.dir/foo.o %s
5+
# RUN: wasm-ld --reproduce=%t.dir/repro.tar -o %t.dir/out.wasm %t.dir/foo.o
6+
# RUN: env LLD_REPRODUCE=%t.dir/repro2.tar wasm-ld -o %t.dir/out.wasm %t.dir/foo.o
7+
8+
# RUN: cd %t.dir
9+
# RUN: tar tf repro.tar | FileCheck --check-prefix=TAR %s
10+
# RUN: tar tf repro2.tar | FileCheck --check-prefix=TAR2 %s
11+
12+
# TAR: repro/response.txt
13+
# TAR: repro/version.txt
14+
# TAR: repro/{{.*}}/foo.o
15+
16+
# TAR2: repro2/response.txt
17+
# TAR2: repro2/version.txt
18+
# TAR2: repro2/{{.*}}/foo.o
19+
20+
# RUN: tar xf repro.tar
21+
# RUN: FileCheck --check-prefix=RSP %s < repro/response.txt
22+
23+
# RSP: -o {{.*}}out.wasm
24+
# RSP: {{.*}}/foo.o
25+
26+
# RUN: FileCheck %s --check-prefix=VERSION < repro/version.txt
27+
# VERSION: LLD
28+
29+
.globl _start
30+
_start:
31+
.functype _start () -> ()
32+
end_function

lld/wasm/Driver.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ static void checkOptions(opt::InputArgList &args) {
618618
}
619619
}
620620

621+
static const char *getReproduceOption(opt::InputArgList &args) {
622+
if (auto *arg = args.getLastArg(OPT_reproduce))
623+
return arg->getValue();
624+
return getenv("LLD_REPRODUCE");
625+
}
626+
621627
// Force Sym to be entered in the output. Used for -u or equivalent.
622628
static Symbol *handleUndefined(StringRef name) {
623629
Symbol *sym = symtab->find(name);
@@ -955,8 +961,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
955961
}
956962

957963
// Handle --reproduce
958-
if (auto *arg = args.getLastArg(OPT_reproduce)) {
959-
StringRef path = arg->getValue();
964+
if (const char *path = getReproduceOption(args)) {
960965
Expected<std::unique_ptr<TarWriter>> errOrWriter =
961966
TarWriter::create(path, path::stem(path));
962967
if (errOrWriter) {

0 commit comments

Comments
 (0)