1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_LIBELFFILE_ELF_ELF_UTILS_H_
18 #define ART_LIBELFFILE_ELF_ELF_UTILS_H_
19 
20 #include <elf.h>
21 
22 #include <sys/cdefs.h>
23 
24 #include <android-base/logging.h>
25 
26 namespace art {
27 
28 struct ElfTypes32 {
29   using Addr = Elf32_Addr;
30   using Off = Elf32_Off;
31   using Half = Elf32_Half;
32   using Word = Elf32_Word;
33   using Sword = Elf32_Sword;
34   using Ehdr = Elf32_Ehdr;
35   using Shdr = Elf32_Shdr;
36   using Sym = Elf32_Sym;
37   using Rel = Elf32_Rel;
38   using Rela = Elf32_Rela;
39   using Phdr = Elf32_Phdr;
40   using Dyn = Elf32_Dyn;
41 };
42 
43 struct ElfTypes64 {
44   using Addr = Elf64_Addr;
45   using Off = Elf64_Off;
46   using Half = Elf64_Half;
47   using Word = Elf64_Word;
48   using Sword = Elf64_Sword;
49   using Xword = Elf64_Xword;
50   using Sxword = Elf64_Sxword;
51   using Ehdr = Elf64_Ehdr;
52   using Shdr = Elf64_Shdr;
53   using Sym = Elf64_Sym;
54   using Rel = Elf64_Rel;
55   using Rela = Elf64_Rela;
56   using Phdr = Elf64_Phdr;
57   using Dyn = Elf64_Dyn;
58 };
59 
60 // Only bionic has ELF class generic macros; glibc/musl require you to specify
61 // ELF32 or ELF64, even though they're the same, and that makes call sites look
62 // misleadingly class-specific.
63 #ifndef __BIONIC__
64 #define ELF_ST_BIND(x) ELF64_ST_BIND(x)
65 #define ELF_ST_TYPE(x) ELF64_ST_TYPE(x)
66 #endif
67 
68 // Missing from musl (https://www.openwall.com/lists/musl/2024/03/21/10).
69 #ifndef EF_RISCV_RVC
70 #define EF_RISCV_RVC 0x1
71 #define EF_RISCV_FLOAT_ABI_DOUBLE 0x4
72 #endif
73 
74 // Patching section type
75 #define SHT_OAT_PATCH        SHT_LOUSER
76 
77 }  // namespace art
78 
79 #endif  // ART_LIBELFFILE_ELF_ELF_UTILS_H_
80