Skip to content

[lld/COFF] Handle -start-lib / -end-lib better in /reproduce: output #119752

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
Dec 17, 2024
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
19 changes: 9 additions & 10 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
StringRef filename = mb->getBufferIdentifier();

MemoryBufferRef mbref = takeBuffer(std::move(mb));
filePaths.push_back(filename);

// File type is detected by contents, not by file extension.
switch (identify_magic(mbref.getBuffer())) {
Expand Down Expand Up @@ -857,7 +856,6 @@ static std::string rewritePath(StringRef s) {
// Reconstructs command line arguments so that so that you can re-run
// the same command with the same inputs. This is for --reproduce.
static std::string createResponseFile(const opt::InputArgList &args,
ArrayRef<StringRef> filePaths,
ArrayRef<StringRef> searchPaths) {
SmallString<0> data;
raw_svector_ostream os(data);
Expand All @@ -866,11 +864,15 @@ static std::string createResponseFile(const opt::InputArgList &args,
switch (arg->getOption().getID()) {
case OPT_linkrepro:
case OPT_reproduce:
case OPT_INPUT:
case OPT_defaultlib:
case OPT_libpath:
case OPT_winsysroot:
break;
case OPT_INPUT:
os << quote(rewritePath(arg->getValue())) << "\n";
break;
case OPT_wholearchive_file:
os << arg->getSpelling() << quote(rewritePath(arg->getValue())) << "\n";
break;
case OPT_call_graph_ordering_file:
case OPT_deffile:
case OPT_manifestinput:
Expand Down Expand Up @@ -907,9 +909,6 @@ static std::string createResponseFile(const opt::InputArgList &args,
os << "/libpath:" << quote(relPath) << "\n";
}

for (StringRef path : filePaths)
os << quote(relativeToRoot(path)) << "\n";

return std::string(data);
}

Expand Down Expand Up @@ -2347,9 +2346,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {

if (tar) {
llvm::TimeTraceScope timeScope("Reproducer: response file");
tar->append("response.txt",
createResponseFile(args, filePaths,
ArrayRef<StringRef>(searchPaths).slice(1)));
tar->append(
"response.txt",
createResponseFile(args, ArrayRef<StringRef>(searchPaths).slice(1)));
}

// Handle /largeaddressaware
Expand Down
1 change: 0 additions & 1 deletion lld/COFF/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class LinkerDriver {
bool run();

std::list<std::function<void()>> taskQueue;
std::vector<StringRef> filePaths;
std::vector<MemoryBufferRef> resources;

llvm::DenseSet<StringRef> directivesExports;
Expand Down
107 changes: 102 additions & 5 deletions lld/test/COFF/linkrepro.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# REQUIRES: x86, shell

# RUN: rm -rf %t.dir
# RUN: split-file %s %t.dir

# RUN: yaml2obj %p/Inputs/hello32.yaml -o %t.obj
# RUN: llvm-mc -filetype=obj -triple=i386-windows %t.dir/drectve.s -o %t.dir/drectve.obj
# RUN: echo '_main@0' > %t.order
# RUN: touch %t.def
# RUN: touch %t.cg
Expand Down Expand Up @@ -46,7 +49,7 @@ and various other flags.
# RUN: diff %t.order repro/%:t.order
# RUN: diff %t.def repro/%:t.def
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
# RUN: FileCheck %s --check-prefix=RSP-DEFAULTLIB < repro/response.txt
# RUN: cd repro; lld-link @response.txt

Test adding .lib files with LIB env var to repro archive,
Expand All @@ -61,7 +64,7 @@ and various other flags.
# RUN: diff %t.order repro/%:t.order
# RUN: diff %t.def repro/%:t.def
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
# RUN: FileCheck %s --check-prefix=RSP < repro/response.txt
# RUN: FileCheck %s --check-prefix=RSP-DEFAULTLIB < repro/response.txt
# RUN: cd repro; lld-link @response.txt

# LIST: .obj
Expand All @@ -70,14 +73,21 @@ and various other flags.
# LIST: .def
# LIST: .order

# RSP: linkrepro.test.tmp.obj
# RSP: std32.lib
# RSP: /subsystem:console
# RSP: /entry:main@0
# RSP: /out:
# RSP-NOT: /order:@/
# RSP-NOT: /def:/
# RSP: linkrepro.test.tmp.obj
# RSP-NOT: defaultlib
# RSP: std32.lib

# RSP-DEFAULTLIB: linkrepro.test.tmp.obj
# RSP-DEFAULTLIB: /defaultlib:std32
# RSP-DEFAULTLIB: /subsystem:console
# RSP-DEFAULTLIB: /entry:main@0
# RSP-DEFAULTLIB: /out:
# RSP-DEFAULTLIB-NOT: /order:@/
# RSP-DEFAULTLIB-NOT: /def:/

Test /call-graph-ordering-file (can't be used with /order:, needs separate test)
# RUN: mkdir -p %t.dir/build5
Expand All @@ -96,3 +106,90 @@ Test /call-graph-ordering-file (can't be used with /order:, needs separate test)
# LISTCG: .cg

# RSPCG-NOT: /call-graph-ordering-file:/

Test /defaultlib: from a .drectve section
# RUN: mkdir -p %t.dir/build6
# RUN: cd %t.dir/build6
# RUN: lld-link %t.obj %t.dir/drectve.obj /libpath:%p/Inputs /subsystem:console \
# RUN: /entry:main@0 /linkrepro:. -safeseh:no /out:%t.exe /order:@%t.order /def:%t.def
# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s
# RUN: tar xf repro.tar
# RUN: diff %t.obj repro/%:t.obj
# RUN: diff %t.order repro/%:t.order
# RUN: diff %t.def repro/%:t.def
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
# RUN: FileCheck %s --check-prefix=RSP-DRECTVE < repro/response.txt
# RUN: cd repro; lld-link @response.txt

# RSP-DRECTVE: linkrepro.test.tmp.obj
# RSP-DRECTVE: drectve.obj
# RSP-DRECTVE: /subsystem:console
# RSP-DRECTVE: /entry:main@0
# RSP-DRECTVE: -safeseh:no
# RSP-DRECTVE: /out:

Test /wholearchive: with /linkrepro:
# RUN: llvm-mc -filetype=obj -triple=i386-windows %t.dir/archive.s -o %t.dir/archive.obj
# RUN: rm -f %t.dir/build7/archive.lib
# RUN: llvm-ar rcs %t.dir/archive.lib %t.dir/archive.obj
# RUN: mkdir -p %t.dir/build7
# RUN: cd %t.dir/build7
RUN: lld-link %t.obj /defaultlib:std32 /libpath:%p/Inputs /subsystem:console \
# RUN: /entry:main@0 /linkrepro:. -safeseh:no /wholearchive:%t.dir/archive.lib \
# RUN: /out:%t.exe /order:@%t.order /def:%t.def
# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s
# RUN: tar xf repro.tar
# RUN: diff %t.obj repro/%:t.obj
# RUN: diff %t.order repro/%:t.order
# RUN: diff %t.def repro/%:t.def
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
# RUN: FileCheck %s --check-prefix=RSP-WHOLEARCHIVE < repro/response.txt
# RUN: cd repro; lld-link @response.txt

# RSP-WHOLEARCHIVE: linkrepro.test.tmp.obj
# RSP-WHOLEARCHIVE: /defaultlib:std32
# RSP-WHOLEARCHIVE: /subsystem:console
# RSP-WHOLEARCHIVE: /entry:main@0
# RSP-WHOLEARCHIVE: -safeseh:no
# RSP-WHOLEARCHIVE: /wholearchive:{{.*}}archive.lib
# RSP-WHOLEARCHIVE: /out:

Test /start-lib / /end-lib with /linkrepro:
# RUN: mkdir -p %t.dir/build8
# RUN: cd %t.dir/build8
# RUN: lld-link %t.obj /defaultlib:std32 /libpath:%p/Inputs /subsystem:console \
# RUN: /entry:main@0 /linkrepro:. -safeseh:no /start-lib %t.dir/drectve.obj /end-lib \
# RUN: /out:%t.exe /order:@%t.order /def:%t.def
# RUN: tar tf repro.tar | FileCheck --check-prefix=LIST %s
# RUN: tar xf repro.tar
# RUN: diff %t.obj repro/%:t.obj
# RUN: diff %t.order repro/%:t.order
# RUN: diff %t.def repro/%:t.def
# RUN: diff %p/Inputs/std32.lib repro/%:p/Inputs/std32.lib
# RUN: FileCheck %s --check-prefix=RSP-STARTLIB < repro/response.txt
# RUN: cd repro; lld-link @response.txt

# RSP-STARTLIB: linkrepro.test.tmp.obj
# RSP-STARTLIB: /defaultlib:std32
# RSP-STARTLIB: /subsystem:console
# RSP-STARTLIB: /entry:main@0
# RSP-STARTLIB: -safeseh:no
# RSP-STARTLIB: /start-lib
# RSP-STARTLIB-NEXT: drectve.obj
# RSP-STARTLIB-NEXT: /end-lib
# RSP-STARTLIB: /out:

#--- drectve.s
.section .drectve, "yn"
.ascii "/defaultlib:std32"

#--- archive.s
.text
.intel_syntax noprefix
.globl exportfn3
.p2align 4
exportfn3:
ret

.section .drectve,"yni"
.ascii " /EXPORT:exportfn3"
Loading