Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -604,17 +604,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; @@ -793,6 +782,17 @@ OutputSections.push_back(C); }; + // A core file does not usually contain unmodified segments except + // the first page of the executable. Add the build ID section to beginning of + // the file so that the section is included in the first page. + if (Out::BuildId) + OutputSections.insert(OutputSections.begin(), Out::BuildId); + + // Add .interp at first because some loaders want to see that section + // on the first page of the executable file when loaded into memory. + if (needsInterpSection()) + OutputSections.insert(OutputSections.begin(), Out::Interp); + // This order is not the same as the final output order // because we sort the sections using their attributes below. Add(Out::SymTab);