mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Bastian Krause <bst@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Bastian Krause <bst@pengutronix.de>
Subject: [PATCH] kbuild: undefine linux/unix macros
Date: Thu, 27 Mar 2025 14:20:52 +0100	[thread overview]
Message-ID: <20250327132052.3187117-1-bst@pengutronix.de> (raw)

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




             reply	other threads:[~2025-03-27 13:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-27 13:20 Bastian Krause [this message]
2025-03-27 13:24 ` Ahmad Fatoum
2025-03-31  7:11 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250327132052.3187117-1-bst@pengutronix.de \
    --to=bst@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox