| Peter Collingbourne | 66ac1d6 | 2016-04-22 20:21:26 +0000 | [diff] [blame] | 1 | //===- SymbolListFile.cpp -------------------------------------------------===// |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the parser/evaluator of the linker script. |
| 11 | // It does not construct an AST but consume linker script directives directly. |
| 12 | // Results are written to Driver or Config object. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| Peter Collingbourne | 66ac1d6 | 2016-04-22 20:21:26 +0000 | [diff] [blame] | 16 | #include "SymbolListFile.h" |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 17 | #include "Config.h" |
| 18 | #include "ScriptParser.h" |
| George Rimar | cd574a5 | 2016-09-09 14:35:36 +0000 | [diff] [blame] | 19 | #include "Strings.h" |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MemoryBuffer.h" |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| Rui Ueyama | 2506866 | 2016-07-16 03:08:26 +0000 | [diff] [blame] | 23 | using namespace llvm::ELF; |
| 24 | |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 25 | using namespace lld; |
| 26 | using namespace lld::elf; |
| 27 | |
| 28 | // Parse the --dynamic-list argument. A dynamic list is in the form |
| 29 | // |
| 30 | // { symbol1; symbol2; [...]; symbolN }; |
| 31 | // |
| Rui Ueyama | 52654eb | 2016-07-16 03:45:59 +0000 | [diff] [blame] | 32 | // Multiple groups can be defined in the same file, and they are merged |
| 33 | // into a single group. |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 34 | |
| Benjamin Kramer | df8f196 | 2016-08-06 13:52:37 +0000 | [diff] [blame] | 35 | namespace { |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 36 | class DynamicListParser final : public ScriptParserBase { |
| 37 | public: |
| 38 | DynamicListParser(StringRef S) : ScriptParserBase(S) {} |
| Rui Ueyama | 4a46539 | 2016-04-22 22:59:24 +0000 | [diff] [blame] | 39 | void run(); |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 40 | }; |
| Benjamin Kramer | df8f196 | 2016-08-06 13:52:37 +0000 | [diff] [blame] | 41 | } // end anonymous namespace |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 42 | |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 43 | void DynamicListParser::run() { |
| Rui Ueyama | 52654eb | 2016-07-16 03:45:59 +0000 | [diff] [blame] | 44 | while (!atEOF()) { |
| 45 | expect("{"); |
| 46 | while (!Error) { |
| George Rimar | cd574a5 | 2016-09-09 14:35:36 +0000 | [diff] [blame] | 47 | Config->DynamicList.push_back(unquote(next())); |
| Rui Ueyama | 52654eb | 2016-07-16 03:45:59 +0000 | [diff] [blame] | 48 | expect(";"); |
| 49 | if (skip("}")) |
| 50 | break; |
| 51 | } |
| 52 | expect(";"); |
| 53 | } |
| Adhemerval Zanella | 9df0720 | 2016-04-13 18:51:11 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void elf::parseDynamicList(MemoryBufferRef MB) { |
| 57 | DynamicListParser(MB.getBuffer()).run(); |
| 58 | } |