Index: lib/MC/MCParser/ELFAsmParser.cpp =================================================================== --- lib/MC/MCParser/ELFAsmParser.cpp +++ lib/MC/MCParser/ELFAsmParser.cpp @@ -594,8 +594,20 @@ } } - MCSection *ELFSection = getContext().getELFSection( + MCSectionELF *ELFSection = getContext().getELFSection( SectionName, Type, Flags, Size, GroupName, UniqueID, Associated); + // Sections are not identified by flags. Check if there is a mismatch in the + // flags requested and the flags in the section returned. If the mismatch is + // in OS or CPU specific flags, just add them. For any other mismatch warn + // the user that we are ignoring the new flags. + const unsigned overrideMask = (ELF::SHF_MASKOS | ELF::SHF_MASKPROC); + unsigned curFlags = ELFSection->getFlags(); + curFlags |= Flags & overrideMask; + Flags |= curFlags & overrideMask; + ELFSection->setFlags(curFlags); + if (curFlags != Flags) + Warning(loc, "ignoring override of non-target sepecific section flags"); + getStreamer().SwitchSection(ELFSection, Subsection); if (getContext().getGenDwarfForAssembly()) { Index: test/MC/ELF/section-override-flags.s =================================================================== --- /dev/null +++ test/MC/ELF/section-override-flags.s @@ -0,0 +1,36 @@ +// RUN: llvm-mc -filetype=obj -triple arm-pc-linux-gnu %s -o %t 2>&1 | FileCheck -check-prefix=DIAG %s +// RUN: llvm-readobj -s %t | FileCheck %s + +// REQUIRES: arm-registered-target + +// Test we handle overriding OS and PROC specific flags on the builtin .text section +.section .text,"0x200006",%progbits +.section .text,"0x40000006",%progbits + +// CHECK: Section { +// CHECK: Name: .text +// CHECK-NEXT: Type: SHT_PROGBITS (0x1) +// CHECK-NEXT: Flags [ (0x40200006) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_EXECINSTR (0x4) +// CHECK-NEXT: ] + +//Attempt to override flags that are not target specific should be ignored +.section foo,"ax",%progbits +.section foo,"0x7",%progbits +.section foo,"0x10000007",%progbits + +// DIAG: warning: ignoring override of non-target sepecific section flags +// DIAG: warning: ignoring override of non-target sepecific section flags + +// CHECK: Section { +// CHECK: Name: foo +// CHECK-NEXT: Type: SHT_PROGBITS (0x1) +// CHECK-NEXT: Flags [ (0x10000006) +// CHECK-NEXT: SHF_ALLOC (0x2) +// CHECK-NEXT: SHF_EXECINSTR (0x4) +// CHECK-NEXT: ] + + +// We want to see this warning the exact number times specified +// DIAG-NOT: warning: ignoring override of non-target sepecific section flags