From 3a9eef1670a50265379d4602d17644e491d39597 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 1 Sep 2016 13:52:52 +0000 Subject: [PATCH] Sign extend a value before passing it to the Target. This is what InputSectionBase::relocate does and we need to be consistent. The other option would be to be more explicit about which relocations are signed and which are not, and sign extend only when appropriated. That would require extending the target interface. llvm-svn: 280366 --- lld/ELF/Thunks.cpp | 3 ++- lld/test/ELF/arm-thumb-interwork-thunk-range.s | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/arm-thumb-interwork-thunk-range.s diff --git a/lld/ELF/Thunks.cpp b/lld/ELF/Thunks.cpp index 1ebbb17f3032..50b05c777aec 100644 --- a/lld/ELF/Thunks.cpp +++ b/lld/ELF/Thunks.cpp @@ -100,7 +100,8 @@ public: // ARM Target Thunks template static uint64_t getARMThunkDestVA(const SymbolBody &S) { - return S.isInPlt() ? S.getPltVA() : S.getVA(); + uint64_t V = S.isInPlt() ? S.getPltVA() : S.getVA(); + return SignExtend64<32>(V); } template diff --git a/lld/test/ELF/arm-thumb-interwork-thunk-range.s b/lld/test/ELF/arm-thumb-interwork-thunk-range.s new file mode 100644 index 000000000000..9ef64c7cb1c8 --- /dev/null +++ b/lld/test/ELF/arm-thumb-interwork-thunk-range.s @@ -0,0 +1,14 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t.o +// RUN: ld.lld %t.o -o %t -image-base=0x80000000 + +// Test that when the thunk is at a high address we don't get confused with it +// being out of range. + +.thumb +.global _start +_start: +b.w foo + +.arm +.weak foo +foo: