Sparse warnings on GENMASK + arm32
Subsystems (2)
I see sparse warning when I check a clk driver file in the kernel on a 32-bit ARM build.
drivers/clk/sunxi/clk-sun6i-ar100.c:65:20: warning: cast truncates bits from constant value (3ffffffff becomes ffffffff)
The code in question looks like:
static const struct factors_data sun6i_ar100_data = {
.mux = 16,
.muxmask = GENMASK(1, 0),
.table = &sun6i_ar100_config,
.getter = sun6i_get_ar100_factors,
};where factors_data is
struct factors_data {
int enable;
int mux;
int muxmask;
const struct clk_factors_config *table;
void (*getter)(struct factors_request *req);
void (*recalc)(struct factors_request *req);
const char *name;
};and sparse seems to be complaining about the muxmask assignment here. Oddly, this doesn't happen on arm64 builds. Both times, I'm checking this on an x86-64 machine.
$ sparse --version v0.5.1-rc4-1-gfa71b7ac0594
Is there something confusing to sparse in the GENMASK macro?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 1/1 arm: fix sparse flags for build on 64bit machines
By default sparse uses the characteristics of the build machine to infer things like the wordsize.
This is fine when doing native builds but for ARM it's, I suspect, very rarely the case and if the build are done on a 64bit machine we get a bunch of warnings like:
'cast truncates bits from constant value (... becomes ...)'
Fix this by adding the -m32 flags for sparse.
--- arch/arm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Makefile +1 -1
@@ -131,7 +131,7 @@ endif KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float -CHECKFLAGS += -D__arm__ +CHECKFLAGS += -D__arm__ -m32 #Default value head-y := arch/arm/kernel/head$(MMUEXT).o
Signature · 1 line
2.13.2
PATCH 1/1 arm: fix sparse flags for build on 64bit machines
Quoted 11 lines · Luc Van Oostenryck
By default sparse uses the characteristics of the build machine to infer things like the wordsize.
This is fine when doing native builds but for ARM it's, I suspect, very rarely the case and if the build are done on a 64bit machine we get a bunch of warnings like:
'cast truncates bits from constant value (... becomes ...)'Fix this by adding the -m32 flags for sparse.
Reported-by Stephen Boyd <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>
Thanks.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 1/1 arm: fix sparse flags for build on 64bit machines
Quoted 8 lines · Stephen Boyd
Quoted 7 lines · Luc Van Oostenryck
By default sparse uses the characteristics of the build machine to infer things like the wordsize.
This is fine when doing native builds but for ARM it's, I suspect, very rarely the case and if the build are done on a 64bit machine we get a bunch of warnings like:
'cast truncates bits from constant value (... becomes ...)'
Quoted 7 lines
Quoted 4 lines
Fix this by adding the -m32 flags for sparse.
Reported-by Stephen Boyd <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>Tested-by Stephen Boyd <[email protected]>
Russell, is this good to put in the patch tracker?
Luc, can you submit this via Russell's patch tracking system (see
http://www.arm.linux.org.uk/developer/patches/info.php)?
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 1/1 arm: fix sparse flags for build on 64bit machines
Quoted 17 lines · Stephen Boyd
Quoted 8 lines · Stephen Boyd
Quoted 7 lines · Luc Van Oostenryck
By default sparse uses the characteristics of the build machine to infer things like the wordsize.
This is fine when doing native builds but for ARM it's, I suspect, very rarely the case and if the build are done on a 64bit machine we get a bunch of warnings like:
'cast truncates bits from constant value (... becomes ...)'Quoted 7 lines
Quoted 4 lines
Fix this by adding the -m32 flags for sparse.
Reported-by Stephen Boyd <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>Tested-by Stephen Boyd <[email protected]>
Quoted 6 lines
Russell, is this good to put in the patch tracker?
Luc, can you submit this via Russell's patch tracking system (see
http://www.arm.linux.org.uk/developer/patches/info.php)?
It's been a while, and this isn't in linux-next or the patch tracker from what I can tell. I'll forward it along if nothing happens in the next couple days.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 1/1 arm: fix sparse flags for build on 64bit machines
Quoted 21 lines · Stephen Boyd
Quoted 20 lines · Stephen Boyd
Quoted 8 lines · Stephen Boyd
Quoted 7 lines · Luc Van Oostenryck
By default sparse uses the characteristics of the build machine to infer things like the wordsize.
This is fine when doing native builds but for ARM it's, I suspect, very rarely the case and if the build are done on a 64bit machine we get a bunch of warnings like:
'cast truncates bits from constant value (... becomes ...)'Quoted 7 lines
Quoted 4 lines
Fix this by adding the -m32 flags for sparse.
Reported-by Stephen Boyd <[email protected]>Signed-off-by Luc Van Oostenryck <[email protected]>Tested-by Stephen Boyd <[email protected]>Russell, is this good to put in the patch tracker?
Quoted 7 lines
Quoted 3 lines
Luc, can you submit this via Russell's patch tracking system (see
http://www.arm.linux.org.uk/developer/patches/info.php)?It's been a while, and this isn't in linux-next or the patch tracker from what I can tell. I'll forward it along if nothing happens in the next couple days.
Sorry, I had forgot about it.
It's now added as patch 8701/1 in Russell's system.
-- Luc
Quoted 34 lines
From: "Stephen Boyd" <[email protected]>
To: [email protected]
Cc: [email protected]
Sent: Tuesday, 25 July, 2017 9:30:20 PM
Subject: Sparse warnings on GENMASK + arm32I see sparse warning when I check a clk driver file in the kernel on a 32-bit ARM build.
drivers/clk/sunxi/clk-sun6i-ar100.c:65:20: warning: cast truncates bits from constant value (3ffffffffbecomes ffffffff)The code in question looks like:
static const struct factors_data sun6i_ar100_data = { .mux = 16, .muxmask = GENMASK(1, 0), .table = &sun6i_ar100_config, .getter = sun6i_get_ar100_factors, };where
factors_dataisstruct factors_data { int enable; int mux; int muxmask; const struct clk_factors_config *table; void (*getter)(struct factors_request *req); void (*recalc)(struct factors_request *req); const char *name; };
Quoted 9 lines
and sparse seems to be complaining about the muxmask assignment here. Oddly, this doesn't happen on arm64 builds. Both times, I'm checking this on an x86-64 machine.
$ sparse --version v0.5.1-rc4-1-gfa71b7ac0594Is there something confusing to sparse in the GENMASK macro?
Hmm, it seems sparse is incorrectly taking ~0UL to be a 64-bit value while BITS_PER_LONG is (correctly) evaluated to be 32.
#define GENMASK(h, l) \ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
Quoted 8 lines
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Lance Richardson
Quoted 4 lines
From: "Stephen Boyd" <[email protected]>
I see sparse warning when I check a clk driver file in the kernel on a 32-bit ARM build.
Quoted 8 lines
Quoted 2 lines
drivers/clk/sunxi/clk-sun6i-ar100.c:65:20: warning: cast truncates bits from constant value (3ffffffffbecomes ffffffff)Hmm, it seems sparse is incorrectly taking ~0UL to be a 64-bit value while
BITS_PER_LONGis (correctly) evaluated to be 32.#define GENMASK(h, l) \ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
It's the kernel CHECKFLAGS that should be using -m32/-m64 if built on a machine with a different wordsize tht the arch.
I sent earlier a patch for ARM, I just forgot to CC the mailing list here.
-- Luc
Christopher Li
maintainerQuoted 6 lines · Lance Richardson
Hmm, it seems sparse is incorrectly taking ~0UL to be a 64-bit value while
BITS_PER_LONGis (correctly) evaluated to be 32.#define GENMASK(h, l) \ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
What is the sizeof(unsigned long) in ARM 32 bit world?
~0UL has the type of "unsigned long", I assume BITS_PER_LONG is just plain "int"? Using sparse -E should be able to get the expression after the macro expression.
The kernel compile invoke sparse directly. That is the assumption that the host gcc has the same type size as the target gcc. That is no longer true if you have cross compiler.
If you want to have sparse understand the proper architecture difference, the current practices is using cgcc to handle the architecture specific macros.
you can try to invoke the kernel building with: CHECK="cgcc -no-compile".
Warning: I haven't try that myself, it might not work as expected.
In the long run, I do wish sparse can implement the proper handling of the architecture specific stuff by itself without go through of cgcc.
Chris