mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] kbuild: undefine linux/unix macros
@ 2025-03-27 13:20 Bastian Krause
  2025-03-27 13:24 ` Ahmad Fatoum
  2025-03-31  7:11 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Bastian Krause @ 2025-03-27 13:20 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Bastian Krause

gcc and clang, when using `-std=gnu11`, predefine `linux` and `unix` as
macros:

  $ gcc -std=gnu11 -dM -E - < /dev/null | grep -v "define _"
  #define unix 1
  #define linux 1

This causes issues in `BAREBOX_MAGICVAR()`, where variable names
containing "linux" or "unix" get incorrectly expanded, leading to invalid
names:

  barebox@Sandbox:/ magicvar
  [...]
  global.1.blkdevparts.*           Linux blkdevparts variables
  global.1.bootargs.*              Linux bootargs variables
  global.1.bootargs.console        console= argument for Linux from the stdout-path property in /chosen node
  global.1.bootargs_append         append to original oftree bootargs
  global.1.mtdparts.*              Linux mtdparts variables
  [...]

Explicitly undefine these non-conforming macros to ensure correct
behavior.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5c9fce83123..ff7179bf9d5 100644
--- a/Makefile
+++ b/Makefile
@@ -486,7 +486,8 @@ LINUXINCLUDE    := -Iinclude \
 		   -I$(objtree)/arch/$(SRCARCH)/include \
 		   $(USERINCLUDE)
 
-KBUILD_CPPFLAGS        := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) -fno-builtin -ffreestanding
+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 \
-- 
2.39.5




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

end of thread, other threads:[~2025-03-31  7:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-27 13:20 [PATCH] kbuild: undefine linux/unix macros Bastian Krause
2025-03-27 13:24 ` Ahmad Fatoum
2025-03-31  7:11 ` Sascha Hauer

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