blob: 3fe83d470f29f87d315feb8074eee67ed47137ac [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"
George Rimarcd574a52016-09-09 14:35:36 +000019#include "Strings.h"
Adhemerval Zanella9df07202016-04-13 18:51:11 +000020#include "llvm/Support/MemoryBuffer.h"
Adhemerval Zanella9df07202016-04-13 18:51:11 +000021
22using namespace llvm;
Rui Ueyama25068662016-07-16 03:08:26 +000023using namespace llvm::ELF;
24
Adhemerval Zanella9df07202016-04-13 18:51:11 +000025using namespace lld;
26using namespace lld::elf;
27
28// Parse the --dynamic-list argument. A dynamic list is in the form
29//
30// { symbol1; symbol2; [...]; symbolN };
31//
Rui Ueyama52654eb2016-07-16 03:45:59 +000032// Multiple groups can be defined in the same file, and they are merged
33// into a single group.
Adhemerval Zanella9df07202016-04-13 18:51:11 +000034
Benjamin Kramerdf8f1962016-08-06 13:52:37 +000035namespace {
Adhemerval Zanella9df07202016-04-13 18:51:11 +000036class DynamicListParser final : public ScriptParserBase {
37public:
38 DynamicListParser(StringRef S) : ScriptParserBase(S) {}
Rui Ueyama4a465392016-04-22 22:59:24 +000039 void run();
Adhemerval Zanella9df07202016-04-13 18:51:11 +000040};
Benjamin Kramerdf8f1962016-08-06 13:52:37 +000041} // end anonymous namespace
Adhemerval Zanella9df07202016-04-13 18:51:11 +000042
Adhemerval Zanella9df07202016-04-13 18:51:11 +000043void DynamicListParser::run() {
Rui Ueyama52654eb2016-07-16 03:45:59 +000044 while (!atEOF()) {
45 expect("{");
46 while (!Error) {
George Rimarcd574a52016-09-09 14:35:36 +000047 Config->DynamicList.push_back(unquote(next()));
Rui Ueyama52654eb2016-07-16 03:45:59 +000048 expect(";");
49 if (skip("}"))
50 break;
51 }
52 expect(";");
53 }
Adhemerval Zanella9df07202016-04-13 18:51:11 +000054}
55
56void elf::parseDynamicList(MemoryBufferRef MB) {
57 DynamicListParser(MB.getBuffer()).run();
58}