All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
       [not found] <20180928142533.8451-1-peter.maydell@linaro.org>
@ 2018-10-04 16:55 ` Laurent Vivier
  2018-10-05  0:28   ` Laurent Vivier
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2018-10-04 16:55 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Riku Voipio, Richard Henderson, patches

Le 28/09/2018 à 16:25, Peter Maydell a écrit :
> Our __get_user_e() and __put_user_e() macros cause newer versions
> of clang to generate false-positive -Waddress-of-packed-member
> warnings if they are passed the address of a member of a packed
> struct (see https://bugs.llvm.org/show_bug.cgi?id=39113).
> Suppress these using the _Pragma() operator.
> 
> To put in the pragmas we need to convert the macros from
> expressions to statements, but all the callsites effectively
> treat them as statements already so this is OK.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  linux-user/qemu.h | 57 +++++++++++++++++++++++++++++++----------------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 

Applied to my linux-user branch.

Thanks,
Laurent

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-04 16:55 ` [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e Laurent Vivier
@ 2018-10-05  0:28   ` Laurent Vivier
  2018-10-05  9:10     ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2018-10-05  0:28 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Riku Voipio, Richard Henderson, patches

On 04/10/2018 18:55, Laurent Vivier wrote:
> Le 28/09/2018 à 16:25, Peter Maydell a écrit :
>> Our __get_user_e() and __put_user_e() macros cause newer versions
>> of clang to generate false-positive -Waddress-of-packed-member
>> warnings if they are passed the address of a member of a packed
>> struct (see https://bugs.llvm.org/show_bug.cgi?id=39113).
>> Suppress these using the _Pragma() operator.
>>
>> To put in the pragmas we need to convert the macros from
>> expressions to statements, but all the callsites effectively
>> treat them as statements already so this is OK.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>>  linux-user/qemu.h | 57 +++++++++++++++++++++++++++++++----------------
>>  1 file changed, 38 insertions(+), 19 deletions(-)
>>
> 
> Applied to my linux-user branch.

I have the following error when building on Fedora 28 and gcc (GCC)
8.1.1 20180712 (Red Hat 8.1.1-5)

  CC      aarch64_be-linux-user/target/arm/arm-semi.o
.../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
.../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
GCC diagnostic’ kind [-Werror=pragmas]

Perhaps you should use a "#if defined(__clang__)" to apply your fix only
to clang?

Thanks,
Laurent

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-05  0:28   ` Laurent Vivier
@ 2018-10-05  9:10     ` Peter Maydell
  2018-10-05  9:43       ` Laurent Vivier
  2018-10-05 15:25       ` Richard Henderson
  0 siblings, 2 replies; 9+ messages in thread
From: Peter Maydell @ 2018-10-05  9:10 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: QEMU Developers, Riku Voipio, Richard Henderson, patches

On 5 October 2018 at 01:28, Laurent Vivier <laurent@vivier.eu> wrote:
> I have the following error when building on Fedora 28 and gcc (GCC)
> 8.1.1 20180712 (Red Hat 8.1.1-5)
>
>   CC      aarch64_be-linux-user/target/arm/arm-semi.o
> .../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
> .../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
> GCC diagnostic’ kind [-Werror=pragmas]
>
> Perhaps you should use a "#if defined(__clang__)" to apply your fix only
> to clang?

I did test on gcc, but not that version. The point of the
   _Pragma("GCC diagnostic ignored \"-Wpragmas\"");
line is to suppress that error (which it does on my gcc 5)
so I don't know why your gcc is complaining :-(

If you add an extra diagnostic push, so:

+        _Pragma("GCC diagnostic push");                                     \
+        _Pragma("GCC diagnostic ignored \"-Wpragmas\"");                    \
+        _Pragma("GCC diagnostic push");                                     \
+        _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");   \

and then a balancing extra

+        _Pragma("GCC diagnostic pop");                                      \

at the end, I don't suppose that helps?

(I generally prefer to avoid marking things as clang- or gcc-
specific where I can.)

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-05  9:10     ` Peter Maydell
@ 2018-10-05  9:43       ` Laurent Vivier
  2018-10-05 15:25       ` Richard Henderson
  1 sibling, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2018-10-05  9:43 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Riku Voipio, Richard Henderson, patches

On 05/10/2018 11:10, Peter Maydell wrote:
> On 5 October 2018 at 01:28, Laurent Vivier <laurent@vivier.eu> wrote:
>> I have the following error when building on Fedora 28 and gcc (GCC)
>> 8.1.1 20180712 (Red Hat 8.1.1-5)
>>
>>   CC      aarch64_be-linux-user/target/arm/arm-semi.o
>> .../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
>> .../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
>> GCC diagnostic’ kind [-Werror=pragmas]
>>
>> Perhaps you should use a "#if defined(__clang__)" to apply your fix only
>> to clang?
> 
> I did test on gcc, but not that version. The point of the
>    _Pragma("GCC diagnostic ignored \"-Wpragmas\"");
> line is to suppress that error (which it does on my gcc 5)
> so I don't know why your gcc is complaining :-(

You should add Fedora 28 to you collection of virtual machines :)

> 
> If you add an extra diagnostic push, so:
> 
> +        _Pragma("GCC diagnostic push");                                     \
> +        _Pragma("GCC diagnostic ignored \"-Wpragmas\"");                    \
> +        _Pragma("GCC diagnostic push");                                     \
> +        _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");   \
> 
> and then a balancing extra
> 
> +        _Pragma("GCC diagnostic pop");                                      \
> 
> at the end, I don't suppose that helps?

No, it doesn't help

> (I generally prefer to avoid marking things as clang- or gcc-
> specific where I can.)

I understand.
But it's a clang bug, it seems reasonable to have specific code to
workaround it.

Thanks,
Laurent

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-05  9:10     ` Peter Maydell
  2018-10-05  9:43       ` Laurent Vivier
@ 2018-10-05 15:25       ` Richard Henderson
  2018-10-05 16:09         ` Laurent Vivier
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Henderson @ 2018-10-05 15:25 UTC (permalink / raw)
  To: Peter Maydell, Laurent Vivier; +Cc: QEMU Developers, Riku Voipio, patches

On 10/5/18 4:10 AM, Peter Maydell wrote:
> On 5 October 2018 at 01:28, Laurent Vivier <laurent@vivier.eu> wrote:
>> I have the following error when building on Fedora 28 and gcc (GCC)
>> 8.1.1 20180712 (Red Hat 8.1.1-5)
>>
>>   CC      aarch64_be-linux-user/target/arm/arm-semi.o
>> .../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
>> .../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
>> GCC diagnostic’ kind [-Werror=pragmas]
>>
>> Perhaps you should use a "#if defined(__clang__)" to apply your fix only
>> to clang?
> 
> I did test on gcc, but not that version. The point of the
>    _Pragma("GCC diagnostic ignored \"-Wpragmas\"");
> line is to suppress that error (which it does on my gcc 5)
> so I don't know why your gcc is complaining :-(

I suppose you could try -Wunknown-pragmas.
But from reading the manual it shouldn't make a difference.
OTOH, what you wrote should have worked...


r~

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-05 15:25       ` Richard Henderson
@ 2018-10-05 16:09         ` Laurent Vivier
  2018-10-09 11:59           ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Laurent Vivier @ 2018-10-05 16:09 UTC (permalink / raw)
  To: Richard Henderson, Peter Maydell; +Cc: QEMU Developers, Riku Voipio, patches

On 05/10/2018 17:25, Richard Henderson wrote:
> On 10/5/18 4:10 AM, Peter Maydell wrote:
>> On 5 October 2018 at 01:28, Laurent Vivier <laurent@vivier.eu> wrote:
>>> I have the following error when building on Fedora 28 and gcc (GCC)
>>> 8.1.1 20180712 (Red Hat 8.1.1-5)
>>>
>>>   CC      aarch64_be-linux-user/target/arm/arm-semi.o
>>> .../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
>>> .../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
>>> GCC diagnostic’ kind [-Werror=pragmas]
>>>
>>> Perhaps you should use a "#if defined(__clang__)" to apply your fix only
>>> to clang?
>>
>> I did test on gcc, but not that version. The point of the
>>    _Pragma("GCC diagnostic ignored \"-Wpragmas\"");
>> line is to suppress that error (which it does on my gcc 5)
>> so I don't know why your gcc is complaining :-(
> 
> I suppose you could try -Wunknown-pragmas.
> But from reading the manual it shouldn't make a difference.
> OTOH, what you wrote should have worked...

Could it be a bug in _Pragma()?

If I use "#pragma" for the file, it works:

--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -474,10 +474,10 @@ static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
  *   an unknown warning type from older compilers that don't know about
  *   -Waddress-of-packed-member.
  */
+#pragma GCC diagnostic ignored "-Wpragmas"
 #define __put_user_e(x, hptr, e)                                            \
     do {                                                                    \
         _Pragma("GCC diagnostic push");                                     \
-        _Pragma("GCC diagnostic ignored \"-Wpragmas\"");                    \
         _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");   \
         (__builtin_choose_expr(sizeof(*(hptr)) == 1, stb_p,                 \
         __builtin_choose_expr(sizeof(*(hptr)) == 2, stw_##e##_p,            \
@@ -490,7 +490,6 @@ static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 #define __get_user_e(x, hptr, e)                                            \
     do {                                                                    \
         _Pragma("GCC diagnostic push");                                     \
-        _Pragma("GCC diagnostic ignored \"-Wpragmas\"");                    \
         _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");   \
         ((x) = (typeof(*hptr))(                                             \
         __builtin_choose_expr(sizeof(*(hptr)) == 1, ldub_p,                 \

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-05 16:09         ` Laurent Vivier
@ 2018-10-09 11:59           ` Peter Maydell
  2018-10-09 14:52             ` Peter Maydell
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2018-10-09 11:59 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Richard Henderson, QEMU Developers, Riku Voipio, patches

On 5 October 2018 at 17:09, Laurent Vivier <laurent@vivier.eu> wrote:
> On 05/10/2018 17:25, Richard Henderson wrote:
>> On 10/5/18 4:10 AM, Peter Maydell wrote:
>>> On 5 October 2018 at 01:28, Laurent Vivier <laurent@vivier.eu> wrote:
>>>> I have the following error when building on Fedora 28 and gcc (GCC)
>>>> 8.1.1 20180712 (Red Hat 8.1.1-5)
>>>>
>>>>   CC      aarch64_be-linux-user/target/arm/arm-semi.o
>>>> .../target/arm/arm-semi.c: In function ‘do_arm_semihosting’:
>>>> .../target/arm/arm-semi.c:270:1: error: unknown option after ‘#pragma
>>>> GCC diagnostic’ kind [-Werror=pragmas]
>>>>
>>>> Perhaps you should use a "#if defined(__clang__)" to apply your fix only
>>>> to clang?
>>>
>>> I did test on gcc, but not that version. The point of the
>>>    _Pragma("GCC diagnostic ignored \"-Wpragmas\"");
>>> line is to suppress that error (which it does on my gcc 5)
>>> so I don't know why your gcc is complaining :-(
>>
>> I suppose you could try -Wunknown-pragmas.
>> But from reading the manual it shouldn't make a difference.
>> OTOH, what you wrote should have worked...
>
> Could it be a bug in _Pragma()?

I got an f28 VM and can repro this. It looks like the problem
only happens when the get_user/put_user stuff is used via some
other macro, for some reason -- so the GET_ARG and SET_ARG
macros in arm-semi.c and the NEW_AUX_ENT macro in elfload.c
cause problems, but less indirect use does not. I'll try to
trim this down to a smaller test case somehow...

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-09 11:59           ` Peter Maydell
@ 2018-10-09 14:52             ` Peter Maydell
  2018-10-09 14:57               ` Laurent Vivier
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Maydell @ 2018-10-09 14:52 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Richard Henderson, QEMU Developers, Riku Voipio, patches

On 9 October 2018 at 12:59, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 5 October 2018 at 17:09, Laurent Vivier <laurent@vivier.eu> wrote:
>> Could it be a bug in _Pragma()?
>
> I got an f28 VM and can repro this. It looks like the problem
> only happens when the get_user/put_user stuff is used via some
> other macro, for some reason -- so the GET_ARG and SET_ARG
> macros in arm-semi.c and the NEW_AUX_ENT macro in elfload.c
> cause problems, but less indirect use does not. I'll try to
> trim this down to a smaller test case somehow...

I think it is a bug in _Pragma(). I boiled it down to a
small test case, and tested using the compilers on godbolt.org.
The test fails with gcc 5, 6, 7 and 8 but works on 4 and on
gcc trunk.

Trying to use _Pragma() inside a macro to disable warnings
seems to be pretty broken. The GCC bugzilla has:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85153
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69558
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82335
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66099
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543

which are various bug reports in this area, with test cases
which variously are fixed in gcc 8, or fixed not in 8 but
in trunk, or still broken in trunk. So there isn't a single
bug here but a cluster of similar ones.

I think the underlying difficulty is that the compiler decides
whether to suppress the warning by looking at the source location
for the warning, and at the source locations of the various
pragmas, and especially when macro expansion is involved the
"source location" can be harder to correctly identify.

I'm not sure if there is some "safe" subset of _Pragma()-in-macro
use here that will work regardless of compiler version, or if
we should just give up on it as non-feasible and try to silence
the warnings some other way.

Looks like clang is not flawless in this area either:
https://bugs.llvm.org/show_bug.cgi?id=31999
https://bugs.llvm.org/show_bug.cgi?id=15129
https://bugs.llvm.org/show_bug.cgi?id=35154

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e
  2018-10-09 14:52             ` Peter Maydell
@ 2018-10-09 14:57               ` Laurent Vivier
  0 siblings, 0 replies; 9+ messages in thread
From: Laurent Vivier @ 2018-10-09 14:57 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Richard Henderson, QEMU Developers, Riku Voipio, patches

Le 09/10/2018 à 16:52, Peter Maydell a écrit :
> On 9 October 2018 at 12:59, Peter Maydell <peter.maydell@linaro.org> wrote:
>> On 5 October 2018 at 17:09, Laurent Vivier <laurent@vivier.eu> wrote:
>>> Could it be a bug in _Pragma()?
>>
>> I got an f28 VM and can repro this. It looks like the problem
>> only happens when the get_user/put_user stuff is used via some
>> other macro, for some reason -- so the GET_ARG and SET_ARG
>> macros in arm-semi.c and the NEW_AUX_ENT macro in elfload.c
>> cause problems, but less indirect use does not. I'll try to
>> trim this down to a smaller test case somehow...
> 
> I think it is a bug in _Pragma(). I boiled it down to a
> small test case, and tested using the compilers on godbolt.org.
> The test fails with gcc 5, 6, 7 and 8 but works on 4 and on
> gcc trunk.
> 
> Trying to use _Pragma() inside a macro to disable warnings
> seems to be pretty broken. The GCC bugzilla has:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85153
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69558
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82335
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66099
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69543
> 
> which are various bug reports in this area, with test cases
> which variously are fixed in gcc 8, or fixed not in 8 but
> in trunk, or still broken in trunk. So there isn't a single
> bug here but a cluster of similar ones.
> 
> I think the underlying difficulty is that the compiler decides
> whether to suppress the warning by looking at the source location
> for the warning, and at the source locations of the various
> pragmas, and especially when macro expansion is involved the
> "source location" can be harder to correctly identify.
> 
> I'm not sure if there is some "safe" subset of _Pragma()-in-macro
> use here that will work regardless of compiler version, or if
> we should just give up on it as non-feasible and try to silence
> the warnings some other way.

To keep it simple, and as I have suggested before, perhaps you can use
only the _Pragma() we need to workaround clang bug with clang (#ifde
__clang__)?

Thanks,
Laurent

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

end of thread, other threads:[~2018-10-09 14:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20180928142533.8451-1-peter.maydell@linaro.org>
2018-10-04 16:55 ` [Qemu-devel] [PATCH] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e Laurent Vivier
2018-10-05  0:28   ` Laurent Vivier
2018-10-05  9:10     ` Peter Maydell
2018-10-05  9:43       ` Laurent Vivier
2018-10-05 15:25       ` Richard Henderson
2018-10-05 16:09         ` Laurent Vivier
2018-10-09 11:59           ` Peter Maydell
2018-10-09 14:52             ` Peter Maydell
2018-10-09 14:57               ` Laurent Vivier

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.