diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/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 encryptablePlatforms{ PLATFORM_IOS, PLATFORM_WATCHOS, PLATFORM_TVOS}; diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/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; +def reproducible : Flag<["-"], "reproducible">, + HelpText<"Make the output reproducible by removing timestamps and other non-deterministic data. This is the default behavior.">, + Group; 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 --- 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.