summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2016-08-18 04:34:27 +0000
committerPetr Hosek <phosek@chromium.org>2016-08-18 04:34:27 +0000
commit0df80bef9631ae50cdb37e16956020b92dc6e38c (patch)
tree0453f48f695be0d5d4237bc684628e18ecd0e67f
parentc7c81fa197ba6d1671004519f544e0c061629a76 (diff)
downloadbcm5719-llvm-0df80bef9631ae50cdb37e16956020b92dc6e38c.tar.gz
bcm5719-llvm-0df80bef9631ae50cdb37e16956020b92dc6e38c.zip
[ELF] Linkerscript: support assignment outside SECTIONS
We only support assignments inside SECTIONS, but this does not match the behavior of GNU linker which also allows them outside SECTIONS. The only restriction on assignments outside SECTIONS is that they cannot reference . (they have to be absolute expressions). Differential Revision: https://reviews.llvm.org/D23598 llvm-svn: 279033
-rw-r--r--lld/ELF/LinkerScript.cpp2
-rw-r--r--lld/test/ELF/invalid-linkerscript.test2
-rw-r--r--lld/test/ELF/linkerscript/linkerscript-symbols.s26
3 files changed, 29 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 4d8cec0fb8b..922c7da6f32 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -655,6 +655,8 @@ void ScriptParser::run() {
StringRef Tok = next();
if (Handler Fn = Cmd.lookup(Tok))
(this->*Fn)();
+ else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok))
+ Opt.Commands.emplace_back(Cmd);
else
setError("unknown directive: " + Tok);
}
diff --git a/lld/test/ELF/invalid-linkerscript.test b/lld/test/ELF/invalid-linkerscript.test
index e0881662b96..3316becce1d 100644
--- a/lld/test/ELF/invalid-linkerscript.test
+++ b/lld/test/ELF/invalid-linkerscript.test
@@ -15,7 +15,7 @@
# RUN: echo foobar > %t1
# RUN: not ld.lld %t1 no-such-file 2>&1 | FileCheck -check-prefix=ERR1 %s
-# ERR1: unknown directive: foobar
+# ERR1: unexpected EOF
# ERR1: cannot open no-such-file:
# RUN: echo "foo \"bar" > %t2
diff --git a/lld/test/ELF/linkerscript/linkerscript-symbols.s b/lld/test/ELF/linkerscript/linkerscript-symbols.s
index 4cd1a27c892..8136b5fd5c5 100644
--- a/lld/test/ELF/linkerscript/linkerscript-symbols.s
+++ b/lld/test/ELF/linkerscript/linkerscript-symbols.s
@@ -41,6 +41,32 @@
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN3 %s
# HIDDEN3: 0000000000000001 *ABS* 00000000 .hidden newsym
+# The symbol is not referenced. Don't provide it.
+# RUN: echo "PROVIDE(newsym = 1);" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE4 %s
+# PROVIDE4-NOT: 0000000000000001 *ABS* 00000000 newsym
+
+# The symbol is not referenced. Don't provide it.
+# RUN: echo "PROVIDE_HIDDEN(newsym = 1);" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN4 %s
+# HIDDEN4-NOT: 0000000000000001 *ABS* 00000000 .hidden newsym
+
+# Provide existing symbol. The value should be 0, even though we
+# have value of 1 in PROVIDE()
+# RUN: echo "PROVIDE(somesym = 1);" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE5 %s
+# PROVIDE5: 0000000000000000 *ABS* 00000000 somesym
+
+# Provide existing symbol. The value should be 0, even though we
+# have value of 1 in PROVIDE_HIDDEN(). Visibility should not change
+# RUN: echo "PROVIDE_HIDDEN(somesym = 1);" > %t.script
+# RUN: ld.lld -o %t1 --script %t.script %t
+# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN5 %s
+# HIDDEN5: 0000000000000000 *ABS* 00000000 somesym
+
.global _start
_start:
nop
OpenPOWER on IntegriCloud