[RFC PATCH v2] ld: Optionally nullify default PIE in all linker tests
Hans-Peter Nilsson
hp@bitrange.com
Sat Mar 29 01:32:54 GMT 2025
On Fri, 28 Mar 2025, Jens Remus wrote:
> Some distributions configure GCC with --enable-default-pie [1]. LLVM
> defaults Clang to CLANG_DEFAULT_PIE_ON_LINUX=ON [2]. This causes
> compiles to default to -fPIE and links to default to -pie, unless other
> options are explicitly given. As a consequence several linker tests
> are compiled and linked in unexpected ways and may even unexpectedly
> fail or pass.
>
> Add the configuration variable "NULLIFY_DEFAULT_PIE" to the linker test
> suite to optionally nullify default PIE, by prepending $NOPIE_CFLAGS to
> the compile flags and $NOPIE_LDFLAGS to the link flags for all linker
> tests. These are then overridden by any deviating compiler flags
> (e.g. -fPIC or -fPIE) and linker flags (e.g -pie or -shared) explicitly
> specified by the tests. Possible values of NULLIFY_DEFAULT_PIE are:
>
> 0: Do not nullify default PIE. (default)
> 1: Unconditionally prefix $NOPIE_CLFAGS and $NOPIE_LDFLAGS.
> auto: Prefix $NOPIE_CLFAGS and $NOPIE_LDFLAGS if compiler configured
> to default to PIE.
>
> NULLIFY_DEFAULT_PIE can for instance be specified via RUNTESTFLAGS:
>
> $ make check RUNTESTFLAGS="NULLIFY_DEFAULT_PIE=1"
>
> or in ~/.dejagnurc:
>
> # Prefix $NOPIE_CLFAGS and $NOPIE_LDFLAGS if compiler defaults to PIE.
> set nullify_default_pie "auto"
I can't help but thinking this is overthinking or
overengineering, sorry.
Why not keep it simple: for each test creating an executable and
that lacks an option mentioning specifying -pie -no-pie or
-static, add "-no-pie"? No $NOPIE_*. (And subsequently make
sure new tests mention such an option.) IIRC, that's the way
this (systems-having-different-pie-defaults) had been handled in
the past.
For extra credit, for those tests with the new specified option,
add an extra test with the inverted option, but as a separate
patch.
brgds, H-P
More information about the Binutils
mailing list