[PATCH] D122843: [lld-macho] Include output filename in UUID hash

Leonard Grey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 12:04:23 PDT 2022


lgrey created this revision.
lgrey added reviewers: thakis, lld-macho.
Herald added projects: lld-macho, All.
lgrey requested review of this revision.
Herald added a project: LLVM.

Similar to what ld64 does here: https://github.com/apple-opensource/ld64/blob/e28c028b20af187a16a7161d89e91868a450cadc/src/ld/OutputFile.cpp#L3724


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122843

Files:
  lld/MachO/Writer.cpp
  lld/test/MachO/uuid.s


Index: lld/test/MachO/uuid.s
===================================================================
--- lld/test/MachO/uuid.s
+++ lld/test/MachO/uuid.s
@@ -1,8 +1,15 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
-# RUN: %lld -lSystem %t.o -o %t
-# RUN: llvm-dwarfdump --uuid %t | FileCheck %s
-# CHECK: 4C4C44{{([[:xdigit:]]{2})}}-5555-{{([[:xdigit:]]{4})}}-A1{{([[:xdigit:]]{2})}}-{{([[:xdigit:]]{12})}} (x86_64)
+# RUN: rm -rf %t && mkdir -p %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
+# RUN: %lld -lSystem %t/test.o -o %t/a
+# RUN: %lld -lSystem %t/test.o -o %t/b
+# RUN: llvm-dwarfdump --uuid %t/a | awk '{print $2}' > %t/uuida
+# RUN: llvm-dwarfdump --uuid %t/b | awk '{print $2}' > %t/uuidb
+# RUN: FileCheck %s < %t/uuida
+# RUN: FileCheck %s < %t/uuidb
+# RUN: not cmp %t/uuida %t/uuidb
+
+# CHECK: 4C4C44{{([[:xdigit:]]{2})}}-5555-{{([[:xdigit:]]{4})}}-A1{{([[:xdigit:]]{2})}}-{{([[:xdigit:]]{12})}}
 
 .globl _main
 _main:
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -1075,7 +1075,8 @@
   // Round-up integer division
   size_t chunkSize = (data.size() + chunkCount - 1) / chunkCount;
   std::vector<ArrayRef<uint8_t>> chunks = split(data, chunkSize);
-  std::vector<uint64_t> hashes(chunks.size());
+  // Leave one slot for filename
+  std::vector<uint64_t> hashes(chunks.size() + 1);
   SmallVector<std::shared_future<void>> threadFutures;
   threadFutures.reserve(chunks.size());
   for (size_t i = 0; i < chunks.size(); ++i)
@@ -1083,7 +1084,9 @@
         [&](size_t j) { hashes[j] = xxHash64(chunks[j]); }, i));
   for (std::shared_future<void> &future : threadFutures)
     future.wait();
-
+  // Append the output filename so that identical binaries with different names
+  // don't get the same UUID.
+  hashes[chunks.size()] = xxHash64(sys::path::filename(config->outputFile));
   uint64_t digest = xxHash64({reinterpret_cast<uint8_t *>(hashes.data()),
                               hashes.size() * sizeof(uint64_t)});
   uuidCommand->writeUuid(digest);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122843.419529.patch
Type: text/x-patch
Size: 2153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220331/fee8236d/attachment.bin>


More information about the llvm-commits mailing list