From 678844e68ace26245fb673a63b71cd3b696bc840 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 17 Jun 2016 15:42:36 +0000 Subject: [PATCH] Don't confuse input and output section offsets. llvm-svn: 273006 --- lld/ELF/Relocations.cpp | 10 +++++----- lld/test/ELF/Inputs/x86-64-relax-offset.s | 7 +++++++ lld/test/ELF/x86-64-relax-offset.s | 13 +++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 lld/test/ELF/Inputs/x86-64-relax-offset.s create mode 100644 lld/test/ELF/x86-64-relax-offset.s diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 4d068cf6c1c7..f6e4b03ed3c6 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -511,13 +511,13 @@ static void scanRelocs(InputSectionBase &C, ArrayRef 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) + bool Preemptible = isPreemptible(Body, Type); + Expr = adjustExpr(File, Body, IsWrite, Expr, Type, Buf + RI.r_offset); + if (HasError) continue; - bool Preemptible = isPreemptible(Body, Type); - Expr = adjustExpr(File, Body, IsWrite, Expr, Type, Buf + Offset); - if (HasError) + 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 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 000000000000..780d1d0e64c1 --- /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 000000000000..a7c7ce6f6271 --- /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