-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unnecessarily relink when Link-Time Optimization is on #2535
Comments
It looks like the compiler or linker command is generating incorrect depfile information that includes temporary files that are removed after the compile/link step. It's either a bug in the toolchain, or the CMake-generated Ninja build plan triggered by I recommend you file a bug in the CMake bug tracker for this issue instead. |
Addendum: When LTO is on: |
I don't think it is CMake and I have examined the I think the But how can I make Ninja to omit the files? For GCC+ld:
For Clang+lld
|
Thanks for the extra information. Entries like I.e. there is really no practical reason to list them in the So this definitely looks like a linker bug, not CMake or Ninja related per se. You would probably have the same issue with the Make backend if it reuses the same files. A temporary work-around would use a wrapper script around the linker command to process its generated |
I tried the code you shown and can not reproduce. $ cmake -S ../ -G Ninja -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release --fresh
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/ilya/devel/tmp/lto/build
$ ninja
[2/2] Linking C executable main
$ ninja
ninja: no work to do.
$ ninja
ninja: no work to do. $ gcc --version
gcc (Ubuntu 14.2.0-4ubuntu2) 14.2.0
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.43.1
$ cmake --version
cmake version 3.30.3 Looks like there is something with your linker? Or how your toolchain is configured. Interestingly, for me
does not show anything for |
Finally I found the problem from binutils (2.43+r4+g7999dae6961-1) from Arch Linux. On Ubuntu, binutils 2.42 generate depfile more like lld. I will close the issue since resolved. |
Ninja version: 1.12.1
Ninja seems tracking some link-time temporary files, maybe for link-time optimization, and finds them missing at next build time.
Project to reproduce:
CMakeLists.txt
:main.c
:Case 1: Release build w/o Link-Time Optimization
Case 2: Release build w/ Link-Time Optimization
The text was updated successfully, but these errors were encountered: