@@ -810,7 +810,8 @@ Error RewriteInstance::run() {
810810 if (opts::Instrument && !BC->IsStaticExecutable ) {
811811 if (Error E = updateRtInitReloc ())
812812 return E;
813- updateRtFiniReloc ();
813+ if (Error E = updateRtFiniReloc ())
814+ return E;
814815 }
815816
816817 if (opts::OutputFilename == " /dev/null" ) {
@@ -1593,33 +1594,36 @@ Error RewriteInstance::updateRtInitReloc() {
15931594 return Error::success ();
15941595}
15951596
1596- void RewriteInstance::updateRtFiniReloc () {
1597+ Error RewriteInstance::updateRtFiniReloc () {
15971598 // Updating DT_FINI is handled by patchELFDynamic.
15981599 if (BC->FiniAddress )
1599- return ;
1600+ return Error::success () ;
16001601
16011602 const RuntimeLibrary *RT = BC->getRuntimeLibrary ();
16021603 if (!RT || !RT->getRuntimeFiniAddress ())
1603- return ;
1604+ return Error::success () ;
16041605
16051606 // It is still possible to generate profile without fini hook if
16061607 // InstrumentationSleepTime is set
16071608 if ((!BC->FiniArrayAddress || !BC->FiniArraySize ) &&
16081609 opts::InstrumentationSleepTime > 0 ) {
1609- return ;
1610+ return Error::success () ;
16101611 }
16111612
1612- assert (BC->FiniArrayAddress && BC->FiniArraySize &&
1613- " inconsistent .fini_array state" );
1613+ if (!BC->FiniArrayAddress || !BC->FiniArraySize )
1614+ return createStringError (std::errc::not_supported,
1615+ " inconsistent .fini_array state" );
16141616
16151617 ErrorOr<BinarySection &> FiniArraySection =
16161618 BC->getSectionForAddress (*BC->FiniArrayAddress );
1617- assert (FiniArraySection && " .fini_array removed" );
1619+ if (!FiniArraySection)
1620+ return createStringError (std::errc::not_supported, " .fini_array removed" );
16181621
16191622 if (std::optional<Relocation> Reloc =
16201623 FiniArraySection->takeDynamicRelocationAt (0 )) {
1621- assert (Reloc->Addend == BC->FiniFunctionAddress &&
1622- " inconsistent .fini_array dynamic relocation" );
1624+ if (Reloc->Addend != BC->FiniFunctionAddress )
1625+ return createStringError (std::errc::not_supported,
1626+ " inconsistent .fini_array dynamic relocation" );
16231627 Reloc->Addend = RT->getRuntimeFiniAddress ();
16241628 FiniArraySection->addDynamicRelocation (*Reloc);
16251629 }
@@ -1632,6 +1636,7 @@ void RewriteInstance::updateRtFiniReloc() {
16321636 FiniArraySection->addPendingRelocation (Relocation{
16331637 /* Offset*/ 0 , /* Symbol*/ nullptr , /* Type*/ Relocation::getAbs64 (),
16341638 /* Addend*/ RT->getRuntimeFiniAddress (), /* Value*/ 0 });
1639+ return Error::success ();
16351640}
16361641
16371642void RewriteInstance::registerFragments () {
0 commit comments