efi: arm: Simplify the crt0 file and update link script
We don't need to manually add the PE header, since binutils has support for this now. Remove it to simplify the file. Set the link-target to efi-app-aarch64 so that binutils knows what to do. Add rules to pick up the arm64 files. Make some updates to the link-script for arm64, so this all works: - Pass .hash .eh_frame and .reloc sections through to objcopy - Put RELA pieces into a single section - Put linker lists into .data - Embed the dtb Add a config.mk fragment into the baord directory. Note that it does not seem to be possible to use this approach with 32-bit ARM, so this is left alone. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -10,140 +10,11 @@
|
||||
|
||||
#include <asm-generic/pe.h>
|
||||
|
||||
.section .text.head
|
||||
|
||||
/*
|
||||
* Magic "MZ" signature for PE/COFF
|
||||
*/
|
||||
.globl image_base
|
||||
image_base:
|
||||
.short IMAGE_DOS_SIGNATURE /* 'MZ' */
|
||||
.skip 54 /* 'MZ' + pad + offset == 64 */
|
||||
.long LINUX_ARM64_MAGIC /* For GRUB's linux command */
|
||||
.long pe_header - image_base /* Offset to the PE header */
|
||||
pe_header:
|
||||
.long IMAGE_NT_SIGNATURE /* 'PE' */
|
||||
coff_header:
|
||||
.short IMAGE_FILE_MACHINE_ARM64 /* AArch64 */
|
||||
.short 3 /* nr_sections */
|
||||
.long 0 /* TimeDateStamp */
|
||||
.long 0 /* PointerToSymbolTable */
|
||||
.long 0 /* NumberOfSymbols */
|
||||
.short section_table - optional_header /* SizeOfOptionalHeader */
|
||||
/* Characteristics */
|
||||
.short (IMAGE_FILE_EXECUTABLE_IMAGE | \
|
||||
IMAGE_FILE_LINE_NUMS_STRIPPED | \
|
||||
IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
|
||||
IMAGE_FILE_LARGE_ADDRESS_AWARE | \
|
||||
IMAGE_FILE_DEBUG_STRIPPED)
|
||||
optional_header:
|
||||
.short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
|
||||
.byte 0x02 /* MajorLinkerVersion */
|
||||
.byte 0x14 /* MinorLinkerVersion */
|
||||
.long _etext - _start /* SizeOfCode */
|
||||
.long 0 /* SizeOfInitializedData */
|
||||
.long 0 /* SizeOfUninitializedData */
|
||||
.long _start - image_base /* AddressOfEntryPoint */
|
||||
.long _start - image_base /* BaseOfCode */
|
||||
|
||||
extra_header_fields:
|
||||
.quad 0 /* image_base */
|
||||
.long 0x1000 /* SectionAlignment */
|
||||
.long 0x200 /* FileAlignment */
|
||||
.short 0 /* MajorOperatingSystemVersion */
|
||||
.short 0 /* MinorOperatingSystemVersion */
|
||||
.short 0 /* MajorImageVersion */
|
||||
.short 0 /* MinorImageVersion */
|
||||
.short 0 /* MajorSubsystemVersion */
|
||||
.short 0 /* MinorSubsystemVersion */
|
||||
.long 0 /* Win32VersionValue */
|
||||
|
||||
.long _edata - image_base /* SizeOfImage */
|
||||
|
||||
/*
|
||||
* Everything before the kernel image is considered part of the header
|
||||
*/
|
||||
.long _start - image_base /* SizeOfHeaders */
|
||||
.long 0 /* CheckSum */
|
||||
.short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
|
||||
#if CONFIG_ARCH_EFI
|
||||
.short 0 /* DllCharacteristics */
|
||||
#else
|
||||
.short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
|
||||
#endif
|
||||
.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 */
|
||||
/* Characteristics (section flags) */
|
||||
.long (IMAGE_SCN_MEM_READ | \
|
||||
IMAGE_SCN_MEM_DISCARDABLE | \
|
||||
IMAGE_SCN_CNT_INITIALIZED_DATA)
|
||||
|
||||
.ascii ".text"
|
||||
.byte 0
|
||||
.byte 0
|
||||
.byte 0 /* end of 0 padding of section name */
|
||||
.long _etext - _start /* VirtualSize */
|
||||
.long _start - image_base /* VirtualAddress */
|
||||
.long _etext - _start /* SizeOfRawData */
|
||||
.long _start - image_base /* PointerToRawData */
|
||||
.long 0 /* PointerToRelocations */
|
||||
.long 0 /* PointerToLineNumbers */
|
||||
.short 0 /* NumberOfRelocations */
|
||||
.short 0 /* NumberOfLineNumbers */
|
||||
/* Characteristics (section flags) */
|
||||
.long (IMAGE_SCN_MEM_READ | \
|
||||
IMAGE_SCN_MEM_EXECUTE | \
|
||||
IMAGE_SCN_CNT_CODE)
|
||||
|
||||
.ascii ".data"
|
||||
.byte 0
|
||||
.byte 0
|
||||
.byte 0 /* end of 0 padding of section name */
|
||||
.long _data_size /* VirtualSize */
|
||||
.long _data - image_base /* VirtualAddress */
|
||||
.long _data_size /* SizeOfRawData */
|
||||
.long _data - image_base /* PointerToRawData */
|
||||
.long 0 /* PointerToRelocations */
|
||||
.long 0 /* PointerToLineNumbers */
|
||||
.short 0 /* NumberOfRelocations */
|
||||
.short 0 /* NumberOfLineNumbers */
|
||||
/* Characteristics (section flags) */
|
||||
.long (IMAGE_SCN_MEM_WRITE | \
|
||||
IMAGE_SCN_MEM_READ | \
|
||||
IMAGE_SCN_CNT_INITIALIZED_DATA)
|
||||
|
||||
.text
|
||||
.align 12
|
||||
|
||||
.globl _start
|
||||
.type _start,%function
|
||||
_start:
|
||||
stp x29, x30, [sp, #-32]!
|
||||
mov x29, sp
|
||||
@@ -160,3 +31,22 @@ _start:
|
||||
|
||||
0: ldp x29, x30, [sp], #32
|
||||
ret
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -7,18 +7,19 @@
|
||||
|
||||
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
|
||||
OUTPUT_ARCH(aarch64)
|
||||
|
||||
PHDRS
|
||||
{
|
||||
data PT_LOAD FLAGS(3); /* SHF_WRITE | SHF_ALLOC */
|
||||
}
|
||||
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
.text 0x0 : {
|
||||
. = 0;
|
||||
image_base = .;
|
||||
/* .hash and/or .gnu.hash MUST come first! */
|
||||
.hash : { *(.hash) }
|
||||
.gnu.hash : { *(.gnu.hash) }
|
||||
. = ALIGN(4096);
|
||||
.eh_frame : { *(.eh_frame) }
|
||||
. = ALIGN(4096);
|
||||
.text : {
|
||||
_text = .;
|
||||
*(.text.head)
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.gnu.linkonce.t.*)
|
||||
@@ -28,12 +29,12 @@ SECTIONS
|
||||
*(.dynamic);
|
||||
. = ALIGN(512);
|
||||
}
|
||||
.rela.dyn : { *(.rela.dyn) }
|
||||
.rela.plt : { *(.rela.plt) }
|
||||
.rela.got : { *(.rela.got) }
|
||||
.rela.data : { *(.rela.data) *(.rela.data*) }
|
||||
_etext = .;
|
||||
_text_size = . - _text;
|
||||
. = ALIGN(65536);
|
||||
.reloc : {
|
||||
KEEP (*(.reloc))
|
||||
}
|
||||
. = ALIGN(4096);
|
||||
.data : {
|
||||
_data = .;
|
||||
@@ -43,6 +44,10 @@ SECTIONS
|
||||
*(.data.*)
|
||||
*(.got.plt)
|
||||
*(.got)
|
||||
/* U-Boot lists and device tree */
|
||||
. = ALIGN(8);
|
||||
*(SORT(__u_boot_list*));
|
||||
. = ALIGN(8);
|
||||
|
||||
/*
|
||||
* The EFI loader doesn't seem to like a .bss section, so we
|
||||
@@ -59,9 +64,24 @@ SECTIONS
|
||||
. = ALIGN(512);
|
||||
_bss_end = .;
|
||||
_edata = .;
|
||||
} :data
|
||||
_end = .;
|
||||
}
|
||||
_data_size = _edata - _data;
|
||||
|
||||
. = ALIGN(4096);
|
||||
.rela : {
|
||||
*(.rela.text*)
|
||||
*(.rela.data*)
|
||||
*(.rela.got)
|
||||
*(.rela.dyn)
|
||||
*(.rela.stab)
|
||||
*(.rela.init_array*)
|
||||
*(.rela.fini_array*)
|
||||
*(.rela.ctors*)
|
||||
*(.rela.dtors*)
|
||||
*(.rela__u_boot_list*)
|
||||
}
|
||||
|
||||
. = ALIGN(4096);
|
||||
.dynsym : { *(.dynsym) }
|
||||
. = ALIGN(4096);
|
||||
@@ -73,5 +93,8 @@ SECTIONS
|
||||
*(.eh_frame)
|
||||
*(.note.GNU-stack)
|
||||
}
|
||||
.embedded_dtb : {
|
||||
*(.embedded_dtb)
|
||||
}
|
||||
.comment 0 : { *(.comment) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user