[PATCH] D30291: Handle section header flags redefinitions similar to GAS
Christof Douma via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 23 02:23:02 PST 2017
christof created this revision.
A .section directive defining an already existing section has now the following behavior:
- target specific flags (that is OS or PROC specific) are added to the existing section
- Any other flag is ignored and a warning is emitted
This makes the integrated assembler behave like GNU as version 2.27.
Repository:
rL LLVM
https://reviews.llvm.org/D30291
Files:
lib/MC/MCParser/ELFAsmParser.cpp
test/MC/ELF/section-override-flags.s
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
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()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30291.89483.patch
Type: text/x-patch
Size: 2611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170223/28380d1a/attachment.bin>
More information about the llvm-commits
mailing list