[lld] 277c382 - [lld-macho] Flip ZERO_AR_DATE default
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 10 13:11:47 PDT 2022
Author: Keith Smiley
Date: 2022-10-10T13:10:09-07:00
New Revision: 277c382760bf9575cfa2eac73d5ad1db91466d3f
URL: https://github.com/llvm/llvm-project/commit/277c382760bf9575cfa2eac73d5ad1db91466d3f
DIFF: https://github.com/llvm/llvm-project/commit/277c382760bf9575cfa2eac73d5ad1db91466d3f.diff
LOG: [lld-macho] Flip ZERO_AR_DATE default
Previously unless ZERO_AR_DATE was set to any value, ld64.lld would
embed non-hermetic timestamps into the final binary. This flips that
default to zero those values unless ZERO_AR_DATE is set explicitly to 0.
As far as I know there isn't a downside to this, except that it differs
from ld64.
Differential Revision: https://reviews.llvm.org/D135529
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/docs/MachO/ld64-vs-lld.rst
lld/test/MachO/lto-object-path.ll
lld/test/MachO/stabs.s
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 81bc6cc546cb2..3d5f4cbe71864 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -205,7 +205,7 @@ struct Configuration {
SymtabPresence localSymbolsPresence = SymtabPresence::All;
SymbolPatterns localSymbolPatterns;
- bool zeroModTime = false;
+ bool zeroModTime = true;
llvm::StringRef osoPrefix;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 92230db0629a0..29472f2a164b0 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1550,7 +1550,8 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
}
// FIXME: Add a commandline flag for this too.
- config->zeroModTime = getenv("ZERO_AR_DATE");
+ if (const char *zero = getenv("ZERO_AR_DATE"))
+ config->zeroModTime = strcmp(zero, "0") != 0;
std::array<PlatformType, 3> encryptablePlatforms{
PLATFORM_IOS, PLATFORM_WATCHOS, PLATFORM_TVOS};
diff --git a/lld/docs/MachO/ld64-vs-lld.rst b/lld/docs/MachO/ld64-vs-lld.rst
index 6ee48715b2ecb..f164dd45c4d7b 100644
--- a/lld/docs/MachO/ld64-vs-lld.rst
+++ b/lld/docs/MachO/ld64-vs-lld.rst
@@ -55,3 +55,11 @@ result in duplicate symbol errors. LLD does not check for duplicate aliases;
instead we perform alias resolution first, and only then do we check for
duplicate symbols. In particular, we will not report a duplicate symbol error if
the aliased symbols turn out to be weak definitions, but ld64 will.
+
+``ZERO_AR_DATE`` enabled by default
+***********************************
+ld64 has a special mode where it sets some stabs modification times to 0 for
+hermetic builds, enabled by setting any value for the ``ZERO_AR_DATE``
+environment variable. LLD flips this default to perfer hermetic builds, but
+allows disabling this behavior by setting ``ZERO_AR_DATE=0``. Any other value
+of ``ZERO_AR_DATE`` will be ignored.
diff --git a/lld/test/MachO/lto-object-path.ll b/lld/test/MachO/lto-object-path.ll
index 39bf4c006a09e..8903175bd4510 100644
--- a/lld/test/MachO/lto-object-path.ll
+++ b/lld/test/MachO/lto-object-path.ll
@@ -7,17 +7,17 @@
; RUN: %lld %t/test.o -o %t/test
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,NOOBJPATH
-; RUN: %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps
+; RUN: ZERO_AR_DATE=0 %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-DIR -DDIR=%t/lto-temps
;; Ensure object path is still used if the cache is used
-; RUN: %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps -prune_interval_lto 20 -cache_path_lto %t/cache --thinlto-cache-policy=cache_size_files=1:cache_size_bytes=10
+; RUN: ZERO_AR_DATE=0 %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps -prune_interval_lto 20 -cache_path_lto %t/cache --thinlto-cache-policy=cache_size_files=1:cache_size_bytes=10
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-DIR -DDIR=%t/lto-temps
;; And that dsymutil can read the result
; RUN: dsymutil -f -o - %t/test | llvm-dwarfdump - | FileCheck %s --check-prefix=DSYM
;; Test that the object path hardlinks to the cache when possible
-;; NB:
+;; NB:
;; 1) Need to delete current object path contents or hardlink will fail.
;; 2) Note the cache policy is
diff erent from the test above (which is crafted
;; to ensure that the cache is pruned immediately; we want the opposite here).
@@ -28,7 +28,7 @@
;; check that the object path can be an existing file
; RUN: touch %t/lto-tmp.o
-; RUN: %lld %t/test.o -o %t/test -object_path_lto %t/lto-tmp.o
+; RUN: ZERO_AR_DATE=0 %lld %t/test.o -o %t/test -object_path_lto %t/lto-tmp.o
; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-FILE -DFILE=%t/lto-tmp.o
diff --git a/lld/test/MachO/stabs.s b/lld/test/MachO/stabs.s
index e2ef9daa15720..b10793fae1572 100644
--- a/lld/test/MachO/stabs.s
+++ b/lld/test/MachO/stabs.s
@@ -9,14 +9,14 @@
# RUN: env TZ=UTC touch -t "197001010000.32" %t/foo.o
# RUN: llvm-ar rcsU %t/foo.a %t/foo.o
-# RUN: %lld -lSystem %t/test.o %t/foo.o %t/no-debug.o -o %t/test
+# RUN: ZERO_AR_DATE=0 %lld -lSystem %t/test.o %t/foo.o %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=0x10 -D#FOO_TIME=0x20
## Check that we emit the right modtime even when the object file is in an
## archive.
-# RUN: %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o -o %t/test
+# RUN: ZERO_AR_DATE=0 %lld -lSystem %t/test.o %t/foo.a %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.a\(foo.o\) \
# RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
@@ -27,17 +27,17 @@
# 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
-# RUN: env ZERO_AR_DATE=1 %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o \
+# RUN: env %lld -lSystem %t/test.o %t/foo.a %t/no-debug.o \
# RUN: -o %t/test
# 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=1 %lld -lSystem %t/test.o %t/no-debug.o \
+# RUN: env %lld -lSystem %t/test.o %t/no-debug.o \
# RUN: -all_load %t/foo.a -o %t/test
# 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=1 %lld -lSystem %t/test.o %t/no-debug.o \
+# RUN: env %lld -lSystem %t/test.o %t/no-debug.o \
# RUN: -force_load %t/foo.a -o %t/test
# RUN: (llvm-objdump --section-headers %t/test; dsymutil -s %t/test) | \
# RUN: FileCheck %s -DDIR=%t -DFOO_PATH=%t/foo.a\(foo.o\) \
@@ -45,21 +45,21 @@
## Check that we emit absolute paths to the object files in our OSO entries
## even if our inputs are relative paths.
-# RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -o test
+# RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -o 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=0x10 -D#FOO_TIME=0x20
## Check that we emit relative path to object files in OSO entries
## when -oso_prefix <path> is used.
-# RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t" -o %t/test-rel
+# RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t" -o %t/test-rel
# RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH
-# RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t/" -o %t/test-rel
+# RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "%t/" -o %t/test-rel
# RUN: dsymutil -s %t/test-rel | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH-NO-SLASH
-# RUN: cd %t && %lld -lSystem test.o foo.o no-debug.o -oso_prefix "." -o %t/test-rel-dot
+# RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "." -o %t/test-rel-dot
# RUN: dsymutil -s %t/test-rel-dot | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-DOT
## Set HOME to %t (for ~ to expand to)
-# RUN: cd %t && env HOME=%t %lld -lSystem test.o foo.o no-debug.o -oso_prefix "~" -o %t/test-rel-tilde
+# RUN: cd %t && env HOME=%t ZERO_AR_DATE=0 %lld -lSystem test.o foo.o no-debug.o -oso_prefix "~" -o %t/test-rel-tilde
# RUN: dsymutil -s %t/test-rel-tilde | grep 'N_OSO' | FileCheck %s -D#TEST_TIME=0x10 -D#FOO_TIME=0x20 --check-prefix=REL-PATH
## Check that we don't emit DWARF or stabs when -S is used
@@ -68,7 +68,7 @@
## expect to not find any entries which requires the exit code to be negated.
# RUN: llvm-nm -ap %t/test-no-debug | not grep -e ' - '
-# RUN: cd %t && %lld -lSystem test.o foo.a no-debug.o -o %t/test
+# RUN: cd %t && ZERO_AR_DATE=0 %lld -lSystem test.o foo.a 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.a\(foo.o\) \
# RUN: -D#TEST_TIME=0x10 -D#FOO_TIME=0x20
More information about the llvm-commits
mailing list