From d598c8103a66823ed076b52320e1389a561c82b1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 27 Oct 2016 17:28:56 +0000 Subject: [PATCH] Be less aggressive at relaxing got access in this case. This fixes pr30803 by not relaxing that particular access. We could also let adjustRelaxExpr know that the target is absolute so that it uses R_RELAX_GOT_PC_NOPIC, but it is not clear if it is worth it. llvm-svn: 285317 --- lld/ELF/Relocations.cpp | 8 ++++++-- lld/test/ELF/x86-64-relax-got-abs.s | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lld/test/ELF/x86-64-relax-got-abs.s diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 875871b0ca63..e5dc0c4d0f29 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -286,6 +286,10 @@ template static bool isAbsolute(const SymbolBody &Body) { return false; } +template static bool isAbsoluteValue(const SymbolBody &Body) { + return isAbsolute(Body) || Body.isTls(); +} + static bool needsPlt(RelExpr Expr) { return Expr == R_PLT_PC || Expr == R_PPC_PLT_OPD || Expr == R_PLT || Expr == R_PLT_PAGE_PC || Expr == R_THUNK_PLT_PC; @@ -322,7 +326,7 @@ static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type, if (!Config->Pic) return true; - bool AbsVal = isAbsolute(Body) || Body.isTls(); + bool AbsVal = isAbsoluteValue(Body); bool RelE = isRelExpr(E); if (AbsVal && !RelE) return true; @@ -433,7 +437,7 @@ static RelExpr adjustExpr(const elf::ObjectFile &File, SymbolBody &Body, } else if (!Preemptible) { if (needsPlt(Expr)) Expr = fromPlt(Expr); - if (Expr == R_GOT_PC) + if (Expr == R_GOT_PC && !isAbsoluteValue(Body)) Expr = Target->adjustRelaxExpr(Type, Data, Expr); } Expr = Target->getThunkExpr(Expr, Type, File, Body); diff --git a/lld/test/ELF/x86-64-relax-got-abs.s b/lld/test/ELF/x86-64-relax-got-abs.s new file mode 100644 index 000000000000..c4291202f035 --- /dev/null +++ b/lld/test/ELF/x86-64-relax-got-abs.s @@ -0,0 +1,16 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-pc-linux %s \ +// RUN: -o %t.o +// RUN: ld.lld %t.o -o %t.so -shared +// RUN: llvm-objdump -d %t.so | FileCheck %s + +// We used to fail trying to relax this into a pc relocation to an absolute +// value. + +// CHECK: movq 4185(%rip), %rax + + movq bar@GOTPCREL(%rip), %rax + .data + .global bar + .hidden bar + bar = 42 -- GitLab