mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] kbuild: treat char as always unsigned
@ 2025-04-22  6:39 Ahmad Fatoum
  2025-04-22  7:42 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2025-04-22  6:39 UTC (permalink / raw)
  To: barebox; +Cc: Yann Sionneau, Michael Olbrich, Ahmad Fatoum

The C standard makes it implementation defined whether a plain char is
unsigned or signed and the architectures where barebox is compiled for
differ in that, e.g. chars are traditionally unsigned on ARM, but on x86
for example they tend to be signed.

This caused different bugs[1][2][3] in the past, especially around
behavior when casted to int. Let's instruct the compiler to treat char
as always unsigned. This may fix some issues that flew under the radar
so far, but also break drivers that were compiled and used only for
specific architectures, which implicitly assumed char is signed, which
we'll have to fix.

Linux is also being compiled with the same flag since 2022 with Linux
commit 3bc753c06dd0 ("kbuild: treat char as always unsigned").

[1]: 02a3c4f39690 ("readkey: keys are unsigned char")
[2]: f8fccf2ef8c9 ("mci: fix wrong sd/mmc/emmc card size computation for arch where char is signed")
[3]: https://lore.barebox.org/barebox/20250422053641.3435585-1-a.fatoum@pengutronix.de/T/#u

Cc: Yann Sionneau <ysionneau@kalrayinc.com>
Cc: Michael Olbrich <mol@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
This will need extra testing, so this shouldn't go into next until after
the next release.
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 7739078288ea..e37b82d5132c 100644
--- a/Makefile
+++ b/Makefile
@@ -490,7 +490,7 @@ KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) \
 			  -fno-builtin -ffreestanding -Ulinux -Uunix
 
 KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
-		   -fno-strict-aliasing -fno-common -fshort-wchar \
+		   -fno-strict-aliasing -fno-common -fshort-wchar -funsigned-char \
 		   -Werror=implicit-function-declaration -Werror=implicit-int \
 		   -Werror=int-conversion \
 		   -Os -pipe -Wmissing-prototypes -std=gnu11
-- 
2.39.5




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: treat char as always unsigned
  2025-04-22  6:39 [PATCH] kbuild: treat char as always unsigned Ahmad Fatoum
@ 2025-04-22  7:42 ` Sascha Hauer
  2025-04-22  7:52   ` Ahmad Fatoum
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2025-04-22  7:42 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: Yann Sionneau, Michael Olbrich


On Tue, 22 Apr 2025 08:39:10 +0200, Ahmad Fatoum wrote:
> The C standard makes it implementation defined whether a plain char is
> unsigned or signed and the architectures where barebox is compiled for
> differ in that, e.g. chars are traditionally unsigned on ARM, but on x86
> for example they tend to be signed.
> 
> This caused different bugs[1][2][3] in the past, especially around
> behavior when casted to int. Let's instruct the compiler to treat char
> as always unsigned. This may fix some issues that flew under the radar
> so far, but also break drivers that were compiled and used only for
> specific architectures, which implicitly assumed char is signed, which
> we'll have to fix.
> 
> [...]

Applied, thanks!

[1/1] kbuild: treat char as always unsigned
      https://git.pengutronix.de/cgit/barebox/commit/?id=2a6033a6610b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: treat char as always unsigned
  2025-04-22  7:42 ` Sascha Hauer
@ 2025-04-22  7:52   ` Ahmad Fatoum
  2025-04-22  8:14     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2025-04-22  7:52 UTC (permalink / raw)
  To: Sascha Hauer, barebox; +Cc: Yann Sionneau, Michael Olbrich

Hello Sascha,

On 22.04.25 09:42, Sascha Hauer wrote:
> 
> On Tue, 22 Apr 2025 08:39:10 +0200, Ahmad Fatoum wrote:
>> The C standard makes it implementation defined whether a plain char is
>> unsigned or signed and the architectures where barebox is compiled for
>> differ in that, e.g. chars are traditionally unsigned on ARM, but on x86
>> for example they tend to be signed.
>>
>> This caused different bugs[1][2][3] in the past, especially around
>> behavior when casted to int. Let's instruct the compiler to treat char
>> as always unsigned. This may fix some issues that flew under the radar
>> so far, but also break drivers that were compiled and used only for
>> specific architectures, which implicitly assumed char is signed, which
>> we'll have to fix.
>>
>> [...]
> 
> Applied, thanks!

Please wait with this until after the release, so it sits in next for
a whole month first.

Thanks,
Ahmad

> 
> [1/1] kbuild: treat char as always unsigned
>       https://git.pengutronix.de/cgit/barebox/commit/?id=2a6033a6610b (link may not be stable)
> 
> Best regards,


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: treat char as always unsigned
  2025-04-22  7:52   ` Ahmad Fatoum
@ 2025-04-22  8:14     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-04-22  8:14 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, Yann Sionneau, Michael Olbrich

On Tue, Apr 22, 2025 at 09:52:06AM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 22.04.25 09:42, Sascha Hauer wrote:
> > 
> > On Tue, 22 Apr 2025 08:39:10 +0200, Ahmad Fatoum wrote:
> >> The C standard makes it implementation defined whether a plain char is
> >> unsigned or signed and the architectures where barebox is compiled for
> >> differ in that, e.g. chars are traditionally unsigned on ARM, but on x86
> >> for example they tend to be signed.
> >>
> >> This caused different bugs[1][2][3] in the past, especially around
> >> behavior when casted to int. Let's instruct the compiler to treat char
> >> as always unsigned. This may fix some issues that flew under the radar
> >> so far, but also break drivers that were compiled and used only for
> >> specific architectures, which implicitly assumed char is signed, which
> >> we'll have to fix.
> >>
> >> [...]
> > 
> > Applied, thanks!
> 
> Please wait with this until after the release, so it sits in next for
> a whole month first.

Ok, dropped for now. Please ping me after the release in case I forget.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-22  9:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-22  6:39 [PATCH] kbuild: treat char as always unsigned Ahmad Fatoum
2025-04-22  7:42 ` Sascha Hauer
2025-04-22  7:52   ` Ahmad Fatoum
2025-04-22  8:14     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox