Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #include <elf.h> |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <string> |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 22 | #include <utility> |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 23 | |
Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 24 | #include <7zCrc.h> |
| 25 | #include <Xz.h> |
| 26 | #include <XzCrc64.h> |
| 27 | |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 28 | #include <unwindstack/DwarfError.h> |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 29 | #include <unwindstack/DwarfSection.h> |
| 30 | #include <unwindstack/ElfInterface.h> |
| 31 | #include <unwindstack/Log.h> |
| 32 | #include <unwindstack/Memory.h> |
| 33 | #include <unwindstack/Regs.h> |
| 34 | |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 35 | #include "DwarfDebugFrame.h" |
| 36 | #include "DwarfEhFrame.h" |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 37 | #include "DwarfEhFrameWithHdr.h" |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 38 | #include "Symbols.h" |
| 39 | |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 40 | namespace unwindstack { |
| 41 | |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 42 | ElfInterface::~ElfInterface() { |
| 43 | for (auto symbol : symbols_) { |
| 44 | delete symbol; |
| 45 | } |
| 46 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 47 | |
Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 48 | bool ElfInterface::IsValidPc(uint64_t pc) { |
| 49 | if (!pt_loads_.empty()) { |
| 50 | for (auto& entry : pt_loads_) { |
| 51 | uint64_t start = entry.second.table_offset; |
| 52 | uint64_t end = start + entry.second.table_size; |
| 53 | if (pc >= start && pc < end) { |
| 54 | return true; |
| 55 | } |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | // No PT_LOAD data, look for a fde for this pc in the section data. |
| 61 | if (debug_frame_ != nullptr && debug_frame_->GetFdeFromPc(pc) != nullptr) { |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | if (eh_frame_ != nullptr && eh_frame_->GetFdeFromPc(pc) != nullptr) { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 72 | bool ElfInterface::GetTextRange(uint64_t* addr, uint64_t* size) { |
| 73 | if (text_size_ != 0) { |
| 74 | *addr = text_addr_; |
| 75 | *size = text_size_; |
| 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 81 | Memory* ElfInterface::CreateGnuDebugdataMemory() { |
| 82 | if (gnu_debugdata_offset_ == 0 || gnu_debugdata_size_ == 0) { |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
| 86 | // TODO: Only call these initialization functions once. |
| 87 | CrcGenerateTable(); |
| 88 | Crc64GenerateTable(); |
| 89 | |
| 90 | std::vector<uint8_t> src(gnu_debugdata_size_); |
Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 91 | if (!memory_->ReadFully(gnu_debugdata_offset_, src.data(), gnu_debugdata_size_)) { |
Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 92 | gnu_debugdata_offset_ = 0; |
| 93 | gnu_debugdata_size_ = static_cast<uint64_t>(-1); |
| 94 | return nullptr; |
| 95 | } |
| 96 | |
| 97 | ISzAlloc alloc; |
| 98 | CXzUnpacker state; |
Sen Jiang | 2ef03e0 | 2018-05-04 12:56:04 -0700 | [diff] [blame] | 99 | alloc.Alloc = [](ISzAllocPtr, size_t size) { return malloc(size); }; |
| 100 | alloc.Free = [](ISzAllocPtr, void* ptr) { return free(ptr); }; |
Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 101 | |
| 102 | XzUnpacker_Construct(&state, &alloc); |
| 103 | |
| 104 | std::unique_ptr<MemoryBuffer> dst(new MemoryBuffer); |
| 105 | int return_val; |
| 106 | size_t src_offset = 0; |
| 107 | size_t dst_offset = 0; |
| 108 | ECoderStatus status; |
| 109 | dst->Resize(5 * gnu_debugdata_size_); |
| 110 | do { |
| 111 | size_t src_remaining = src.size() - src_offset; |
| 112 | size_t dst_remaining = dst->Size() - dst_offset; |
| 113 | if (dst_remaining < 2 * gnu_debugdata_size_) { |
| 114 | dst->Resize(dst->Size() + 2 * gnu_debugdata_size_); |
| 115 | dst_remaining += 2 * gnu_debugdata_size_; |
| 116 | } |
| 117 | return_val = XzUnpacker_Code(&state, dst->GetPtr(dst_offset), &dst_remaining, &src[src_offset], |
Sen Jiang | 2ef03e0 | 2018-05-04 12:56:04 -0700 | [diff] [blame] | 118 | &src_remaining, true, CODER_FINISH_ANY, &status); |
Christopher Ferris | bae69f1 | 2017-06-28 14:51:54 -0700 | [diff] [blame] | 119 | src_offset += src_remaining; |
| 120 | dst_offset += dst_remaining; |
| 121 | } while (return_val == SZ_OK && status == CODER_STATUS_NOT_FINISHED); |
| 122 | XzUnpacker_Free(&state); |
| 123 | if (return_val != SZ_OK || !XzUnpacker_IsStreamWasFinished(&state)) { |
| 124 | gnu_debugdata_offset_ = 0; |
| 125 | gnu_debugdata_size_ = static_cast<uint64_t>(-1); |
| 126 | return nullptr; |
| 127 | } |
| 128 | |
| 129 | // Shrink back down to the exact size. |
| 130 | dst->Resize(dst_offset); |
| 131 | |
| 132 | return dst.release(); |
| 133 | } |
| 134 | |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 135 | template <typename AddressType> |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 136 | void ElfInterface::InitHeadersWithTemplate(uint64_t load_bias) { |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 137 | if (eh_frame_hdr_offset_ != 0) { |
| 138 | eh_frame_.reset(new DwarfEhFrameWithHdr<AddressType>(memory_)); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 139 | if (!eh_frame_->Init(eh_frame_hdr_offset_, eh_frame_hdr_size_, load_bias)) { |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 140 | eh_frame_.reset(nullptr); |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 141 | } |
Christopher Ferris | 1a141a0 | 2018-01-24 08:52:47 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if (eh_frame_.get() == nullptr && eh_frame_offset_ != 0) { |
| 145 | // If there is an eh_frame section without an eh_frame_hdr section, |
| 146 | // or using the frame hdr object failed to init. |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 147 | eh_frame_.reset(new DwarfEhFrame<AddressType>(memory_)); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 148 | if (!eh_frame_->Init(eh_frame_offset_, eh_frame_size_, load_bias)) { |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 149 | eh_frame_.reset(nullptr); |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
Christopher Ferris | 1a141a0 | 2018-01-24 08:52:47 -0800 | [diff] [blame] | 153 | if (eh_frame_.get() == nullptr) { |
| 154 | eh_frame_hdr_offset_ = 0; |
| 155 | eh_frame_hdr_size_ = static_cast<uint64_t>(-1); |
| 156 | eh_frame_offset_ = 0; |
| 157 | eh_frame_size_ = static_cast<uint64_t>(-1); |
| 158 | } |
| 159 | |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 160 | if (debug_frame_offset_ != 0) { |
| 161 | debug_frame_.reset(new DwarfDebugFrame<AddressType>(memory_)); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 162 | if (!debug_frame_->Init(debug_frame_offset_, debug_frame_size_, load_bias)) { |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 163 | debug_frame_.reset(nullptr); |
| 164 | debug_frame_offset_ = 0; |
| 165 | debug_frame_size_ = static_cast<uint64_t>(-1); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 170 | template <typename EhdrType, typename PhdrType, typename ShdrType> |
Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 171 | bool ElfInterface::ReadAllHeaders(uint64_t* load_bias) { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 172 | EhdrType ehdr; |
Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 173 | if (!memory_->ReadFully(0, &ehdr, sizeof(ehdr))) { |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 174 | last_error_.code = ERROR_MEMORY_INVALID; |
| 175 | last_error_.address = 0; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 176 | return false; |
| 177 | } |
| 178 | |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 179 | // If we have enough information that this is an elf file, then allow |
| 180 | // malformed program and section headers. |
| 181 | ReadProgramHeaders<EhdrType, PhdrType>(ehdr, load_bias); |
| 182 | ReadSectionHeaders<EhdrType, ShdrType>(ehdr); |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 183 | return true; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | template <typename EhdrType, typename PhdrType> |
Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 187 | uint64_t ElfInterface::GetLoadBias(Memory* memory) { |
| 188 | EhdrType ehdr; |
Christopher Ferris | cadacdf | 2019-01-15 19:10:49 -0800 | [diff] [blame] | 189 | if (!memory->ReadFully(0, &ehdr, sizeof(ehdr))) { |
Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | |
| 193 | uint64_t offset = ehdr.e_phoff; |
| 194 | for (size_t i = 0; i < ehdr.e_phnum; i++, offset += ehdr.e_phentsize) { |
| 195 | PhdrType phdr; |
Christopher Ferris | cadacdf | 2019-01-15 19:10:49 -0800 | [diff] [blame] | 196 | if (!memory->ReadFully(offset, &phdr, sizeof(phdr))) { |
Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | if (phdr.p_type == PT_LOAD && phdr.p_offset == 0) { |
| 200 | return phdr.p_vaddr; |
| 201 | } |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | template <typename EhdrType, typename PhdrType> |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 207 | void ElfInterface::ReadProgramHeaders(const EhdrType& ehdr, uint64_t* load_bias) { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 208 | uint64_t offset = ehdr.e_phoff; |
| 209 | for (size_t i = 0; i < ehdr.e_phnum; i++, offset += ehdr.e_phentsize) { |
| 210 | PhdrType phdr; |
Christopher Ferris | 5afddb0 | 2018-06-29 16:30:55 -0700 | [diff] [blame] | 211 | if (!memory_->ReadFully(offset, &phdr, sizeof(phdr))) { |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 212 | return; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 215 | switch (phdr.p_type) { |
| 216 | case PT_LOAD: |
| 217 | { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 218 | if ((phdr.p_flags & PF_X) == 0) { |
| 219 | continue; |
| 220 | } |
| 221 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 222 | pt_loads_[phdr.p_offset] = LoadInfo{phdr.p_offset, phdr.p_vaddr, |
| 223 | static_cast<size_t>(phdr.p_memsz)}; |
| 224 | if (phdr.p_offset == 0) { |
Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 225 | *load_bias = phdr.p_vaddr; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 226 | } |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | case PT_GNU_EH_FRAME: |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 231 | // This is really the pointer to the .eh_frame_hdr section. |
| 232 | eh_frame_hdr_offset_ = phdr.p_offset; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 233 | eh_frame_hdr_size_ = phdr.p_memsz; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 234 | break; |
| 235 | |
| 236 | case PT_DYNAMIC: |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 237 | dynamic_offset_ = phdr.p_offset; |
Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 238 | dynamic_vaddr_ = phdr.p_vaddr; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 239 | dynamic_size_ = phdr.p_memsz; |
| 240 | break; |
Christopher Ferris | 5afddb0 | 2018-06-29 16:30:55 -0700 | [diff] [blame] | 241 | |
| 242 | default: |
| 243 | HandleUnknownType(phdr.p_type, phdr.p_offset, phdr.p_filesz); |
| 244 | break; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 245 | } |
| 246 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 249 | template <typename NhdrType> |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 250 | std::string ElfInterface::ReadBuildID() { |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 251 | // Ensure there is no overflow in any of the calulations below. |
| 252 | uint64_t tmp; |
| 253 | if (__builtin_add_overflow(gnu_build_id_offset_, gnu_build_id_size_, &tmp)) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 254 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | uint64_t offset = 0; |
| 258 | while (offset < gnu_build_id_size_) { |
| 259 | if (gnu_build_id_size_ - offset < sizeof(NhdrType)) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 260 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 261 | } |
| 262 | NhdrType hdr; |
| 263 | if (!memory_->ReadFully(gnu_build_id_offset_ + offset, &hdr, sizeof(hdr))) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 264 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 265 | } |
| 266 | offset += sizeof(hdr); |
| 267 | |
| 268 | if (gnu_build_id_size_ - offset < hdr.n_namesz) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 269 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 270 | } |
| 271 | if (hdr.n_namesz > 0) { |
| 272 | std::string name(hdr.n_namesz, '\0'); |
| 273 | if (!memory_->ReadFully(gnu_build_id_offset_ + offset, &(name[0]), hdr.n_namesz)) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 274 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | // Trim trailing \0 as GNU is stored as a C string in the ELF file. |
| 278 | if (name.back() == '\0') |
| 279 | name.resize(name.size() - 1); |
| 280 | |
| 281 | // Align hdr.n_namesz to next power multiple of 4. See man 5 elf. |
| 282 | offset += (hdr.n_namesz + 3) & ~3; |
| 283 | |
| 284 | if (name == "GNU" && hdr.n_type == NT_GNU_BUILD_ID) { |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 285 | if (gnu_build_id_size_ - offset < hdr.n_descsz || hdr.n_descsz == 0) { |
| 286 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 287 | } |
Christopher Ferris | a46de76 | 2019-04-03 14:14:30 -0700 | [diff] [blame^] | 288 | std::string build_id(hdr.n_descsz, '\0'); |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 289 | if (memory_->ReadFully(gnu_build_id_offset_ + offset, &build_id[0], hdr.n_descsz)) { |
| 290 | return build_id; |
| 291 | } |
| 292 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | // Align hdr.n_descsz to next power multiple of 4. See man 5 elf. |
| 296 | offset += (hdr.n_descsz + 3) & ~3; |
| 297 | } |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 298 | return ""; |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 301 | template <typename EhdrType, typename ShdrType> |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 302 | void ElfInterface::ReadSectionHeaders(const EhdrType& ehdr) { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 303 | uint64_t offset = ehdr.e_shoff; |
| 304 | uint64_t sec_offset = 0; |
| 305 | uint64_t sec_size = 0; |
| 306 | |
| 307 | // Get the location of the section header names. |
| 308 | // If something is malformed in the header table data, we aren't going |
| 309 | // to terminate, we'll simply ignore this part. |
| 310 | ShdrType shdr; |
| 311 | if (ehdr.e_shstrndx < ehdr.e_shnum) { |
| 312 | uint64_t sh_offset = offset + ehdr.e_shstrndx * ehdr.e_shentsize; |
Christopher Ferris | 5afddb0 | 2018-06-29 16:30:55 -0700 | [diff] [blame] | 313 | if (memory_->ReadFully(sh_offset, &shdr, sizeof(shdr))) { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 314 | sec_offset = shdr.sh_offset; |
| 315 | sec_size = shdr.sh_size; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // Skip the first header, it's always going to be NULL. |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 320 | offset += ehdr.e_shentsize; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 321 | for (size_t i = 1; i < ehdr.e_shnum; i++, offset += ehdr.e_shentsize) { |
Christopher Ferris | cadacdf | 2019-01-15 19:10:49 -0800 | [diff] [blame] | 322 | if (!memory_->ReadFully(offset, &shdr, sizeof(shdr))) { |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 323 | return; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 326 | if (shdr.sh_type == SHT_SYMTAB || shdr.sh_type == SHT_DYNSYM) { |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 327 | // Need to go get the information about the section that contains |
| 328 | // the string terminated names. |
| 329 | ShdrType str_shdr; |
| 330 | if (shdr.sh_link >= ehdr.e_shnum) { |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 331 | continue; |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 332 | } |
| 333 | uint64_t str_offset = ehdr.e_shoff + shdr.sh_link * ehdr.e_shentsize; |
Christopher Ferris | cadacdf | 2019-01-15 19:10:49 -0800 | [diff] [blame] | 334 | if (!memory_->ReadFully(str_offset, &str_shdr, sizeof(str_shdr))) { |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 335 | continue; |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 336 | } |
| 337 | if (str_shdr.sh_type != SHT_STRTAB) { |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 338 | continue; |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 339 | } |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 340 | symbols_.push_back(new Symbols(shdr.sh_offset, shdr.sh_size, shdr.sh_entsize, |
| 341 | str_shdr.sh_offset, str_shdr.sh_size)); |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 342 | } else if (shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS) { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 343 | // Look for the .debug_frame and .gnu_debugdata. |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 344 | if (shdr.sh_name < sec_size) { |
| 345 | std::string name; |
| 346 | if (memory_->ReadString(sec_offset + shdr.sh_name, &name)) { |
| 347 | if (name == ".debug_frame") { |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 348 | debug_frame_offset_ = shdr.sh_offset; |
| 349 | debug_frame_size_ = shdr.sh_size; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 350 | } else if (name == ".gnu_debugdata") { |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 351 | gnu_debugdata_offset_ = shdr.sh_offset; |
| 352 | gnu_debugdata_size_ = shdr.sh_size; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 353 | } else if (name == ".eh_frame") { |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 354 | eh_frame_offset_ = shdr.sh_offset; |
| 355 | eh_frame_size_ = shdr.sh_size; |
Christopher Ferris | c9dee84 | 2017-11-03 14:50:27 -0700 | [diff] [blame] | 356 | } else if (eh_frame_hdr_offset_ == 0 && name == ".eh_frame_hdr") { |
David Srbecky | 85b5fec | 2018-02-23 18:06:13 +0000 | [diff] [blame] | 357 | eh_frame_hdr_offset_ = shdr.sh_offset; |
| 358 | eh_frame_hdr_size_ = shdr.sh_size; |
| 359 | } else if (name == ".text") { |
| 360 | text_addr_ = shdr.sh_addr; |
| 361 | text_size_ = shdr.sh_size; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | } |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 365 | } else if (shdr.sh_type == SHT_STRTAB) { |
| 366 | // In order to read soname, keep track of address to offset mapping. |
| 367 | strtabs_.push_back(std::make_pair<uint64_t, uint64_t>(static_cast<uint64_t>(shdr.sh_addr), |
| 368 | static_cast<uint64_t>(shdr.sh_offset))); |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 369 | } else if (shdr.sh_type == SHT_NOTE) { |
| 370 | if (shdr.sh_name < sec_size) { |
| 371 | std::string name; |
| 372 | if (memory_->ReadString(sec_offset + shdr.sh_name, &name) && |
| 373 | name == ".note.gnu.build-id") { |
| 374 | gnu_build_id_offset_ = shdr.sh_offset; |
| 375 | gnu_build_id_size_ = shdr.sh_size; |
| 376 | } |
| 377 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 378 | } |
| 379 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | template <typename DynType> |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 383 | std::string ElfInterface::GetSonameWithTemplate() { |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 384 | if (soname_type_ == SONAME_INVALID) { |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 385 | return ""; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 386 | } |
| 387 | if (soname_type_ == SONAME_VALID) { |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 388 | return soname_; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | soname_type_ = SONAME_INVALID; |
| 392 | |
| 393 | uint64_t soname_offset = 0; |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 394 | uint64_t strtab_addr = 0; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 395 | uint64_t strtab_size = 0; |
| 396 | |
| 397 | // Find the soname location from the dynamic headers section. |
| 398 | DynType dyn; |
| 399 | uint64_t offset = dynamic_offset_; |
| 400 | uint64_t max_offset = offset + dynamic_size_; |
| 401 | for (uint64_t offset = dynamic_offset_; offset < max_offset; offset += sizeof(DynType)) { |
Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 402 | if (!memory_->ReadFully(offset, &dyn, sizeof(dyn))) { |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 403 | last_error_.code = ERROR_MEMORY_INVALID; |
| 404 | last_error_.address = offset; |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 405 | return ""; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | if (dyn.d_tag == DT_STRTAB) { |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 409 | strtab_addr = dyn.d_un.d_ptr; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 410 | } else if (dyn.d_tag == DT_STRSZ) { |
| 411 | strtab_size = dyn.d_un.d_val; |
| 412 | } else if (dyn.d_tag == DT_SONAME) { |
| 413 | soname_offset = dyn.d_un.d_val; |
| 414 | } else if (dyn.d_tag == DT_NULL) { |
| 415 | break; |
| 416 | } |
| 417 | } |
| 418 | |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 419 | // Need to map the strtab address to the real offset. |
| 420 | for (const auto& entry : strtabs_) { |
| 421 | if (entry.first == strtab_addr) { |
| 422 | soname_offset = entry.second + soname_offset; |
| 423 | if (soname_offset >= entry.second + strtab_size) { |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 424 | return ""; |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 425 | } |
| 426 | if (!memory_->ReadString(soname_offset, &soname_)) { |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 427 | return ""; |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 428 | } |
| 429 | soname_type_ = SONAME_VALID; |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 430 | return soname_; |
Christopher Ferris | beae42b | 2018-02-15 17:36:33 -0800 | [diff] [blame] | 431 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 432 | } |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 433 | return ""; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 436 | template <typename SymType> |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 437 | bool ElfInterface::GetFunctionNameWithTemplate(uint64_t addr, std::string* name, |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 438 | uint64_t* func_offset) { |
| 439 | if (symbols_.empty()) { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | for (const auto symbol : symbols_) { |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 444 | if (symbol->GetName<SymType>(addr, memory_, name, func_offset)) { |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 445 | return true; |
| 446 | } |
| 447 | } |
| 448 | return false; |
| 449 | } |
| 450 | |
Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 451 | template <typename SymType> |
| 452 | bool ElfInterface::GetGlobalVariableWithTemplate(const std::string& name, uint64_t* memory_address) { |
| 453 | if (symbols_.empty()) { |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | for (const auto symbol : symbols_) { |
| 458 | if (symbol->GetGlobal<SymType>(memory_, name, memory_address)) { |
| 459 | return true; |
| 460 | } |
| 461 | } |
| 462 | return false; |
| 463 | } |
| 464 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 465 | bool ElfInterface::Step(uint64_t pc, Regs* regs, Memory* process_memory, bool* finished) { |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 466 | last_error_.code = ERROR_NONE; |
| 467 | last_error_.address = 0; |
| 468 | |
Christopher Ferris | 1a141a0 | 2018-01-24 08:52:47 -0800 | [diff] [blame] | 469 | // Try the debug_frame first since it contains the most specific unwind |
| 470 | // information. |
| 471 | DwarfSection* debug_frame = debug_frame_.get(); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 472 | if (debug_frame != nullptr && debug_frame->Step(pc, regs, process_memory, finished)) { |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 473 | return true; |
| 474 | } |
| 475 | |
Christopher Ferris | 1a141a0 | 2018-01-24 08:52:47 -0800 | [diff] [blame] | 476 | // Try the eh_frame next. |
| 477 | DwarfSection* eh_frame = eh_frame_.get(); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 478 | if (eh_frame != nullptr && eh_frame->Step(pc, regs, process_memory, finished)) { |
Christopher Ferris | e7b6624 | 2017-12-15 11:17:45 -0800 | [diff] [blame] | 479 | return true; |
| 480 | } |
| 481 | |
Christopher Ferris | e7b6624 | 2017-12-15 11:17:45 -0800 | [diff] [blame] | 482 | if (gnu_debugdata_interface_ != nullptr && |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 483 | gnu_debugdata_interface_->Step(pc, regs, process_memory, finished)) { |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 484 | return true; |
| 485 | } |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 486 | |
| 487 | // Set the error code based on the first error encountered. |
| 488 | DwarfSection* section = nullptr; |
| 489 | if (debug_frame_ != nullptr) { |
| 490 | section = debug_frame_.get(); |
| 491 | } else if (eh_frame_ != nullptr) { |
| 492 | section = eh_frame_.get(); |
| 493 | } else if (gnu_debugdata_interface_ != nullptr) { |
| 494 | last_error_ = gnu_debugdata_interface_->last_error(); |
| 495 | return false; |
| 496 | } else { |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | // Convert the DWARF ERROR to an external error. |
| 501 | DwarfErrorCode code = section->LastErrorCode(); |
| 502 | switch (code) { |
| 503 | case DWARF_ERROR_NONE: |
| 504 | last_error_.code = ERROR_NONE; |
| 505 | break; |
| 506 | |
| 507 | case DWARF_ERROR_MEMORY_INVALID: |
| 508 | last_error_.code = ERROR_MEMORY_INVALID; |
| 509 | last_error_.address = section->LastErrorAddress(); |
| 510 | break; |
| 511 | |
| 512 | case DWARF_ERROR_ILLEGAL_VALUE: |
| 513 | case DWARF_ERROR_ILLEGAL_STATE: |
| 514 | case DWARF_ERROR_STACK_INDEX_NOT_VALID: |
| 515 | case DWARF_ERROR_TOO_MANY_ITERATIONS: |
| 516 | case DWARF_ERROR_CFA_NOT_DEFINED: |
| 517 | case DWARF_ERROR_NO_FDES: |
| 518 | last_error_.code = ERROR_UNWIND_INFO; |
| 519 | break; |
| 520 | |
| 521 | case DWARF_ERROR_NOT_IMPLEMENTED: |
| 522 | case DWARF_ERROR_UNSUPPORTED_VERSION: |
| 523 | last_error_.code = ERROR_UNSUPPORTED; |
| 524 | break; |
| 525 | } |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 526 | return false; |
| 527 | } |
| 528 | |
Christopher Ferris | 3f805ac | 2017-08-30 13:15:19 -0700 | [diff] [blame] | 529 | // This is an estimation of the size of the elf file using the location |
| 530 | // of the section headers and size. This assumes that the section headers |
| 531 | // are at the end of the elf file. If the elf has a load bias, the size |
| 532 | // will be too large, but this is acceptable. |
| 533 | template <typename EhdrType> |
| 534 | void ElfInterface::GetMaxSizeWithTemplate(Memory* memory, uint64_t* size) { |
| 535 | EhdrType ehdr; |
Josh Gao | ef35aa5 | 2017-10-18 11:44:51 -0700 | [diff] [blame] | 536 | if (!memory->ReadFully(0, &ehdr, sizeof(ehdr))) { |
Christopher Ferris | 3f805ac | 2017-08-30 13:15:19 -0700 | [diff] [blame] | 537 | return; |
| 538 | } |
| 539 | if (ehdr.e_shnum == 0) { |
| 540 | return; |
| 541 | } |
| 542 | *size = ehdr.e_shoff + ehdr.e_shentsize * ehdr.e_shnum; |
| 543 | } |
| 544 | |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 545 | template <typename EhdrType, typename ShdrType> |
| 546 | bool GetBuildIDInfo(Memory* memory, uint64_t* build_id_offset, uint64_t* build_id_size) { |
| 547 | EhdrType ehdr; |
| 548 | if (!memory->ReadFully(0, &ehdr, sizeof(ehdr))) { |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | uint64_t offset = ehdr.e_shoff; |
| 553 | uint64_t sec_offset; |
| 554 | uint64_t sec_size; |
| 555 | ShdrType shdr; |
| 556 | if (ehdr.e_shstrndx >= ehdr.e_shnum) { |
| 557 | return false; |
| 558 | } |
| 559 | |
| 560 | uint64_t sh_offset = offset + ehdr.e_shstrndx * ehdr.e_shentsize; |
| 561 | if (!memory->ReadFully(sh_offset, &shdr, sizeof(shdr))) { |
| 562 | return false; |
| 563 | } |
| 564 | sec_offset = shdr.sh_offset; |
| 565 | sec_size = shdr.sh_size; |
| 566 | |
| 567 | // Skip the first header, it's always going to be NULL. |
| 568 | offset += ehdr.e_shentsize; |
| 569 | for (size_t i = 1; i < ehdr.e_shnum; i++, offset += ehdr.e_shentsize) { |
| 570 | if (!memory->ReadFully(offset, &shdr, sizeof(shdr))) { |
| 571 | return false; |
| 572 | } |
| 573 | std::string name; |
| 574 | if (shdr.sh_type == SHT_NOTE && shdr.sh_name < sec_size && |
| 575 | memory->ReadString(sec_offset + shdr.sh_name, &name) && name == ".note.gnu.build-id") { |
| 576 | *build_id_offset = shdr.sh_offset; |
| 577 | *build_id_size = shdr.sh_size; |
| 578 | return true; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | template <typename EhdrType, typename ShdrType, typename NhdrType> |
| 586 | std::string ElfInterface::ReadBuildIDFromMemory(Memory* memory) { |
| 587 | uint64_t note_offset; |
| 588 | uint64_t note_size; |
| 589 | if (!GetBuildIDInfo<EhdrType, ShdrType>(memory, ¬e_offset, ¬e_size)) { |
| 590 | return ""; |
| 591 | } |
| 592 | |
| 593 | // Ensure there is no overflow in any of the calculations below. |
| 594 | uint64_t tmp; |
| 595 | if (__builtin_add_overflow(note_offset, note_size, &tmp)) { |
| 596 | return ""; |
| 597 | } |
| 598 | |
| 599 | uint64_t offset = 0; |
| 600 | while (offset < note_size) { |
| 601 | if (note_size - offset < sizeof(NhdrType)) { |
| 602 | return ""; |
| 603 | } |
| 604 | NhdrType hdr; |
| 605 | if (!memory->ReadFully(note_offset + offset, &hdr, sizeof(hdr))) { |
| 606 | return ""; |
| 607 | } |
| 608 | offset += sizeof(hdr); |
| 609 | |
| 610 | if (note_size - offset < hdr.n_namesz) { |
| 611 | return ""; |
| 612 | } |
| 613 | if (hdr.n_namesz > 0) { |
| 614 | std::string name(hdr.n_namesz, '\0'); |
| 615 | if (!memory->ReadFully(note_offset + offset, &(name[0]), hdr.n_namesz)) { |
| 616 | return ""; |
| 617 | } |
| 618 | |
| 619 | // Trim trailing \0 as GNU is stored as a C string in the ELF file. |
| 620 | if (name.back() == '\0') name.resize(name.size() - 1); |
| 621 | |
| 622 | // Align hdr.n_namesz to next power multiple of 4. See man 5 elf. |
| 623 | offset += (hdr.n_namesz + 3) & ~3; |
| 624 | |
| 625 | if (name == "GNU" && hdr.n_type == NT_GNU_BUILD_ID) { |
| 626 | if (note_size - offset < hdr.n_descsz || hdr.n_descsz == 0) { |
| 627 | return ""; |
| 628 | } |
| 629 | std::string build_id(hdr.n_descsz - 1, '\0'); |
| 630 | if (memory->ReadFully(note_offset + offset, &build_id[0], hdr.n_descsz)) { |
| 631 | return build_id; |
| 632 | } |
| 633 | return ""; |
| 634 | } |
| 635 | } |
| 636 | // Align hdr.n_descsz to next power multiple of 4. See man 5 elf. |
| 637 | offset += (hdr.n_descsz + 3) & ~3; |
| 638 | } |
| 639 | return ""; |
| 640 | } |
| 641 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 642 | // Instantiate all of the needed template functions. |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 643 | template void ElfInterface::InitHeadersWithTemplate<uint32_t>(uint64_t); |
| 644 | template void ElfInterface::InitHeadersWithTemplate<uint64_t>(uint64_t); |
Christopher Ferris | 61d4097 | 2017-06-12 19:14:20 -0700 | [diff] [blame] | 645 | |
Christopher Ferris | e69f470 | 2017-10-19 16:08:58 -0700 | [diff] [blame] | 646 | template bool ElfInterface::ReadAllHeaders<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr>(uint64_t*); |
| 647 | template bool ElfInterface::ReadAllHeaders<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr>(uint64_t*); |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 648 | |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 649 | template void ElfInterface::ReadProgramHeaders<Elf32_Ehdr, Elf32_Phdr>(const Elf32_Ehdr&, |
| 650 | uint64_t*); |
| 651 | template void ElfInterface::ReadProgramHeaders<Elf64_Ehdr, Elf64_Phdr>(const Elf64_Ehdr&, |
| 652 | uint64_t*); |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 653 | |
Christopher Ferris | 5acf069 | 2018-08-01 13:10:46 -0700 | [diff] [blame] | 654 | template void ElfInterface::ReadSectionHeaders<Elf32_Ehdr, Elf32_Shdr>(const Elf32_Ehdr&); |
| 655 | template void ElfInterface::ReadSectionHeaders<Elf64_Ehdr, Elf64_Shdr>(const Elf64_Ehdr&); |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 656 | |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 657 | template std::string ElfInterface::ReadBuildID<Elf32_Nhdr>(); |
| 658 | template std::string ElfInterface::ReadBuildID<Elf64_Nhdr>(); |
Florian Mayer | da459e5 | 2018-11-23 16:56:17 +0000 | [diff] [blame] | 659 | |
Christopher Ferris | 02a6c44 | 2019-03-11 14:43:33 -0700 | [diff] [blame] | 660 | template std::string ElfInterface::GetSonameWithTemplate<Elf32_Dyn>(); |
| 661 | template std::string ElfInterface::GetSonameWithTemplate<Elf64_Dyn>(); |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 662 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 663 | template bool ElfInterface::GetFunctionNameWithTemplate<Elf32_Sym>(uint64_t, std::string*, |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 664 | uint64_t*); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 665 | template bool ElfInterface::GetFunctionNameWithTemplate<Elf64_Sym>(uint64_t, std::string*, |
Christopher Ferris | 8098b1c | 2017-06-20 13:54:08 -0700 | [diff] [blame] | 666 | uint64_t*); |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 667 | |
Christopher Ferris | 150db12 | 2017-12-20 18:49:01 -0800 | [diff] [blame] | 668 | template bool ElfInterface::GetGlobalVariableWithTemplate<Elf32_Sym>(const std::string&, uint64_t*); |
| 669 | template bool ElfInterface::GetGlobalVariableWithTemplate<Elf64_Sym>(const std::string&, uint64_t*); |
| 670 | |
Christopher Ferris | 3f805ac | 2017-08-30 13:15:19 -0700 | [diff] [blame] | 671 | template void ElfInterface::GetMaxSizeWithTemplate<Elf32_Ehdr>(Memory*, uint64_t*); |
| 672 | template void ElfInterface::GetMaxSizeWithTemplate<Elf64_Ehdr>(Memory*, uint64_t*); |
| 673 | |
Christopher Ferris | b7de5f5 | 2017-12-01 21:37:37 -0800 | [diff] [blame] | 674 | template uint64_t ElfInterface::GetLoadBias<Elf32_Ehdr, Elf32_Phdr>(Memory*); |
| 675 | template uint64_t ElfInterface::GetLoadBias<Elf64_Ehdr, Elf64_Phdr>(Memory*); |
| 676 | |
Christopher Ferris | bf373ed | 2019-01-16 17:23:39 -0800 | [diff] [blame] | 677 | template std::string ElfInterface::ReadBuildIDFromMemory<Elf32_Ehdr, Elf32_Shdr, Elf32_Nhdr>( |
| 678 | Memory*); |
| 679 | template std::string ElfInterface::ReadBuildIDFromMemory<Elf64_Ehdr, Elf64_Shdr, Elf64_Nhdr>( |
| 680 | Memory*); |
| 681 | |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 682 | } // namespace unwindstack |