diff mbox

[PULL,v2,00/30] QAPI patches for 2018-03-01

Message ID ef125528-3e7a-5009-31aa-a3a8e8fd7ca2@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake March 2, 2018, 2:05 p.m. UTC
On 03/02/2018 06:38 AM, Peter Maydell wrote:
> On 2 March 2018 at 01:29, Eric Blake <eblake@redhat.com> wrote:
>> The following changes since commit 0dc8ae5e8e693737dfe65ba02d0c6eccb58a9c67:
>>
>>    Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20180301-v2' into staging (2018-03-01 17:08:16 +0000)
>>
>> are available in the Git repository at:
>>
>>    git://repo.or.cz/qemu/ericb.git tags/pull-qapi-2018-03-01-v2
>>
>> for you to fetch changes up to 76b2baeed38089c19f69c7117b8eaa64b0e7d227:
>>
>>    qapi: Don't create useless directory qapi-generated (2018-03-01 19:16:40 -0600)
>>

> 
> This produces a huge pile of warnings from my OSX toolchain.
> 
> When running ar on libqemuutil.a:
>    AR      libqemuutil.a
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib:
> file: libqemuutil.a(qapi-types.o) has no symbols

Part of this change was moving the location of the generated 
./qapi-types.c to qapi/qapi-types.c.  Could it be that you are doing an 
incremental build, rather than a clean build, and the compiler is 
picking up the stale version of the file rather than its new location?

> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib:
> file: libqemuutil.a(qapi-visit.o) has no symbols

Same thing.

> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib:
> file: libqemuutil.a(qapi-events.o) has no symbols

Here, we renamed ./qapi-event.c to qapi/qapi-events.c, so the fact that 
the compiler named the right file is promising, but the fact that the 
file has no symbols is not good.

> 
> I think these are related -- nm complains once for every .o file in the archive
> that doesn't have any symbols in it.
> 
> I had a look at the autogenerated .c files on my Linux build, and they
> seem to consist only of a bunch of #includes. Why are we not generating
> any code here?

I don't have easy access to an OSX machine.  What version of python is 
in use?  My first thought was that it could be a subtle bug due to 
differences in the python engine running the qapi generators.

But I just checked, and at least for qapi/qapi-types.c, the generated 
file IS just a list of includes; and in fact, it looks like all of the 
mentioned files are in that boat (for example, qapi/transaction.json has 
no events, so qapi/qapi-events-transaction.c being empty makes sense).

I know that some compilers are picky about that.  Is a typedef enough to 
cause the compiler to have something to compile without warnings?  If 
so, does this patch solve things?  If it does, I'll squash it in the 
right place within the series and submit a v3 pull request.

Comments

Peter Maydell March 2, 2018, 2:34 p.m. UTC | #1
On 2 March 2018 at 14:05, Eric Blake <eblake@redhat.com> wrote:
> On 03/02/2018 06:38 AM, Peter Maydell wrote:
>> This produces a huge pile of warnings from my OSX toolchain.
>>
>> When running ar on libqemuutil.a:
>>    AR      libqemuutil.a
>>
>> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib:
>> file: libqemuutil.a(qapi-types.o) has no symbols
>
>
> Part of this change was moving the location of the generated ./qapi-types.c
> to qapi/qapi-types.c.  Could it be that you are doing an incremental build,
> rather than a clean build, and the compiler is picking up the stale version
> of the file rather than its new location?

I am doing an incremental build, yes. That needs to work, not break...

>> I had a look at the autogenerated .c files on my Linux build, and they
>> seem to consist only of a bunch of #includes. Why are we not generating
>> any code here?

> But I just checked, and at least for qapi/qapi-types.c, the generated file
> IS just a list of includes; and in fact, it looks like all of the mentioned
> files are in that boat (for example, qapi/transaction.json has no events, so
> qapi/qapi-events-transaction.c being empty makes sense).

> I know that some compilers are picky about that.

Yes, I think this is what is causing the problem.

> Is a typedef enough to
> cause the compiler to have something to compile without warnings?

Given that the warnings are coming from nm and ranlib, anything that
doesn't actually cause a symbol to be put into the .o file isn't going
to be enough I suspect.

