[PATCH] D24685: Simplify SORT and --sort-section command line option handling.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 16 14:24:27 PDT 2016
ruiu updated this revision to Diff 71700.
ruiu added a comment.
Rebased.
https://reviews.llvm.org/D24685
Files:
ELF/LinkerScript.cpp
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -162,6 +162,12 @@
});
}
+void sortSections(std::vector<InputSectionData *> &Sections,
+ SortSectionPolicy K) {
+ if (K != SortSectionPolicy::Default)
+ std::stable_sort(Sections.begin(), Sections.end(), getComparator(K));
+}
+
// Compute and remember which sections the InputSectionDescription matches.
template <class ELFT>
void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I) {
@@ -179,12 +185,15 @@
}
}
- if (I->SortInner != SortSectionPolicy::Default)
- std::stable_sort(I->Sections.begin(), I->Sections.end(),
- getComparator(I->SortInner));
- if (I->SortOuter != SortSectionPolicy::Default)
- std::stable_sort(I->Sections.begin(), I->Sections.end(),
- getComparator(I->SortOuter));
+ // Sort sections by --sort-section and SORT_*() commands.
+ // We do not sort it at all if it was surrounded by SORT_NONE().
+ if (I->SortOuter != SortSectionPolicy::None) {
+ if (I->SortInner == SortSectionPolicy::Default)
+ sortSections(I->Sections, Config->SortSection);
+ else
+ sortSections(I->Sections, I->SortInner);
+ sortSections(I->Sections, I->SortOuter);
+ }
// We do not add duplicate input sections, so mark them with a dummy output
// section for now.
@@ -1006,27 +1015,6 @@
return SortSectionPolicy::Default;
}
-static void selectSortKind(InputSectionDescription *Cmd) {
- if (Cmd->SortOuter == SortSectionPolicy::None) {
- Cmd->SortOuter = SortSectionPolicy::Default;
- return;
- }
-
- if (Cmd->SortOuter != SortSectionPolicy::Default) {
- // If the section sorting command in linker script is nested, the command
- // line option will be ignored.
- if (Cmd->SortInner != SortSectionPolicy::Default)
- return;
- // If the section sorting command in linker script isn't nested, the
- // command line option will make the section sorting command to be treated
- // as nested sorting command.
- Cmd->SortInner = Config->SortSection;
- return;
- }
- // If sorting rule not specified, use command line option.
- Cmd->SortOuter = Config->SortSection;
-}
-
// Method reads a list of sequence of excluded files and section globs given in
// a following form: ((EXCLUDE_FILE(file_pattern+))? section_pattern+)+
// Example: *(.foo.1 EXCLUDE_FILE (*a.o) .foo.2 EXCLUDE_FILE (*b.o) .foo.3)
@@ -1077,11 +1065,9 @@
Cmd->SectionsVec.push_back({llvm::Regex(), readFilePatterns()});
}
expect(")");
- selectSortKind(Cmd);
return Cmd;
}
- selectSortKind(Cmd);
readSectionExcludes(Cmd);
return Cmd;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24685.71700.patch
Type: text/x-patch
Size: 2765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160916/407e89c8/attachment.bin>
More information about the llvm-commits
mailing list