Message ID | 20221209112409.184703-27-pbonzini@redhat.com |
---|---|
State | New |
Headers | show |
Series | Meson changes for QEMU 8.0 | expand |
Hi On Fri, Dec 9, 2022 at 3:38 PM Paolo Bonzini <pbonzini@redhat.com> wrote: > > Remove the only remaining uses of QEMU_CFLAGS. Now that no > feature tests are done in configure, it is possible to remove > CONFIGURE_CFLAGS and CONFIGURE_LDFLAGS as well. > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> > --- > configure | 79 ++++++++--------------------------------------------- > meson.build | 49 ++++++++++++++++++++++++++++++++- > 2 files changed, 59 insertions(+), 69 deletions(-) > > diff --git a/configure b/configure > index 6df61f4337e4..d5491fc3b986 100755 > --- a/configure > +++ b/configure > @@ -158,14 +158,14 @@ do_cc() { > > compile_object() { > local_cflags="$1" > - do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC > + do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC > } > > compile_prog() { > local_cflags="$1" > local_ldflags="$2" > - do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \ > - $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $local_ldflags > + do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \ > + $LDFLAGS $EXTRA_LDFLAGS $local_ldflags > } > > # symbolically link $1 to $2. Portable version of "ln -sf". > @@ -351,19 +351,6 @@ windres="${WINDRES-${cross_prefix}windres}" > pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}" > sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}" > > -# default flags for all hosts > -# We use -fwrapv to tell the compiler that we require a C dialect where > -# left shift of signed integers is well defined and has the expected > -# 2s-complement style results. (Both clang and gcc agree that it > -# provides these semantics.) > -QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv" > -QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" > - > -# Flags that are needed during configure but later taken care of by Meson > -CONFIGURE_CFLAGS="-std=gnu11 -Wall" > -CONFIGURE_LDFLAGS= > - > - > check_define() { > cat > $TMPC <<EOF > #if !defined($1) > @@ -442,21 +429,13 @@ openbsd) > darwin) > bsd="yes" > darwin="yes" > - # Disable attempts to use ObjectiveC features in os/object.h since they > - # won't work when we're compiling with gcc as a C compiler. > - QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" > ;; > sunos) > solaris="yes" > make="${MAKE-gmake}" > -# needed for CMSG_ macros in sys/socket.h > - QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS" > -# needed for TIOCWIN* defines in termios.h > - QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS" > ;; > haiku) > pie="no" > - QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS" > ;; > linux) > linux="yes" > @@ -589,8 +568,6 @@ fi > > if test "$mingw32" = "yes" ; then > EXESUF=".exe" > - # MinGW needs -mthreads for TLS and macro _MT. > - CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS" > prefix="/qemu" > bindir="" > qemu_suffix="" > @@ -1102,59 +1079,26 @@ static THREAD int tls_var; > int main(void) { return tls_var; } > EOF > > -# Meson currently only handles pie as a boolean for now so if we have > -# explicitly disabled PIE we need to extend our cflags because it wont. > 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 -no-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" > +elif test "$pie" != "no"; then > + if compile_prog "-Werror -fPIE -DPIE" "-pie"; then > + pie="yes" > + elif test "$pie" = "yes"; then > + error_exit "PIE not available due to missing toolchain support" > + else > + echo "Disabling PIE due to missing toolchain support" > + pie="no" > fi > -elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then > - CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS" > - CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS" > - pie="yes" > -elif test "$pie" = "yes"; then > - error_exit "PIE not available due to missing toolchain support" > -else > - echo "Disabling PIE due to missing toolchain support" > - pie="no" > fi > > ########################################## > -# __sync_fetch_and_and requires at least -march=i486. Many toolchains > -# use i686 as default anyway, but for those that don't, an explicit > -# specification is necessary > - > -if test "$cpu" = "i386"; then > - cat > $TMPC << EOF > -static int sfaa(int *ptr) > -{ > - return __sync_fetch_and_and(ptr, 0); > -} > - > -int main(void) > -{ > - int val = 42; > - val = __sync_val_compare_and_swap(&val, 0, 1); > - sfaa(&val); > - return val; > -} > -EOF > - if ! compile_prog "" "" ; then > - QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS" > - fi > -fi > > if test -z "${target_list+xxx}" ; then > default_targets=yes > @@ -1834,7 +1778,6 @@ echo "MESON=$meson" >> $config_host_mak > echo "NINJA=$ninja" >> $config_host_mak > echo "PKG_CONFIG=${pkg_config_exe}" >> $config_host_mak > echo "CC=$cc" >> $config_host_mak > -echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak > echo "EXESUF=$EXESUF" >> $config_host_mak > > # use included Linux headers > diff --git a/meson.build b/meson.build > index 4ec8104b73a3..01c6ac0045bc 100644 > --- a/meson.build > +++ b/meson.build > @@ -190,10 +190,50 @@ endif > # Compiler flags # > ################## > > -qemu_common_flags = config_host['QEMU_CFLAGS'].split() > +# default flags for all hosts > +# We use -fwrapv to tell the compiler that we require a C dialect where > +# left shift of signed integers is well defined and has the expected > +# 2s-complement style results. (Both clang and gcc agree that it > +# provides these semantics.) > + > +qemu_common_flags = [ > + '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', > + '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] > qemu_cflags = [] > qemu_ldflags = [] > > +if targetos == 'darwin' > + # Disable attempts to use ObjectiveC features in os/object.h since they > + # won't work when we're compiling with gcc as a C compiler. > + qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0' > +elif targetos == 'solaris' > + # needed for CMSG_ macros in sys/socket.h > + qemu_common_flags += '-D_XOPEN_SOURCE=600' > + # needed for TIOCWIN* defines in termios.h > + qemu_common_flags += '-D__EXTENSIONS__' > +elif targetos == 'haiku' > + qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC'] > +endif > + > +# __sync_fetch_and_and requires at least -march=i486. Many toolchains > +# use i686 as default anyway, but for those that don't, an explicit > +# specification is necessary > +if host_arch == 'i386' and not cc.links(''' > + static int sfaa(int *ptr) > + { > + return __sync_fetch_and_and(ptr, 0); > + } > + > + int main(void) > + { > + int val = 42; > + val = __sync_val_compare_and_swap(&val, 0, 1); > + sfaa(&val); > + return val; > + }''') > + qemu_common_flags = ['-march=i486'] + qemu_common_flags > +endif > + > if get_option('gprof') > qemu_common_flags += ['-p'] > qemu_ldflags += ['-p'] > @@ -203,6 +243,13 @@ if get_option('prefer_static') > qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static' > endif > > +# Meson currently only handles pie as a boolean for now, so if the user > +# has explicitly disabled PIE we need to extend our cflags. > +if not get_option('b_pie') > + qemu_cflags += cc.get_supported_arguments('-fno-pie') > + qemu_ldflags += cc.get_supported_link_arguments('-no-pie') > +endif > + > if not get_option('stack_protector').disabled() > stack_protector_probe = ''' > int main(int argc, char *argv[]) > -- > 2.38.1 > >
diff --git a/configure b/configure index 6df61f4337e4..d5491fc3b986 100755 --- a/configure +++ b/configure @@ -158,14 +158,14 @@ do_cc() { compile_object() { local_cflags="$1" - do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC + do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -c -o $TMPO $TMPC } compile_prog() { local_cflags="$1" local_ldflags="$2" - do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \ - $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $local_ldflags + do_cc $CFLAGS $EXTRA_CFLAGS $local_cflags -o $TMPE $TMPC \ + $LDFLAGS $EXTRA_LDFLAGS $local_ldflags } # symbolically link $1 to $2. Portable version of "ln -sf". @@ -351,19 +351,6 @@ windres="${WINDRES-${cross_prefix}windres}" pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}" sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}" -# default flags for all hosts -# We use -fwrapv to tell the compiler that we require a C dialect where -# left shift of signed integers is well defined and has the expected -# 2s-complement style results. (Both clang and gcc agree that it -# provides these semantics.) -QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv" -QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" - -# Flags that are needed during configure but later taken care of by Meson -CONFIGURE_CFLAGS="-std=gnu11 -Wall" -CONFIGURE_LDFLAGS= - - check_define() { cat > $TMPC <<EOF #if !defined($1) @@ -442,21 +429,13 @@ openbsd) darwin) bsd="yes" darwin="yes" - # Disable attempts to use ObjectiveC features in os/object.h since they - # won't work when we're compiling with gcc as a C compiler. - QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" ;; sunos) solaris="yes" make="${MAKE-gmake}" -# needed for CMSG_ macros in sys/socket.h - QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS" -# needed for TIOCWIN* defines in termios.h - QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS" ;; haiku) pie="no" - QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS" ;; linux) linux="yes" @@ -589,8 +568,6 @@ fi if test "$mingw32" = "yes" ; then EXESUF=".exe" - # MinGW needs -mthreads for TLS and macro _MT. - CONFIGURE_CFLAGS="-mthreads $CONFIGURE_CFLAGS" prefix="/qemu" bindir="" qemu_suffix="" @@ -1102,59 +1079,26 @@ static THREAD int tls_var; int main(void) { return tls_var; } EOF -# Meson currently only handles pie as a boolean for now so if we have -# explicitly disabled PIE we need to extend our cflags because it wont. 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 -no-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" +elif test "$pie" != "no"; then + if compile_prog "-Werror -fPIE -DPIE" "-pie"; then + pie="yes" + elif test "$pie" = "yes"; then + error_exit "PIE not available due to missing toolchain support" + else + echo "Disabling PIE due to missing toolchain support" + pie="no" fi -elif compile_prog "-Werror -fPIE -DPIE" "-pie"; then - CONFIGURE_CFLAGS="-fPIE -DPIE $CONFIGURE_CFLAGS" - CONFIGURE_LDFLAGS="-pie $CONFIGURE_LDFLAGS" - pie="yes" -elif test "$pie" = "yes"; then - error_exit "PIE not available due to missing toolchain support" -else - echo "Disabling PIE due to missing toolchain support" - pie="no" fi ########################################## -# __sync_fetch_and_and requires at least -march=i486. Many toolchains -# use i686 as default anyway, but for those that don't, an explicit -# specification is necessary - -if test "$cpu" = "i386"; then - cat > $TMPC << EOF -static int sfaa(int *ptr) -{ - return __sync_fetch_and_and(ptr, 0); -} - -int main(void) -{ - int val = 42; - val = __sync_val_compare_and_swap(&val, 0, 1); - sfaa(&val); - return val; -} -EOF - if ! compile_prog "" "" ; then - QEMU_CFLAGS="-march=i486 $QEMU_CFLAGS" - fi -fi if test -z "${target_list+xxx}" ; then default_targets=yes @@ -1834,7 +1778,6 @@ echo "MESON=$meson" >> $config_host_mak echo "NINJA=$ninja" >> $config_host_mak echo "PKG_CONFIG=${pkg_config_exe}" >> $config_host_mak echo "CC=$cc" >> $config_host_mak -echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak # use included Linux headers diff --git a/meson.build b/meson.build index 4ec8104b73a3..01c6ac0045bc 100644 --- a/meson.build +++ b/meson.build @@ -190,10 +190,50 @@ endif # Compiler flags # ################## -qemu_common_flags = config_host['QEMU_CFLAGS'].split() +# default flags for all hosts +# We use -fwrapv to tell the compiler that we require a C dialect where +# left shift of signed integers is well defined and has the expected +# 2s-complement style results. (Both clang and gcc agree that it +# provides these semantics.) + +qemu_common_flags = [ + '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', + '-fno-strict-aliasing', '-fno-common', '-fwrapv' ] qemu_cflags = [] qemu_ldflags = [] +if targetos == 'darwin' + # Disable attempts to use ObjectiveC features in os/object.h since they + # won't work when we're compiling with gcc as a C compiler. + qemu_common_flags += '-DOS_OBJECT_USE_OBJC=0' +elif targetos == 'solaris' + # needed for CMSG_ macros in sys/socket.h + qemu_common_flags += '-D_XOPEN_SOURCE=600' + # needed for TIOCWIN* defines in termios.h + qemu_common_flags += '-D__EXTENSIONS__' +elif targetos == 'haiku' + qemu_common_flags += ['-DB_USE_POSITIVE_POSIX_ERRORS', '-D_BSD_SOURCE', '-fPIC'] +endif + +# __sync_fetch_and_and requires at least -march=i486. Many toolchains +# use i686 as default anyway, but for those that don't, an explicit +# specification is necessary +if host_arch == 'i386' and not cc.links(''' + static int sfaa(int *ptr) + { + return __sync_fetch_and_and(ptr, 0); + } + + int main(void) + { + int val = 42; + val = __sync_val_compare_and_swap(&val, 0, 1); + sfaa(&val); + return val; + }''') + qemu_common_flags = ['-march=i486'] + qemu_common_flags +endif + if get_option('gprof') qemu_common_flags += ['-p'] qemu_ldflags += ['-p'] @@ -203,6 +243,13 @@ if get_option('prefer_static') qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static' endif +# Meson currently only handles pie as a boolean for now, so if the user +# has explicitly disabled PIE we need to extend our cflags. +if not get_option('b_pie') + qemu_cflags += cc.get_supported_arguments('-fno-pie') + qemu_ldflags += cc.get_supported_link_arguments('-no-pie') +endif + if not get_option('stack_protector').disabled() stack_protector_probe = ''' int main(int argc, char *argv[])
Remove the only remaining uses of QEMU_CFLAGS. Now that no feature tests are done in configure, it is possible to remove CONFIGURE_CFLAGS and CONFIGURE_LDFLAGS as well. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- configure | 79 ++++++++--------------------------------------------- meson.build | 49 ++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 69 deletions(-)