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