1 /* BFD back-end for LoongArch64 COFF files.
2 Copyright (C) 2022 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
22 #ifndef COFF_WITH_peLoongArch64
23 #define COFF_WITH_peLoongArch64
26 /* Note we have to make sure not to include headers twice.
27 Not all headers are wrapped in #ifdef guards, so we define
28 PEI_HEADERS to prevent double including here. */
33 #include "coff/loongarch64.h"
34 #include "coff/internal.h"
37 #include "libiberty.h"
42 /* The page size is a guess based on ELF. */
44 #define COFF_PAGE_SIZE 0x4000
46 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
47 #define OCTETS_PER_BYTE(ABFD, SEC) 1
50 #define PCRELOFFSET true
53 /* Currently we don't handle any relocations. */
54 static reloc_howto_type pe_loongarch64_std_reloc_howto
[] =
59 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2
62 #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
65 #define NUM_RELOCS NUM_ELEM (pe_loongarch64_std_reloc_howto)
67 #define RTYPE2HOWTO(cache_ptr, dst) \
68 (cache_ptr)->howto = NULL
70 #ifndef bfd_pe_print_pdata
71 #define bfd_pe_print_pdata NULL
74 /* Return TRUE if this relocation should
75 appear in the output .reloc section. */
78 in_reloc_p (bfd
* abfd ATTRIBUTE_UNUSED
,
79 reloc_howto_type
* howto
)
81 return !howto
->pc_relative
;
97 "pei-loongarch64", /* Name. */
99 bfd_target_coff_flavour
,
100 BFD_ENDIAN_LITTLE
, /* Data byte order is little. */
101 BFD_ENDIAN_LITTLE
, /* Header byte order is little. */
103 (HAS_RELOC
| EXEC_P
/* Object flags. */
104 | HAS_LINENO
| HAS_DEBUG
105 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
| BFD_COMPRESS
| BFD_DECOMPRESS
),
107 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
/* Section flags. */
108 #if defined(COFF_WITH_PE)
109 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
| SEC_READONLY
| SEC_DEBUGGING
111 | SEC_CODE
| SEC_DATA
| SEC_EXCLUDE
),
113 #ifdef TARGET_UNDERSCORE
114 TARGET_UNDERSCORE
, /* Leading underscore. */
116 0, /* Leading underscore. */
118 '/', /* Ar_pad_char. */
119 15, /* Ar_max_namelen. */
120 0, /* match priority. */
121 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
123 /* Data conversion functions. */
124 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
125 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
126 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Data. */
127 /* Header conversion functions. */
128 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
129 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
130 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* Hdrs. */
132 /* Note that we allow an object file to be treated as a core file as well. */
133 { /* bfd_check_format. */
136 bfd_generic_archive_p
,
139 { /* bfd_set_format. */
140 _bfd_bool_bfd_false_error
,
142 _bfd_generic_mkarchive
,
143 _bfd_bool_bfd_false_error
145 { /* bfd_write_contents. */
146 _bfd_bool_bfd_false_error
,
147 coff_write_object_contents
,
148 _bfd_write_archive_contents
,
149 _bfd_bool_bfd_false_error
152 BFD_JUMP_TABLE_GENERIC (coff
),
153 BFD_JUMP_TABLE_COPY (coff
),
154 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
155 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
156 BFD_JUMP_TABLE_SYMBOLS (coff
),
157 BFD_JUMP_TABLE_RELOCS (coff
),
158 BFD_JUMP_TABLE_WRITE (coff
),
159 BFD_JUMP_TABLE_LINK (coff
),
160 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),