clang 23.1.0 writes COFF timestamp on `*-windows-gnu`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
While upgrading from LLVM 21 to 23, I noticed that `clang` 23.1.0 writes a non-zero COFF timestamp by default on `x86_64-w64-windows-gnu`. This was not previously the case in LLVM 21.
A naive look at the git log between the two releases suggests that maybe e97a42d5f9fe could be at fault? At least it is the only commit I could find that does meaningful changes to `-mno-incremental-linker-compatible` which is the option to suppress this behavior.
## Reproducer
test.c:
```c
int main() {
return 0;
}
```
commands:
```sh
# ./build/release/stage1/bin/clang.exe -c test.c -o test.o; sha256sum test.o
e1aa8b5343f8046651ee73bb93c9ea86280df5b1dfe0180c76a15da32fda93ce *test.o
# ./build/release/stage1/bin/clang.exe -c test.c -o test.o; sha256sum test.o
83c2cbf780d0787d5efe340e9b14b2fea8fcc80992bd203549b61608a85ce18a *test.o
```
According to hexdump the only difference between the two `test.o` is the timestamp field.
## Workaround
On previous clang versions the build is deterministic by default (here clang 21.2.8):
```
# clang.exe -c test.c -o test.o; sha256sum test.o
3836fc1cf3f96ceb468a56a858a6368d9bdb6730be20664504035559c39a7884 *test.o
# clang.exe -c test.c -o test.o; sha256sum test.o
3836fc1cf3f96ceb468a56a858a6368d9bdb6730be20664504035559c39a7884 *test.o
```
Alternatively, explicitly passing `-mno-incremental-linker-compatible` to clang 23.1.0:
```
# ./build/release/stage1/bin/clang.exe -mno-incremental-linker-compatible -c test.c -o test.o; sha256sum test.o
65f57ad014a331155c3ef61353bde4b47ce6dd7bc4991ae26df98d096c8bde2b *test.o
# ./build/release/stage1/bin/clang.exe -mno-incremental-linker-compatible -c test.c -o test.o; sha256sum test.o
65f57ad014a331155c3ef61353bde4b47ce6dd7bc4991ae26df98d096c8bde2b *test.o
```
However, to the best of my understanding, this flag should only be necessary on `*-windows-msvc` targets and not `*-windows-gnu`.
## Version Information
```
# ./clang.exe --print-target-triple
x86_64-w64-windows-gnu
# ./clang.exe --version
clang version 23.1.0
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/Users/Administrator/lean4/build/release/stage1/bin
```
Compiled using the Lean LLVM setup at https://github.com/leanprover/lean-llvm/blob/23.1.0/.github/workflows/build.yml.
Contributor guide
Research direction
Start with the test.c reproducer on the x86_64-w64-windows-gnu target and compare repeated object-file hashes and the COFF timestamp. Inspect commit e97a42d5f9fe and the handling of -mno-incremental-linker-compatible. Done means clang produces deterministic objects by default for windows-gnu targets while retaining the expected behavior for windows-msvc targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100