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 @@ -633,10 +633,13 @@ } } - MCSection *ELFSection = - getContext().getELFSection(SectionName, Type, Flags, Size, GroupName, - UniqueID, Associated); + MCSectionELF *ELFSection = getContext().getELFSection( + SectionName, Type, Flags, Size, GroupName, UniqueID, Associated); getStreamer().SwitchSection(ELFSection, Subsection); + if (ELFSection->getType() != Type) + Warning(loc, "ignoring changed section type for " + SectionName); + if (ELFSection->getFlags() != Flags) + Warning(loc, "ignoring changed section flags for " + SectionName); if (getContext().getGenDwarfForAssembly()) { bool InsertResult = getContext().addGenDwarfSection(ELFSection); 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: llvm-mc -filetype=obj -triple=x86_64 %s -o - 2>&1 | FileCheck %s --implicit-check-not=warning: + +foo: +.section .foo,"ax",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section flags for .foo +.section .foo,"awx",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section flags for .foo +.section .foo,"awo",@progbits,foo + +.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,14 @@ +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o - 2>&1 | FileCheck %s --implicit-check-not=warning: + +.section .foo,"a",@progbits + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo +.section .foo,"a",@init_array + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo +.section .foo,"a",@note + +# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo +.pushsection .foo,"a",@nobits + +.pushsection .foo,"a",@progbits