[PATCH] D147663: [lld-macho] Add new -reproducible flag

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


This revision was automatically updated to reflect the committed changes.
keith marked 2 inline comments as done.
Closed by commit rG1167d676100f: [lld-macho] Add new -reproducible flag (authored by keith).

Changed prior to commit:
  https://reviews.llvm.org/D147663?vs=511216&id=511464#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147663/new/

https://reviews.llvm.org/D147663

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


Index: lld/test/MachO/stabs.s
===================================================================
--- lld/test/MachO/stabs.s
+++ 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.
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -670,6 +670,9 @@
 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]>,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1644,9 +1644,10 @@
         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};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147663.511464.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230406/af70961a/attachment.bin>


More information about the llvm-commits mailing list