Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -687,15 +687,15 @@ return BIsWritable; if (!Config->SingleRoRx) { - // For a corresponding reason, put non exec sections first (the program - // header PT_LOAD is not executable). + // For a corresponding reason, put read-only non-exec sections + // first (the program header PT_LOAD is not executable). // We only do that if we are not using linker scripts, since with linker // scripts ro and rx sections are in the same PT_LOAD, so their relative // order is not important. The same applies for -no-rosegment. bool AIsExec = A->Flags & SHF_EXECINSTR; bool BIsExec = B->Flags & SHF_EXECINSTR; if (AIsExec != BIsExec) - return BIsExec; + return (A->Flags & SHF_WRITE) ? AIsExec : BIsExec; } // If we got here we know that both A and B are in the same PT_LOAD.