From 5b4f6c6b2870c2bd866d117a4e1fe1e45752cd9b Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 22 Aug 2016 19:01:53 +0000 Subject: [PATCH] [ELF] Only print symbol name when it is available Not only symbols (like sections) have names, in case where we fail to create relocation against such symbol, we should not print out an empty string, instead we should print a generic message. Differential Revision: https://reviews.llvm.org/D23731 llvm-svn: 279459 --- lld/ELF/Relocations.cpp | 15 +++++++++------ lld/test/ELF/dynamic-reloc-in-ro.s | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 0f03857..9a29483 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -401,9 +401,13 @@ template static void addCopyRelSymbol(SharedSymbol *SS) { } template -static StringRef getLocalSymbolName(const elf::ObjectFile &File, - SymbolBody &Body) { - return File.getStringTable().data() + Body.getNameOffset(); +static StringRef getSymbolName(const elf::ObjectFile &File, + SymbolBody &Body) { + if (Body.isLocal() && Body.getNameOffset()) + return File.getStringTable().data() + Body.getNameOffset(); + if (!Body.isLocal()) + return Body.getName(); + return ""; } template @@ -428,10 +432,9 @@ static RelExpr adjustExpr(const elf::ObjectFile &File, SymbolBody &Body, // only memory. We can hack around it if we are producing an executable and // the refered symbol can be preemepted to refer to the executable. if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) { - StringRef Name = Body.isLocal() ? getLocalSymbolName(File, Body) - : Body.getName(); + StringRef Name = getSymbolName(File, Body); error("can't create dynamic relocation " + getRelName(Type) + - " against symbol " + Name); + " against " + (Name.empty() ? "readonly segment" : "symbol " + Name)); return Expr; } if (Body.getVisibility() != STV_DEFAULT) { diff --git a/lld/test/ELF/dynamic-reloc-in-ro.s b/lld/test/ELF/dynamic-reloc-in-ro.s index 72ab49b..2ef36f6 100644 --- a/lld/test/ELF/dynamic-reloc-in-ro.s +++ b/lld/test/ELF/dynamic-reloc-in-ro.s @@ -5,4 +5,4 @@ foo: .quad foo -// CHECK: can't create dynamic relocation R_X86_64_64 against symbol +// CHECK: can't create dynamic relocation R_X86_64_64 against readonly segment -- 2.7.4