Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 1 | //===- SymbolizableObjectFile.cpp -----------------------------------------===// |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Implementation of SymbolizableObjectFile class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "SymbolizableObjectFile.h" |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/STLExtras.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include "llvm/ADT/Triple.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 17 | #include "llvm/BinaryFormat/COFF.h" |
Reid Kleckner | c038e2d | 2015-11-13 17:00:36 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" |
| 20 | #include "llvm/Object/COFF.h" |
| 21 | #include "llvm/Object/ObjectFile.h" |
| 22 | #include "llvm/Object/SymbolSize.h" |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Casting.h" |
| 24 | #include "llvm/Support/DataExtractor.h" |
| 25 | #include "llvm/Support/Error.h" |
| 26 | #include <algorithm> |
| 27 | #include <cstdint> |
| 28 | #include <memory> |
| 29 | #include <string> |
| 30 | #include <system_error> |
| 31 | #include <utility> |
| 32 | #include <vector> |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 33 | |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 34 | using namespace llvm; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 35 | using namespace object; |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 36 | using namespace symbolize; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 37 | |
| 38 | static DILineInfoSpecifier |
| 39 | getDILineInfoSpecifier(FunctionNameKind FNKind) { |
| 40 | return DILineInfoSpecifier( |
| 41 | DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FNKind); |
| 42 | } |
| 43 | |
| 44 | ErrorOr<std::unique_ptr<SymbolizableObjectFile>> |
| 45 | SymbolizableObjectFile::create(object::ObjectFile *Obj, |
| 46 | std::unique_ptr<DIContext> DICtx) { |
| 47 | std::unique_ptr<SymbolizableObjectFile> res( |
| 48 | new SymbolizableObjectFile(Obj, std::move(DICtx))); |
| 49 | std::unique_ptr<DataExtractor> OpdExtractor; |
| 50 | uint64_t OpdAddress = 0; |
| 51 | // Find the .opd (function descriptor) section if any, for big-endian |
| 52 | // PowerPC64 ELF. |
| 53 | if (Obj->getArch() == Triple::ppc64) { |
| 54 | for (section_iterator Section : Obj->sections()) { |
| 55 | StringRef Name; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 56 | if (auto EC = Section->getName(Name)) |
| 57 | return EC; |
| 58 | if (Name == ".opd") { |
Fangrui Song | a076ec5 | 2019-05-16 11:33:48 +0000 | [diff] [blame] | 59 | Expected<StringRef> E = Section->getContents(); |
| 60 | if (!E) |
| 61 | return errorToErrorCode(E.takeError()); |
| 62 | OpdExtractor.reset(new DataExtractor(*E, Obj->isLittleEndian(), |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 63 | Obj->getBytesInAddress())); |
| 64 | OpdAddress = Section->getAddress(); |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | std::vector<std::pair<SymbolRef, uint64_t>> Symbols = |
| 70 | computeSymbolSizes(*Obj); |
| 71 | for (auto &P : Symbols) |
| 72 | res->addSymbol(P.first, P.second, OpdExtractor.get(), OpdAddress); |
| 73 | |
| 74 | // If this is a COFF object and we didn't find any symbols, try the export |
| 75 | // table. |
| 76 | if (Symbols.empty()) { |
| 77 | if (auto *CoffObj = dyn_cast<COFFObjectFile>(Obj)) |
| 78 | if (auto EC = res->addCoffExportSymbols(CoffObj)) |
| 79 | return EC; |
| 80 | } |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 81 | |
| 82 | std::vector<std::pair<SymbolDesc, StringRef>> &Fs = res->Functions, |
| 83 | &Os = res->Objects; |
Fangrui Song | cb300f1 | 2019-04-06 02:18:56 +0000 | [diff] [blame] | 84 | auto Uniquify = [](std::vector<std::pair<SymbolDesc, StringRef>> &S) { |
| 85 | // Sort by (Addr,Size,Name). If several SymbolDescs share the same Addr, |
| 86 | // pick the one with the largest Size. This helps us avoid symbols with no |
| 87 | // size information (Size=0). |
| 88 | llvm::sort(S); |
| 89 | auto I = S.begin(), E = S.end(), J = S.begin(); |
| 90 | while (I != E) { |
| 91 | auto OI = I; |
| 92 | while (++I != E && OI->first.Addr == I->first.Addr) { |
| 93 | } |
| 94 | *J++ = I[-1]; |
| 95 | } |
| 96 | S.erase(J, S.end()); |
| 97 | }; |
| 98 | Uniquify(Fs); |
| 99 | Uniquify(Os); |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 100 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 101 | return std::move(res); |
| 102 | } |
| 103 | |
| 104 | SymbolizableObjectFile::SymbolizableObjectFile(ObjectFile *Obj, |
| 105 | std::unique_ptr<DIContext> DICtx) |
| 106 | : Module(Obj), DebugInfoContext(std::move(DICtx)) {} |
| 107 | |
| 108 | namespace { |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 109 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 110 | struct OffsetNamePair { |
| 111 | uint32_t Offset; |
| 112 | StringRef Name; |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 113 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 114 | bool operator<(const OffsetNamePair &R) const { |
| 115 | return Offset < R.Offset; |
| 116 | } |
| 117 | }; |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 118 | |
| 119 | } // end anonymous namespace |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 120 | |
| 121 | std::error_code SymbolizableObjectFile::addCoffExportSymbols( |
| 122 | const COFFObjectFile *CoffObj) { |
| 123 | // Get all export names and offsets. |
| 124 | std::vector<OffsetNamePair> ExportSyms; |
| 125 | for (const ExportDirectoryEntryRef &Ref : CoffObj->export_directories()) { |
| 126 | StringRef Name; |
| 127 | uint32_t Offset; |
| 128 | if (auto EC = Ref.getSymbolName(Name)) |
| 129 | return EC; |
| 130 | if (auto EC = Ref.getExportRVA(Offset)) |
| 131 | return EC; |
| 132 | ExportSyms.push_back(OffsetNamePair{Offset, Name}); |
| 133 | } |
| 134 | if (ExportSyms.empty()) |
| 135 | return std::error_code(); |
| 136 | |
| 137 | // Sort by ascending offset. |
| 138 | array_pod_sort(ExportSyms.begin(), ExportSyms.end()); |
| 139 | |
| 140 | // Approximate the symbol sizes by assuming they run to the next symbol. |
| 141 | // FIXME: This assumes all exports are functions. |
| 142 | uint64_t ImageBase = CoffObj->getImageBase(); |
| 143 | for (auto I = ExportSyms.begin(), E = ExportSyms.end(); I != E; ++I) { |
| 144 | OffsetNamePair &Export = *I; |
| 145 | // FIXME: The last export has a one byte size now. |
| 146 | uint32_t NextOffset = I != E ? I->Offset : Export.Offset + 1; |
| 147 | uint64_t SymbolStart = ImageBase + Export.Offset; |
| 148 | uint64_t SymbolSize = NextOffset - Export.Offset; |
| 149 | SymbolDesc SD = {SymbolStart, SymbolSize}; |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 150 | Functions.emplace_back(SD, Export.Name); |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 151 | } |
| 152 | return std::error_code(); |
| 153 | } |
| 154 | |
| 155 | std::error_code SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol, |
| 156 | uint64_t SymbolSize, |
| 157 | DataExtractor *OpdExtractor, |
| 158 | uint64_t OpdAddress) { |
Matt Davis | 123be5d | 2019-02-14 23:50:35 +0000 | [diff] [blame] | 159 | // Avoid adding symbols from an unknown/undefined section. |
| 160 | const ObjectFile *Obj = Symbol.getObject(); |
| 161 | Expected<section_iterator> Sec = Symbol.getSection(); |
| 162 | if (!Sec || (Obj && Obj->section_end() == *Sec)) |
| 163 | return std::error_code(); |
Kevin Enderby | 7bd8d99 | 2016-05-02 20:28:12 +0000 | [diff] [blame] | 164 | Expected<SymbolRef::Type> SymbolTypeOrErr = Symbol.getType(); |
| 165 | if (!SymbolTypeOrErr) |
| 166 | return errorToErrorCode(SymbolTypeOrErr.takeError()); |
Kevin Enderby | 5afbc1c | 2016-03-23 20:27:00 +0000 | [diff] [blame] | 167 | SymbolRef::Type SymbolType = *SymbolTypeOrErr; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 168 | if (SymbolType != SymbolRef::ST_Function && SymbolType != SymbolRef::ST_Data) |
| 169 | return std::error_code(); |
Kevin Enderby | 931cb65 | 2016-06-24 18:24:42 +0000 | [diff] [blame] | 170 | Expected<uint64_t> SymbolAddressOrErr = Symbol.getAddress(); |
| 171 | if (!SymbolAddressOrErr) |
| 172 | return errorToErrorCode(SymbolAddressOrErr.takeError()); |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 173 | uint64_t SymbolAddress = *SymbolAddressOrErr; |
| 174 | if (OpdExtractor) { |
| 175 | // For big-endian PowerPC64 ELF, symbols in the .opd section refer to |
| 176 | // function descriptors. The first word of the descriptor is a pointer to |
| 177 | // the function's code. |
| 178 | // For the purposes of symbolization, pretend the symbol's address is that |
| 179 | // of the function's code, not the descriptor. |
| 180 | uint64_t OpdOffset = SymbolAddress - OpdAddress; |
| 181 | uint32_t OpdOffset32 = OpdOffset; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 182 | if (OpdOffset == OpdOffset32 && |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 183 | OpdExtractor->isValidOffsetForAddress(OpdOffset32)) |
| 184 | SymbolAddress = OpdExtractor->getAddress(&OpdOffset32); |
| 185 | } |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame] | 186 | Expected<StringRef> SymbolNameOrErr = Symbol.getName(); |
| 187 | if (!SymbolNameOrErr) |
| 188 | return errorToErrorCode(SymbolNameOrErr.takeError()); |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 189 | StringRef SymbolName = *SymbolNameOrErr; |
| 190 | // Mach-O symbol table names have leading underscore, skip it. |
Eugene Zelenko | 44d9512 | 2017-02-09 01:09:54 +0000 | [diff] [blame] | 191 | if (Module->isMachO() && !SymbolName.empty() && SymbolName[0] == '_') |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 192 | SymbolName = SymbolName.drop_front(); |
| 193 | // FIXME: If a function has alias, there are two entries in symbol table |
| 194 | // with same address size. Make sure we choose the correct one. |
| 195 | auto &M = SymbolType == SymbolRef::ST_Function ? Functions : Objects; |
| 196 | SymbolDesc SD = { SymbolAddress, SymbolSize }; |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 197 | M.emplace_back(SD, SymbolName); |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 198 | return std::error_code(); |
| 199 | } |
| 200 | |
| 201 | // Return true if this is a 32-bit x86 PE COFF module. |
| 202 | bool SymbolizableObjectFile::isWin32Module() const { |
| 203 | auto *CoffObject = dyn_cast<COFFObjectFile>(Module); |
| 204 | return CoffObject && CoffObject->getMachine() == COFF::IMAGE_FILE_MACHINE_I386; |
| 205 | } |
| 206 | |
| 207 | uint64_t SymbolizableObjectFile::getModulePreferredBase() const { |
| 208 | if (auto *CoffObject = dyn_cast<COFFObjectFile>(Module)) |
| 209 | return CoffObject->getImageBase(); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | bool SymbolizableObjectFile::getNameFromSymbolTable(SymbolRef::Type Type, |
| 214 | uint64_t Address, |
| 215 | std::string &Name, |
| 216 | uint64_t &Addr, |
| 217 | uint64_t &Size) const { |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 218 | const auto &Symbols = Type == SymbolRef::ST_Function ? Functions : Objects; |
| 219 | std::pair<SymbolDesc, StringRef> SD{{Address, UINT64_C(-1)}, StringRef()}; |
Fangrui Song | afb54fd | 2019-04-05 12:52:04 +0000 | [diff] [blame] | 220 | auto SymbolIterator = llvm::upper_bound(Symbols, SD); |
| 221 | if (SymbolIterator == Symbols.begin()) |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 222 | return false; |
| 223 | --SymbolIterator; |
| 224 | if (SymbolIterator->first.Size != 0 && |
| 225 | SymbolIterator->first.Addr + SymbolIterator->first.Size <= Address) |
| 226 | return false; |
| 227 | Name = SymbolIterator->second.str(); |
| 228 | Addr = SymbolIterator->first.Addr; |
| 229 | Size = SymbolIterator->first.Size; |
| 230 | return true; |
| 231 | } |
| 232 | |
Reid Kleckner | c038e2d | 2015-11-13 17:00:36 +0000 | [diff] [blame] | 233 | bool SymbolizableObjectFile::shouldOverrideWithSymbolTable( |
| 234 | FunctionNameKind FNKind, bool UseSymbolTable) const { |
| 235 | // When DWARF is used with -gline-tables-only / -gmlt, the symbol table gives |
| 236 | // better answers for linkage names than the DIContext. Otherwise, we are |
| 237 | // probably using PEs and PDBs, and we shouldn't do the override. PE files |
| 238 | // generally only contain the names of exported symbols. |
| 239 | return FNKind == FunctionNameKind::LinkageName && UseSymbolTable && |
| 240 | isa<DWARFContext>(DebugInfoContext.get()); |
| 241 | } |
| 242 | |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 243 | DILineInfo |
| 244 | SymbolizableObjectFile::symbolizeCode(object::SectionedAddress ModuleOffset, |
| 245 | FunctionNameKind FNKind, |
| 246 | bool UseSymbolTable) const { |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 247 | DILineInfo LineInfo; |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 248 | |
| 249 | if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection) |
| 250 | ModuleOffset.SectionIndex = |
| 251 | getModuleSectionIndexForAddress(ModuleOffset.Address); |
| 252 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 253 | if (DebugInfoContext) { |
| 254 | LineInfo = DebugInfoContext->getLineInfoForAddress( |
| 255 | ModuleOffset, getDILineInfoSpecifier(FNKind)); |
| 256 | } |
| 257 | // Override function name from symbol table if necessary. |
Reid Kleckner | c038e2d | 2015-11-13 17:00:36 +0000 | [diff] [blame] | 258 | if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) { |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 259 | std::string FunctionName; |
| 260 | uint64_t Start, Size; |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 261 | if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address, |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 262 | FunctionName, Start, Size)) { |
| 263 | LineInfo.FunctionName = FunctionName; |
| 264 | } |
| 265 | } |
| 266 | return LineInfo; |
| 267 | } |
| 268 | |
| 269 | DIInliningInfo SymbolizableObjectFile::symbolizeInlinedCode( |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 270 | object::SectionedAddress ModuleOffset, FunctionNameKind FNKind, |
| 271 | bool UseSymbolTable) const { |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 272 | DIInliningInfo InlinedContext; |
| 273 | |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 274 | if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection) |
| 275 | ModuleOffset.SectionIndex = |
| 276 | getModuleSectionIndexForAddress(ModuleOffset.Address); |
| 277 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 278 | if (DebugInfoContext) |
| 279 | InlinedContext = DebugInfoContext->getInliningInfoForAddress( |
| 280 | ModuleOffset, getDILineInfoSpecifier(FNKind)); |
| 281 | // Make sure there is at least one frame in context. |
| 282 | if (InlinedContext.getNumberOfFrames() == 0) |
| 283 | InlinedContext.addFrame(DILineInfo()); |
| 284 | |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 285 | // Override the function name in lower frame with name from symbol table. |
Reid Kleckner | c038e2d | 2015-11-13 17:00:36 +0000 | [diff] [blame] | 286 | if (shouldOverrideWithSymbolTable(FNKind, UseSymbolTable)) { |
Alexey Samsonov | e46bd74 | 2015-10-30 00:02:55 +0000 | [diff] [blame] | 287 | std::string FunctionName; |
| 288 | uint64_t Start, Size; |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 289 | if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset.Address, |
Alexey Samsonov | e46bd74 | 2015-10-30 00:02:55 +0000 | [diff] [blame] | 290 | FunctionName, Start, Size)) { |
| 291 | InlinedContext.getMutableFrame(InlinedContext.getNumberOfFrames() - 1) |
| 292 | ->FunctionName = FunctionName; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 293 | } |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 294 | } |
Alexey Samsonov | e46bd74 | 2015-10-30 00:02:55 +0000 | [diff] [blame] | 295 | |
| 296 | return InlinedContext; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 299 | DIGlobal SymbolizableObjectFile::symbolizeData( |
| 300 | object::SectionedAddress ModuleOffset) const { |
Alexey Samsonov | 76f7ecb | 2015-10-29 23:49:19 +0000 | [diff] [blame] | 301 | DIGlobal Res; |
Alexey Lapshin | 77fc1f6 | 2019-02-27 13:17:36 +0000 | [diff] [blame] | 302 | getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset.Address, Res.Name, |
| 303 | Res.Start, Res.Size); |
Alexey Samsonov | 76f7ecb | 2015-10-29 23:49:19 +0000 | [diff] [blame] | 304 | return Res; |
Alexey Samsonov | 8df3a07 | 2015-10-29 22:21:37 +0000 | [diff] [blame] | 305 | } |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 306 | |
| 307 | /// Search for the first occurence of specified Address in ObjectFile. |
| 308 | uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress( |
| 309 | uint64_t Address) const { |
| 310 | |
| 311 | for (SectionRef Sec : Module->sections()) { |
| 312 | if (!Sec.isText() || Sec.isVirtual()) |
| 313 | continue; |
| 314 | |
| 315 | if (Address >= Sec.getAddress() && |
Fangrui Song | dd0e833 | 2019-04-20 13:00:09 +0000 | [diff] [blame] | 316 | Address < Sec.getAddress() + Sec.getSize()) |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 317 | return Sec.getIndex(); |
Alexey Lapshin | b2c4b8b | 2019-03-23 08:08:40 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | return object::SectionedAddress::UndefSection; |
| 321 | } |