318 lines
8.1 KiB
Diff
318 lines
8.1 KiB
Diff
From 9298f84d8d18db669b1e3593a65080cc01b68ac6 Mon Sep 17 00:00:00 2001
|
|
From: Xiaotian Wu <wuxiaotian@loongson.cn>
|
|
Date: Thu, 18 May 2023 19:49:32 +0800
|
|
Subject: [PATCH 2/3] Make loongarch64 use efi-app-loongarch64
|
|
|
|
Binutils 2.41 now supports efi-app-loongarch64, so to use this we must add a
|
|
dummy reloc section and remove the PE header definition from crt0 as this will
|
|
conflict with the version added by objcopy
|
|
|
|
Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
|
|
Signed-off-by: yueyuankun <yueyuankun@kylinos.cn>
|
|
---
|
|
Make.defaults | 4 +-
|
|
gnuefi/crt0-efi-loongarch64.S | 131 +++++----------------------------
|
|
gnuefi/elf_loongarch64_efi.lds | 75 ++++++++++++++++---
|
|
3 files changed, 86 insertions(+), 124 deletions(-)
|
|
|
|
diff --git a/Make.defaults b/Make.defaults
|
|
index 434a44e..0ef5a73 100755
|
|
--- a/Make.defaults
|
|
+++ b/Make.defaults
|
|
@@ -161,18 +161,16 @@ endif
|
|
ifneq ($(ARCH),arm)
|
|
ifneq ($(ARCH),mips64el)
|
|
ifneq ($(ARCH),riscv64)
|
|
-ifneq ($(ARCH),loongarch64)
|
|
export HAVE_EFI_OBJCOPY=y
|
|
endif
|
|
endif
|
|
endif
|
|
-endif
|
|
|
|
ifeq ($(ARCH),arm)
|
|
CFLAGS += -marm
|
|
endif
|
|
|
|
-ifeq ($(ARCH),aarch64)
|
|
+ifeq ($(ARCH),aarch64 loongarch64)
|
|
LDFLAGS += -z common-page-size=4096
|
|
LDFLAGS += -z max-page-size=4096
|
|
endif
|
|
diff --git a/gnuefi/crt0-efi-loongarch64.S b/gnuefi/crt0-efi-loongarch64.S
|
|
index af45d46..af939ff 100644
|
|
--- a/gnuefi/crt0-efi-loongarch64.S
|
|
+++ b/gnuefi/crt0-efi-loongarch64.S
|
|
@@ -17,115 +17,8 @@
|
|
* either version 2 of the License, or (at your option) any later version.
|
|
*/
|
|
|
|
-#ifndef EFI_SUBSYSTEM
|
|
-#define EFI_SUBSYSTEM 0xa
|
|
-#endif
|
|
- .section .text.head
|
|
-
|
|
- /*
|
|
- * Magic "MZ" signature for PE/COFF
|
|
- */
|
|
- .globl ImageBase
|
|
-ImageBase:
|
|
- .ascii "MZ"
|
|
- .skip 58 // 'MZ' + pad + offset == 64
|
|
- .long pe_header - ImageBase // Offset to the PE header.
|
|
-pe_header:
|
|
- .ascii "PE"
|
|
- .short 0
|
|
-coff_header:
|
|
- .short 0x6264 // loongarch64 little endian
|
|
- .short 2 // nr_sections
|
|
- .long 0 // TimeDateStamp
|
|
- .long 0 // PointerToSymbolTable
|
|
- .long 1 // NumberOfSymbols
|
|
- .short section_table - optional_header // SizeOfOptionalHeader
|
|
- .short 0x206 // Characteristics.
|
|
- // IMAGE_FILE_DEBUG_STRIPPED |
|
|
- // IMAGE_FILE_EXECUTABLE_IMAGE |
|
|
- // IMAGE_FILE_LINE_NUMS_STRIPPED
|
|
-optional_header:
|
|
- .short 0x20b // PE32+ format
|
|
- .byte 0x02 // MajorLinkerVersion
|
|
- .byte 0x14 // MinorLinkerVersion
|
|
- .long _edata - _start // SizeOfCode
|
|
- .long 0 // SizeOfInitializedData
|
|
- .long 0 // SizeOfUninitializedData
|
|
- .long _start - ImageBase // AddressOfEntryPoint
|
|
- .long _start - ImageBase // BaseOfCode
|
|
-
|
|
-extra_header_fields:
|
|
- .quad 0 // ImageBase
|
|
- .long 0x20 // SectionAlignment
|
|
- .long 0x8 // FileAlignment
|
|
- .short 0 // MajorOperatingSystemVersion
|
|
- .short 0 // MinorOperatingSystemVersion
|
|
- .short 0 // MajorImageVersion
|
|
- .short 0 // MinorImageVersion
|
|
- .short 0 // MajorSubsystemVersion
|
|
- .short 0 // MinorSubsystemVersion
|
|
- .long 0 // Win32VersionValue
|
|
-
|
|
- .long _edata - ImageBase // SizeOfImage
|
|
-
|
|
- // Everything before the kernel image is considered part of the header
|
|
- .long _start - ImageBase // SizeOfHeaders
|
|
- .long 0 // CheckSum
|
|
- .short EFI_SUBSYSTEM // Subsystem
|
|
- .short 0 // DllCharacteristics
|
|
- .quad 0 // SizeOfStackReserve
|
|
- .quad 0 // SizeOfStackCommit
|
|
- .quad 0 // SizeOfHeapReserve
|
|
- .quad 0 // SizeOfHeapCommit
|
|
- .long 0 // LoaderFlags
|
|
- .long 0x6 // NumberOfRvaAndSizes
|
|
-
|
|
- .quad 0 // ExportTable
|
|
- .quad 0 // ImportTable
|
|
- .quad 0 // ResourceTable
|
|
- .quad 0 // ExceptionTable
|
|
- .quad 0 // CertificationTable
|
|
- .quad 0 // BaseRelocationTable
|
|
-
|
|
- // Section table
|
|
-section_table:
|
|
-
|
|
- /*
|
|
- * The EFI application loader requires a relocation section
|
|
- * because EFI applications must be relocatable. This is a
|
|
- * dummy section as far as we are concerned.
|
|
- */
|
|
- .ascii ".reloc"
|
|
- .byte 0
|
|
- .byte 0 // end of 0 padding of section name
|
|
- .long 0
|
|
- .long 0
|
|
- .long 0 // SizeOfRawData
|
|
- .long 0 // PointerToRawData
|
|
- .long 0 // PointerToRelocations
|
|
- .long 0 // PointerToLineNumbers
|
|
- .short 0 // NumberOfRelocations
|
|
- .short 0 // NumberOfLineNumbers
|
|
- .long 0x42100040 // Characteristics (section flags)
|
|
-
|
|
-
|
|
- .ascii ".text"
|
|
- .byte 0
|
|
- .byte 0
|
|
- .byte 0 // end of 0 padding of section name
|
|
- .long _edata - _start // VirtualSize
|
|
- .long _start - ImageBase // VirtualAddress
|
|
- .long _edata - _start // SizeOfRawData
|
|
- .long _start - ImageBase // PointerToRawData
|
|
-
|
|
- .long 0 // PointerToRelocations (0 for executables)
|
|
- .long 0 // PointerToLineNumbers (0 for executables)
|
|
- .short 0 // NumberOfRelocations (0 for executables)
|
|
- .short 0 // NumberOfLineNumbers (0 for executables)
|
|
- .long 0xe0500020 // Characteristics (section flags)
|
|
-
|
|
- .align 4
|
|
-
|
|
+ .text
|
|
+ .align 12
|
|
.globl _start
|
|
.type _start, @function
|
|
_start:
|
|
@@ -143,9 +36,25 @@ _start:
|
|
|
|
ld.d $a0, $sp, 8
|
|
ld.d $a1, $sp, 16
|
|
- bl efi_main
|
|
+ bl _entry
|
|
|
|
0: ld.d $ra, $sp, 0
|
|
addi.d $sp, $sp, 24
|
|
jr $ra
|
|
- .end _start
|
|
+
|
|
+// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable:
|
|
+
|
|
+ .data
|
|
+dummy: .4byte 0
|
|
+
|
|
+#define IMAGE_REL_ABSOLUTE 0
|
|
+ .section .reloc, "a"
|
|
+label1:
|
|
+ .4byte dummy-label1 // Page RVA
|
|
+ .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits
|
|
+ .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
|
|
+ .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy
|
|
+
|
|
+#if defined(__ELF__) && defined(__linux__)
|
|
+ .section .note.GNU-stack,"",%progbits
|
|
+#endif
|
|
diff --git a/gnuefi/elf_loongarch64_efi.lds b/gnuefi/elf_loongarch64_efi.lds
|
|
index e7b4d6b..0132dbb 100644
|
|
--- a/gnuefi/elf_loongarch64_efi.lds
|
|
+++ b/gnuefi/elf_loongarch64_efi.lds
|
|
@@ -3,9 +3,17 @@ OUTPUT_ARCH(loongarch)
|
|
ENTRY(_start)
|
|
SECTIONS
|
|
{
|
|
- .text 0x0 : {
|
|
+ . = 0;
|
|
+ ImageBase = .;
|
|
+ /* .hash and/or .gnu.hash MUST come first! */
|
|
+ .hash : { *(.hash) }
|
|
+ .gnu.hash : { *(.gnu.hash) }
|
|
+ . = ALIGN(4096);
|
|
+ .eh_frame : { *(.eh_frame) }
|
|
+ .gcc_except_table : { *(.gcc_except_table*) }
|
|
+ . = ALIGN(4096);
|
|
+ .text : {
|
|
_text = .;
|
|
- *(.text.head)
|
|
*(.text)
|
|
*(.text.*)
|
|
*(.gnu.linkonce.t.*)
|
|
@@ -15,8 +23,15 @@ SECTIONS
|
|
}
|
|
_etext = .;
|
|
_text_size = . - _text;
|
|
+ . = ALIGN(4096);
|
|
+ .reloc :
|
|
+ {
|
|
+ KEEP (*(.reloc))
|
|
+ }
|
|
+ . = ALIGN(65536);
|
|
.dynamic : { *(.dynamic) }
|
|
- .data : ALIGN(4096)
|
|
+ . = ALIGN(4096);
|
|
+ .data :
|
|
{
|
|
_data = .;
|
|
*(.sdata)
|
|
@@ -26,6 +41,33 @@ SECTIONS
|
|
*(.got.plt)
|
|
*(.got)
|
|
|
|
+ /*
|
|
+ * Note that these aren't the using the GNU "CONSTRUCTOR" output section
|
|
+ * command, so they don't start with a size. Because of p2align and the
|
|
+ * end/END definitions, and the fact that they're mergeable, they can also
|
|
+ * have NULLs which aren't guaranteed to be at the end.
|
|
+ */
|
|
+ . = ALIGN(16);
|
|
+ __init_array_start = .;
|
|
+ *(SORT(.init_array.*))
|
|
+ *(.init_array)
|
|
+ __init_array_end = .;
|
|
+ . = ALIGN(16);
|
|
+ __CTOR_LIST__ = .;
|
|
+ *(SORT(.ctors.*))
|
|
+ *(.ctors)
|
|
+ __CTOR_END__ = .;
|
|
+ . = ALIGN(16);
|
|
+ __DTOR_LIST__ = .;
|
|
+ *(SORT(.dtors.*))
|
|
+ *(.dtors)
|
|
+ __DTOR_END__ = .;
|
|
+ . = ALIGN(16);
|
|
+ __fini_array_start = .;
|
|
+ *(SORT(.fini_array.*))
|
|
+ *(.fini_array)
|
|
+ __fini_array_end = .;
|
|
+
|
|
/* the EFI loader doesn't seem to like a .bss section, so we stick
|
|
it all into .data: */
|
|
. = ALIGN(16);
|
|
@@ -33,16 +75,30 @@ SECTIONS
|
|
*(.sbss)
|
|
*(.scommon)
|
|
*(.dynbss)
|
|
- *(.bss)
|
|
+ *(.bss*)
|
|
*(COMMON)
|
|
+ *(.rel.local)
|
|
. = ALIGN(16);
|
|
+
|
|
_bss_end = .;
|
|
}
|
|
|
|
- .rela.dyn : { *(.rela.dyn) }
|
|
+ . = ALIGN(4096);
|
|
+ .rela :
|
|
+ {
|
|
+ *(.rela.text*)
|
|
+ *(.rela.data*)
|
|
+ *(.rela.got)
|
|
+ *(.rela.dyn)
|
|
+ *(.rela.stab)
|
|
+ *(.rela.init_array*)
|
|
+ *(.rela.fini_array*)
|
|
+ *(.rela.ctors*)
|
|
+ *(.rela.dtors*)
|
|
+
|
|
+ }
|
|
+ . = ALIGN(4096);
|
|
.rela.plt : { *(.rela.plt) }
|
|
- .rela.got : { *(.rela.got) }
|
|
- .rela.data : { *(.rela.data) *(.rela.data*) }
|
|
. = ALIGN(512);
|
|
_edata = .;
|
|
_data_size = . - _data;
|
|
@@ -53,10 +109,9 @@ SECTIONS
|
|
.dynstr : { *(.dynstr) }
|
|
. = ALIGN(4096);
|
|
.note.gnu.build-id : { *(.note.gnu.build-id) }
|
|
- /DISCARD/ :
|
|
+ .ignored.reloc :
|
|
{
|
|
- *(.rel.reloc)
|
|
- *(.eh_frame)
|
|
+ *(.rela.reloc)
|
|
*(.note.GNU-stack)
|
|
}
|
|
.comment 0 : { *(.comment) }
|
|
--
|
|
2.43.0
|
|
|