Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -469,13 +469,14 @@ // Finally, move some output sections to the end. auto SectionOrder = [&](OutputSection *S) { // .reloc should come last of all since it refers to RVAs of data in the - // previous sections. + // previous sections, but before all other discardble sections which may + // later be removed by strip. if (S == RelocSec) - return 3; + return 2; // Move DISCARDABLE (or non-memory-mapped) sections to the end of file because // the loader cannot handle holes. if (S->Header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) - return 2; + return 3; // .rsrc should come at the end of the non-discardable sections because its // size may change by the Win32 UpdateResources() function, causing // subsequent sections to move (see https://crbug.com/827082). Index: test/COFF/sort-debug.test =================================================================== --- test/COFF/sort-debug.test +++ test/COFF/sort-debug.test @@ -9,20 +9,20 @@ # RUN: llvm-readobj -sections %t.exe | FileCheck -check-prefix=NODEBUG %s # CHECK: Name: .text +# CHECK: Name: .reloc # CHECK: Name: .debug_abbrev # CHECK: Name: .debug_info # CHECK: Name: .debug_line # CHECK: Name: .debug_pubnames # CHECK: Name: .debug_pubtypes -# CHECK: Name: .reloc # NODEBUG: Name: .text +# NODEBUG: Name: .reloc # NODEBUG-NOT: Name: .debug_abbrev # NODEBUG-NOT: Name: .debug_info # NODEBUG-NOT: Name: .debug_line # NODEBUG-NOT: Name: .debug_pubnames # NODEBUG-NOT: Name: .debug_pubtypes -# NODEBUG: Name: .reloc --- !COFF header: