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