firmware: build fixes with gcc-11
cover firmware: build fixes with gcc-11
Hello,
The following fixes some firmware build issues with gcc-11. Note that dropping of .note.gnu.property section could likely be done in the linker script in the hvmloader case, but rombios has no linker script and such note is causing a non-working image. Other options could be using objcopy to drop the section, but those seems more complicated than just using the compiler command line option.
Thanks, Roger.
Roger Pau Monne (2):
tools/firmware: fix setting of fcf-protection=none tools/firmware: do not add a .note.gnu.property section
Config.mk | 2 +- tools/firmware/Makefile | 2 -- tools/firmware/Rules.mk | 6 ++++++ 3 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.35.1
PATCH 2/2 tools/firmware: do not add a .note.gnu.property section
Prevent the assembler from creating a .note.gnu.property section on the output objects, as it's not useful for firmware related binaries, and breaks the resulting rombios image.
This requires modifying the cc-option Makefile macro so it can test assembler options (by replacing the usage of the -S flag with -c) and also stripping the -Wa, prefix if present when checking for the test output.
--- Config.mk | 2 +- tools/firmware/Rules.mk | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
Config.mk +1 -1
@@ -91,7 +91,7 @@ PYTHON_PREFIX_ARG ?= --prefix="$(prefix)" # # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586) cc-option = $(shell if test -z "`echo 'void*p=1;' | \ - $(1) $(2) -S -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \ + $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2:-Wa$(comma)%=%) -`"; \ then echo "$(2)"; else echo "$(3)"; fi ;) # cc-option-add: Add an option to compilation flags, but only if supported.
tools/firmware/Rules.mk +4 -0
@@ -15,6 +15,10 @@ CFLAGS += -Werror EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none +# Do not add the .note.gnu.property section to any of the firmware objects: it +# breaks the rombios binary and is not useful for firmware anyway. +EMBEDDED_EXTRA_CFLAGS += -Wa$$(comma)-mx86-used-note=no + $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) # Extra CFLAGS suitable for an embedded type of environment.
Signature · 1 line
2.35.1
PATCH 1/2 tools/firmware: fix setting of fcf-protection=none
In reply to Roger Pau MonneSetting the fcf-protection=none option in EMBEDDED_EXTRA_CFLAGS in the Makefile doesn't get it propagated to the subdirectories, so instead set the flag in firmware/Rules.mk, like it's done for other compiler flags.
--- tools/firmware/Makefile | 2 -- tools/firmware/Rules.mk | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)
tools/firmware/Makefile +0 -2
@@ -6,8 +6,6 @@ TARGET := hvmloader/hvmloader INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR) DEBG_DIR := $(DESTDIR)$(DEBUG_DIR)$(XENFIRMWAREDIR) -EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none - SUBDIRS-y := SUBDIRS-$(CONFIG_OVMF) += ovmf-dir SUBDIRS-$(CONFIG_SEABIOS) += seabios-dir
tools/firmware/Rules.mk +2 -0
@@ -13,6 +13,8 @@ endif CFLAGS += -Werror +EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none + $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) # Extra CFLAGS suitable for an embedded type of environment.
Signature · 1 line
2.35.1
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
Quoted 7 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
In reply to Roger Pau MonneQuoted 30 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>--- tools/firmware/Makefile | 2 -- tools/firmware/Rules.mk | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)tools/firmware/Makefile +0
-2@@ -6,8 +6,6 @@ TARGET := hvmloader/hvmloader INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR) DEBG_DIR := $(DESTDIR)$(DEBUG_DIR)$(XENFIRMWAREDIR) -EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none - SUBDIRS-y := SUBDIRS-$(CONFIG_OVMF) += ovmf-dir SUBDIRS-$(CONFIG_SEABIOS) += seabios-dirtools/firmware/Rules.mk +0
-0
tools/firmware/Rules.mk endif · line 17
Quoted 5 lines
tools/firmware/Rules.mk +2
-0@@ -13,6 +13,8 @@ endif CFLAGS += -Werror +EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none +
I think making modification to $(EMBEDDED_EXTRA_CFLAGS) outside of "Config.mk" is confusing and would be better be avoided.
Could you instead call $(cc-option-add ) just for that extra CFLAGS?
tools/firmware/Rules.mk endif · line 20
Quoted 3 lines
tools/firmware/Rules.mk +0
-0$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) # Extra CFLAGS suitable for an embedded type of environment.
Thanks,
Signature · 1 line
Anthony PERARD
Re: [PATCH 2/2] tools/firmware: do not add a .note.gnu.property section
In reply to Roger Pau MonneQuoted 10 lines · Roger Pau Monne
Prevent the assembler from creating a .note.gnu.property section on the output objects, as it's not useful for firmware related binaries, and breaks the resulting rombios image.
This requires modifying the cc-option
Makefilemacro so it can test assembler options (by replacing the usage of the -S flag with -c) and also stripping the -Wa, prefix if present when checking for the test output.Signed-off-by Roger Pau Monné <[email protected]>
It's worth saying that this was found from XenServer's testing, but there's no obvious Fixes: tag to use.
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
In reply to Anthony PERARDQuoted 32 lines · Anthony PERARD
Quoted 31 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>--- tools/firmware/Makefile | 2 -- tools/firmware/Rules.mk | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-)tools/firmware/Makefile +0
-2@@ -6,8 +6,6 @@ TARGET := hvmloader/hvmloader INST_DIR := $(DESTDIR)$(XENFIRMWAREDIR) DEBG_DIR := $(DESTDIR)$(DEBUG_DIR)$(XENFIRMWAREDIR) -EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none - SUBDIRS-y := SUBDIRS-$(CONFIG_OVMF) += ovmf-dir SUBDIRS-$(CONFIG_SEABIOS) += seabios-dirtools/firmware/Rules.mk +0
-0@@ -13,6 +13,8 @@ endif
Quoted 6 lines
tools/firmware/Rules.mk endif · line 17
Quoted 4 lines
tools/firmware/Rules.mk +2
-0CFLAGS += -Werror +EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none +I think making modification to $(EMBEDDED_EXTRA_CFLAGS) outside of "Config.mk" is confusing and would be better be avoided.
EMBEDDED_EXTRA_CFLAGS in the root Config.mk is conceptually broken and needs deleting.
Yes, xen/ and tools/firmware/ are freestanding from C's point of view, and embedded from many peoples points of view, but this doesn't mean they have shared build requirements.
-nopie isn't even a CFLAG. It's spelt -no-pie and is an LDFLAG. This bug is hidden by everything being cc-option'd behind the scenes.
Stack protector we'd absolutely have in Xen if it weren't for a quirk of supporting PV guests.
-fno-exceptions is C++ only so not relevant for anything in xen.git
~Andrew
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
In reply to Andrew CooperQuoted 9 lines · Andrew Cooper
Quoted 7 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>
This also needs backporting with the XSA-398 CET-IBT fixes.
~Andrew
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
In reply to Andrew CooperQuoted 9 lines · Andrew Cooper
Quoted 5 lines · Anthony PERARD
tools/firmware/Rules.mk endif · line 17
Quoted 2 lines · Roger Pau Monne
tools/firmware/Rules.mk +2
-0+EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none +I think making modification to $(EMBEDDED_EXTRA_CFLAGS) outside of "Config.mk" is confusing and would be better be avoided.
EMBEDDED_EXTRA_CFLAGSin the root Config.mk is conceptually broken and needs deleting.
I'm asking to remove "-fcf-protection=none" from the broken variable EMBEDDED_EXTRA_CFLAGS, and instead only modify the CFLAGS variable of "tools/firmware/".
As this patch show, making modification to EMBEDDED_EXTRA_CFLAGS outside of Config.mk doesn't work because changes doesn't propagate.
So the modification I've ask for the patch goes toward deleting EMBEDDED_EXTRA_CFLAGS, like you want.
Cheers,
Signature · 1 line
Anthony PERARD
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>This also needs backporting with the XSA-398 CET-IBT fixes.
I don't think so - the backports of the original commit didn't include what this patch fixes. I have queued patch 2 of this series though.
Jan
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>This also needs backporting with the XSA-398 CET-IBT fixes.
I don't think so - the backports of the original commit didn't include what this patch fixes. I have queued patch 2 of this series though.
In which case I screwed up the backport. (I remember spotting this bug and thought I'd corrected it, but clearly not.) tools/firmware really does need to be -fcf-protection=none to counteract the defaults in Ubuntu/etc.
~Andrew
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This also needs backporting with the XSA-398 CET-IBT fixes.
I don't think so - the backports of the original commit didn't include what this patch fixes. I have queued patch 2 of this series though.
In which case I screwed up the backport. (I remember spotting this bug and thought I'd corrected it, but clearly not.)
tools/firmwarereally does need to be -fcf-protection=none to counteract the defaults in Ubuntu/etc.
Okay, I'll adjust title and description some then while doing the backport.
Jan
Re: [PATCH 1/2] tools/firmware: fix setting of fcf-protection=none
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Roger Pau Monne
Setting the fcf-protection=none option in
EMBEDDED_EXTRA_CFLAGSin theMakefiledoesn't get it propagated to the subdirectories, so instead set the flag infirmware/Rules.mk, like it's done for other compiler flags.Fixes 3667f7f8f7 ('x86: Introduce support for CET-IBT')Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
This also needs backporting with the XSA-398 CET-IBT fixes.
I don't think so - the backports of the original commit didn't include what this patch fixes. I have queued patch 2 of this series though.
In which case I screwed up the backport. (I remember spotting this bug and thought I'd corrected it, but clearly not.)
tools/firmwarereally does need to be -fcf-protection=none to counteract the defaults in Ubuntu/etc.Okay, I'll adjust title and description some then while doing the backport.
Thanks, and sorry for this mess.
~Andrew