Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1189,8 +1189,6 @@ if (ErrorCount) return; - // So far we have added sections from input object files. - // This function adds linker-created Out::* sections. addPredefinedSections(); removeUnusedSyntheticSections(OutputSections); @@ -1258,8 +1256,17 @@ // ARM ABI requires .ARM.exidx to be terminated by some piece of data. // We have the terminater synthetic section class. Add that at the end. auto *OS = dyn_cast_or_null(findSection(".ARM.exidx")); - if (OS && !OS->Sections.empty() && !Config->Relocatable) - OS->addSection(make()); + if (!OS || OS->Sections.empty() || Config->Relocatable) + return; + + auto *Sentinel = make(); + OS->addSection(Sentinel); + // If there are linker script commands existing at this point then add the + // sentinel to these too. + if (OutputSectionCommand *C = Script->getCmd(OS)) { + auto *ISD = make(""); + ISD->Sections.push_back(Sentinel); + } } // The linker is expected to define SECNAME_start and SECNAME_end