All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes
@ 2015-03-25 22:57 John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 1/4] configure: handle clang -nopie argument warning John Snow
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: John Snow @ 2015-03-25 22:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha

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

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

Regrettably, this is v5 because I overlooked deleting "--keep-tmpc" in the
previous version. Sorry mom, I let the homestead down. We'll be eating dirt
this winter. I can always go to the city for work, please don't cry.

v4:
- Enable ccache workaround for configurations without -Werror,
  to suppress warnings as well.
- Removed optimization from cc_has_warning_flag()
- Renamed ccache variable to ccache_cpp2

John Snow (3):
  configure: factor out supported flag check
  configure: silence glib unknown attribute __alloc_size__
  configure: Add workaround for ccache and clang

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

 configure | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 65 insertions(+), 16 deletions(-)

-- 
2.1.0

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

* [Qemu-devel] [PATCH v5 1/4] configure: handle clang -nopie argument warning
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
@ 2015-03-25 22:57 ` John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 2/4] configure: factor out supported flag check John Snow
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: John Snow @ 2015-03-25 22:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha

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 589798e..7a8637e 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] 9+ messages in thread

* [Qemu-devel] [PATCH v5 2/4] configure: factor out supported flag check
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 1/4] configure: handle clang -nopie argument warning John Snow
@ 2015-03-25 22:57 ` John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: John Snow @ 2015-03-25 22:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha

Factor out the function that checks if a compiler
flag is supported or not.

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

diff --git a/configure b/configure
index 7a8637e..3e71bb8 100755
--- a/configure
+++ b/configure
@@ -435,6 +435,12 @@ EOF
   compile_object
 }
 
+write_c_skeleton() {
+    cat > $TMPC <<EOF
+int main(void) { return 0; }
+EOF
+}
+
 if check_define __linux__ ; then
   targetos="Linux"
 elif check_define _WIN32 ; then
@@ -704,9 +710,7 @@ if test "$mingw32" = "yes" ; then
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
   LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
-cat > $TMPC << EOF
-int main(void) { return 0; }
-EOF
+  write_c_skeleton;
   if compile_prog "" "-liberty" ; then
     LIBS="-liberty $LIBS"
   fi
@@ -1438,10 +1442,7 @@ if test -z "$werror" ; then
 fi
 
 # check that the C compiler works.
-cat > $TMPC <<EOF
-int main(void) { return 0; }
-EOF
-
+write_c_skeleton;
 if compile_object ; then
   : C compiler works ok
 else
@@ -1489,16 +1490,20 @@ gcc_flags="-Wno-string-plus-int $gcc_flags"
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
 # so it's too error prone.
-cat > $TMPC << EOF
-int main(void) { return 0; }
-EOF
-for flag in $gcc_flags; do
+
+cc_has_warning_flag() {
+    write_c_skeleton;
+
     # 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/')"
-    if compile_prog "-Werror $optflag" "" ; then
-	QEMU_CFLAGS="$QEMU_CFLAGS $flag"
+    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
+    compile_prog "-Werror $optflag" ""
+}
+
+for flag in $gcc_flags; do
+    if cc_has_warning_flag $flag ; then
+        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
     fi
 done
 
-- 
2.1.0

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

* [Qemu-devel] [PATCH v5 3/4] configure: silence glib unknown attribute __alloc_size__
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 1/4] configure: handle clang -nopie argument warning John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 2/4] configure: factor out supported flag check John Snow
@ 2015-03-25 22:57 ` John Snow
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 4/4] configure: Add workaround for ccache and clang John Snow
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: John Snow @ 2015-03-25 22:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha

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 it is able to.

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

diff --git a/configure b/configure
index 3e71bb8..c02a26b 100755
--- a/configure
+++ b/configure
@@ -2789,6 +2789,18 @@ 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
+    if cc_has_warning_flag "-Wno-unknown-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] 9+ messages in thread

* [Qemu-devel] [PATCH v5 4/4] configure: Add workaround for ccache and clang
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
                   ` (2 preceding siblings ...)
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
@ 2015-03-25 22:57 ` John Snow
  2015-03-30 15:10 ` [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes Stefan Hajnoczi
  2015-05-05 10:05 ` Stefan Hajnoczi
  5 siblings, 0 replies; 9+ messages in thread
From: John Snow @ 2015-03-25 22:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow, stefanha

Test if ccache is interfering with semantic analysis of macros,
disable its habit of trying to compile already pre-processed
versions of code if so. ccache attempts to save time by compiling
pre-processed versions of code, but this disturbs clang's static
analysis enough to produce false positives.

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.

This workaround only activates for users using ccache AND clang,
and only if their configuration is observed to be producing warnings.
You may need to clear your ccache for builds started without -Werror,
as those may continue to produce warnings from the cache.

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 | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index c02a26b..dfd23ad 100755
--- a/configure
+++ b/configure
@@ -103,7 +103,8 @@ update_cxxflags() {
 }
 
 compile_object() {
-  do_cc $QEMU_CFLAGS -c -o $TMPO $TMPC
+  local_cflags="$1"
+  do_cc $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
 }
 
 compile_prog() {
@@ -4169,6 +4170,33 @@ if compile_prog "" "" ; then
     getauxval=yes
 fi
 
+########################################
+# check if ccache is interfering with
+# semantic analysis of macros
+
+ccache_cpp2=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 "-Werror"; then
+    ccache_cpp2=yes
+fi
+
 ##########################################
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -5461,6 +5489,10 @@ if test "$numa" = "yes"; then
   echo "CONFIG_NUMA=y" >> $config_host_mak
 fi
 
+if test "$ccache_cpp2" = "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] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
                   ` (3 preceding siblings ...)
  2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 4/4] configure: Add workaround for ccache and clang John Snow
