summaryrefslogtreecommitdiff
path: root/bfd/coffcode.h
diff options
context:
space:
mode:
authorYouling Tang <tangyouling@loongson.cn>2022-08-06 14:49:43 +0800
committerliuzhensong <liuzhensong@loongson.cn>2022-08-10 09:26:25 +0800
commit31f6009538b75c22a4b3f99216846973283f0c6d (patch)
tree593e7e73578a9e614611adb395193ddc1d590d7b /bfd/coffcode.h
parent4c3cb23cc00025fe7105254203ec58679051cf94 (diff)
downloadbinutils-gdb-31f6009538b75c22a4b3f99216846973283f0c6d.tar.gz
bfd: Add support for LoongArch64 EFI (efi-*-loongarch64).
This adds support for efi-loongarch64 by virtue of adding a new PEI target pei-loongarch64. 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 loongarch64 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. We should't limit addresses to 32-bits for 64-bit vma, otherwise there will be "RVA truncated" error when using objcopy on loongarch64. With these changes the resulting file is recognized as an efi image. Any magic number is based on the Microsoft PE specification [1]. The test results are as follows: $ make check-binutils RUNTESTFLAGS='loongarch64.exp' PASS: Check if efi app format is recognized $ objdump -h -f tmpdir/loongarch64copy.o tmpdir/loongarch64copy.o: file format pei-loongarch64 architecture: Loongarch64, flags 0x00000132: EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED start address 0x0000000000000000 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000003c 00000000200000b0 00000000200000b0 00000200 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd: * .gitignore (pe-loongarch64igen.c): New. * Makefile.am (pei-loongarch64.lo, pe-loongarch64igen.lo, pei-loongarch64.c, pe-loongarch64igen.c): Add support. * Makefile.in: Likewise. * bfd.c (bfd_get_sign_extend_vma): Add pei-loongarch64. * coff-loongarch64.c: New file. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags, coff_write_object_contents) Add loongarch64 (loongarch64_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_peLoongArch64_bfd_copy_private_bfd_data_common, _bfd_peLoongArch64_bfd_copy_private_section_data, _bfd_peLoongArch64_get_symbol_info, _bfd_peLoongArch64_only_swap_filehdr_out, _bfd_peLoongArch64_print_private_bfd_data_common, _bfd_peLoongArch64i_final_link_postscript, _bfd_peLoongArch64i_only_swap_filehdr_out, _bfd_peLoongArch64i_swap_aouthdr_in, _bfd_peLoongArch64i_swap_aouthdr_out, _bfd_peLoongArch64i_swap_aux_in, _bfd_peLoongArch64i_swap_aux_out, _bfd_peLoongArch64i_swap_lineno_in, _bfd_peLoongArch64i_swap_lineno_out, _bfd_peLoongArch64i_swap_scnhdr_out, _bfd_peLoongArch64i_swap_sym_in, _bfd_peLoongArch64i_swap_sym_out, _bfd_peLoongArch64i_swap_debugdir_in, _bfd_peLoongArch64i_swap_debugdir_out, _bfd_peLoongArch64i_write_codeview_record, _bfd_peLoongArch64i_slurp_codeview_record, _bfd_peLoongArch64_print_ce_compressed_pdata): New. * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out, _bfd_XXi_swap_scnhdr_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_peLoongArch64, * pei-loongarch64.c: New file. * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p): Support COFF_WITH_peLoongArch64. (jtab): Add dummy entry that traps. * targets.c (loongarch64_pei_vec): New. binutils * testsuite/binutils-all/loongarch64/loongarch64.exp: New file. * testsuite/binutils-all/loongarch64/pei-loongarch64.d: New test. * testsuite/binutils-all/loongarch64/pei-loongarch64.s: New test. include * coff/loongarch64.h: New file. * coff/pe.h (IMAGE_FILE_MACHINE_LOONGARCH64): New. Signed-off-by: Youling Tang <tangyouling@loongson.cn>
Diffstat (limited to 'bfd/coffcode.h')
-rw-r--r--bfd/coffcode.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 798b9f249b5..67aaf158ca1 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -2231,6 +2231,12 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
machine = internal_f->f_flags & F_AARCH64_ARCHITECTURE_MASK;
break;
#endif
+#ifdef LOONGARCH64MAGIC
+ case LOONGARCH64MAGIC:
+ arch = bfd_arch_loongarch;
+ machine = internal_f->f_flags & F_LOONGARCH64_ARCHITECTURE_MASK;
+ break;
+#endif
#ifdef Z80MAGIC
case Z80MAGIC:
arch = bfd_arch_z80;
@@ -2795,6 +2801,12 @@ coff_set_flags (bfd * abfd,
return true;
#endif
+#ifdef LOONGARCH64MAGIC
+ case bfd_arch_loongarch:
+ * magicp = LOONGARCH64MAGIC;
+ return true;
+#endif
+
#ifdef ARMMAGIC
case bfd_arch_arm:
#ifdef ARM_WINCE
@@ -3890,7 +3902,7 @@ coff_write_object_contents (bfd * abfd)
internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
#endif
-#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64)
+#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
#ifdef COFF_WITH_PE
internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
#else
@@ -3944,6 +3956,11 @@ coff_write_object_contents (bfd * abfd)
internal_a.magic = ZMAGIC;
#endif
+#if defined(LOONGARCH64)
+#define __A_MAGIC_SET__
+ internal_a.magic = ZMAGIC;
+#endif
+
#if defined MCORE_PE
#define __A_MAGIC_SET__
internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;