From c5ed3fcc0a1436379f449d739198316c4d4fbd47 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Thu, 9 Jul 2026 13:36:24 -0400 Subject: [PATCH 1/3] Add some stuff to .gitignore This adds a few things to .gitignore: - vim and emacs temporary files - generated source files - our target object directories Signed-off-by: Peter Jones --- .gitignore | 8 ++++++++ lib/.gitignore | 1 + 2 files changed, 9 insertions(+) create mode 100644 lib/.gitignore diff --git a/.gitignore b/.gitignore index 7f79717f..188fde08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.sw? +*~ *.efi *.efi.debug *.o @@ -5,3 +7,9 @@ *.so *.tar.* *.tar +/aarch64/ +/arm/ +/ia32/ +/ia64/ +/mips64el/ +/x86_64/ diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 00000000..eee4ded6 --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1 @@ +ms_va_print.c From 8bef16fbd81727739986b3ff249cda1c8cc00727 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 20 May 2026 13:27:00 -0400 Subject: [PATCH 2/3] make: make it easier to specify optimization and debug flags This adds two new make variables, OPTIMIZATION_CFLAGS and DEBUG_CFLAGS, and moves the relevant compiler flags from EFI_CFLAGS into those variables. This makes it easier to align those options with applications using consuming this library. Signed-off-by: Peter Jones --- Make.defaults | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Make.defaults b/Make.defaults index cf7a88e7..6429bd24 100755 --- a/Make.defaults +++ b/Make.defaults @@ -270,12 +270,17 @@ ifeq ($(IS_MINGW32),) EFI_CFLAGS += -fPIC endif +OPTIMIZATION_CFLAGS ?= -O2 +DEBUG_CFLAGS ?= -g + ifeq ($(USING_FREEBSD),1) -EFI_CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wstrict-prototypes -Werror \ +EFI_CFLAGS += $(ARCH3264) $(OPTIMIZATION_CFLAGS) $(DEBUG_CFLAGS) \ + -Wall -Wextra -Wstrict-prototypes -Werror \ -fno-strict-aliasing \ -ffreestanding -fno-stack-protector else -EFI_CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wstrict-prototypes -Werror \ +EFI_CFLAGS += $(ARCH3264) $(OPTIMIZATION_CFLAGS) $(DEBUG_CFLAGS) \ + -Wall -Wextra -Wstrict-prototypes -Werror \ -fno-strict-aliasing \ -ffreestanding -fno-stack-protector \ $(if $(findstring 0,$(USING_CLANG)),-fno-merge-all-constants,) From 3f7cd908eaf7887992e554a973af3303f56b34c1 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 20 May 2026 13:23:15 -0400 Subject: [PATCH 3/3] x86_64: Enable building the entire library as EFIAPI. This adds a build variable, GNU_EFI_EXPORT_MS_ABI, that allows an application consuming gnu-efi to build the entire tree with -mabi=ms. This has numerous advantages, not least traceback handlers that expect that ABI will seamlessly walk the call stack from a faulting function all the way up into the firmware correctly. As an implementation detail, this changes the ABI of _entry() to effectively be EFIAPI, and as such on x86_64 that means _start has to call _entry() with those conventions. If it weren't for this detail we wouldn't actually need the GNU_EFI_EXPORT_MS_ABI variable, we could just pass -mabi=ms in to EFI_CFLAGS. Signed-off-by: Peter Jones --- Make.defaults | 3 +++ gnuefi/crt0-efi-x86_64.S | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Make.defaults b/Make.defaults index 6429bd24..5b0c690a 100755 --- a/Make.defaults +++ b/Make.defaults @@ -180,6 +180,9 @@ EFI_CFLAGS += -std=c11 ifeq ($(ARCH),x86_64) ifeq ($(GCCNEWENOUGH),1) EFI_CFLAGS += -DGNU_EFI_USE_MS_ABI + ifeq ($(GNU_EFI_EXPORT_MS_ABI),1) + EFI_CFLAGS += -mabi=ms -DGNU_EFI_EXPORT_MS_ABI + endif ifneq ($(USING_CLANG),clang) EFI_CFLAGS += -maccumulate-outgoing-args endif diff --git a/gnuefi/crt0-efi-x86_64.S b/gnuefi/crt0-efi-x86_64.S index b393a18b..7ffd3166 100644 --- a/gnuefi/crt0-efi-x86_64.S +++ b/gnuefi/crt0-efi-x86_64.S @@ -40,6 +40,28 @@ .globl _start .type _start,%function _start: + +#if defined(GNU_EFI_EXPORT_MS_ABI) + pushq %rsi + movq %rdx, %rsi + pushq %rbx + movq %rcx, %rbx + movq %rdx, %r9 + movq %rcx, %r8 + subq $40, %rsp + + lea _DYNAMIC(%rip), %rdx + lea ImageBase(%rip), %rcx + call _relocate + + addq $40, %rsp + movq %rsi, %rdx + movq %rbx, %rcx + popq %rbx + popq %rsi + jmp _entry + nop +#else subq $8, %rsp pushq %rcx pushq %rdx @@ -59,6 +81,7 @@ _start: call _entry addq $8, %rsp +#endif .L_exit: ret