[llvm] r175327 - Derive ELF section type from the name in some cases where GNU as does
Joerg Sonnenberger
joerg at bec.de
Fri Feb 15 16:32:54 PST 2013
Author: joerg
Date: Fri Feb 15 18:32:53 2013
New Revision: 175327
URL: http://llvm.org/viewvc/llvm-project?rev=175327&view=rev
Log:
Derive ELF section type from the name in some cases where GNU as does
so.
Added:
llvm/trunk/test/MC/AsmParser/section_names.s
Modified:
llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp?rev=175327&r1=175326&r2=175327&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/ELFAsmParser.cpp Fri Feb 15 18:32:53 2013
@@ -413,7 +413,16 @@ bool ELFAsmParser::ParseDirectiveSection
unsigned Type = ELF::SHT_PROGBITS;
- if (!TypeName.empty()) {
+ if (TypeName.empty()) {
+ if (SectionName.startswith(".note"))
+ Type = ELF::SHT_NOTE;
+ else if (SectionName == ".init_array")
+ Type = ELF::SHT_INIT_ARRAY;
+ else if (SectionName == ".fini_array")
+ Type = ELF::SHT_FINI_ARRAY;
+ else if (SectionName == ".preinit_array")
+ Type = ELF::SHT_PREINIT_ARRAY;
+ } else {
if (TypeName == "init_array")
Type = ELF::SHT_INIT_ARRAY;
else if (TypeName == "fini_array")
Added: llvm/trunk/test/MC/AsmParser/section_names.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/section_names.s?rev=175327&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/section_names.s (added)
+++ llvm/trunk/test/MC/AsmParser/section_names.s Fri Feb 15 18:32:53 2013
@@ -0,0 +1,62 @@
+# RUN: llvm-mc -triple i386-pc-linux-gnu -filetype=obj -o %t %s
+# RUN: elf-dump --dump-section-data < %t | FileCheck %s
+.section .nobits
+.byte 1
+.section .nobits2
+.byte 1
+.section .nobitsfoo
+.byte 1
+.section .init_array
+.byte 1
+.section .init_array2
+.byte 1
+.section .init_arrayfoo
+.byte 1
+.section .fini_array
+.byte 1
+.section .fini_array2
+.byte 1
+.section .fini_arrayfoo
+.byte 1
+.section .preinit_array
+.byte 1
+.section .preinit_array2
+.byte 1
+.section .preinit_arrayfoo
+.byte 1
+.section .note
+.byte 1
+.section .note2
+.byte 1
+.section .notefoo
+.byte 1
+# CHECK: (('sh_name', 0x00000{{...}}) # '.nobits'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.nobits2'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.nobitsfoo'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.init_array'
+# CHECK-NEXT: ('sh_type', 0x0000000e)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.init_array2'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.init_arrayfoo'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.fini_array'
+# CHECK-NEXT: ('sh_type', 0x0000000f)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.fini_array2'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.fini_arrayfoo'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.preinit_array'
+# CHECK-NEXT: ('sh_type', 0x00000010)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.preinit_array2'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.preinit_arrayfoo'
+# CHECK-NEXT: ('sh_type', 0x00000001)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.note'
+# CHECK-NEXT: ('sh_type', 0x00000007)
+# CHECK: (('sh_name', 0x00000{{...}}) # '.note2'
+# CHECK-NEXT: ('sh_type', 0x00000007)
+#CHECK: (('sh_name', 0x00000{{...}}) # '.notefoo'
+# CHECK-NEXT: ('sh_type', 0x00000007)
More information about the llvm-commits
mailing list