Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -401,9 +401,13 @@ } 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 @@ // 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) { Index: lld/trunk/test/ELF/dynamic-reloc-in-ro.s =================================================================== --- lld/trunk/test/ELF/dynamic-reloc-in-ro.s +++ lld/trunk/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