[lld] r311073 - [ELF] - Don't segfault when accessing location counter inside MEMORY command.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 17 01:47:21 PDT 2017
Author: grimar
Date: Thu Aug 17 01:47:21 2017
New Revision: 311073
URL: http://llvm.org/viewvc/llvm-project?rev=311073&view=rev
Log:
[ELF] - Don't segfault when accessing location counter inside MEMORY command.
We would previously crash on next script:
MEMORY { name : ORIGIN = .; }
Patch fixes that.
Differential revision: https://reviews.llvm.org/D36138
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/memory-err.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=311073&r1=311072&r2=311073&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Aug 17 01:47:21 2017
@@ -842,8 +842,13 @@ bool LinkerScript::ignoreInterpSection()
}
ExprValue LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) {
- if (S == ".")
- return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr, Loc};
+ if (S == ".") {
+ if (CurAddressState)
+ return {CurAddressState->OutSec, Dot - CurAddressState->OutSec->Addr,
+ Loc};
+ error(Loc + ": unable to get location counter value");
+ return 0;
+ }
if (SymbolBody *B = Symtab->find(S)) {
if (auto *D = dyn_cast<DefinedRegular>(B))
return {D->Section, D->Value, Loc};
Modified: lld/trunk/test/ELF/linkerscript/memory-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/memory-err.s?rev=311073&r1=311072&r2=311073&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/memory-err.s (original)
+++ lld/trunk/test/ELF/linkerscript/memory-err.s Thu Aug 17 01:47:21 2017
@@ -8,3 +8,9 @@
# RUN: not ld.lld -shared -o %t2 --script %t.script %t 2>&1 |\
# RUN: FileCheck %s --check-prefix=ERR2
# ERR2: error: {{.*}}.script:1: unable to calculate page size
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "MEMORY { name : ORIGIN = .; }" > %t.script
+# RUN: not ld.lld -shared -o %t2 --script %t.script %t 2>&1 |\
+# RUN: FileCheck %s --check-prefix=ERR3
+# ERR3: error: {{.*}}.script:1: unable to get location counter value
More information about the llvm-commits
mailing list