[lld] f317ce2 - [lld-macho] Implement -no_uuid

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 16:39:47 PDT 2023


Author: Keith Smiley
Date: 2023-07-19T16:39:31-07:00
New Revision: f317ce218e75abe6bc0818709fbbb81657224ffe

URL: https://github.com/llvm/llvm-project/commit/f317ce218e75abe6bc0818709fbbb81657224ffe
DIFF: https://github.com/llvm/llvm-project/commit/f317ce218e75abe6bc0818709fbbb81657224ffe.diff

LOG: [lld-macho] Implement -no_uuid

Since UUID generation in lld is fast this is rarely used but it can be
helpful to avoid temporary issues like https://github.com/llvm/llvm-project/issues/63961

Differential Revision: https://reviews.llvm.org/D155735

Added: 
    

Modified: 
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/Options.td
    lld/MachO/Writer.cpp
    lld/test/MachO/uuid.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 3fefafc81bc2b1..59eb882c078369 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -227,6 +227,7 @@ struct Configuration {
   llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
 
   bool zeroModTime = true;
+  bool generateUuid = true;
 
   llvm::StringRef osoPrefix;
 

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 8fa3ee08287977..ce7f6d567b613b 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1640,6 +1640,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
   config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
   config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
+  config->generateUuid = !args.hasArg(OPT_no_uuid);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
     config->aliasedSymbols.push_back(

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 9970fa69bf51ed..b60f5e44c3c1d9 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -791,7 +791,6 @@ def allow_sub_type_mismatches : Flag<["-"], "allow_sub_type_mismatches">,
     Group<grp_rare>;
 def no_uuid : Flag<["-"], "no_uuid">,
     HelpText<"Do not generate the LC_UUID load command">,
-    Flags<[HelpHidden]>,
     Group<grp_rare>;
 def root_safe : Flag<["-"], "root_safe">,
     HelpText<"Set the MH_ROOT_SAFE bit in the mach-o header">,

diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 5dc67fb4198bb9..871e4967d313ce 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -813,8 +813,10 @@ template <class LP> void Writer::createLoadCommands() {
     llvm_unreachable("unhandled output file type");
   }
 
-  uuidCommand = make<LCUuid>();
-  in.header->addLoadCommand(uuidCommand);
+  if (config->generateUuid) {
+    uuidCommand = make<LCUuid>();
+    in.header->addLoadCommand(uuidCommand);
+  }
 
   if (useLCBuildVersion(config->platformInfo))
     in.header->addLoadCommand(make<LCBuildVersion>(config->platformInfo));
@@ -1264,7 +1266,8 @@ void Writer::writeOutputFile() {
   writeSections();
   applyOptimizationHints();
   buildFixupChains();
-  writeUuid();
+  if (config->generateUuid)
+    writeUuid();
   writeCodeSignature();
 
   if (auto e = buffer->commit())

diff  --git a/lld/test/MachO/uuid.s b/lld/test/MachO/uuid.s
index 2382939eaf6ec3..68a9e5da2f0001 100644
--- a/lld/test/MachO/uuid.s
+++ b/lld/test/MachO/uuid.s
@@ -16,6 +16,9 @@
 # RUN: llvm-dwarfdump --uuid %t/c | awk '{print $2}' > %t/uuidc
 # RUN: cmp %t/uuida %t/uuidc
 
+## Test disabling UUID generation
+# RUN: %lld -lSystem %t/test.o -o %t/d -no_uuid
+# RUN: llvm-dwarfdump --uuid %t/d | count 0
 
 # CHECK: 4C4C44{{([[:xdigit:]]{2})}}-5555-{{([[:xdigit:]]{4})}}-A1{{([[:xdigit:]]{2})}}-{{([[:xdigit:]]{12})}}
 


        


More information about the llvm-commits mailing list