2016-04-23 04:21:26 +08:00
|
|
|
//===- SymbolListFile.cpp -------------------------------------------------===//
|
2016-04-14 02:51:11 +08:00
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the parser/evaluator of the linker script.
|
|
|
|
// It does not construct an AST but consume linker script directives directly.
|
|
|
|
// Results are written to Driver or Config object.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-04-23 04:21:26 +08:00
|
|
|
#include "SymbolListFile.h"
|
2016-04-14 02:51:11 +08:00
|
|
|
#include "Config.h"
|
|
|
|
#include "ScriptParser.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf;
|
|
|
|
|
|
|
|
// Parse the --dynamic-list argument. A dynamic list is in the form
|
|
|
|
//
|
|
|
|
// { symbol1; symbol2; [...]; symbolN };
|
|
|
|
//
|
|
|
|
// Multiple groups can be defined in the same file and they are merged
|
|
|
|
// in only one definition.
|
|
|
|
|
|
|
|
class DynamicListParser final : public ScriptParserBase {
|
|
|
|
public:
|
|
|
|
DynamicListParser(StringRef S) : ScriptParserBase(S) {}
|
|
|
|
|
2016-04-23 06:59:24 +08:00
|
|
|
void run();
|
2016-04-14 02:51:11 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void readGroup();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parse the default group definition using C language symbol name.
|
|
|
|
void DynamicListParser::readGroup() {
|
|
|
|
expect("{");
|
|
|
|
while (!Error) {
|
|
|
|
Config->DynamicList.push_back(next());
|
|
|
|
expect(";");
|
|
|
|
if (peek() == "}") {
|
|
|
|
next();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expect(";");
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicListParser::run() {
|
|
|
|
while (!atEOF())
|
|
|
|
readGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void elf::parseDynamicList(MemoryBufferRef MB) {
|
|
|
|
DynamicListParser(MB.getBuffer()).run();
|
|
|
|
}
|
2016-04-23 04:21:26 +08:00
|
|
|
|
|
|
|
// Parse the --version-script argument. We currently only accept the following
|
|
|
|
// version script syntax:
|
|
|
|
//
|
|
|
|
// { [ global: symbol1; symbol2; [...]; symbolN; ] local: *; };
|
|
|
|
//
|
|
|
|
// No wildcards are supported, other than for the local entry. Symbol versioning
|
|
|
|
// is also not supported.
|
|
|
|
|
|
|
|
class VersionScriptParser final : public ScriptParserBase {
|
|
|
|
public:
|
|
|
|
VersionScriptParser(StringRef S) : ScriptParserBase(S) {}
|
|
|
|
|
2016-04-23 06:59:24 +08:00
|
|
|
void run();
|
2016-06-17 02:47:04 +08:00
|
|
|
|
|
|
|
private:
|
2016-06-20 18:29:53 +08:00
|
|
|
void parseVersion();
|
2016-06-17 21:38:09 +08:00
|
|
|
void parseLocal();
|
2016-06-20 18:29:53 +08:00
|
|
|
void parseVersionSymbols();
|
2016-04-23 04:21:26 +08:00
|
|
|
};
|
|
|
|
|
2016-06-20 18:29:53 +08:00
|
|
|
void VersionScriptParser::parseVersion() {
|
2016-04-23 04:21:26 +08:00
|
|
|
expect("{");
|
|
|
|
if (peek() == "global:") {
|
|
|
|
next();
|
2016-06-20 18:29:53 +08:00
|
|
|
parseVersionSymbols();
|
2016-04-23 04:21:26 +08:00
|
|
|
}
|
2016-06-17 21:38:09 +08:00
|
|
|
if (peek() == "local:")
|
|
|
|
parseLocal();
|
|
|
|
else
|
2016-06-20 18:29:53 +08:00
|
|
|
parseVersionSymbols();
|
2016-06-17 21:38:09 +08:00
|
|
|
|
|
|
|
expect("}");
|
|
|
|
expect(";");
|
|
|
|
}
|
|
|
|
|
|
|
|
void VersionScriptParser::parseLocal() {
|
2016-04-23 04:21:26 +08:00
|
|
|
expect("local:");
|
|
|
|
expect("*");
|
|
|
|
expect(";");
|
2016-06-17 21:38:09 +08:00
|
|
|
Config->VersionScriptGlobalByDefault = false;
|
|
|
|
}
|
|
|
|
|
2016-06-20 18:29:53 +08:00
|
|
|
void VersionScriptParser::parseVersionSymbols() {
|
2016-06-17 21:38:09 +08:00
|
|
|
for (;;) {
|
|
|
|
StringRef Cur = peek();
|
|
|
|
if (Cur == "}" || Cur == "local:")
|
|
|
|
return;
|
|
|
|
next();
|
2016-06-20 18:29:53 +08:00
|
|
|
Config->VersionScriptGlobals.push_back(Cur);
|
2016-06-17 21:38:09 +08:00
|
|
|
expect(";");
|
|
|
|
}
|
2016-06-17 02:47:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionScriptParser::run() {
|
|
|
|
StringRef Msg = "anonymous version definition is used in "
|
|
|
|
"combination with other version definitions";
|
|
|
|
if (peek() == "{") {
|
2016-06-20 18:29:53 +08:00
|
|
|
parseVersion();
|
2016-06-17 02:47:04 +08:00
|
|
|
if (!atEOF())
|
|
|
|
setError(Msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!atEOF() && !Error) {
|
2016-06-20 18:29:53 +08:00
|
|
|
if (next() == "{") {
|
2016-06-17 02:47:04 +08:00
|
|
|
setError(Msg);
|
|
|
|
return;
|
|
|
|
}
|
2016-06-20 18:29:53 +08:00
|
|
|
parseVersion();
|
2016-06-17 02:47:04 +08:00
|
|
|
}
|
2016-04-23 04:21:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void elf::parseVersionScript(MemoryBufferRef MB) {
|
|
|
|
VersionScriptParser(MB.getBuffer()).run();
|
|
|
|
}
|