[PATCH v7 2/2] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS


Gerd Hoffmann
 

Fixes problems due to code assuming it runs with frame pointers and thus
updates rbp / ebp registers when switching stacks.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
BaseTools/Conf/tools_def.template | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 73f95b2a3a9f..f1fd6a003062 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -1888,8 +1888,8 @@ DEFINE GCC_DEPS_FLAGS = -MMD -MF $@.deps

DEFINE GCC48_ALL_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20
-DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address
-DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address
+DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
+DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
DEFINE GCC48_IA32_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE GCC48_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON)
--
2.38.1


Brian J. Johnson
 

Gerd,

Sorry, gotta ask: does this make much difference in the size of the compiled code? That's a constraint on many real-hardware X64 platforms, especially for 32-bit code.

Brian J. Johnson

-------- Original Message --------
From: Gerd Hoffmann [mailto:kraxel@...]
Sent: Wednesday, November 30, 2022 at 3:44 AM
To: devel@edk2.groups.io
Cc: Alexey Kardashevskiy <aik@...>, Liming Gao <gaoliming@...>, Erdem Aktas <erdemaktas@...>, Pawel Polawski <ppolawsk@...>, Jordan Justen <jordan.l.justen@...>, Ard Biesheuvel <ardb+tianocore@...>, Yuwei Chen <yuwei.chen@...>, Tom Lendacky <thomas.lendacky@...>, James Bottomley <jejb@...>, Gerd Hoffmann <kraxel@...>, Oliver Steffen <osteffen@...>, Jiewen Yao <jiewen.yao@...>, Min Xu <min.m.xu@...>, Brijesh Singh <brijesh.singh@...>, Bob Feng <bob.c.feng@...>
Subject: [edk2-devel] [PATCH v7 2/2] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS

Fixes problems due to code assuming it runs with frame pointers and thus
updates rbp / ebp registers when switching stacks.

Signed-off-by: Gerd Hoffmann <kraxel@...>
---
BaseTools/Conf/tools_def.template | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 73f95b2a3a9f..f1fd6a003062 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -1888,8 +1888,8 @@ DEFINE GCC_DEPS_FLAGS = -MMD -MF $@.deps

DEFINE GCC48_ALL_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
DEFINE GCC48_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20
-DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address
-DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address
+DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
+DEFINE GCC48_X64_CC_FLAGS = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
DEFINE GCC48_IA32_X64_DLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
DEFINE GCC48_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON)

--

Brian

--------------------------------------------------------------------

"I love deadlines. I like the whooshing sound they make as they fly by."
-- Douglas Adams


Gerd Hoffmann
 

On Wed, Nov 30, 2022 at 01:28:42PM -0600, Brian J. Johnson wrote:
Gerd,

Sorry, gotta ask: does this make much difference in the size of the
compiled code? That's a constraint on many real-hardware X64 platforms,
especially for 32-bit code.
Quick test with OvmfPkg/OvmfPkgIa32X64.dsc (sec/pei ia32, dxe x64):

master branch:

FV Space Information
SECFV [11%Full] 212992 (0x34000) total, 23728 (0x5cb0) used, 189264 (0x2e350) free
PEIFV [34%Full] 917504 (0xe0000) total, 319416 (0x4dfb8) used, 598088 (0x92048) free
DXEFV [49%Full] 12582912 (0xc00000) total, 6268032 (0x5fa480) used, 6314880 (0x605b80) free
FVMAIN_COMPACT [98%Full] 1753088 (0x1ac000) total, 1725328 (0x1a5390) used, 27760 (0x6c70) free

with patch applied:

FV Space Information
SECFV [11%Full] 212992 (0x34000) total, 23728 (0x5cb0) used, 189264 (0x2e350) free
PEIFV [34%Full] 917504 (0xe0000) total, 319416 (0x4dfb8) used, 598088 (0x92048) free
DXEFV [50%Full] 12582912 (0xc00000) total, 6335936 (0x60adc0) used, 6246976 (0x5f5240) free
FVMAIN_COMPACT [99%Full] 1753088 (0x1ac000) total, 1738176 (0x1a85c0) used, 14912 (0x3a40) free

So slightly more for 64-bit code.

take care,
Gerd


Brian J. Johnson
 

OK. Doesn't look like a big impact.

Thanks,
Brian J. Johnson

-------- Original Message --------
From: Gerd Hoffmann [mailto:kraxel@...]
Sent: Thursday, December 1, 2022 at 2:38 AM
To: Brian J. Johnson <brian.johnson@...>
Cc: devel@edk2.groups.io, Alexey Kardashevskiy <aik@...>, Liming Gao <gaoliming@...>, Erdem Aktas <erdemaktas@...>, Pawel Polawski <ppolawsk@...>, Jordan Justen <jordan.l.justen@...>, Ard Biesheuvel <ardb+tianocore@...>, Yuwei Chen <yuwei.chen@...>, Tom Lendacky <thomas.lendacky@...>, James Bottomley <jejb@...>, Oliver Steffen <osteffen@...>, Jiewen Yao <jiewen.yao@...>, Min Xu <min.m.xu@...>, Brijesh Singh <brijesh.singh@...>, Bob Feng <bob.c.feng@...>
Subject: [edk2-devel] [PATCH v7 2/2] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS

On Wed, Nov 30, 2022 at 01:28:42PM -0600, Brian J. Johnson wrote:
Gerd,

Sorry, gotta ask: does this make much difference in the size of the
compiled code? That's a constraint on many real-hardware X64 platforms,
especially for 32-bit code.
Quick test with OvmfPkg/OvmfPkgIa32X64.dsc (sec/pei ia32, dxe x64):

master branch:

FV Space Information
SECFV [11%Full] 212992 (0x34000) total, 23728 (0x5cb0) used, 189264 (0x2e350) free
PEIFV [34%Full] 917504 (0xe0000) total, 319416 (0x4dfb8) used, 598088 (0x92048) free
DXEFV [49%Full] 12582912 (0xc00000) total, 6268032 (0x5fa480) used, 6314880 (0x605b80) free
FVMAIN_COMPACT [98%Full] 1753088 (0x1ac000) total, 1725328 (0x1a5390) used, 27760 (0x6c70) free

with patch applied:

FV Space Information
SECFV [11%Full] 212992 (0x34000) total, 23728 (0x5cb0) used, 189264 (0x2e350) free
PEIFV [34%Full] 917504 (0xe0000) total, 319416 (0x4dfb8) used, 598088 (0x92048) free
DXEFV [50%Full] 12582912 (0xc00000) total, 6335936 (0x60adc0) used, 6246976 (0x5f5240) free
FVMAIN_COMPACT [99%Full] 1753088 (0x1ac000) total, 1738176 (0x1a85c0) used, 14912 (0x3a40) free

So slightly more for 64-bit code.

take care,
Gerd