Browse Source
This adds support for efi-*-aarch64 by virtue of adding a new PEI target pei-aarch64-little. This is not a full target and only exists to support EFI at this time. This means that this target does not support relocation processing and is mostly a container format. This format has been added to elf based aarch64 targets such that efi images can be made natively on Linux. However this target is not valid for use with gas but only with objcopy. With these changes the resulting file is recognized as an efi image by third party tools: > pecli info hello.efi Metadata ================================================================================ MD5: 598c32a778b0f0deebe977fef8578c4e SHA1: 4580121edd5cb4dc40f51b28f171fd15250df84c SHA256: 3154bd7cf42433d1c957f6bf55a17ad8c57ed41b29df2d485703349fd6ff1d5c Imphash: Size: 47561 bytes Type: PE32+ executable (EFI application) (stripped to external PDB), for MS Windows Compile Time: 1970-01-01 00:00:00 (UTC - 0x0 ) Entry point: 0x2000 (section .text) Sections ================================================================================ Name RWX VirtSize VirtAddr RawAddr RawSize Entropy md5 .text R-X 0x5bb0 0x2000 0x400 0x5c00 6.39 551fbc264256a3f387de8a891500ae0d .reloc R-- 0xc 0x8000 0x6000 0x200 0.02 0c45f6d812d079821c1d54c09ab89e1d .data RW- 0x1d88 0x9000 0x6200 0x1e00 4.18 5d1137c09f01289dc62bf754f7290db3 .dynamic RW- 0xf0 0xb000 0x8000 0x200 0.34 5c94ed3206f05a277e6f04fbf131f131 .rela R-- 0xe58 0xc000 0x8200 0x1000 1.87 8b5c6bc30f3acb7ca7bf2e6789d68519 .dynsym R-- 0x138 0xd000 0x9200 0x200 0.96 bdcf5101da51aadc663ca8859f88138c Imports ================================================================================ Any magic number is based on the Microsoft PE specification [1]. [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * .gitignore (pe-aarch64igen.c): New. * Makefile.am (pei-aarch64.lo, pe-aarch64igen.lo, pei-aarch64.c, pe-aarch64igen.c): Add support. * Makefile.in: Likewise. * bfd.c (bfd_get_sign_extend_vma): Add pei-aarch64-little. * coff-aarch64.c: New file. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags, coff_write_object_contents) Add aarch64 (aarch64_pei_vec) support. * config.bfd: Likewise. * configure: Likewise. * configure.ac: Likewise. * libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE, GET_OPTHDR_SIZE_OF_STACK_RESERVE, PUT_OPTHDR_SIZE_OF_STACK_RESERVE, GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT, GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE, GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT, GET_PDATA_ENTRY, _bfd_peAArch64_bfd_copy_private_bfd_data_common, _bfd_peAArch64_bfd_copy_private_section_data, _bfd_peAArch64_get_symbol_info, _bfd_peAArch64_only_swap_filehdr_out, _bfd_peAArch64_print_private_bfd_data_common, _bfd_peAArch64i_final_link_postscript, _bfd_peAArch64i_only_swap_filehdr_out, _bfd_peAArch64i_swap_aouthdr_in, _bfd_peAArch64i_swap_aouthdr_out, _bfd_peAArch64i_swap_aux_in, _bfd_peAArch64i_swap_aux_out, _bfd_peAArch64i_swap_lineno_in, _bfd_peAArch64i_swap_lineno_out, _bfd_peAArch64i_swap_scnhdr_out, _bfd_peAArch64i_swap_sym_in, _bfd_peAArch64i_swap_sym_out, _bfd_peAArch64i_swap_debugdir_in, _bfd_peAArch64i_swap_debugdir_out, _bfd_peAArch64i_write_codeview_record, _bfd_peAArch64i_slurp_codeview_record, _bfd_peAArch64_print_ce_compressed_pdata): New. * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out, pe_print_pdata, _bfd_XX_print_private_bfd_data_common, _bfd_XX_bfd_copy_private_section_data, _bfd_XXi_final_link_postscript): Support COFF_WITH_peAArch64, * pei-aarch64.c: New file. * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p): Support COFF_WITH_peAArch64. (jtab): Add dummy entry that traps. * targets.c (aarch64_pei_vec): New. binutils/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * NEWS: Add new support. * objcopy.c (convert_efi_target): Add efi-*-aarch64 support. * testsuite/binutils-all/aarch64/pei-aarch64-little.d: New test. * testsuite/binutils-all/aarch64/pei-aarch64-little.s: New test. include/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * coff/aarch64.h: New file. * coff/pe.h (IMAGE_FILE_MACHINE_ARM64): New.binutils-2_38-branch
20 changed files with 495 additions and 27 deletions
@ -0,0 +1,166 @@ |
|||
/* BFD back-end for AArch64 COFF files.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
|
|||
This file is part of BFD, the Binary File Descriptor library. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
|||
MA 02110-1301, USA. */ |
|||
|
|||
|
|||
#ifndef COFF_WITH_peAArch64 |
|||
#define COFF_WITH_peAArch64 |
|||
#endif |
|||
|
|||
/* Note we have to make sure not to include headers twice.
|
|||
Not all headers are wrapped in #ifdef guards, so we define |
|||
PEI_HEADERS to prevent double including here. */ |
|||
#ifndef PEI_HEADERS |
|||
#include "sysdep.h" |
|||
#include "bfd.h" |
|||
#include "libbfd.h" |
|||
#include "coff/aarch64.h" |
|||
#include "coff/internal.h" |
|||
#include "coff/pe.h" |
|||
#include "libcoff.h" |
|||
#include "libiberty.h" |
|||
#endif |
|||
|
|||
#include "libcoff.h" |
|||
|
|||
/* The page size is a guess based on ELF. */ |
|||
|
|||
#define COFF_PAGE_SIZE 0x1000 |
|||
|
|||
/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */ |
|||
#define OCTETS_PER_BYTE(ABFD, SEC) 1 |
|||
|
|||
#ifndef PCRELOFFSET |
|||
#define PCRELOFFSET true |
|||
#endif |
|||
|
|||
/* Currently we don't handle any relocations. */ |
|||
static reloc_howto_type pe_aarch64_std_reloc_howto[] = |
|||
{ |
|||
|
|||
}; |
|||
|
|||
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
|||
#define COFF_PAGE_SIZE 0x1000 |
|||
|
|||
#ifndef NUM_ELEM |
|||
#define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0])) |
|||
#endif |
|||
|
|||
#define NUM_RELOCS NUM_ELEM (pe_aarch64_std_reloc_howto) |
|||
|
|||
#define RTYPE2HOWTO(cache_ptr, dst) \ |
|||
(cache_ptr)->howto = NULL |
|||
|
|||
#ifndef bfd_pe_print_pdata |
|||
#define bfd_pe_print_pdata NULL |
|||
#endif |
|||
|
|||
/* Return TRUE if this relocation should
|
|||
appear in the output .reloc section. */ |
|||
|
|||
static bool |
|||
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, |
|||
reloc_howto_type * howto) |
|||
{ |
|||
return !howto->pc_relative; |
|||
} |
|||
|
|||
#include "coffcode.h" |
|||
|
|||
/* Target vectors. */ |
|||
const bfd_target |
|||
#ifdef TARGET_SYM |
|||
TARGET_SYM = |
|||
#else |
|||
aarch64_pei_vec = |
|||
#endif |
|||
{ |
|||
#ifdef TARGET_NAME |
|||
TARGET_NAME, |
|||
#else |
|||
"pei-aarch64-little", /* Name. */ |
|||
#endif |
|||
bfd_target_coff_flavour, |
|||
BFD_ENDIAN_LITTLE, /* Data byte order is little. */ |
|||
BFD_ENDIAN_LITTLE, /* Header byte order is little. */ |
|||
|
|||
(HAS_RELOC | EXEC_P /* Object flags. */ |
|||
| HAS_LINENO | HAS_DEBUG |
|||
| HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), |
|||
|
|||
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ |
|||
#if defined(COFF_WITH_PE) |
|||
| SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING |
|||
#endif |
|||
| SEC_CODE | SEC_DATA | SEC_EXCLUDE ), |
|||
|
|||
#ifdef TARGET_UNDERSCORE |
|||
TARGET_UNDERSCORE, /* Leading underscore. */ |
|||
#else |
|||
0, /* Leading underscore. */ |
|||
#endif |
|||
'/', /* Ar_pad_char. */ |
|||
15, /* Ar_max_namelen. */ |
|||
0, /* match priority. */ |
|||
TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
|||
|
|||
/* Data conversion functions. */ |
|||
bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
|||
bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
|||
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ |
|||
/* Header conversion functions. */ |
|||
bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
|||
bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
|||
bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs. */ |
|||
|
|||
/* Note that we allow an object file to be treated as a core file as well. */ |
|||
{ /* bfd_check_format. */ |
|||
_bfd_dummy_target, |
|||
coff_object_p, |
|||
bfd_generic_archive_p, |
|||
coff_object_p |
|||
}, |
|||
{ /* bfd_set_format. */ |
|||
_bfd_bool_bfd_false_error, |
|||
coff_mkobject, |
|||
_bfd_generic_mkarchive, |
|||
_bfd_bool_bfd_false_error |
|||
}, |
|||
{ /* bfd_write_contents. */ |
|||
_bfd_bool_bfd_false_error, |
|||
coff_write_object_contents, |
|||
_bfd_write_archive_contents, |
|||
_bfd_bool_bfd_false_error |
|||
}, |
|||
|
|||
BFD_JUMP_TABLE_GENERIC (coff), |
|||
BFD_JUMP_TABLE_COPY (coff), |
|||
BFD_JUMP_TABLE_CORE (_bfd_nocore), |
|||
BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), |
|||
BFD_JUMP_TABLE_SYMBOLS (coff), |
|||
BFD_JUMP_TABLE_RELOCS (coff), |
|||
BFD_JUMP_TABLE_WRITE (coff), |
|||
BFD_JUMP_TABLE_LINK (coff), |
|||
BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
|||
|
|||
NULL, |
|||
|
|||
COFF_SWAP_TABLE |
|||
}; |
|||
@ -0,0 +1,75 @@ |
|||
/* BFD back-end for AArch64 PE IMAGE COFF files.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
|
|||
This file is part of BFD, the Binary File Descriptor library. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
|||
MA 02110-1301, USA. */ |
|||
|
|||
#include "sysdep.h" |
|||
#include "bfd.h" |
|||
|
|||
#define TARGET_SYM aarch64_pei_vec |
|||
#define TARGET_NAME "pei-aarch64-little" |
|||
#define TARGET_ARCHITECTURE bfd_arch_aarch64 |
|||
#define TARGET_PAGESIZE 4096 |
|||
#define TARGET_BIG_ENDIAN 0 |
|||
#define TARGET_ARCHIVE 0 |
|||
#define TARGET_PRIORITY 0 |
|||
|
|||
#define COFF_IMAGE_WITH_PE |
|||
/* Rename the above into.. */ |
|||
#define COFF_WITH_peAArch64 |
|||
#define COFF_WITH_PE |
|||
#define PCRELOFFSET true |
|||
|
|||
/* Long section names not allowed in executable images, only object files. */ |
|||
#define COFF_LONG_SECTION_NAMES 0 |
|||
|
|||
#define COFF_SECTION_ALIGNMENT_ENTRIES \ |
|||
{ COFF_SECTION_NAME_EXACT_MATCH (".bss"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_EXACT_MATCH (".data"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_EXACT_MATCH (".rdata"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_EXACT_MATCH (".text"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \ |
|||
{ COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \ |
|||
{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \ |
|||
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 } |
|||
|
|||
#define PEI_HEADERS |
|||
#include "sysdep.h" |
|||
#include "bfd.h" |
|||
#include "libbfd.h" |
|||
#include "coff/aarch64.h" |
|||
#include "coff/internal.h" |
|||
#include "coff/pe.h" |
|||
#include "libcoff.h" |
|||
#include "libpei.h" |
|||
#include "libiberty.h" |
|||
|
|||
/* Make sure we're setting a 64-bit format. */ |
|||
#undef AOUTSZ |
|||
#define AOUTSZ PEPAOUTSZ |
|||
#define PEAOUTHDR PEPAOUTHDR |
|||
|
|||
#include "coff-aarch64.c" |
|||
@ -0,0 +1,16 @@ |
|||
#skip: aarch64_be-*-* |
|||
#ld: -e0 |
|||
#PROG: objcopy |
|||
#objcopy: -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* -j .reloc --target=efi-app-aarch64 |
|||
#objdump: -h -f |
|||
#name: Check if efi app format is recognized |
|||
|
|||
.*: file format pei-aarch64-little |
|||
architecture: aarch64, flags 0x00000132: |
|||
EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED |
|||
start address 0x0000000000000000 |
|||
|
|||
Sections: |
|||
Idx Name Size VMA LMA File off Algn |
|||
0 \.text 00000030 0[^ ]+ 0[^ ]+ 0[^ ]+ 2\*\*2 |
|||
CONTENTS, ALLOC, LOAD, READONLY, CODE |
|||
@ -0,0 +1,42 @@ |
|||
.arch armv8-a |
|||
.text |
|||
.align 2 |
|||
.global foo |
|||
.type foo, %function |
|||
foo: |
|||
.LFB0: |
|||
.cfi_startproc |
|||
sub sp, sp, #16 |
|||
.cfi_def_cfa_offset 16 |
|||
str w0, [sp, 12] |
|||
ldr w0, [sp, 12] |
|||
mul w0, w0, w0 |
|||
add sp, sp, 16 |
|||
.cfi_def_cfa_offset 0 |
|||
ret |
|||
.cfi_endproc |
|||
.LFE0: |
|||
.size foo, .-foo |
|||
.align 2 |
|||
.global main |
|||
.type main, %function |
|||
main: |
|||
.LFB1: |
|||
.cfi_startproc |
|||
stp x29, x30, [sp, -16]! |
|||
.cfi_def_cfa_offset 16 |
|||
.cfi_offset 29, -16 |
|||
.cfi_offset 30, -8 |
|||
mov x29, sp |
|||
mov w0, 5 |
|||
bl foo |
|||
ldp x29, x30, [sp], 16 |
|||
.cfi_restore 30 |
|||
.cfi_restore 29 |
|||
.cfi_def_cfa_offset 0 |
|||
ret |
|||
.cfi_endproc |
|||
.LFE1: |
|||
.size main, .-main |
|||
.ident "GCC: (fsf-trunk.2870) 12.0.0 20210930 (experimental)" |
|||
.section .note.GNU-stack,"",@progbits |
|||
@ -0,0 +1,63 @@ |
|||
/* AArch64 COFF support for BFD.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
|
|||
This file is part of BFD, the Binary File Descriptor library. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software Foundation, |
|||
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
|||
|
|||
#define COFFAARCH64 1 |
|||
|
|||
#define L_LNNO_SIZE 2 |
|||
#define INCLUDE_COMDAT_FIELDS_IN_AUXENT |
|||
#include "coff/external.h" |
|||
|
|||
#define F_AARCH64_ARCHITECTURE_MASK (0x4000) |
|||
|
|||
#define AARCH64MAGIC 0xaa64 /* From Microsoft specification. */ |
|||
|
|||
#undef BADMAG |
|||
#define BADMAG(x) ((x).f_magic != AARCH64MAGIC) |
|||
#define AARCH64 1 /* Customize coffcode.h. */ |
|||
|
|||
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b |
|||
|
|||
#define OMAGIC 0404 /* Object files, eg as output. */ |
|||
#define ZMAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC /* Demand load format, eg normal ld output 0x10b. */ |
|||
#define STMAGIC 0401 /* Target shlib. */ |
|||
#define SHMAGIC 0443 /* Host shlib. */ |
|||
|
|||
/* define some NT default values */ |
|||
/* #define NT_IMAGE_BASE 0x400000 moved to internal.h */ |
|||
#define NT_SECTION_ALIGNMENT 0x1000 |
|||
#define NT_FILE_ALIGNMENT 0x200 |
|||
#define NT_DEF_RESERVE 0x100000 |
|||
#define NT_DEF_COMMIT 0x1000 |
|||
|
|||
/* We use the .rdata section to hold read only data. */ |
|||
#define _LIT ".rdata" |
|||
|
|||
/********************** RELOCATION DIRECTIVES **********************/ |
|||
struct external_reloc |
|||
{ |
|||
char r_vaddr[4]; |
|||
char r_symndx[4]; |
|||
char r_type[2]; |
|||
char r_offset[4]; |
|||
}; |
|||
|
|||
#define RELOC struct external_reloc |
|||
#define RELSZ 14 |
|||
|
|||
#define ARM_NOTE_SECTION ".note" |
|||
Loading…
Reference in new issue