On Mon, May 22, 2023 at 4:39 PM Richard Henderson <richard.hender...@linaro.org> wrote: > > + # What about linker flags? For a static build, no PIE is implied by > > -static > > + # which we added above. > > Is it though? That was the major problem at the time: it wasn't.
It's what configure was doing: if test "$static" = "yes"; then if test "$pie" != "no" && compile_prog "-Werror -fPIE -DPIE" "-static-pie"; then CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS" pie="yes" elif test "$pie" = "yes"; then error_exit "-static-pie not available due to missing toolchain support" else pie="no" QEMU_CFLAGS="-fno-pie $QEMU_CFLAGS" fi elif test "$pie" = "no"; then if compile_prog "-Werror -fno-pie" "-no-pie"; then CONFIGURE_CFLAGS="-fno-pie $CONFIGURE_CFLAGS" CONFIGURE_LDFLAGS="-no-pie $CONFIGURE_LDFLAGS" QEMU_CFLAGS="-fno-pie -no-pie $QEMU_CFLAGS" fi fi Note that the code to use -no-pie is only used if test "$static" = no. > Trying both now, e.g. '--static --disable-system --disable-tools > --disable-docs', > a link line contains > > ... -Wl,--as-needed -Wl,--no-undefined -pie -Wl,--whole-archive libhwcore.fa > ... > ^^^^ > > Where does that come from, and why isn't -no-pie the antidote? That comes from Meson's -Db_pie=true, but it is followed by -static-pie later in the command line so all is good. In other words, whatever we add second in the command line wins and that is good for executables; but it is a problem when -no-pie overrides -shared, thus messing up compilation of any shared library. Paolo