Bug 1910842 - fix non-scaling-stroke when outer svg element has a CSS transform r...
[gecko.git] / mozglue / linker / Elfxx.h
blob3b79fdd8c623bf0a73bdbdbff52c28e4a2c76908
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef Elfxx_h
6 #define Elfxx_h
8 #include "Utils.h"
10 #include <elf.h>
11 #include <endian.h>
13 /**
14 * Generic ELF macros for the target system
16 #ifdef __LP64__
17 # define Elf_(type) Elf64_##type
18 # define ELFCLASS ELFCLASS64
19 # define ELF_R_TYPE ELF64_R_TYPE
20 # define ELF_R_SYM ELF64_R_SYM
21 # ifndef ELF_ST_BIND
22 # define ELF_ST_BIND ELF64_ST_BIND
23 # endif
24 #else
25 # define Elf_(type) Elf32_##type
26 # define ELFCLASS ELFCLASS32
27 # define ELF_R_TYPE ELF32_R_TYPE
28 # define ELF_R_SYM ELF32_R_SYM
29 # ifndef ELF_ST_BIND
30 # define ELF_ST_BIND ELF32_ST_BIND
31 # endif
32 #endif
34 #ifndef __BYTE_ORDER
35 # error Cannot find endianness
36 #endif
38 #if __BYTE_ORDER == __LITTLE_ENDIAN
39 # define ELFDATA ELFDATA2LSB
40 #elif __BYTE_ORDER == __BIG_ENDIAN
41 # define ELFDATA ELFDATA2MSB
42 #endif
44 #ifdef __linux__
45 # define ELFOSABI ELFOSABI_LINUX
46 # ifdef EI_ABIVERSION
47 # define ELFABIVERSION 0
48 # endif
49 #else
50 # error Unknown ELF OSABI
51 #endif
53 #if defined(__i386__)
54 # define ELFMACHINE EM_386
56 // Doing this way probably doesn't scale to other architectures
57 # define R_ABS R_386_32
58 # define R_GLOB_DAT R_386_GLOB_DAT
59 # define R_JMP_SLOT R_386_JMP_SLOT
60 # define R_RELATIVE R_386_RELATIVE
61 # define RELOC(n) DT_REL##n
62 # define UNSUPPORTED_RELOC(n) DT_RELA##n
63 # define STR_RELOC(n) "DT_REL" #n
64 # define Reloc Rel
66 #elif defined(__x86_64__)
67 # define ELFMACHINE EM_X86_64
69 # define R_ABS R_X86_64_64
70 # define R_GLOB_DAT R_X86_64_GLOB_DAT
71 # define R_JMP_SLOT R_X86_64_JUMP_SLOT
72 # define R_RELATIVE R_X86_64_RELATIVE
73 # define RELOC(n) DT_RELA##n
74 # define UNSUPPORTED_RELOC(n) DT_REL##n
75 # define STR_RELOC(n) "DT_RELA" #n
76 # define Reloc Rela
78 #elif defined(__arm__)
79 # define ELFMACHINE EM_ARM
81 # ifndef R_ARM_ABS32
82 # define R_ARM_ABS32 2
83 # endif
84 # ifndef R_ARM_GLOB_DAT
85 # define R_ARM_GLOB_DAT 21
86 # endif
87 # ifndef R_ARM_JUMP_SLOT
88 # define R_ARM_JUMP_SLOT 22
89 # endif
90 # ifndef R_ARM_RELATIVE
91 # define R_ARM_RELATIVE 23
92 # endif
94 # define R_ABS R_ARM_ABS32
95 # define R_GLOB_DAT R_ARM_GLOB_DAT
96 # define R_JMP_SLOT R_ARM_JUMP_SLOT
97 # define R_RELATIVE R_ARM_RELATIVE
98 # define RELOC(n) DT_REL##n
99 # define UNSUPPORTED_RELOC(n) DT_RELA##n
100 # define STR_RELOC(n) "DT_REL" #n
101 # define Reloc Rel
103 #elif defined(__aarch64__)
104 # define ELFMACHINE EM_AARCH64
106 # define R_ABS R_AARCH64_ABS64
107 # define R_GLOB_DAT R_AARCH64_GLOB_DAT
108 # define R_JMP_SLOT R_AARCH64_JUMP_SLOT
109 # define R_RELATIVE R_AARCH64_RELATIVE
110 # define RELOC(n) DT_RELA##n
111 # define UNSUPPORTED_RELOC(n) DT_REL##n
112 # define STR_RELOC(n) "DT_RELA" #n
113 # define Reloc Rela
115 #else
116 # error Unknown ELF machine type
117 #endif
119 namespace Elf {
122 * Define a few basic Elf Types
124 typedef Elf_(Phdr) Phdr;
125 typedef Elf_(Dyn) Dyn;
126 typedef Elf_(Sym) Sym;
127 typedef Elf_(Addr) Addr;
128 typedef Elf_(Word) Word;
129 typedef Elf_(Half) Half;
132 * Helper class around the standard Elf header struct
134 struct Ehdr : public Elf_(Ehdr) {
136 * Equivalent to reinterpret_cast<const Ehdr *>(buf), but additionally
137 * checking that this is indeed an Elf header and that the Elf type
138 * corresponds to that of the system
140 static const Ehdr* validate(const void* buf);
144 * Elf String table
146 class Strtab : public UnsizedArray<const char> {
147 public:
149 * Returns the string at the given index in the table
151 const char* GetStringAt(off_t index) const {
152 return &UnsizedArray<const char>::operator[](index);
157 * Helper class around Elf relocation.
159 struct Rel
160 : public Elf_(Rel){/**
161 * Returns the addend for the relocation, which is the
162 * value stored at r_offset.
164 Addr GetAddend(void* base)
165 const {return *(reinterpret_cast<const Addr*>(
166 reinterpret_cast<const char*>(base) + r_offset));
167 } // namespace Elf
172 * Helper class around Elf relocation with addend.
174 struct Rela
175 : public Elf_(Rela){/**
176 * Returns the addend for the relocation.
178 Addr GetAddend(void* base) const {return r_addend;
183 } /* namespace Elf */
185 #endif /* Elfxx_h */