* [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build
@ 2025-02-20 6:46 Ahmad Fatoum
2025-02-20 6:46 ` [PATCH master 2/2] scripts: common.h: define loff_t on musl Ahmad Fatoum
2025-02-21 10:22 ` [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-02-20 6:46 UTC (permalink / raw)
To: barebox; +Cc: ejo, Ahmad Fatoum
Defining _GNU_SOURCE via userccflags (for target tools) and KBUILD_HOSTCFLAGS
(for host tools) works, but needs to be repeated in subdirectories like i.MX
as well. As we make ample use of the asprintf GNU extension anyway, let's just
define it in the top-level makefile for build of all user code.
Fixes: 02a61edc1842 ("scripts: define _GNU_SOURCE for all source files")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Makefile | 3 ++-
scripts/Makefile | 4 ----
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 5488f9d97251..4e6ac5a10a97 100644
--- a/Makefile
+++ b/Makefile
@@ -399,7 +399,8 @@ HOSTCXX = g++
endif
KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
- -O2 -fomit-frame-pointer -std=gnu11
+ -O2 -fomit-frame-pointer -std=gnu11 \
+ -D_GNU_SOURCE=""
KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
KBUILD_USERLDFLAGS := $(USERLDFLAGS)
diff --git a/scripts/Makefile b/scripts/Makefile
index bb4e85b0a639..6d89af7d4f35 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -60,10 +60,6 @@ rk-usb-loader-target-userldlibs += `$(CROSS_PKG_CONFIG) --libs libusb-1.0`
userccflags += -I $(srctree)/$(src)/include -isystem $(srctree)/scripts/include
-# We need to explicitly set the macro to empty, otherwise it's defined to =1
-userccflags += -D_GNU_SOURCE=""
-KBUILD_HOSTCFLAGS += -D_GNU_SOURCE=""
-
subdir-y += mod
subdir-y += imx
subdir-$(CONFIG_ARCH_TEGRA) += tegra
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH master 2/2] scripts: common.h: define loff_t on musl
2025-02-20 6:46 [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Ahmad Fatoum
@ 2025-02-20 6:46 ` Ahmad Fatoum
2025-02-21 10:22 ` [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-02-20 6:46 UTC (permalink / raw)
To: barebox; +Cc: ejo, Ahmad Fatoum
Target tool build against musl fails, because loff_t is undefined,
despite _GNU_SOURCE being defined.
This is because glibc defines loff_t via <sys/types.h>, but musl defines
loff_t only in fcntl.h and the latter file isn't included beforehand in
imx-usb-loader-target.c.
Add the missing include to <linux/types.h> and include that header in
scripts/common.h to resolve the musl breakage.
This issue was noticedd during a Yocto build against musl, but can be
easily reproduced in Debian as well using the musl-tools package:
export ARCH=sandbox
make HOSTCC=musl-gcc CC=musl-gcc targettools_defconfig
make HOSTCC=musl-gcc CC=musl-gcc
Changes to CI to build sandbox against musl will follow later.
Fixes: 5171f4d0696f ("scripts: implement read_fd and pread_full for tools")
Reported-by: Enrico Jörns <ejo@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/common.h | 2 ++
scripts/include/linux/types.h | 1 +
2 files changed, 3 insertions(+)
diff --git a/scripts/common.h b/scripts/common.h
index a0d16606b5d9..21ec576a5be9 100644
--- a/scripts/common.h
+++ b/scripts/common.h
@@ -1,6 +1,8 @@
#ifndef __COMMON_H
#define __COMMON_H
+#include <linux/types.h>
+
int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_size);
void *read_file(const char *filename, size_t *size);
void *read_fd(int fd, size_t *out_size);
diff --git a/scripts/include/linux/types.h b/scripts/include/linux/types.h
index e81d7e810126..5b0133345bb9 100644
--- a/scripts/include/linux/types.h
+++ b/scripts/include/linux/types.h
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <fcntl.h>
typedef uint64_t __u64;
typedef int64_t __s64;
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build
2025-02-20 6:46 [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Ahmad Fatoum
2025-02-20 6:46 ` [PATCH master 2/2] scripts: common.h: define loff_t on musl Ahmad Fatoum
@ 2025-02-21 10:22 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-02-21 10:22 UTC (permalink / raw)
To: barebox, Ahmad Fatoum; +Cc: ejo
On Thu, 20 Feb 2025 07:46:11 +0100, Ahmad Fatoum wrote:
> Defining _GNU_SOURCE via userccflags (for target tools) and KBUILD_HOSTCFLAGS
> (for host tools) works, but needs to be repeated in subdirectories like i.MX
> as well. As we make ample use of the asprintf GNU extension anyway, let's just
> define it in the top-level makefile for build of all user code.
>
>
Applied, thanks!
[1/2] scripts: define _GNU_SOURCE for every user tool build
https://git.pengutronix.de/cgit/barebox/commit/?id=6b0121ddc44b (link may not be stable)
[2/2] scripts: common.h: define loff_t on musl
https://git.pengutronix.de/cgit/barebox/commit/?id=f0c67c9477c9 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-21 10:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 6:46 [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Ahmad Fatoum
2025-02-20 6:46 ` [PATCH master 2/2] scripts: common.h: define loff_t on musl Ahmad Fatoum
2025-02-21 10:22 ` [PATCH master 1/2] scripts: define _GNU_SOURCE for every user tool build Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox