* [PATCH v3 0/3] BaseTools: fix gcc workaround
@ 2022-04-04 9:32 Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel Gerd Hoffmann
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2022-04-04 9:32 UTC (permalink / raw)
To: devel
Cc: Yuwei Chen, Liming Gao, Pawel Polawski, Bob Feng, Oliver Steffen,
Rebecca Cran, Gerd Hoffmann
The linux kernel has a bunch of useful macros to check whenever a given
compiler supports specific flags. Import them, adapt them for edk2, then
put them into use to make both gcc5 and gcc12 work for BaseTools.
Gerd Hoffmann (3):
BaseTools: import compiler check macros from linux kernel
BaseTools: adapt comniler checks mmacros for edk2
BaseTools: fix gcc workaround
BaseTools/Source/C/DevicePath/GNUmakefile | 3 +-
.../Source/C/Makefiles/compiler.makefile | 76 +++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletion(-)
create mode 100644 BaseTools/Source/C/Makefiles/compiler.makefile
--
2.35.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel
2022-04-04 9:32 [PATCH v3 0/3] BaseTools: fix gcc workaround Gerd Hoffmann
@ 2022-04-04 9:32 ` Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 2/3] BaseTools: adapt comniler checks mmacros for edk2 Gerd Hoffmann
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2022-04-04 9:32 UTC (permalink / raw)
To: devel
Cc: Yuwei Chen, Liming Gao, Pawel Polawski, Bob Feng, Oliver Steffen,
Rebecca Cran, Gerd Hoffmann
Makefile functions to check for compiler flags supported.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
.../Source/C/Makefiles/compiler.makefile | 76 +++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 BaseTools/Source/C/Makefiles/compiler.makefile
diff --git a/BaseTools/Source/C/Makefiles/compiler.makefile b/BaseTools/Source/C/Makefiles/compiler.makefile
new file mode 100644
index 000000000000..b575391c08d6
--- /dev/null
+++ b/BaseTools/Source/C/Makefiles/compiler.makefile
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+# copy from linux kernel soure tree (scripts/Makefile.compiler)
+
+# cc-cross-prefix
+# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
+# Return first <prefix> where a <prefix>gcc is found in PATH.
+# If no gcc found in PATH with listed prefixes return nothing
+#
+# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
+# would try to directly execute the shell builtin 'command'. This workaround
+# should be kept for a long time since this issue was fixed only after the
+# GNU Make 4.2.1 release.
+cc-cross-prefix = $(firstword $(foreach c, $(1), \
+ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
+
+# output directory for tests below
+TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
+
+# try-run
+# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
+# Exit code chooses option. "$$TMP" serves as a temporary file and is
+# automatically cleaned up.
+try-run = $(shell set -e; \
+ TMP=$(TMPOUT)/tmp; \
+ mkdir -p $(TMPOUT); \
+ trap "rm -rf $(TMPOUT)" EXIT; \
+ if ($(1)) >/dev/null 2>&1; \
+ then echo "$(2)"; \
+ else echo "$(3)"; \
+ fi)
+
+# as-option
+# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
+
+as-option = $(call try-run,\
+ $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
+
+# as-instr
+# Usage: cflags-y += $(call as-instr,instr,option1,option2)
+
+as-instr = $(call try-run,\
+ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
+
+# __cc-option
+# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
+__cc-option = $(call try-run,\
+ $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
+
+# cc-option
+# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
+
+cc-option = $(call __cc-option, $(CC),\
+ $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2))
+
+# cc-option-yn
+# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
+cc-option-yn = $(call try-run,\
+ $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+
+# cc-disable-warning
+# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
+cc-disable-warning = $(call try-run,\
+ $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+
+# cc-ifversion
+# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
+cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
+
+# ld-option
+# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
+ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
+
+# ld-ifversion
+# Usage: $(call ld-ifversion, -ge, 22252, y)
+ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4))
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/3] BaseTools: adapt comniler checks mmacros for edk2
2022-04-04 9:32 [PATCH v3 0/3] BaseTools: fix gcc workaround Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel Gerd Hoffmann
@ 2022-04-04 9:32 ` Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 3/3] BaseTools: fix gcc workaround Gerd Hoffmann
2022-04-04 15:18 ` [edk2-devel] [PATCH v3 0/3] " Pedro Falcato
3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2022-04-04 9:32 UTC (permalink / raw)
To: devel
Cc: Yuwei Chen, Liming Gao, Pawel Polawski, Bob Feng, Oliver Steffen,
Rebecca Cran, Gerd Hoffmann
edk2 BaseTools use BUILD_CC not CC. Update the check macros
accordingly so they actually work with BaseTools.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
BaseTools/Source/C/Makefiles/compiler.makefile | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/BaseTools/Source/C/Makefiles/compiler.makefile b/BaseTools/Source/C/Makefiles/compiler.makefile
index b575391c08d6..3337857ca9c5 100644
--- a/BaseTools/Source/C/Makefiles/compiler.makefile
+++ b/BaseTools/Source/C/Makefiles/compiler.makefile
@@ -18,7 +18,7 @@ cc-cross-prefix = $(firstword $(foreach c, $(1), \
TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
# try-run
-# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
+# Usage: option = $(call try-run, $(BUILD_CC)...-o "$$TMP",option-ok,otherwise)
# Exit code chooses option. "$$TMP" serves as a temporary file and is
# automatically cleaned up.
try-run = $(shell set -e; \
@@ -34,34 +34,34 @@ try-run = $(shell set -e; \
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
as-option = $(call try-run,\
- $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
+ $(BUILD_CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
# as-instr
# Usage: cflags-y += $(call as-instr,instr,option1,option2)
as-instr = $(call try-run,\
- printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
+ printf "%b\n" "$(1)" | $(BUILD_CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
# __cc-option
-# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
+# Usage: MY_CFLAGS += $(call __cc-option,$(BUILD_CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
__cc-option = $(call try-run,\
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
# cc-option
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
-cc-option = $(call __cc-option, $(CC),\
+cc-option = $(call __cc-option, $(BUILD_CC),\
$(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2))
# cc-option-yn
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
cc-option-yn = $(call try-run,\
- $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+ $(BUILD_CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
# cc-disable-warning
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
cc-disable-warning = $(call try-run,\
- $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+ $(BUILD_CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
# cc-ifversion
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
@@ -69,7 +69,7 @@ cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || e
# ld-option
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
-ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
+ld-option = $(call try-run, $(BUILD_LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
# ld-ifversion
# Usage: $(call ld-ifversion, -ge, 22252, y)
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/3] BaseTools: fix gcc workaround
2022-04-04 9:32 [PATCH v3 0/3] BaseTools: fix gcc workaround Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 2/3] BaseTools: adapt comniler checks mmacros for edk2 Gerd Hoffmann
@ 2022-04-04 9:32 ` Gerd Hoffmann
2022-04-04 15:18 ` [edk2-devel] [PATCH v3 0/3] " Pedro Falcato
3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2022-04-04 9:32 UTC (permalink / raw)
To: devel
Cc: Yuwei Chen, Liming Gao, Pawel Polawski, Bob Feng, Oliver Steffen,
Rebecca Cran, Gerd Hoffmann
Check whenever the compiler used knows the warning we want disable.
Fixes: 22130dcd98b4 ("Basetools: turn off gcc12 warning")
Reported-by: Rebecca Cran <rebecca@bsdio.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
BaseTools/Source/C/DevicePath/GNUmakefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile
index b05d2bddfa68..1cc966c4831f 100644
--- a/BaseTools/Source/C/DevicePath/GNUmakefile
+++ b/BaseTools/Source/C/DevicePath/GNUmakefile
@@ -12,9 +12,10 @@ APPNAME = DevicePath
OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o DevicePathUtilities.o
include $(MAKEROOT)/Makefiles/app.makefile
+include $(MAKEROOT)/Makefiles/compiler.makefile
# gcc 12 trips over device path handling
-BUILD_CFLAGS += -Wno-error=stringop-overflow
+BUILD_CFLAGS += $(call cc-disable-warning,stringop-overflow)
LIBS = -lCommon
ifeq ($(CYGWIN), CYGWIN)
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [PATCH v3 0/3] BaseTools: fix gcc workaround
2022-04-04 9:32 [PATCH v3 0/3] BaseTools: fix gcc workaround Gerd Hoffmann
` (2 preceding siblings ...)
2022-04-04 9:32 ` [PATCH v3 3/3] BaseTools: fix gcc workaround Gerd Hoffmann
@ 2022-04-04 15:18 ` Pedro Falcato
2022-04-07 10:12 ` Gerd Hoffmann
3 siblings, 1 reply; 7+ messages in thread
From: Pedro Falcato @ 2022-04-04 15:18 UTC (permalink / raw)
To: edk2-devel-groups-io, Gerd Hoffmann
Cc: Yuwei Chen, Liming Gao, Pawel Polawski, Bob Feng, Oliver Steffen,
Rebecca Cran
[-- Attachment #1: Type: text/plain, Size: 972 bytes --]
Hi Gerd,
These patches are a great idea but I don't know if we can take GPLv2 code
like that. Are they even mergeable into the main edk2 repo (as it's not
compatible with BSD-2-clause)?
Thanks,
Pedro
On Mon, Apr 4, 2022 at 10:32 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
> The linux kernel has a bunch of useful macros to check whenever a given
> compiler supports specific flags. Import them, adapt them for edk2, then
> put them into use to make both gcc5 and gcc12 work for BaseTools.
>
> Gerd Hoffmann (3):
> BaseTools: import compiler check macros from linux kernel
> BaseTools: adapt comniler checks mmacros for edk2
> BaseTools: fix gcc workaround
>
> BaseTools/Source/C/DevicePath/GNUmakefile | 3 +-
> .../Source/C/Makefiles/compiler.makefile | 76 +++++++++++++++++++
> 2 files changed, 78 insertions(+), 1 deletion(-)
> create mode 100644 BaseTools/Source/C/Makefiles/compiler.makefile
>
> --
> 2.35.1
>
>
>
>
>
>
>
--
Pedro Falcato
[-- Attachment #2: Type: text/html, Size: 1505 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [PATCH v3 0/3] BaseTools: fix gcc workaround
2022-04-04 15:18 ` [edk2-devel] [PATCH v3 0/3] " Pedro Falcato
@ 2022-04-07 10:12 ` Gerd Hoffmann
2022-04-09 3:53 ` Bob Feng
0 siblings, 1 reply; 7+ messages in thread
From: Gerd Hoffmann @ 2022-04-07 10:12 UTC (permalink / raw)
To: Pedro Falcato
Cc: edk2-devel-groups-io, Yuwei Chen, Liming Gao, Pawel Polawski,
Bob Feng, Oliver Steffen, Rebecca Cran
On Mon, Apr 04, 2022 at 04:18:56PM +0100, Pedro Falcato wrote:
> Hi Gerd,
>
> These patches are a great idea but I don't know if we can take GPLv2 code
> like that. Are they even mergeable into the main edk2 repo (as it's not
> compatible with BSD-2-clause)?
It's build system, doesn't end up being linked into firmware code, so
not sure license compatibility is actually a problem here.
In any case I strongly prefer to fix that in some automatic way which
does *not* require a new GCC12 tool chain definition.
So, any comments how to move forward with this?
Can we take the series as-is?
If not, other suggestions?
Second-best idea I've seen on the list is using 'gcc -dumpversion'.
Is it an option to just raise the minimum required gcc version to
something newer? gcc5 was released almost 7 years ago ...
take care,
Gerd
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [edk2-devel] [PATCH v3 0/3] BaseTools: fix gcc workaround
2022-04-07 10:12 ` Gerd Hoffmann
@ 2022-04-09 3:53 ` Bob Feng
0 siblings, 0 replies; 7+ messages in thread
From: Bob Feng @ 2022-04-09 3:53 UTC (permalink / raw)
To: Gerd Hoffmann, Pedro Falcato, Chen, Christine, Gao, Liming
Cc: edk2-devel-groups-io, Pawel Polawski, Oliver Steffen,
Rebecca Cran
Hi Gerd,
Your patches are great but I think we can't take them because of the incompatible license.
I think the new Toolchain definition, like GCC12, can not resolve this issue because Toolchain is not used for building BaseTools.
So I'd prefer the second option of using 'gcc -dumpversion'.
And also we have the task to convert the tools implemented by C to python implementation. After we have done that, there will be no BaseTools build issue.
https://github.com/tianocore/edk2-staging/tree/PyBaseTools
@Gao, Liming @Chen, Christine
Could you review the corresponding patch?
Thanks,
Bob
-----Original Message-----
From: Gerd Hoffmann <kraxel@redhat.com>
Sent: Thursday, April 7, 2022 6:12 PM
To: Pedro Falcato <pedro.falcato@gmail.com>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>; Chen, Christine <yuwei.chen@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Pawel Polawski <ppolawsk@redhat.com>; Feng, Bob C <bob.c.feng@intel.com>; Oliver Steffen <osteffen@redhat.com>; Rebecca Cran <rebecca@bsdio.com>
Subject: Re: [edk2-devel] [PATCH v3 0/3] BaseTools: fix gcc workaround
On Mon, Apr 04, 2022 at 04:18:56PM +0100, Pedro Falcato wrote:
> Hi Gerd,
>
> These patches are a great idea but I don't know if we can take GPLv2
> code like that. Are they even mergeable into the main edk2 repo (as
> it's not compatible with BSD-2-clause)?
It's build system, doesn't end up being linked into firmware code, so not sure license compatibility is actually a problem here.
In any case I strongly prefer to fix that in some automatic way which does *not* require a new GCC12 tool chain definition.
So, any comments how to move forward with this?
Can we take the series as-is?
If not, other suggestions?
Second-best idea I've seen on the list is using 'gcc -dumpversion'.
Is it an option to just raise the minimum required gcc version to something newer? gcc5 was released almost 7 years ago ...
take care,
Gerd
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-09 3:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-04 9:32 [PATCH v3 0/3] BaseTools: fix gcc workaround Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 1/3] BaseTools: import compiler check macros from linux kernel Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 2/3] BaseTools: adapt comniler checks mmacros for edk2 Gerd Hoffmann
2022-04-04 9:32 ` [PATCH v3 3/3] BaseTools: fix gcc workaround Gerd Hoffmann
2022-04-04 15:18 ` [edk2-devel] [PATCH v3 0/3] " Pedro Falcato
2022-04-07 10:12 ` Gerd Hoffmann
2022-04-09 3:53 ` Bob Feng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox