[PATCH] D75518: [MC][ELF] Allow section directives with empty flags

Ilie Halip via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:21:20 PST 2020


ihalip created this revision.
ihalip created this object with visibility "All Users".
ihalip added a project: LLVM.
Herald added subscribers: llvm-commits, MaskRay, hiraditya, emaste.
Herald added a reviewer: espindola.
ihalip edited the summary of this revision.

Initially reported here: https://github.com/ClangBuiltLinux/linux/issues/913. I didn't create an entry in bugs.llvm.org because I think the change is very trivial.

GNU as allows empty flags in assembler section directives. LLVM on the other hand doesn't, if the section already exists with different flags. An example:

  $ cat vdso-note.s
  .pushsection .note.Linux, "a", at note ;
   .long 0x1234 ;
  .popsection ;
  
  .pushsection .note.Linux, "", at note ;
   .long 0x5678 ;
  .popsection ;
  
  $ as -o vdso-note.o vdso-note.s && objdump -D vdso-note.o
  [...]
  0000000000000000 <.note.Linux>:
     0:	34 12                	xor    $0x12,%al
     2:	00 00                	add    %al,(%rax)
     4:	78 56                	js     0x5c
  	...
  
  $ clang-11 -cc1as -triple x86_64-pc-linux-gnu -o vdso-note.o vdso-note.s
  vdso-note.s:5:1: error: changed section flags for .note.Linux, expected: 0x2
  .pushsection .note.Linux, "", at note ;
  ^

Just checking that Flags != 0 seems to do the trick.

The error message could be improved too (the 0x2 is a bit cryptic), I'll create a different review for that later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75518

Files:
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/test/MC/ELF/section-flags-empty.s


Index: llvm/test/MC/ELF/section-flags-empty.s
===================================================================
--- /dev/null
+++ llvm/test/MC/ELF/section-flags-empty.s
@@ -0,0 +1,25 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
+# RUN: llvm-readelf -S -x .foo -x .bar %t | FileCheck %s
+
+# CHECK-COUNT-1: .foo        {{.*}} AX
+# CHECK-COUNT-1: .bar        {{.*}} WAX
+
+# CHECK:      Hex dump of section '.foo':
+# CHECK-NEXT: 0x00000000 0103
+
+# CHECK:      Hex dump of section '.bar':
+# CHECK-NEXT: 0x00000000 0204
+
+.section .foo,"ax", at progbits
+.byte 1
+
+.pushsection .bar,"wax", at progbits
+.byte 2
+.popsection
+
+.section .foo,"", at progbits
+.byte 3
+
+.pushsection .bar,"", at progbits
+.byte 4
+.popsection
Index: llvm/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/lib/MC/MCParser/ELFAsmParser.cpp
@@ -640,7 +640,7 @@
   if (Section->getType() != Type)
     Error(loc, "changed section type for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getType()));
-  if (Section->getFlags() != Flags)
+  if (Flags && Section->getFlags() != Flags)
     Error(loc, "changed section flags for " + SectionName + ", expected: 0x" +
                    utohexstr(Section->getFlags()));
   if (Section->getEntrySize() != Size)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75518.247875.patch
Type: text/x-patch
Size: 1369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/40577308/attachment.bin>


More information about the llvm-commits mailing list