1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
2 Contributed by Loongson Ltd.
4 This file is part of GNU Binutils.
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; see the file COPYING3. If not,
18 see <http://www.gnu.org/licenses/>. */
20 #ifndef _ELF_LOONGARCH_H
21 #define _ELF_LOONGARCH_H
23 #include "elf/reloc-macros.h"
24 #include "libiberty.h"
26 START_RELOC_NUMBERS (elf_loongarch_reloc_type
)
27 /* Used by the dynamic linker. */
28 RELOC_NUMBER (R_LARCH_NONE
, 0)
29 RELOC_NUMBER (R_LARCH_32
, 1)
30 RELOC_NUMBER (R_LARCH_64
, 2)
31 RELOC_NUMBER (R_LARCH_RELATIVE
, 3)
32 RELOC_NUMBER (R_LARCH_COPY
, 4)
33 RELOC_NUMBER (R_LARCH_JUMP_SLOT
, 5)
34 RELOC_NUMBER (R_LARCH_TLS_DTPMOD32
, 6)
35 RELOC_NUMBER (R_LARCH_TLS_DTPMOD64
, 7)
36 RELOC_NUMBER (R_LARCH_TLS_DTPREL32
, 8)
37 RELOC_NUMBER (R_LARCH_TLS_DTPREL64
, 9)
38 RELOC_NUMBER (R_LARCH_TLS_TPREL32
, 10)
39 RELOC_NUMBER (R_LARCH_TLS_TPREL64
, 11)
40 RELOC_NUMBER (R_LARCH_IRELATIVE
, 12)
41 RELOC_NUMBER (R_LARCH_TLS_DESC32
, 13)
42 RELOC_NUMBER (R_LARCH_TLS_DESC64
, 14)
43 /* Reserved for future relocs that the dynamic linker must understand. */
45 /* Used by the static linker for relocating .text. */
46 RELOC_NUMBER (R_LARCH_MARK_LA
, 20)
47 RELOC_NUMBER (R_LARCH_MARK_PCREL
, 21)
49 RELOC_NUMBER (R_LARCH_SOP_PUSH_PCREL
, 22)
51 RELOC_NUMBER (R_LARCH_SOP_PUSH_ABSOLUTE
, 23)
53 RELOC_NUMBER (R_LARCH_SOP_PUSH_DUP
, 24)
54 RELOC_NUMBER (R_LARCH_SOP_PUSH_GPREL
, 25)
55 RELOC_NUMBER (R_LARCH_SOP_PUSH_TLS_TPREL
, 26)
56 RELOC_NUMBER (R_LARCH_SOP_PUSH_TLS_GOT
, 27)
57 RELOC_NUMBER (R_LARCH_SOP_PUSH_TLS_GD
, 28)
58 RELOC_NUMBER (R_LARCH_SOP_PUSH_PLT_PCREL
, 29)
60 RELOC_NUMBER (R_LARCH_SOP_ASSERT
, 30)
61 RELOC_NUMBER (R_LARCH_SOP_NOT
, 31)
62 RELOC_NUMBER (R_LARCH_SOP_SUB
, 32)
63 RELOC_NUMBER (R_LARCH_SOP_SL
, 33)
64 RELOC_NUMBER (R_LARCH_SOP_SR
, 34)
65 RELOC_NUMBER (R_LARCH_SOP_ADD
, 35)
66 RELOC_NUMBER (R_LARCH_SOP_AND
, 36)
67 RELOC_NUMBER (R_LARCH_SOP_IF_ELSE
, 37)
68 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_10_5
, 38)
69 RELOC_NUMBER (R_LARCH_SOP_POP_32_U_10_12
, 39)
70 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_10_12
, 40)
71 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_10_16
, 41)
72 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_10_16_S2
, 42)
73 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_5_20
, 43)
74 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_0_5_10_16_S2
, 44)
75 RELOC_NUMBER (R_LARCH_SOP_POP_32_S_0_10_10_16_S2
, 45)
76 RELOC_NUMBER (R_LARCH_SOP_POP_32_U
, 46)
78 /* Used by the static linker for relocating non .text. */
79 RELOC_NUMBER (R_LARCH_ADD8
, 47)
80 RELOC_NUMBER (R_LARCH_ADD16
, 48)
81 RELOC_NUMBER (R_LARCH_ADD24
, 49)
82 RELOC_NUMBER (R_LARCH_ADD32
, 50)
83 RELOC_NUMBER (R_LARCH_ADD64
, 51)
84 RELOC_NUMBER (R_LARCH_SUB8
, 52)
85 RELOC_NUMBER (R_LARCH_SUB16
, 53)
86 RELOC_NUMBER (R_LARCH_SUB24
, 54)
87 RELOC_NUMBER (R_LARCH_SUB32
, 55)
88 RELOC_NUMBER (R_LARCH_SUB64
, 56)
90 /* I don't know what it is. Existing in almost all other arch. */
91 RELOC_NUMBER (R_LARCH_GNU_VTINHERIT
, 57)
92 RELOC_NUMBER (R_LARCH_GNU_VTENTRY
, 58)
96 beq/bne/blt/bge/bltu/bgeu/jirl
98 RELOC_NUMBER (R_LARCH_B16
, 64)
102 RELOC_NUMBER (R_LARCH_B21
, 65)
105 %b26 (sym) or %plt (sym). */
106 RELOC_NUMBER (R_LARCH_B26
, 66)
111 RELOC_NUMBER (R_LARCH_ABS_HI20
, 67)
115 RELOC_NUMBER (R_LARCH_ABS_LO12
, 68)
119 %abs64_lo20 (sym). */
120 RELOC_NUMBER (R_LARCH_ABS64_LO20
, 69)
123 %abs64_hi12 (sym). */
124 RELOC_NUMBER (R_LARCH_ABS64_HI12
, 70)
129 RELOC_NUMBER (R_LARCH_PCALA_HI20
, 71)
133 RELOC_NUMBER (R_LARCH_PCALA_LO12
, 72)
137 RELOC_NUMBER (R_LARCH_PCALA64_LO20
, 73)
141 RELOC_NUMBER (R_LARCH_PCALA64_HI12
, 74)
145 %got_pc_hi20 (got). */
146 RELOC_NUMBER (R_LARCH_GOT_PC_HI20
, 75)
149 %got_pc_lo12 (got). */
150 RELOC_NUMBER (R_LARCH_GOT_PC_LO12
, 76)
153 %got_pc_lo12 (got). */
154 RELOC_NUMBER (R_LARCH_GOT64_PC_LO20
, 77)
157 %got64_pc_hi12 (got). */
158 RELOC_NUMBER (R_LARCH_GOT64_PC_HI12
, 78)
162 RELOC_NUMBER (R_LARCH_GOT_HI20
, 79)
166 RELOC_NUMBER (R_LARCH_GOT_LO12
, 80)
169 %got64_lo20 (got). */
170 RELOC_NUMBER (R_LARCH_GOT64_LO20
, 81)
173 %got64_hi12 (got). */
174 RELOC_NUMBER (R_LARCH_GOT64_HI12
, 82)
179 RELOC_NUMBER (R_LARCH_TLS_LE_HI20
, 83)
183 RELOC_NUMBER (R_LARCH_TLS_LE_LO12
, 84)
187 RELOC_NUMBER (R_LARCH_TLS_LE64_LO20
, 85)
191 RELOC_NUMBER (R_LARCH_TLS_LE64_HI12
, 86)
195 %ie_pc_hi20 (sym). */
196 RELOC_NUMBER (R_LARCH_TLS_IE_PC_HI20
, 87)
197 RELOC_NUMBER (R_LARCH_TLS_IE_PC_LO12
, 88)
198 RELOC_NUMBER (R_LARCH_TLS_IE64_PC_LO20
, 89)
199 RELOC_NUMBER (R_LARCH_TLS_IE64_PC_HI12
, 90)
201 /* TLS-IE: 32/64: ABS
204 RELOC_NUMBER (R_LARCH_TLS_IE_HI20
, 91)
205 RELOC_NUMBER (R_LARCH_TLS_IE_LO12
, 92)
206 RELOC_NUMBER (R_LARCH_TLS_IE64_LO20
, 93)
207 RELOC_NUMBER (R_LARCH_TLS_IE64_HI12
, 94)
211 %ld_pc_hi20 (sym). */
212 RELOC_NUMBER (R_LARCH_TLS_LD_PC_HI20
, 95)
213 /* TLS-LD: 32/64: ABS
216 RELOC_NUMBER (R_LARCH_TLS_LD_HI20
, 96)
220 %gd_pc_hi20 (sym). */
221 RELOC_NUMBER (R_LARCH_TLS_GD_PC_HI20
, 97)
222 /* TLS-GD: 32/64: ABS
225 RELOC_NUMBER (R_LARCH_TLS_GD_HI20
, 98)
227 /* For eh_frame and debug info. */
228 RELOC_NUMBER (R_LARCH_32_PCREL
, 99)
231 RELOC_NUMBER (R_LARCH_RELAX
, 100)
234 RELOC_NUMBER (R_LARCH_DELETE
, 101)
237 RELOC_NUMBER (R_LARCH_ALIGN
, 102)
240 RELOC_NUMBER (R_LARCH_PCREL20_S2
, 103)
243 RELOC_NUMBER (R_LARCH_CFA
, 104)
245 /* DW_CFA_advance_loc. */
246 RELOC_NUMBER (R_LARCH_ADD6
, 105)
247 RELOC_NUMBER (R_LARCH_SUB6
, 106)
249 /* unsigned leb128. */
250 RELOC_NUMBER (R_LARCH_ADD_ULEB128
, 107)
251 RELOC_NUMBER (R_LARCH_SUB_ULEB128
, 108)
253 RELOC_NUMBER (R_LARCH_64_PCREL
, 109)
255 RELOC_NUMBER (R_LARCH_CALL36
, 110)
257 /* TLS_DESC PCREL. */
258 RELOC_NUMBER (R_LARCH_TLS_DESC_PC_HI20
, 111)
259 RELOC_NUMBER (R_LARCH_TLS_DESC_PC_LO12
, 112)
261 /* TLS_DESC LARGE PCREL. */
262 RELOC_NUMBER (R_LARCH_TLS_DESC64_PC_LO20
, 113)
263 RELOC_NUMBER (R_LARCH_TLS_DESC64_PC_HI12
, 114)
266 RELOC_NUMBER (R_LARCH_TLS_DESC_HI20
, 115)
267 RELOC_NUMBER (R_LARCH_TLS_DESC_LO12
, 116)
269 /* TLSDESC LARGE ABS. */
270 RELOC_NUMBER (R_LARCH_TLS_DESC64_LO20
, 117)
271 RELOC_NUMBER (R_LARCH_TLS_DESC64_HI12
, 118)
273 RELOC_NUMBER (R_LARCH_TLS_DESC_LD
, 119)
274 RELOC_NUMBER (R_LARCH_TLS_DESC_CALL
, 120)
277 lu12i.w rd,%le_hi20_r (sym). */
278 RELOC_NUMBER (R_LARCH_TLS_LE_HI20_R
, 121)
281 add.d rd,rj,rk,%le_add_r (sym). */
282 RELOC_NUMBER (R_LARCH_TLS_LE_ADD_R
, 122)
285 st.w/addi.w/ld.w rd,rj,%le_lo12_r (sym). */
286 RELOC_NUMBER (R_LARCH_TLS_LE_LO12_R
, 123)
288 RELOC_NUMBER (R_LARCH_TLS_LD_PCREL20_S2
, 124)
289 RELOC_NUMBER (R_LARCH_TLS_GD_PCREL20_S2
, 125)
290 RELOC_NUMBER (R_LARCH_TLS_DESC_PCREL20_S2
, 126)
292 END_RELOC_NUMBERS (R_LARCH_count
)
294 /* Processor specific flags for the ELF header e_flags field. */
295 /* Base ABI modifier, 3bits. */
296 #define EF_LOONGARCH_ABI_SOFT_FLOAT 0x1
297 #define EF_LOONGARCH_ABI_SINGLE_FLOAT 0x2
298 #define EF_LOONGARCH_ABI_DOUBLE_FLOAT 0x3
299 #define EF_LOONGARCH_ABI_MODIFIER_MASK 0x7
301 #define EF_LOONGARCH_OBJABI_V1 0x40
302 #define EF_LOONGARCH_OBJABI_MASK 0xC0
304 #define EF_LOONGARCH_ABI_MASK \
305 (EF_LOONGARCH_OBJABI_MASK | EF_LOONGARCH_ABI_MODIFIER_MASK)
307 #define EF_LOONGARCH_ABI_MODIFIER(abi) \
308 (EF_LOONGARCH_ABI_MODIFIER_MASK & (abi))
309 #define EF_LOONGARCH_OBJABI(abi) \
310 (EF_LOONGARCH_OBJABI_MASK & (abi))
312 #define EF_LOONGARCH_ABI(abi) ((abi) & EF_LOONGARCH_ABI_MASK)
314 #define EF_LOONGARCH_IS_SOFT_FLOAT(abi) \
315 (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_SOFT_FLOAT)
316 #define EF_LOONGARCH_IS_SINGLE_FLOAT(abi) \
317 (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_SINGLE_FLOAT)
318 #define EF_LOONGARCH_IS_DOUBLE_FLOAT(abi) \
319 (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_DOUBLE_FLOAT)
321 #define EF_LOONGARCH_IS_OBJ_V0(abi) (!EF_LOONGARCH_OBJABI (abi))
322 #define EF_LOONGARCH_IS_OBJ_V1(abi) \
323 (EF_LOONGARCH_OBJABI (abi) == EF_LOONGARCH_OBJABI_V1)
325 #endif /* _ELF_LOONGARCH_H */