[lld] r302668 - [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed May 10 07:23:33 PDT 2017
Author: grimar
Date: Wed May 10 09:23:33 2017
New Revision: 302668
URL: http://llvm.org/viewvc/llvm-project?rev=302668&view=rev
Log:
[ELF] - Don't segfault when assigning non-calculatable absolute symbol value.
This is PR32664.
Issue was revealed by linux kernel script which was:
SECTIONS {
. = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000));
phys_startup_64 = ABSOLUTE(startup_64 - 0xffffffff80000000);
.text : AT(ADDR(.text) - 0xffffffff80000000) {
.....
*(.head.text)
Where startup_64 is in .head.text.
At the place of assignment to phys_startup_64 we can not calculate absolute value for startup_64
because .text section has no VA assigned. Two patches were prepared earlier to address this: D32173 and D32174.
And in comments for D32173 was suggested not try to support this case, but error out.
Differential revision: https://reviews.llvm.org/D32793
Added:
lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=302668&r1=302667&r2=302668&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed May 10 09:23:33 2017
@@ -48,8 +48,12 @@ using namespace lld::elf;
LinkerScript *elf::Script;
uint64_t ExprValue::getValue() const {
- if (Sec)
- return Sec->getOffset(Val) + Sec->getOutputSection()->Addr;
+ if (Sec) {
+ if (Sec->getOutputSection())
+ return Sec->getOffset(Val) + Sec->getOutputSection()->Addr;
+ error("unable to evaluate expression: input section " + Sec->Name +
+ " has no output section assigned");
+ }
return Val;
}
Added: lld/trunk/test/ELF/linkerscript/early-assign-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/early-assign-symbol.s?rev=302668&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/early-assign-symbol.s (added)
+++ lld/trunk/test/ELF/linkerscript/early-assign-symbol.s Wed May 10 09:23:33 2017
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo "SECTIONS { aaa = 1 + ABSOLUTE(foo - 1); }" > %t1.script
+# RUN: not ld.lld -o %t --script %t1.script %t.o 2>&1 | FileCheck %s
+
+# RUN: echo "SECTIONS { aaa = ABSOLUTE(foo - 1) + 1; }" > %t2.script
+# RUN: not ld.lld -o %t --script %t2.script %t.o 2>&1 | FileCheck %s
+
+# CHECK: error: unable to evaluate expression: input section .text has no output section assigned
+
+.section .text
+.globl foo
+foo:
More information about the llvm-commits
mailing list