Skip to content

Commit

Permalink
[BOLT] Issue error in relocs mode if input is lacking relocations.
Browse files Browse the repository at this point in the history
Summary:
If we specify "-relocs" flag and an input has no relocations we
proceed with assumptions that relocations were there and break the
binary.

Detect the condition above, and reject the input.

(cherry picked from FBD4761239)
  • Loading branch information
maksfb committed Mar 23, 2017
1 parent ad81bd6 commit d5a0264
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bolt/RewriteInstance.cpp
Expand Up @@ -1250,6 +1250,8 @@ BinaryFunction *RewriteInstance::createBinaryFunction(
}

void RewriteInstance::readSpecialSections() {
bool HasTextRelocations = false;

// Process special sections.
for (const auto &Section : InputFile->sections()) {
StringRef SectionName;
Expand All @@ -1268,6 +1270,8 @@ void RewriteInstance::readSpecialSections() {
DebugLocSize = Section.getSize();
} else if (SectionName == ".eh_frame") {
EHFrameSection = Section;
} else if (SectionName == ".rela.text") {
HasTextRelocations = true;
}

// Ignore zero-size allocatable sections as they present no interest to us.
Expand All @@ -1278,6 +1282,12 @@ void RewriteInstance::readSpecialSections() {
}
}

if (opts::Relocs && !HasTextRelocations) {
errs() << "BOLT-ERROR: relocations against code are missing from the input "
"file. Cannot proceed in relocations mode (-relocs).\n";
exit(1);
}

// Process debug sections.
EHFrame = BC->DwCtx->getEHFrame();
if (opts::DumpEHFrame) {
Expand Down

0 comments on commit d5a0264

Please sign in to comment.