qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] include: Make headers more self-contained


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH] include: Make headers more self-contained
Date: Mon, 15 Jul 2019 15:18:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

Philippe Mathieu-Daudé <address@hidden> writes:

> On 7/15/19 1:39 PM, Markus Armbruster wrote:
>> Back in 2016, we discussed[1] rules for headers, and these were
>> generally liked:
>> 
>> 1. Have a carefully curated header that's included everywhere first.  We
>>    got that already thanks to Peter: osdep.h.
>> 
>> 2. Headers should normally include everything they need beyond osdep.h.
>>    If exceptions are needed for some reason, they must be documented in
>>    the header.  If all that's needed from a header is typedefs, put
>>    those into qemu/typedefs.h instead of including the header.
>> 
>> 3. Cyclic inclusion is forbidden.
>> 
>> This patch gets include/ closer to obeying 2.
>
> A step forward using precompiled headers?
>
> https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html

I doubt his can help a hypothetical future adoption of precompiled
headers in QEMU much.

Precompiled headers are a finicky.  From the GCC manual:

    A precompiled header file can be used only when these conditions
    apply:

        * Only one precompiled header can be used in a particular
          compilation.

        * A precompiled header cannot be used once the first C token is
          seen. You can have preprocessor directives before a
          precompiled header; you cannot include a precompiled header
          from inside another header.

        * The precompiled header file must be produced for the same
          language as the current compilation. You cannot use a C
          precompiled header for a C++ compilation.

        * The precompiled header file must have been produced by the
          same compiler binary as the current compilation is using.

        * Any macros defined before the precompiled header is included
          must either be defined in the same way as when the precompiled
          header was generated, or must not affect the precompiled
          header, which usually means that they don’t appear in the
          precompiled header at all.

          [Details...]

        [More conditions on compiler options...]

Since we always include qemu/osdep.h first, that's the header we could
precompile.  Last time I checked, a .c file that includes nothing but
that comes out well over half a Megabyte in ~20k lines preprocessed.
I'd welcome build time comparisons with and without precompiling
qemu/osdep.h.

We have headers that are included from almost everywhere.  Some of them
are due to undisciplined use of #include; that needs fixing.  But some
may actually be needed almost everywhere.  Inluding them from a
precompiled qemu/osdep.h might gain further build speedups.

Making headers self-contained makes reordering inclusions safe.  That's
about what this patch can contribute to precompiled header adoption.
Nice, but not essential; we can always fix up things as they break.

How widely used are precompiled headers?  I'm asking because underused
parts of tools tend to be buggy parts.

[...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]