Skip to content

Commit d5a0264

Browse files
committed
[BOLT] Issue error in relocs mode if input is lacking relocations.
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)
1 parent ad81bd6 commit d5a0264

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bolt/RewriteInstance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,8 @@ BinaryFunction *RewriteInstance::createBinaryFunction(
12501250
}
12511251

12521252
void RewriteInstance::readSpecialSections() {
1253+
bool HasTextRelocations = false;
1254+
12531255
// Process special sections.
12541256
for (const auto &Section : InputFile->sections()) {
12551257
StringRef SectionName;
@@ -1268,6 +1270,8 @@ void RewriteInstance::readSpecialSections() {
12681270
DebugLocSize = Section.getSize();
12691271
} else if (SectionName == ".eh_frame") {
12701272
EHFrameSection = Section;
1273+
} else if (SectionName == ".rela.text") {
1274+
HasTextRelocations = true;
12711275
}
12721276

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

1285+
if (opts::Relocs && !HasTextRelocations) {
1286+
errs() << "BOLT-ERROR: relocations against code are missing from the input "
1287+
"file. Cannot proceed in relocations mode (-relocs).\n";
1288+
exit(1);
1289+
}
1290+
12811291
// Process debug sections.
12821292
EHFrame = BC->DwCtx->getEHFrame();
12831293
if (opts::DumpEHFrame) {

0 commit comments

Comments
 (0)