[clang] Add necessary linker flags when -static-pie is enabled in BareMetal Toolchain (PR #147589)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 7 08:35:29 PDT 2025
================
@@ -599,11 +599,18 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const Driver &D = getToolChain().getDriver();
const llvm::Triple::ArchType Arch = TC.getArch();
const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
+ const bool IsStaticPIE = getStaticPIE(Args, TC);
if (!D.SysRoot.empty())
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
CmdArgs.push_back("-Bstatic");
+ if (IsStaticPIE) {
+ CmdArgs.push_back("-pie");
+ CmdArgs.push_back("--no-dynamic-linker");
----------------
MaskRay wrote:
`ld.bfd -pie a.o -o a` might have a default linker script like`/lib/ld64.so.1`. --no-dynamic-linker suppresses it.
In addition, the option used to have special implication in LLD before 994cea3f0a2d0caf4d66321ad5a06ab330144d89
For compatibility with both linkers, --no-dynamic-linker is recommended for driver -static-pie.
https://github.com/llvm/llvm-project/pull/147589
More information about the cfe-commits
mailing list