diff options
| -rw-r--r-- | lld/ELF/Relocations.cpp | 15 | ||||
| -rw-r--r-- | 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 0f03857985b..9a294839300 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -401,9 +401,13 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol<ELFT> *SS) { } template <class ELFT> -static StringRef getLocalSymbolName(const elf::ObjectFile<ELFT> &File, - SymbolBody &Body) { - return File.getStringTable().data() + Body.getNameOffset(); +static StringRef getSymbolName(const elf::ObjectFile<ELFT> &File, + SymbolBody &Body) { + if (Body.isLocal() && Body.getNameOffset()) + return File.getStringTable().data() + Body.getNameOffset(); + if (!Body.isLocal()) + return Body.getName(); + return ""; } template <class ELFT> @@ -428,10 +432,9 @@ static RelExpr adjustExpr(const elf::ObjectFile<ELFT> &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 72ab49bf674..2ef36f695fb 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 |

