diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3594,11 +3594,6 @@ void RewriteInstance::mapCodeSections(RuntimeDyld &RTDyld) { if (BC->HasRelocations) { - ErrorOr TextSection = - BC->getUniqueSectionByName(BC->getMainCodeSectionName()); - assert(TextSection && ".text section not found in output"); - assert(TextSection->hasValidSectionID() && ".text section should be valid"); - // Map sections for functions with pre-assigned addresses. for (BinaryFunction *InjectedFunction : BC->getInjectedBinaryFunctions()) { const uint64_t OutputAddress = InjectedFunction->getOutputAddress(); @@ -3638,7 +3633,9 @@ } // Make sure we allocate enough space for huge pages. - if (opts::HotText) { + ErrorOr TextSection = + BC->getUniqueSectionByName(BC->getMainCodeSectionName()); + if (opts::HotText && TextSection && TextSection->hasValidSectionID()) { uint64_t HotTextEnd = TextSection->getOutputAddress() + TextSection->getOutputSize(); HotTextEnd = alignTo(HotTextEnd, BC->PageAlign);