[PATCH] D73999: [MC][ELF] Warn changed section type or flags

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 9 09:41:21 PST 2020


MaskRay updated this revision to Diff 243452.
MaskRay marked 4 inline comments as done.
MaskRay added a comment.

Address review comments.

I tend to agree with Alan Modra's arguement in
https://sourceware.org/ml/binutils/2020-02/msg00093.html

> I don't think so.  User assembly often gets section attributes wrong
>  or leaves them off entirely for special sections known to the
>  assembler.  ie. the first .section .foo above is a built-in rather
>  than user input.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73999/new/

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,11 @@
+# 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
+.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
+.pushsection .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
@@ -634,9 +634,13 @@
       }
   }
 
-  MCSection *ELFSection = getContext().getELFSection(
+  MCSectionELF *ELFSection = getContext().getELFSection(
       SectionName, Type, Flags, Size, GroupName, UniqueID, LinkedToSym);
   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.243452.patch
Type: text/x-patch
Size: 2040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200209/85265943/attachment.bin>


More information about the llvm-commits mailing list