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 19:55:12 +08:00
|
|
|
void parseVersion(StringRef Version);
|
2016-06-17 21:38:09 +08:00
|
|
|
void parseLocal();
|
2016-06-20 19:55:12 +08:00
|
|
|
void parseVersionSymbols(StringRef Version);
|
2016-04-23 04:21:26 +08:00
|
|
|
};
|
|
|
|
|
2016-06-20 19:55:12 +08:00
|
|
|
void VersionScriptParser::parseVersion(StringRef Version) {
|
2016-04-23 04:21:26 +08:00
|
|
|
expect("{");
|
|
|
|
if (peek() == "global:") {
|
|
|
|
next();
|
2016-06-20 19:55:12 +08:00
|
|
|
parseVersionSymbols(Version);
|
2016-04-23 04:21:26 +08:00
|
|
|
}
|
2016-06-17 21:38:09 +08:00
|
|
|
if (peek() == "local:")
|
|
|
|
parseLocal();
|
|
|
|
else
|
2016-06-20 19:55:12 +08:00
|
|
|
parseVersionSymbols(Version);
|
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 19:55:12 +08:00
|
|
|
void VersionScriptParser::parseVersionSymbols(StringRef Version) {
|
|
|
|
std::vector<StringRef> *Globals;
|
|
|
|
if (Version.empty()) {
|
|
|
|
Globals = &Config->VersionScriptGlobals;
|
|
|
|
} else {
|
|
|
|
Config->SymbolVersions.push_back(elf::Version(Version));
|
|
|
|
Globals = &Config->SymbolVersions.back().Globals;
|
|
|
|
}
|
|
|
|
|
2016-06-17 21:38:09 +08:00
|
|
|
for (;;) {
|
|
|
|
StringRef Cur = peek();
|
2016-06-20 22:02:22 +08:00
|
|
|
if (Cur == "}" || Cur == "local:" || Error)
|
2016-06-17 21:38:09 +08:00
|
|
|
return;
|
|
|
|
next();
|
2016-06-20 19:55:12 +08:00
|
|
|
Globals->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 19:55:12 +08:00
|
|
|
parseVersion("");
|
2016-06-17 02:47:04 +08:00
|
|
|
if (!atEOF())
|
|
|
|
setError(Msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!atEOF() && !Error) {
|
2016-06-20 19:55:12 +08:00
|
|
|
if (peek() == "{") {
|
2016-06-17 02:47:04 +08:00
|
|
|
setError(Msg);
|
|
|
|
return;
|
|
|
|
}
|
2016-06-20 19:55:12 +08:00
|
|
|
parseVersion(next());
|
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();
|
|
|
|
}
|