175fd0b74Schristos // powerpc.h -- ELF definitions specific to EM_PPC and EM_PPC64 -*- C++ -*-
275fd0b74Schristos
3*e992f068Schristos // Copyright (C) 2008-2022 Free Software Foundation, Inc.
475fd0b74Schristos // Written by David S. Miller <davem@davemloft.net>.
575fd0b74Schristos
675fd0b74Schristos // This file is part of elfcpp.
775fd0b74Schristos
875fd0b74Schristos // This program is free software; you can redistribute it and/or
975fd0b74Schristos // modify it under the terms of the GNU Library General Public License
1075fd0b74Schristos // as published by the Free Software Foundation; either version 2, or
1175fd0b74Schristos // (at your option) any later version.
1275fd0b74Schristos
1375fd0b74Schristos // In addition to the permissions in the GNU Library General Public
1475fd0b74Schristos // License, the Free Software Foundation gives you unlimited
1575fd0b74Schristos // permission to link the compiled version of this file into
1675fd0b74Schristos // combinations with other programs, and to distribute those
1775fd0b74Schristos // combinations without any restriction coming from the use of this
1875fd0b74Schristos // file. (The Library Public License restrictions do apply in other
1975fd0b74Schristos // respects; for example, they cover modification of the file, and
2075fd0b74Schristos /// distribution when not linked into a combined executable.)
2175fd0b74Schristos
2275fd0b74Schristos // This program is distributed in the hope that it will be useful, but
2375fd0b74Schristos // WITHOUT ANY WARRANTY; without even the implied warranty of
2475fd0b74Schristos // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2575fd0b74Schristos // Library General Public License for more details.
2675fd0b74Schristos
2775fd0b74Schristos // You should have received a copy of the GNU Library General Public
2875fd0b74Schristos // License along with this program; if not, write to the Free Software
2975fd0b74Schristos // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
3075fd0b74Schristos // 02110-1301, USA.
3175fd0b74Schristos
3275fd0b74Schristos #ifndef ELFCPP_POWERPC_H
3375fd0b74Schristos #define ELFCPP_POWERPC_H
3475fd0b74Schristos
3575fd0b74Schristos namespace elfcpp
3675fd0b74Schristos {
3775fd0b74Schristos
3875fd0b74Schristos // The relocation numbers for 32-bit and 64-bit powerpc are nearly
3975fd0b74Schristos // identical. Therefore I've adopted the convention of using
4075fd0b74Schristos // R_POWERPC_foo for values which are the same in R_PPC_* and R_PPC64_*.
4175fd0b74Schristos // For relocations which are specific to the word size I will use
4275fd0b74Schristos // R_PPC_foo or R_PPC64_foo.
4375fd0b74Schristos enum
4475fd0b74Schristos {
4575fd0b74Schristos R_POWERPC_NONE = 0,
4675fd0b74Schristos R_POWERPC_ADDR32 = 1,
4775fd0b74Schristos R_POWERPC_ADDR24 = 2,
4875fd0b74Schristos R_POWERPC_ADDR16 = 3,
4975fd0b74Schristos R_POWERPC_ADDR16_LO = 4,
5075fd0b74Schristos R_POWERPC_ADDR16_HI = 5,
5175fd0b74Schristos R_POWERPC_ADDR16_HA = 6,
5275fd0b74Schristos R_POWERPC_ADDR14 = 7,
5375fd0b74Schristos R_POWERPC_ADDR14_BRTAKEN = 8,
5475fd0b74Schristos R_POWERPC_ADDR14_BRNTAKEN = 9,
5575fd0b74Schristos R_POWERPC_REL24 = 10,
5675fd0b74Schristos R_POWERPC_REL14 = 11,
5775fd0b74Schristos R_POWERPC_REL14_BRTAKEN = 12,
5875fd0b74Schristos R_POWERPC_REL14_BRNTAKEN = 13,
5975fd0b74Schristos R_POWERPC_GOT16 = 14,
6075fd0b74Schristos R_POWERPC_GOT16_LO = 15,
6175fd0b74Schristos R_POWERPC_GOT16_HI = 16,
6275fd0b74Schristos R_POWERPC_GOT16_HA = 17,
6375fd0b74Schristos R_PPC_PLTREL24 = 18,
6475fd0b74Schristos R_POWERPC_COPY = 19,
6575fd0b74Schristos R_POWERPC_GLOB_DAT = 20,
6675fd0b74Schristos R_POWERPC_JMP_SLOT = 21,
6775fd0b74Schristos R_POWERPC_RELATIVE = 22,
6875fd0b74Schristos R_PPC_LOCAL24PC = 23,
6975fd0b74Schristos R_POWERPC_UADDR32 = 24,
7075fd0b74Schristos R_POWERPC_UADDR16 = 25,
7175fd0b74Schristos R_POWERPC_REL32 = 26,
7275fd0b74Schristos R_POWERPC_PLT32 = 27,
7375fd0b74Schristos R_POWERPC_PLTREL32 = 28,
7475fd0b74Schristos R_POWERPC_PLT16_LO = 29,
7575fd0b74Schristos R_POWERPC_PLT16_HI = 30,
7675fd0b74Schristos R_POWERPC_PLT16_HA = 31,
7775fd0b74Schristos R_PPC_SDAREL16 = 32,
7875fd0b74Schristos R_POWERPC_SECTOFF = 33,
7975fd0b74Schristos R_POWERPC_SECTOFF_LO = 34,
8075fd0b74Schristos R_POWERPC_SECTOFF_HI = 35,
8175fd0b74Schristos R_POWERPC_SECTOFF_HA = 36,
8275fd0b74Schristos R_POWERPC_ADDR30 = 37,
8375fd0b74Schristos R_PPC64_ADDR64 = 38,
8475fd0b74Schristos R_PPC64_ADDR16_HIGHER = 39,
8575fd0b74Schristos R_PPC64_ADDR16_HIGHERA = 40,
8675fd0b74Schristos R_PPC64_ADDR16_HIGHEST = 41,
8775fd0b74Schristos R_PPC64_ADDR16_HIGHESTA = 42,
8875fd0b74Schristos R_PPC64_UADDR64 = 43,
8975fd0b74Schristos R_PPC64_REL64 = 44,
9075fd0b74Schristos R_PPC64_PLT64 = 45,
9175fd0b74Schristos R_PPC64_PLTREL64 = 46,
9275fd0b74Schristos R_PPC64_TOC16 = 47,
9375fd0b74Schristos R_PPC64_TOC16_LO = 48,
9475fd0b74Schristos R_PPC64_TOC16_HI = 49,
9575fd0b74Schristos R_PPC64_TOC16_HA = 50,
9675fd0b74Schristos R_PPC64_TOC = 51,
9775fd0b74Schristos R_PPC64_PLTGOT16 = 52,
9875fd0b74Schristos R_PPC64_PLTGOT16_LO = 53,
9975fd0b74Schristos R_PPC64_PLTGOT16_HI = 54,
10075fd0b74Schristos R_PPC64_PLTGOT16_HA = 55,
10175fd0b74Schristos R_PPC64_ADDR16_DS = 56,
10275fd0b74Schristos R_PPC64_ADDR16_LO_DS = 57,
10375fd0b74Schristos R_PPC64_GOT16_DS = 58,
10475fd0b74Schristos R_PPC64_GOT16_LO_DS = 59,
10575fd0b74Schristos R_PPC64_PLT16_LO_DS = 60,
10675fd0b74Schristos R_PPC64_SECTOFF_DS = 61,
10775fd0b74Schristos R_PPC64_SECTOFF_LO_DS = 62,
10875fd0b74Schristos R_PPC64_TOC16_DS = 63,
10975fd0b74Schristos R_PPC64_TOC16_LO_DS = 64,
11075fd0b74Schristos R_PPC64_PLTGOT16_DS = 65,
11175fd0b74Schristos R_PPC64_PLTGOT16_LO_DS = 66,
11275fd0b74Schristos R_POWERPC_TLS = 67,
11375fd0b74Schristos R_POWERPC_DTPMOD = 68,
11475fd0b74Schristos R_POWERPC_TPREL16 = 69,
11575fd0b74Schristos R_POWERPC_TPREL16_LO = 70,
11675fd0b74Schristos R_POWERPC_TPREL16_HI = 71,
11775fd0b74Schristos R_POWERPC_TPREL16_HA = 72,
11875fd0b74Schristos R_POWERPC_TPREL = 73,
11975fd0b74Schristos R_POWERPC_DTPREL16 = 74,
12075fd0b74Schristos R_POWERPC_DTPREL16_LO = 75,
12175fd0b74Schristos R_POWERPC_DTPREL16_HI = 76,
12275fd0b74Schristos R_POWERPC_DTPREL16_HA = 77,
12375fd0b74Schristos R_POWERPC_DTPREL = 78,
12475fd0b74Schristos R_POWERPC_GOT_TLSGD16 = 79,
12575fd0b74Schristos R_POWERPC_GOT_TLSGD16_LO = 80,
12675fd0b74Schristos R_POWERPC_GOT_TLSGD16_HI = 81,
12775fd0b74Schristos R_POWERPC_GOT_TLSGD16_HA = 82,
12875fd0b74Schristos R_POWERPC_GOT_TLSLD16 = 83,
12975fd0b74Schristos R_POWERPC_GOT_TLSLD16_LO = 84,
13075fd0b74Schristos R_POWERPC_GOT_TLSLD16_HI = 85,
13175fd0b74Schristos R_POWERPC_GOT_TLSLD16_HA = 86,
13275fd0b74Schristos R_POWERPC_GOT_TPREL16 = 87,
13375fd0b74Schristos R_POWERPC_GOT_TPREL16_LO = 88,
13475fd0b74Schristos R_POWERPC_GOT_TPREL16_HI = 89,
13575fd0b74Schristos R_POWERPC_GOT_TPREL16_HA = 90,
13675fd0b74Schristos R_POWERPC_GOT_DTPREL16 = 91,
13775fd0b74Schristos R_POWERPC_GOT_DTPREL16_LO = 92,
13875fd0b74Schristos R_POWERPC_GOT_DTPREL16_HI = 93,
13975fd0b74Schristos R_POWERPC_GOT_DTPREL16_HA = 94,
14075fd0b74Schristos R_PPC_TLSGD = 95,
14175fd0b74Schristos R_PPC64_TPREL16_DS = 95,
14275fd0b74Schristos R_PPC_TLSLD = 96,
14375fd0b74Schristos R_PPC64_TPREL16_LO_DS = 96,
14475fd0b74Schristos R_PPC64_TPREL16_HIGHER = 97,
14575fd0b74Schristos R_PPC64_TPREL16_HIGHERA = 98,
14675fd0b74Schristos R_PPC64_TPREL16_HIGHEST = 99,
14775fd0b74Schristos R_PPC64_TPREL16_HIGHESTA = 100,
14875fd0b74Schristos R_PPC_EMB_NADDR32 = 101,
14975fd0b74Schristos R_PPC64_DTPREL16_DS = 101,
15075fd0b74Schristos R_PPC_EMB_NADDR16 = 102,
15175fd0b74Schristos R_PPC64_DTPREL16_LO_DS = 102,
15275fd0b74Schristos R_PPC_EMB_NADDR16_LO = 103,
15375fd0b74Schristos R_PPC64_DTPREL16_HIGHER = 103,
15475fd0b74Schristos R_PPC_EMB_NADDR16_HI = 104,
15575fd0b74Schristos R_PPC64_DTPREL16_HIGHERA = 104,
15675fd0b74Schristos R_PPC_EMB_NADDR16_HA = 105,
15775fd0b74Schristos R_PPC64_DTPREL16_HIGHEST = 105,
15875fd0b74Schristos R_PPC_EMB_SDAI16 = 106,
15975fd0b74Schristos R_PPC64_DTPREL16_HIGHESTA = 106,
16075fd0b74Schristos R_PPC_EMB_SDA2I16 = 107,
16175fd0b74Schristos R_PPC64_TLSGD = 107,
16275fd0b74Schristos R_PPC_EMB_SDA2REL = 108,
16375fd0b74Schristos R_PPC64_TLSLD = 108,
16475fd0b74Schristos R_PPC_EMB_SDA21 = 109,
16575fd0b74Schristos R_PPC64_TOCSAVE = 109,
16675fd0b74Schristos R_PPC_EMB_MRKREF = 110,
16775fd0b74Schristos R_PPC64_ADDR16_HIGH = 110,
16875fd0b74Schristos R_PPC_EMB_RELSEC16 = 111,
16975fd0b74Schristos R_PPC64_ADDR16_HIGHA = 111,
17075fd0b74Schristos R_PPC_EMB_RELST_LO = 112,
17175fd0b74Schristos R_PPC64_TPREL16_HIGH = 112,
17275fd0b74Schristos R_PPC_EMB_RELST_HI = 113,
17375fd0b74Schristos R_PPC64_TPREL16_HIGHA = 113,
17475fd0b74Schristos R_PPC_EMB_RELST_HA = 114,
17575fd0b74Schristos R_PPC64_DTPREL16_HIGH = 114,
17675fd0b74Schristos R_PPC_EMB_BIT_FLD = 115,
17775fd0b74Schristos R_PPC64_DTPREL16_HIGHA = 115,
17875fd0b74Schristos R_PPC_EMB_RELSDA = 116,
17975fd0b74Schristos R_PPC64_REL24_NOTOC = 116,
18075fd0b74Schristos R_PPC64_ADDR64_LOCAL = 117,
18175fd0b74Schristos R_PPC64_ENTRY = 118,
182ede78133Schristos R_POWERPC_PLTSEQ = 119,
183ede78133Schristos R_POWERPC_PLTCALL = 120,
184012573ebSchristos R_PPC64_PLTSEQ_NOTOC = 121,
185012573ebSchristos R_PPC64_PLTCALL_NOTOC = 122,
186012573ebSchristos R_PPC64_PCREL_OPT = 123,
187*e992f068Schristos R_PPC64_REL24_P9NOTOC = 124,
188012573ebSchristos
189012573ebSchristos R_PPC64_D34 = 128,
190012573ebSchristos R_PPC64_D34_LO = 129,
191012573ebSchristos R_PPC64_D34_HI30 = 130,
192012573ebSchristos R_PPC64_D34_HA30 = 131,
193012573ebSchristos R_PPC64_PCREL34 = 132,
194012573ebSchristos R_PPC64_GOT_PCREL34 = 133,
195012573ebSchristos R_PPC64_PLT_PCREL34 = 134,
196012573ebSchristos R_PPC64_PLT_PCREL34_NOTOC = 135,
197012573ebSchristos R_PPC64_ADDR16_HIGHER34 = 136,
198012573ebSchristos R_PPC64_ADDR16_HIGHERA34 = 137,
199012573ebSchristos R_PPC64_ADDR16_HIGHEST34 = 138,
200012573ebSchristos R_PPC64_ADDR16_HIGHESTA34 = 139,
201012573ebSchristos R_PPC64_REL16_HIGHER34 = 140,
202012573ebSchristos R_PPC64_REL16_HIGHERA34 = 141,
203012573ebSchristos R_PPC64_REL16_HIGHEST34 = 142,
204012573ebSchristos R_PPC64_REL16_HIGHESTA34 = 143,
205012573ebSchristos R_PPC64_D28 = 144,
206012573ebSchristos R_PPC64_PCREL28 = 145,
207012573ebSchristos R_PPC64_TPREL34 = 146,
208012573ebSchristos R_PPC64_DTPREL34 = 147,
209*e992f068Schristos R_PPC64_GOT_TLSGD_PCREL34 = 148,
210*e992f068Schristos R_PPC64_GOT_TLSLD_PCREL34 = 149,
211*e992f068Schristos R_PPC64_GOT_TPREL_PCREL34 = 150,
212*e992f068Schristos R_PPC64_GOT_DTPREL_PCREL34 = 151,
21375fd0b74Schristos
21475fd0b74Schristos R_PPC_VLE_REL8 = 216,
21575fd0b74Schristos R_PPC_VLE_REL15 = 217,
21675fd0b74Schristos R_PPC_VLE_REL24 = 218,
21775fd0b74Schristos R_PPC_VLE_LO16A = 219,
21875fd0b74Schristos R_PPC_VLE_LO16D = 220,
21975fd0b74Schristos R_PPC_VLE_HI16A = 221,
22075fd0b74Schristos R_PPC_VLE_HI16D = 222,
22175fd0b74Schristos R_PPC_VLE_HA16A = 223,
22275fd0b74Schristos R_PPC_VLE_HA16D = 224,
22375fd0b74Schristos R_PPC_VLE_SDA21 = 225,
22475fd0b74Schristos R_PPC_VLE_SDA21_LO = 226,
22575fd0b74Schristos R_PPC_VLE_SDAREL_LO16A = 227,
22675fd0b74Schristos R_PPC_VLE_SDAREL_LO16D = 228,
22775fd0b74Schristos R_PPC_VLE_SDAREL_HI16A = 229,
22875fd0b74Schristos R_PPC_VLE_SDAREL_HI16D = 230,
22975fd0b74Schristos R_PPC_VLE_SDAREL_HA16A = 231,
23075fd0b74Schristos R_PPC_VLE_SDAREL_HA16D = 232,
23175fd0b74Schristos
232012573ebSchristos R_PPC64_REL16_HIGH = 240,
233012573ebSchristos R_PPC64_REL16_HIGHA = 241,
234012573ebSchristos R_PPC64_REL16_HIGHER = 242,
235012573ebSchristos R_PPC64_REL16_HIGHERA = 243,
236012573ebSchristos R_PPC64_REL16_HIGHEST = 244,
237012573ebSchristos R_PPC64_REL16_HIGHESTA = 245,
238012573ebSchristos
23975fd0b74Schristos R_POWERPC_REL16DX_HA = 246,
24075fd0b74Schristos R_PPC64_JMP_IREL = 247,
24175fd0b74Schristos R_POWERPC_IRELATIVE = 248,
24275fd0b74Schristos R_POWERPC_REL16 = 249,
24375fd0b74Schristos R_POWERPC_REL16_LO = 250,
24475fd0b74Schristos R_POWERPC_REL16_HI = 251,
24575fd0b74Schristos R_POWERPC_REL16_HA = 252,
24675fd0b74Schristos R_POWERPC_GNU_VTINHERIT = 253,
24775fd0b74Schristos R_POWERPC_GNU_VTENTRY = 254,
24875fd0b74Schristos R_PPC_TOC16 = 255,
24975fd0b74Schristos };
25075fd0b74Schristos
25175fd0b74Schristos // e_flags values defined for powerpc
25275fd0b74Schristos enum
25375fd0b74Schristos {
25475fd0b74Schristos EF_PPC_EMB = 0x80000000, // PowerPC embedded flag.
25575fd0b74Schristos EF_PPC_RELOCATABLE = 0x00010000, // PowerPC -mrelocatable flag. */
25675fd0b74Schristos EF_PPC_RELOCATABLE_LIB = 0x00008000, // PowerPC -mrelocatable-lib flag. */
25775fd0b74Schristos };
25875fd0b74Schristos
25975fd0b74Schristos // e_flags values defined for powerpc64
26075fd0b74Schristos enum
26175fd0b74Schristos {
26275fd0b74Schristos // ABI version
26375fd0b74Schristos // 1 for original function descriptor using ABI,
26475fd0b74Schristos // 2 for revised ABI without function descriptors,
26575fd0b74Schristos // 0 for unspecified or not using any features affected by the differences.
26675fd0b74Schristos EF_PPC64_ABI = 3
26775fd0b74Schristos };
26875fd0b74Schristos
269ede78133Schristos // Object attribute tags. 0-3 are generic.
270ede78133Schristos enum
271ede78133Schristos {
272ede78133Schristos // FP ABI, low 2 bits:
273ede78133Schristos // 1 for double precision hard-float,
274ede78133Schristos // 2 for soft-float,
275ede78133Schristos // 3 for single precision hard-float.
276ede78133Schristos // 0 for not tagged or not using any ABIs affected by the differences.
277ede78133Schristos // Next 2 bits:
278ede78133Schristos // 1 for ibm long double
279ede78133Schristos // 2 for 64-bit long double
280ede78133Schristos // 3 for IEEE long double.
281ede78133Schristos // 0 for not tagged or not using any ABIs affected by the differences.
282ede78133Schristos Tag_GNU_Power_ABI_FP = 4,
283ede78133Schristos
284ede78133Schristos // Value 1 for general purpose registers only, 2 for AltiVec
285ede78133Schristos // registers, 3 for SPE registers; 0 for not tagged or not using any
286ede78133Schristos // ABIs affected by the differences.
287ede78133Schristos Tag_GNU_Power_ABI_Vector = 8,
288ede78133Schristos
289ede78133Schristos // Value 1 for ABIs using r3/r4 for returning structures <= 8 bytes,
290ede78133Schristos // 2 for ABIs using memory; 0 for not tagged or not using any ABIs
291ede78133Schristos // affected by the differences.
292ede78133Schristos Tag_GNU_Power_ABI_Struct_Return = 12
293ede78133Schristos };
294ede78133Schristos
295ede78133Schristos // DT_PPC_OPT bits
296ede78133Schristos enum
297ede78133Schristos {
298ede78133Schristos PPC_OPT_TLS = 1
299ede78133Schristos };
300ede78133Schristos
301ede78133Schristos // DT_PPC64_OPT bits
302ede78133Schristos enum
303ede78133Schristos {
304ede78133Schristos PPC64_OPT_TLS = 1,
305ede78133Schristos PPC64_OPT_MULTI_TOC = 2,
306ede78133Schristos PPC64_OPT_LOCALENTRY = 4
307ede78133Schristos };
308ede78133Schristos
30975fd0b74Schristos enum
31075fd0b74Schristos {
31175fd0b74Schristos // The ELFv2 ABI uses three bits in the symbol st_other field of a
31275fd0b74Schristos // function definition to specify the number of instructions between a
31375fd0b74Schristos // function's global entry point and local entry point.
31475fd0b74Schristos // The global entry point is used when it is necessary to set up the
31575fd0b74Schristos // toc pointer (r2) for the function. Callers must enter the global
31675fd0b74Schristos // entry point with r12 set to the global entry point address. On
31775fd0b74Schristos // return from the function, r2 may have a different value to that
31875fd0b74Schristos // which it had on entry.
31975fd0b74Schristos // The local entry point is used when r2 is known to already be valid
32075fd0b74Schristos // for the function. There is no requirement on r12 when using the
32175fd0b74Schristos // local entry point, and on return r2 will contain the same value as
32275fd0b74Schristos // at entry.
32375fd0b74Schristos // A value of zero in these bits means that the function has a single
32475fd0b74Schristos // entry point with no requirement on r12 or r2, and that on return r2
32575fd0b74Schristos // will contain the same value as at entry.
32675fd0b74Schristos // Values of one and seven are reserved.
32775fd0b74Schristos
32875fd0b74Schristos STO_PPC64_LOCAL_BIT = 5,
32975fd0b74Schristos STO_PPC64_LOCAL_MASK = 0xE0
33075fd0b74Schristos };
33175fd0b74Schristos
33275fd0b74Schristos // 3 bit other field to bytes.
33375fd0b74Schristos static inline unsigned int
ppc64_decode_local_entry(unsigned int other)33475fd0b74Schristos ppc64_decode_local_entry(unsigned int other)
33575fd0b74Schristos {
33675fd0b74Schristos return ((1 << other) >> 2) << 2;
33775fd0b74Schristos }
33875fd0b74Schristos
33975fd0b74Schristos // bytes to field value.
34075fd0b74Schristos static inline unsigned int
ppc64_encode_local_entry(unsigned int val)34175fd0b74Schristos ppc64_encode_local_entry(unsigned int val)
34275fd0b74Schristos {
34375fd0b74Schristos return (val >= 4 * 4
34475fd0b74Schristos ? (val >= 8 * 4
34575fd0b74Schristos ? (val >= 16 * 4 ? 6 : 5)
34675fd0b74Schristos : 4)
34775fd0b74Schristos : (val >= 2 * 4
34875fd0b74Schristos ? 3
34975fd0b74Schristos : (val >= 1 * 4 ? 2 : 0)));
35075fd0b74Schristos }
35175fd0b74Schristos
35275fd0b74Schristos } // End namespace elfcpp.
35375fd0b74Schristos
35475fd0b74Schristos #endif // !defined(ELFCPP_POWERPC_H)
355