Skip to content

Commit 641bb12

Browse files
Vasily Leonenkovleonen
authored andcommitted
[BOLT] Update updateRtFiniReloc to return error instead of assertions
1 parent 01a2c2b commit 641bb12

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class RewriteInstance {
109109

110110
/// If DT_FINI_ARRAY is used for instrumentation, update the relocation of its
111111
/// first entry to point to the instrumentation library's fini address.
112-
void updateRtFiniReloc();
112+
Error updateRtFiniReloc();
113113

114114
/// Create and initialize metadata rewriters for this instance.
115115
void initializeMetadataManager();

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ Error RewriteInstance::run() {
814814
if (opts::Instrument && !BC->IsStaticExecutable) {
815815
if (Error E = updateRtInitReloc())
816816
return E;
817-
updateRtFiniReloc();
817+
if (Error E = updateRtFiniReloc())
818+
return E;
818819
}
819820

820821
if (opts::OutputFilename == "/dev/null") {
@@ -1597,33 +1598,36 @@ Error RewriteInstance::updateRtInitReloc() {
15971598
return Error::success();
15981599
}
15991600

1600-
void RewriteInstance::updateRtFiniReloc() {
1601+
Error RewriteInstance::updateRtFiniReloc() {
16011602
// Updating DT_FINI is handled by patchELFDynamic.
16021603
if (BC->FiniAddress)
1603-
return;
1604+
return Error::success();
16041605

16051606
const RuntimeLibrary *RT = BC->getRuntimeLibrary();
16061607
if (!RT || !RT->getRuntimeFiniAddress())
1607-
return;
1608+
return Error::success();
16081609

16091610
// It is still possible to generate profile without fini hook if
16101611
// InstrumentationSleepTime is set
16111612
if ((!BC->FiniArrayAddress || !BC->FiniArraySize) &&
16121613
opts::InstrumentationSleepTime > 0) {
1613-
return;
1614+
return Error::success();
16141615
}
16151616

1616-
assert(BC->FiniArrayAddress && BC->FiniArraySize &&
1617-
"inconsistent .fini_array state");
1617+
if (!BC->FiniArrayAddress || !BC->FiniArraySize)
1618+
return createStringError(std::errc::not_supported,
1619+
"inconsistent .fini_array state");
16181620

16191621
ErrorOr<BinarySection &> FiniArraySection =
16201622
BC->getSectionForAddress(*BC->FiniArrayAddress);
1621-
assert(FiniArraySection && ".fini_array removed");
1623+
if (!FiniArraySection)
1624+
return createStringError(std::errc::not_supported, ".fini_array removed");
16221625

16231626
if (std::optional<Relocation> Reloc =
16241627
FiniArraySection->takeDynamicRelocationAt(0)) {
1625-
assert(Reloc->Addend == BC->FiniFunctionAddress &&
1626-
"inconsistent .fini_array dynamic relocation");
1628+
if (Reloc->Addend != BC->FiniFunctionAddress)
1629+
return createStringError(std::errc::not_supported,
1630+
"inconsistent .fini_array dynamic relocation");
16271631
Reloc->Addend = RT->getRuntimeFiniAddress();
16281632
FiniArraySection->addDynamicRelocation(*Reloc);
16291633
}
@@ -1636,6 +1640,7 @@ void RewriteInstance::updateRtFiniReloc() {
16361640
FiniArraySection->addPendingRelocation(Relocation{
16371641
/*Offset*/ 0, /*Symbol*/ nullptr, /*Type*/ Relocation::getAbs64(),
16381642
/*Addend*/ RT->getRuntimeFiniAddress(), /*Value*/ 0});
1643+
return Error::success();
16391644
}
16401645

16411646
void RewriteInstance::registerFragments() {

0 commit comments

Comments
 (0)