> If so,
> does this patch solve things?  If it does, I'll squash it in the right place
> within the series and submit a v3 pull request.
>
> diff --git i/scripts/qapi/common.py w/scripts/qapi/common.py
> index 077e0fde4f4..aed32646c00 100644
> --- i/scripts/qapi/common.py
> +++ w/scripts/qapi/common.py
> @@ -2035,6 +2035,13 @@ class QAPIGenC(QAPIGen):
>  ''',
>                       blurb=self._blurb, copyright=self._copyright)
>
> +    def _bottom(self, fname):
> +        return mcgen('''
> +/* Dummy typedef to prevent empty .o file */
> +typedef int %(name)s;
> +''',
> +                     name=c_name(fname))
> +
>
>  class QAPIGenH(QAPIGenC):

I just tested this, and it isn't sufficient.

thanks
-- PMM
Eric Blake March 2, 2018, 2:45 p.m. UTC | #2
On 03/02/2018 08:34 AM, Peter Maydell wrote:
> On 2 March 2018 at 14:05, Eric Blake <eblake@redhat.com> wrote:
>> On 03/02/2018 06:38 AM, Peter Maydell wrote:
>>> This produces a huge pile of warnings from my OSX toolchain.
>>>
>>> When running ar on libqemuutil.a:
>>>     AR      libqemuutil.a
>>>
>>> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib:
>>> file: libqemuutil.a(qapi-types.o) has no symbols
>>
>>
>> Part of this change was moving the location of the generated ./qapi-types.c
>> to qapi/qapi-types.c.  Could it be that you are doing an incremental build,
>> rather than a clean build, and the compiler is picking up the stale version
>> of the file rather than its new location?
> 
> I am doing an incremental build, yes. That needs to work, not break...

And since it was warnings and you picked up qapi/qapi-events.c, it looks 
like it does work; phew.

> 
>>> I had a look at the autogenerated .c files on my Linux build, and they
>>> seem to consist only of a bunch of #includes. Why are we not generating
>>> any code here?
> 
>> But I just checked, and at least for qapi/qapi-types.c, the generated file
>> IS just a list of includes; and in fact, it looks like all of the mentioned
>> files are in that boat (for example, qapi/transaction.json has no events, so
>> qapi/qapi-events-transaction.c being empty makes sense).
> 
>> I know that some compilers are picky about that.
> 
> Yes, I think this is what is causing the problem.

Okay, we've narrowed in on root cause, and it's now just a matter of 
finding the magic formula to shut up the toolchain.

> 
>> Is a typedef enough to
>> cause the compiler to have something to compile without warnings?
> 
> Given that the warnings are coming from nm and ranlib, anything that
> doesn't actually cause a symbol to be put into the .o file isn't going
> to be enough I suspect.

As I mentioned on IRC, gnulib has used typedefs to prevent empty files 
before:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/lib/binary-io.c?id=c5d07ce91a8ad51591154450442fa4376441fdfa
https://lists.gnu.org/archive/html/bug-gnulib/2015-10/msg00019.html
https://lists.gnu.org/archive/html/bug-gnulib/2004-07/msg00029.html

>> +    def _bottom(self, fname):
>> +        return mcgen('''
>> +/* Dummy typedef to prevent empty .o file */
>> +typedef int %(name)s;
>> +''',
>> +                     name=c_name(fname))
>> +
>>
>>   class QAPIGenH(QAPIGenC):
> 
> I just tested this, and it isn't sufficient.

Oh well, we'll have to burn actual storage, then.  My next try is:

static char dummy_%(name)s;

perhaps with an __attribute__((unused)); if that gets by without 
warnings on the toolchains I have available, it should hopefully be 
stronger than just the typedef and therefore enough for your toolchain. 
I'll submit v3 shortly.
diff mbox

Patch

diff --git i/scripts/qapi/common.py w/scripts/qapi/common.py
index 077e0fde4f4..aed32646c00 100644
--- i/scripts/qapi/common.py
+++ w/scripts/qapi/common.py
@@ -2035,6 +2035,13 @@  class QAPIGenC(QAPIGen):
  ''',
                       blurb=self._blurb, copyright=self._copyright)

+    def _bottom(self, fname):
+        return mcgen('''
+/* Dummy typedef to prevent empty .o file */
+typedef int %(name)s;
+''',
+                     name=c_name(fname))
+

  class QAPIGenH(QAPIGenC):