/src/binutils-gdb/bfd/coff-loongarch64.c
Line | Count | Source |
1 | | /* BFD back-end for LoongArch64 COFF files. |
2 | | Copyright (C) 2022-2026 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 | | #ifndef COFF_WITH_PE |
22 | | #error non-PE COFF unsupported |
23 | | #endif |
24 | | |
25 | | #include "sysdep.h" |
26 | | #include "bfd.h" |
27 | | #include "libbfd.h" |
28 | | #include "coff/loongarch64.h" |
29 | | #include "coff/internal.h" |
30 | | #include "coff/pe.h" |
31 | | #include "libcoff.h" |
32 | | #include "libiberty.h" |
33 | | |
34 | | /* The page size is a guess based on ELF. */ |
35 | | |
36 | 181 | #define COFF_PAGE_SIZE 0x4000 |
37 | | |
38 | | /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */ |
39 | | #define OCTETS_PER_BYTE(ABFD, SEC) 1 |
40 | | |
41 | | #ifndef PCRELOFFSET |
42 | | #define PCRELOFFSET true |
43 | | #endif |
44 | | |
45 | | /* Currently we don't handle any relocations. */ |
46 | | static reloc_howto_type pe_loongarch64_std_reloc_howto[] = |
47 | | { |
48 | | |
49 | | }; |
50 | | |
51 | 93.3k | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
52 | | |
53 | | #ifndef NUM_ELEM |
54 | | #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0])) |
55 | | #endif |
56 | | |
57 | | #define NUM_RELOCS NUM_ELEM (pe_loongarch64_std_reloc_howto) |
58 | | |
59 | | #define RTYPE2HOWTO(cache_ptr, dst) \ |
60 | 0 | (cache_ptr)->howto = NULL |
61 | | |
62 | | #ifndef bfd_pe_print_pdata |
63 | | #define bfd_pe_print_pdata NULL |
64 | | #endif |
65 | | |
66 | | /* Handle include/coff/loongarch64.h external_reloc. */ |
67 | 2.40k | #define SWAP_IN_RELOC_OFFSET H_GET_32 |
68 | 17 | #define SWAP_OUT_RELOC_OFFSET H_PUT_32 |
69 | | |
70 | | /* Return TRUE if this relocation should |
71 | | appear in the output .reloc section. */ |
72 | | |
73 | | static bool |
74 | | in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, |
75 | | reloc_howto_type * howto) |
76 | 0 | { |
77 | 0 | return !howto->pc_relative; |
78 | 0 | } |
79 | | |
80 | | #include "coffcode.h" |
81 | | |
82 | | /* Target vectors. */ |
83 | | const bfd_target |
84 | | #ifdef TARGET_SYM |
85 | | TARGET_SYM = |
86 | | #else |
87 | | loongarch64_pei_vec = |
88 | | #endif |
89 | | { |
90 | | #ifdef TARGET_NAME |
91 | | TARGET_NAME, |
92 | | #else |
93 | | "pei-loongarch64", /* Name. */ |
94 | | #endif |
95 | | bfd_target_coff_flavour, |
96 | | BFD_ENDIAN_LITTLE, /* Data byte order is little. */ |
97 | | BFD_ENDIAN_LITTLE, /* Header byte order is little. */ |
98 | | |
99 | | (HAS_RELOC | EXEC_P /* Object flags. */ |
100 | | | HAS_LINENO | HAS_DEBUG |
101 | | | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS), |
102 | | |
103 | | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags. */ |
104 | | #if defined(COFF_WITH_PE) |
105 | | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING |
106 | | #endif |
107 | | | SEC_CODE | SEC_DATA | SEC_EXCLUDE ), |
108 | | |
109 | | #ifdef TARGET_UNDERSCORE |
110 | | TARGET_UNDERSCORE, /* Leading underscore. */ |
111 | | #else |
112 | | 0, /* Leading underscore. */ |
113 | | #endif |
114 | | '/', /* Ar_pad_char. */ |
115 | | 15, /* Ar_max_namelen. */ |
116 | | 0, /* match priority. */ |
117 | | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
118 | | TARGET_MERGE_SECTIONS, |
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 | | }; |