[PATCH] D123612: [Driver] Support linking to compiler-rt on AVR
Ben Shi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 6 19:28:52 PDT 2022
benshi001 added inline comments.
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:430
+ // libgcc distributed with avr-gcc always named 'libgcc.a' even on windows.
+ return (Twine("libclang_rt.") + Component + Arch + ".a").str();
+}
----------------
This method decides the file name of compiler-rt, it is expected to be
`libclang_rt.builtins-avrfamily.a`, such as
`libclang_rt.builtins-avr51.a`
`libclang_rt.builtins-avrtiny.a`
`libclang_rt.builtins-avrxmega3.a`
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:433
+
+std::string AVRToolChain::getCompilerRTPath() const {
+ // Return default path appended with "/avr", if it exists.
----------------
This method decides the library path of compiler-rt, it is
`$(RESOURCE_DIR)/lib/avr` or `$(RESOURCE_DIR)/lib/`. The resource dir is either explicitly specified via user option `-resource-dir` or has default value `$(LLVM_INSTALL_DIR)/lib/clang/$(LLVM_VERSION`. such as
`/opt/avr-tool-chain/lib/clang/14.0.1/lib/avr`
`/opt/avr-tool-chain/lib/clang/14.0.1/lib/`
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:444
+ToolChain::RuntimeLibType AVRToolChain::GetDefaultRuntimeLibType() const {
+ return GCCInstallation.isValid() ? ToolChain::RLT_Libgcc
+ : ToolChain::RLT_CompilerRT;
----------------
Currently we still use libgcc if `--rtlib` option is not specified.
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:482
+ (RtLib == ToolChain::RLT_Libgcc || RtLib == ToolChain::RLT_CompilerRT) &&
+ "unknown runtime library");
+
----------------
Currently we only allow `--rtlib=libgcc` and `--rtlib=compiler-rt`
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:510
+ if (RtLib == ToolChain::RLT_Libgcc)
+ CmdArgs.push_back(Args.MakeArgString("-L" + TC.getGCCInstallPath() +
+ "/" + SubPath));
----------------
If `--rtlib` is not specified or specified to `libgcc`, then we generate `-L$PATH_TO_LIBGCC`
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:542
+ // Link to libgcc.
+ if (RtLib == ToolChain::RLT_Libgcc)
+ CmdArgs.push_back("-lgcc");
----------------
If `--rtlib` is not specified or specified to `libgcc`, then we generate `-lgcc`
================
Comment at: clang/lib/Driver/ToolChains/AVR.cpp:555
+ // Link to compiler-rt.
+ if (RtLib == ToolChain::RLT_CompilerRT) {
+ std::string RtLib =
----------------
If `--rtlib=compiler-rt` is explicitly specified, we directly put the `libclang.builtins-avrxxx.a` as input file, other than `-lclang.builtins-avrxxx`, this is a tradition from other platforms, such as x86 and arm.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123612/new/
https://reviews.llvm.org/D123612
More information about the cfe-commits
mailing list