Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,15 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
}
} else {
config->repro = false;
config->timestamp = time(nullptr);
if (std::optional<std::string> epoch =
Process::GetEnv("SOURCE_DATE_EPOCH")) {
StringRef value(*epoch);
if (value.getAsInteger(0, config->timestamp))
fatal(Twine("invalid SOURCE_DATE_EPOCH timestamp: ") + value +
". Expected 32-bit integer");
} else {
config->timestamp = time(nullptr);
}
}

// Handle /alternatename
Expand Down
2 changes: 2 additions & 0 deletions lld/test/COFF/timestamp.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ RUN: yaml2obj %p/Inputs/generic.yaml -o %t.obj
RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.1.exe
RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.2.exe
RUN: lld-link %t.obj /debug /timestamp:0 /entry:main /nodefaultlib /out:%t.3.exe
RUN: env SOURCE_DATE_EPOCH=0 lld-link %t.obj /debug /entry:main /nodefaultlib /out:%t.4.exe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to test another value like clang/test/Preprocessor/SOURCE_DATE_EPOCH.c

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added more tests for more interesting cases.

What do you think of backporting this to 18.x? It’s not a bug fix per se, but a pretty safe improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for a backport to improve reproducibility!

https://reproducible-builds.org/

RUN: llvm-readobj --file-headers --coff-debug-directory %t.1.exe | FileCheck %s --check-prefix=HASH
RUN: llvm-readobj --file-headers --coff-debug-directory %t.2.exe | FileCheck %s --check-prefix=HASH
RUN: llvm-readobj --file-headers --coff-debug-directory %t.3.exe | FileCheck %s --check-prefix=ZERO
RUN: llvm-readobj --file-headers --coff-debug-directory %t.4.exe | FileCheck %s --check-prefix=ZERO

HASH: ImageFileHeader {
HASH: TimeDateStamp: [[STAMP:.*]]
Expand Down