[lld] r285896 - [ELF] Do not create interworking thunks for undefined weak references.
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 3 04:49:24 PDT 2016
Author: psmith
Date: Thu Nov 3 06:49:23 2016
New Revision: 285896
URL: http://llvm.org/viewvc/llvm-project?rev=285896&view=rev
Log:
[ELF] Do not create interworking thunks for undefined weak references.
An undefined weak reference is given an address of 0 this will
incorrectly trigger the creation of a Thumb to ARM interworking Thunk
if there is a Thumb branch instruction to the symbol. This results in
an error as Thunks only make sense to defined or shared symbols.
We prevent this by detecting an undefined symbol and not creating a thunk
for it.
Differential Revision: https://reviews.llvm.org/D26239
Added:
lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s (with props)
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=285896&r1=285895&r2=285896&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Nov 3 06:49:23 2016
@@ -1652,6 +1652,9 @@ void ARMTargetInfo::writePlt(uint8_t *Bu
RelExpr ARMTargetInfo::getThunkExpr(RelExpr Expr, uint32_t RelocType,
const InputFile &File,
const SymbolBody &S) const {
+ // If S is an undefined weak symbol we don't need a Thunk
+ if (S.isUndefined())
+ return Expr;
// A state change from ARM to Thumb and vice versa must go through an
// interworking thunk if the relocation type is not R_ARM_CALL or
// R_ARM_THM_CALL.
Added: lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s?rev=285896&view=auto
==============================================================================
--- lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s (added)
+++ lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s Thu Nov 3 06:49:23 2016
@@ -0,0 +1,23 @@
+// RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t
+// RUN: ld.lld %t -o %t2 2>&1
+// RUN: llvm-objdump -triple=thumbv7a-none-linux-gnueabi -d %t2 | FileCheck %s
+// REQUIRES: arm
+
+// Check that no thunks are created for an undefined weak symbol
+ .syntax unified
+
+.weak target
+
+.section .text.thumb, "ax", %progbits
+ .thumb
+ .global
+_start:
+ bl target
+ b target
+ b.w target
+
+// CHECK: Disassembly of section .text:
+// CHECK-NEXT: _start:
+// CHECK-NEXT: 11000: ee f7 fe ef blx #-69636
+// CHECK-NEXT: 11004: ee f7 fc bf b.w #-69640
+// CHECK-NEXT: 11008: ee f7 fa bf b.w #-69644
Propchange: lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lld/trunk/test/ELF/arm-thumb-no-undefined-thunk.s
------------------------------------------------------------------------------
svn:keywords = Rev Date Author URL Id
More information about the llvm-commits
mailing list