[PATCH] D73999: [MC][ELF] Warn changed section type or flags
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 4 15:00:12 PST 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson.
Herald added subscribers: llvm-commits, hiraditya, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay updated this revision to Diff 242437.
MaskRay added a comment.
Use -o /dev/null
MaskRay added a comment.
There is a discussion on https://bugs.llvm.org/show_bug.cgi?id=44775 about whether the following two directives should mean the different sections
> .data
> foo:
> bar:
> .section .text,"axo",%progbits,foo
> .section .text,"axo",%progbits,bar
Perhaps you can chime in.
GNU as emits the warnings for changed section type or flags. They seem nice addition.
A possible improvement in the future is to reuse
llvm-readobj/ELFDumper.cpp:getSectionTypeString so that we can name the
type in the diagnostics.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73999
Files:
llvm/lib/MC/MCParser/ELFAsmParser.cpp
llvm/test/MC/ELF/section-flags-changed.s
llvm/test/MC/ELF/section-type-changed.s
Index: llvm/test/MC/ELF/section-type-changed.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-type-changed.s
@@ -0,0 +1,14 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=warning:
+
+.section .foo,"a", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo
+.section .foo,"a", at init_array
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo
+.section .foo,"a", at note
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section type for .foo
+.pushsection .foo,"a", at nobits
+
+.pushsection .foo,"a", at progbits
Index: llvm/test/MC/ELF/section-flags-changed.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-flags-changed.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=warning:
+
+foo:
+.section .foo,"ax", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section flags for .foo
+.section .foo,"awx", at progbits
+
+# CHECK: {{.*}}.s:[[# @LINE+1]]:1: warning: ignoring changed section flags for .foo
+.section .foo,"awo", at progbits,foo
+
+.pushsection .foo,"ax", at progbits
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73999.242437.patch
Type: text/x-patch
Size: 2253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200204/a1ed806d/attachment.bin>
More information about the llvm-commits
mailing list