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)) IS_MINGW32 := $(findstring mingw32, $(GCCMACHINE))
ifeq ($(IS_MINGW32),) ifeq ($(IS_MINGW32),)
CFLAGS += -fPIE CFLAGS += -fPIE
else
CFLAGS += -DGNU_EFI_USE_MS_ABI
endif endif
ifeq (FreeBSD, $(findstring FreeBSD, $(OS))) ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
@ -203,16 +201,19 @@ CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
else else
CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \ CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \
-funsigned-char -fshort-wchar -fno-strict-aliasing \ -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,) $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
endif endif
ARFLAGS := rDv ARFLAGS := rDv
ASFLAGS += $(ARCH3264) ASFLAGS += $(ARCH3264)
LDFLAGS += -nostdlib --warn-common --no-undefined --fatal-warnings \ LDFLAGS += -nostdlib
--build-id=sha1
ifeq ($(IS_MINGW32),) 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 endif
ifneq ($(ARCH),arm) ifneq ($(ARCH),arm)

View File

@ -36,6 +36,7 @@
.SECONDARY: .SECONDARY:
ifeq ($(IS_MINGW32),)
%.efi: %.so %.efi: %.so
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \ $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \
-j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \ -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
@ -49,6 +50,10 @@
%.so: %.o %.so: %.o
$(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES) $(LD) $(LDFLAGS) $^ -o $@ $(LOADLIBES)
else
%.efi: %.o
$(CC) $(LDFLAGS) $< -o $@ $(LOADLIBES)
endif
%.o: %.c %.o: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ $(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 \ 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 \ tcc.efi printenv.efi modelist.efi route80h.efi route80h.efi \
drv0_use.efi AllocPages.efi exit.efi FreePages.efi bltgrid.efi \ drv0_use.efi AllocPages.efi exit.efi FreePages.efi bltgrid.efi \
lfbgrid.efi setdbg.efi unsetdbg.efi ctors_test.efi \ lfbgrid.efi setdbg.efi unsetdbg.efi
ctors_dtors_priority_test.efi
ifeq ($(IS_MINGW32),) 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 endif
TARGET_BSDRIVERS = drv0.efi TARGET_BSDRIVERS = drv0.efi
TARGET_RTDRIVERS = TARGET_RTDRIVERS =
SUBSYSTEM := 0xa
$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
ifneq ($(HAVE_EFI_OBJCOPY),) ifneq ($(HAVE_EFI_OBJCOPY),)
FORMAT := --target efi-app-$(ARCH) FORMAT := --target efi-app-$(ARCH)
$(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH) $(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH)
$(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(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 else
LDFLAGS += -e efi_main
endif
endif
SUBSYSTEM := 0xa else
$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
FORMAT := -O binary FORMAT := -O binary
LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM) LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)