xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/coff-aarch64.c (revision c42dbd0ed2e61fe6eda8590caa852ccf34719964)
1 /* BFD back-end for AArch64 COFF files.
2    Copyright (C) 2021-2022 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 
22 #ifndef COFF_WITH_peAArch64
23 #define COFF_WITH_peAArch64
24 #endif
25 
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.  */
29 #ifndef PEI_HEADERS
30 #include "sysdep.h"
31 #include "bfd.h"
32 #include "libbfd.h"
33 #include "coff/aarch64.h"
34 #include "coff/internal.h"
35 #include "coff/pe.h"
36 #include "libcoff.h"
37 #include "libiberty.h"
38 #endif
39 
40 #include "libcoff.h"
41 
42 /* The page size is a guess based on ELF.  */
43 
44 #define COFF_PAGE_SIZE 0x1000
45 
46 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1.  */
47 #define OCTETS_PER_BYTE(ABFD, SEC) 1
48 
49 #ifndef PCRELOFFSET
50 #define PCRELOFFSET true
51 #endif
52 
53 /* Currently we don't handle any relocations.  */
54 static reloc_howto_type pe_aarch64_std_reloc_howto[] =
55   {
56 
57   };
58 
59 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER  2
60 #define COFF_PAGE_SIZE			      0x1000
61 
62 #ifndef NUM_ELEM
63 #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
64 #endif
65 
66 #define NUM_RELOCS NUM_ELEM (pe_aarch64_std_reloc_howto)
67 
68 #define RTYPE2HOWTO(cache_ptr, dst)             \
69   (cache_ptr)->howto = NULL
70 
71 #ifndef bfd_pe_print_pdata
72 #define bfd_pe_print_pdata      NULL
73 #endif
74 
75 /* Return TRUE if this relocation should
76    appear in the output .reloc section.  */
77 
78 static bool
in_reloc_p(bfd * abfd ATTRIBUTE_UNUSED,reloc_howto_type * howto)79 in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
80             reloc_howto_type * howto)
81 {
82   return !howto->pc_relative;
83 }
84 
85 #include "coffcode.h"
86 
87 /* Target vectors.  */
88 const bfd_target
89 #ifdef TARGET_SYM
90   TARGET_SYM =
91 #else
92   aarch64_pei_vec =
93 #endif
94 {
95 #ifdef TARGET_NAME
96   TARGET_NAME,
97 #else
98  "pei-aarch64-little",			/* Name.  */
99 #endif
100   bfd_target_coff_flavour,
101   BFD_ENDIAN_LITTLE,		/* Data byte order is little.  */
102   BFD_ENDIAN_LITTLE,		/* Header byte order is little.  */
103 
104   (HAS_RELOC | EXEC_P		/* Object flags.  */
105    | HAS_LINENO | HAS_DEBUG
106    | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS),
107 
108   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* Section flags.  */
109 #if defined(COFF_WITH_PE)
110    | SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_READONLY | SEC_DEBUGGING
111 #endif
112    | SEC_CODE | SEC_DATA | SEC_EXCLUDE ),
113 
114 #ifdef TARGET_UNDERSCORE
115   TARGET_UNDERSCORE,		/* Leading underscore.  */
116 #else
117   0,				/* Leading underscore.  */
118 #endif
119   '/',				/* Ar_pad_char.  */
120   15,				/* Ar_max_namelen.  */
121   0,				/* match priority.  */
122   TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
123 
124      /* Data 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, /* Data.  */
128      /* Header conversion functions.  */
129      bfd_getl64, bfd_getl_signed_64, bfd_putl64,
130      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
131      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* Hdrs.  */
132 
133   /* Note that we allow an object file to be treated as a core file as well.  */
134   {				/* bfd_check_format.  */
135     _bfd_dummy_target,
136     coff_object_p,
137     bfd_generic_archive_p,
138     coff_object_p
139   },
140   {				/* bfd_set_format.  */
141     _bfd_bool_bfd_false_error,
142     coff_mkobject,
143     _bfd_generic_mkarchive,
144     _bfd_bool_bfd_false_error
145   },
146   {				/* bfd_write_contents.  */
147     _bfd_bool_bfd_false_error,
148     coff_write_object_contents,
149     _bfd_write_archive_contents,
150     _bfd_bool_bfd_false_error
151   },
152 
153   BFD_JUMP_TABLE_GENERIC (coff),
154   BFD_JUMP_TABLE_COPY (coff),
155   BFD_JUMP_TABLE_CORE (_bfd_nocore),
156   BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
157   BFD_JUMP_TABLE_SYMBOLS (coff),
158   BFD_JUMP_TABLE_RELOCS (coff),
159   BFD_JUMP_TABLE_WRITE (coff),
160   BFD_JUMP_TABLE_LINK (coff),
161   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
162 
163   NULL,
164 
165   COFF_SWAP_TABLE
166 };
167