summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2018-12-19 10:19:40 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2018-12-19 10:19:40 +0000
commitf53694e8169ba85a2b2f5c370c5947070b44a601 (patch)
treed8d5f5c79e4dd48af5933a57752ad97c70dc3dbd /lld
parentb72cc1192980492e182f95d0c6e14b4923eaa651 (diff)
[LLD][ELF] - Report a location for symbols from the linker script when reporting an error.
When we report an error for symbols defined in the linker script, we do not report the location properly. For example: ld.lld: error: relocation R_AARCH64_CALL26 cannot refer to absolute symbol: aliasto__text >>> defined in <internal> >>> referenced by rtoabs.o:(.text+0x4) This patch fixes that. Differential revision: https://reviews.llvm.org/D55360
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Relocations.cpp17
-rw-r--r--lld/test/ELF/linkerscript/symbol-location.s15
2 files changed, 30 insertions, 2 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index c75ae4f823f..e01fdd2ee0d 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -66,6 +66,14 @@ using namespace llvm::support::endian;
using namespace lld;
using namespace lld::elf;
+static Optional<std::string> getLinkerScriptLocation(const Symbol &Sym) {
+ for (BaseCommand *Base : Script->SectionCommands)
+ if (auto *Cmd = dyn_cast<SymbolAssignment>(Base))
+ if (Cmd->Sym == &Sym)
+ return Cmd->Location;
+ return None;
+}
+
// Construct a message in the following format.
//
// >>> defined in /home/alice/src/foo.o
@@ -73,8 +81,13 @@ using namespace lld::elf;
// >>> /home/alice/src/bar.o:(.text+0x1)
static std::string getLocation(InputSectionBase &S, const Symbol &Sym,
uint64_t Off) {
- std::string Msg =
- "\n>>> defined in " + toString(Sym.File) + "\n>>> referenced by ";
+ std::string Msg = "\n>>> defined in ";
+ if (Sym.File)
+ Msg += toString(Sym.File);
+ else if (Optional<std::string> Loc = getLinkerScriptLocation(Sym))
+ Msg += *Loc;
+
+ Msg += "\n>>> referenced by ";
std::string Src = S.getSrcMsg(Sym, Off);
if (!Src.empty())
Msg += Src + "\n>>> ";
diff --git a/lld/test/ELF/linkerscript/symbol-location.s b/lld/test/ELF/linkerscript/symbol-location.s
new file mode 100644
index 00000000000..323d237e153
--- /dev/null
+++ b/lld/test/ELF/linkerscript/symbol-location.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "foo = 1;" > %t.script
+# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | FileCheck %s
+
+## Here we check that symbol 'foo' location is reported properly.
+
+# CHECK: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo
+# CHECK: >>> defined in {{.*}}.script:1
+# CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
+
+.text
+.globl _start
+_start:
+ call foo@PLT