1 1.1 christos /* BFD back-end for RISC-V 64-bit COFF files. 2 1.1 christos Copyright (C) 2023-2024 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 christos #include "sysdep.h" 22 1.1 christos #include "bfd.h" 23 1.1 christos #include "libbfd.h" 24 1.1 christos #include "coff/riscv64.h" 25 1.1 christos #include "coff/internal.h" 26 1.1 christos #include "coff/pe.h" 27 1.1 christos #include "libcoff.h" 28 1.1 christos #include "libiberty.h" 29 1.1 christos 30 1.1 christos #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 31 1.1 christos 32 1.1 christos #ifndef bfd_pe_print_pdata 33 1.1 christos #define bfd_pe_print_pdata NULL 34 1.1 christos #endif 35 1.1 christos 36 1.1 christos #define RTYPE2HOWTO(cache_ptr, dst) \ 37 1.1 christos (cache_ptr)->howto = NULL 38 1.1 christos 39 1.1 christos /* Return TRUE if this relocation should 40 1.1 christos appear in the output .reloc section. */ 41 1.1 christos 42 1.1 christos static bool 43 1.1 christos in_reloc_p (bfd *abfd ATTRIBUTE_UNUSED, 44 1.1 christos reloc_howto_type *howto) 45 1.1 christos { 46 1.1 christos return !howto->pc_relative; 47 1.1 christos } 48 1.1 christos 49 1.1 christos #include "coffcode.h" 50 1.1 christos 51 1.1 christos /* Target vectors. */ 52 1.1 christos const bfd_target 53 1.1 christos #ifdef TARGET_SYM 54 1.1 christos TARGET_SYM = 55 1.1 christos #else 56 1.1 christos riscv64_coff_vec = 57 1.1 christos #endif 58 1.1 christos { 59 1.1 christos #ifdef TARGET_NAME 60 1.1 christos TARGET_NAME, 61 1.1 christos #else 62 1.1 christos "coff-riscv64-little", /* Name. */ 63 1.1 christos #endif 64 1.1 christos bfd_target_coff_flavour, 65 1.1 christos BFD_ENDIAN_LITTLE, /* Data byte order is little. */ 66 1.1 christos BFD_ENDIAN_LITTLE, /* Header byte order is little. */ 67 1.1 christos 68 1.1 christos (HAS_RELOC | EXEC_P /* Object flags. */ 69 1.1 christos | HAS_LINENO | HAS_DEBUG 70 1.1 christos | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), 71 1.1 christos 72 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ 73 1.1 christos #if defined(COFF_WITH_PE) 74 1.1 christos | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING 75 1.1 christos #endif 76 1.1 christos | SEC_CODE | SEC_DATA | SEC_EXCLUDE ), 77 1.1 christos 78 1.1 christos #ifdef TARGET_UNDERSCORE 79 1.1 christos TARGET_UNDERSCORE, /* Leading underscore. */ 80 1.1 christos #else 81 1.1 christos 0, /* Leading underscore. */ 82 1.1 christos #endif 83 1.1 christos '/', /* Ar_pad_char. */ 84 1.1 christos 15, /* Ar_max_namelen. */ 85 1.1 christos 0, /* match priority. */ 86 1.1 christos TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ 87 1.1 christos 88 1.1 christos /* Data conversion functions. */ 89 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 90 1.1 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 91 1.1 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Data. */ 92 1.1 christos /* Header conversion functions. */ 93 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64, 94 1.1 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32, 95 1.1 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs. */ 96 1.1 christos 97 1.1 christos /* Note that we allow an object file to be treated as a core file as well. */ 98 1.1 christos { /* bfd_check_format. */ 99 1.1 christos _bfd_dummy_target, 100 1.1 christos coff_object_p, 101 1.1 christos bfd_generic_archive_p, 102 1.1 christos coff_object_p 103 1.1 christos }, 104 1.1 christos { /* bfd_set_format. */ 105 1.1 christos _bfd_bool_bfd_false_error, 106 1.1 christos coff_mkobject, 107 1.1 christos _bfd_generic_mkarchive, 108 1.1 christos _bfd_bool_bfd_false_error 109 1.1 christos }, 110 1.1 christos { /* bfd_write_contents. */ 111 1.1 christos _bfd_bool_bfd_false_error, 112 1.1 christos coff_write_object_contents, 113 1.1 christos _bfd_write_archive_contents, 114 1.1 christos _bfd_bool_bfd_false_error 115 1.1 christos }, 116 1.1 christos 117 1.1 christos BFD_JUMP_TABLE_GENERIC (coff), 118 1.1 christos BFD_JUMP_TABLE_COPY (coff), 119 1.1 christos BFD_JUMP_TABLE_CORE (_bfd_nocore), 120 1.1 christos BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), 121 1.1 christos BFD_JUMP_TABLE_SYMBOLS (coff), 122 1.1 christos BFD_JUMP_TABLE_RELOCS (coff), 123 1.1 christos BFD_JUMP_TABLE_WRITE (coff), 124 1.1 christos BFD_JUMP_TABLE_LINK (coff), 125 1.1 christos BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), 126 1.1 christos 127 1.1 christos NULL, 128 1.1 christos 129 1.1 christos COFF_SWAP_TABLE 130 1.1 christos }; 131