qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes
@ 2015-03-18 22:43 John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls John Snow
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Snow @ 2015-03-18 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha, kbastian

QEMU does not compile cleanly under clang 3.5.0.  These patches eliminate the
avalanche of warnings and make the build usable.

v2:
 - Stole the series from Stefan
 - No changes to the -nopie patch, which I think was fine.
 - Fixed the -Wno-unknown-attributes patch.
 - Added a tricore fix for -Wabsolute-value
 - Added a workaround to help suppress ccache warnings

The result is that you *should* be able to use clang 3.5.0 *with* ccache and
-Werror and produce all targets.

John Snow (3):
  tricore: remove no-op abs() calls
  configure: silence glib unknown attribute __alloc_size__
  configure: Add workaround for ccache and clang

Stefan Hajnoczi (1):
  configure: handle clang -nopie argument warning

 configure                  | 48 +++++++++++++++++++++++++++++++++++++++++++++-
 target-tricore/op_helper.c | 12 ++++++------
 2 files changed, 53 insertions(+), 7 deletions(-)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls
  2015-03-18 22:43 [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes John Snow
@ 2015-03-18 22:43 ` John Snow
  2015-03-18 22:51   ` Peter Maydell
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 2/4] configure: handle clang -nopie argument warning John Snow
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: John Snow @ 2015-03-18 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha, kbastian

Calling abs() on a uint32_t is a no-op, so remove it.
clang 3.5.0 will not compile this if -Werror is set,
throwing a -Wabsolute-value warning.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 target-tricore/op_helper.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/target-tricore/op_helper.c b/target-tricore/op_helper.c
index 97b0c8b..5b82223 100644
--- a/target-tricore/op_helper.c
+++ b/target-tricore/op_helper.c
@@ -1953,9 +1953,9 @@ uint64_t helper_dvinit_b_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
         quotient_sign = 1;
     }
 
-    abs_sig_dividend = abs(r1) >> 7;
-    abs_base_dividend = abs(r1) & 0x7f;
-    abs_divisor = abs(r1);
+    abs_sig_dividend = r1 >> 7;
+    abs_base_dividend = r1 & 0x7f;
+    abs_divisor = r1;
     /* calc overflow */
     env->PSW_USB_V = 0;
     if ((quotient_sign) && (abs_divisor)) {
@@ -2003,9 +2003,9 @@ uint64_t helper_dvinit_h_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
         quotient_sign = 1;
     }
 
