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 25namespace OHOS { 26namespace HiviewDFX { 27static const std::string NOTE_GNU_BUILD_ID = ".note.gnu.build-id"; 28static const std::string NOTES = ".notes"; 29static const std::string GNU_DEBUGDATA = ".gnu_debugdata"; 30static const std::string EH_FRAME_HDR = ".eh_frame_hdr"; 31static const std::string EH_FRAME = ".eh_frame"; 32static const std::string ARM_EXIDX = ".ARM.exidx"; 33static const std::string ARM_EXTAB = ".ARM.extab"; 34static const std::string SHSTRTAB = ".shstrtab"; 35static const std::string STRTAB = ".strtab"; 36static const std::string SYMTAB = ".symtab"; 37static const std::string DYNSYM = ".dynsym"; 38static const std::string DYNSTR = ".dynstr"; 39static const std::string PLT = ".plt"; 40 41struct 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 49struct 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}; 58 59struct ElfShdr { 60 uint32_t name = 0; // Section name (string tbl index) 61 uint32_t type = 0; // Section type 62 uint64_t flags = 0; // Section flags 63 uint64_t addr = 0; // Section virtual addr at execution 64 uint64_t offset = 0; // Section file offset 65 uint64_t size = 0; // Section size in bytes 66 uint32_t link = 0; // Link to another section 67 uint32_t info = 0; // Additional section information 68 uint64_t addrAlign = 0; // Section alignment 69 uint64_t entSize = 0; // Entry size if section holds table 70}; 71 72struct ShdrInfo { 73 uint64_t addr = 0; 74 uint64_t entSize = 0; 75 uint64_t offset = 0; 76 uint64_t size = 0; 77}; 78 79struct __attribute__((packed)) DwarfEhFrameHdr { 80 unsigned char version = 0; 81 unsigned char ehFramePtrEnc = 0; 82 unsigned char fdeCountEnc = 0; 83 unsigned char tableEnc = 0; 84 ElfW(Addr) ehFrame; 85}; 86 87struct MiniDebugInfo { 88 uint64_t offset = 0; 89 uintptr_t size = 0; 90}; 91 92} // namespace HiviewDFX 93} // namespace OHOS 94#endif 95