summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/Relocations.cpp10
-rw-r--r--lld/test/ELF/Inputs/x86-64-relax-offset.s7
-rw-r--r--lld/test/ELF/x86-64-relax-offset.s13
3 files changed, 25 insertions, 5 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 4d068cf6c1c..f6e4b03ed3c 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -511,15 +511,15 @@ static void scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
uint32_t Type = RI.getType(Config->Mips64EL);
RelExpr Expr = Target->getRelExpr(Type, Body);
- uintX_t Offset = C.getOffset(RI.r_offset);
- if (Offset == (uintX_t)-1)
- continue;
-
bool Preemptible = isPreemptible(Body, Type);
- Expr = adjustExpr(File, Body, IsWrite, Expr, Type, Buf + Offset);
+ Expr = adjustExpr(File, Body, IsWrite, Expr, Type, Buf + RI.r_offset);
if (HasError)
continue;
+ uintX_t Offset = C.getOffset(RI.r_offset);
+ if (Offset == (uintX_t)-1)
+ continue;
+
// This relocation does not require got entry, but it is relative to got and
// needs it to be created. Here we request for that.
if (Expr == R_GOTONLY_PC || Expr == R_GOTREL || Expr == R_PPC_TOC)
diff --git a/lld/test/ELF/Inputs/x86-64-relax-offset.s b/lld/test/ELF/Inputs/x86-64-relax-offset.s
new file mode 100644
index 00000000000..780d1d0e64c
--- /dev/null
+++ b/lld/test/ELF/Inputs/x86-64-relax-offset.s
@@ -0,0 +1,7 @@
+.global foo
+.hidden foo
+foo:
+ nop
+ nop
+ nop
+ nop
diff --git a/lld/test/ELF/x86-64-relax-offset.s b/lld/test/ELF/x86-64-relax-offset.s
new file mode 100644
index 00000000000..a7c7ce6f627
--- /dev/null
+++ b/lld/test/ELF/x86-64-relax-offset.s
@@ -0,0 +1,13 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-pc-linux %s \
+// RUN: -o %t.o
+// RUN: llvm-mc -filetype=obj -relax-relocations -triple=x86_64-pc-linux \
+// RUN: %p/Inputs/x86-64-relax-offset.s -o %t2.o
+// RUN: ld.lld %t2.o %t.o -o %t.so -shared
+// RUN: llvm-objdump -d %t.so | FileCheck %s
+
+ mov foo@gotpcrel(%rip), %rax
+ nop
+
+// CHECK: 1004: {{.*}} leaq -11(%rip), %rax
+// CHECK-NEXT: 100b: {{.*}} nop
OpenPOWER on IntegriCloud