Fix RISCV64 not setting the subsystem according to EFI_SUBSYSTEM

The RISCV64 toolchain does not support 16-bit variable relocation from assembly,
and even if it did support relocations, it would not properly set the subsystem
from --defsym. So we add an extra step on RISCV64, post objcopy, to set the field
manually (using dd and /bin/echo to output the relevant byte, as GNU Make's echo
does not support -ne).
Closes ncroxon/gnu-efi#27.

Signed-off-by: Pete Batard <pete@akeo.ie>
This commit is contained in:
Pete Batard 2024-05-23 20:08:57 +01:00
parent 5d0de491f1
commit eeb0e6a830
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
2 changed files with 6 additions and 5 deletions

View File

@ -36,12 +36,17 @@
.SECONDARY: .SECONDARY:
CHAR_SUBSYSTEM=$(subst 0x,\x,$(SUBSYSTEM))
ifeq ($(IS_MINGW32),) ifeq ($(IS_MINGW32),)
%.efi: %.so %.efi: %.so
@$(ECHO) " OBJCOPY $(notdir $@)" @$(ECHO) " OBJCOPY $(notdir $@)"
$(HIDE)$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \ $(HIDE)$(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* \
-j .areloc -j .reloc $(FORMAT) $*.so $@ -j .areloc -j .reloc $(FORMAT) $*.so $@
ifeq ($(ARCH),riscv64)
$(HIDE)/bin/echo -ne "$(CHAR_SUBSYSTEM)" | dd of=$@ bs=1 seek=156 count=1 conv=notrunc status=none
endif
%.efi.debug: %.so %.efi.debug: %.so
@$(ECHO) " OBJCOPY $(notdir $@)" @$(ECHO) " OBJCOPY $(notdir $@)"

View File

@ -16,10 +16,6 @@
* either version 2 of the License, or (at your option) any later version. * either version 2 of the License, or (at your option) any later version.
*/ */
#ifndef EFI_SUBSYSTEM
#define EFI_SUBSYSTEM 10
#endif
.section .text.head .section .text.head
/* /*
@ -71,7 +67,7 @@ extra_header_fields:
// Everything before the kernel image is considered part of the header // Everything before the kernel image is considered part of the header
.4byte _text - ImageBase // SizeOfHeaders .4byte _text - ImageBase // SizeOfHeaders
.4byte 0 // CheckSum .4byte 0 // CheckSum
.2byte EFI_SUBSYSTEM // Subsystem .2byte 0 // Subsystem
.2byte 0 // DllCharacteristics .2byte 0 // DllCharacteristics
.8byte 0 // SizeOfStackReserve .8byte 0 // SizeOfStackReserve
.8byte 0 // SizeOfStackCommit .8byte 0 // SizeOfStackCommit