-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed as not planned
Labels
LTOLink time optimization (regular/full LTO or ThinLTO)Link time optimization (regular/full LTO or ThinLTO)questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Description
Posted a SO question about this: https://stackoverflow.com/questions/72190379/lld-runs-lto-even-if-fno-lto-is-passed. Copying here the content:
I have a CMake project with several subprojects that create static libraries built with -flto=thin
.
The project has a lot of tests that are linked against the aforementioned libraries. With LTO it takes a lot of time to build tests, therefore I have disabled LTO for tests using -fno-lto
.
What I noticed though, is that lld
performs LTO on tests even with -fno-lto
. If I run the linker with --time-trace
I can see that the majority of the time is spent on LTO.
My questions are:
- Is this expected? If so I can assume that
lld
performs LTO whenever it finds the LTO info in the object it links. - If not, is there a way to disable this behavior? Adding
-fno-lto
to the compiler does not seem to work, andlld
does not have a param to explicitly disable LTO. - If not, is this a bug? If this is a bug I will submit a repro.
This is how I handle lto
in CMake:
# Enable Thin LTO only on non-test targets.
if(ENABLE_LTO)
if (IS_TEST)
target_compile_options(${TARGET} PRIVATE -fno-lto)
# Probably pointless.
target_link_options(${TARGET} PRIVATE -fno-lto)
else()
message(STATUS "ENABLE_LTO on target ${TARGET})")
target_compile_options(${TARGET} PRIVATE -flto=thin)
target_link_options(${TARGET} PRIVATE -flto=thin -Wl,--thinlto-cache-dir=${CMAKE_BINARY_DIR}/lto.cache)
endif()
endif()
The command that builds the tests does not contain -flto=thin
at all, it only contains -fno-lto
Metadata
Metadata
Assignees
Labels
LTOLink time optimization (regular/full LTO or ThinLTO)Link time optimization (regular/full LTO or ThinLTO)questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!