!38 回合社区补丁,解决loongarch64架构的编译错误
From: @yue-yuankun Reviewed-by: @caodongxia Signed-off-by: @caodongxia
This commit is contained in:
commit
c7837a166f
49
backport-0001-Add-some-definitions-for-LoongArch.patch
Normal file
49
backport-0001-Add-some-definitions-for-LoongArch.patch
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
From b9c62d6b03e3bd343334a47618eee164fee93b86 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Xiaotian Wu <wuxiaotian@loongson.cn>
|
||||||
|
Date: Wed, 17 May 2023 17:22:49 +0800
|
||||||
|
Subject: [PATCH 1/3] Add some definitions for LoongArch
|
||||||
|
|
||||||
|
Added CHAR8, CHAR16, WCHAR and VOID type definitions for LoongArch
|
||||||
|
Signed-off-by: yueyuankun <yueyuankun@kylinos.cn>
|
||||||
|
---
|
||||||
|
inc/loongarch64/efibind.h | 11 ++++++-----
|
||||||
|
1 file changed, 6 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/inc/loongarch64/efibind.h b/inc/loongarch64/efibind.h
|
||||||
|
index 23178a0..2287be1 100644
|
||||||
|
--- a/inc/loongarch64/efibind.h
|
||||||
|
+++ b/inc/loongarch64/efibind.h
|
||||||
|
@@ -42,9 +42,10 @@ typedef int64_t intptr_t;
|
||||||
|
// Basic EFI types of various widths
|
||||||
|
//
|
||||||
|
|
||||||
|
-#ifndef __WCHAR_TYPE__
|
||||||
|
-# define __WCHAR_TYPE__ short
|
||||||
|
-#endif
|
||||||
|
+#include <stddef.h>
|
||||||
|
+
|
||||||
|
+typedef wchar_t CHAR16;
|
||||||
|
+#define WCHAR CHAR16
|
||||||
|
|
||||||
|
#ifndef __CHAR16_TYPE__
|
||||||
|
# define __CHAR16_TYPE__ unsigned short
|
||||||
|
@@ -58,14 +59,14 @@ typedef int32_t INT32;
|
||||||
|
|
||||||
|
typedef uint16_t UINT16;
|
||||||
|
typedef int16_t INT16;
|
||||||
|
+
|
||||||
|
typedef __CHAR16_TYPE__ CHAR16;
|
||||||
|
typedef uint8_t UINT8;
|
||||||
|
typedef int8_t INT8;
|
||||||
|
typedef char CHAR8;
|
||||||
|
-typedef __WCHAR_TYPE__ WCHAR;
|
||||||
|
|
||||||
|
#undef VOID
|
||||||
|
-#define VOID void
|
||||||
|
+typedef void VOID;
|
||||||
|
|
||||||
|
typedef int64_t INTN;
|
||||||
|
typedef uint64_t UINTN;
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
317
backport-0002-Make-loongarch64-use-efi-app-loongarch64.patch
Normal file
317
backport-0002-Make-loongarch64-use-efi-app-loongarch64.patch
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
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
|
||||||
|
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
From 98f7e9bd21bced75dd10f08766a2fc162ffb0838 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Xiaotian Wu <wuxiaotian@loongson.cn>
|
||||||
|
Date: Sat, 26 Aug 2023 11:05:58 +0800
|
||||||
|
Subject: [PATCH 3/3] add non-executable GNU stack marking on ELF-linux
|
||||||
|
|
||||||
|
Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
|
||||||
|
---
|
||||||
|
lib/loongarch64/efi_stub.S | 3 +++
|
||||||
|
1 file changed, 3 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/lib/loongarch64/efi_stub.S b/lib/loongarch64/efi_stub.S
|
||||||
|
index 464eae5..b3fba1d 100644
|
||||||
|
--- a/lib/loongarch64/efi_stub.S
|
||||||
|
+++ b/lib/loongarch64/efi_stub.S
|
||||||
|
@@ -1 +1,4 @@
|
||||||
|
/* This stub is a stub to make the build happy */
|
||||||
|
+#if defined(__ELF__) && defined(__linux__)
|
||||||
|
+ .section .note.GNU-stack,"",%progbits
|
||||||
|
+#endif
|
||||||
|
--
|
||||||
|
2.43.0
|
||||||
|
|
||||||
11
gnu-efi.spec
11
gnu-efi.spec
@ -1,7 +1,7 @@
|
|||||||
%define debug_package %{nil}
|
%define debug_package %{nil}
|
||||||
Name: gnu-efi
|
Name: gnu-efi
|
||||||
Version: 3.0.17
|
Version: 3.0.17
|
||||||
Release: 7
|
Release: 8
|
||||||
Summary: Development Libraries and headers for EFI
|
Summary: Development Libraries and headers for EFI
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
License: BSD
|
License: BSD
|
||||||
@ -16,6 +16,12 @@ Patch1: 0001-gnu-efi-add-CHAR16-for-loongarch64.patch
|
|||||||
Patch2: riscv64-fix-efibind.h-missing-duplicate-types.patch
|
Patch2: riscv64-fix-efibind.h-missing-duplicate-types.patch
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
# https://sourceforge.net/p/gnu-efi/code/merge-requests/65/
|
||||||
|
# https://github.com/rhboot/gnu-efi/commit/52455a5f10d24bda9df92d77363f2ce4d135b2be
|
||||||
|
Patch3: backport-0001-Add-some-definitions-for-LoongArch.patch
|
||||||
|
Patch4: backport-0002-Make-loongarch64-use-efi-app-loongarch64.patch
|
||||||
|
Patch5: backport-0003-add-non-executable-GNU-stack-marking-on-ELF-linux.patch
|
||||||
|
|
||||||
%global efidir %(eval echo $(grep ^ID= /etc/os-release | sed 's/^ID=//'))
|
%global efidir %(eval echo $(grep ^ID= /etc/os-release | sed 's/^ID=//'))
|
||||||
|
|
||||||
%ifarch x86_64
|
%ifarch x86_64
|
||||||
@ -78,6 +84,9 @@ mv %{efiarch}/apps/{route80h.efi,modelist.efi} %{buildroot}/boot/efi/EFI/%{efidi
|
|||||||
%{_includedir}/efi
|
%{_includedir}/efi
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon May 27 2024 yueyuankun <yueyuankun@kylinos.cn> - 1:3.0.17-8
|
||||||
|
- LoongArch64: backport upstream patches, fix compilation errors
|
||||||
|
|
||||||
* Mon Apr 08 2024 wulei <wu_lei@hoperun.com> - 1:3.0.17-7
|
* Mon Apr 08 2024 wulei <wu_lei@hoperun.com> - 1:3.0.17-7
|
||||||
- Remove ia32 architecture
|
- Remove ia32 architecture
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user