Skip to content
Open
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
11 changes: 8 additions & 3 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2483,10 +2483,14 @@ static void writeDependencyFile(Ctx &ctx) {
// We use the same escape rules as Clang/GCC which are accepted by Make/Ninja:
// * A space is escaped by a backslash which itself must be escaped.
// * A hash sign is escaped by a single backslash.
// * $ is escapes as $$.
// * $ is escaped as $$.
auto printFilename = [](raw_fd_ostream &os, StringRef filename) {
llvm::SmallString<256> nativePath;
#ifdef _WIN32
llvm::sys::path::native(filename.str(), nativePath);
#else
nativePath = filename;
#endif
llvm::sys::path::remove_dots(nativePath, /*remove_dot_dot=*/true);
for (unsigned i = 0, e = nativePath.size(); i != e; ++i) {
if (nativePath[i] == '#') {
Expand All @@ -2503,9 +2507,10 @@ static void writeDependencyFile(Ctx &ctx) {
}
};

os << ctx.arg.outputFile << ":";
printFilename(os, ctx.arg.outputFile);
os << ":";
for (StringRef path : ctx.arg.dependencyFiles) {
os << " \\\n ";
os << " \\\n ";
printFilename(os, path);
}
os << "\n";
Expand Down
13 changes: 13 additions & 0 deletions lld/test/ELF/dependency-file-backslash-as-normal-char.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# REQUIRES: x86, !system-windows
# RUN: mkdir -p %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o "%t/back\\slash.o"
# RUN: ld.lld -o %t/foo.exe "%t/back\\slash.o" --dependency-file=%t/foo.d
# RUN: FileCheck --match-full-lines --strict-whitespace -DFILE=%t %s < %t/foo.d

# CHECK:[[FILE]]/foo.exe: \
# CHECK-NEXT: [[FILE]]/back\slash.o
# CHECK-EMPTY:
# CHECK-NEXT:[[FILE]]/back\slash.o:

.global _start
_start:
13 changes: 13 additions & 0 deletions lld/test/ELF/dependency-file-backslash-as-path-separator.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# REQUIRES: x86, system-windows
# RUN: mkdir -p %t/back
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o "%t/back\\slash.o"
# RUN: ld.lld -o %t/foo.exe "%t/back\\slash.o" --dependency-file=%t/foo.d
# RUN: FileCheck --match-full-lines --strict-whitespace -DFILE=%t %s < %t/foo.d

# CHECK:[[FILE]]\foo.exe: \
# CHECK-NEXT: [[FILE]]\back\slash.o
# CHECK-EMPTY:
# CHECK-NEXT:[[FILE]]\back\slash.o:

.global _start
_start:
16 changes: 8 additions & 8 deletions lld/test/ELF/dependency-file.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o "%t/bar baz.o"
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o "%t/#quux$.o"
# RUN: ld.lld -o %t/foo.exe %t/foo.o %t/"bar baz.o" "%t/#quux$.o" --dependency-file=%t/foo.d
# RUN: FileCheck --match-full-lines -DFILE=%t %s < %t/foo.d
# RUN: FileCheck --match-full-lines --strict-whitespace -DFILE=%t %s < %t/foo.d

# CHECK: [[FILE]]{{/|(\\)+}}foo.exe: \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}foo.o \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}bar\ baz.o \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}\#quux$$.o
# CHECK:[[FILE]]{{/|(\\)+}}foo.exe: \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}foo.o \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}bar\ baz.o \
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}\#quux$$.o
# CHECK-EMPTY:
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}foo.o:
# CHECK-NEXT:[[FILE]]{{/|(\\)+}}foo.o:
# CHECK-EMPTY:
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}bar\ baz.o:
# CHECK-NEXT:[[FILE]]{{/|(\\)+}}bar\ baz.o:
# CHECK-EMPTY:
# CHECK-NEXT: [[FILE]]{{/|(\\)+}}\#quux$$.o:
# CHECK-NEXT:[[FILE]]{{/|(\\)+}}\#quux$$.o:

.global _start
_start: