1 /* BFD back-end for LoongArch64 COFF files. 2 Copyright (C) 2022-2024 Free Software Foundation, Inc. 3 4 This file is part of BFD, the Binary File Descriptor library. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 22 #ifndef COFF_WITH_peLoongArch64 23 #define COFF_WITH_peLoongArch64 24 #endif 25 26 #include "sysdep.h" 27 #include "bfd.h" 28 #include "libbfd.h" 29 #include "coff/loongarch64.h" 30 #include "coff/internal.h" 31 #include "coff/pe.h" 32 #include "libcoff.h" 33 #include "libiberty.h" 34 35 /* The page size is a guess based on ELF. */ 36 37 #define COFF_PAGE_SIZE 0x4000 38 39 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */ 40 #define OCTETS_PER_BYTE(ABFD, SEC) 1 41 42 #ifndef PCRELOFFSET 43 #define PCRELOFFSET true 44 #endif 45 46 /* Currently we don't handle any relocations. */ 47 static reloc_howto_type pe_loongarch64_std_reloc_howto[] = 48 { 49 50 }; 51 52 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 53 54 #ifndef NUM_ELEM 55 #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0])) 56 #endif 57 58 #define NUM_RELOCS NUM_ELEM (pe_loongarch64_std_reloc_howto) 59 60 #define RTYPE2HOWTO(cache_ptr, dst) \ 61 (cache_ptr)->howto = NULL 62 63 #ifndef bfd_pe_print_pdata 64 #define bfd_pe_print_pdata NULL 65 #endif 66 67 /* Handle include/coff/loongarch64.h external_reloc. */ 68 #define SWAP_IN_RELOC_OFFSET H_GET_32 69 #define SWAP_OUT_RELOC_OFFSET H_PUT_32 70 71 /* Return TRUE if this relocation should 72 appear in the output .reloc section. */ 73 74 static bool 75 in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, 76 reloc_howto_type * howto) 77 { 78 return !howto->pc_relative; 79 } 80 81 #include "coffcode.h" 82 83 /* Target vectors. */ 84 const bfd_target 85 #ifdef TARGET_SYM 86 TARGET_SYM = 87 #else 88 loongarch64_pei_vec = 89 #endif 90 { 91 #ifdef TARGET_NAME 92 TARGET_NAME, 93 #else 94 "pei-loongarch64", /* Name. */ 95 #endif 96 bfd_target_coff_flavour, 97 BFD_ENDIAN_LITTLE, /* Data byte order is little. */ 98 BFD_ENDIAN_LITTLE, /* Header byte order is little. */ 99 100 (HAS_RELOC | EXEC_P /* Object flags. */ 101 | HAS_LINENO | HAS_DEBUG 102 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), 103 104 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ 105 #if defined(COFF_WITH_PE) 106 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING 107 #endif 108 | SEC_CODE | SEC_DATA | SEC_EXCLUDE ), 109 110 #ifdef TARGET_UNDERSCORE 111 TARGET_UNDERSCORE, /* Leading underscore. */ 112 #else 113 0, /* Leading underscore. */ 114 #endif 115 '/', /* Ar_pad_char. */ 116 15, /* Ar_max_namelen. */ 117 0, /* match priority. */ 118 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ 119 120 /* Data conversion functions. */ 121 bfd_getl64, bfd_getl_signed_64, bfd_putl64, 122 bfd_getl32, bfd_getl_signed_32, bfd_putl32, 123 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ 124 /* Header conversion functions. */ 125 bfd_getl64, bfd_getl_signed_64, bfd_putl64, 126 bfd_getl32, bfd_getl_signed_32, bfd_putl32, 127 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs. */ 128 129 /* Note that we allow an object file to be treated as a core file as well. */ 130 { /* bfd_check_format. */ 131 _bfd_dummy_target, 132 coff_object_p, 133 bfd_generic_archive_p, 134 coff_object_p 135 }, 136 { /* bfd_set_format. */ 137 _bfd_bool_bfd_false_error, 138 coff_mkobject, 139 _bfd_generic_mkarchive, 140 _bfd_bool_bfd_false_error 141 }, 142 { /* bfd_write_contents. */ 143 _bfd_bool_bfd_false_error, 144 coff_write_object_contents, 145 _bfd_write_archive_contents, 146 _bfd_bool_bfd_false_error 147 }, 148 149 BFD_JUMP_TABLE_GENERIC (coff), 150 BFD_JUMP_TABLE_COPY (coff), 151 BFD_JUMP_TABLE_CORE (_bfd_nocore), 152 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), 153 BFD_JUMP_TABLE_SYMBOLS (coff), 154 BFD_JUMP_TABLE_RELOCS (coff), 155 BFD_JUMP_TABLE_WRITE (coff), 156 BFD_JUMP_TABLE_LINK (coff), 157 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 158 159 NULL, 160 161 COFF_SWAP_TABLE 162 }; 163