[PATCH] D29719: [MC] Accept a numeric value as an ELF section header's type

Simon Atanasyan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 13:59:38 PST 2017


atanasyan updated this revision to Diff 91216.
atanasyan retitled this revision from "[MC] Accept and print a numeric value as an ELF section header's type" to "[MC] Accept a numeric value as an ELF section header's type".
atanasyan edited the summary of this revision.
atanasyan added a comment.
Herald added a subscriber: aprantl.

- Show an error if MCSectionELF attempt to print unknown section type value.
- Added a test case to check the error mentioned above.


Repository:
  rL LLVM

https://reviews.llvm.org/D29719

Files:
  lib/MC/MCParser/ELFAsmParser.cpp
  lib/MC/MCSectionELF.cpp
  test/MC/ELF/section-numeric-invalid-type.s
  test/MC/ELF/section-numeric-type.s


Index: test/MC/ELF/section-numeric-type.s
===================================================================
--- /dev/null
+++ test/MC/ELF/section-numeric-type.s
@@ -0,0 +1,20 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux-gnu %s -o - \
+// RUN:   | llvm-readobj -s -t | FileCheck --check-prefix=OBJ %s
+
+// RUN: llvm-mc -filetype=asm -triple=x86_64-pc-linux-gnu %s -o - \
+// RUN:   | FileCheck --check-prefix=ASM %s
+
+  .section .sec1,"a", at 0x70000001
+  .section .sec2,"a", at 1879048193
+
+// OBJ:      Section {
+// OBJ:        Name: .sec1
+// OBJ-NEXT:   Type: SHT_X86_64_UNWIND (0x70000001)
+// OBJ:      }
+// OBJ:      Section {
+// OBJ:        Name: .sec2
+// OBJ-NEXT:   Type: SHT_X86_64_UNWIND (0x70000001)
+// OBJ:      }
+
+// ASM: .section  .sec1,"a", at unwind
+// ASM: .section  .sec2,"a", at unwind
Index: test/MC/ELF/section-numeric-invalid-type.s
===================================================================
--- /dev/null
+++ test/MC/ELF/section-numeric-invalid-type.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux-gnu %s -o - \
+// RUN:   | llvm-readobj -s -t | FileCheck --check-prefix=OBJ %s
+
+// RUN: not llvm-mc -filetype=asm -triple=x86_64-pc-linux-gnu %s -o - 2>&1 \
+// RUN:   | FileCheck --check-prefix=ASM %s
+
+  .section .sec,"a", at 0x7fffffff
+
+// OBJ:      Section {
+// OBJ:        Name: .sec
+// OBJ-NEXT:   Type: (0x7FFFFFFF)
+// OBJ:      }
+
+// ASM: unsupported type 0x7fffffff for section .sec
Index: lib/MC/MCSectionELF.cpp
===================================================================
--- lib/MC/MCSectionELF.cpp
+++ lib/MC/MCSectionELF.cpp
@@ -12,6 +12,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/Support/ELF.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
 
@@ -140,6 +141,9 @@
     OS << "progbits";
   else if (Type == ELF::SHT_X86_64_UNWIND)
     OS << "unwind";
+  else
+    report_fatal_error("unsupported type 0x" + Twine::utohexstr(Type) +
+                       " for section " + getSectionName());
 
   if (EntrySize) {
     assert(Flags & ELF::SHF_MERGE);
Index: lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- lib/MC/MCParser/ELFAsmParser.cpp
+++ lib/MC/MCParser/ELFAsmParser.cpp
@@ -395,7 +395,10 @@
     return TokError("expected '@<type>', '%<type>' or \"<type>\"");
   if (!L.is(AsmToken::String))
     Lex();
-  if (getParser().parseIdentifier(TypeName))
+  if (L.is(AsmToken::Integer)) {
+    TypeName = getTok().getString();
+    Lex();
+  } else if (getParser().parseIdentifier(TypeName))
     return TokError("expected identifier in directive");
   return false;
 }
@@ -580,7 +583,7 @@
       Type = ELF::SHT_NOTE;
     else if (TypeName == "unwind")
       Type = ELF::SHT_X86_64_UNWIND;
-    else
+    else if (TypeName.getAsInteger(0, Type))
       return TokError("unknown section type");
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29719.91216.patch
Type: text/x-patch
Size: 2962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170309/40a5690d/attachment.bin>


More information about the llvm-commits mailing list