Fix MinGW EFI applications

The EFI subsystem and application entrypoint were not being set for MinGW builds
and we don't need to go through objcopy either, so fix that.
Also make sure that the link options can be understood by the compiler, which
is what we use for linking, and remove the extra GNU_EFI_USE_MS_ABI, that was
already automatically added.

Signed-off-by: Pete Batard <pete@akeo.ie>
This commit is contained in:
Pete Batard 2024-05-18 15:21:33 +01:00
parent 52c3c36e34
commit 5dee8b0339
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
3 changed files with 27 additions and 12 deletions

View File

@ -192,8 +192,6 @@ GCCMACHINE := $(shell $(CC) -dumpmachine)
IS_MINGW32 := $(findstring mingw32, $(GCCMACHINE))
ifeq ($(IS_MINGW32),)
CFLAGS += -fPIE
else
CFLAGS += -DGNU_EFI_USE_MS_ABI
endif
ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
@ -203,16 +201,19 @@ CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
else
CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \
-funsigned-char -fshort-wchar -fno-strict-aliasing \
-ffreestanding -fno-stack-protector -fno-stack-check \
-ffreestanding -fno-stack-protector -fno-stack-check \
$(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
endif
ARFLAGS := rDv
ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \
--build-id=sha1
LDFLAGS += -nostdlib
ifeq ($(IS_MINGW32),)
LDFLAGS += -z nocombreloc -z norelro
LDFLAGS += --warn-common --no-undefined --fatal-warnings \
--build-id=sha1 -z nocombreloc -z norelro
else
LDFLAGS += -Wl,--warn-common -Wl,--no-undefined -Wl,--fatal-warnings \
-Wl,--build-id=sha1
endif
ifneq ($(ARCH),arm)

View File

@ -36,6 +36,7 @@
.SECONDARY:
ifeq ($(IS_MINGW32),)
%.efi: %.so
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \
-j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
@ -49,6 +50,10 @@
%.so: %.o
$(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES)
else
%.efi: %.o
$(CC) $(LDFLAGS) $< -o $@ $(LOADLIBES)
endif
%.o: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

View File

@ -68,26 +68,35 @@ LOADLIBES += $(LIBGCC)
TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi t7.efi t8.efi \
tcc.efi printenv.efi modelist.efi route80h.efi route80h.efi \
drv0_use.efi AllocPages.efi exit.efi FreePages.efi bltgrid.efi \
lfbgrid.efi setdbg.efi unsetdbg.efi ctors_test.efi \
ctors_dtors_priority_test.efi
lfbgrid.efi setdbg.efi unsetdbg.efi
ifeq ($(IS_MINGW32),)
TARGET_APPS += setjmp.efi debughook.efi debughook.efi.debug
TARGET_APPS += setjmp.efi debughook.efi debughook.efi.debug \
ctors_test.efi ctors_dtors_priority_test.efi
endif
TARGET_BSDRIVERS = drv0.efi
TARGET_RTDRIVERS =
SUBSYSTEM := 0xa
$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
ifneq ($(HAVE_EFI_OBJCOPY),)
FORMAT := --target efi-app-$(ARCH)
$(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH)
$(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(ARCH)
ifneq ($(IS_MINGW32),)
LDFLAGS += -s -Wl,-dll -Wl,--subsystem,$(SUBSYSTEM)
ifeq ($(ARCH),ia32)
LDFLAGS += -e _efi_main
else
LDFLAGS += -e efi_main
endif
endif
SUBSYSTEM := 0xa
$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
else
FORMAT := -O binary
LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)