<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55431>55431</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld runs LTO even if -fno-lto is passed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          simone-gaia
      </td>
    </tr>
</table>

<pre>
    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:
1. Is this expected? If so I can assume that `lld` performs LTO whenever it finds the LTO info in the object it links.
2. If not, is there a way to disable this behavior? Adding `-fno-lto` to the compiler does not seem to work, and `lld` does not have a param to explicitly disable LTO.
3. 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`

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVV1v4jgU_TXh5SqIJFDKAw-00BXa6UzVslvtE3ISh3jq2KztlOXf77ETPqYdrVa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