26using namespace object;
27using namespace symbolize;
31 std::unique_ptr<DIContext> DICtx,
32 bool UntagAddresses) {
34 std::unique_ptr<SymbolizableObjectFile> res(
36 std::unique_ptr<DataExtractor> OpdExtractor;
46 if (*NameOrErr ==
".opd") {
52 OpdAddress = Section->getAddress();
57 std::vector<std::pair<SymbolRef, uint64_t>> Symbols =
59 for (
auto &
P : Symbols)
61 res->addSymbol(
P.first,
P.second, OpdExtractor.get(), OpdAddress))
66 if (Symbols.empty()) {
67 if (
auto *CoffObj = dyn_cast<COFFObjectFile>(Obj))
68 if (
Error E = res->addCoffExportSymbols(CoffObj))
72 std::vector<SymbolDesc> &SS = res->Symbols;
77 auto I = SS.begin(), E = SS.end(), J = SS.begin();
80 while (++
I != E && OI->Addr ==
I->Addr) {
84 SS.erase(J, SS.end());
86 return std::move(res);
89SymbolizableObjectFile::SymbolizableObjectFile(
const ObjectFile *Obj,
90 std::unique_ptr<DIContext> DICtx,
93 UntagAddresses(UntagAddresses) {}
97struct OffsetNamePair {
101 bool operator<(
const OffsetNamePair &R)
const {
108Error SymbolizableObjectFile::addCoffExportSymbols(
111 std::vector<OffsetNamePair> ExportSyms;
115 if (
auto EC =
Ref.getSymbolName(
Name))
119 ExportSyms.push_back(OffsetNamePair{
Offset,
Name});
121 if (ExportSyms.empty())
130 for (
auto I = ExportSyms.begin(), E = ExportSyms.end();
I != E; ++
I) {
136 Symbols.push_back({SymbolStart, SymbolSize,
Export.Name, 0});
148 if (!SymbolNameOrErr)
160 FileSymbols.emplace_back(ELFSymIdx, SymbolName);
166 if (!SymbolTypeOrErr)
184 if (Flags & SymbolRef::SF_FormatSpecific)
192 if (!SymbolAddressOrErr)
194 uint64_t SymbolAddress = *SymbolAddressOrErr;
195 if (UntagAddresses) {
198 SymbolAddress &= (1ull << 56) - 1;
199 SymbolAddress = (int64_t(SymbolAddress) << 8) >> 8;
207 uint64_t OpdOffset = SymbolAddress - OpdAddress;
209 SymbolAddress = OpdExtractor->
getAddress(&OpdOffset);
217 Symbols.push_back({SymbolAddress, SymbolSize,
SymbolName, ELFSymIdx});
223 auto *CoffObject = dyn_cast<COFFObjectFile>(
Module);
228 if (
auto *CoffObject = dyn_cast<COFFObjectFile>(
Module))
229 return CoffObject->getImageBase();
233bool SymbolizableObjectFile::getNameFromSymbolTable(
235 std::string &FileName)
const {
238 if (SymbolIterator == Symbols.begin())
241 if (SymbolIterator->Size != 0 &&
242 SymbolIterator->Addr + SymbolIterator->Size <=
Address)
244 Name = SymbolIterator->Name.str();
245 Addr = SymbolIterator->Addr;
246 Size = SymbolIterator->Size;
248 if (SymbolIterator->ELFLocalSymIdx != 0) {
255 std::make_pair(SymbolIterator->ELFLocalSymIdx,
StringRef()));
256 if (It != FileSymbols.begin())
257 FileName = It[-1].second.str();
262bool SymbolizableObjectFile::shouldOverrideWithSymbolTable(
268 return FNKind == FunctionNameKind::LinkageName && UseSymbolTable &&
269 isa<DWARFContext>(DebugInfoContext.get());
275 bool UseSymbolTable)
const {
278 getModuleSectionIndexForAddress(ModuleOffset.
Address);
280 DebugInfoContext->getLineInfoForAddress(ModuleOffset, LineInfoSpecifier);
283 if (shouldOverrideWithSymbolTable(LineInfoSpecifier.
FNKind, UseSymbolTable)) {
284 std::string FunctionName, FileName;
286 if (getNameFromSymbolTable(ModuleOffset.
Address, FunctionName, Start,
Size,
302 getModuleSectionIndexForAddress(ModuleOffset.
Address);
304 ModuleOffset, LineInfoSpecifier);
311 if (shouldOverrideWithSymbolTable(LineInfoSpecifier.
FNKind, UseSymbolTable)) {
312 std::string FunctionName, FileName;
314 if (getNameFromSymbolTable(ModuleOffset.
Address, FunctionName, Start,
Size,
331 std::string FileName;
337 DILineInfo DL = DebugInfoContext->getLineInfoForDataAddress(ModuleOffset);
349 getModuleSectionIndexForAddress(ModuleOffset.
Address);
350 return DebugInfoContext->getLocalsForAddress(ModuleOffset);
353std::vector<object::SectionedAddress>
355 std::vector<object::SectionedAddress> Result;
356 for (
const SymbolDesc &
Sym : Symbols) {
357 if (
Sym.Name == Symbol) {
369uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress(
373 if (!Sec.isText() || Sec.isVirtual())
376 if (
Address >= Sec.getAddress() &&
377 Address < Sec.getAddress() + Sec.getSize())
378 return Sec.getIndex();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A format-neutral container for inlined code description.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
A Module instance is used to store all the information related to an LLVM module.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
DataRefImpl getRawDataRefImpl() const
bool isLittleEndian() const
iterator_range< export_directory_iterator > export_directories() const
uint64_t getImageBase() const
uint64_t getFlags() const
uint8_t getELFType() const
uint8_t getBinding() const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
section_iterator_range sections() const
virtual Triple::ArchType getArch() const =0
This is a value type class that represents a single section in the list of sections in the object fil...
This is a value type class that represents a single symbol in the list of symbols in the object file.
DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override
DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
static Expected< std::unique_ptr< SymbolizableObjectFile > > create(const object::ObjectFile *Obj, std::unique_ptr< DIContext > DICtx, bool UntagAddresses)
std::vector< object::SectionedAddress > findSymbol(StringRef Symbol, uint64_t Offset) const override
uint64_t getModulePreferredBase() const override
std::vector< DILocal > symbolizeFrame(object::SectionedAddress ModuleOffset) const override
bool isWin32Module() const override
DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset, DILineInfoSpecifier LineInfoSpecifier, bool UseSymbolTable) const override
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
@ IMAGE_FILE_MACHINE_I386
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
void stable_sort(R &&Range)
@ Export
Export information to summary.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
@ Ref
The access may reference the value stored in memory.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Implement std::hash so that hash_code can be used in STL containers.
Container for description of a global variable.
Controls which fields of DILineInfo container should be filled with data.
A format-neutral container for source line information.
static constexpr const char *const BadString
std::optional< uint64_t > StartAddress
static const uint64_t UndefSection
struct llvm::object::DataRefImpl::@371 d