qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
@ 2011-12-20  9:03 Dong Xu Wang
  2011-12-20 10:13 ` Stefan Hajnoczi
  2012-02-08 12:49 ` Kevin Wolf
  0 siblings, 2 replies; 8+ messages in thread
From: Dong Xu Wang @ 2011-12-20  9:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Dong Xu Wang

From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

On some platforms, __LINE__ will not expand to real number in QEMU_BUILD_BUG_ON,
so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This patch will
fix it.

BTW, I got error message on RHEL 6.1/gcc 4.4.5.

Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
---
 compiler.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/compiler.h b/compiler.h
index a1c0794..736e770 100644
--- a/compiler.h
+++ b/compiler.h
@@ -30,8 +30,10 @@
 # define QEMU_PACKED __attribute__((packed))
 #endif
 
+#define cat(x,y) x ## y
+#define cat2(x,y) cat(x,y)
 #define QEMU_BUILD_BUG_ON(x) \
-    typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
+    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
 
 #if defined __GNUC__
 # if !QEMU_GNUC_PREREQ(4, 4)
-- 
1.7.5.4

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20  9:03 [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON Dong Xu Wang
@ 2011-12-20 10:13 ` Stefan Hajnoczi
  2011-12-20 10:47   ` Dong Xu Wang
  2012-02-08 12:49 ` Kevin Wolf
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2011-12-20 10:13 UTC (permalink / raw)
  To: Dong Xu Wang; +Cc: qemu-devel

On Tue, Dec 20, 2011 at 05:03:47PM +0800, Dong Xu Wang wrote:
> From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> 
> On some platforms, __LINE__ will not expand to real number in QEMU_BUILD_BUG_ON,
> so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This patch will
> fix it.
> 
> BTW, I got error message on RHEL 6.1/gcc 4.4.5.

Can you post the gcc -E output of the file that produces the error as
well as the gcc error output?

Stefan

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20 10:13 ` Stefan Hajnoczi
@ 2011-12-20 10:47   ` Dong Xu Wang
  2011-12-20 12:08     ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Dong Xu Wang @ 2011-12-20 10:47 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

于 2011年12月20日 18:13, Stefan Hajnoczi 写道:
> On Tue, Dec 20, 2011 at 05:03:47PM +0800, Dong Xu Wang wrote:
>> From: Dong Xu Wang<wdongxu@linux.vnet.ibm.com>
>>
>> On some platforms, __LINE__ will not expand to real number in QEMU_BUILD_BUG_ON,
>> so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This patch will
>> fix it.
>>
>> BTW, I got error message on RHEL 6.1/gcc 4.4.5.
>
> Can you post the gcc -E output of the file that produces the error as
> well as the gcc error output?
>
> Stefan
>
>

I doubled the following lines in block/qcow2-snapshot.c(line 211 and 212):

QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots));"


While "gcc -E -C -I. block/qcow2-snapshot.c", I can get:
typedef char
  qemu_build_bug_on____LINE__
# 241 "block/qcow2-snapshot.c"
     [(__builtin_offsetof (QCowHeader, snapshots_offset) != 
__builtin_offsetof (QCowHeader, nb_snapshots) + 
sizeof(header_data.nb_snapshots))?-1:1];
 
        ;
   typedef char
  qemu_build_bug_on____LINE__
# 243 "block/qcow2-snapshot.c"
   [(__builtin_offsetof (QCowHeader, snapshots_offset) != 
__builtin_offsetof (QCowHeader, nb_snapshots) + 
sizeof(header_data.nb_snapshots))?-1:1];

__LINE__ are not expanded to real line number.



While normally compiling, error message is:
   CC    block/qcow2-snapshot.o
block/qcow2-snapshot.c: In function \u2018qcow2_write_snapshots\u2019:
block/qcow2-snapshot.c:244: error: redefinition of typedef 
\u2018qemu_build_bug_on____LINE__\u2019
block/qcow2-snapshot.c:242: note: previous declaration of 
\u2018qemu_build_bug_on____LINE__\u2019 was here
make: *** [block/qcow2-snapshot.o] Error 1

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20 10:47   ` Dong Xu Wang
@ 2011-12-20 12:08     ` Stefan Hajnoczi
  2011-12-20 13:12       ` Dong Xu Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2011-12-20 12:08 UTC (permalink / raw)
  To: Dong Xu Wang; +Cc: qemu-devel

On Tue, Dec 20, 2011 at 10:47 AM, Dong Xu Wang
<wdongxu@linux.vnet.ibm.com> wrote:
> 于 2011年12月20日 18:13, Stefan Hajnoczi 写道:
>
>> On Tue, Dec 20, 2011 at 05:03:47PM +0800, Dong Xu Wang wrote:
>>>
>>> From: Dong Xu Wang<wdongxu@linux.vnet.ibm.com>
>>>
>>> On some platforms, __LINE__ will not expand to real number in
>>> QEMU_BUILD_BUG_ON,
>>> so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This
>>> patch will
>>> fix it.
>>>
>>> BTW, I got error message on RHEL 6.1/gcc 4.4.5.
>>
>>
>> Can you post the gcc -E output of the file that produces the error as
>> well as the gcc error output?
>>
>> Stefan
>>
>>
>
> I doubled the following lines in block/qcow2-snapshot.c(line 211 and 212):
>
> QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
> offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots));"
>
>
> While "gcc -E -C -I. block/qcow2-snapshot.c", I can get:
> typedef char
>  qemu_build_bug_on____LINE__
> # 241 "block/qcow2-snapshot.c"
>    [(__builtin_offsetof (QCowHeader, snapshots_offset) != __builtin_offsetof
> (QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots))?-1:1];
>
>       ;
>  typedef char
>  qemu_build_bug_on____LINE__
> # 243 "block/qcow2-snapshot.c"
>  [(__builtin_offsetof (QCowHeader, snapshots_offset) != __builtin_offsetof
> (QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots))?-1:1];
>
> __LINE__ are not expanded to real line number.
>
>
>
> While normally compiling, error message is:
>  CC    block/qcow2-snapshot.o
> block/qcow2-snapshot.c: In function \u2018qcow2_write_snapshots\u2019:
> block/qcow2-snapshot.c:244: error: redefinition of typedef
> \u2018qemu_build_bug_on____LINE__\u2019
> block/qcow2-snapshot.c:242: note: previous declaration of
> \u2018qemu_build_bug_on____LINE__\u2019 was here
> make: *** [block/qcow2-snapshot.o] Error 1

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

This isn't a compiler-specific issue, it has never worked but we
didn't realize it.  I suggest removing "On some platforms," from the
patch description.  The preprocessor won't expand __LINE__ since there
is a ## and it is inside the QEMU_BUILD_BUG_ON_MACRO():

http://stackoverflow.com/questions/1597007/creating-c-macro-with-and-line-token-concatenation-with-positioning-macr

Stefan

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20 12:08     ` Stefan Hajnoczi
@ 2011-12-20 13:12       ` Dong Xu Wang
  2011-12-20 13:41         ` Stefan Hajnoczi
  0 siblings, 1 reply; 8+ messages in thread
From: Dong Xu Wang @ 2011-12-20 13:12 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

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

It can compile on my Ubuntu:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10"

gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

While "gcc -E", it gets the same output as RHEL's, but it can compile. I do
not know why was that.  :(

在 2011年12月20日 下午8:08,Stefan Hajnoczi <stefanha@gmail.com>写道:

> On Tue, Dec 20, 2011 at 10:47 AM, Dong Xu Wang
> <wdongxu@linux.vnet.ibm.com> wrote:
> > 于 2011年12月20日 18:13, Stefan Hajnoczi 写道:
> >
> >> On Tue, Dec 20, 2011 at 05:03:47PM +0800, Dong Xu Wang wrote:
> >>>
> >>> From: Dong Xu Wang<wdongxu@linux.vnet.ibm.com>
> >>>
> >>> On some platforms, __LINE__ will not expand to real number in
> >>> QEMU_BUILD_BUG_ON,
> >>> so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This
> >>> patch will
> >>> fix it.
> >>>
> >>> BTW, I got error message on RHEL 6.1/gcc 4.4.5.
> >>
> >>
> >> Can you post the gcc -E output of the file that produces the error as
> >> well as the gcc error output?
> >>
> >> Stefan
> >>
> >>
> >
> > I doubled the following lines in block/qcow2-snapshot.c(line 211 and
> 212):
> >
> > QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
> > offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots));"
> >
> >
> > While "gcc -E -C -I. block/qcow2-snapshot.c", I can get:
> > typedef char
> >  qemu_build_bug_on____LINE__
> > # 241 "block/qcow2-snapshot.c"
> >    [(__builtin_offsetof (QCowHeader, snapshots_offset) !=
> __builtin_offsetof
> > (QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots))?-1:1];
> >
> >       ;
> >  typedef char
> >  qemu_build_bug_on____LINE__
> > # 243 "block/qcow2-snapshot.c"
> >  [(__builtin_offsetof (QCowHeader, snapshots_offset) !=
> __builtin_offsetof
> > (QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots))?-1:1];
> >
> > __LINE__ are not expanded to real line number.
> >
> >
> >
> > While normally compiling, error message is:
> >  CC    block/qcow2-snapshot.o
> > block/qcow2-snapshot.c: In function \u2018qcow2_write_snapshots\u2019:
> > block/qcow2-snapshot.c:244: error: redefinition of typedef
> > \u2018qemu_build_bug_on____LINE__\u2019
> > block/qcow2-snapshot.c:242: note: previous declaration of
> > \u2018qemu_build_bug_on____LINE__\u2019 was here
> > make: *** [block/qcow2-snapshot.o] Error 1
>
> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> This isn't a compiler-specific issue, it has never worked but we
> didn't realize it.  I suggest removing "On some platforms," from the
> patch description.  The preprocessor won't expand __LINE__ since there
> is a ## and it is inside the QEMU_BUILD_BUG_ON_MACRO():
>
>
> http://stackoverflow.com/questions/1597007/creating-c-macro-with-and-line-token-concatenation-with-positioning-macr
>
> Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 4035 bytes --]

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20 13:12       ` Dong Xu Wang
@ 2011-12-20 13:41         ` Stefan Hajnoczi
  2012-01-09  5:26           ` Dong Xu Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2011-12-20 13:41 UTC (permalink / raw)
  To: Dong Xu Wang; +Cc: qemu-devel

