Skip to contentSkip to conversation

tools: Stop re-defining -std= when building tools

PATCH Superseded Tom Rini 2 participants 4 messages Oct 10, 2021 – Oct 11, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 tools: Stop re-defining -std= when building tools

While we intentionally set -std=gnu11 for building host tools, and have
for quite some time, we never dropped -std=gnu99 from tools/Makefile.
This resulted in passing -std=gnu11 ... -std=gnu99 when building, and
gnu99 would win. This in turn would result now in warnings such as:
tools/mkeficapsule.c:25:15: warning: redefinition of typedef 'u32' is a C11 feature [-Wtypedef-redefinition]

typedef __u32 u32;
              ^
---
 tools/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/Makefile +1 -2
index 999fd4653166..b45219e2c30c 100644
@@ -295,8 +295,7 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
 		-I$(srctree)/tools \
 		-DUSE_HOSTCC \
 		-D__KERNEL_STRICT_NAMES \
-		-D_GNU_SOURCE \
-		-std=gnu99
+		-D_GNU_SOURCE
 
 __build:	$(LOGO-y)
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 19 lines · Tom Rini

While we intentionally set -std=gnu11 for building host tools, and have
for quite some time, we never dropped -std=gnu99 from tools/Makefile.
This resulted in passing -std=gnu11 ... -std=gnu99 when building, and
gnu99 would win. This in turn would result now in warnings such as:
tools/mkeficapsule.c:25:15: warning: redefinition of typedef 'u32' is a C11 feature [-Wtypedef-redefinition]

typedef __u32 u32;
              ^
---
 tools/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/Makefile +0 -0
index 999fd4653166..b45219e2c30c 100644

tools/Makefile HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \ · line 298

Quoted 6 lines
tools/Makefile +1 -2
@@ -295,8 +295,7 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
                -I$(srctree)/tools \
                -DUSE_HOSTCC \
                -D__KERNEL_STRICT_NAMES \
-               -D_GNU_SOURCE \
-               -std=gnu99
+               -D_GNU_SOURCE

It looks like std=gnu11 is only added for Linux host.

KBUILD_HOSTCFLAGS += $(CSTD_FLAG)

Should we still keep it for other hosts?

Regards,
Bin

author
#2 lore raw
Quoted 29 lines · Bin Meng
Quoted 19 lines · Tom Rini

While we intentionally set -std=gnu11 for building host tools, and have
for quite some time, we never dropped -std=gnu99 from tools/Makefile.
This resulted in passing -std=gnu11 ... -std=gnu99 when building, and
gnu99 would win. This in turn would result now in warnings such as:
tools/mkeficapsule.c:25:15: warning: redefinition of typedef 'u32' is a C11 feature [-Wtypedef-redefinition]

typedef __u32 u32;
              ^
---
 tools/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/Makefile +0 -0
index 999fd4653166..b45219e2c30c 100644

tools/Makefile HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \ · line 298

Quoted 6 lines
tools/Makefile +1 -2
@@ -295,8 +295,7 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
                -I$(srctree)/tools \
                -DUSE_HOSTCC \
                -D__KERNEL_STRICT_NAMES \
-               -D_GNU_SOURCE \
-               -std=gnu99
+               -D_GNU_SOURCE

It looks like std=gnu11 is only added for Linux host.

Quoted 3 lines

KBUILD_HOSTCFLAGS += $(CSTD_FLAG)

Should we still keep it for other hosts?

Good question. Looking at the Linux kernel, we're of course vastly diverged again at this point, but it always passes -std=gnu89 (because hey, we demand a newer minimum than the kernel) unless it's a tool/test that spells out something else. Given that Azure builds macOS and cygwin for us, I'll see what happens when we tell everyone to use -std=gnu11 and report back.

Signature · 1 line
Tom
author
#3 lore raw
Quoted 32 lines · Tom Rini
Quoted 31 lines · Bin Meng
Quoted 19 lines · Tom Rini

While we intentionally set -std=gnu11 for building host tools, and have
for quite some time, we never dropped -std=gnu99 from tools/Makefile.
This resulted in passing -std=gnu11 ... -std=gnu99 when building, and
gnu99 would win. This in turn would result now in warnings such as:
tools/mkeficapsule.c:25:15: warning: redefinition of typedef 'u32' is a C11 feature [-Wtypedef-redefinition]

typedef __u32 u32;
              ^
---
 tools/Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/Makefile +0 -0
index 999fd4653166..b45219e2c30c 100644

tools/Makefile HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \ · line 298

Quoted 6 lines
tools/Makefile +1 -2
@@ -295,8 +295,7 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/compiler.h \
                -I$(srctree)/tools \
                -DUSE_HOSTCC \
                -D__KERNEL_STRICT_NAMES \
-               -D_GNU_SOURCE \
-               -std=gnu99
+               -D_GNU_SOURCE

It looks like std=gnu11 is only added for Linux host.

KBUILD_HOSTCFLAGS += $(CSTD_FLAG)

Quoted 8 lines
Quoted 1 line

Should we still keep it for other hosts?

Good question. Looking at the Linux kernel, we're of course vastly diverged again at this point, but it always passes -std=gnu89 (because hey, we demand a newer minimum than the kernel) unless it's a tool/test that spells out something else. Given that Azure builds macOS and cygwin for us, I'll see what happens when we tell everyone to use -std=gnu11 and report back.

The build completed:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=3024&view=results
and the interesting parts are:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=3024&view=logs&j=35e64860-b659-5ca1-bdf9-6e9833a3e679&t=17b0785b-bff7-569f-a47c-ec4f4762bca5
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=3024&view=logs&j=54366476-fdb5-57fd-e8dc-672a8abc134d&t=4b05ba05-ad38-52b6-35d9-bb8255f5e2ea

In sum, we can use -std=gnu11 everywhere. There's warnings on these hosts, but that's been true before this change:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=2991&view=results

Posting v2 in a moment.

Signature · 1 line
Tom