Skip to content

Commit

Permalink
[clang][Driver] Make multiarch output file basenames reproducible
Browse files Browse the repository at this point in the history
When building a multiarch MachO binary, previously the intermediate
output file names would contain random characters. On macOS this
filename, since it's used when linking, ended up being used as a
stable-ish identifier for the adhoc codesignature of the binary, leading
to non-reproducible binaries. This change uses the architecture, when
available, to create a stable, but unique, basename for the file.

Differential Revision: https://reviews.llvm.org/D111269
  • Loading branch information
keith committed Oct 19, 2021
1 parent e2faf72 commit 17386cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4960,7 +4960,13 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
return "";
}
} else {
TmpName = GetTemporaryPath(Split.first, Suffix);
if (MultipleArchs && !BoundArch.empty()) {
TmpName = GetTemporaryDirectory(Split.first);
llvm::sys::path::append(TmpName,
Split.first + "-" + BoundArch + "." + Suffix);
} else {
TmpName = GetTemporaryPath(Split.first, Suffix);
}
}
return C.addTempFile(C.getArgs().MakeArgString(TmpName));
}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/darwin-dsymutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Linker", inputs: [{{.*}}], output: "[[outfile]]"
// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["[[outfile]]"], output: "[[dsymfile]]"

// Check output name derivation for multiple -arch options.
//
// RUN: %clang -target x86_64-apple-darwin10 \
// RUN: -arch x86_64 -arch arm64 -ccc-print-bindings %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-MULTIARCH-OUTPUT-NAME < %t %s
//
// CHECK-MULTIARCH-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Linker", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-x86_64.o"], output: "{{.*}}{{/|\\}}darwin-dsymutil-x86_64.out"
// CHECK-MULTIARCH-OUTPUT-NAME: "arm64-apple-darwin10" - "darwin::Linker", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-arm64.o"], output: "{{.*}}{{/|\\}}darwin-dsymutil-arm64.out"
// CHECK-MULTIARCH-OUTPUT-NAME: "arm64-apple-darwin10" - "darwin::Lipo", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-x86_64.out", "{{.*}}{{/|\\}}darwin-dsymutil-arm64.out"], output: "a.out"

// Check that we only use dsymutil when needed.
//
// RUN: touch %t.o
Expand Down

0 comments on commit 17386cb

Please sign in to comment.