本文整理汇总了C++中ObjectFile::isELF方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectFile::isELF方法的具体用法?C++ ObjectFile::isELF怎么用?C++ ObjectFile::isELF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectFile
的用法示例。
在下文中一共展示了ObjectFile::isELF方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpObject
static error_code dumpObject(const ObjectFile &Obj) {
if (Obj.isCOFF())
return coff2yaml(outs(), cast<COFFObjectFile>(Obj));
if (Obj.isELF())
return elf2yaml(outs(), Obj);
return obj2yaml_error::unsupported_obj_file_format;
}
示例2: recordRelocations
void ObjectLoadListener::recordRelocations(
const ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L) {
for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end();
SI != SE; ++SI) {
section_iterator Section = SI->getRelocatedSection();
if (Section == SE) {
continue;
}
StringRef SectionName;
std::error_code ErrorCode = Section->getName(SectionName);
if (ErrorCode) {
assert(false && ErrorCode.message().c_str());
}
if (SectionName.startswith(".debug") ||
SectionName.startswith(".rela.debug") ||
!SectionName.compare(".pdata") || SectionName.startswith(".eh_frame") ||
SectionName.startswith(".rela.eh_frame")) {
// Skip sections whose contents are not directly reported to the EE
continue;
}
relocation_iterator I = SI->relocation_begin();
relocation_iterator E = SI->relocation_end();
for (; I != E; ++I) {
symbol_iterator Symbol = I->getSymbol();
assert(Symbol != Obj.symbol_end());
ErrorOr<section_iterator> SymbolSectionOrErr = Symbol->getSection();
assert(!SymbolSectionOrErr.getError());
object::section_iterator SymbolSection = *SymbolSectionOrErr;
const bool IsExtern = SymbolSection == Obj.section_end();
uint64_t RelType = I->getType();
uint64_t Offset = I->getOffset();
uint8_t *RelocationTarget;
if (IsExtern) {
// This is an external symbol. Verify that it's one we created for
// a global variable and report the relocation via Jit interface.
ErrorOr<StringRef> NameOrError = Symbol->getName();
assert(NameOrError);
StringRef TargetName = NameOrError.get();
auto MapIter = Context->NameToHandleMap.find(TargetName);
if (MapIter == Context->NameToHandleMap.end()) {
// The xdata gets a pointer to our personality routine, which we
// dummied up. We can safely skip it since the EE isn't actually
// going to use the value (it inserts the correct one before handing
// the xdata off to the OS).
assert(!TargetName.compare("ProcessCLRException"));
assert(SectionName.startswith(".xdata"));
continue;
} else {
assert(MapIter->second == Context->NameToHandleMap[TargetName]);
RelocationTarget = (uint8_t *)MapIter->second;
}
} else {
RelocationTarget = (uint8_t *)(L.getSectionLoadAddress(*SymbolSection) +
Symbol->getValue());
}
uint64_t Addend = 0;
uint64_t EERelType = getRelocationType(RelType);
uint64_t SectionAddress = L.getSectionLoadAddress(*Section);
assert(SectionAddress != 0);
uint8_t *FixupAddress = (uint8_t *)(SectionAddress + Offset);
if (Obj.isELF()) {
// Addend is part of the relocation
ELFRelocationRef ElfReloc(*I);
ErrorOr<uint64_t> ElfAddend = ElfReloc.getAddend();
assert(!ElfAddend.getError());
Addend = ElfAddend.get();
} else {
// Addend is read from the location to be fixed up
Addend = getRelocationAddend(RelType, FixupAddress);
}
Context->JitInfo->recordRelocation(FixupAddress,
RelocationTarget + Addend, EERelType);
}
}
}
示例3: recordRelocations
void ObjectLoadListener::recordRelocations(
const ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L) {
for (section_iterator SI = Obj.section_begin(), SE = Obj.section_end();
SI != SE; ++SI) {
section_iterator Section = SI->getRelocatedSection();
if (Section == SE) {
continue;
}
StringRef SectionName;
std::error_code ErrorCode = Section->getName(SectionName);
if (ErrorCode) {
assert(false && ErrorCode.message().c_str());
}
if (SectionName.startswith(".debug") ||
SectionName.startswith(".rela.debug") ||
!SectionName.compare(".pdata") || SectionName.startswith(".eh_frame") ||
SectionName.startswith(".rela.eh_frame")) {
// Skip sections whose contents are not directly reported to the EE
continue;
}
relocation_iterator I = SI->relocation_begin();
relocation_iterator E = SI->relocation_end();
for (; I != E; ++I) {
symbol_iterator Symbol = I->getSymbol();
assert(Symbol != Obj.symbol_end());
ErrorOr<section_iterator> SymbolSectionOrErr = Symbol->getSection();
assert(!SymbolSectionOrErr.getError());
object::section_iterator SymbolSection = *SymbolSectionOrErr;
const bool IsExtern = SymbolSection == Obj.section_end();
uint64_t RelType = I->getType();
uint64_t Offset = I->getOffset();
uint8_t *RelocationTarget = nullptr;
if (IsExtern) {
// This is an external symbol. Verify that it's one we created for
// a global variable and report the relocation via Jit interface.
ErrorOr<StringRef> NameOrError = Symbol->getName();
assert(NameOrError);
StringRef TargetName = NameOrError.get();
assert(Context->NameToHandleMap.count(TargetName) == 1);
RelocationTarget = (uint8_t *)Context->NameToHandleMap[TargetName];
} else {
RelocationTarget = (uint8_t *)(L.getSectionLoadAddress(*SymbolSection) +
Symbol->getValue());
}
uint64_t Addend = 0;
uint64_t EERelType = getRelocationType(RelType);
uint64_t SectionAddress = L.getSectionLoadAddress(*Section);
assert(SectionAddress != 0);
uint8_t *FixupAddress = (uint8_t *)(SectionAddress + Offset);
if (Obj.isELF()) {
// Addend is part of the relocation
ELFRelocationRef ElfReloc(*I);
ErrorOr<uint64_t> ElfAddend = ElfReloc.getAddend();
assert(!ElfAddend.getError());
Addend = ElfAddend.get();
} else {
// Addend is read from the location to be fixed up
Addend = getRelocationAddend(RelType, FixupAddress);
}
Context->JitInfo->recordRelocation(FixupAddress,
RelocationTarget + Addend, EERelType);
}
}
}