Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1293,17 +1293,6 @@ // Create output section objects and add them to OutputSections. template void Writer::createSections() { - // Add .interp first because some loaders want to see that section - // on the first page of the executable file when loaded into memory. - if (needsInterpSection()) - OutputSections.push_back(Out::Interp); - - // A core file does not usually contain unmodified segments except - // the first page of the executable. Add the build ID section now - // so that the section is included in the first page. - if (Out::BuildId) - OutputSections.push_back(Out::BuildId); - // Create output sections for input object file sections. std::vector *> RegularSections; OutputSectionFactory Factory; @@ -1478,6 +1467,18 @@ OutputSections.push_back(C); }; + // Add .interp at first because some loaders want to see that section + // on the first page of the executable file when loaded into memory. + auto I = OutputSections.begin(); + if (needsInterpSection()) + I = OutputSections.insert(I, Out::Interp); + + // A core file does not usually contain unmodified segments except + // the first page of the executable. Add the build ID section now + // so that the section is included in the first page. + if (Out::BuildId) + OutputSections.insert(I, Out::BuildId); + // This order is not the same as the final output order // because we sort the sections using their attributes below. Add(Out::SymTab);