Set default type and flags for .init and .fini.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 27 Oct 2010 18:45:20 +0000 (18:45 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 27 Oct 2010 18:45:20 +0000 (18:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117471 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/ELFAsmParser.cpp
test/MC/ELF/section.s

index 33fdf98bcfc2fdc8ea0156f17e2f77ad7cf9a10a..83c562bf4a42edf3d808777a387860c91776de6f 100644 (file)
@@ -240,6 +240,15 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
     return TokError("unexpected token in directive");
 
   unsigned Flags = 0;
+  unsigned Type = MCSectionELF::SHT_NULL;
+
+  // Set the defaults first.
+  if (SectionName == ".fini" || SectionName == ".init") {
+    Type = MCSectionELF::SHT_PROGBITS;
+    Flags |= MCSectionELF::SHF_ALLOC;
+    Flags |= MCSectionELF::SHF_EXECINSTR;
+  }
+
   for (unsigned i = 0; i < FlagsStr.size(); i++) {
     switch (FlagsStr[i]) {
     case 'a':
@@ -271,7 +280,6 @@ bool ELFAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
     }
   }
 
-  unsigned Type = MCSectionELF::SHT_NULL;
   if (!TypeName.empty()) {
     if (TypeName == "init_array")
       Type = MCSectionELF::SHT_INIT_ARRAY;
index cc6fa4c31429a7820dba12fabfad9a953fb566c4..ea89a80f6ef1f600eac1d074001ab55ebfa25c58 100644 (file)
@@ -9,3 +9,31 @@
 // CHECK: ('sh_name', 0x00000012) # '.note.GNU-stack'
 // CHECK: ('sh_name', 0x00000022) # '.note.GNU-'
 // CHECK: ('sh_name', 0x0000002d) # '-.note.GNU'
+
+// Test that the dafults for init and fini are used
+
+.section       .init
+.section       .fini
+
+// CHECK:      (('sh_name', 0x00000038) # '.init'
+// CHECK-NEXT:  ('sh_type', 0x00000001)
+// CHECK-NEXT:  ('sh_flags', 0x00000006)
+// CHECK-NEXT:  ('sh_addr', 0x00000000)
+// CHECK-NEXT:  ('sh_offset', 0x00000040)
+// CHECK-NEXT:  ('sh_size', 0x00000000)
+// CHECK-NEXT:  ('sh_link', 0x00000000)
+// CHECK-NEXT:  ('sh_info', 0x00000000)
+// CHECK-NEXT:  ('sh_addralign', 0x00000001)
+// CHECK-NEXT:  ('sh_entsize', 0x00000000)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Section 0x00000008
+// CHECK-NEXT: (('sh_name', 0x0000003e) # '.fini'
+// CHECK-NEXT:  ('sh_type', 0x00000001)
+// CHECK-NEXT:  ('sh_flags', 0x00000006)
+// CHECK-NEXT:  ('sh_addr', 0x00000000)
+// CHECK-NEXT:  ('sh_offset', 0x00000040)
+// CHECK-NEXT:  ('sh_size', 0x00000000)
+// CHECK-NEXT:  ('sh_link', 0x00000000)
+// CHECK-NEXT:  ('sh_info', 0x00000000)
+// CHECK-NEXT:  ('sh_addralign', 0x00000001)
+// CHECK-NEXT:  ('sh_entsize', 0x00000000)