diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -634,9 +634,15 @@ } } - MCSection *ELFSection = getContext().getELFSection( + MCSectionELF *ELFSection = getContext().getELFSection( SectionName, Type, Flags, Size, GroupName, UniqueID, LinkedToSym); getStreamer().SwitchSection(ELFSection, Subsection); + if (ELFSection->getType() != Type) + Error(loc, "changed section type for " + SectionName); + if (ELFSection->getFlags() != Flags) + Error(loc, "changed section flags for " + SectionName); + if (ELFSection->getEntrySize() != Size) + Error(loc, "changed section entsize for " + SectionName); if (getContext().getGenDwarfForAssembly()) { bool InsertResult = getContext().addGenDwarfSection(ELFSection); diff --git a/llvm/test/MC/ELF/exclude-debug-dwo.s b/llvm/test/MC/ELF/exclude-debug-dwo.s --- a/llvm/test/MC/ELF/exclude-debug-dwo.s +++ b/llvm/test/MC/ELF/exclude-debug-dwo.s @@ -10,23 +10,23 @@ # CHECK: .debug_loc.dwo {{.*}} E # CHECK: .debug_str_offsets.dwo {{.*}} E -.section .debug_info.dwo +.section .debug_info.dwo,"e" nop -.section .debug_types.dwo +.section .debug_types.dwo,"e" nop -.section .debug_abbrev.dwo +.section .debug_abbrev.dwo,"e" nop -.section .debug_str.dwo +.section .debug_str.dwo,"MSe",@progbits,1 nop -.section .debug_line.dwo +.section .debug_line.dwo,"e" nop -.section .debug_loc.dwo +.section .debug_loc.dwo,"e" nop -.section .debug_str_offsets.dwo +.section .debug_str_offsets.dwo,"e" nop diff --git a/llvm/test/MC/ELF/section-flags-changed.s b/llvm/test/MC/ELF/section-flags-changed.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/ELF/section-flags-changed.s @@ -0,0 +1,12 @@ +# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error: + +foo: +.section .foo,"ax",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo +.section .foo,"awx",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section flags for .foo +.pushsection .foo,"a",@progbits + +.pushsection .foo,"ax",@progbits diff --git a/llvm/test/MC/ELF/section-type-changed.s b/llvm/test/MC/ELF/section-type-changed.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/ELF/section-type-changed.s @@ -0,0 +1,11 @@ +# RUN: not llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error: + +.section .foo,"a",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section type for .foo +.section .foo,"a",@init_array + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: error: changed section type for .foo +.pushsection .foo,"a",@nobits + +.pushsection .foo,"a",@progbits