Skip to content

Commit 17386cb

Browse files
committed
[clang][Driver] Make multiarch output file basenames reproducible
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
1 parent e2faf72 commit 17386cb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4960,7 +4960,13 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
49604960
return "";
49614961
}
49624962
} else {
4963-
TmpName = GetTemporaryPath(Split.first, Suffix);
4963+
if (MultipleArchs && !BoundArch.empty()) {
4964+
TmpName = GetTemporaryDirectory(Split.first);
4965+
llvm::sys::path::append(TmpName,
4966+
Split.first + "-" + BoundArch + "." + Suffix);
4967+
} else {
4968+
TmpName = GetTemporaryPath(Split.first, Suffix);
4969+
}
49644970
}
49654971
return C.addTempFile(C.getArgs().MakeArgString(TmpName));
49664972
}

clang/test/Driver/darwin-dsymutil.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Linker", inputs: [{{.*}}], output: "[[outfile]]"
4343
// CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["[[outfile]]"], output: "[[dsymfile]]"
4444

45+
// Check output name derivation for multiple -arch options.
46+
//
47+
// RUN: %clang -target x86_64-apple-darwin10 \
48+
// RUN: -arch x86_64 -arch arm64 -ccc-print-bindings %s 2> %t
49+
// RUN: FileCheck --check-prefix=CHECK-MULTIARCH-OUTPUT-NAME < %t %s
50+
//
51+
// CHECK-MULTIARCH-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Linker", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-x86_64.o"], output: "{{.*}}{{/|\\}}darwin-dsymutil-x86_64.out"
52+
// CHECK-MULTIARCH-OUTPUT-NAME: "arm64-apple-darwin10" - "darwin::Linker", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-arm64.o"], output: "{{.*}}{{/|\\}}darwin-dsymutil-arm64.out"
53+
// CHECK-MULTIARCH-OUTPUT-NAME: "arm64-apple-darwin10" - "darwin::Lipo", inputs: ["{{.*}}{{/|\\}}darwin-dsymutil-x86_64.out", "{{.*}}{{/|\\}}darwin-dsymutil-arm64.out"], output: "a.out"
54+
4555
// Check that we only use dsymutil when needed.
4656
//
4757
// RUN: touch %t.o

0 commit comments

Comments
 (0)