本文整理汇总了C++中SectionRef类的典型用法代码示例。如果您正苦于以下问题:C++ SectionRef类的具体用法?C++ SectionRef怎么用?C++ SectionRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SectionRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MCObjectSymbolizer
MCMachObjectSymbolizer::MCMachObjectSymbolizer(
MCContext &Ctx, std::unique_ptr<MCRelocationInfo> &RelInfo,
const MachOObjectFile *MOOF)
: MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF), StubsStart(0),
StubsCount(0), StubSize(0), StubsIndSymIndex(0) {
for (const SectionRef &Section : MOOF->sections()) {
StringRef Name;
Section.getName(Name);
if (Name == "__stubs") {
SectionRef StubsSec = Section;
if (MOOF->is64Bit()) {
MachO::section_64 S = MOOF->getSection64(StubsSec.getRawDataRefImpl());
StubsIndSymIndex = S.reserved1;
StubSize = S.reserved2;
} else {
MachO::section S = MOOF->getSection(StubsSec.getRawDataRefImpl());
StubsIndSymIndex = S.reserved1;
StubSize = S.reserved2;
}
assert(StubSize && "Mach-O stub entry size can't be zero!");
StubsSec.getAddress(StubsStart);
StubsSec.getSize(StubsCount);
StubsCount /= StubSize;
}
}
}
示例2: getRelocationValueRef
RelocationValueRef RuntimeDyldMachO::getRelocationValueRef(
const ObjectFile &BaseTObj, const relocation_iterator &RI,
const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID) {
const MachOObjectFile &Obj =
static_cast<const MachOObjectFile &>(BaseTObj);
MachO::any_relocation_info RelInfo =
Obj.getRelocation(RI->getRawDataRefImpl());
RelocationValueRef Value;
bool IsExternal = Obj.getPlainRelocationExternal(RelInfo);
if (IsExternal) {
symbol_iterator Symbol = RI->getSymbol();
StringRef TargetName;
Symbol->getName(TargetName);
SymbolTableMap::const_iterator SI =
GlobalSymbolTable.find(TargetName.data());
if (SI != GlobalSymbolTable.end()) {
Value.SectionID = SI->second.first;
Value.Offset = SI->second.second + RE.Addend;
} else {
Value.SymbolName = TargetName.data();
Value.Offset = RE.Addend;
}
} else {
SectionRef Sec = Obj.getRelocationSection(RelInfo);
bool IsCode = Sec.isText();
Value.SectionID = findOrEmitSection(Obj, Sec, IsCode, ObjSectionToID);
uint64_t Addr = Sec.getAddress();
Value.Offset = RE.Addend - Addr;
}
return Value;
}
示例3: getSectionsAndSymbols
static void getSectionsAndSymbols(const macho::Header &Header,
MachOObjectFile *MachOObj,
InMemoryStruct<macho::SymtabLoadCommand> *SymtabLC,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns) {
error_code ec;
for (symbol_iterator SI = MachOObj->begin_symbols(),
SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
Symbols.push_back(*SI);
for (section_iterator SI = MachOObj->begin_sections(),
SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
SectionRef SR = *SI;
StringRef SectName;
SR.getName(SectName);
Sections.push_back(*SI);
}
for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
const MachOObject::LoadCommandInfo &LCI =
MachOObj->getObject()->getLoadCommandInfo(i);
if (LCI.Command.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
InMemoryStruct<macho::LinkeditDataLoadCommand> LLC;
MachOObj->getObject()->ReadLinkeditDataLoadCommand(LCI, LLC);
MachOObj->getObject()->ReadULEB128s(LLC->DataOffset, FoundFns);
}
}
}
示例4: computeSectionStubBufSize
// compute stub buffer size for the given section
unsigned RuntimeDyldImpl::computeSectionStubBufSize(ObjectImage &Obj,
const SectionRef &Section) {
unsigned StubSize = getMaxStubSize();
if (StubSize == 0) {
return 0;
}
// FIXME: this is an inefficient way to handle this. We should computed the
// necessary section allocation size in loadObject by walking all the sections
// once.
unsigned StubBufSize = 0;
for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections();
SI != SE; ++SI) {
section_iterator RelSecI = SI->getRelocatedSection();
if (!(RelSecI == Section))
continue;
for (const RelocationRef &Reloc : SI->relocations()) {
(void)Reloc;
StubBufSize += StubSize;
}
}
// Get section data size and alignment
uint64_t DataSize = Section.getSize();
uint64_t Alignment64 = Section.getAlignment();
// Add stubbuf size alignment
unsigned Alignment = (unsigned)Alignment64 & 0xffffffffL;
unsigned StubAlignment = getStubAlignment();
unsigned EndAlignment = (DataSize | Alignment) & -(DataSize | Alignment);
if (StubAlignment > EndAlignment)
StubBufSize += StubAlignment - EndAlignment;
return StubBufSize;
}
示例5: readBytesUnaligned
relocation_iterator RuntimeDyldMachO::processScatteredVANILLA(
unsigned SectionID, relocation_iterator RelI,
const ObjectFile &BaseObjT,
RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID) {
const MachOObjectFile &Obj =
static_cast<const MachOObjectFile&>(BaseObjT);
MachO::any_relocation_info RE =
Obj.getRelocation(RelI->getRawDataRefImpl());
SectionEntry &Section = Sections[SectionID];
uint32_t RelocType = Obj.getAnyRelocationType(RE);
bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
unsigned Size = Obj.getAnyRelocationLength(RE);
uint64_t Offset = RelI->getOffset();
uint8_t *LocalAddress = Section.getAddressWithOffset(Offset);
unsigned NumBytes = 1 << Size;
int64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
unsigned SymbolBaseAddr = Obj.getScatteredRelocationValue(RE);
section_iterator TargetSI = getSectionByAddress(Obj, SymbolBaseAddr);
assert(TargetSI != Obj.section_end() && "Can't find section for symbol");
uint64_t SectionBaseAddr = TargetSI->getAddress();
SectionRef TargetSection = *TargetSI;
bool IsCode = TargetSection.isText();
uint32_t TargetSectionID =
findOrEmitSection(Obj, TargetSection, IsCode, ObjSectionToID);
Addend -= SectionBaseAddr;
RelocationEntry R(SectionID, Offset, RelocType, Addend, IsPCRel, Size);
addRelocationForSection(R, TargetSectionID);
return ++RelI;
}
示例6: section
explicit section(const SectionRef& sec) {
StringRef name;
if(error_code err = sec.getName(name))
llvm_binary_fail(err);
this->name_ = name.str();
if (error_code err = sec.getAddress(this->addr_))
llvm_binary_fail(err);
if (error_code err = sec.getSize(this->size_))
llvm_binary_fail(err);
}
示例7: getSectionsAndSymbols
static void
getSectionsAndSymbols(const MachO::mach_header Header,
MachOObjectFile *MachOObj,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns,
uint64_t &BaseSegmentAddress) {
for (symbol_iterator SI = MachOObj->symbol_begin(),
SE = MachOObj->symbol_end();
SI != SE; ++SI)
Symbols.push_back(*SI);
for (section_iterator SI = MachOObj->section_begin(),
SE = MachOObj->section_end();
SI != SE; ++SI) {
SectionRef SR = *SI;
StringRef SectName;
SR.getName(SectName);
Sections.push_back(*SI);
}
MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
bool BaseSegmentAddressSet = false;
for (unsigned i = 0; ; ++i) {
if (Command.C.cmd == MachO::LC_FUNCTION_STARTS) {
// We found a function starts segment, parse the addresses for later
// consumption.
MachO::linkedit_data_command LLC =
MachOObj->getLinkeditDataLoadCommand(Command);
MachOObj->ReadULEB128s(LLC.dataoff, FoundFns);
}
else if (Command.C.cmd == MachO::LC_SEGMENT) {
MachO::segment_command SLC =
MachOObj->getSegmentLoadCommand(Command);
StringRef SegName = SLC.segname;
if(!BaseSegmentAddressSet && SegName != "__PAGEZERO") {
BaseSegmentAddressSet = true;
BaseSegmentAddress = SLC.vmaddr;
}
}
if (i == Header.ncmds - 1)
break;
else
Command = MachOObj->getNextLoadCommandInfo(Command);
}
}
示例8: printRelocation
void COFFDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) {
uint64_t Offset;
uint64_t RelocType;
SmallString<32> RelocName;
StringRef SymbolName;
StringRef Contents;
if (error(Reloc.getOffset(Offset)))
return;
if (error(Reloc.getType(RelocType)))
return;
if (error(Reloc.getTypeName(RelocName)))
return;
symbol_iterator Symbol = Reloc.getSymbol();
if (error(Symbol->getName(SymbolName)))
return;
if (error(Section.getContents(Contents)))
return;
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printHex("Offset", Offset);
W.printNumber("Type", RelocName, RelocType);
W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
} else {
raw_ostream& OS = W.startLine();
OS << W.hex(Offset)
<< " " << RelocName
<< " " << (SymbolName.size() > 0 ? SymbolName : "-")
<< "\n";
}
}
示例9: isRequiredForExecution
static bool isRequiredForExecution(const SectionRef &Section) {
const ObjectFile *Obj = Section.getObject();
if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
return ELFObj->getSectionFlags(Section) & ELF::SHF_ALLOC;
assert(isa<MachOObjectFile>(Obj));
return true;
}
示例10: isReadOnlyData
static bool isReadOnlyData(const SectionRef &Section) {
const ObjectFile *Obj = Section.getObject();
if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
return !(ELFObj->getSectionFlags(Section) &
(ELF::SHF_WRITE | ELF::SHF_EXECINSTR));
assert(isa<MachOObjectFile>(Obj));
return false;
}
示例11: findUnwindRelocNameAddend
/// Given a relocation from __compact_unwind, consisting of the RelocationRef
/// and data being relocated, determine the best base Name and Addend to use for
/// display purposes.
///
/// 1. An Extern relocation will directly reference a symbol (and the data is
/// then already an addend), so use that.
/// 2. Otherwise the data is an offset in the object file's layout; try to find
// a symbol before it in the same section, and use the offset from there.
/// 3. Finally, if all that fails, fall back to an offset from the start of the
/// referenced section.
static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols,
const RelocationRef &Reloc,
uint64_t Addr,
StringRef &Name, uint64_t &Addend) {
if (Reloc.getSymbol() != Obj->symbol_end()) {
Reloc.getSymbol()->getName(Name);
Addend = Addr;
return;
}
auto RE = Obj->getRelocation(Reloc.getRawDataRefImpl());
SectionRef RelocSection = Obj->getRelocationSection(RE);
uint64_t SectionAddr;
RelocSection.getAddress(SectionAddr);
auto Sym = Symbols.upper_bound(Addr);
if (Sym == Symbols.begin()) {
// The first symbol in the object is after this reference, the best we can
// do is section-relative notation.
RelocSection.getName(Name);
Addend = Addr - SectionAddr;
return;
}
// Go back one so that SymbolAddress <= Addr.
--Sym;
section_iterator SymSection = Obj->section_end();
Sym->second.getSection(SymSection);
if (RelocSection == *SymSection) {
// There's a valid symbol in the same section before this reference.
Sym->second.getName(Name);
Addend = Addr - Sym->first;
return;
}
// There is a symbol before this reference, but it's in a different
// section. Probably not helpful to mention it, so use the section name.
RelocSection.getName(Name);
Addend = Addr - SectionAddr;
}
示例12: isZeroInit
static bool isZeroInit(const SectionRef &Section) {
const ObjectFile *Obj = Section.getObject();
if (auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj))
return ELFObj->getSectionType(Section) == ELF::SHT_NOBITS;
auto *MachO = cast<MachOObjectFile>(Obj);
unsigned SectionType = MachO->getSectionType(Section);
return SectionType == MachO::S_ZEROFILL ||
SectionType == MachO::S_GB_ZEROFILL;
}
示例13: checked
bool checked(const ELFObjectFile<T> &obj, SectionRef sec_ref) {
typedef typename ELFObjectFile<T>::Elf_Shdr Elf_Shdr;
auto &elf = *obj.getELFFile();
const Elf_Shdr *RelSec = obj.getSection(sec_ref.getRawDataRefImpl());
auto symsec = elf.getSection(RelSec->sh_link);
if (!symsec) return false;
uint32_t sec_typ = (*symsec)->sh_type;
return
(sec_typ == ELF::SHT_SYMTAB || sec_typ == ELF::SHT_DYNSYM);
}
示例14:
void DyldELFObject<target_endianness, is64Bits>::updateSectionAddress(
const SectionRef &Sec,
uint64_t Addr) {
DataRefImpl ShdrRef = Sec.getRawDataRefImpl();
Elf_Shdr *shdr = const_cast<Elf_Shdr*>(
reinterpret_cast<const Elf_Shdr *>(ShdrRef.p));
// This assumes the address passed in matches the target address bitness
// The template-based type cast handles everything else.
shdr->sh_addr = static_cast<addr_type>(Addr);
}
示例15: getSectionsAndSymbols
static void
getSectionsAndSymbols(const macho::Header Header,
MachOObjectFile *MachOObj,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns) {
error_code ec;
for (symbol_iterator SI = MachOObj->begin_symbols(),
SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
Symbols.push_back(*SI);
for (section_iterator SI = MachOObj->begin_sections(),
SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) {
SectionRef SR = *SI;
StringRef SectName;
SR.getName(SectName);
Sections.push_back(*SI);
}
MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
for (unsigned i = 0; ; ++i) {
if (Command.C.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
macho::LinkeditDataLoadCommand LLC =
MachOObj->getLinkeditDataLoadCommand(Command);
MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
}
if (i == Header.NumLoadCommands - 1)
break;
else
Command = MachOObj->getNextLoadCommandInfo(Command);
}
}