xref: /llvm-project/llvm/test/CodeGen/ARM/thumb-function-section-reloc.ll (revision df00dac828d7d0f88106d34b12a4eafaa8dd93ea)
1;; -ffunction-sections previously resulted in call relocations against the
2;; .text.foo section symbol instead of the actual function symbol.
3;; However, that results in a relocation against a symbol without the LSB set,
4;; so the linker thinks it is not linking against a Thumb symbol.
5;; Check that we use a relocation against the symbol for calls to functions
6;; marked as dso_local (foo$local)
7;; NB: Right now only R_ARM_PREL31 and R_ARM_ABS32 are converted to section
8;; plus offset, so this test can't use a call.
9; RUN: llc -mtriple=armv7a-none-linux-gnueabi --function-sections -o - --relocation-model=pic %s | FileCheck %s
10; RUN: llc -mtriple=armv7a-none-linux-gnueabi --function-sections --filetype=obj -o %t --relocation-model=pic %s
11; RUN: llvm-readobj -r --symbols %t | FileCheck %s --check-prefix=RELOCS
12;; Do not autogen (we check directives that are normally filtered out):
13; UTC-ARGS: --disable
14
15; RELOCS-LABEL: Relocations [
16; RELOCS-NEXT:   Section (5) .rel.ARM.exidx.text._ZdlPv {
17; RELOCS-NEXT:     0x0 R_ARM_PREL31 .text._ZdlPv
18; RELOCS-NEXT:   }
19; RELOCS-NEXT:   Section (7) .rel.text.test {
20; RELOCS-NEXT:     0x4 R_ARM_CALL .L_ZdlPv$local
21; RELOCS-NEXT:     0xC R_ARM_ABS32 .L_ZdlPv$local
22; RELOCS-NEXT:     0x10 R_ARM_ABS32 .L_ZdlPv$local
23; RELOCS-NEXT:     0x1C R_ARM_REL32 .L_ZdlPv$local
24; RELOCS-NEXT:   }
25; RELOCS-NEXT:   Section (9) .rel.ARM.exidx.text.test {
26; RELOCS-NEXT:     0x0 R_ARM_PREL31 .text.test
27; RELOCS-NEXT:   }
28; RELOCS-NEXT:   Section (11) .rel.data {
29; RELOCS-NEXT:     0x0 R_ARM_ABS32 _ZdlPv
30; RELOCS-NEXT:   }
31; RELOCS-NEXT: ]
32
33; RELOCS-LABEL: Symbols [
34; RELOCS:      Symbol {
35; RELOCS:        Name: .L_ZdlPv$local
36; RELOCS-NEXT:   Value: 0x1
37; RELOCS-NEXT:   Size: 2
38; RELOCS-NEXT:   Binding: Local (0x0)
39; RELOCS-NEXT:   Type: Function (0x2)
40; RELOCS-NEXT:   Other: 0
41; RELOCS-NEXT:   Section: .text._ZdlPv (
42; RELOCS-NEXT: }
43
44define dso_local void @_ZdlPv(ptr %ptr) local_unnamed_addr nounwind "target-features"="+armv7-a,+thumb-mode" {
45; CHECK-LABEL: 	.section	.text._ZdlPv,"ax",%progbits
46; CHECK-NEXT: 	.globl	_ZdlPv                          @ -- Begin function _ZdlPv
47; CHECK-NEXT: 	.p2align	1
48; CHECK-NEXT: 	.type	_ZdlPv,%function
49; CHECK-NEXT: 	.code	16                              @ @_ZdlPv
50; CHECK-NEXT: 	.thumb_func
51; CHECK-NEXT: _ZdlPv:
52; CHECK-NEXT: .L_ZdlPv$local:
53; CHECK-NEXT: .type .L_ZdlPv$local,%function
54; CHECK-NEXT: 	.fnstart
55; CHECK-NEXT: @ %bb.0:
56; CHECK-NEXT: 	bx	lr
57; CHECK-NEXT: .Lfunc_end0:
58; CHECK-NEXT: 	.size	_ZdlPv, .Lfunc_end0-_ZdlPv
59; CHECK-NEXT: 	.size .L_ZdlPv$local, .Lfunc_end0-_ZdlPv
60; CHECK-NEXT: 	.cantunwind
61; CHECK-NEXT: 	.fnend
62  ret void
63}
64
65define ptr @test(ptr %ptr) nounwind {
66; CHECK-LABEL: test:
67; CHECK:       @ %bb.0: @ %entry
68; CHECK-NEXT:    .save {r11, lr}
69; CHECK-NEXT:    push {r11, lr}
70; CHECK-NEXT:    bl .L_ZdlPv$local
71; CHECK-NEXT:    ldr r0, .LCPI1_0
72; CHECK-NEXT:    @APP
73; CHECK-NEXT:    .long .L_ZdlPv$local
74; CHECK-NEXT:    @NO_APP
75; CHECK-NEXT:    @APP
76; CHECK-NEXT:    .Ltmp0:
77; CHECK-NEXT:    .reloc .Ltmp0, R_ARM_ABS32, .L_ZdlPv$local
78; CHECK-NEXT:    .long 0
79; CHECK-NEXT:    @NO_APP
80; CHECK-NEXT:  .LPC1_0:
81; CHECK-NEXT:    add r0, pc, r0
82; CHECK-NEXT:    pop {r11, pc}
83; CHECK-NEXT:    .p2align 2
84; CHECK-NEXT:  @ %bb.1:
85; CHECK-NEXT:  .LCPI1_0:
86; CHECK-NEXT:    .long .L_ZdlPv$local-(.LPC1_0+8)
87entry:
88  call void @_ZdlPv(ptr %ptr)
89  ; This inline assembly is needed to highlight the missing Thumb LSB since
90  ; only R_ARM_ABS32 is converted to section+offset
91  tail call void asm sideeffect ".4byte .L_ZdlPv$$local", ""()
92  tail call void asm sideeffect ".reloc ., R_ARM_ABS32, .L_ZdlPv$$local\0A.4byte 0", ""()
93  ret ptr @_ZdlPv
94}
95
96@fnptr = hidden local_unnamed_addr global ptr @_ZdlPv
97