diff options
author | Fangrui Song <i@maskray.me> | 2020-11-12 08:46:53 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-11-12 08:46:53 -0800 |
commit | 2a9aed0e8b538955f38f036bd34ea79adfce2ad7 (patch) | |
tree | a419eaa7a8fbffe445f16e498ce14a497ed9cb48 /lld/ELF/ScriptParser.cpp | |
parent | 170e45ae186b3eed16898db933c94a85ac623933 (diff) | |
download | llvm-2a9aed0e8b538955f38f036bd34ea79adfce2ad7.zip llvm-2a9aed0e8b538955f38f036bd34ea79adfce2ad7.tar.gz llvm-2a9aed0e8b538955f38f036bd34ea79adfce2ad7.tar.bz2 |
[ELF] Support multiple SORT in an input section description
The second `SORT` in `*(SORT(...) SORT(...))` is incorrectly parsed as a file pattern.
Fix the bug by stopping at `SORT*` in `readInputSectionsList`.
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D91180
Diffstat (limited to 'lld/ELF/ScriptParser.cpp')
-rw-r--r-- | lld/ELF/ScriptParser.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 5a81311..c68d7f4 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -102,6 +102,7 @@ private: uint64_t withFlags, uint64_t withoutFlags); unsigned readPhdrType(); + SortSectionPolicy peekSortKind(); SortSectionPolicy readSortKind(); SymbolAssignment *readProvideHidden(bool provide, bool hidden); SymbolAssignment *readAssignment(StringRef tok); @@ -618,16 +619,20 @@ StringMatcher ScriptParser::readFilePatterns() { return Matcher; } +SortSectionPolicy ScriptParser::peekSortKind() { + return StringSwitch<SortSectionPolicy>(peek()) + .Cases("SORT", "SORT_BY_NAME", SortSectionPolicy::Name) + .Case("SORT_BY_ALIGNMENT", SortSectionPolicy::Alignment) + .Case("SORT_BY_INIT_PRIORITY", SortSectionPolicy::Priority) + .Case("SORT_NONE", SortSectionPolicy::None) + .Default(SortSectionPolicy::Default); +} + SortSectionPolicy ScriptParser::readSortKind() { - if (consume("SORT") || consume("SORT_BY_NAME")) - return SortSectionPolicy::Name; - if (consume("SORT_BY_ALIGNMENT")) - return SortSectionPolicy::Alignment; - if (consume("SORT_BY_INIT_PRIORITY")) - return SortSectionPolicy::Priority; - if (consume("SORT_NONE")) - return SortSectionPolicy::None; - return SortSectionPolicy::Default; + SortSectionPolicy ret = peekSortKind(); + if (ret != SortSectionPolicy::Default) + skip(); + return ret; } // Reads SECTIONS command contents in the following form: @@ -653,11 +658,15 @@ std::vector<SectionPattern> ScriptParser::readInputSectionsList() { } StringMatcher SectionMatcher; - while (!errorCount() && peek() != ")" && peek() != "EXCLUDE_FILE") + // Break if the next token is ), EXCLUDE_FILE, or SORT*. + while (!errorCount() && peek() != ")" && peek() != "EXCLUDE_FILE" && + peekSortKind() == SortSectionPolicy::Default) SectionMatcher.addPattern(unquote(next())); if (!SectionMatcher.empty()) ret.push_back({std::move(excludeFilePat), std::move(SectionMatcher)}); + else if (excludeFilePat.empty()) + break; else setError("section pattern is expected"); } |