summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptParser.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2018-08-06 21:29:41 +0000
committerRui Ueyama <ruiu@google.com>2018-08-06 21:29:41 +0000
commite262bb1afb391eb705cf2fa733e04cca6d51bf47 (patch)
tree7a5ffe9160b74fabf89cc33427b12c6ba959e4e9 /lld/ELF/ScriptParser.cpp
parent5327805d7cadb5cf25ef520bc1dd034a94734f52 (diff)
downloadbcm5719-llvm-e262bb1afb391eb705cf2fa733e04cca6d51bf47.tar.gz
bcm5719-llvm-e262bb1afb391eb705cf2fa733e04cca6d51bf47.zip
Add TARGET(foo) linker script directive.
GNU ld's manual says that TARGET(foo) is basically an alias for `--format foo` where foo is a BFD target name such as elf64-x86-64. Unlike GNU linkers, lld doesn't allow arbitrary BFD target name for --format. We accept only "default", "elf" or "binary". This makes situation a bit tricky because we can't simply make TARGET an alias for --target. A quick code search revealed that the usage number of TARGET is very small, and the only meaningful usage is to switch to the binary mode. Thus, in this patch, we handle only TARGET(elf.*) and TARGET(binary). Differential Revision: https://reviews.llvm.org/D48153 llvm-svn: 339060
Diffstat (limited to 'lld/ELF/ScriptParser.cpp')
-rw-r--r--lld/ELF/ScriptParser.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index ddb4a49a3e5..ffc69b265f7 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -72,6 +72,7 @@ private:
void readRegionAlias();
void readSearchDir();
void readSections();
+ void readTarget();
void readVersion();
void readVersionScriptCommand();
@@ -255,6 +256,8 @@ void ScriptParser::readLinkerScript() {
readSearchDir();
} else if (Tok == "SECTIONS") {
readSections();
+ } else if (Tok == "TARGET") {
+ readTarget();
} else if (Tok == "VERSION") {
readVersion();
} else if (SymbolAssignment *Cmd = readAssignment(Tok)) {
@@ -522,6 +525,23 @@ void ScriptParser::readSections() {
V.end());
}
+void ScriptParser::readTarget() {
+ // TARGET(foo) is an alias for "--format foo". Unlike GNU linkers,
+ // we accept only a limited set of BFD names (i.e. "elf" or "binary")
+ // for --format. We recognize only /^elf/ and "binary" in the linker
+ // script as well.
+ expect("(");
+ StringRef Tok = next();
+ expect(")");
+
+ if (Tok.startswith("elf"))
+ Config->FormatBinary = false;
+ else if (Tok == "binary")
+ Config->FormatBinary = true;
+ else
+ setError("unknown target: " + Tok);
+}
+
static int precedence(StringRef Op) {
return StringSwitch<int>(Op)
.Cases("*", "/", "%", 8)
OpenPOWER on IntegriCloud