Skip to content

Commit

Permalink
Do not record response files as dependency files
Browse files Browse the repository at this point in the history
Fixes #1258
  • Loading branch information
rui314 committed May 16, 2024
1 parent 08be7ff commit 4281f45
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,9 @@ class MappedFile {
MappedFile *parent = nullptr;
MappedFile *thin_parent = nullptr;

// For --dependency-file
bool is_dependency = true;

#ifdef _WIN32
HANDLE fd = INVALID_HANDLE_VALUE;
#else
Expand Down
2 changes: 2 additions & 0 deletions elf/cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ read_response_file(Context<E> &ctx, std::string_view path, i64 depth) {
MappedFile *mf = must_open_file(ctx, std::string(path));
std::string_view data((char *)mf->data, mf->size);

mf->is_dependency = false;

while (!data.empty()) {
if (isspace(data[0])) {
data = data.substr(1);
Expand Down
2 changes: 1 addition & 1 deletion elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ void write_dependency_file(Context<E> &ctx) {
std::unordered_set<std::string> seen;

for (std::unique_ptr<MappedFile> &mf : ctx.mf_pool)
if (!mf->parent)
if (mf->is_dependency && !mf->parent)
if (std::string path = path_clean(mf->name); seen.insert(path).second)
deps.push_back(path);

Expand Down
17 changes: 17 additions & 0 deletions test/elf/dependency-file-response-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
. $(dirname $0)/common.inc

cat <<EOF | $CC -o $t/a.o -c -xc -
#include <stdio.h>
int main() {
printf("Hello world\n");
}
EOF

echo "$t/a.o -Wl,-dependency-file=$t/dep" > $t/rsp

$CC -B. -o $t/exe @$t/rsp

grep -q '/exe:.*/a.o ' $t/dep
grep -q '/a.o:$' $t/dep
! grep -q '^/tmp' $t/dep || false

0 comments on commit 4281f45

Please sign in to comment.