Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "dso.h" |
| 18 | |
Yabin Cui | b378355 | 2015-06-11 11:15:42 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 20 | #include <string.h> |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 21 | |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 22 | #include <algorithm> |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 23 | #include <limits> |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 24 | #include <vector> |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 25 | |
Elliott Hughes | 66dd09e | 2015-12-04 14:00:57 -0800 | [diff] [blame] | 26 | #include <android-base/logging.h> |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 27 | |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 28 | #include "environment.h" |
Yabin Cui | 7288501 | 2016-02-14 19:18:02 -0800 | [diff] [blame^] | 29 | #include "read_apk.h" |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 30 | #include "read_elf.h" |
Yabin Cui | b378355 | 2015-06-11 11:15:42 -0700 | [diff] [blame] | 31 | #include "utils.h" |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 32 | |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 33 | static OneTimeFreeAllocator symbol_name_allocator; |
| 34 | |
| 35 | Symbol::Symbol(const std::string& name, uint64_t addr, uint64_t len) |
| 36 | : addr(addr), |
| 37 | len(len), |
| 38 | name_(symbol_name_allocator.AllocateString(name)), |
| 39 | demangled_name_(nullptr) { |
Yabin Cui | b10a8fb | 2015-08-18 16:32:18 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 42 | const char* Symbol::DemangledName() const { |
| 43 | if (demangled_name_ == nullptr) { |
| 44 | const std::string s = Dso::Demangle(name_); |
| 45 | if (s == name_) { |
| 46 | demangled_name_ = name_; |
| 47 | } else { |
| 48 | demangled_name_ = symbol_name_allocator.AllocateString(s); |
| 49 | } |
| 50 | } |
| 51 | return demangled_name_; |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 54 | bool Dso::demangle_ = true; |
| 55 | std::string Dso::symfs_dir_; |
| 56 | std::string Dso::vmlinux_; |
| 57 | std::unordered_map<std::string, BuildId> Dso::build_id_map_; |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 58 | size_t Dso::dso_count_; |
Yabin Cui | ba50c4b | 2015-07-21 11:24:48 -0700 | [diff] [blame] | 59 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 60 | void Dso::SetDemangle(bool demangle) { |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 61 | demangle_ = demangle; |
| 62 | } |
Yabin Cui | b378355 | 2015-06-11 11:15:42 -0700 | [diff] [blame] | 63 | |
Yabin Cui | b10a8fb | 2015-08-18 16:32:18 -0700 | [diff] [blame] | 64 | extern "C" char* __cxa_demangle(const char* mangled_name, char* buf, size_t* n, int* status); |
| 65 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 66 | std::string Dso::Demangle(const std::string& name) { |
Yabin Cui | b10a8fb | 2015-08-18 16:32:18 -0700 | [diff] [blame] | 67 | if (!demangle_) { |
| 68 | return name; |
| 69 | } |
| 70 | int status; |
| 71 | bool is_linker_symbol = (name.find(linker_prefix) == 0); |
| 72 | const char* mangled_str = name.c_str(); |
| 73 | if (is_linker_symbol) { |
| 74 | mangled_str += linker_prefix.size(); |
| 75 | } |
| 76 | std::string result = name; |
| 77 | char* demangled_name = __cxa_demangle(mangled_str, nullptr, nullptr, &status); |
| 78 | if (status == 0) { |
| 79 | if (is_linker_symbol) { |
| 80 | result = std::string("[linker]") + demangled_name; |
| 81 | } else { |
| 82 | result = demangled_name; |
| 83 | } |
| 84 | free(demangled_name); |
| 85 | } else if (is_linker_symbol) { |
| 86 | result = std::string("[linker]") + mangled_str; |
| 87 | } |
| 88 | return result; |
| 89 | } |
| 90 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 91 | bool Dso::SetSymFsDir(const std::string& symfs_dir) { |
| 92 | std::string dirname = symfs_dir; |
| 93 | if (!dirname.empty()) { |
| 94 | if (dirname.back() != '/') { |
| 95 | dirname.push_back('/'); |
| 96 | } |
| 97 | std::vector<std::string> files; |
| 98 | std::vector<std::string> subdirs; |
| 99 | GetEntriesInDir(symfs_dir, &files, &subdirs); |
| 100 | if (files.empty() && subdirs.empty()) { |
| 101 | LOG(ERROR) << "Invalid symfs_dir '" << symfs_dir << "'"; |
Yabin Cui | ba50c4b | 2015-07-21 11:24:48 -0700 | [diff] [blame] | 102 | return false; |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 103 | } |
Yabin Cui | ba50c4b | 2015-07-21 11:24:48 -0700 | [diff] [blame] | 104 | } |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 105 | symfs_dir_ = dirname; |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | void Dso::SetVmlinux(const std::string& vmlinux) { |
| 110 | vmlinux_ = vmlinux; |
| 111 | } |
| 112 | |
| 113 | void Dso::SetBuildIds(const std::vector<std::pair<std::string, BuildId>>& build_ids) { |
| 114 | std::unordered_map<std::string, BuildId> map; |
| 115 | for (auto& pair : build_ids) { |
| 116 | LOG(DEBUG) << "build_id_map: " << pair.first << ", " << pair.second.ToString(); |
| 117 | map.insert(pair); |
| 118 | } |
| 119 | build_id_map_ = std::move(map); |
| 120 | } |
| 121 | |
| 122 | BuildId Dso::GetExpectedBuildId(const std::string& filename) { |
| 123 | auto it = build_id_map_.find(filename); |
| 124 | if (it != build_id_map_.end()) { |
| 125 | return it->second; |
| 126 | } |
| 127 | return BuildId(); |
| 128 | } |
| 129 | |
| 130 | std::unique_ptr<Dso> Dso::CreateDso(DsoType dso_type, const std::string& dso_path) { |
| 131 | std::string path = dso_path; |
| 132 | if (dso_type == DSO_KERNEL) { |
| 133 | path = "[kernel.kallsyms]"; |
| 134 | } |
| 135 | return std::unique_ptr<Dso>(new Dso(dso_type, path)); |
| 136 | } |
| 137 | |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 138 | Dso::Dso(DsoType type, const std::string& path) |
| 139 | : type_(type), path_(path), min_vaddr_(std::numeric_limits<uint64_t>::max()), is_loaded_(false) { |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 140 | dso_count_++; |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 143 | Dso::~Dso() { |
| 144 | if (--dso_count_ == 0) { |
| 145 | symbol_name_allocator.Clear(); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | struct SymbolComparator { |
| 150 | bool operator()(const Symbol& symbol1, const Symbol& symbol2) { |
| 151 | return symbol1.addr < symbol2.addr; |
| 152 | } |
| 153 | }; |
| 154 | |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 155 | std::string Dso::GetAccessiblePath() const { |
| 156 | return symfs_dir_ + path_; |
| 157 | } |
| 158 | |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 159 | const Symbol* Dso::FindSymbol(uint64_t vaddr_in_dso) { |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 160 | if (!is_loaded_) { |
| 161 | is_loaded_ = true; |
| 162 | if (!Load()) { |
| 163 | LOG(DEBUG) << "failed to load dso: " << path_; |
| 164 | return nullptr; |
| 165 | } |
| 166 | } |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 167 | |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 168 | auto it = std::upper_bound(symbols_.begin(), symbols_.end(), Symbol("", vaddr_in_dso, 0), |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 169 | SymbolComparator()); |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 170 | if (it != symbols_.begin()) { |
| 171 | --it; |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 172 | if (it->addr <= vaddr_in_dso && it->addr + it->len > vaddr_in_dso) { |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 173 | return &*it; |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | return nullptr; |
| 177 | } |
| 178 | |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 179 | uint64_t Dso::MinVirtualAddress() { |
| 180 | if (min_vaddr_ == std::numeric_limits<uint64_t>::max()) { |
| 181 | min_vaddr_ = 0; |
| 182 | if (type_ == DSO_ELF_FILE) { |
| 183 | BuildId build_id = GetExpectedBuildId(GetAccessiblePath()); |
| 184 | |
| 185 | uint64_t addr; |
| 186 | if (ReadMinExecutableVirtualAddressFromElfFile(GetAccessiblePath(), build_id, &addr)) { |
| 187 | min_vaddr_ = addr; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | return min_vaddr_; |
| 192 | } |
| 193 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 194 | bool Dso::Load() { |
| 195 | bool result = false; |
| 196 | switch (type_) { |
| 197 | case DSO_KERNEL: |
| 198 | result = LoadKernel(); |
| 199 | break; |
| 200 | case DSO_KERNEL_MODULE: |
| 201 | result = LoadKernelModule(); |
| 202 | break; |
Yabin Cui | 7288501 | 2016-02-14 19:18:02 -0800 | [diff] [blame^] | 203 | case DSO_ELF_FILE: { |
| 204 | if (std::get<0>(SplitUrlInApk(path_))) { |
| 205 | result = LoadEmbeddedElfFile(); |
| 206 | } else { |
| 207 | result = LoadElfFile(); |
| 208 | } |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 209 | break; |
Yabin Cui | 7288501 | 2016-02-14 19:18:02 -0800 | [diff] [blame^] | 210 | } |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 211 | } |
| 212 | if (result) { |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 213 | std::sort(symbols_.begin(), symbols_.end(), SymbolComparator()); |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 214 | FixupSymbolLength(); |
| 215 | } |
| 216 | return result; |
Yabin Cui | ba50c4b | 2015-07-21 11:24:48 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 219 | static bool IsKernelFunctionSymbol(const KernelSymbol& symbol) { |
| 220 | return (symbol.type == 'T' || symbol.type == 't' || symbol.type == 'W' || symbol.type == 'w'); |
| 221 | } |
| 222 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 223 | bool Dso::KernelSymbolCallback(const KernelSymbol& kernel_symbol, Dso* dso) { |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 224 | if (IsKernelFunctionSymbol(kernel_symbol)) { |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 225 | dso->InsertSymbol(Symbol(kernel_symbol.name, kernel_symbol.addr, 0)); |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 226 | } |
| 227 | return false; |
| 228 | } |
| 229 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 230 | void Dso::VmlinuxSymbolCallback(const ElfFileSymbol& elf_symbol, Dso* dso) { |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 231 | if (elf_symbol.is_func) { |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 232 | dso->InsertSymbol(Symbol(elf_symbol.name, elf_symbol.vaddr, elf_symbol.len)); |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 236 | bool Dso::LoadKernel() { |
Yabin Cui | 638c558 | 2015-07-01 16:16:57 -0700 | [diff] [blame] | 237 | BuildId build_id = GetExpectedBuildId(DEFAULT_KERNEL_FILENAME_FOR_BUILD_ID); |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 238 | if (!vmlinux_.empty()) { |
| 239 | ParseSymbolsFromElfFile(vmlinux_, build_id, |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 240 | std::bind(VmlinuxSymbolCallback, std::placeholders::_1, this)); |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 241 | } else { |
Yabin Cui | 04c70a6 | 2015-08-04 14:48:39 -0700 | [diff] [blame] | 242 | if (!build_id.IsEmpty()) { |
| 243 | BuildId real_build_id; |
| 244 | GetKernelBuildId(&real_build_id); |
| 245 | bool match = (build_id == real_build_id); |
| 246 | LOG(DEBUG) << "check kernel build id (" << (match ? "match" : "mismatch") << "): expected " |
| 247 | << build_id.ToString() << ", real " << real_build_id.ToString(); |
| 248 | if (!match) { |
| 249 | return false; |
| 250 | } |
Yabin Cui | 39d3cae | 2015-07-13 16:23:13 -0700 | [diff] [blame] | 251 | } |
Yabin Cui | 8a52e97 | 2015-10-01 11:32:44 -0700 | [diff] [blame] | 252 | |
Yabin Cui | 04c70a6 | 2015-08-04 14:48:39 -0700 | [diff] [blame] | 253 | ProcessKernelSymbols("/proc/kallsyms", |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 254 | std::bind(&KernelSymbolCallback, std::placeholders::_1, this)); |
Yabin Cui | 8a52e97 | 2015-10-01 11:32:44 -0700 | [diff] [blame] | 255 | bool allZero = true; |
| 256 | for (auto& symbol : symbols_) { |
| 257 | if (symbol.addr != 0) { |
| 258 | allZero = false; |
| 259 | break; |
| 260 | } |
| 261 | } |
| 262 | if (allZero) { |
| 263 | LOG(WARNING) << "Symbol addresses in /proc/kallsyms are all zero. Check " |
| 264 | "/proc/sys/kernel/kptr_restrict if possible."; |
| 265 | symbols_.clear(); |
| 266 | return false; |
| 267 | } |
Yabin Cui | 638c558 | 2015-07-01 16:16:57 -0700 | [diff] [blame] | 268 | } |
Yabin Cui | 04c70a6 | 2015-08-04 14:48:39 -0700 | [diff] [blame] | 269 | return true; |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 272 | void Dso::ElfFileSymbolCallback(const ElfFileSymbol& elf_symbol, Dso* dso, |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 273 | bool (*filter)(const ElfFileSymbol&)) { |
| 274 | if (filter(elf_symbol)) { |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 275 | dso->InsertSymbol(Symbol(elf_symbol.name, elf_symbol.vaddr, elf_symbol.len)); |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | static bool SymbolFilterForKernelModule(const ElfFileSymbol& elf_symbol) { |
| 280 | // TODO: Parse symbol outside of .text section. |
| 281 | return (elf_symbol.is_func && elf_symbol.is_in_text_section); |
| 282 | } |
| 283 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 284 | bool Dso::LoadKernelModule() { |
| 285 | BuildId build_id = GetExpectedBuildId(path_); |
Yabin Cui | ba50c4b | 2015-07-21 11:24:48 -0700 | [diff] [blame] | 286 | ParseSymbolsFromElfFile( |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 287 | symfs_dir_ + path_, build_id, |
| 288 | std::bind(ElfFileSymbolCallback, std::placeholders::_1, this, SymbolFilterForKernelModule)); |
Yabin Cui | 04c70a6 | 2015-08-04 14:48:39 -0700 | [diff] [blame] | 289 | return true; |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static bool SymbolFilterForDso(const ElfFileSymbol& elf_symbol) { |
Yabin Cui | b378355 | 2015-06-11 11:15:42 -0700 | [diff] [blame] | 293 | return elf_symbol.is_func || (elf_symbol.is_label && elf_symbol.is_in_text_section); |
| 294 | } |
| 295 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 296 | bool Dso::LoadElfFile() { |
Yabin Cui | 547c60e | 2015-10-12 16:56:05 -0700 | [diff] [blame] | 297 | bool loaded = false; |
| 298 | BuildId build_id = GetExpectedBuildId(GetAccessiblePath()); |
| 299 | |
| 300 | if (symfs_dir_.empty()) { |
| 301 | // Linux host can store debug shared libraries in /usr/lib/debug. |
| 302 | loaded = ParseSymbolsFromElfFile( |
| 303 | "/usr/lib/debug" + path_, build_id, |
| 304 | std::bind(ElfFileSymbolCallback, std::placeholders::_1, this, SymbolFilterForDso)); |
| 305 | } |
| 306 | if (!loaded) { |
| 307 | loaded = ParseSymbolsFromElfFile( |
| 308 | GetAccessiblePath(), build_id, |
| 309 | std::bind(ElfFileSymbolCallback, std::placeholders::_1, this, SymbolFilterForDso)); |
| 310 | } |
| 311 | return loaded; |
Yabin Cui | ec12ed9 | 2015-06-08 10:38:10 -0700 | [diff] [blame] | 312 | } |
Yabin Cui | 638c558 | 2015-07-01 16:16:57 -0700 | [diff] [blame] | 313 | |
Yabin Cui | 7288501 | 2016-02-14 19:18:02 -0800 | [diff] [blame^] | 314 | bool Dso::LoadEmbeddedElfFile() { |
| 315 | std::string path = GetAccessiblePath(); |
| 316 | BuildId build_id = GetExpectedBuildId(path); |
| 317 | auto tuple = SplitUrlInApk(path); |
| 318 | CHECK(std::get<0>(tuple)); |
| 319 | return ParseSymbolsFromApkFile(std::get<1>(tuple), std::get<2>(tuple), build_id, |
| 320 | std::bind(ElfFileSymbolCallback, std::placeholders::_1, |
| 321 | this, SymbolFilterForDso)); |
| 322 | } |
| 323 | |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 324 | void Dso::InsertSymbol(const Symbol& symbol) { |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 325 | symbols_.push_back(symbol); |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void Dso::FixupSymbolLength() { |
| 329 | Symbol* prev_symbol = nullptr; |
| 330 | for (auto& symbol : symbols_) { |
| 331 | if (prev_symbol != nullptr && prev_symbol->len == 0) { |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 332 | prev_symbol->len = symbol.addr - prev_symbol->addr; |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 333 | } |
Yabin Cui | cc2e59e | 2015-08-21 14:23:43 -0700 | [diff] [blame] | 334 | prev_symbol = &symbol; |
Yabin Cui | 638c558 | 2015-07-01 16:16:57 -0700 | [diff] [blame] | 335 | } |
Yabin Cui | c848560 | 2015-08-20 15:04:39 -0700 | [diff] [blame] | 336 | if (prev_symbol != nullptr && prev_symbol->len == 0) { |
| 337 | prev_symbol->len = std::numeric_limits<unsigned long long>::max() - prev_symbol->addr; |
| 338 | } |
Yabin Cui | 638c558 | 2015-07-01 16:16:57 -0700 | [diff] [blame] | 339 | } |