Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -753,6 +753,11 @@ for (auto &YamlPhdr : Doc.ProgramHeaders) { Elf_Phdr &PHeader = PHeaders[PhdrIdx++]; std::vector Fragments = getPhdrFragments(YamlPhdr, SHeaders); + if (!llvm::is_sorted(Fragments, [](const Fragment &A, const Fragment &B) { + return A.Offset < B.Offset; + })) + reportError("sections in the program header with index " + + Twine(PhdrIdx) + " are not sorted by their file offset"); if (YamlPhdr.Offset) { PHeader.p_offset = *YamlPhdr.Offset; Index: llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml =================================================================== --- llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml +++ llvm/test/tools/llvm-gsymutil/X86/elf-dwarf.yaml @@ -395,8 +395,6 @@ - Section: .note.ABI-tag - Section: .note.gnu.build-id - Section: .gnu.hash - - Section: .dynsym - - Section: .dynstr - Section: .gnu.version - Section: .gnu.version_r - Section: .rela.dyn @@ -409,6 +407,8 @@ - Section: .rodata - Section: .eh_frame_hdr - Section: .eh_frame + - Section: .dynsym + - Section: .dynstr Symbols: - Name: .interp Type: STT_SECTION Index: llvm/test/tools/llvm-readobj/ELF/demangle.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/demangle.test +++ llvm/test/tools/llvm-readobj/ELF/demangle.test @@ -213,8 +213,8 @@ Flags: [ PF_R, PF_X ] VAddr: 0x0 Sections: - - Section: .dynsym - Section: .dynstr + - Section: .dynsym - Section: .rela.dyn - Section: .dynamic - Section: .text.foo Index: llvm/test/tools/llvm-readobj/ELF/hash-symbols.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/hash-symbols.test +++ llvm/test/tools/llvm-readobj/ELF/hash-symbols.test @@ -298,8 +298,8 @@ Flags: [ PF_R, PF_X ] VAddr: 0x0 Sections: - - Section: .dynsym - Section: .dynstr + - Section: .dynsym - Section: .dynamic - Section: .text.foo - Type: PT_DYNAMIC Index: llvm/test/tools/llvm-readobj/ELF/reloc-negative-addend-no-sym.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/reloc-negative-addend-no-sym.test +++ llvm/test/tools/llvm-readobj/ELF/reloc-negative-addend-no-sym.test @@ -65,8 +65,8 @@ - Type: PT_LOAD VAddr: 0x1000 Sections: - - Section: .rela.dyn - Section: .dynamic + - Section: .rela.dyn - Type: PT_DYNAMIC VAddr: 0x1000 Sections: Index: llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test +++ llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test @@ -101,8 +101,8 @@ - Type: PT_LOAD VAddr: 0x1000 Sections: - - Section: .rela.dyn - Section: .dynamic + - Section: .rela.dyn - Type: PT_DYNAMIC VAddr: 0x1000 Sections: