[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
llvm-svn: 302668
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e0e8069..e416c8d 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -48,8 +48,12 @@
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;
}