forked from OSchip/llvm-project
[BOLT] Add BinarySection::flushPendingRelocations()
(cherry picked from FBD18623527)
This commit is contained in:
parent
3b1b9916dd
commit
b07e870d78
|
@ -109,6 +109,26 @@ void BinarySection::emitAsData(MCStreamer &Streamer, StringRef NewName) const {
|
|||
Streamer.EmitLabel(BC.Ctx->getOrCreateSymbol("__hot_data_end"));
|
||||
}
|
||||
|
||||
void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS) {
|
||||
DEBUG(dbgs() << "BOLT-DEBUG: flushing pending relocs for section "
|
||||
<< getName() << '\n');
|
||||
for (auto &Reloc : PendingRelocations) {
|
||||
DEBUG(dbgs() << "BOLT-DEBUG: writing value 0x"
|
||||
<< Twine::utohexstr(Reloc.Addend)
|
||||
<< " of size " << Relocation::getSizeForType(Reloc.Type)
|
||||
<< " at offset 0x"
|
||||
<< Twine::utohexstr(Reloc.Offset) << '\n');
|
||||
assert(Reloc.Type == ELF::R_X86_64_32 &&
|
||||
"only R_X86_64_32 relocations are supported at the moment");
|
||||
const uint32_t Value = Reloc.Addend;
|
||||
OS.pwrite(reinterpret_cast<const char*>(&Value),
|
||||
Relocation::getSizeForType(Reloc.Type),
|
||||
FileOffset + Reloc.Offset);
|
||||
}
|
||||
|
||||
clearList(PendingRelocations);
|
||||
}
|
||||
|
||||
BinarySection::~BinarySection() {
|
||||
if (isReordered()) {
|
||||
delete[] getData();
|
||||
|
|
|
@ -414,6 +414,9 @@ public:
|
|||
// for the section during emission if non-empty.
|
||||
void emitAsData(MCStreamer &Streamer, StringRef NewName = StringRef()) const;
|
||||
|
||||
/// Flush all pending relocations to the emitted section.
|
||||
void flushPendingRelocations(raw_pwrite_stream &OS);
|
||||
|
||||
/// Reorder the contents of this section according to /p Order. If
|
||||
/// /p Inplace is true, the entire contents of the section is reordered,
|
||||
/// otherwise the new contents contain only the reordered data.
|
||||
|
|
|
@ -3748,23 +3748,8 @@ void RewriteInstance::rewriteNoteSections() {
|
|||
Size += BSec->getOutputSize();
|
||||
}
|
||||
|
||||
if (BSec->hasPendingRelocations()) {
|
||||
DEBUG(dbgs() << "BOLT-DEBUG: processing relocs for section "
|
||||
<< SectionName << '\n');
|
||||
for (auto &Reloc : BSec->pendingRelocations()) {
|
||||
DEBUG(dbgs() << "BOLT-DEBUG: writing value 0x"
|
||||
<< Twine::utohexstr(Reloc.Addend)
|
||||
<< " of size " << Relocation::getSizeForType(Reloc.Type)
|
||||
<< " at offset 0x"
|
||||
<< Twine::utohexstr(Reloc.Offset) << '\n');
|
||||
assert(Reloc.Type == ELF::R_X86_64_32 &&
|
||||
"only R_X86_64_32 relocations are supported at the moment");
|
||||
uint32_t Value = Reloc.Addend;
|
||||
OS.pwrite(reinterpret_cast<const char*>(&Value),
|
||||
Relocation::getSizeForType(Reloc.Type),
|
||||
NextAvailableOffset + Reloc.Offset);
|
||||
}
|
||||
}
|
||||
BSec->setFileOffset(NextAvailableOffset);
|
||||
BSec->flushPendingRelocations(OS);
|
||||
}
|
||||
|
||||
// Set/modify section info.
|
||||
|
|
Loading…
Reference in New Issue