@ 2015-03-30 15:10 ` Stefan Hajnoczi
  2015-04-28 19:32   ` John Snow
  2015-05-05 10:05 ` Stefan Hajnoczi
  5 siblings, 1 reply; 9+ messages in thread
From: Stefan Hajnoczi @ 2015-03-30 15:10 UTC (permalink / raw)
  To: John Snow; +Cc: peter.maydell, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 1215 bytes --]

On Wed, Mar 25, 2015 at 06:57:35PM -0400, John Snow wrote:
> QEMU does not compile cleanly under clang 3.5.0.  These patches eliminate the
> avalanche of warnings and make the build usable.
> 
> The result is that you *should* be able to use clang 3.5.0 *with* ccache and
> -Werror and produce all targets.
> 
> Regrettably, this is v5 because I overlooked deleting "--keep-tmpc" in the
> previous version. Sorry mom, I let the homestead down. We'll be eating dirt
> this winter. I can always go to the city for work, please don't cry.
> 
> v4:
> - Enable ccache workaround for configurations without -Werror,
>   to suppress warnings as well.
> - Removed optimization from cc_has_warning_flag()
> - Renamed ccache variable to ccache_cpp2
> 
> John Snow (3):
>   configure: factor out supported flag check
>   configure: silence glib unknown attribute __alloc_size__
>   configure: Add workaround for ccache and clang
> 
> Stefan Hajnoczi (1):
>   configure: handle clang -nopie argument warning
> 
>  configure | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 65 insertions(+), 16 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes
  2015-03-30 15:10 ` [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes Stefan Hajnoczi
@ 2015-04-28 19:32   ` John Snow
  2015-04-28 19:33     ` John Snow
  0 siblings, 1 reply; 9+ messages in thread
From: John Snow @ 2015-04-28 19:32 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: peter.maydell, qemu-devel, stefanha

On 03/30/2015 11:10 AM, Stefan Hajnoczi wrote:
> On Wed, Mar 25, 2015 at 06:57:35PM -0400, John Snow wrote:
>> QEMU does not compile cleanly under clang 3.5.0.  These patches eliminate the
>> avalanche of warnings and make the build usable.
>>
>> The result is that you *should* be able to use clang 3.5.0 *with* ccache and
>> -Werror and produce all targets.
>>
>> Regrettably, this is v5 because I overlooked deleting "--keep-tmpc" in the
>> previous version. Sorry mom, I let the homestead down. We'll be eating dirt
>> this winter. I can always go to the city for work, please don't cry.
>>
>> v4:
>> - Enable ccache workaround for configurations without -Werror,
>>    to suppress warnings as well.
>> - Removed optimization from cc_has_warning_flag()
>> - Renamed ccache variable to ccache_cpp2
>>
>> John Snow (3):
>>    configure: factor out supported flag check
>>    configure: silence glib unknown attribute __alloc_size__
>>    configure: Add workaround for ccache and clang
>>
>> Stefan Hajnoczi (1):
>>    configure: handle clang -nopie argument warning
>>
>>   configure | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
>>   1 file changed, 65 insertions(+), 16 deletions(-)
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
>

ping for 3.4

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

* Re: [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes
  2015-04-28 19:32   ` John Snow
@ 2015-04-28 19:33     ` John Snow
  0 siblings, 0 replies; 9+ messages in thread
From: John Snow @ 2015-04-28 19:33 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: peter.maydell, qemu-devel, stefanha



On 04/28/2015 03:32 PM, John Snow wrote:
> On 03/30/2015 11:10 AM, Stefan Hajnoczi wrote:
>> On Wed, Mar 25, 2015 at 06:57:35PM -0400, John Snow wrote:
>>> QEMU does not compile cleanly under clang 3.5.0.  These patches
>>> eliminate the
>>> avalanche of warnings and make the build usable.
>>>
>>> The result is that you *should* be able to use clang 3.5.0 *with*
>>> ccache and
>>> -Werror and produce all targets.
>>>
>>> Regrettably, this is v5 because I overlooked deleting "--keep-tmpc"
>>> in the
>>> previous version. Sorry mom, I let the homestead down. We'll be
>>> eating dirt
>>> this winter. I can always go to the city for work, please don't cry.
>>>
>>> v4:
>>> - Enable ccache workaround for configurations without -Werror,
>>>    to suppress warnings as well.
>>> - Removed optimization from cc_has_warning_flag()
>>> - Renamed ccache variable to ccache_cpp2
>>>
>>> John Snow (3):
>>>    configure: factor out supported flag check
>>>    configure: silence glib unknown attribute __alloc_size__
>>>    configure: Add workaround for ccache and clang
>>>
>>> Stefan Hajnoczi (1):
>>>    configure: handle clang -nopie argument warning
>>>
>>>   configure | 81
>>> ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
>>>   1 file changed, 65 insertions(+), 16 deletions(-)
>>
>> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
>>
>
> ping for 3.4

Actually, I think we can get this in for *2.4*. No need to wait until 2023.

--js

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

* Re: [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes
  2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
                   ` (4 preceding siblings ...)
  2015-03-30 15:10 ` [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes Stefan Hajnoczi
@ 2015-05-05 10:05 ` Stefan Hajnoczi
  5 siblings, 0 replies; 9+ messages in thread
From: Stefan Hajnoczi @ 2015-05-05 10:05 UTC (permalink / raw)
  To: John Snow; +Cc: peter.maydell, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 1256 bytes --]

On Wed, Mar 25, 2015 at 06:57:35PM -0400, John Snow wrote:
> QEMU does not compile cleanly under clang 3.5.0.  These patches eliminate the
> avalanche of warnings and make the build usable.
> 
> The result is that you *should* be able to use clang 3.5.0 *with* ccache and
> -Werror and produce all targets.
> 
> Regrettably, this is v5 because I overlooked deleting "--keep-tmpc" in the
> previous version. Sorry mom, I let the homestead down. We'll be eating dirt
> this winter. I can always go to the city for work, please don't cry.
> 
> v4:
> - Enable ccache workaround for configurations without -Werror,
>   to suppress warnings as well.
> - Removed optimization from cc_has_warning_flag()
> - Renamed ccache variable to ccache_cpp2
> 
> John Snow (3):
>   configure: factor out supported flag check
>   configure: silence glib unknown attribute __alloc_size__
>   configure: Add workaround for ccache and clang
> 
> Stefan Hajnoczi (1):
>   configure: handle clang -nopie argument warning
> 
>  configure | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 65 insertions(+), 16 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2015-05-05 10:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 22:57 [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes John Snow
2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 1/4] configure: handle clang -nopie argument warning John Snow
2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 2/4] configure: factor out supported flag check John Snow
2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 3/4] configure: silence glib unknown attribute __alloc_size__ John Snow
2015-03-25 22:57 ` [Qemu-devel] [PATCH v5 4/4] configure: Add workaround for ccache and clang John Snow
2015-03-30 15:10 ` [Qemu-devel] [PATCH v5 0/4] configure: clang 3.5.0 build fixes Stefan Hajnoczi
2015-04-28 19:32   ` John Snow
2015-04-28 19:33     ` John Snow
2015-05-05 10:05 ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.