Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -2585,12 +2585,13 @@ // The sentinel has to be removed if there are no other .ARM.exidx entries. bool ARMExidxSentinelSection::empty() const { - OutputSection *OS = getParent(); - for (auto *B : OS->SectionCommands) - if (auto *ISD = dyn_cast(B)) - for (auto *S : ISD->Sections) - if (!isa(S)) - return false; + if (OutputSection *OS = getParent()) { + for (auto *B : OS->SectionCommands) + if (auto *ISD = dyn_cast(B)) + for (auto *S : ISD->Sections) + if (!isa(S)) + return false; + } return true; } Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1309,7 +1309,7 @@ if (!SS) return; OutputSection *OS = SS->getParent(); - if (!SS->empty() || !OS) + if (!OS || !SS->empty()) continue; std::vector::iterator Empty = OS->SectionCommands.end();