overall: Avoid using inlined functions with external linkage again
v2 cover overall: Avoid using inlined functions with external linkage again
Oops, I forgot patch 3 needed rework :/ Is it too late to enforce that flag for 9.0?
Missing review: #3
Since v1:
- Reduce size_to_prdtl() scope
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: Reduce size_to_prdtl() declaration scope
meson: Enable -Wstatic-in-inline
meson.build | 1 + tests/qtest/libqos/ahci.h | 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 +- 6 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 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,
^Message-Id: <[email protected]>
--- 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? v2 1/4] hw/arm/smmu: Avoid using inlined functions with external linkage again
Hi,
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 4 lines
Fixes ccc3ee3871 ("hw/arm/smmuv3: Add CMDs related to stage-2")Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Thanks
Eric
Quoted 17 lines
--- 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);
PATCH v2 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.
Message-Id: <[email protected]>
--- 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
PATCH v2 3/4 qtest/libqos: Reduce size_to_prdtl() declaration scope
In reply to Philippe Mathieu-DaudéSince size_to_prdtl() is only used within ahci.c, declare it statically. This removes the last use of "inlined function with external linkage". See previous commit and commit 9de9fa5cf2 for rationale.
--- tests/qtest/libqos/ahci.h | 1 - tests/qtest/libqos/ahci.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
tests/qtest/libqos/ahci.h +0 -1
@@ -599,7 +599,6 @@ void ahci_port_check_cmd_sanity(AHCIQState *ahci, AHCICommand *cmd);/* Misc */ bool is_atapi (AHCIQState *ahci,uint8_t port); -unsigned size_to_prdtl (unsigned bytes,unsigned bytes_per_prd);/* Command: Macro level execution */ void ahci_guest_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,
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) +static 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? v2 3/4] qtest/libqos: Reduce size_to_prdtl() declaration scope
Quoted 8 lines · Philippe Mathieu-Daudé
Since
size_to_prdtl()is only used withinahci.c, declare it statically. This removes the last use of "inlined function with external linkage". See previous commit and commit9de9fa5cf2for rationale.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
thanks
-- PMM
Re: [PATCH-for-9.0? v2 3/4] qtest/libqos: Reduce size_to_prdtl() declaration scope
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
Since
size_to_prdtl()is only used withinahci.c, declare it statically. This removes the last use of "inlined function with external linkage". See previous commit and commit9de9fa5cf2for rationale.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
PATCH v2 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.
Message-Id: <[email protected]>
--- 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? v2 4/4] meson: Enable -Wstatic-in-inline
Quoted 6 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++).
Add the -Wstatic-in-inline CPPFLAG to prevent public and
I think this is rather a compiler than a pre-processor flag, so s/CPPFLAG/CFLAGS/ ?
Anyway:
Quoted 21 lines
inline function to be added in the code base.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
--- 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',
Re: [PATCH-for-9.0? v2 4/4] meson: Enable -Wstatic-in-inline
Quoted 9 lines · Thomas Huth
Quoted 6 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++).
Add the -Wstatic-in-inline CPPFLAG to prevent public and
I think this is rather a compiler than a pre-processor flag, so s/CPPFLAG/CFLAGS/ ?
Oops indeed you are right, thanks!
Quoted 13 lines
Anyway:
Reviewed-by Thomas Huth <[email protected]>Quoted 8 lines
inline function to be added in the code base.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
---
meson.build | 1 +1 file changed, 1 insertion(+)
Re: [PATCH-for-9.0? v2 4/4] meson: Enable -Wstatic-in-inline
In reply to Philippe Mathieu-DaudéQuoted 7 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++).
Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.
No problem with the first three patches, but -Wstatic-in-inline is not warning for non-static inline functions. The warning is enabled by default by GCC (which has no way to disable it even) and by clang outside headers:
f.h:
static int y;
inline int f()
{
return y;
}f.c:
#include "f.h"
int main()
{
}
$ clang f.c ./f.h:5:12: warning: static variable 'y' is used in an inline function with external linkage [-Wstatic-in-inline]
$ gcc f.c f.h:5:12: warning: ‘y’ is static but used in inline function ‘f’ which is not static
The actual effect of this patch is to enable the warning on clang *even outside headers* (clang only enables the warning in headers by default because, if a static variable belongs to the main source file, it has a single definition anyway unlike if it's defined in an included file).
For now I'm queuing patches 1-3 only.
Paolo
Quoted 20 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Reviewed-by Thomas Huth <[email protected]>--- 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',
Re: [PATCH-for-9.0? v2 4/4] meson: Enable -Wstatic-in-inline
Quoted 32 lines · Paolo Bonzini
Quoted 7 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++).
Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.
No problem with the first three patches, but -Wstatic-in-inline is not warning for non-static inline functions. The warning is enabled by default by GCC (which has no way to disable it even) and by clang outside headers:
f.h:
static int y;inline int
f()
{
return y;
}
f.c:
#include "f.h"int
main()
{
}$ clang f.c ./f.h:5:12: warning: static variable 'y' is used in an inline function with external linkage [-Wstatic-in-inline]
Quoted 7 lines
$ gcc f.c f.h:5:12: warning: ‘y’ is static but used in inline function ‘f’ which is not staticThe actual effect of this patch is to enable the warning on clang *even outside headers* (clang only enables the warning in headers by default because, if a static variable belongs to the main source file, it has a single definition anyway unlike if it's defined in an included file).
IIUC your comment, you are worried about system headers declaring non-static inline functions?
Quoted 26 lines
For now I'm queuing patches 1-3 only.
Paolo
Quoted 20 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Reviewed-by Thomas Huth <[email protected]>---
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',
Re: [PATCH-for-9.0? v2 4/4] meson: Enable -Wstatic-in-inline
Il mer 27 mar 2024, 13:42 Philippe Mathieu-Daudé <[email protected]> ha scritto:
Quoted 3 lines
IIUC your comment, you are worried about system headers declaring non-static inline functions?
No, it's just that the flag (and thus the patch) is not doing what the commit message says.
Perhaps you could instead add a checkpatch test that catches occurrences of inline without static.
Paolo
Quoted 28 lines
Quoted 26 lines
For now I'm queuing patches 1-3 only.
Paolo
Quoted 20 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Reviewed-by Thomas Huth <[email protected]>--- 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',