2e9b04
diff -rup binutils.orig/bfd/.gitignore binutils-2.35.2/bfd/.gitignore
2e9b04
--- binutils.orig/bfd/.gitignore	2021-11-30 13:38:24.349744247 +0000
2e9b04
+++ binutils-2.35.2/bfd/.gitignore	2021-11-30 13:38:37.236657064 +0000
2e9b04
@@ -11,6 +11,7 @@
2e9b04
 /peigen.c
2e9b04
 /pepigen.c
2e9b04
 /pex64igen.c
2e9b04
+/pe-aarch64igen.c
2e9b04
 /stmp-bfd-h
2e9b04
 /targmatch.h
2e9b04
 
2e9b04
diff -rup binutils.orig/bfd/Makefile.am binutils-2.35.2/bfd/Makefile.am
2e9b04
--- binutils.orig/bfd/Makefile.am	2021-11-30 13:38:24.358744186 +0000
2e9b04
+++ binutils-2.35.2/bfd/Makefile.am	2021-11-30 13:38:37.237657058 +0000
2e9b04
@@ -571,7 +571,9 @@ BFD64_BACKENDS = \
2e9b04
 	mach-o-aarch64.lo \
2e9b04
 	mach-o-x86-64.lo \
2e9b04
 	mmo.lo \
2e9b04
+	pe-aarch64igen.lo \
2e9b04
 	pe-x86_64.lo \
2e9b04
+	pei-aarch64lo \
2e9b04
 	pei-ia64.lo \
2e9b04
 	pei-x86_64.lo \
2e9b04
 	pepigen.lo \
2e9b04
@@ -611,6 +613,7 @@ BFD64_BACKENDS_CFILES = \
2e9b04
 	mach-o-x86-64.c \
2e9b04
 	mmo.c \
2e9b04
 	pe-x86_64.c \
2e9b04
+	pei-aarch64.c \
2e9b04
 	pei-ia64.c \
2e9b04
 	pei-x86_64.c \
2e9b04
 	vms-alpha.c
2e9b04
@@ -670,7 +673,7 @@ BUILD_CFILES = \
2e9b04
 	elf32-aarch64.c elf64-aarch64.c \
2e9b04
 	elf32-ia64.c elf64-ia64.c \
2e9b04
 	elf32-riscv.c elf64-riscv.c \
2e9b04
-	peigen.c pepigen.c pex64igen.c
2e9b04
+	peigen.c pepigen.c pex64igen.c pe-aarch64igen.c
2e9b04
 
2e9b04
 CFILES = $(SOURCE_CFILES) $(BUILD_CFILES)
2e9b04
 
2e9b04
@@ -866,6 +869,10 @@ pex64igen.c: peXXigen.c
2e9b04
 	echo "#line 1 \"peXXigen.c\"" > $@
2e9b04
 	$(SED) -e s/XX/pex64/g < $< >> $@
2e9b04
 
2e9b04
+pe-aarch64igen.c: peXXigen.c
2e9b04
+	echo "#line 1 \"peXXigen.c\"" > $@
2e9b04
+	$(SED) -e s/XX/peAArch64/g < $< >> $@
2e9b04
+
2e9b04
 BFD_H_DEPS= $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/diagnostics.h
2e9b04
 LOCAL_H_DEPS= libbfd.h sysdep.h config.h bfd_stdint.h
2e9b04
 $(BFD32_LIBS) \
2e9b04
diff -rup binutils.orig/bfd/Makefile.in binutils-2.35.2/bfd/Makefile.in
2e9b04
--- binutils.orig/bfd/Makefile.in	2021-11-30 13:38:24.346744267 +0000
2e9b04
+++ binutils-2.35.2/bfd/Makefile.in	2021-11-30 13:38:37.238657051 +0000
2e9b04
@@ -997,7 +997,9 @@ BFD64_BACKENDS = \
2e9b04
 	mach-o-aarch64.lo \
2e9b04
 	mach-o-x86-64.lo \
2e9b04
 	mmo.lo \
2e9b04
+	pe-aarch64igen.lo \
2e9b04
 	pe-x86_64.lo \
2e9b04
+	pei-aarch64.lo \
2e9b04
 	pei-ia64.lo \
2e9b04
 	pei-x86_64.lo \
2e9b04
 	pepigen.lo \
2e9b04
@@ -1037,6 +1039,7 @@ BFD64_BACKENDS_CFILES = \
2e9b04
 	mach-o-x86-64.c \
2e9b04
 	mmo.c \
2e9b04
 	pe-x86_64.c \
2e9b04
+	pei-aarch64.c \
2e9b04
 	pei-ia64.c \
2e9b04
 	pei-x86_64.c \
2e9b04
 	vms-alpha.c
2e9b04
@@ -1095,7 +1098,7 @@ BUILD_CFILES = \
2e9b04
 	elf32-aarch64.c elf64-aarch64.c \
2e9b04
 	elf32-ia64.c elf64-ia64.c \
2e9b04
 	elf32-riscv.c elf64-riscv.c \
2e9b04
-	peigen.c pepigen.c pex64igen.c
2e9b04
+	peigen.c pepigen.c pex64igen.c pe-aarch64igen.c
2e9b04
 
2e9b04
 CFILES = $(SOURCE_CFILES) $(BUILD_CFILES)
2e9b04
 SOURCE_HFILES = \
2e9b04
@@ -1556,9 +1559,11 @@ distclean-compile:
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-ppc.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-sh.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-x86_64.Plo@am__quote@
2e9b04
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pei-aarch64.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/peigen.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pepigen.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pex64igen.Plo@am__quote@
2e9b04
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pe-aarch64igen.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plugin.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppcboot.Plo@am__quote@
2e9b04
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reloc.Plo@am__quote@
2e9b04
@@ -1996,6 +2001,11 @@ pepigen.c : peXXigen.c
2e9b04
 pex64igen.c: peXXigen.c
2e9b04
 	echo "#line 1 \"peXXigen.c\"" > $@
2e9b04
 	$(SED) -e s/XX/pex64/g < $< >> $@
2e9b04
+
2e9b04
+pe-aarch64igen.c: peXXigen.c
2e9b04
+	echo "#line 1 \"peXXigen.c\"" > $@
2e9b04
+	$(SED) -e s/XX/peAArch64/g < $< >> $@
2e9b04
+
2e9b04
 $(BFD32_LIBS) \
2e9b04
  $(BFD64_LIBS) \
2e9b04
  $(ALL_MACHINES) \
