[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] x86: reduce general stack alignment to 8



commit 6bb013e5e50a5a94dc97c6391f20c7f4040eb654
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri May 17 14:35:14 2019 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri May 17 14:35:14 2019 +0200

    x86: reduce general stack alignment to 8
    
    We don't need bigger alignment except when calling EFI boot or runtime
    services functions (and we don't guarantee that either, as explained
    close to the top of xen/common/efi/runtime.c in the struct efi_rs_state
    declaration). Hence if the compiler supports reducing stack alignment
    from the ABI compatible 16 bytes (gcc 7 and newer), do so wherever
    possible.
    
    The EFI case itself is largely dealt with already (actually forcing
    32-byte alignment) as a result of commit f6b7fedc89 ("x86/EFI: meet
    further spec requirements for runtime calls"). However, as explained in
    the description of that earlier change, without using
    -mincoming-stack-boundary=3 (which we don't want) we still have to make
    the compiler assume 16-byte stack boundaries for CUs making EFI calls in
    order to keep the compiler from aligning the stack, but then placing an
    odd number of 8-byte objects on it, resulting in a mis-aligned outgoing
    stack.
    
    This as a side effect yields some code size reduction, since for a
    number of sufficiently simple non-leaf functions the stack adjustment
    (by 8, when there are no local stack variables at all) gets dropped
    altogether. I notice exceptions though, for example in guest_cpuid(),
    where in a release build gcc 8.2 now decides to set up a frame pointer
    (without ever using %rbp); I consider this a compiler quirk which we
    should leave to the compiler folks to address eventually.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/Rules.mk     | 5 +++++
 xen/arch/x86/efi/Makefile | 6 +++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/Rules.mk b/xen/arch/x86/Rules.mk
index 3f2687bbe4..babc0edbcd 100644
--- a/xen/arch/x86/Rules.mk
+++ b/xen/arch/x86/Rules.mk
@@ -52,6 +52,11 @@ CFLAGS += -fno-jump-tables
 export CONFIG_INDIRECT_THUNK=y
 endif
 
+# If supported by the compiler, reduce stack alignment to 8 bytes. But allow
+# this to be overridden elsewhere.
+$(call cc-option-add,CFLAGS-stack-boundary,CC,-mpreferred-stack-boundary=3)
+CFLAGS += $(CFLAGS-stack-boundary)
+
 # Set up the assembler include path properly for older toolchains.
 CFLAGS += -Wa,-I$(BASEDIR)/include
 
diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile
index 3816de2738..f223ef058e 100644
--- a/xen/arch/x86/efi/Makefile
+++ b/xen/arch/x86/efi/Makefile
@@ -5,7 +5,11 @@ CFLAGS += -fshort-wchar
 
 boot.init.o: buildid.o
 
+EFIOBJ := boot.init.o compat.o runtime.o
+
+$(EFIOBJ): CFLAGS-stack-boundary := -mpreferred-stack-boundary=4
+
 obj-y := stub.o
-obj-$(XEN_BUILD_EFI) := boot.init.o compat.o relocs-dummy.o runtime.o
+obj-$(XEN_BUILD_EFI) := $(EFIOBJ) relocs-dummy.o
 extra-$(XEN_BUILD_EFI) += buildid.o
 nocov-$(XEN_BUILD_EFI) += stub.o
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.