• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef DFX_ELF_DEFINE_H
16 #define DFX_ELF_DEFINE_H
17 
18 #include <cinttypes>
19 #include <string>
20 #if !is_mingw
21 #include <elf.h>
22 #include <link.h>
23 #endif
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 static const std::string NOTE_GNU_BUILD_ID = ".note.gnu.build-id";
28 static const std::string NOTES = ".notes";
29 static const std::string GNU_DEBUGDATA = ".gnu_debugdata";
30 static const std::string EH_FRAME_HDR = ".eh_frame_hdr";
31 static const std::string EH_FRAME = ".eh_frame";
32 static const std::string ARM_EXIDX = ".ARM.exidx";
33 static const std::string ARM_EXTAB = ".ARM.extab";
34 static const std::string SHSTRTAB = ".shstrtab";
35 static const std::string STRTAB = ".strtab";
36 static const std::string SYMTAB = ".symtab";
37 static const std::string DYNSYM = ".dynsym";
38 static const std::string DYNSTR = ".dynstr";
39 static const std::string PLT = ".plt";
40 
41 struct ElfLoadInfo {
42     uint64_t offset = 0;
43     uint64_t tableVaddr = 0;
44     size_t tableSize = 0;
45     uint64_t align = 0;
46     uint64_t mmapLen = 0;
47 };
48 
49 struct ElfSymbol {
50     std::string nameStr = "";
51     uint32_t name = 0;
52     unsigned char info = 0;
53     unsigned char other = 0;
54     uint16_t shndx = 0;
55     uint64_t value = 0;
56     uint64_t size = 0;
57     bool operator<(const ElfSymbol& other) const
58     {
59         return value < other.value;
60     }
61 };
62 
63 struct ElfShdr {
64     uint32_t	name = 0;       // Section name (string tbl index)
65     uint32_t	type = 0;       // Section type
66     uint64_t	flags = 0;      // Section flags
67     uint64_t	addr = 0;       // Section virtual addr at execution
68     uint64_t	offset = 0;     // Section file offset
69     uint64_t	size = 0;       // Section size in bytes
70     uint32_t	link = 0;       // Link to another section
71     uint32_t	info = 0;       // Additional section information
72     uint64_t	addrAlign = 0;  // Section alignment
73     uint64_t	entSize = 0;    // Entry size if section holds table
74 };
75 
76 struct ShdrInfo {
77     uint64_t addr = 0;
78     uint64_t entSize = 0;
79     uint64_t offset = 0;
80     uint64_t size = 0;
81 };
82 
83 struct __attribute__((packed)) DwarfEhFrameHdr {
84     unsigned char version = 0;
85     unsigned char ehFramePtrEnc = 0;
86     unsigned char fdeCountEnc = 0;
87     unsigned char tableEnc = 0;
88     ElfW(Addr) ehFrame;
89 };
90 
91 struct GnuDebugDataHdr {
92     uintptr_t address = 0;
93     uintptr_t size = 0;
94 };
95 
96 } // namespace HiviewDFX
97 } // namespace OHOS
98 #endif
99