[clang] Add necessary linker flags when -static-pie is enabled in BareMetal Toolchain (PR #147589)

Garvit Gupta via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 8 04:31:17 PDT 2025


quic-garvgupt wrote:

> > "Gentle ping @petrhosek @smithp35 - if the changes look good and all your comments have been addressed, can you approve the PR as well. Thanks!"
> 
> Apologies for the delay. I've been away for the past couple of weeks on holiday and am just catching up.
> 
> I don't have any objections to the patch. I'm happy for this to go through using the existing approval. I'm confident that this won't adversely affect the LLVM bare-metal driver using compiler-rt, but I can't offer much experience with libgcc.
> 
> The one area I was concerned about was the lack of crtbeginS.o on the `aarch64-none-elf` and `arm-none-eabi` GNU toolchains. Looking into this, they have been configured with `--disable-shared` https://gitlab.arm.com/tooling/gnu-devtools-for-arm/-/blob/main/build-baremetal-toolchain.sh?ref_type=heads#L1157 so they just use the crtbegin.o and the GNU ld default -z notext even when static-pie is used. When I try using --static-pie on these toolchains the resulting binary is static but it is not PIE.
> 
> I think using crtbeginS in LLVM is fine as it is probably best that there is a link error for static-pie to catch the non-PIE nature of the output.

Thanks Peter for providing the information from the GNU toolchain side. I also think that if `static-pie` is used then it is not prudent to generate static binary, atleast not without any warning to user.

Thanks for the approval. I will merge the changes.

https://github.com/llvm/llvm-project/pull/147589


More information about the cfe-commits mailing list