[lld] 1167d67 - [lld-macho] Add new -reproducible flag

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 10:01:13 PDT 2023


Author: Keith Smiley
Date: 2023-04-06T09:59:53-07:00
New Revision: 1167d676100ffebcafaf130b3af9250d81c4f5c7

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

LOG: [lld-macho] Add new -reproducible flag

As of Xcode 14.3 it passes -reproducible by default to ld64. It seems
this flag was added in ld64 with Xcode 14.0, but it is not documented.
Through my testing the only thing I have seen it do is the same as
ZERO_AR_DATE, but it's possible it does more, or will do more in the
future. Since we already default to this option, this is more about
handling the command line flag to maintain Xcode compatibility than
anything else.

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/Options.td
    lld/test/MachO/stabs.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 093538f7da64a..3452dcd51d6fa 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1644,9 +1644,10 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
         std::make_pair(arg->getValue(0), arg->getValue(1)));
   }
 
-  // FIXME: Add a commandline flag for this too.
   if (const char *zero = getenv("ZERO_AR_DATE"))
     config->zeroModTime = strcmp(zero, "0") != 0;
+  if (args.getLastArg(OPT_reproducible))
+    config->zeroModTime = true;
 
   std::array<PlatformType, 3> encryptablePlatforms{
       PLATFORM_IOS, PLATFORM_WATCHOS, PLATFORM_TVOS};

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index ec747d0c9042b..4d4181471c3e8 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -670,6 +670,9 @@ def adhoc_codesign : Flag<["-"], "adhoc_codesign">,
 def no_adhoc_codesign : Flag<["-"], "no_adhoc_codesign">,
     HelpText<"Do not write an ad-hoc code signature to the output file (default for x86_64 binaries)">,
     Group<grp_rare>;
+def reproducible : Flag<["-"], "reproducible">,
+    HelpText<"Make the output reproducible by removing timestamps and other non-deterministic data. This is the default behavior.">,
+    Group<grp_rare>;
 def version_details : Flag<["-"], "version_details">,
     HelpText<"Print the linker version in JSON form">,
     Flags<[HelpHidden]>,

diff  --git a/lld/test/MachO/stabs.s b/lld/test/MachO/stabs.s
index 0d93b7214d3f5..aa96f7c147a7e 100644
--- a/lld/test/MachO/stabs.s
+++ b/lld/test/MachO/stabs.s
@@ -42,6 +42,11 @@
 # RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
 # RUN:   FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
 # RUN:       -D#TEST_TIME=0 -D#FOO_TIME=0
+# RUN: env ZERO_AR_DATE=0 %lld -lSystem -reproducible %t/test.o %t/foo.o \
+# RUN:     %t/no-debug.o -o %t/test
+# RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
+# RUN:   FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.o \
+# RUN:       -D#TEST_TIME=0 -D#FOO_TIME=0
 
 ## Check that we emit absolute paths to the object files in our OSO entries
 ## even if our inputs are relative paths.


        


More information about the llvm-commits mailing list