On Tue, Dec 20, 2011 at 1:12 PM, Dong Xu Wang
<wdongxu@linux.vnet.ibm.com> wrote:
> It can compile on my Ubuntu:
>
> DISTRIB_ID=Ubuntu
> DISTRIB_RELEASE=11.10
> DISTRIB_CODENAME=oneiric
> DISTRIB_DESCRIPTION="Ubuntu 11.10"
>
> gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
>
> While "gcc -E", it gets the same output as RHEL's, but it can compile. I do
> not know why was that.  :(

I see what you mean.  I find some gccs compile it successfully and
others warn about the typedef redefinition.  Whether or not you get an
error without the fix depends on whether your compiling warns about
redefined typedefs.

Your fix makes sense in any case.

Stefan

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20 13:41         ` Stefan Hajnoczi
@ 2012-01-09  5:26           ` Dong Xu Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Dong Xu Wang @ 2012-01-09  5:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi

QEMU_BUILD_BUG_ON is only used in ./block/qcow2-snapshot.c, so CCed Kevin.

On Tue, Dec 20, 2011 at 21:41, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>
> On Tue, Dec 20, 2011 at 1:12 PM, Dong Xu Wang
> <wdongxu@linux.vnet.ibm.com> wrote:
> > It can compile on my Ubuntu:
> >
> > DISTRIB_ID=Ubuntu
> > DISTRIB_RELEASE=11.10
> > DISTRIB_CODENAME=oneiric
> > DISTRIB_DESCRIPTION="Ubuntu 11.10"
> >
> > gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
> >
> > While "gcc -E", it gets the same output as RHEL's, but it can compile. I do
> > not know why was that.  :(
>
> I see what you mean.  I find some gccs compile it successfully and
> others warn about the typedef redefinition.  Whether or not you get an
> error without the fix depends on whether your compiling warns about
> redefined typedefs.
>
> Your fix makes sense in any case.
>
> Stefan
>

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

* Re: [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON
  2011-12-20  9:03 [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON Dong Xu Wang
  2011-12-20 10:13 ` Stefan Hajnoczi
@ 2012-02-08 12:49 ` Kevin Wolf
  1 sibling, 0 replies; 8+ messages in thread
From: Kevin Wolf @ 2012-02-08 12:49 UTC (permalink / raw)
  To: Dong Xu Wang; +Cc: qemu-devel

Am 20.12.2011 10:03, schrieb Dong Xu Wang:
> From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
> 
> On some platforms, __LINE__ will not expand to real number in QEMU_BUILD_BUG_ON,
> so if using QEMU_BUILD_BUG_ON twice, compiler will report errors. This patch will
> fix it.
> 
> BTW, I got error message on RHEL 6.1/gcc 4.4.5.
> 
> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

Thanks, applied to the block branch.

Kevin

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

end of thread, other threads:[~2012-02-08 13:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-20  9:03 [Qemu-devel] [PATCH] rewrite QEMU_BUILD_BUG_ON Dong Xu Wang
2011-12-20 10:13 ` Stefan Hajnoczi
2011-12-20 10:47   ` Dong Xu Wang
2011-12-20 12:08     ` Stefan Hajnoczi
2011-12-20 13:12       ` Dong Xu Wang
2011-12-20 13:41         ` Stefan Hajnoczi
2012-01-09  5:26           ` Dong Xu Wang
2012-02-08 12:49 ` Kevin Wolf

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).