[ELF] - Linkerscript: implemented SORT_BY_INIT_PRIORITY.

This is PR30386,

SORT_BY_INIT_PRIORITY is a keyword can be used to sort sections by numerical value of the
GCC init_priority attribute encoded in the section name.

Differential revision: https://reviews.llvm.org/D24611

llvm-svn: 281646
This commit is contained in:
George Rimar
2016-09-15 19:15:12 +00:00
parent a0601a40f7
commit 575208cabd
6 changed files with 47 additions and 14 deletions

View File

@@ -110,6 +110,10 @@ static bool fileMatches(const InputSectionDescription *Desc,
!const_cast<Regex &>(Desc->ExcludedFileRe).match(Filename);
}
static bool comparePriority(InputSectionData *A, InputSectionData *B) {
return getPriority(A->Name) < getPriority(B->Name);
}
static bool compareName(InputSectionData *A, InputSectionData *B) {
return A->Name < B->Name;
}
@@ -123,6 +127,8 @@ static bool compareAlignment(InputSectionData *A, InputSectionData *B) {
static std::function<bool(InputSectionData *, InputSectionData *)>
getComparator(SortKind K) {
if (K == SortByPriority)
return comparePriority;
if (K == SortByName)
return compareName;
return compareAlignment;
@@ -967,6 +973,8 @@ SortKind ScriptParser::readSortKind() {
return SortByName;
if (skip("SORT_BY_ALIGNMENT"))
return SortByAlignment;
if (skip("SORT_BY_INIT_PRIORITY"))
return SortByPriority;
return SortNone;
}