2e9b04
diff -rup binutils.orig/bfd/bfd.c binutils-2.35.2/bfd/bfd.c
2e9b04
--- binutils.orig/bfd/bfd.c	2021-11-30 13:38:24.344744281 +0000
2e9b04
+++ binutils-2.35.2/bfd/bfd.c	2021-11-30 13:38:37.239657044 +0000
2e9b04
@@ -1747,6 +1747,7 @@ bfd_get_sign_extend_vma (bfd *abfd)
2e9b04
       || strcmp (name, "pei-i386") == 0
2e9b04
       || strcmp (name, "pe-x86-64") == 0
2e9b04
       || strcmp (name, "pei-x86-64") == 0
2e9b04
+      || strcmp (name, "pei-aarch64-little") == 0
2e9b04
       || strcmp (name, "pe-arm-wince-little") == 0
2e9b04
       || strcmp (name, "pei-arm-wince-little") == 0
2e9b04
       || strcmp (name, "aixcoff-rs6000") == 0
2e9b04
diff -rup binutils.orig/bfd/coffcode.h binutils-2.35.2/bfd/coffcode.h
2e9b04
--- binutils.orig/bfd/coffcode.h	2021-11-30 13:38:24.345744274 +0000
2e9b04
+++ binutils-2.35.2/bfd/coffcode.h	2021-11-30 13:38:37.242657024 +0000
2e9b04
@@ -2195,6 +2195,12 @@ coff_set_arch_mach_hook (bfd *abfd, void
2e9b04
 	}
2e9b04
       break;
2e9b04
 #endif
2e9b04
+#ifdef AARCH64MAGIC
2e9b04
+    case AARCH64MAGIC:
2e9b04
+      arch = bfd_arch_aarch64;
2e9b04
+      machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
2e9b04
+      break;
2e9b04
+#endif
2e9b04
 #ifdef Z80MAGIC
2e9b04
     case Z80MAGIC:
2e9b04
       arch = bfd_arch_z80;
2e9b04
@@ -2751,6 +2757,12 @@ coff_set_flags (bfd * abfd,
2e9b04
       return TRUE;
2e9b04
 #endif
2e9b04
 
2e9b04
+#ifdef AARCH64MAGIC
2e9b04
+    case bfd_arch_aarch64:
2e9b04
+      * magicp = AARCH64MAGIC;
2e9b04
+      return TRUE;
2e9b04
+#endif
2e9b04
+
2e9b04
 #ifdef ARMMAGIC
2e9b04
     case bfd_arch_arm:
2e9b04
 #ifdef ARM_WINCE
2e9b04
@@ -3841,7 +3853,7 @@ coff_write_object_contents (bfd * abfd)
2e9b04
     internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
2e9b04
 #endif
2e9b04
 
2e9b04
-#ifndef COFF_WITH_pex64
2e9b04
+#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
 #ifdef COFF_WITH_PE
2e9b04
   internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
2e9b04
 #else
2e9b04
@@ -3895,6 +3907,11 @@ coff_write_object_contents (bfd * abfd)
2e9b04
     internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
2e9b04
 #endif
2e9b04
 
2e9b04
+#if defined(AARCH64)
2e9b04
+#define __A_MAGIC_SET__
2e9b04
+    internal_a.magic = ZMAGIC;
2e9b04
+#endif
2e9b04
+
2e9b04
 #if defined MCORE_PE
2e9b04
 #define __A_MAGIC_SET__
2e9b04
     internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
2e9b04
diff -rup binutils.orig/bfd/config.bfd binutils-2.35.2/bfd/config.bfd
2e9b04
--- binutils.orig/bfd/config.bfd	2021-11-30 13:38:24.358744186 +0000
2e9b04
+++ binutils-2.35.2/bfd/config.bfd	2021-11-30 13:41:24.512525484 +0000
2e9b04
@@ -256,12 +256,12 @@ case "${targ}" in
2e9b04
     ;;
2e9b04
   aarch64-*-linux*)
2e9b04
     targ_defvec=aarch64_elf64_le_vec
2e9b04
-    targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec"
2e9b04
+    targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec aarch64_pei_vec"
2e9b04
     want64=true
2e9b04
     ;;
2e9b04
   aarch64_be-*-linux*)
2e9b04
     targ_defvec=aarch64_elf64_be_vec
2e9b04
-    targ_selvecs="aarch64_elf64_le_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_be_vec arm_elf32_le_vec"
2e9b04
+    targ_selvecs="aarch64_elf64_le_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_be_vec arm_elf32_le_vec aarch64_pei_vec"
2e9b04
     want64=true
2e9b04
     ;;
2e9b04
   alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
2e9b04
diff -rup binutils.orig/bfd/configure binutils-2.35.2/bfd/configure
2e9b04
--- binutils.orig/bfd/configure	2021-11-30 13:38:24.358744186 +0000
2e9b04
+++ binutils-2.35.2/bfd/configure	2021-11-30 13:38:37.250656970 +0000
2e9b04
@@ -14738,6 +14738,7 @@ do
2e9b04
     aarch64_elf64_le_vec)	   tb="$tb elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     aarch64_elf64_le_cloudabi_vec) tb="$tb elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     aarch64_mach_o_vec)		 tb="$tb mach-o-aarch64.lo"; target_size=64 ;;
2e9b04
+    aarch64_pei_vec)		 tb="$tb pei-aarch64.lo pe-aarch64igen.lo $coff"; target_size=64 ;;
2e9b04
     alpha_ecoff_le_vec)		 tb="$tb coff-alpha.lo ecoff.lo $ecoff"; target_size=64 ;;
2e9b04
     alpha_elf64_vec)		 tb="$tb elf64-alpha.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     alpha_elf64_fbsd_vec)	 tb="$tb elf64-alpha.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
diff -rup binutils.orig/bfd/configure.ac binutils-2.35.2/bfd/configure.ac
2e9b04
--- binutils.orig/bfd/configure.ac	2021-11-30 13:38:24.354744213 +0000
2e9b04
+++ binutils-2.35.2/bfd/configure.ac	2021-11-30 13:38:37.251656963 +0000
2e9b04
@@ -450,6 +450,7 @@ do
2e9b04
     aarch64_elf64_le_vec)	   tb="$tb elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     aarch64_elf64_le_cloudabi_vec) tb="$tb elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     aarch64_mach_o_vec)		 tb="$tb mach-o-aarch64.lo"; target_size=64 ;;
2e9b04
+    aarch64_pei_vec)		 tb="$tb pei-aarch64.lo pe-aarch64igen.lo $coff"; target_size=64 ;;
2e9b04
     alpha_ecoff_le_vec)		 tb="$tb coff-alpha.lo ecoff.lo $ecoff"; target_size=64 ;;
2e9b04
     alpha_elf64_vec)		 tb="$tb elf64-alpha.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
     alpha_elf64_fbsd_vec)	 tb="$tb elf64-alpha.lo elf64.lo $elf"; target_size=64 ;;
2e9b04
diff -rup binutils.orig/bfd/libpei.h binutils-2.35.2/bfd/libpei.h
2e9b04
--- binutils.orig/bfd/libpei.h	2021-11-30 13:38:24.355744206 +0000
2e9b04
+++ binutils-2.35.2/bfd/libpei.h	2021-11-30 13:41:57.744300692 +0000
2e9b04
@@ -275,6 +275,41 @@
2e9b04
 #define _bfd_XXi_write_codeview_record			_bfd_pepi_write_codeview_record
2e9b04
 #define _bfd_XXi_slurp_codeview_record			_bfd_pepi_slurp_codeview_record
2e9b04
 
2e9b04
+#elif defined COFF_WITH_peAArch64
2e9b04
+
2e9b04
+#define GET_OPTHDR_IMAGE_BASE		 H_GET_64
2e9b04
+#define PUT_OPTHDR_IMAGE_BASE		 H_PUT_64
2e9b04
+#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_64
2e9b04
+#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_64
2e9b04
+#define GET_OPTHDR_SIZE_OF_STACK_COMMIT	 H_GET_64
2e9b04
+#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT	 H_PUT_64
2e9b04
+#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE	 H_GET_64
2e9b04
+#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE	 H_PUT_64
2e9b04
+#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT	 H_GET_64
2e9b04
+#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT	 H_PUT_64
2e9b04
+#define GET_PDATA_ENTRY			 bfd_get_32
2e9b04
+
2e9b04
+#define _bfd_XX_bfd_copy_private_bfd_data_common	_bfd_peAArch64_bfd_copy_private_bfd_data_common
2e9b04
+#define _bfd_XX_bfd_copy_private_section_data		_bfd_peAArch64_bfd_copy_private_section_data
2e9b04
+#define _bfd_XX_get_symbol_info				_bfd_peAArch64_get_symbol_info
2e9b04
+#define _bfd_XX_only_swap_filehdr_out			_bfd_peAArch64_only_swap_filehdr_out
2e9b04
+#define _bfd_XX_print_private_bfd_data_common		_bfd_peAArch64_print_private_bfd_data_common
2e9b04
+#define _bfd_XXi_final_link_postscript			_bfd_peAArch64i_final_link_postscript
2e9b04
+#define _bfd_XXi_only_swap_filehdr_out			_bfd_peAArch64i_only_swap_filehdr_out
2e9b04
+#define _bfd_XXi_swap_aouthdr_in			_bfd_peAArch64i_swap_aouthdr_in
2e9b04
+#define _bfd_XXi_swap_aouthdr_out			_bfd_peAArch64i_swap_aouthdr_out
2e9b04
+#define _bfd_XXi_swap_aux_in				_bfd_peAArch64i_swap_aux_in
2e9b04
+#define _bfd_XXi_swap_aux_out				_bfd_peAArch64i_swap_aux_out
2e9b04
+#define _bfd_XXi_swap_lineno_in				_bfd_peAArch64i_swap_lineno_in
2e9b04
+#define _bfd_XXi_swap_lineno_out			_bfd_peAArch64i_swap_lineno_out
2e9b04
+#define _bfd_XXi_swap_scnhdr_out			_bfd_peAArch64i_swap_scnhdr_out
2e9b04
+#define _bfd_XXi_swap_sym_in				_bfd_peAArch64i_swap_sym_in
2e9b04
+#define _bfd_XXi_swap_sym_out				_bfd_peAArch64i_swap_sym_out
2e9b04
+#define _bfd_XXi_swap_debugdir_in			_bfd_peAArch64i_swap_debugdir_in
2e9b04
+#define _bfd_XXi_swap_debugdir_out			_bfd_peAArch64i_swap_debugdir_out
2e9b04
+#define _bfd_XXi_write_codeview_record			_bfd_peAArch64i_write_codeview_record
2e9b04
+#define _bfd_XXi_slurp_codeview_record			_bfd_peAArch64i_slurp_codeview_record
2e9b04
+
2e9b04
 #else /* !COFF_WITH_pep */
2e9b04
 
2e9b04
 #define GET_OPTHDR_IMAGE_BASE H_GET_32
2e9b04
@@ -368,4 +403,5 @@ bfd_boolean _bfd_pe_print_ce_compressed_
2e9b04
 bfd_boolean _bfd_pe64_print_ce_compressed_pdata (bfd *, void *);
2e9b04
 bfd_boolean _bfd_pex64_print_ce_compressed_pdata (bfd *, void *);
2e9b04
 bfd_boolean _bfd_pep_print_ce_compressed_pdata (bfd *, void *);
2e9b04
+bfd_boolean _bfd_peAArch64_print_ce_compressed_pdata (bfd *, void *);
2e9b04
 
2e9b04
diff -rup binutils.orig/bfd/peXXigen.c binutils-2.35.2/bfd/peXXigen.c
2e9b04
--- binutils.orig/bfd/peXXigen.c	2021-11-30 13:38:24.352744227 +0000
2e9b04
+++ binutils-2.35.2/bfd/peXXigen.c	2021-11-30 13:38:37.255656936 +0000
2e9b04
@@ -60,8 +60,9 @@
2e9b04
    on this code has a chance of getting something accomplished without
2e9b04
    wasting too much time.  */
2e9b04
 
2e9b04
-/* This expands into COFF_WITH_pe, COFF_WITH_pep, or COFF_WITH_pex64
2e9b04
-   depending on whether we're compiling for straight PE or PE+.  */
2e9b04
+/* This expands into COFF_WITH_pe, COFF_WITH_pep, COFF_WITH_pex64 or
2e9b04
+   COFF_WITH_peAArch64 depending on whether we're compiling for straight
2e9b04
+   PE or PE+.  */
2e9b04
 #define COFF_WITH_XX
2e9b04
 
2e9b04
 #include "sysdep.h"
2e9b04
@@ -87,6 +88,8 @@
2e9b04
 # include "coff/x86_64.h"
2e9b04
 #elif defined COFF_WITH_pep
2e9b04
 # include "coff/ia64.h"
2e9b04
+#elif defined COFF_WITH_peAArch64
2e9b04
+# include "coff/aarch64.h"
2e9b04
 #else
2e9b04
 # include "coff/i386.h"
2e9b04
 #endif
2e9b04
@@ -96,7 +99,7 @@
2e9b04
 #include "libpei.h"
2e9b04
 #include "safe-ctype.h"
2e9b04
 
2e9b04
-#if defined COFF_WITH_pep || defined COFF_WITH_pex64
2e9b04
+#if defined COFF_WITH_pep || defined COFF_WITH_pex64 || defined COFF_WITH_peAArch64
2e9b04
 # undef AOUTSZ
2e9b04
 # define AOUTSZ		PEPAOUTSZ
2e9b04
 # define PEAOUTHDR	PEPAOUTHDR
2e9b04
@@ -485,7 +488,7 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
2e9b04
   aouthdr_int->text_start =
2e9b04
     GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start);
2e9b04
 
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
   /* PE32+ does not have data_start member!  */
2e9b04
   aouthdr_int->data_start =
2e9b04
     GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start);
2e9b04
@@ -571,7 +574,7 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
2e9b04
   if (aouthdr_int->entry)
2e9b04
     {
2e9b04
       aouthdr_int->entry += a->ImageBase;
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       aouthdr_int->entry &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
@@ -579,12 +582,12 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
2e9b04
   if (aouthdr_int->tsize)
2e9b04
     {
2e9b04
       aouthdr_int->text_start += a->ImageBase;
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       aouthdr_int->text_start &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
 
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
   /* PE32+ does not have data_start member!  */
2e9b04
   if (aouthdr_int->dsize)
2e9b04
     {
2e9b04
@@ -653,7 +656,7 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
2e9b04
   if (aouthdr_in->tsize)
2e9b04
     {
2e9b04
       aouthdr_in->text_start -= ib;
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       aouthdr_in->text_start &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
@@ -661,7 +664,7 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
2e9b04
   if (aouthdr_in->dsize)
2e9b04
     {
2e9b04
       aouthdr_in->data_start -= ib;
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       aouthdr_in->data_start &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
@@ -669,7 +672,7 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
2e9b04
   if (aouthdr_in->entry)
2e9b04
     {
2e9b04
       aouthdr_in->entry -= ib;
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       aouthdr_in->entry &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
@@ -773,7 +776,7 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, v
2e9b04
   PUT_AOUTHDR_TEXT_START (abfd, aouthdr_in->text_start,
2e9b04
 			  aouthdr_out->standard.text_start);
2e9b04
 
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
   /* PE32+ does not have data_start member!  */
2e9b04
   PUT_AOUTHDR_DATA_START (abfd, aouthdr_in->data_start,
2e9b04
 			  aouthdr_out->standard.data_start);
2e9b04
@@ -1886,7 +1889,7 @@ pe_print_edata (bfd * abfd, void * vfile
2e9b04
 static bfd_boolean
2e9b04
 pe_print_pdata (bfd * abfd, void * vfile)
2e9b04
 {
2e9b04
-#if defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
 # define PDATA_ROW_SIZE	(3 * 8)
2e9b04
 #else
2e9b04
 # define PDATA_ROW_SIZE	(5 * 4)
2e9b04
@@ -1913,7 +1916,7 @@ pe_print_pdata (bfd * abfd, void * vfile
2e9b04
 
2e9b04
   fprintf (file,
2e9b04
 	   _("\nThe Function Table (interpreted .pdata section contents)\n"));
2e9b04
-#if defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
   fprintf (file,
2e9b04
 	   _(" vma:\t\t\tBegin Address    End Address      Unwind Info\n"));
2e9b04
 #else
2e9b04
@@ -1950,7 +1953,7 @@ pe_print_pdata (bfd * abfd, void * vfile
2e9b04
       bfd_vma eh_handler;
2e9b04
       bfd_vma eh_data;
2e9b04
       bfd_vma prolog_end_addr;
2e9b04
-#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
2e9b04
       int em_data;
2e9b04
 #endif
2e9b04
 
2e9b04
@@ -1968,7 +1971,7 @@ pe_print_pdata (bfd * abfd, void * vfile
2e9b04
 	/* We are probably into the padding of the section now.  */
2e9b04
 	break;
2e9b04
 
2e9b04
-#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
2e9b04
       em_data = ((eh_handler & 0x1) << 2) | (prolog_end_addr & 0x3);
2e9b04
 #endif
2e9b04
       eh_handler &= ~(bfd_vma) 0x3;
2e9b04
@@ -1979,7 +1982,7 @@ pe_print_pdata (bfd * abfd, void * vfile
2e9b04
       bfd_fprintf_vma (abfd, file, begin_addr); fputc (' ', file);
2e9b04
       bfd_fprintf_vma (abfd, file, end_addr); fputc (' ', file);
2e9b04
       bfd_fprintf_vma (abfd, file, eh_handler);
2e9b04
-#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) || defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
2e9b04
       fputc (' ', file);
2e9b04
       bfd_fprintf_vma (abfd, file, eh_data); fputc (' ', file);
2e9b04
       bfd_fprintf_vma (abfd, file, prolog_end_addr);
2e9b04
@@ -2894,7 +2897,7 @@ _bfd_XX_print_private_bfd_data_common (b
2e9b04
   bfd_fprintf_vma (abfd, file, i->AddressOfEntryPoint);
2e9b04
   fprintf (file, "\nBaseOfCode\t\t");
2e9b04
   bfd_fprintf_vma (abfd, file, i->BaseOfCode);
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
   /* PE32+ does not have BaseOfData member!  */
2e9b04
   fprintf (file, "\nBaseOfData\t\t");
2e9b04
   bfd_fprintf_vma (abfd, file, i->BaseOfData);
2e9b04
@@ -3163,7 +3166,7 @@ _bfd_XX_get_symbol_info (bfd * abfd, asy
2e9b04
   coff_get_symbol_info (abfd, symbol, ret);
2e9b04
 }
2e9b04
 
2e9b04
-#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64) && defined(COFF_WITH_peAArch64)
2e9b04
 static int
2e9b04
 sort_x64_pdata (const void *l, const void *r)
2e9b04
 {
2e9b04
@@ -4595,7 +4598,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
2e9b04
 	the TLS data directory consists of 4 pointers, followed
2e9b04
 	by two 4-byte integer. This implies that the total size
2e9b04
 	is different for 32-bit and 64-bit executables.  */
2e9b04
-#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x18;
2e9b04
 #else
2e9b04
       pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x28;
2e9b04
@@ -4604,7 +4607,7 @@ _bfd_XXi_final_link_postscript (bfd * ab
2e9b04
 
2e9b04
 /* If there is a .pdata section and we have linked pdata finally, we
2e9b04
      need to sort the entries ascending.  */
2e9b04
-#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64)
2e9b04
+#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64) && defined(COFF_WITH_peAArch64)
2e9b04
   {
2e9b04
     asection *sec = bfd_get_section_by_name (abfd, ".pdata");
2e9b04
 
2e9b04
Only in binutils-2.35.2/bfd: pei-aarch64.c
2e9b04
diff -rup binutils.orig/bfd/peicode.h binutils-2.35.2/bfd/peicode.h
2e9b04
--- binutils.orig/bfd/peicode.h	2021-11-30 13:38:24.354744213 +0000
2e9b04
+++ binutils-2.35.2/bfd/peicode.h	2021-11-30 13:38:37.256656929 +0000
2e9b04
@@ -231,7 +231,7 @@ coff_swap_scnhdr_in (bfd * abfd, void *
2e9b04
     {
2e9b04
       scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
2e9b04
       /* Do not cut upper 32-bits for 64-bit vma.  */
2e9b04
-#ifndef COFF_WITH_pex64
2e9b04
+#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
2e9b04
       scnhdr_int->s_vaddr &= 0xffffffff;
2e9b04
 #endif
2e9b04
     }
2e9b04
@@ -738,6 +738,16 @@ static jump_table jtab[] =
2e9b04
   },
2e9b04
 #endif
2e9b04
 
2e9b04
+#ifdef AARCH64MAGIC
2e9b04
+/* We don't currently support jumping to DLLs, so if
2e9b04
+   someone does try emit a runtime trap.  Through UDF #0.  */
2e9b04
+  { AARCH64MAGIC,
2e9b04
+    { 0x00, 0x00, 0x00, 0x00 },
2e9b04
+    4, 0
2e9b04
+  },
2e9b04
+
2e9b04
+#endif
2e9b04
+
2e9b04
 #ifdef  ARMPEMAGIC
2e9b04
   { ARMPEMAGIC,
2e9b04
     { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
2e9b04
@@ -910,7 +920,7 @@ pe_ILF_build_a_bfd (bfd *	    abfd,
2e9b04
 	/* See PR 20907 for a reproducer.  */
2e9b04
 	goto error_return;
2e9b04
 
2e9b04
-#ifdef COFF_WITH_pex64
2e9b04
+#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
2e9b04
       ((unsigned int *) id4->contents)[0] = ordinal;
2e9b04
       ((unsigned int *) id4->contents)[1] = 0x80000000;
2e9b04
       ((unsigned int *) id5->contents)[0] = ordinal;
2e9b04
@@ -1206,6 +1216,12 @@ pe_ILF_object_p (bfd * abfd)
2e9b04
 #endif
2e9b04
       break;
2e9b04
 
2e9b04
+    case IMAGE_FILE_MACHINE_ARM64:
2e9b04
+#ifdef AARCH64MAGIC
2e9b04
+      magic = AARCH64MAGIC;
2e9b04
+#endif
2e9b04
+      break;
2e9b04
+
2e9b04
     case IMAGE_FILE_MACHINE_THUMB:
2e9b04
 #ifdef THUMBPEMAGIC
2e9b04
       {
2e9b04
diff -rup binutils.orig/bfd/targets.c binutils-2.35.2/bfd/targets.c
2e9b04
--- binutils.orig/bfd/targets.c	2021-11-30 13:38:24.354744213 +0000
2e9b04
+++ binutils-2.35.2/bfd/targets.c	2021-11-30 13:38:37.257656922 +0000
2e9b04
@@ -668,6 +668,7 @@ extern const bfd_target aarch64_elf64_be
2e9b04
 extern const bfd_target aarch64_elf64_le_vec;
2e9b04
 extern const bfd_target aarch64_elf64_le_cloudabi_vec;
2e9b04
 extern const bfd_target aarch64_mach_o_vec;
2e9b04
+extern const bfd_target aarch64_pei_vec;
2e9b04
 extern const bfd_target alpha_ecoff_le_vec;
2e9b04
 extern const bfd_target alpha_elf64_vec;
2e9b04
 extern const bfd_target alpha_elf64_fbsd_vec;
2e9b04
@@ -983,6 +984,7 @@ static const bfd_target * const _bfd_tar
2e9b04
 	&aarch64_elf64_le_vec,
2e9b04
 	&aarch64_elf64_le_cloudabi_vec,
2e9b04
 	&aarch64_mach_o_vec,
2e9b04
+	&aarch64_pei_vec,
2e9b04
 #endif
2e9b04
 
2e9b04
 #ifdef BFD64
2e9b04
diff -rup binutils.orig/binutils/NEWS binutils-2.35.2/binutils/NEWS
2e9b04
--- binutils.orig/binutils/NEWS	2021-11-30 13:38:23.874747460 +0000
2e9b04
+++ binutils-2.35.2/binutils/NEWS	2021-11-30 13:42:31.024075560 +0000
2e9b04
@@ -1,5 +1,8 @@
2e9b04
 -*- text -*-
2e9b04
 
2e9b04
+* Support for efi-app-aarch64, efi-rtdrv-aarch64 and efi-bsdrv-aarch64 has been
2e9b04
+  added to objcopy in order to enable UEFI development using binutils.
2e9b04
+
2e9b04
 Changes in 2.35:
2e9b04
 
2e9b04
 * Changed readelf's display of symbol names when wide mode is not enabled.
2e9b04
diff -rup binutils.orig/binutils/objcopy.c binutils-2.35.2/binutils/objcopy.c
2e9b04
--- binutils.orig/binutils/objcopy.c	2021-11-30 13:38:23.874747460 +0000
2e9b04
+++ binutils-2.35.2/binutils/objcopy.c	2021-11-30 13:38:37.260656902 +0000
2e9b04
@@ -4950,6 +4950,13 @@ convert_efi_target (char *efi)
2e9b04
       /* Change x86_64 to x86-64.  */
2e9b04
       efi[7] = '-';
2e9b04
     }
2e9b04
+  else if (strcmp (efi + 4, "aarch64") == 0)
2e9b04
+    {
2e9b04
+      /* Change aarch64 to aarch64-little.  */
2e9b04
+      efi = (char *) xrealloc (efi, strlen (efi) + 7);
2e9b04
+      char *t = "aarch64-little";
2e9b04
+      strcpy (efi + 4, t);
2e9b04
+    }
2e9b04
 }
2e9b04
 
2e9b04
 /* Allocate and return a pointer to a struct section_add, initializing the
2e9b04
diff -rup binutils.orig/include/coff/pe.h binutils-2.35.2/include/coff/pe.h
2e9b04
--- binutils.orig/include/coff/pe.h	2021-11-30 13:38:23.827747778 +0000
2e9b04
+++ binutils-2.35.2/include/coff/pe.h	2021-11-30 13:38:37.261656895 +0000
2e9b04
@@ -132,6 +132,7 @@
2e9b04
 #define IMAGE_FILE_MACHINE_AM33              0x01d3
2e9b04
 #define IMAGE_FILE_MACHINE_AMD64             0x8664
2e9b04
 #define IMAGE_FILE_MACHINE_ARM               0x01c0
2e9b04
+#define IMAGE_FILE_MACHINE_ARM64             0xaa64
2e9b04
 #define IMAGE_FILE_MACHINE_AXP64             IMAGE_FILE_MACHINE_ALPHA64
2e9b04
 #define IMAGE_FILE_MACHINE_CEE               0xc0ee
2e9b04
 #define IMAGE_FILE_MACHINE_CEF               0x0cef
2e9b04
--- /dev/null	2021-11-30 07:48:35.901044247 +0000
2e9b04
+++ binutils-2.35.2/bfd/coff-aarch64.c	2021-11-30 13:43:11.774799879 +0000
2e9b04
@@ -0,0 +1,165 @@
2e9b04
+/* BFD back-end for AArch64 COFF files.
2e9b04
+   Copyright (C) 2021 Free Software Foundation, Inc.
2e9b04
+
2e9b04
+   This file is part of BFD, the Binary File Descriptor library.
2e9b04
+
2e9b04
+   This program is free software; you can redistribute it and/or modify
2e9b04
+   it under the terms of the GNU General Public License as published by
2e9b04
+   the Free Software Foundation; either version 3 of the License, or
2e9b04
+   (at your option) any later version.
2e9b04
+
2e9b04
+   This program is distributed in the hope that it will be useful,
2e9b04
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2e9b04
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2e9b04
+   GNU General Public License for more details.
2e9b04
+
2e9b04
+   You should have received a copy of the GNU General Public License
2e9b04
+   along with this program; if not, write to the Free Software
2e9b04
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2e9b04
+   MA 02110-1301, USA.  */
2e9b04
+
2e9b04
+
2e9b04
+#ifndef COFF_WITH_peAArch64
2e9b04
+#define COFF_WITH_peAArch64
2e9b04
+#endif
2e9b04
+
2e9b04
+/* Note we have to make sure not to include headers twice.
2e9b04
+   Not all headers are wrapped in #ifdef guards, so we define
2e9b04
+   PEI_HEADERS to prevent double including here.  */
2e9b04
+#ifndef PEI_HEADERS
2e9b04
+#include "sysdep.h"
2e9b04
+#include "bfd.h"
2e9b04
+#include "libbfd.h"
2e9b04
+#include "coff/aarch64.h"
2e9b04
+#include "coff/internal.h"
2e9b04
+#include "coff/pe.h"
2e9b04
+#include "libcoff.h"
2e9b04
+#include "libiberty.h"
2e9b04
+#endif
2e9b04
+
2e9b04
+#include "libcoff.h"
2e9b04
+
2e9b04
+/* The page size is a guess based on ELF.  */
2e9b04
+
2e9b04
+#define COFF_PAGE_SIZE 0x1000
2e9b04
+
2e9b04
+/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
2e9b04
+#define OCTETS_PER_BYTE(ABFD, SEC) 1
2e9b04
+
2e9b04
+#ifndef PCRELOFFSET
2e9b04
+#define PCRELOFFSET TRUE
2e9b04
+#endif
2e9b04
+
2e9b04
+/* Currently we don't handle any relocations.  */
2e9b04
+static reloc_howto_type pe_aarch64_std_reloc_howto[] =
2e9b04
+  {
2e9b04
+
2e9b04
+  };
2e9b04
+
2e9b04
+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  2
2e9b04
+#define COFF_PAGE_SIZE			      0x1000
2e9b04
+
2e9b04
+#ifndef NUM_ELEM
2e9b04
+#define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
2e9b04
+#endif
2e9b04
+
2e9b04
+#define NUM_RELOCS NUM_ELEM (pe_aarch64_std_reloc_howto)
2e9b04
+
2e9b04
+#define RTYPE2HOWTO(cache_ptr, dst)             \
2e9b04
+  (cache_ptr)->howto = NULL
2e9b04
+
2e9b04
+#ifndef bfd_pe_print_pdata
2e9b04
+#define bfd_pe_print_pdata      NULL
2e9b04
+#endif
2e9b04
+
2e9b04
+/* Return TRUE if this relocation should
2e9b04
+   appear in the output .reloc section.  */
2e9b04
+
2e9b04
+static bfd_boolean
2e9b04
+in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
2e9b04
+            reloc_howto_type * howto)
2e9b04
+{
2e9b04
+  return !howto->pc_relative;
2e9b04
+}
2e9b04
+
2e9b04
+#include "coffcode.h"
2e9b04
+
2e9b04
+/* Target vectors.  */
2e9b04
+const bfd_target
2e9b04
+#ifdef TARGET_SYM
2e9b04
+  TARGET_SYM =
2e9b04
+#else
2e9b04
+  aarch64_pei_vec =
2e9b04
+#endif
2e9b04
+{
2e9b04
+#ifdef TARGET_NAME
2e9b04
+  TARGET_NAME,
2e9b04
+#else
2e9b04
+ "pei-aarch64-little",			/* Name.  */
2e9b04
+#endif
2e9b04
+  bfd_target_coff_flavour,
2e9b04
+  BFD_ENDIAN_LITTLE,		/* Data byte order is little.  */
2e9b04
+  BFD_ENDIAN_LITTLE,		/* Header byte order is little.  */
2e9b04
+
2e9b04
+  (HAS_RELOC | EXEC_P		/* Object flags.  */
2e9b04
+   | HAS_LINENO | HAS_DEBUG
2e9b04
+   | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS),
2e9b04
+
2e9b04
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags.  */
2e9b04
+#if defined(COFF_WITH_PE)
2e9b04
+   | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING
2e9b04
+#endif
2e9b04
+   | SEC_CODE | SEC_DATA | SEC_EXCLUDE ),
2e9b04
+
2e9b04
+#ifdef TARGET_UNDERSCORE
2e9b04
+  TARGET_UNDERSCORE,		/* Leading underscore.  */
2e9b04
+#else
2e9b04
+  0,				/* Leading underscore.  */
2e9b04
+#endif
2e9b04
+  '/',				/* Ar_pad_char.  */
2e9b04
+  15,				/* Ar_max_namelen.  */
2e9b04
+  0,				/* match priority.  */
2e9b04
+
2e9b04
+     /* Data conversion functions.  */
2e9b04
+     bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2e9b04
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2e9b04
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data.  */
2e9b04
+     /* Header conversion functions.  */
2e9b04
+     bfd_getl64, bfd_getl_signed_64, bfd_putl64,
2e9b04
+     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
2e9b04
+     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs.  */
2e9b04
+
2e9b04
+  /* Note that we allow an object file to be treated as a core file as well.  */
2e9b04
+  {				/* bfd_check_format.  */
2e9b04
+    _bfd_dummy_target,
2e9b04
+    coff_object_p,
2e9b04
+    bfd_generic_archive_p,
2e9b04
+    coff_object_p
2e9b04
+  },
2e9b04
+  {				/* bfd_set_format.  */
2e9b04
+    _bfd_bool_bfd_false_error,
2e9b04
+    coff_mkobject,
2e9b04
+    _bfd_generic_mkarchive,
2e9b04
+    _bfd_bool_bfd_false_error
2e9b04
+  },
2e9b04
+  {				/* bfd_write_contents.  */
2e9b04
+    _bfd_bool_bfd_false_error,
2e9b04
+    coff_write_object_contents,
2e9b04
+    _bfd_write_archive_contents,
2e9b04
+    _bfd_bool_bfd_false_error
2e9b04
+  },
2e9b04
+
2e9b04
+  BFD_JUMP_TABLE_GENERIC (coff),
2e9b04
+  BFD_JUMP_TABLE_COPY (coff),
2e9b04
+  BFD_JUMP_TABLE_CORE (_bfd_nocore),
2e9b04
+  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
2e9b04
+  BFD_JUMP_TABLE_SYMBOLS (coff),
2e9b04
+  BFD_JUMP_TABLE_RELOCS (coff),
2e9b04
+  BFD_JUMP_TABLE_WRITE (coff),
2e9b04
+  BFD_JUMP_TABLE_LINK (coff),
2e9b04
+  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
2e9b04
+
2e9b04
+  NULL,
2e9b04
+
2e9b04
+  COFF_SWAP_TABLE
2e9b04
+};
2e9b04
--- /dev/null	2021-11-30 07:48:35.901044247 +0000
2e9b04
+++ binutils-2.35.2/include/coff/aarch64.h	2021-11-30 13:38:37.261656895 +0000
2e9b04
@@ -0,0 +1,63 @@
2e9b04
+/* AArch64 COFF support for BFD.
2e9b04
+   Copyright (C) 2021 Free Software Foundation, Inc.
2e9b04
+
2e9b04
+   This file is part of BFD, the Binary File Descriptor library.
2e9b04
+
2e9b04
+   This program is free software; you can redistribute it and/or modify
2e9b04
+   it under the terms of the GNU General Public License as published by
2e9b04
+   the Free Software Foundation; either version 3 of the License, or
2e9b04
+   (at your option) any later version.
2e9b04
+
2e9b04
+   This program is distributed in the hope that it will be useful,
2e9b04
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2e9b04
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2e9b04
+   GNU General Public License for more details.
2e9b04
+
2e9b04
+   You should have received a copy of the GNU General Public License
2e9b04
+   along with this program; if not, write to the Free Software Foundation,
2e9b04
+   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2e9b04
+
2e9b04
+#define COFFAARCH64 1
2e9b04
+
2e9b04
+#define L_LNNO_SIZE 2
2e9b04
+#define INCLUDE_COMDAT_FIELDS_IN_AUXENT
2e9b04
+#include "coff/external.h"
2e9b04
+
2e9b04
+#define F_AARCH64_ARCHITECTURE_MASK	(0x4000)
2e9b04
+
2e9b04
+#define	AARCH64MAGIC	0xaa64  /* From Microsoft specification. */
2e9b04
+
2e9b04
+#undef  BADMAG
2e9b04
+#define BADMAG(x) ((x).f_magic != AARCH64MAGIC)
2e9b04
+#define AARCH64         1                 /* Customize coffcode.h.  */
2e9b04
+
2e9b04
+#define IMAGE_NT_OPTIONAL_HDR64_MAGIC      0x20b
2e9b04
+
2e9b04
+#define OMAGIC          0404    /* Object files, eg as output.  */
2e9b04
+#define ZMAGIC          IMAGE_NT_OPTIONAL_HDR64_MAGIC    /* Demand load format, eg normal ld output 0x10b.  */
2e9b04
+#define STMAGIC		0401	/* Target shlib.  */
2e9b04
+#define SHMAGIC		0443	/* Host   shlib.  */
2e9b04
+
2e9b04
+/* define some NT default values */
2e9b04
+/*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
2e9b04
+#define NT_SECTION_ALIGNMENT 0x1000
2e9b04
+#define NT_FILE_ALIGNMENT    0x200
2e9b04
+#define NT_DEF_RESERVE       0x100000
2e9b04
+#define NT_DEF_COMMIT        0x1000
2e9b04
+
2e9b04
+/* We use the .rdata section to hold read only data.  */
2e9b04
+#define _LIT	".rdata"
2e9b04
+
2e9b04
+/********************** RELOCATION DIRECTIVES **********************/
2e9b04
+struct external_reloc
2e9b04
+{
2e9b04
+  char r_vaddr[4];
2e9b04
+  char r_symndx[4];
2e9b04
+  char r_type[2];
2e9b04
+  char r_offset[4];
2e9b04
+};
2e9b04
+
2e9b04
+#define RELOC struct external_reloc
2e9b04
+#define RELSZ 14
2e9b04
+
2e9b04
+#define ARM_NOTE_SECTION ".note"
2e9b04
--- /dev/null	2021-11-30 07:48:35.901044247 +0000
2e9b04
+++ binutils-2.35.2/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.s	2021-11-30 13:38:37.260656902 +0000
2e9b04
@@ -0,0 +1,42 @@
2e9b04
+	.arch armv8-a
2e9b04
+	.text
2e9b04
+	.align	2
2e9b04
+	.global	foo
2e9b04
+	.type	foo, %function
2e9b04
+foo:
2e9b04
+.LFB0:
2e9b04
+	.cfi_startproc
2e9b04
+	sub	sp, sp, #16
2e9b04
+	.cfi_def_cfa_offset 16
2e9b04
+	str	w0, [sp, 12]
2e9b04
+	ldr	w0, [sp, 12]
2e9b04
+	mul	w0, w0, w0
2e9b04
+	add	sp, sp, 16
2e9b04
+	.cfi_def_cfa_offset 0
2e9b04
+	ret
2e9b04
+	.cfi_endproc
2e9b04
+.LFE0:
2e9b04
+	.size	foo, .-foo
2e9b04
+	.align	2
2e9b04
+	.global	main
2e9b04
+	.type	main, %function
2e9b04
+main:
2e9b04
+.LFB1:
2e9b04
+	.cfi_startproc
2e9b04
+	stp	x29, x30, [sp, -16]!
2e9b04
+	.cfi_def_cfa_offset 16
2e9b04
+	.cfi_offset 29, -16
2e9b04
+	.cfi_offset 30, -8
2e9b04
+	mov	x29, sp
2e9b04
+	mov	w0, 5
2e9b04
+	bl	foo
2e9b04
+	ldp	x29, x30, [sp], 16
2e9b04
+	.cfi_restore 30
2e9b04
+	.cfi_restore 29
2e9b04
+	.cfi_def_cfa_offset 0
2e9b04
+	ret
2e9b04
+	.cfi_endproc
2e9b04
+.LFE1:
2e9b04
+	.size	main, .-main
2e9b04
+	.ident	"GCC: (fsf-trunk.2870) 12.0.0 20210930 (experimental)"
2e9b04
+	.section	.note.GNU-stack,"",@progbits
2e9b04
--- /dev/null	2021-11-30 07:48:35.901044247 +0000
2e9b04
+++ binutils-2.35.2/binutils/testsuite/binutils-all/aarch64/pei-aarch64-little.d	2021-11-30 13:38:37.260656902 +0000
2e9b04
@@ -0,0 +1,16 @@
2e9b04
+#skip: aarch64_be-*-*
2e9b04
+#ld: -e0
2e9b04
+#PROG: objcopy
2e9b04
+#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
2e9b04
+#objdump: -h -f
2e9b04
+#name: Check if efi app format is recognized
2e9b04
+
2e9b04
+.*:     file format pei-aarch64-little
2e9b04
+architecture: aarch64, flags 0x00000132:
2e9b04
+EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED
2e9b04
+start address 0x0000000000000000
2e9b04
+
2e9b04
+Sections:
2e9b04
+Idx Name          Size      VMA               LMA               File off  Algn
2e9b04
+  0 \.text         00000030  0[^ ]+  0[^ ]+  0[^ ]+  2\*\*2
2e9b04
+                  CONTENTS, ALLOC, LOAD, READONLY, CODE
2e9b04
--- /dev/null	2021-11-30 07:48:35.901044247 +0000
2e9b04
+++ binutils-2.35.2/bfd/pei-aarch64.c	2021-11-30 13:38:37.255656936 +0000
2e9b04
@@ -0,0 +1,75 @@
2e9b04
+/* BFD back-end for AArch64 PE IMAGE COFF files.
2e9b04
+   Copyright (C) 2021 Free Software Foundation, Inc.
2e9b04
+
2e9b04
+   This file is part of BFD, the Binary File Descriptor library.
2e9b04
+
2e9b04
+   This program is free software; you can redistribute it and/or modify
2e9b04
+   it under the terms of the GNU General Public License as published by
2e9b04
+   the Free Software Foundation; either version 3 of the License, or
2e9b04
+   (at your option) any later version.
2e9b04
+
2e9b04
+   This program is distributed in the hope that it will be useful,
2e9b04
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2e9b04
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2e9b04
+   GNU General Public License for more details.
2e9b04
+
2e9b04
+   You should have received a copy of the GNU General Public License
2e9b04
+   along with this program; if not, write to the Free Software
2e9b04
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
2e9b04
+   MA 02110-1301, USA.  */
2e9b04
+
2e9b04
+#include "sysdep.h"
2e9b04
+#include "bfd.h"
2e9b04
+
2e9b04
+#define TARGET_SYM		aarch64_pei_vec
2e9b04
+#define TARGET_NAME		"pei-aarch64-little"
2e9b04
+#define TARGET_ARCHITECTURE	bfd_arch_aarch64
2e9b04
+#define TARGET_PAGESIZE		4096
2e9b04
+#define TARGET_BIG_ENDIAN	0
2e9b04
+#define TARGET_ARCHIVE		0
2e9b04
+#define TARGET_PRIORITY		0
2e9b04
+
2e9b04
+#define COFF_IMAGE_WITH_PE
2e9b04
+/* Rename the above into.. */
2e9b04
+#define COFF_WITH_peAArch64
2e9b04
+#define COFF_WITH_PE
2e9b04
+#define PCRELOFFSET	   TRUE
2e9b04
+
2e9b04
+/* Long section names not allowed in executable images, only object files.  */
2e9b04
+#define COFF_LONG_SECTION_NAMES 0
2e9b04
+
2e9b04
+#define COFF_SECTION_ALIGNMENT_ENTRIES \
2e9b04
+{ COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_EXACT_MATCH (".data"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_EXACT_MATCH (".rdata"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_EXACT_MATCH (".text"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
2e9b04
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
2e9b04
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
2e9b04
+  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
2e9b04
+
2e9b04
+#define PEI_HEADERS
2e9b04
+#include "sysdep.h"
2e9b04
+#include "bfd.h"
2e9b04
+#include "libbfd.h"
2e9b04
+#include "coff/aarch64.h"
2e9b04
+#include "coff/internal.h"
2e9b04
+#include "coff/pe.h"
2e9b04
+#include "libcoff.h"
2e9b04
+#include "libpei.h"
2e9b04
+#include "libiberty.h"
2e9b04
+
2e9b04
+/* Make sure we're setting a 64-bit format.  */
2e9b04
+#undef AOUTSZ
2e9b04
+#define AOUTSZ          PEPAOUTSZ
2e9b04
+#define PEAOUTHDR       PEPAOUTHDR
2e9b04
+
2e9b04
+#include "coff-aarch64.c"