-    abs_sig_dividend = abs(r1) >> 7;
-    abs_base_dividend = abs(r1) & 0x7f;
-    abs_divisor = abs(r1);
+    abs_sig_dividend = r1 >> 7;
+    abs_base_dividend = r1 & 0x7f;
+    abs_divisor = r1;
     /* calc overflow */
     env->PSW_USB_V = 0;
     if ((quotient_sign) && (abs_divisor)) {
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 2/4] configure: handle clang -nopie argument warning
  2015-03-18 22:43 [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls John Snow
@ 2015-03-18 22:43 ` John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 4/4] configure: Add workaround for ccache and clang John Snow
  3 siblings, 0 replies; 8+ messages in thread
From: John Snow @ 2015-03-18 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha, kbastian

From: Stefan Hajnoczi <stefanha@redhat.com>

gcc 4.9.2 treats -nopie as an error:

  cc: error: unrecognized command line option ‘-nopie’

clang 3.5.0 treats -nopie as a warning:

  clang: warning: argument unused during compilation: '-nopie'

The causes ./configure to fail with clang:

  ERROR: configure test passed without -Werror but failed with -Werror.

Make the -nopie test use -Werror so that compile_prog works for both gcc
and clang.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index f74a6fd..062df84 100755
--- a/configure
+++ b/configure
@@ -1589,7 +1589,7 @@ EOF
     fi
   fi
 
-  if compile_prog "-fno-pie" "-nopie"; then
+  if compile_prog "-Werror -fno-pie" "-nopie"; then
     CFLAGS_NOPIE="-fno-pie"
     LDFLAGS_NOPIE="-nopie"
   fi
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__
  2015-03-18 22:43 [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls John Snow
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 2/4] configure: handle clang -nopie argument warning John Snow
@ 2015-03-18 22:43 ` John Snow
  2015-03-18 22:55   ` Peter Maydell
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 4/4] configure: Add workaround for ccache and clang John Snow
  3 siblings, 1 reply; 8+ messages in thread
From: John Snow @ 2015-03-18 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha, kbastian

v2: We must test compilation with the right glib flags,
    otherwise the test compile will always fail.
    In addition, test-compile the warning flag to make
    sure we can use it.

The glib headers use GCC attributes.  Unfortunately the __GNUC__ and
__GNUC_MINOR__ version macros are also defined by clang, but clang
doesn't support the same attributes as GCC.

clang 3.5.0 does not support the __alloc_size__ attribute:

  https://github.com/llvm-mirror/clang/commit/c047507a9a79e89fc8339e074fa72822a7e7ea73

The following warning is produced:

  gstrfuncs.h:257:44: warning: unknown attribute '__alloc_size__' ignored [-Wunknown-attributes]
        G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
          gmacros.h:67:45: note: expanded from macro 'G_GNUC_ALLOC_SIZE'
                #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))

This patch checks whether glib headers cause warnings and disables
-Wunknown-attributes if that is the case.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
 configure | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/configure b/configure
index 062df84..9db53ba 100755
--- a/configure
+++ b/configure
@@ -2784,6 +2784,21 @@ if ! $pkg_config --atleast-version=2.38 glib-2.0; then
     glib_subprocess=no
 fi
 
+# Silence clang 3.5.0 warnings about glib attribute __alloc_size__ usage
+cat > $TMPC << EOF
+#include <glib.h>
+int main(void) { return 0; }
+EOF
+if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
+    cat > $TMPC << EOF
+    int main(void) { return 0; }
+EOF
+    if compile_prog "-Werror -Wunknown-attributes" ""; then
+        glib_cflags="-Wno-unknown-attributes $glib_cflags"
+        CFLAGS="-Wno-unknown-attributes $CFLAGS"
+    fi
+fi
+
 ##########################################
 # SHA command probe for modules
 if test "$modules" = yes; then
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH v2 4/4] configure: Add workaround for ccache and clang
  2015-03-18 22:43 [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes John Snow
                   ` (2 preceding siblings ...)
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
@ 2015-03-18 22:43 ` John Snow
  3 siblings, 0 replies; 8+ messages in thread
From: John Snow @ 2015-03-18 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha, kbastian

Test if ccache is interfering with our life, and
disable its habit of trying to compile already pre-processed
versions of code if so.

In particular, clang has different semantic warnings based on
if the warning arose from a macro or not. By trying to build
preprocessed versions of code, we get more errors than we should.

ccache allows us to disable this feature, opting instead to
compile the original version instead of its preprocessed version.

This makes ccache much slower for cache misses, but at least it
becomes usable with QEMU/clang.

Thanks to Peter Eisentraut for his writeup on the issue:
http://peter.eisentraut.org/blog/2014/12/01/ccache-and-clang-part-3/

Signed-off-by: John Snow <jsnow@redhat.com>
---
 configure | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/configure b/configure
index 9db53ba..f242181 100755
--- a/configure
+++ b/configure
@@ -4167,6 +4167,33 @@ if compile_prog "" "" ; then
     getauxval=yes
 fi
 
+########################################
+# check if ccache is interfering with
+# semantic analysis of macros
+
+ccache=no
+cat > $TMPC << EOF
+static const int Z = 1;
+#define fn() ({ Z; })
+#define TAUT(X) ((X) == Z)
+#define PAREN(X, Y) (X == Y)
+#define ID(X) (X)
+int main(int argc, char *argv[])
+{
+    int x = 0, y = 0;
+    x = ID(x);
+    x = fn();
+    fn();
+    if (PAREN(x, y)) return 0;
+    if (TAUT(Z)) return 0;
+    return 0;
+}
+EOF
+
+if ! compile_object; then
+    ccache=yes
+fi
+
 ##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -5457,6 +5484,10 @@ if test "$numa" = "yes"; then
   echo "CONFIG_NUMA=y" >> $config_host_mak
 fi
 
+if test "$ccache" = "yes"; then
+  echo "export CCACHE_CPP2=y" >> $config_host_mak
+fi
+
 # build tree in object directory in case the source is not in the current directory
 DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests"
 DIRS="$DIRS fsdev"
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls John Snow
@ 2015-03-18 22:51   ` Peter Maydell
  2015-03-18 22:55     ` John Snow
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2015-03-18 22:51 UTC (permalink / raw)
  To: John Snow; +Cc: Bastian Koppelmann, QEMU Developers, Stefan Hajnoczi

On 18 March 2015 at 22:43, John Snow <jsnow@redhat.com> wrote:
> Calling abs() on a uint32_t is a no-op, so remove it.
> clang 3.5.0 will not compile this if -Werror is set,
> throwing a -Wabsolute-value warning.
>
> Signed-off-by: John Snow <jsnow@redhat.com>

This is probably the wrong fix (ie it silences the
warning rather than fixing the bug). See
http://patchwork.ozlabs.org/patch/447585/

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls
  2015-03-18 22:51   ` Peter Maydell
@ 2015-03-18 22:55     ` John Snow
  0 siblings, 0 replies; 8+ messages in thread
From: John Snow @ 2015-03-18 22:55 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Bastian Koppelmann, QEMU Developers, Stefan Hajnoczi



On 03/18/2015 06:51 PM, Peter Maydell wrote:
> On 18 March 2015 at 22:43, John Snow <jsnow@redhat.com> wrote:
>> Calling abs() on a uint32_t is a no-op, so remove it.
>> clang 3.5.0 will not compile this if -Werror is set,
>> throwing a -Wabsolute-value warning.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>
> This is probably the wrong fix (ie it silences the
> warning rather than fixing the bug). See
> http://patchwork.ozlabs.org/patch/447585/
>
> thanks
> -- PMM
>

Ah, I missed that there was another patch out there and a deeper bug. I 
thought this was a harmless abs() inclusion, but I didn't look too 
deeply at it.

I am fine with dropping this patch if a more comprehensive change is in 
the works, but the other three should still stand.

--js

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__
  2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
@ 2015-03-18 22:55   ` Peter Maydell
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2015-03-18 22:55 UTC (permalink / raw)
  To: John Snow; +Cc: Bastian Koppelmann, QEMU Developers, Stefan Hajnoczi

On 18 March 2015 at 22:43, John Snow <jsnow@redhat.com> wrote:
> v2: We must test compilation with the right glib flags,
>     otherwise the test compile will always fail.
>     In addition, test-compile the warning flag to make
>     sure we can use it.
>
> The glib headers use GCC attributes.  Unfortunately the __GNUC__ and
> __GNUC_MINOR__ version macros are also defined by clang, but clang
> doesn't support the same attributes as GCC.
>
> clang 3.5.0 does not support the __alloc_size__ attribute:
>
>   https://github.com/llvm-mirror/clang/commit/c047507a9a79e89fc8339e074fa72822a7e7ea73
>
> The following warning is produced:
>
>   gstrfuncs.h:257:44: warning: unknown attribute '__alloc_size__' ignored [-Wunknown-attributes]
>         G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
>           gmacros.h:67:45: note: expanded from macro 'G_GNUC_ALLOC_SIZE'
>                 #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
>
> This patch checks whether glib headers cause warnings and disables
> -Wunknown-attributes if that is the case.

Is it worth factoring out the body of the "see if we support
this long list of gcc warning flags?" check into a function?

cc_has_warning_flag () {
    # Use the positive sense of the flag when testing for -Wno-wombat
    # support (gcc will happily accept the -Wno- form of unknown
    # warning options).
    optflag="$(echo $flag | sed -e 's/^-Wno-/-W/')"
    compile_prog "-Werror $optflag" ""
}

and then

for flag in $gcc_flags; do
    if cc_has_warning_flag $flag
        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
    fi
done

where we currently inline that sed/compile_prog. (Untested :-))

-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-18 22:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-18 22:43 [Qemu-devel] [PATCH v2 0/4] configure: clang 3.5.0 build fixes John Snow
2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 1/4] tricore: remove no-op abs() calls John Snow
2015-03-18 22:51   ` Peter Maydell
2015-03-18 22:55     ` John Snow
2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 2/4] configure: handle clang -nopie argument warning John Snow
2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
2015-03-18 22:55   ` Peter Maydell
2015-03-18 22:43 ` [Qemu-devel] [PATCH v2 4/4] configure: Add workaround for ccache and clang John Snow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).