How lld invoke LTO or thinLTO and is there some cases and some method to get the step-by-step message for me to understand how LTO worked?

I want to learn how LTO and thinLTO work? But I’m confused how lld invoked either library. How can I find it in lld. Should i be familiar with lld source code? And i also think if there is some easy test case and with step-by- step debugging or some log messages can help me learn this? Is there some method can do stuff like this?
Thank you very much.

Hi ZhengXianLi,

The main entry point into the LTO LLVM code from lld is in Specifically see the call to ltoObj->run which launches the main LTO handling after all of the setup here: Most of the actual LTO handling is in the LLVM LTO code here:
and here:
Note there is an old LTO API implementation in LTOModule.cpp and *LTOCodeGenerator.cpp that is not used by lld, gold or bfd (just ld64 and some custom linkers nowadays that haven’t yet migrated). The newer LTO API implementation in LTO.cpp and LTOBackend.cpp relies on linker resolutions passed by lld (or gold/bfd via gold-plugin.cpp) via that lld file I pointed to.

The following lld test contain some simple test cases for thinLTO:

To run them with regular LTO instead of ThinLTO, just remove the -module-summary from the opt invocations.

There’s clang documentation on ThinLTO here:
and an old blog post on ThinLTO here:
but they don’t get into the details of the code implementation.

Hope that helps,

Hi Teresa:
Thank you, It’s very help for me.