]> granicus.if.org Git - llvm/commitdiff
[ARM] Create relocations for Thumb functions calling ARM fns in ELF.
authorFlorian Hahn <florian.hahn@arm.com>
Thu, 1 Jun 2017 13:50:57 +0000 (13:50 +0000)
committerFlorian Hahn <florian.hahn@arm.com>
Thu, 1 Jun 2017 13:50:57 +0000 (13:50 +0000)
Summary:
Without using a fixup in this case, BL will be used instead of BLX to
call internal ARM functions from Thumb functions.

Reviewers: rafael, t.p.northover, peter.smith, kristof.beyls

Reviewed By: peter.smith

Subscribers: srhines, echristo, aemerson, rengolin, javed.absar, llvm-commits

Differential Revision: https://reviews.llvm.org/D33436

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304413 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
test/MC/ARM/big-endian-thumb-fixup.s
test/MC/ARM/mixed-arm-thumb-bl-fixup.ll [new file with mode: 0644]

index 40bf545e83224ab32e3218b1bfef8abc343b682b..b0d1d3fb9ef0b69967e5bf9ce1e6f9f9bc3095c0 100644 (file)
@@ -729,6 +729,15 @@ void ARMAsmBackend::processFixupValue(const MCAssembler &Asm,
     // linker can handle it. GNU AS produces an error in this case.
     if (Sym->isExternal() || Value >= 0x400004)
       IsResolved = false;
+    // When an ARM function is called from a Thumb function, produce a
+    // relocation so the linker will use the correct branch instruction for ELF
+    // binaries.
+    if (Sym->isELF()) {
+      unsigned Type = dyn_cast<MCSymbolELF>(Sym)->getType();
+      if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC) &&
+          !Asm.isThumbFunc(Sym))
+        IsResolved = false;
+    }
   }
   // We must always generate a relocation for BL/BLX instructions if we have
   // a symbol to reference, as the linker relies on knowing the destination
index 5023fca26be106b1925ef5113fa2a305bd8cae17..4e81469fe489b0d624ccb3bd31d95d9ef8f38d88 100644 (file)
@@ -4,6 +4,7 @@
        .text
        .align  2
        .code 16
+       .thumb_func
 
 @ARM::fixup_arm_thumb_bl
 .section s_thumb_bl,"ax",%progbits
diff --git a/test/MC/ARM/mixed-arm-thumb-bl-fixup.ll b/test/MC/ARM/mixed-arm-thumb-bl-fixup.ll
new file mode 100644 (file)
index 0000000..155ce5a
--- /dev/null
@@ -0,0 +1,77 @@
+; RUN: llc -O0 < %s -mtriple armv7-linux-gnueabi -o - \
+; RUN:   | llvm-mc -triple armv7-linux-gnueabi -filetype=obj -o - \
+; RUN:    | llvm-readobj -r | FileCheck --check-prefix LINUX %s
+
+; RUN: llc -O0 < %s -mtriple armv7-linux-android -o - \
+; RUN:   | llvm-mc -triple armv7-linux-android -filetype=obj -o - \
+; RUN:    | llvm-readobj -r | FileCheck --check-prefix LINUX %s
+
+
+; RUN: llc -O0 < %s -mtriple armv7-apple-ios -o - \
+; RUN:   | llvm-mc -triple armv7-apple-ios -filetype=obj -o - \
+; RUN:    | llvm-readobj -r | FileCheck --check-prefix IOS %s
+
+
+define void @thumb_caller() #0 {
+  call void @internal_arm_fn()
+  call void @global_arm_fn()
+  call void @internal_thumb_fn()
+  call void @global_thumb_fn()
+  ret void
+}
+
+define void @arm_caller() #1 {
+  call void @internal_arm_fn()
+  call void @global_arm_fn()
+  call void @internal_thumb_fn()
+  call void @global_thumb_fn()
+  ret void
+}
+
+define internal void @internal_thumb_fn() #0 {
+  ret void
+}
+
+define void @global_thumb_fn() #0 {
+entry:
+  br label %end
+end:
+  br label %end
+  ret void
+}
+
+define internal void @internal_arm_fn() #1 {
+  ret void
+}
+
+define void @global_arm_fn() #1 {
+entry:
+  br label %end
+end:
+  br label %end
+  ret void
+}
+
+attributes #0 = { "target-features"="+thumb-mode" }
+attributes #1 = { "target-features"="-thumb-mode" }
+
+; LINUX: Section (3) .rel.text {
+; LINUX-NEXT: 0x2 R_ARM_THM_CALL internal_arm_fn 0x0
+; LINUX-NEXT: 0x6 R_ARM_THM_CALL global_arm_fn 0x0
+; LINUX-NEXT: 0xE R_ARM_THM_CALL global_thumb_fn 0x0
+; LINUX-NEXT: 0x1C R_ARM_CALL internal_arm_fn 0x0
+; LINUX-NEXT: 0x20 R_ARM_CALL global_arm_fn 0x0
+; LINUX-NEXT: 0x24 R_ARM_CALL internal_thumb_fn 0x0
+; LINUX-NEXT: 0x28 R_ARM_CALL global_thumb_fn 0x0
+; LINUX-NEXT: }
+
+; IOS:   Section __text {
+; IOS-NEXT: 0x2C 1 2 0 ARM_RELOC_BR24 0 __text
+; IOS-NEXT: 0x28 1 2 0 ARM_RELOC_BR24 0 __text
+; IOS-NEXT: 0x24 1 2 0 ARM_RELOC_BR24 0 __text
+; IOS-NEXT: 0x20 1 2 0 ARM_RELOC_BR24 0 __text
+; IOS-NEXT: 0x10 1 2 0 ARM_THUMB_RELOC_BR22 0 __text
+; IOS-NEXT: 0xC 1 2 0 ARM_THUMB_RELOC_BR22 0 __text
+; IOS-NEXT: 0x8 1 2 0 ARM_THUMB_RELOC_BR22 0 __text
+; IOS-NEXT: 0x4 1 2 0 ARM_THUMB_RELOC_BR22 0 __text
+; IOS-NEXT: }