diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 56 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDie.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 4 |
7 files changed, 34 insertions, 59 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index c326f39fbde..896837c8547 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -60,15 +60,12 @@ typedef DILineInfoSpecifier::FileLineInfoKind FileLineInfoKind; typedef DILineInfoSpecifier::FunctionNameKind FunctionNameKind; uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size, - uint32_t *Off, const RelocAddrMap *Relocs, - uint64_t *SectionIndex) { + uint32_t *Off, const RelocAddrMap *Relocs) { if (!Relocs) return Data.getUnsigned(Off, Size); RelocAddrMap::const_iterator AI = Relocs->find(*Off); if (AI == Relocs->end()) return Data.getUnsigned(Off, Size); - if (SectionIndex) - *SectionIndex = AI->second.SectionIndex; return Data.getUnsigned(Off, Size) + AI->second.Value; } @@ -961,27 +958,23 @@ static Error createError(const Twine &Reason, llvm::Error E) { inconvertibleErrorCode()); } -struct SymInfo { - uint64_t Address; - uint64_t SectionIndex; -}; - -/// Returns the address of symbol relocation used against and a section index. -/// Used for futher relocations computation. Symbol's section load address is -static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj, - const RelocationRef &Reloc, - const LoadedObjectInfo *L, - std::map<SymbolRef, SymInfo> &Cache) { - SymInfo Ret; +/// Returns the address of symbol relocation used against. Used for futher +/// relocations computation. Symbol's section load address is taken in account if +/// LoadedObjectInfo interface is provided. +static Expected<uint64_t> +getSymbolAddress(const object::ObjectFile &Obj, const RelocationRef &Reloc, + const LoadedObjectInfo *L, + std::map<SymbolRef, uint64_t> &Cache) { + uint64_t Ret = 0; object::section_iterator RSec = Obj.section_end(); object::symbol_iterator Sym = Reloc.getSymbol(); - std::map<SymbolRef, SymInfo>::iterator CacheIt = Cache.end(); + std::map<SymbolRef, uint64_t>::iterator CacheIt = Cache.end(); // First calculate the address of the symbol or section as it appears // in the object file if (Sym != Obj.symbol_end()) { bool New; - std::tie(CacheIt, New) = Cache.insert({*Sym, {0, 0}}); + std::tie(CacheIt, New) = Cache.insert({*Sym, 0}); if (!New) return CacheIt->second; @@ -997,14 +990,12 @@ static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj, SectOrErr.takeError()); RSec = *SectOrErr; - Ret.Address = *SymAddrOrErr; + Ret = *SymAddrOrErr; } else if (auto *MObj = dyn_cast<MachOObjectFile>(&Obj)) { RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl()); - Ret.Address = RSec->getAddress(); + Ret = RSec->getAddress(); } - Ret.SectionIndex = RSec->getIndex(); - // If we are given load addresses for the sections, we need to adjust: // SymAddr = (Address of Symbol Or Section in File) - // (Address of Section in File) + @@ -1014,7 +1005,7 @@ static Expected<SymInfo> getSymbolInfo(const object::ObjectFile &Obj, // we need to perform the same computation. if (L && RSec != Obj.section_end()) if (uint64_t SectionLoadAddress = L->getSectionLoadAddress(*RSec)) - Ret.Address += SectionLoadAddress - RSec->getAddress(); + Ret += SectionLoadAddress - RSec->getAddress(); if (CacheIt != Cache.end()) CacheIt->second = Ret; @@ -1073,7 +1064,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, // Try to obtain an already relocated version of this section. // Else use the unrelocated section from the object file. We'll have to // apply relocations ourselves later. - if (!L || !L->getLoadedSectionContents(*RelocatedSection, data)) + if (!L || !L->getLoadedSectionContents(*RelocatedSection,data)) Section.getContents(data); if (auto Err = maybeDecompress(Section, name, data)) { @@ -1112,7 +1103,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, // If the section we're relocating was relocated already by the JIT, // then we used the relocated version above, so we do not need to process // relocations for it now. - if (L && L->getLoadedSectionContents(*RelocatedSection, RelSecData)) + if (L && L->getLoadedSectionContents(*RelocatedSection,RelSecData)) continue; // In Mach-o files, the relocations do not need to be applied if @@ -1156,30 +1147,29 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, if (Section.relocation_begin() == Section.relocation_end()) continue; - // Symbol to [address, section index] cache mapping. - std::map<SymbolRef, SymInfo> AddrCache; + std::map<SymbolRef, uint64_t> AddrCache; for (const RelocationRef &Reloc : Section.relocations()) { // FIXME: it's not clear how to correctly handle scattered // relocations. if (isRelocScattered(Obj, Reloc)) continue; - Expected<SymInfo> SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache); - if (!SymInfoOrErr) { - errs() << toString(SymInfoOrErr.takeError()) << '\n'; + Expected<uint64_t> SymAddrOrErr = + getSymbolAddress(Obj, Reloc, L, AddrCache); + if (!SymAddrOrErr) { + errs() << toString(SymAddrOrErr.takeError()) << '\n'; continue; } object::RelocVisitor V(Obj); - uint64_t Val = V.visit(Reloc.getType(), Reloc, SymInfoOrErr->Address); + uint64_t Val = V.visit(Reloc.getType(), Reloc, *SymAddrOrErr); if (V.error()) { SmallString<32> Name; Reloc.getTypeName(Name); errs() << "error: failed to compute relocation: " << Name << "\n"; continue; } - llvm::RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val}; - Map->insert({Reloc.getOffset(), Rel}); + Map->insert({Reloc.getOffset(), {Val}}); } } } diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp index 6b5e1d3c931..8da797750ab 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp @@ -35,8 +35,8 @@ bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr, while (true) { RangeListEntry entry; uint32_t prev_offset = *offset_ptr; - entry.StartAddress = getRelocatedValue(data, AddressSize, offset_ptr, - &Relocs, &entry.SectionIndex); + entry.StartAddress = + getRelocatedValue(data, AddressSize, offset_ptr, &Relocs); entry.EndAddress = getRelocatedValue(data, AddressSize, offset_ptr, &Relocs); @@ -69,8 +69,8 @@ DWARFDebugRangeList::getAbsoluteRanges(uint64_t BaseAddress) const { if (RLE.isBaseAddressSelectionEntry(AddressSize)) { BaseAddress = RLE.EndAddress; } else { - Res.push_back({BaseAddress + RLE.StartAddress, - BaseAddress + RLE.EndAddress, RLE.SectionIndex}); + Res.push_back( + {BaseAddress + RLE.StartAddress, BaseAddress + RLE.EndAddress}); } } return Res; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index fd45c77d374..e3bd759ba94 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -211,16 +211,13 @@ Optional<uint64_t> DWARFDie::getHighPC(uint64_t LowPC) const { return None; } -bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, - uint64_t &SectionIndex) const { - auto F = find(DW_AT_low_pc); - auto LowPcAddr = toAddress(F); +bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC) const { + auto LowPcAddr = toAddress(find(DW_AT_low_pc)); if (!LowPcAddr) return false; if (auto HighPcAddr = getHighPC(*LowPcAddr)) { LowPC = *LowPcAddr; HighPC = *HighPcAddr; - SectionIndex = F->getSectionIndex(); return true; } return false; @@ -231,9 +228,9 @@ DWARFDie::getAddressRanges() const { if (isNULL()) return DWARFAddressRangesVector(); // Single range specified by low/high PC. - uint64_t LowPC, HighPC, Index; - if (getLowAndHighPC(LowPC, HighPC, Index)) - return {{LowPC, HighPC, Index}}; + uint64_t LowPC, HighPC; + if (getLowAndHighPC(LowPC, HighPC)) + return {{LowPC, HighPC}}; // Multiple ranges from .debug_ranges section. auto RangesOffset = toSectionOffset(find(DW_AT_ranges)); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp index 0963d7bfd71..1cbd3ea2c86 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -333,8 +333,8 @@ bool DWARFFormValue::extractValue(const DataExtractor &Data, return false; uint16_t AddrSize = (Form == DW_FORM_addr) ? U->getAddressByteSize() : U->getRefAddrByteSize(); - Value.uval = getRelocatedValue(Data, AddrSize, OffsetPtr, - U->getRelocMap(), &Value.SectionIndex); + Value.uval = + getRelocatedValue(Data, AddrSize, OffsetPtr, U->getRelocMap()); break; } case DW_FORM_exprloc: diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index 7372f24cb9a..28531feccfe 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -293,10 +293,6 @@ uint64_t COFFObjectFile::getSectionAddress(DataRefImpl Ref) const { return Result; } -uint64_t COFFObjectFile::getSectionIndex(DataRefImpl Sec) const { - return toSec(Sec) - SectionTable; -} - uint64_t COFFObjectFile::getSectionSize(DataRefImpl Ref) const { return getSectionSize(toSec(Ref)); } diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index bfb8875f47d..3d3fa07db3f 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -1820,10 +1820,6 @@ uint64_t MachOObjectFile::getSectionAddress(DataRefImpl Sec) const { return getSection(Sec).addr; } -uint64_t MachOObjectFile::getSectionIndex(DataRefImpl Sec) const { - return Sec.d.a; -} - uint64_t MachOObjectFile::getSectionSize(DataRefImpl Sec) const { // In the case if a malformed Mach-O file where the section offset is past // the end of the file or some part of the section size is past the end of diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index f565d7a33e5..058686e4db9 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -743,10 +743,6 @@ std::error_code WasmObjectFile::getSectionName(DataRefImpl Sec, uint64_t WasmObjectFile::getSectionAddress(DataRefImpl Sec) const { return 0; } -uint64_t WasmObjectFile::getSectionIndex(DataRefImpl Sec) const { - return Sec.d.a; -} - uint64_t WasmObjectFile::getSectionSize(DataRefImpl Sec) const { const WasmSection &S = Sections[Sec.d.a]; return S.Content.size(); |