Skip to contentSkip to conversation

build: Fix build with Ubuntu

PATCH New Andrew Cooper 4 participants 8 messages May 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: Fix build with Ubuntu

This supercedes "x86/build: Unilaterally disable -fcf-protection"

Andrew Cooper (2):
x86/build: move -fno-asynchronous-unwind-tables into EMBEDDED_EXTRA_CFLAGS x86/build: Unilaterally disable -fcf-protection

 Config.mk                            | 3 ++-
 tools/tests/x86_emulator/testcase.mk | 2 +-
 xen/arch/x86/arch.mk                 | 2 +-
 xen/arch/x86/boot/build32.mk         | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 x86/build: Unilaterally disable -fcf-protection

Xen doesn't support CET-IBT yet. At a minimum, logic is required to enable it for supervisor use, but the livepatch functionality needs to learn not to overwrite ENDBR64 instructions.

Furthermore, Ubuntu enables -fcf-protection by default, along with a buggy version of GCC-9 which objects to it in combination with -mindirect-branch=thunk-extern (Fixed in GCC 10, 9.4).

Various objects (Xen boot path, Rombios 32 stubs) require .text to be at the beginning of the object. These paths explode when .note.gnu.properties gets put ahead of .text and we end up executing the notes data.

Disable -fcf-protection for all embedded objects.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Jason Andryuk <[email protected]>
CC: Stefan Bader <[email protected]>

v2:
* Fix Rombios 32 stubs as well.

---
 Config.mk | 1 +
 1 file changed, 1 insertion(+)
Config.mk +1 -0
index b0f16680f3..7d556aed30 100644
@@ -205,6 +205,7 @@ APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i))
 
 EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
 EMBEDDED_EXTRA_CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables
+EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none
 
 XEN_EXTFILES_URL ?= http://xenbits.xen.org/xen-extfiles
 # All the files at that location were downloaded from elsewhere on
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] x86/build: Unilaterally disable -fcf-protection

Quoted 8 lines · Andrew Cooper

Xen doesn't support CET-IBT yet. At a minimum, logic is required to enable it for supervisor use, but the livepatch functionality needs to learn not to overwrite ENDBR64 instructions.

Furthermore, Ubuntu enables -fcf-protection by default, along with a buggy version of GCC-9 which objects to it in combination with -mindirect-branch=thunk-extern (Fixed in GCC 10, 9.4).

Quoted 8 lines

Various objects (Xen boot path, Rombios 32 stubs) require .text to be at the beginning of the object. These paths explode when .note.gnu.properties gets put ahead of .text and we end up executing the notes data.

Disable -fcf-protection for all embedded objects.

For the immediate purpose

I wonder however ...

Config.mk APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i)) · line 208

Quoted 7 lines
Config.mk +1 -0
@@ -205,6 +205,7 @@ APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i))
 
 EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
 EMBEDDED_EXTRA_CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables
+EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none

... whether this isn't going to bite us once some of the consumers of this variable want to enable some different mode.

Jan

#3 lore raw

Re: [PATCH] x86/build: Unilaterally disable -fcf-protection

Quoted 15 lines · Jan Beulich

[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.

Quoted 12 lines · Andrew Cooper

Xen doesn't support CET-IBT yet. At a minimum, logic is required to enable it for supervisor use, but the livepatch functionality needs to learn not to overwrite ENDBR64 instructions.

Furthermore, Ubuntu enables -fcf-protection by default, along with a buggy version of GCC-9 which objects to it in combination with -mindirect-branch=thunk-extern (Fixed in GCC 10, 9.4).

Various objects (Xen boot path, Rombios 32 stubs) require .text to be at the beginning of the object. These paths explode when .note.gnu.properties gets put ahead of .text and we end up executing the notes data.

Quoted 6 lines
Quoted 4 lines

Disable -fcf-protection for all embedded objects.

For the immediate purpose

Thanks.

Quoted 7 lines

I wonder however ...

Quoted 4 lines
Config.mk +0 -0
@@ -205,6 +205,7 @@ APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i))
 
Quoted 5 lines

Config.mk APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i)) · line 208

Quoted 3 lines
Config.mk +1 -0
 EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
 EMBEDDED_EXTRA_CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables
+EMBEDDED_EXTRA_CFLAGS += -fcf-protection=none

... whether this isn't going to bite us once some of the consumers of this variable want to enable some different mode.

I'm not overly happy with EMBEDDED_EXTRA_CFLAGS as a concept, but these build fixes do need backporting.

All embedded targets may in principle use some/all of these options at some point in the future.

~Andrew

Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] x86/build: Unilaterally disable -fcf-protection

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

Xen doesn't support CET-IBT yet. At a minimum, logic is required to enable it for supervisor use, but the livepatch functionality needs to learn not to overwrite ENDBR64 instructions.

Furthermore, Ubuntu enables -fcf-protection by default, along with a buggy version of GCC-9 which objects to it in combination with -mindirect-branch=thunk-extern (Fixed in GCC 10, 9.4).

Quoted 8 lines

