Skip to content

Commit a9e3251

Browse files
Add output filename to UUID hash
Differential Revision: https://reviews.llvm.org/D122843
1 parent 1474462 commit a9e3251

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lld/MachO/Writer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,15 +1075,18 @@ void Writer::writeUuid() {
10751075
// Round-up integer division
10761076
size_t chunkSize = (data.size() + chunkCount - 1) / chunkCount;
10771077
std::vector<ArrayRef<uint8_t>> chunks = split(data, chunkSize);
1078-
std::vector<uint64_t> hashes(chunks.size());
1078+
// Leave one slot for filename
1079+
std::vector<uint64_t> hashes(chunks.size() + 1);
10791080
SmallVector<std::shared_future<void>> threadFutures;
10801081
threadFutures.reserve(chunks.size());
10811082
for (size_t i = 0; i < chunks.size(); ++i)
10821083
threadFutures.emplace_back(threadPool.async(
10831084
[&](size_t j) { hashes[j] = xxHash64(chunks[j]); }, i));
10841085
for (std::shared_future<void> &future : threadFutures)
10851086
future.wait();
1086-
1087+
// Append the output filename so that identical binaries with different names
1088+
// don't get the same UUID.
1089+
hashes[chunks.size()] = xxHash64(sys::path::filename(config->finalOutput));
10871090
uint64_t digest = xxHash64({reinterpret_cast<uint8_t *>(hashes.data()),
10881091
hashes.size() * sizeof(uint64_t)});
10891092
uuidCommand->writeUuid(digest);

lld/test/MachO/uuid.s

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3-
# RUN: %lld -lSystem %t.o -o %t
4-
# RUN: llvm-dwarfdump --uuid %t | FileCheck %s
5-
# CHECK: 4C4C44{{([[:xdigit:]]{2})}}-5555-{{([[:xdigit:]]{4})}}-A1{{([[:xdigit:]]{2})}}-{{([[:xdigit:]]{12})}} (x86_64)
2+
# RUN: rm -rf %t && mkdir -p %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
4+
# RUN: %lld -lSystem %t/test.o -o %t/a
5+
# RUN: %lld -lSystem %t/test.o -o %t/b
6+
# RUN: llvm-dwarfdump --uuid %t/a | awk '{print $2}' > %t/uuida
7+
# RUN: llvm-dwarfdump --uuid %t/b | awk '{print $2}' > %t/uuidb
8+
# RUN: FileCheck %s < %t/uuida
9+
# RUN: FileCheck %s < %t/uuidb
10+
# RUN: not cmp %t/uuida %t/uuidb
11+
12+
## Ensure -final_output is used for universal binaries, which may be linked with
13+
## temporary output file names
14+
# RUN: %lld -lSystem %t/test.o -o %t/c -final_output %t/a
15+
# RUN: llvm-dwarfdump --uuid %t/c | awk '{print $2}' > %t/uuidc
16+
# RUN: cmp %t/uuida %t/uuidc
17+
18+
19+
# CHECK: 4C4C44{{([[:xdigit:]]{2})}}-5555-{{([[:xdigit:]]{4})}}-A1{{([[:xdigit:]]{2})}}-{{([[:xdigit:]]{12})}}
620

721
.globl _main
822
_main:

0 commit comments

Comments
 (0)