gcc: build with --enable-default-pie configure option

Rather than implementing this at the wrapper level (which has been
attempted but not merged in # 252310 and # 205031), configuring GCC
directly with --enable-default-pie is simple and matches mainstream
distribution practices. Packages that cannot build with PIE can
explicitly pass -no-pie when needed, and mostly already do
due to the prevalence of GCCs built with this flag.

Requires followup to decide what to do with "pie" flag.
This commit is contained in:
Luna Nova
2025-09-01 08:41:40 -07:00
parent 58b0870c75
commit ccc56d1a79
5 changed files with 16 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
enablePlugin,
disableGdbPlugin ? !enablePlugin,
enableShared,
enableDefaultPie,
targetPrefix,
langC,
@@ -279,6 +280,9 @@ let
"libat_cv_have_ifunc=no"
"--disable-gnu-indirect-function"
]
++ lib.optionals enableDefaultPie [
"--enable-default-pie"
]
++ lib.optionals langJit [
"--enable-host-shared"
]

View File

@@ -19,6 +19,7 @@
cargo,
staticCompiler ? false,
enableShared ? stdenv.targetPlatform.hasSharedLibraries,
enableDefaultPie ? true,
enableLTO ? stdenv.hostPlatform.hasSharedLibraries,
texinfo ? null,
perl ? null, # optional, for texi2pod (then pod2man)
@@ -137,6 +138,7 @@ let
darwin
disableBootstrap
disableGdbPlugin
enableDefaultPie
enableLTO
enableMultilib
enablePlugin

View File

@@ -193,6 +193,7 @@ stdenv.mkDerivation (finalAttrs: {
"--disable-multilib"
"--disable-nls"
"--disable-shared"
"--enable-default-pie"
"--enable-languages=${
lib.concatStrings (
lib.intersperse "," (

View File

@@ -54,9 +54,10 @@ stdenv.mkDerivation (finalAttrs: {
# Drop in libiberty, as external builds are not expected
cd "$buildRoot"
(
mkdir -p build-${stdenv.buildPlatform.config}/libiberty/
cd build-${stdenv.buildPlatform.config}/libiberty/
ln -s ${buildPackages.libiberty}/lib/libiberty.a ./
mkdir -p "build-${stdenv.buildPlatform.config}/libiberty/pic"
cd "build-${stdenv.buildPlatform.config}/libiberty/"
ln -s "${buildPackages.libiberty}/lib/libiberty.a" ./
ln -s "${buildPackages.libiberty}/lib/libiberty_pic.a" pic/libiberty.a
)
mkdir -p "$buildRoot/gcc"
cd "$buildRoot/gcc"

View File

@@ -425,6 +425,11 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
# ...-binutils-patchelfed-ld-2.40/bin/ld: ...-xgcc-13.0.0/libexec/gcc/x86_64-unknown-linux-gnu/13.0.1/liblto_plugin.so:
# error loading plugin: ...-bootstrap-tools/lib/libpthread.so.0: undefined symbol: __libc_vfork, version GLIBC_PRIVATE
enableLTO = false;
# relocatable libs may not be available in the bootstrap
# which will cause compilation to fail with
# configure: error: C compiler cannot create executables
enableDefaultPie = false;
}
)).overrideAttrs
(a: {