1// REQUIRES: arm 2// RUN: llvm-mc -filetype=obj --arm-add-build-attributes -triple=armv7a-none-linux-gnueabi %s -o %t 3// RUN: ld.lld %t --no-merge-exidx-entries -o %t2 --gc-sections 4// RUN: llvm-objdump -d --triple=armv7a-none-linux-gnueabi --no-show-raw-insn %t2 | FileCheck %s 5// RUN: llvm-objdump -s --triple=armv7a-none-linux-gnueabi %t2 | FileCheck --check-prefix=CHECK-EXIDX %s 6 7/// Test the behavior of .ARM.exidx sections under garbage collection 8/// A .ARM.exidx section is live if it has a relocation to a live executable 9/// section. 10/// A .ARM.exidx section may have a relocation to a .ARM.extab section, if the 11/// .ARM.exidx is live then the .ARM.extab section is live 12 13 .syntax unified 14 .section .text.func1, "ax",%progbits 15 .global func1 16func1: 17 .fnstart 18 bx lr 19 .save {r7, lr} 20 .setfp r7, sp, #0 21 .fnend 22 23 .section .text.unusedfunc1, "ax",%progbits 24 .global unusedfunc1 25unusedfunc1: 26 .fnstart 27 bx lr 28 .cantunwind 29 .fnend 30 31 /// Unwinding instructions for .text2 too large for an inline entry ARM.exidx 32 /// entry. A separate .ARM.extab section is created to hold the unwind entries 33 /// The .ARM.exidx table entry has a reference to the .ARM.extab section. 34 .section .text.func2, "ax",%progbits 35 .global func2 36func2: 37 .fnstart 38 bx lr 39 .personality __gxx_personality_v0 40 .handlerdata 41 .section .text.func2 42 .fnend 43 44 /// An unused function with a reference to a .ARM.extab section. Both should 45 /// be removed by gc. 46 .section .text.unusedfunc2, "ax",%progbits 47 .global unusedfunc2 48unusedfunc2: 49 .fnstart 50 bx lr 51 .personality __gxx_personality_v1 52 .handlerdata 53 .section .text.unusedfunc2 54 .fnend 55 56 /// Dummy implementation of personality routines to satisfy reference from 57 /// exception tables 58 .section .text.__gcc_personality_v0, "ax", %progbits 59 .global __gxx_personality_v0 60__gxx_personality_v0: 61 .fnstart 62 bx lr 63 .cantunwind 64 .fnend 65 66 .section .text.__gcc_personality_v1, "ax", %progbits 67 .global __gxx_personality_v1 68__gxx_personality_v1: 69 .fnstart 70 bx lr 71 .cantunwind 72 .fnend 73 74 .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits 75 .global __aeabi_unwind_cpp_pr0 76__aeabi_unwind_cpp_pr0: 77 .fnstart 78 bx lr 79 .cantunwind 80 .fnend 81 82// Entry point for GC 83 .text 84 .global _start 85_start: 86 bl func1 87 bl func2 88 bx lr 89 90/// GC should have only removed unusedfunc1 and unusedfunc2 the personality 91/// routines are kept alive by references from live .ARM.exidx and .ARM.extab 92/// sections 93// CHECK: Disassembly of section .text: 94// CHECK-EMPTY: 95// CHECK-NEXT: <_start>: 96// CHECK-NEXT: 2010c: bl #4 <func1> 97// CHECK-NEXT: 20110: bl #4 <func2> 98// CHECK-NEXT: 20114: bx lr 99// CHECK: <func1>: 100// CHECK-NEXT: 20118: bx lr 101// CHECK: <func2>: 102// CHECK-NEXT: 2011c: bx lr 103// CHECK: <__gxx_personality_v0>: 104// CHECK-NEXT: 20120: bx lr 105// CHECK: <__aeabi_unwind_cpp_pr0>: 106// CHECK-NEXT: 20124: bx lr 107 108/// GC should have removed table entries for unusedfunc1, unusedfunc2 109/// and __gxx_personality_v1 110// CHECK-NOT: unusedfunc1 111// CHECK-NOT: unusedfunc2 112// CHECK-NOT: __gxx_personality_v1 113 114/// CHECK-EXIDX: Contents of section .ARM.exidx: 115/// 100d4 + 1038 = 1110c = _start 116/// 100dc + 103c = 11118 = func1 117// CHECK-EXIDX-NEXT: 100d4 38000100 01000000 3c000100 08849780 118/// 100e4 + 1038 = 1111c = func2 (100e8 + 1c = 10104 = .ARM.extab) 119/// 100ec + 1034 = 11120 = __gxx_personality_v0 120// CHECK-EXIDX-NEXT: 100e4 38000100 1c000000 34000100 01000000 121/// 100f4 + 1030 = 11018 = __aeabi_unwind_cpp_pr0 122/// 100fc + 102c = 1101c = __aeabi_unwind_cpp_pr0 + sizeof(__aeabi_unwind_cpp_pr0) 123// CHECK-EXIDX-NEXT: 100f4 30000100 01000000 2c000100 01000000 124// CHECK-EXIDX-NEXT: Contents of section .ARM.extab: 125/// 10104 + 101c = 11120 = __gxx_personality_v0 126// CHECK-EXIDX-NEXT: 10104 1c000100 b0b0b000 127