[libc-commits] [libc] [libc] Omit -fpie from the full build (PR #208343)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Fri Jul 17 06:00:32 PDT 2026
kaladron wrote:
> > > > PIE should be the default, though. Is that cmake knob defaulted to yes?
> > >
> > > No, it's not. Whether PIE or PIC should be the default really depends on the target platform. For example, on baremetal we want neither. The compiler driver would ideally set the default for your target.
> > > We could conditionalize this only for baremetal but I think this should be done universally. None of the runtime libraries (i.e. libc++, libc++abi or libunwind) other than libc hardcode PIE or PIC and instead leave the decision onto the driver/user and I don't think libc should deviate here either.
> >
> > I agree with not hardcoding it, but a sane default here is -fPIE. Heck clang even does it:
> > clang/include/clang/Config/config.h.cmake:
> > /* Default to -fPIE and -pie on Linux. */ #cmakedefine01 CLANG_DEFAULT_PIE_ON_LINUX
> > On a desktop Linux system, PIE is an important mitigation strategy, and I think that the default out of the box should be the settings that the vast majority of people should default to. Can this instead shift these to defaults like Clang does per target?
>
> I agree with you, my point is that this decision should be up to the compiler driver. As you pointed out, Clang and GCC already default to `-fPIE` on Linux (unless someone explicitly overrides this setting in which case they probably have a reason to do so) so specifying `-fpie` in the libc build is superficial. On other platforms like baremetal, `-fpie` is undesirable. Even when building libc as a shared library for Linux (which we don't support yet), we'll want to use `-fPIC` rather than `-fpie`. That's why I'd prefer removing this flag and relying on the compiler driver to choose the right default, but if you prefer I can conditionalize this option and only set it when targeting Linux.
Thanks - I'd missed the distros setting the default on GCC from a few years ago. That overcomes my objections. (If someone builds their own compiler, builds their own C library, then they've signed up for learning opportunities. =P)
https://github.com/llvm/llvm-project/pull/208343
More information about the libc-commits
mailing list