overall: Avoid using inlined functions with external linkage again
cover overall: Avoid using inlined functions with external linkage again
Mostly as a C style cleanup, use -Wstatic-in-inline to avoid using inlined function with external linkage.
Philippe Mathieu-Daudé (4):
hw/arm/smmu: Avoid using inlined functions with external linkage again accel/hvf: Un-inline hvf_arch_supports_guest_debug() qtest/libqos: Un-inline size_to_prdtl()
meson: Enable -Wstatic-in-inline
meson.build | 1 + hw/arm/smmu-common.c | 2 +- target/arm/hvf/hvf.c | 2 +- target/i386/hvf/hvf.c | 2 +- tests/qtest/libqos/ahci.c | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/4 hw/arm/smmu: Avoid using inlined functions with external linkage again
Similarly to commit 9de9fa5cf2 ("hw/arm/smmu-common: Avoid using inlined functions with external linkage"):
None of our code base require / use inlined functions with external linkage. Some places use internal inlining in the hot path. These two functions are certainly not in any hot path and don't justify any inlining, so these are likely oversights rather than intentional.
Fix:
C compiler for the host machine: clang (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
...
hw/arm/smmu-common.c:203:43: error: static function 'smmu_hash_remove_by_vmid' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid);
^
include/hw/arm/smmu-common.h:197:1: note: use 'static' to give inline function 'smmu_iotlb_inv_vmid' internal linkage
void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid);
^
static
hw/arm/smmu-common.c:139:17: note: 'smmu_hash_remove_by_vmid' declared here
static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value,
^--- hw/arm/smmu-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/smmu-common.c +1 -1
@@ -197,7 +197,7 @@ void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_asid, &asid); } -inline void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid) +void smmu_iotlb_inv_vmid (SMMUState *s,uint16_t vmid) {trace_smmu_iotlb_inv_vmid (vmid);g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_vmid, &vmid);
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 1/4] hw/arm/smmu: Avoid using inlined functions with external linkage again
Quoted 24 lines · Philippe Mathieu-Daudé
Similarly to commit
9de9fa5cf2("hw/arm/smmu-common: Avoid using inlined functions with external linkage"):None of our code base require / use inlined functions with external linkage. Some places use internal inlining in the hot path. These two functions are certainly not in any hot path and don't justify any inlining, so these are likely oversights rather than intentional.
Fix:
C compiler for the host machine: clang (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)") ... hw/arm/smmu-common.c:203:43: error: static function 'smmu_hash_remove_by_vmid' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline] g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid); ^ include/hw/arm/smmu-common.h:197:1: note: use 'static' to give inline function 'smmu_iotlb_inv_vmid' internal linkage void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid); ^ static hw/arm/smmu-common.c:139:17: note: 'smmu_hash_remove_by_vmid' declared here static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, ^
Quoted 5 lines
Fixes ccc3ee3871 ("hw/arm/smmuv3: Add CMDs related to stage-2")Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/arm/smmu-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 2/4 accel/hvf: Un-inline hvf_arch_supports_guest_debug()
In reply to Philippe Mathieu-DaudéSee previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.
--- target/arm/hvf/hvf.c | 2 +- target/i386/hvf/hvf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
target/arm/hvf/hvf.c +1 -1
@@ -2246,7 +2246,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu)hvf_arch_set_traps (); } -inline bool hvf_arch_supports_guest_debug (void ) +bool hvf_arch_supports_guest_debug (void ) {return true; }
target/i386/hvf/hvf.c +1 -1
@@ -708,7 +708,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu) { } -inline bool hvf_arch_supports_guest_debug (void ) +bool hvf_arch_supports_guest_debug (void ) {return false; }
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 2/4] accel/hvf: Un-inline hvf_arch_supports_guest_debug()
Quoted 5 lines · Philippe Mathieu-Daudé
See previous commit and commit
9de9fa5cf2("Avoid using inlined functions with external linkage") for rationale.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
thanks
-- PMM
Re: [PATCH-for-9.0 2/4] accel/hvf: Un-inline hvf_arch_supports_guest_debug()
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
See previous commit and commit
9de9fa5cf2("Avoid using inlined functions with external linkage") for rationale.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/hvf/hvf.c | 2 +- target/i386/hvf/hvf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 3/4 qtest/libqos: Un-inline size_to_prdtl()
In reply to Philippe Mathieu-DaudéSee previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.
--- tests/qtest/libqos/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqos/ahci.c +1 -1
@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)g_assert_not_reached (); } -inline unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) +unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) {/* Each PRD can describe up to 4MiB */ g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 3/4] qtest/libqos: Un-inline size_to_prdtl()
Quoted 14 lines · Philippe Mathieu-Daudé
See previous commit and commit
9de9fa5cf2("Avoid using inlined functions with external linkage") for rationale.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qtest/libqos/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qtest/libqos/ahci.c +0
-0
tests/qtest/libqos/ahci.c unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port) · line 668
Quoted 8 lines
tests/qtest/libqos/ahci.c +1
-1@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)g_assert_not_reached (); } -inline unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) +unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) {/* Each PRD can describe up to 4MiB */ g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);
It looks like this function is only used in this file, so we could make it static ?
-- PMM
Re: [PATCH-for-9.0 3/4] qtest/libqos: Un-inline size_to_prdtl()
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Philippe Mathieu-Daudé
See previous commit and commit
9de9fa5cf2("Avoid using inlined functions with external linkage") for rationale.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/qtest/libqos/ahci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qtest/libqos/ahci.c +0
-0@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)g_assert_not_reached (); }
Quoted 8 lines
tests/qtest/libqos/ahci.c unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port) · line 668
Quoted 5 lines
tests/qtest/libqos/ahci.c +1
-1-inline unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) +unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd) {/* Each PRD can describe up to 4MiB */ g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);It looks like this function is only used in this file, so we could make it static ?
Eh I did check for that, but sure how I missed it...
PATCH 4/4 meson: Enable -Wstatic-in-inline
In reply to Philippe Mathieu-DaudéCompilers are clever enough to inline code when necessary.
The only case we accept an inline function is static in header (we use C, not C++).
Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.
--- meson.build | 1 + 1 file changed, 1 insertion(+)
meson.build +1 -0
@@ -591,6 +591,7 @@ warn_flags = [ '-Wold-style-definition', '-Wredundant-decls', '-Wshadow=local', + '-Wstatic-in-inline', '-Wstrict-prototypes', '-Wtype-limits', '-Wundef',
Signature · 1 line
2.41.0
Re: [PATCH-for-9.0 4/4] meson: Enable -Wstatic-in-inline
Quoted 5 lines · Philippe Mathieu-Daudé
Compilers are clever enough to inline code when necessary.
The only case we accept an inline function is static in header (we use C, not C++).
Quoted 7 lines
Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- meson.build | 1 + 1 file changed, 1 insertion(+)
r~