Message ID | 20200331035456.6494-9-richard.henderson@linaro.org |
---|---|
State | Accepted |
Commit | 127814629b32d5e0de2873d742e08cb9bd412af7 |
Headers | show |
Series | tcg patch queue | expand |
On 31/03/2020 05:54, Richard Henderson wrote: > Recent toolchains support static and pie at the same time. > > As with normal dynamic builds, allow --static to default to PIE > if supported by the toolchain. Allow --enable/--disable-pie to > override the default. > > Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > v2: Fix --disable-pie --static > v3: Update for QEMU_LDFLAGS. > --- > configure | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) 'configure --static" always produces a dynamically linked binary for me .../configure' '--disable-system' '--enable-user' '--disable-tools' '--static' ... CFLAGS -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g QEMU_CFLAGS -Werror -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/include/libdrm -I$(SRC_PATH)/capstone/include QEMU_LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -static-pie -m64 -fstack-protector-strong ... static build yes ... PIE yes make -j 8 m68k-linux-user/clean make -j 8 m68k-linux-user/all $ file m68k-linux-user/qemu-m68k m68k-linux-user/qemu-m68k: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=363ee31697e874085ec53c2af454a070c62647e1, for GNU/Linux 3.2.0, with debug_info, not stripped, too many notes (256) $ gdb --version GNU gdb (GDB) Fedora 8.3.50.20190824-30.fc31 Copyright (C) 2019 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. ld --version GNU ld version 2.32-31.fc31 Copyright (C) 2019 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty. Any idea of what happens? Thanks, Laurent
On 31/03/2020 15:34, Laurent Vivier wrote: > On 31/03/2020 05:54, Richard Henderson wrote: >> Recent toolchains support static and pie at the same time. >> >> As with normal dynamic builds, allow --static to default to PIE >> if supported by the toolchain. Allow --enable/--disable-pie to >> override the default. >> >> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >> --- >> v2: Fix --disable-pie --static >> v3: Update for QEMU_LDFLAGS. >> --- >> configure | 19 ++++++++++++------- >> 1 file changed, 12 insertions(+), 7 deletions(-) > > 'configure --static" always produces a dynamically linked binary for me > > .../configure' '--disable-system' '--enable-user' '--disable-tools' > '--static' > ... > CFLAGS -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g > QEMU_CFLAGS -Werror -pthread -I/usr/include/glib-2.0 > -I/usr/lib64/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE > -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes > -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes > -fno-strict-aliasing -fno-common -fwrapv -std=gnu99 > -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value > -Wno-missing-include-dirs -Wempty-body -Wnested-externs > -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers > -Wold-style-declaration -Wold-style-definition -Wtype-limits > -fstack-protector-strong -I/usr/include/libdrm > -I$(SRC_PATH)/capstone/include > QEMU_LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -static-pie > -m64 -fstack-protector-strong > ... > static build yes > ... > PIE yes > > make -j 8 m68k-linux-user/clean > make -j 8 m68k-linux-user/all > > $ file m68k-linux-user/qemu-m68k > m68k-linux-user/qemu-m68k: ELF 64-bit LSB pie executable, x86-64, > version 1 (GNU/Linux), dynamically linked, > BuildID[sha1]=363ee31697e874085ec53c2af454a070c62647e1, for GNU/Linux > 3.2.0, with debug_info, not stripped, too many notes (256) > > $ gdb --version > GNU gdb (GDB) Fedora 8.3.50.20190824-30.fc31 > Copyright (C) 2019 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > <http://gnu.org/licenses/gpl.html> > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. > ld --version > GNU ld version 2.32-31.fc31 > Copyright (C) 2019 Free Software Foundation, Inc. > This program is free software; you may redistribute it under the terms of > the GNU General Public License version 3 or (at your option) a later > version. > This program has absolutely no warranty. > > Any idea of what happens? In fact, the binary works well in a chroot, so it should be a bug in "file" command. Thanks, Laurent
On 3/31/20 6:44 AM, Laurent Vivier wrote: >> QEMU_LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -static-pie >> -m64 -fstack-protector-strong ... >> $ file m68k-linux-user/qemu-m68k >> m68k-linux-user/qemu-m68k: ELF 64-bit LSB pie executable, x86-64, >> version 1 (GNU/Linux), dynamically linked, >> BuildID[sha1]=363ee31697e874085ec53c2af454a070c62647e1, for GNU/Linux >> 3.2.0, with debug_info, not stripped, too many notes (256) ... > In fact, the binary works well in a chroot, so it should be a bug in > "file" command. I hadn't noticed that before, but yes, it appears that file needs an update for -static-pie. r~
diff --git a/configure b/configure index 481d5077f7..22870f3867 100755 --- a/configure +++ b/configure @@ -1067,7 +1067,6 @@ for opt do ;; --static) static="yes" - QEMU_LDFLAGS="-static $QEMU_LDFLAGS" QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS" ;; --mandir=*) mandir="$optarg" @@ -2089,11 +2088,6 @@ if test "$static" = "yes" ; then if test "$modules" = "yes" ; then error_exit "static and modules are mutually incompatible" fi - if test "$pie" = "yes" ; then - error_exit "static and pie are mutually incompatible" - else - pie="no" - fi fi # Unconditional check for compiler __thread support @@ -2124,7 +2118,18 @@ if compile_prog "-Werror -fno-pie" "-no-pie"; then LDFLAGS_NOPIE="-no-pie" fi -if test "$pie" = "no"; then +if test "$static" = "yes"; then + if test "$pie" != "no" && compile_prog "-fPIE -DPIE" "-static-pie"; then + QEMU_CFLAGS="-fPIE -DPIE $QEMU_CFLAGS" + QEMU_LDFLAGS="-static-pie $QEMU_LDFLAGS" + pie="yes" + elif test "$pie" = "yes"; then + error_exit "-static-pie not available due to missing toolchain support" + else + QEMU_LDFLAGS="-static $QEMU_LDFLAGS" + pie="no" + fi +elif test "$pie" = "no"; then QEMU_CFLAGS="$CFLAGS_NOPIE $QEMU_CFLAGS" QEMU_LDFLAGS="$LDFLAGS_NOPIE $QEMU_LDFLAGS" elif compile_prog "-fPIE -DPIE" "-pie"; then