Skip to content

Commit

Permalink
Produce INIT_ARRAY for sections named .init_array.*
Browse files Browse the repository at this point in the history
These sections are merged together by the linker, so they should have
the same time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298505 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Mar 22, 2017
1 parent 6176e44 commit 354d235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/MC/MCParser/ELFAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) {
return false;
}

static bool hasPrefix(StringRef SectionName, StringRef Prefix) {
return SectionName.startswith(Prefix) || SectionName == Prefix.drop_back();
}

bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
StringRef SectionName;

Expand Down Expand Up @@ -565,7 +569,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) {
if (TypeName.empty()) {
if (SectionName.startswith(".note"))
Type = ELF::SHT_NOTE;
else if (SectionName == ".init_array")
else if (hasPrefix(SectionName, ".init_array."))
Type = ELF::SHT_INIT_ARRAY;
else if (SectionName == ".fini_array")
Type = ELF::SHT_FINI_ARRAY;
Expand Down
4 changes: 4 additions & 0 deletions test/MC/AsmParser/section_names.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
.byte 1
.section .init_array
.byte 1
.section .init_array.42
.byte 1
.section .init_array2
.byte 1
.section .init_arrayfoo
Expand Down Expand Up @@ -38,6 +40,8 @@
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK: Name: .init_array
# CHECK-NEXT: Type: SHT_INIT_ARRAY
# CHECK: Name: .init_array.42
# CHECK-NEXT: Type: SHT_INIT_ARRAY
# CHECK: Name: .init_array2
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK: Name: .init_arrayfoo
Expand Down

0 comments on commit 354d235

Please sign in to comment.