Various objects (Xen boot path, Rombios 32 stubs) require .text to be at the beginning of the object. These paths explode when .note.gnu.properties gets put ahead of .text and we end up executing the notes data.

Disable -fcf-protection for all embedded objects.

I have not re-tested this posting, but I tested an equivalent change ~2 weeks ago (in case that counts for Tested-by).

-Jason

#5 lore raw

PATCH 1/1 x86/build: move -fno-asynchronous-unwind-tables into EMBEDDED_EXTRA_CFLAGS

In reply to Andrew Cooper

Users of EMBEDDED_EXTRA_CFLAGS already use -fno-asynchronous-unwind-tables, or ought to. This shrinks the size of the rombios 32bit stubs in guest memory.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 Config.mk                            | 2 +-
 tools/tests/x86_emulator/testcase.mk | 2 +-
 xen/arch/x86/arch.mk                 | 2 +-
 xen/arch/x86/boot/build32.mk         | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
Config.mk +1 -1
index 3621162ae4..b0f16680f3 100644
@@ -204,7 +204,7 @@ APPEND_LDFLAGS += $(foreach i, $(APPEND_LIB), -L$(i))
 APPEND_CFLAGS += $(foreach i, $(APPEND_INCLUDES), -I$(i))
 
 EMBEDDED_EXTRA_CFLAGS := -nopie -fno-stack-protector -fno-stack-protector-all
-EMBEDDED_EXTRA_CFLAGS += -fno-exceptions
+EMBEDDED_EXTRA_CFLAGS += -fno-exceptions -fno-asynchronous-unwind-tables
 
 XEN_EXTFILES_URL ?= http://xenbits.xen.org/xen-extfiles
 # All the files at that location were downloaded from elsewhere on
tools/tests/x86_emulator/testcase.mk +1 -1
index a565d15524..dafeb6caf7 100644
@@ -4,7 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
 
-CFLAGS += -fno-builtin -fno-asynchronous-unwind-tables -g0 $($(TESTCASE)-cflags)
+CFLAGS += -fno-builtin -g0 $($(TESTCASE)-cflags)
 
 .PHONY: all
 all: $(TESTCASE).bin
xen/arch/x86/arch.mk +1 -1
index 2a51553edb..62b7c97007 100644
@@ -56,7 +56,7 @@ $(call as-option-add,CFLAGS,CC,\
 $(call as-option-add,CFLAGS,CC,\
     ".L1: .L2: .nops (.L2 - .L1)$$(comma)9",-DHAVE_AS_NOPS_DIRECTIVE)
 
-CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tables
+CFLAGS += -mno-red-zone -fpic
 
 # Xen doesn't use SSE interally.  If the compiler supports it, also skip the
 # SSE setup for variadic function calls.
xen/arch/x86/boot/build32.mk +1 -1
index 48c7407c00..5851ebff5f 100644
@@ -4,7 +4,7 @@ include $(XEN_ROOT)/Config.mk
 
 $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
 
-CFLAGS += -Werror -fno-asynchronous-unwind-tables -fno-builtin -g0 -msoft-float
+CFLAGS += -Werror -fno-builtin -g0 -msoft-float
 CFLAGS += -I$(XEN_ROOT)/xen/include
 CFLAGS := $(filter-out -flto,$(CFLAGS)) 
 
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] x86/build: move -fno-asynchronous-unwind-tables into EMBEDDED_EXTRA_CFLAGS

Quoted 2 lines · Andrew Cooper

Users of EMBEDDED_EXTRA_CFLAGS already use -fno-asynchronous-unwind-tables, or ought to.

It's not really well defined what they're supposed to be used for (and where it's not supposed to be used). I notice in particular a use in stubdom/Makefile which I'm unsure whether it indeed wants this adjustment. Therefore ...

Quoted 3 lines

This shrinks the size of the rombios 32bit stubs in guest memory.

with the request that Samuel also ack (or otherwise) the change from a stubdom perspective.

Jan

#7 lore raw

Re: [PATCH] x86/build: move -fno-asynchronous-unwind-tables into EMBEDDED_EXTRA_CFLAGS

Hello,

Jan Beulich, le mer. 13 mai 2020 16:11:00 +0200, a ecrit:

Quoted 8 lines · Andrew Cooper
Quoted 2 lines

Users of EMBEDDED_EXTRA_CFLAGS already use -fno-asynchronous-unwind-tables, or ought to.

It's not really well defined what they're supposed to be used for (and where it's not supposed to be used). I notice in particular a use in stubdom/Makefile which I'm unsure whether it indeed wants this adjustment. Therefore ...

I don't know why this is there in mini-os. It dates back 2005 8afe079be ('Mini-OS cleanups. Bug fixes in x86_64 assembly code.')

It indeed looks to me like a general option to minimize binary size, so I'd say it is fine to make its activation general.

Quoted 7 lines
Quoted 3 lines

This shrinks the size of the rombios 32bit stubs in guest memory.

with the request that Samuel also ack (or otherwise) the change from a stubdom perspective.

Samuel