File: elf.h

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (602 lines) | stat: -rw-r--r-- 23,728 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
/*
 * Copyright (C) 2020-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/utilities/const_stringref.h"

#include <cstdint>
#include <stddef.h>

namespace NEO {

namespace Elf {

// Elf identifier class
enum ElfIdentifierClass : uint8_t {
    EI_CLASS_NONE = 0, // undefined
    EI_CLASS_32 = 1,   // 32-bit elf file
    EI_CLASS_64 = 2,   // 64-bit elf file
};

// Elf identifier data
enum ElfIdentifierData : uint8_t {
    EI_DATA_NONE = 0,          // undefined
    EI_DATA_LITTLE_ENDIAN = 1, // little-endian
    EI_DATA_BIG_ENDIAN = 2,    // big-endian
};

// Target machine
enum ElfMachine : uint16_t {
    EM_NONE = 0, // No specific instruction set
    EM_INTELGT = 205,
};

// Elf version
enum ElfVersion : uint8_t {
    EV_INVALID = 0, // undefined
    EV_CURRENT = 1, // current
};

// Elf type
enum ElfType : uint16_t {
    ET_NONE = 0,                       // undefined
    ET_REL = 1,                        // relocatable
    ET_EXEC = 2,                       // executable
    ET_DYN = 3,                        // shared object
    ET_CORE = 4,                       // core file
    ET_LOPROC = 0xff00,                // start of processor-specific type
    ET_OPENCL_RESERVED_START = 0xff01, // start of Intel OCL ElfTypeS
    ET_OPENCL_RESERVED_END = 0xff05,   // end of Intel OCL ElfTypeS
    ET_HIPROC = 0xffff                 // end of processor-specific types
};

// Section header type
enum SectionHeaderType : uint32_t {
    SHT_NULL = 0,                           // inactive section header
    SHT_PROGBITS = 1,                       // program data
    SHT_SYMTAB = 2,                         // symbol table
    SHT_STRTAB = 3,                         // string table
    SHT_RELA = 4,                           // relocation entries with add
    SHT_HASH = 5,                           // symbol hash table
    SHT_DYNAMIC = 6,                        // dynamic linking info
    SHT_NOTE = 7,                           // notes
    SHT_NOBITS = 8,                         // program "no data" space (bss)
    SHT_REL = 9,                            // relocation entries (without add)
    SHT_SHLIB = 10,                         // reserved
    SHT_DYNSYM = 11,                        // dynamic linker symbol table
    SHT_INIT_ARRAY = 14,                    // array of constructors
    SHT_FINI_ARRAY = 15,                    // array of destructors
    SHT_PREINIT_ARRAY = 16,                 // aaray of pre-constructors
    SHT_GROUP = 17,                         // section group
    SHT_SYMTAB_SHNDX = 18,                  // extended section indices
    SHT_NUM = 19,                           // number of defined types
    SHT_LOOS = 0x60000000,                  // start of os-specifc
    SHT_OPENCL_RESERVED_START = 0xff000000, // start of Intel OCL SHT_TYPES
    SHT_OPENCL_RESERVED_END = 0xff00000c    // end of Intel OCL SHT_TYPES
};

enum SpecialSectionHeaderNumber : uint16_t {
    SHN_UNDEF = 0U, // undef section
};

enum SectionHeaderFlags : uint32_t {
    SHF_NONE = 0x0,            // no flags
    SHF_WRITE = 0x1,           // writeable data
    SHF_ALLOC = 0x2,           // occupies memory during execution
    SHF_EXECINSTR = 0x4,       // executable machine instructions
    SHF_MERGE = 0x10,          // data of section can be merged
    SHF_STRINGS = 0x20,        // data of section is null-terminated strings
    SHF_INFO_LINK = 0x40,      // section's sh_info is valid index
    SHF_LINK_ORDER = 0x80,     // has ordering requirements
    SHF_OS_NONCONFORM = 0x100, // requires os-specific processing
    SHF_GROUP = 0x200,         // section is part of section group
    SHF_TLS = 0x400,           // thread-local storage
    SHF_MASKOS = 0x0ff00000,   // operating-system-specific flags
    SHF_MASKPROC = 0xf0000000, // processor-specific flags
};

enum ProgramHeaderType {
    PT_NULL = 0x0,          // unused segment
    PT_LOAD = 0x1,          // loadable segment
    PT_DYNAMIC = 0x2,       // dynamic linking information
    PT_INTERP = 0x3,        // path name to invoke as an interpreter
    PT_NOTE = 0x4,          // auxiliary information
    PT_SHLIB = 0x5,         // reserved
    PT_PHDR = 0x6,          // location and of programe header table
    PT_TLS = 0x7,           // thread-local storage template
    PT_LOOS = 0x60000000,   // start os-specifc segments
    PT_HIOS = 0x6FFFFFFF,   // end of os-specific segments
    PT_LOPROC = 0x70000000, // start processor-specific segments
    PT_HIPROC = 0x7FFFFFFF  // end processor-specific segments
};

enum ProgramHeaderFlags : uint32_t {
    PF_NONE = 0x0,           // all access denied
    PF_X = 0x1,              // execute
    PF_W = 0x2,              // write
    PF_R = 0x4,              // read
    PF_MASKOS = 0x0ff00000,  // operating-system-specific flags
    PF_MASKPROC = 0xf0000000 // processor-specific flags

};

enum SymbolTableType : uint32_t {
    STT_NOTYPE = 0,
    STT_OBJECT = 1,
    STT_FUNC = 2,
    STT_SECTION = 3
};

enum SymbolTableBind : uint32_t {
    STB_LOCAL = 0,
    STB_GLOBAL = 1
};

inline constexpr const char elfMagic[4] = {0x7f, 'E', 'L', 'F'};

struct ElfFileHeaderIdentity {
    ElfFileHeaderIdentity(ElfIdentifierClass classBits)
        : eClass(classBits) {
    }
    char magic[4] = {elfMagic[0], elfMagic[1], elfMagic[2], elfMagic[3]}; // should match elfMagic
    uint8_t eClass = EI_CLASS_NONE;                                       // 32- or 64-bit format
    uint8_t data = EI_DATA_LITTLE_ENDIAN;                                 // endianness
    uint8_t version = EV_CURRENT;                                         // elf file version
    uint8_t osAbi = 0U;                                                   // target system
    uint8_t abiVersion = 0U;                                              // abi
    char padding[7] = {};                                                 // pad to 16 bytes
};
static_assert(sizeof(ElfFileHeaderIdentity) == 16, "");

template <int numBits>
struct ElfProgramHeaderTypes;

template <>
struct ElfProgramHeaderTypes<EI_CLASS_32> {
    using Type = uint32_t;
    using Flags = uint32_t;
    using Offset = uint32_t;
    using VAddr = uint32_t;
    using PAddr = uint32_t;
    using FileSz = uint32_t;
    using MemSz = uint32_t;
    using Align = uint32_t;
};

template <>
struct ElfProgramHeaderTypes<EI_CLASS_64> {
    using Type = uint32_t;
    using Flags = uint32_t;
    using Offset = uint64_t;
    using VAddr = uint64_t;
    using PAddr = uint64_t;
    using FileSz = uint64_t;
    using MemSz = uint64_t;
    using Align = uint64_t;
};

template <int numBits>
struct ElfProgramHeader;

template <>
struct ElfProgramHeader<EI_CLASS_32> {
    ElfProgramHeaderTypes<EI_CLASS_32>::Type type = PT_NULL;   // type of segment
    ElfProgramHeaderTypes<EI_CLASS_32>::Offset offset = 0U;    // absolute offset of segment data in file
    ElfProgramHeaderTypes<EI_CLASS_32>::VAddr vAddr = 0U;      // VA of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_32>::PAddr pAddr = 0U;      // PA of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_32>::FileSz fileSz = 0U;    // size of segment in file
    ElfProgramHeaderTypes<EI_CLASS_32>::MemSz memSz = 0U;      // size of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_32>::Flags flags = PF_NONE; // segment-dependent flags
    ElfProgramHeaderTypes<EI_CLASS_32>::Align align = 1U;      // alignment
};

template <>
struct ElfProgramHeader<EI_CLASS_64> {
    ElfProgramHeaderTypes<EI_CLASS_64>::Type type = PT_NULL;   // type of segment
    ElfProgramHeaderTypes<EI_CLASS_64>::Flags flags = PF_NONE; // segment-dependent flags
    ElfProgramHeaderTypes<EI_CLASS_64>::Offset offset = 0U;    // absolute offset of segment data in file
    ElfProgramHeaderTypes<EI_CLASS_64>::VAddr vAddr = 0U;      // VA of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_64>::PAddr pAddr = 0U;      // PA of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_64>::FileSz fileSz = 0U;    // size of segment in file
    ElfProgramHeaderTypes<EI_CLASS_64>::MemSz memSz = 0U;      // size of segment in memory
    ElfProgramHeaderTypes<EI_CLASS_64>::Align align = 1U;      // alignment
};

static_assert(sizeof(ElfProgramHeader<EI_CLASS_32>) == 0x20, "");
static_assert(sizeof(ElfProgramHeader<EI_CLASS_64>) == 0x38, "");

template <int numBits>
struct ElfSectionHeaderTypes;

template <>
struct ElfSectionHeaderTypes<EI_CLASS_32> {
    using Name = uint32_t;
    using Type = uint32_t;
    using Flags = uint32_t;
    using Addr = uint32_t;
    using Offset = uint32_t;
    using Size = uint32_t;
    using Link = uint32_t;
    using Info = uint32_t;
    using AddrAlign = uint32_t;
    using EntSize = uint32_t;
};

template <>
struct ElfSectionHeaderTypes<EI_CLASS_64> {
    using Name = uint32_t;
    using Type = uint32_t;
    using Flags = uint64_t;
    using Addr = uint64_t;
    using Offset = uint64_t;
    using Size = uint64_t;
    using Link = uint32_t;
    using Info = uint32_t;
    using AddrAlign = uint64_t;
    using EntSize = uint64_t;
};

template <int numBits>
struct ElfSectionHeader {
    typename ElfSectionHeaderTypes<numBits>::Name name = 0U;           // offset to string in string section names
    typename ElfSectionHeaderTypes<numBits>::Type type = SHT_NULL;     // section type
    typename ElfSectionHeaderTypes<numBits>::Flags flags = SHF_NONE;   // section flags
    typename ElfSectionHeaderTypes<numBits>::Addr addr = 0U;           // VA of section in memory
    typename ElfSectionHeaderTypes<numBits>::Offset offset = 0U;       // absolute offset of section data in file
    typename ElfSectionHeaderTypes<numBits>::Size size = 0U;           // size of section's data
    typename ElfSectionHeaderTypes<numBits>::Link link = SHN_UNDEF;    // index of associated section
    typename ElfSectionHeaderTypes<numBits>::Info info = 0U;           // extra information
    typename ElfSectionHeaderTypes<numBits>::AddrAlign addralign = 0U; // section alignment
    typename ElfSectionHeaderTypes<numBits>::EntSize entsize = 0U;     // section's entries size
};

static_assert(sizeof(ElfSectionHeader<EI_CLASS_32>) == 0x28, "");
static_assert(sizeof(ElfSectionHeader<EI_CLASS_64>) == 0x40, "");

template <ElfIdentifierClass numBits>
struct ElfFileHeaderTypes;

template <>
struct ElfFileHeaderTypes<EI_CLASS_32> {
    using Type = uint16_t;
    using Machine = uint16_t;
    using Version = uint32_t;
    using Entry = uint32_t;
    using PhOff = uint32_t;
    using ShOff = uint32_t;
    using Flags = uint32_t;
    using EhSize = uint16_t;
    using PhEntSize = uint16_t;
    using PhNum = uint16_t;
    using ShEntSize = uint16_t;
    using ShNum = uint16_t;
    using ShStrNdx = uint16_t;
};

template <>
struct ElfFileHeaderTypes<EI_CLASS_64> {
    using Type = uint16_t;
    using Machine = uint16_t;
    using Version = uint32_t;
    using Entry = uint64_t;
    using PhOff = uint64_t;
    using ShOff = uint64_t;
    using Flags = uint32_t;
    using EhSize = uint16_t;
    using PhEntSize = uint16_t;
    using PhNum = uint16_t;
    using ShEntSize = uint16_t;
    using ShNum = uint16_t;
    using ShStrNdx = uint16_t;
};

template <ElfIdentifierClass numBits>
struct ElfFileHeader {
    ElfFileHeaderIdentity identity = ElfFileHeaderIdentity(numBits);                               // elf file identity
    typename ElfFileHeaderTypes<numBits>::Type type = ET_NONE;                                     // elf file type
    typename ElfFileHeaderTypes<numBits>::Machine machine = EM_NONE;                               // target machine
    typename ElfFileHeaderTypes<numBits>::Version version = 1U;                                    // elf file version
    typename ElfFileHeaderTypes<numBits>::Entry entry = 0U;                                        // entry point (start address)
    typename ElfFileHeaderTypes<numBits>::PhOff phOff = 0U;                                        // absolute offset to program header table in file
    typename ElfFileHeaderTypes<numBits>::ShOff shOff = 0U;                                        // absolute offset to section header table in file
    typename ElfFileHeaderTypes<numBits>::Flags flags = 0U;                                        // target-dependent flags
    typename ElfFileHeaderTypes<numBits>::EhSize ehSize = sizeof(ElfFileHeader<numBits>);          // header size
    typename ElfFileHeaderTypes<numBits>::PhEntSize phEntSize = sizeof(ElfProgramHeader<numBits>); // size of entries in program header table
    typename ElfFileHeaderTypes<numBits>::PhNum phNum = 0U;                                        // number of entries in pogram header table
    typename ElfFileHeaderTypes<numBits>::ShEntSize shEntSize = sizeof(ElfSectionHeader<numBits>); // size of entries section header table
    typename ElfFileHeaderTypes<numBits>::ShNum shNum = 0U;                                        // number of entries in section header table
    typename ElfFileHeaderTypes<numBits>::ShStrNdx shStrNdx = SHN_UNDEF;                           // index of section header table with section names
};

static_assert(sizeof(ElfFileHeader<EI_CLASS_32>) == 0x34, "");
static_assert(sizeof(ElfFileHeader<EI_CLASS_64>) == 0x40, "");

struct ElfNoteSection {
    uint32_t nameSize;
    uint32_t descSize;
    uint32_t type;
};
static_assert(sizeof(ElfNoteSection) == 0xC, "");

template <int numBits>
struct ElfSymbolEntryTypes;

template <>
struct ElfSymbolEntryTypes<EI_CLASS_32> {
    using Name = uint32_t;
    using Info = uint8_t;
    using Other = uint8_t;
    using Shndx = uint16_t;
    using Value = uint32_t;
    using Size = uint32_t;
};

template <>
struct ElfSymbolEntryTypes<EI_CLASS_64> {
    using Name = uint32_t;
    using Info = uint8_t;
    using Other = uint8_t;
    using Shndx = uint16_t;
    using Value = uint64_t;
    using Size = uint64_t;
};

template <ElfIdentifierClass numBits>
struct ElfSymbolEntry;

template <>
struct ElfSymbolEntry<EI_CLASS_32> {
    using Name = typename ElfSymbolEntryTypes<EI_CLASS_32>::Name;
    using Value = typename ElfSymbolEntryTypes<EI_CLASS_32>::Value;
    using Size = typename ElfSymbolEntryTypes<EI_CLASS_32>::Size;
    using Info = typename ElfSymbolEntryTypes<EI_CLASS_32>::Info;
    using Other = typename ElfSymbolEntryTypes<EI_CLASS_32>::Other;
    using Shndx = typename ElfSymbolEntryTypes<EI_CLASS_32>::Shndx;
    Name name = 0U;
    Value value = 0U;
    Size size = 0U;
    Info info = 0U;
    Other other = 0U;
    Shndx shndx = SHN_UNDEF;

    Info getBinding() const {
        return info >> 4;
    }

    Info getType() const {
        return info & 0xF;
    }

    Other getVisibility() const {
        return other & 0x3;
    }

    void setBinding(Info binding) {
        info = (info & 0xF) | (binding << 4);
    }

    void setType(Info type) {
        info = (info & (~0xF)) | (type & 0xF);
    }

    void setVisibility(Other visibility) {
        other = (other & (~0x3)) | (visibility & 0x3);
    }
};
static_assert(sizeof(ElfSymbolEntry<EI_CLASS_32>) == 0x10, "");

template <>
struct ElfSymbolEntry<EI_CLASS_64> {
    using Name = typename ElfSymbolEntryTypes<EI_CLASS_64>::Name;
    using Value = typename ElfSymbolEntryTypes<EI_CLASS_64>::Value;
    using Size = typename ElfSymbolEntryTypes<EI_CLASS_64>::Size;
    using Info = typename ElfSymbolEntryTypes<EI_CLASS_64>::Info;
    using Other = typename ElfSymbolEntryTypes<EI_CLASS_64>::Other;
    using Shndx = typename ElfSymbolEntryTypes<EI_CLASS_64>::Shndx;
    Name name = 0U;
    Info info = 0U;
    Other other = 0U;
    Shndx shndx = SHN_UNDEF;
    Value value = 0U;
    Size size = 0U;

    Info getBinding() const {
        return info >> 4;
    }

    Info getType() const {
        return info & 0xF;
    }

    Other getVisibility() const {
        return other & 0x3;
    }

    void setBinding(Info binding) {
        info = (info & 0xF) | (binding << 4);
    }

    void setType(Info type) {
        info = (info & (~0xF)) | (type & 0xF);
    }

    void setVisibility(Other visibility) {
        other = (other & (~0x3)) | (visibility & 0x3);
    }
};
static_assert(sizeof(ElfSymbolEntry<EI_CLASS_64>) == 0x18, "");

template <int numBits>
struct ElfRelocationEntryTypes;

template <>
struct ElfRelocationEntryTypes<EI_CLASS_32> {
    using Offset = uint32_t;
    using Info = uint32_t;
    using Addend = int32_t;
};

template <>
struct ElfRelocationEntryTypes<EI_CLASS_64> {
    using Offset = uint64_t;
    using Info = uint64_t;
    using Addend = int64_t;
};

namespace RelocationFuncs {
template <typename T>
constexpr T getSymbolTableIndex(T info);

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_32>::Info getSymbolTableIndex(ElfRelocationEntryTypes<EI_CLASS_32>::Info info) {
    return info >> 8;
}

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_64>::Info getSymbolTableIndex(ElfRelocationEntryTypes<EI_CLASS_64>::Info info) {
    return info >> 32;
}

template <typename T>
constexpr T getRelocationType(T info);

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_32>::Info getRelocationType(ElfRelocationEntryTypes<EI_CLASS_32>::Info info) {
    return static_cast<uint8_t>(info);
}

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_64>::Info getRelocationType(ElfRelocationEntryTypes<EI_CLASS_64>::Info info) {
    return static_cast<uint32_t>(info);
}

template <typename T>
constexpr T setSymbolTableIndex(T info, T index);

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_32>::Info setSymbolTableIndex(ElfRelocationEntryTypes<EI_CLASS_32>::Info info,
                                                                         ElfRelocationEntryTypes<EI_CLASS_32>::Info index) {
    return (info & 0x000000FF) | (index << 8);
}

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_64>::Info setSymbolTableIndex(ElfRelocationEntryTypes<EI_CLASS_64>::Info info,
                                                                         ElfRelocationEntryTypes<EI_CLASS_64>::Info index) {
    return (info & 0x00000000FFFFFFFF) | (index << 32);
}

template <typename T>
constexpr T setRelocationType(T info, T type);

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_32>::Info setRelocationType(ElfRelocationEntryTypes<EI_CLASS_32>::Info info,
                                                                       ElfRelocationEntryTypes<EI_CLASS_32>::Info type) {
    return (info & 0xFFFFFF00) | static_cast<uint8_t>(type);
}

template <>
constexpr ElfRelocationEntryTypes<EI_CLASS_64>::Info setRelocationType(ElfRelocationEntryTypes<EI_CLASS_64>::Info info,
                                                                       ElfRelocationEntryTypes<EI_CLASS_64>::Info type) {
    return (info & 0xFFFFFFFF00000000) | static_cast<uint32_t>(type);
}
} // namespace RelocationFuncs

template <ElfIdentifierClass numBits>
struct ElfRel {
    using Offset = typename ElfRelocationEntryTypes<numBits>::Offset;
    using Info = typename ElfRelocationEntryTypes<numBits>::Info;
    Offset offset = 0U;
    Info info = 0U;

    constexpr Info getSymbolTableIndex() const {
        return RelocationFuncs::getSymbolTableIndex(info);
    }

    constexpr Info getRelocationType() const {
        return RelocationFuncs::getRelocationType(info);
    }

    constexpr void setSymbolTableIndex(Info index) {
        info = RelocationFuncs::setSymbolTableIndex(info, index);
    }

    constexpr void setRelocationType(Info type) {
        info = RelocationFuncs::setRelocationType(info, type);
    }
};

static_assert(sizeof(ElfRel<EI_CLASS_32>) == 0x8, "");
static_assert(sizeof(ElfRel<EI_CLASS_64>) == 0x10, "");

template <int numBits>
struct ElfRela {
    using Offset = typename ElfRelocationEntryTypes<numBits>::Offset;
    using Info = typename ElfRelocationEntryTypes<numBits>::Info;
    using Addend = typename ElfRelocationEntryTypes<numBits>::Addend;
    Offset offset = 0U;
    Info info = 0U;
    Addend addend = 0U;

    constexpr Info getSymbolTableIndex() const {
        return RelocationFuncs::getSymbolTableIndex(info);
    }

    constexpr Info getRelocationType() const {
        return RelocationFuncs::getRelocationType(info);
    }

    constexpr void setSymbolTableIndex(Info index) {
        info = RelocationFuncs::setSymbolTableIndex(info, index);
    }

    constexpr void setRelocationType(Info type) {
        info = RelocationFuncs::setRelocationType(info, type);
    }
};

static_assert(sizeof(ElfRela<EI_CLASS_32>) == 0xC, "");
static_assert(sizeof(ElfRela<EI_CLASS_64>) == 0x18, "");

namespace SpecialSectionNames {
inline constexpr ConstStringRef bss = ".bss";                    // uninitialized memory
inline constexpr ConstStringRef comment = ".comment";            // version control information
inline constexpr ConstStringRef data = ".data";                  // initialized memory
inline constexpr ConstStringRef data1 = ".data1";                // initialized memory
inline constexpr ConstStringRef debug = ".debug";                // debug symbols
inline constexpr ConstStringRef debugInfo = ".debug_info";       // debug info
inline constexpr ConstStringRef dynamic = ".dynamic";            // dynamic linking information
inline constexpr ConstStringRef dynstr = ".dynstr";              // strings for dynamic linking
inline constexpr ConstStringRef dynsym = ".dynsym";              // dynamic linking symbol table
inline constexpr ConstStringRef fini = ".fini";                  // executable instructions of program termination
inline constexpr ConstStringRef finiArray = ".fini_array";       // function pointers of termination array
inline constexpr ConstStringRef got = ".got";                    // global offset table
inline constexpr ConstStringRef hash = ".hash";                  // symbol hash table
inline constexpr ConstStringRef init = ".init";                  // executable instructions of program initializaion
inline constexpr ConstStringRef initArray = ".init_array";       // function pointers of initialization array
inline constexpr ConstStringRef interp = ".interp";              // path name of program interpreter
inline constexpr ConstStringRef line = ".line";                  // line number info for symbolic debugging
inline constexpr ConstStringRef note = ".note";                  // note section
inline constexpr ConstStringRef plt = ".plt";                    // procedure linkage table
inline constexpr ConstStringRef preinitArray = ".preinit_array"; // function pointers of pre-initialization array
inline constexpr ConstStringRef relPrefix = ".rel";              // prefix of .relNAME - relocations for NAME section
inline constexpr ConstStringRef relaPrefix = ".rela";            // prefix of .relaNAME - rela relocations for NAME section
inline constexpr ConstStringRef rodata = ".rodata";              // read-only data
inline constexpr ConstStringRef rodata1 = ".rodata1";            // read-only data
inline constexpr ConstStringRef shStrTab = ".shstrtab";          // section names (strings)
inline constexpr ConstStringRef strtab = ".strtab";              // strings
inline constexpr ConstStringRef symtab = ".symtab";              // symbol table
inline constexpr ConstStringRef symtabShndx = ".symtab_shndx";   // special symbol table section index array
inline constexpr ConstStringRef tbss = ".tbss";                  // uninitialized thread-local data
inline constexpr ConstStringRef tadata = ".tdata";               // initialided thread-local data
inline constexpr ConstStringRef tdata1 = ".tdata1";              // initialided thread-local data
inline constexpr ConstStringRef text = ".text";                  // executable instructions
} // namespace SpecialSectionNames

} // namespace Elf

} // namespace NEO