[PATCH] D30229: [MC] Set defaults based on section names and support name suffixes

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 16:45:20 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL299484: [MC] Set defaults based on section names and support name suffixes (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D30229?vs=94109&id=94138#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D30229

Files:
  llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/trunk/test/MC/ELF/section.s


Index: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
===================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
@@ -493,11 +493,20 @@
   int64_t UniqueID = ~0;
 
   // Set the defaults first.
-  if (SectionName == ".fini" || SectionName == ".init" ||
-      SectionName == ".rodata")
+  if (hasPrefix(SectionName, ".rodata.") || SectionName == ".rodata1")
     Flags |= ELF::SHF_ALLOC;
-  if (SectionName == ".fini" || SectionName == ".init")
-    Flags |= ELF::SHF_EXECINSTR;
+  if (SectionName == ".fini" || SectionName == ".init" ||
+      hasPrefix(SectionName, ".text."))
+    Flags |= ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
+  if (hasPrefix(SectionName, ".data.") || SectionName == ".data1" ||
+      hasPrefix(SectionName, ".bss.") ||
+      hasPrefix(SectionName, ".init_array.") ||
+      hasPrefix(SectionName, ".fini_array.") ||
+      hasPrefix(SectionName, ".preinit_array."))
+    Flags |= ELF::SHF_ALLOC | ELF::SHF_WRITE;
+  if (hasPrefix(SectionName, ".tdata.") ||
+      hasPrefix(SectionName, ".tbss."))
+    Flags |= ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::SHF_TLS;
 
   if (getLexer().is(AsmToken::Comma)) {
     Lex();
@@ -575,9 +584,9 @@
       Type = ELF::SHT_NOBITS;
     else if (hasPrefix(SectionName, ".tbss."))
       Type = ELF::SHT_NOBITS;
-    else if (SectionName == ".fini_array")
+    else if (hasPrefix(SectionName, ".fini_array."))
       Type = ELF::SHT_FINI_ARRAY;
-    else if (SectionName == ".preinit_array")
+    else if (hasPrefix(SectionName, ".preinit_array."))
       Type = ELF::SHT_PREINIT_ARRAY;
   } else {
     if (TypeName == "init_array")
Index: llvm/trunk/test/MC/ELF/section.s
===================================================================
--- llvm/trunk/test/MC/ELF/section.s
+++ llvm/trunk/test/MC/ELF/section.s
@@ -220,3 +220,50 @@
 // CHECK-NEXT:   Size:
 // CHECK-NEXT:   Link:    22
 // CHECK-NEXT:   Info:    0
+
+.section	.text.foo
+// CHECK:        Section {
+// CHECK:          Name: .text.foo
+// CHECK-NEXT:     Type: SHT_PROGBITS
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:       SHF_ALLOC
+// CHECK-NEXT:       SHF_EXECINSTR
+// CHECK-NEXT:     ]
+
+.section .bss
+// CHECK:        Section {
+// CHECK:          Name: .bss
+// CHECK-NEXT:     Type: SHT_NOBITS
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:       SHF_ALLOC
+// CHECK-NEXT:       SHF_WRITE
+// CHECK-NEXT:     ]
+
+.section .bss.foo
+// CHECK:        Section {
+// CHECK:          Name: .bss.foo
+// CHECK-NEXT:     Type: SHT_NOBITS
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:       SHF_ALLOC
+// CHECK-NEXT:       SHF_WRITE
+// CHECK-NEXT:     ]
+
+.section .tbss
+// CHECK:        Section {
+// CHECK:          Name: .tbss
+// CHECK-NEXT:     Type: SHT_NOBITS
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:       SHF_ALLOC
+// CHECK-NEXT:       SHF_TLS
+// CHECK-NEXT:       SHF_WRITE
+// CHECK-NEXT:     ]
+
+.section .tbss.foo
+// CHECK:        Section {
+// CHECK:          Name: .tbss.foo
+// CHECK-NEXT:     Type: SHT_NOBITS
+// CHECK-NEXT:     Flags [
+// CHECK-NEXT:       SHF_ALLOC
+// CHECK-NEXT:       SHF_TLS
+// CHECK-NEXT:       SHF_WRITE
+// CHECK-NEXT:     ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30229.94138.patch
Type: text/x-patch
Size: 3209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/6d05fe89/attachment.bin>


More information about the llvm-commits mailing list