qemu-common.h include cleanup
Subsystems (2)
cover qemu-common.h include cleanup
qemu-common.h has a comment at the top:
* This file is supposed to be included only by .c files. No header file should
* depend on qemu-common.h, as this would easily lead to circular header
* dependencies.
We still have a few .h files which include it, though. The first 3 patches in this series fix that: in 3 out of 4 cases we didn't need the #include at all, and in the 4th case we can instead #include qemu-common.h from just one .c file.
Patch 4 is just removing the #include from 8 files in hw/arm which don't need it at all. (Probably there are other files like this, but I just did the Arm related ones.)
Tested by pushing to gitlab for the CI build.
-- PMM
Peter Maydell (4):
include/hw/i386: Don't include qemu-common.h in .h files target/hexagon/cpu.h: don't include qemu-common.h target/rx/cpu.h: Don't include qemu-common.h hw/arm: Don't include qemu-common.h unnecessarily
include/hw/i386/microvm.h | 1 - include/hw/i386/x86.h | 1 - target/hexagon/cpu.h | 1 - target/rx/cpu.h | 1 - hw/arm/boot.c | 1 - hw/arm/digic_boards.c | 1 - hw/arm/highbank.c | 1 - hw/arm/npcm7xx_boards.c | 1 - hw/arm/sbsa-ref.c | 1 - hw/arm/stm32f405_soc.c | 1 - hw/arm/vexpress.c | 1 - hw/arm/virt.c | 1 - linux-user/hexagon/cpu_loop.c | 1 + 13 files changed, 1 insertion(+), 12 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 include/hw/i386: Don't include qemu-common.h in .h files
The qemu-common.h header is not supposed to be included from any other header files, only from .c files (as documented in a comment at the start of it).
include/hw/i386/x86.h and include/hw/i386/microvm.h break this rule. In fact, the include is not required at all, so we can just drop it from both files.
--- include/hw/i386/microvm.h | 1 - include/hw/i386/x86.h | 1 - 2 files changed, 2 deletions(-)
include/hw/i386/microvm.h +0 -1
@@ -18,7 +18,6 @@#ifndef HW_I386_MICROVM_H #define HW_I386_MICROVM_H -#include "qemu-common.h" #include "exec/hwaddr.h" #include "qemu/notify.h"
include/hw/i386/x86.h +0 -1
@@ -17,7 +17,6 @@#ifndef HW_I386_X86_H #define HW_I386_X86_H -#include "qemu-common.h" #include "exec/hwaddr.h" #include "qemu/notify.h"
Signature · 1 line
2.25.1
PATCH 2/4 target/hexagon/cpu.h: don't include qemu-common.h
In reply to Peter MaydellThe qemu-common.h header is not supposed to be included from any other header files, only from .c files (as documented in a comment at the start of it).
Move the include to linux-user/hexagon/cpu_loop.c, which needs it for the declaration of cpu_exec_step_atomic().
--- target/hexagon/cpu.h | 1 - linux-user/hexagon/cpu_loop.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
target/hexagon/cpu.h +0 -1
@@ -23,7 +23,6 @@ typedef struct CPUHexagonState CPUHexagonState;#include "fpu/softfloat-types.h" -#include "qemu-common.h" #include "exec/cpu-defs.h" #include "hex_regs.h" #include "mmvec/mmvec.h"
linux-user/hexagon/cpu_loop.c +1 -0
@@ -19,6 +19,7 @@*/ #include "qemu/osdep.h" +#include "qemu-common.h" #include "qemu.h" #include "user-internals.h" #include "cpu_loop-common.h"
Signature · 1 line
2.25.1
RE: [PATCH for-7.0 2/4] target/hexagon/cpu.h: don't include qemu-common.h
Quoted 17 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Monday, November 29, 2021 2:05 PM
To: [email protected]; [email protected]
Cc: Paolo Bonzini <[email protected]>; Sergio Lopez <[email protected]>; Taylor Simpson <[email protected]>; Yoshinori Sato <[email protected]>; Marcel Apfelbaum <[email protected]>
Subject: [PATCH for-7.0 2/4]target/hexagon/cpu.h: don't include qemu-common.hThe
qemu-common.hheader is not supposed to be included from any other header files, only from .c files (as documented in a comment at the start of it).
Quoted 8 lines
Move the include to
linux-user/hexagon/cpu_loop.c, which needs it for the declaration ofcpu_exec_step_atomic().Signed-off-by Peter Maydell <[email protected]>--- target/hexagon/cpu.h | 1 - linux-user/hexagon/cpu_loop.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
PATCH 3/4 target/rx/cpu.h: Don't include qemu-common.h
In reply to Peter MaydellThe qemu-common.h header is not supposed to be included from any other header files, only from .c files (as documented in a comment at the start of it).
Nothing actually relies on target/rx/cpu.h including it, so we can just drop the include.
--- target/rx/cpu.h | 1 - 1 file changed, 1 deletion(-)
target/rx/cpu.h +0 -1
@@ -20,7 +20,6 @@#define RX_CPU_H #include "qemu/bitops.h" -#include "qemu-common.h" #include "hw/registerfields.h" #include "cpu-qom.h"
Signature · 1 line
2.25.1
Re: [PATCH for-7.0 3/4] target/rx/cpu.h: Don't include qemu-common.h
Quoted 9 lines · Peter Maydell
The
qemu-common.hheader is not supposed to be included from any other header files, only from .c files (as documented in a comment at the start of it).Nothing actually relies on
target/rx/cpu.hincluding it, so we can just drop the include.Signed-off-by Peter Maydell <[email protected]>
Quoted 20 lines
--- target/rx/cpu.h | 1 - 1 file changed, 1 deletion(-)target/rx/cpu.h +0
-1@@ -20,7 +20,6 @@#define RX_CPU_H #include "qemu/bitops.h" -#include "qemu-common.h" #include "hw/registerfields.h" #include "cpu-qom.h" Signature · 1 line
2.25.1
PATCH 4/4 hw/arm: Don't include qemu-common.h unnecessarily
In reply to Peter MaydellA lot of C files in hw/arm include qemu-common.h when they don't need anything from it. Drop the include lines.
omap1.c, pxa2xx.c and strongarm.c retain the include because they use it for the prototype of qemu_get_timedate().
--- hw/arm/boot.c | 1 - hw/arm/digic_boards.c | 1 - hw/arm/highbank.c | 1 - hw/arm/npcm7xx_boards.c | 1 - hw/arm/sbsa-ref.c | 1 - hw/arm/stm32f405_soc.c | 1 - hw/arm/vexpress.c | 1 - hw/arm/virt.c | 1 - 8 files changed, 8 deletions(-)
hw/arm/boot.c +0 -1
@@ -8,7 +8,6 @@*/ #include "qemu/osdep.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "qemu/error-report.h" #include "qapi/error.h"
hw/arm/digic_boards.c +0 -1
@@ -25,7 +25,6 @@#include "qemu/osdep.h" #include "qapi/error.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "hw/boards.h" #include "qemu/error-report.h"
hw/arm/highbank.c +0 -1
@@ -18,7 +18,6 @@*/ #include "qemu/osdep.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "qapi/error.h" #include "hw/sysbus.h"
hw/arm/npcm7xx_boards.c +0 -1
@@ -24,7 +24,6 @@#include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "qapi/error.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "qemu/units.h" #include "sysemu/blockdev.h"
hw/arm/sbsa-ref.c +0 -1
@@ -18,7 +18,6 @@*/ #include "qemu/osdep.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "qapi/error.h" #include "qemu/error-report.h"
hw/arm/stm32f405_soc.c +0 -1
@@ -24,7 +24,6 @@#include "qemu/osdep.h" #include "qapi/error.h" -#include "qemu-common.h" #include "exec/address-spaces.h" #include "sysemu/sysemu.h" #include "hw/arm/stm32f405_soc.h"
hw/arm/vexpress.c +0 -1
@@ -23,7 +23,6 @@#include "qemu/osdep.h" #include "qapi/error.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "cpu.h" #include "hw/sysbus.h"
hw/arm/virt.c +0 -1
@@ -29,7 +29,6 @@*/ #include "qemu/osdep.h" -#include "qemu-common.h" #include "qemu/datadir.h" #include "qemu/units.h" #include "qemu/option.h"
Signature · 1 line
2.25.1
Quoted 6 lines · Peter Maydell
qemu-common.hhas a comment at the top:* This file is supposed to be included only by .c files. No header file should
* depend onqemu-common.h, as this would easily lead to circular header
* dependencies.
As a side note, that comment was added back in 2012 when qemu-common.h was bigger, included other headers, and did some of the work we currently use osdep.h for. As it stands today qemu-common.h includes no other files so it isn't a source of possible circular dependencies -- it's just a grab-bag of miscellaneous prototypes that in an ideal world would be in more focused individual headers[*]. So there's an argument for deleting this comment...
[*] A cleanup that would be nice, and I'm about to send out a patchset that splits out the rtc related functions; but the grab-bag at the bottom of osdep.h is probably higher priority because that header gets pulled in by an order of magnitude more C files.
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Peter Maydell
qemu-common.hhas a comment at the top:* This file is supposed to be included only by .c files. No header file should
* depend onqemu-common.h, as this would easily lead to circular header
* dependencies.
Quoted 7 lines
As a side note, that comment was added back in 2012 when
qemu-common.hwas bigger, included other headers, and did some of the work we currently useosdep.hfor. As it stands todayqemu-common.hincludes no other files so it isn't a source of possible circular dependencies -- it's just a grab-bag of miscellaneous prototypes that in an ideal world would be in more focused individual headers[*]. So there's an argument for deleting this comment...
First, thank you for this cleanup series.
The comment is from commit 04509ad939a:
qemu-common.h: Comment about usage rules
Every time we make a tiny change on a header file, we often find circular header dependency problems. To avoid this nightmare, we need to stop including qemu-common.h from other headers, and we should gradually move the declarations from the catch-all qemu-common.h header to their specific headers.
This simply adds a comment documenting the rules about qemu-common.h, hoping that people will see it before including qemu-common.h from other header files, and before adding more declarations to qemu-common.h.
You're right: we've since moved all #include out of qemu-common.h, so the risk of circular header dependency is gone, and the comment's claim "this would easily lead to circular header dependencies" is no longer correct.
In my opinion, including qemu-common.h in a header is a bad idea regardless. Headers should include the headers they need to make them self-contained, and no more, because more risks slower compiles, in particular frequent recompiles of pretty much everything. Previously discussed at
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg06291.html Message-ID: <[email protected]>
Nothing in qemu-common.h should be required to make another header self-contained.
This is likely the case for other headers as well, which don't carry a comment forbidding inclusion into headers. You could argue that qemu-common.h should not carry one, either. I can accept that. I'm not attached to the comment. I am interested in keeping unwanted #include in headers under control.
Quoted 4 lines
[*] A cleanup that would be nice, and I'm about to send out a patchset that splits out the rtc related functions; but the grab-bag at the bottom of
osdep.his probably higher priority because that header gets pulled in by an order of magnitude more C files.
By all "normal" ones, in fact.
Quoted 17 lines · Peter Maydell
qemu-common.hhas a comment at the top:* This file is supposed to be included only by .c files. No header file should
* depend onqemu-common.h, as this would easily lead to circular header
* dependencies.We still have a few .h files which include it, though. The first 3 patches in this series fix that: in 3 out of 4 cases we didn't need the #include at all, and in the 4th case we can instead #include
qemu-common.hfrom just one .c file.Patch 4 is just removing the #include from 8 files in hw/arm which don't need it at all. (Probably there are other files like this, but I just did the Arm related ones.)
Tested by pushing to gitlab for the CI build.
Quoted 7 lines
-- PMM
Peter Maydell (4):
include/hw/i386: Don't includeqemu-common.hin .h filestarget/hexagon/cpu.h: don't includeqemu-common.htarget/rx/cpu.h: Don't includeqemu-common.hhw/arm: Don't includeqemu-common.hunnecessarily
r~
Quoted 5 lines · Peter Maydell
Peter Maydell (4):
include/hw/i386: Don't includeqemu-common.hin .h filestarget/hexagon/cpu.h: don't includeqemu-common.htarget/rx/cpu.h: Don't includeqemu-common.hhw/arm: Don't includeqemu-common.hunnecessarily