diff options
| author | Rui Ueyama <ruiu@google.com> | 2016-09-17 02:15:28 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2016-09-17 02:15:28 +0000 |
| commit | 3ff27f49cdad093957a50470b0738cdb5c9c0ed6 (patch) | |
| tree | f79afe359ad03bee2cb5452d2fdaf1c3f6278016 | |
| parent | 027a9e8787b328a8c2ddcf3d2845a42b90a826ce (diff) | |
| download | bcm5719-llvm-3ff27f49cdad093957a50470b0738cdb5c9c0ed6.tar.gz bcm5719-llvm-3ff27f49cdad093957a50470b0738cdb5c9c0ed6.zip | |
Define a versatile utility function and use it instead of a single purpose one.
llvm-svn: 281802
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index c5633a14d04..148e9af4ab9 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -109,10 +109,10 @@ bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) { return false; } -static bool fileMatches(const Regex &FileRe, const Regex &ExcludedFileRe, - StringRef Filename) { - return const_cast<Regex &>(FileRe).match(Filename) && - !const_cast<Regex &>(ExcludedFileRe).match(Filename); +// We need to use const_cast because match() is not a const function. +// This function encapsulates that ugliness. +static bool match(const Regex &Re, StringRef S) { + return const_cast<Regex &>(Re).match(S); } static bool comparePriority(InputSectionData *A, InputSectionData *B) { @@ -167,15 +167,14 @@ template <class ELFT> void LinkerScript<ELFT>::computeInputSections(InputSectionDescription *I) { for (const std::pair<Regex, Regex> &V : I->SectionsVec) { for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) { - if (fileMatches(I->FileRe, V.first, sys::path::filename(F->getName()))) { - Regex &Re = const_cast<Regex &>(V.second); - for (InputSectionBase<ELFT> *S : F->getSections()) - if (!isDiscarded(S) && !S->OutSec && Re.match(S->Name)) - I->Sections.push_back(S); - - if (Re.match("COMMON")) - I->Sections.push_back(CommonInputSection<ELFT>::X); - } + StringRef Filename = sys::path::filename(F->getName()); + if (!match(I->FileRe, Filename) || match(V.first, Filename)) + continue; + for (InputSectionBase<ELFT> *S : F->getSections()) + if (!isDiscarded(S) && !S->OutSec && match(V.second, S->Name)) + I->Sections.push_back(S); + if (match(V.second, "COMMON")) + I->Sections.push_back(CommonInputSection<ELFT>::X); } } |

