[llvm-dev] 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?

417 views
Skip to first unread message

半缘君 via llvm-dev

unread,
Sep 24, 2020, 10:43:22 AM9/24/20
to llvm-dev
Hi:
    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.
   ZhengXianLi

Teresa Johnson via llvm-dev

unread,
Sep 24, 2020, 11:20:57 AM9/24/20
to 半缘君, llvm-dev
Hi ZhengXianLi,

The main entry point into the LTO LLVM code from lld is in https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp. Specifically see the call to ltoObj->run which launches the main LTO handling after all of the setup here: https://github.com/llvm/llvm-project/blob/master/lld/ELF/LTO.cpp#L309. Most of the actual LTO handling is in the LLVM LTO code here: https://github.com/llvm/llvm-project/blob/master/llvm/lib/LTO/LTO.cpp
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: https://clang.llvm.org/docs/ThinLTO.html
but they don't get into the details of the code implementation.

Hope that helps,
Teresa

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


--
Teresa Johnson | Software Engineer | tejo...@google.com |

半缘君 via llvm-dev

unread,
Sep 24, 2020, 7:38:55 PM9/24/20
to Teresa Johnson, llvm-dev
Hi Teresa:
   Thank you, It's very help for me.
 ZhengxianLi

------------------ 原始邮件 ------------------
发件人: "Teresa Johnson" <tejo...@google.com>;
发送时间: 2020年9月24日(星期四) 晚上11:20
收件人: "半缘君"<eng...@foxmail.com>;
抄送: "llvm-dev"<llvm...@lists.llvm.org>;
主题: Re: [llvm-dev] 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?
Reply all
Reply to author
Forward
0 new messages