blob: cd977c5e1291bac252791cae5bc807e93fa2109f [file] [log] [blame]
Peter Collingbourne66ac1d62016-04-22 20:21:26 +00001//===- SymbolListFile.cpp -------------------------------------------------===//
Adhemerval Zanella9df07202016-04-13 18:51:11 +00002//
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 Collingbourne66ac1d62016-04-22 20:21:26 +000016#include "SymbolListFile.h"
Adhemerval Zanella9df07202016-04-13 18:51:11 +000017#include "Config.h"
18#include "ScriptParser.h"
19#include "llvm/Support/MemoryBuffer.h"
Adhemerval Zanella9df07202016-04-13 18:51:11 +000020
21using namespace llvm;
Rui Ueyama25068662016-07-16 03:08:26 +000022using namespace llvm::ELF;
23
Adhemerval Zanella9df07202016-04-13 18:51:11 +000024using namespace lld;
25using namespace lld::elf;
26
27// Parse the --dynamic-list argument. A dynamic list is in the form
28//
29// { symbol1; symbol2; [...]; symbolN };
30//
Rui Ueyama52654eb2016-07-16 03:45:59 +000031// Multiple groups can be defined in the same file, and they are merged
32// into a single group.
Adhemerval Zanella9df07202016-04-13 18:51:11 +000033
Benjamin Kramerdf8f1962016-08-06 13:52:37 +000034namespace {
Adhemerval Zanella9df07202016-04-13 18:51:11 +000035class DynamicListParser final : public ScriptParserBase {
36public:
37 DynamicListParser(StringRef S) : ScriptParserBase(S) {}
Rui Ueyama4a465392016-04-22 22:59:24 +000038 void run();
Adhemerval Zanella9df07202016-04-13 18:51:11 +000039};
Benjamin Kramerdf8f1962016-08-06 13:52:37 +000040} // end anonymous namespace
Adhemerval Zanella9df07202016-04-13 18:51:11 +000041
Adhemerval Zanella9df07202016-04-13 18:51:11 +000042void DynamicListParser::run() {
Rui Ueyama52654eb2016-07-16 03:45:59 +000043 while (!atEOF()) {
44 expect("{");
45 while (!Error) {
46 Config->DynamicList.push_back(next());
47 expect(";");
48 if (skip("}"))
49 break;
50 }
51 expect(";");
52 }
Adhemerval Zanella9df07202016-04-13 18:51:11 +000053}
54
55void elf::parseDynamicList(MemoryBufferRef MB) {
56 DynamicListParser(MB.getBuffer()).run();
57}