136 lines · plain
1# REQUIRES: x862 3## Test that the branch-to-branch optimization follows the links4## from f1 -> f2 -> f3 and updates all references to point to f3.5 6# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o7# RUN: ld.lld %t.o -o %t --branch-to-branch --emit-relocs8# RUN: llvm-objdump -d -s %t | FileCheck --check-prefixes=CHECK,B2B %s9# RUN: llvm-objdump -r %t | FileCheck --check-prefixes=RELOC,B2B-RELOC %s10# RUN: ld.lld %t.o -o %t -O2 --emit-relocs11# RUN: llvm-objdump -d -s %t | FileCheck --check-prefixes=CHECK,B2B %s12# RUN: llvm-objdump -r %t | FileCheck --check-prefixes=RELOC,B2B-RELOC %s13 14## Test that branch-to-branch is disabled by default.15 16# RUN: ld.lld %t.o -o %t --emit-relocs17# RUN: llvm-objdump -d -s %t | FileCheck --check-prefixes=CHECK,NOB2B %s18# RUN: llvm-objdump -r %t | FileCheck --check-prefixes=RELOC,NOB2B-RELOC %s19# RUN: ld.lld %t.o -o %t -O2 --no-branch-to-branch --emit-relocs20# RUN: llvm-objdump -d -s %t | FileCheck --check-prefixes=CHECK,NOB2B %s21# RUN: llvm-objdump -r %t | FileCheck --check-prefixes=RELOC,NOB2B-RELOC %s22 23## Test that branch-to-branch is disabled for preemptible symbols.24 25# RUN: ld.lld %t.o -o %t --branch-to-branch -shared --emit-relocs26# RUN: llvm-objdump -d -s %t | FileCheck --check-prefixes=CHECK,NOB2B %s27# RUN: llvm-objdump -r %t | FileCheck --check-prefixes=RELOC,NOB2B-RELOC %s28 29.section .rodata.vtable,"a"30.globl vtable31vtable:32# B2B: Contents of section .rodata:33# RELOC: RELOCATION RECORDS FOR [.rodata]:34# RELOC-NEXT: OFFSET35# B2B-NEXT: [[VF:[0-9a-f]{8}]]36# B2B-RELOC-NEXT: R_X86_64_PLT32 f337# NOB2B-RELOC-NEXT: R_X86_64_PLT32 f138.4byte f1@PLT - vtable39# B2B-SAME: [[VF]]40# B2B-RELOC-NEXT: R_X86_64_PLT32 f3+0x441# NOB2B-RELOC-NEXT: R_X86_64_PLT32 f2+0x442.4byte f2@PLT - vtable43# B2B-SAME: [[VF]]44# RELOC-NEXT: R_X86_64_PLT32 f3+0x845.4byte f3@PLT - vtable46 47# For .rodata.f648# B2B-RELOC-NEXT: R_X86_64_PLT32 f3-0x449 50.section .text._start,"ax"51.globl _start52# CHECK: <_start>:53# RELOC: RELOCATION RECORDS FOR [.text]:54# RELOC-NEXT: OFFSET55_start:56.cfi_startproc57# B2B-NEXT: jmp {{.*}} <f3>58# B2B-RELOC-NEXT: R_X86_64_PLT32 f3-0x459# NOB2B-NEXT: jmp {{.*}} <f1{{.*}}>60# NOB2B-RELOC-NEXT: R_X86_64_PLT32 f1-0x461jmp f162# B2B-NEXT: jmp {{.*}} <f3>63# B2B-RELOC-NEXT: R_X86_64_PLT32 f3-0x464# NOB2B-NEXT: jmp {{.*}} <f2{{.*}}>65# NOB2B-RELOC-NEXT: R_X86_64_PLT32 f2-0x466jmp f267# This will assemble to a relocation pointing to an STT_SECTION for .text.f468# with an addend, which looks similar to the relative vtable cases above but69# requires different handling of the addend so that we don't think this is70# branching to the `jmp f3` at the start of the target section.71# CHECK-NEXT: jmp {{.*}} <f4{{.*}}>72# RELOC-NEXT: R_X86_64_PLT32 .text+0x2e73jmp f474# B2B-NEXT: jmp 0x[[IPLT:[0-9a-f]*]]75# RELOC-NEXT: R_X86_64_PLT32 f5-0x476jmp f577# B2B-NEXT: jmp {{.*}} <f6>78# RELOC-NEXT: R_X86_64_PLT32 f6-0x479jmp f680# B2B-NEXT: jmp {{.*}} <f7>81# RELOC-NEXT: R_X86_64_PLT32 f7-0x482jmp f783.cfi_endproc84 85.section .text.f1,"ax"86.globl f187f1:88# B2B-RELOC-NEXT: R_X86_64_PLT32 f3-0x489# NOB2B-RELOC-NEXT: R_X86_64_PLT32 f2-0x490jmp f291 92.section .text.f2,"ax"93.globl f294# CHECK: <f2>:95f2:96# CHECK-NEXT: jmp {{.*}} <f3{{.*}}>97# RELOC-NEXT: R_X86_64_PLT32 f3-0x498jmp f399 100.section .text.f3,"ax"101.globl f3102f3:103# Test that a self-branch doesn't trigger an infinite loop.104# RELOC-NEXT: R_X86_64_PLT32 f3-0x4105jmp f3106 107.section .text.f4,"ax"108jmp f3109f4:110ret111 112.section .text.f5,"ax"113.type f5, @gnu_indirect_function114.globl f5115f5:116# RELOC-NEXT: R_X86_64_PLT32 f3-0x4117jmp f3118 119.section .rodata.f6,"a"120.globl f6121f6:122# RELOC-NEXT: R_X86_64_PLT32 f3-0x4123jmp f3124 125# RELOC: RELOCATION RECORDS FOR [.wtext.f7]:126# RELOC-NEXT: OFFSET127 128.section .wtext.f7,"awx"129.globl f7130f7:131# RELOC-NEXT: R_X86_64_PLT32 f3-0x4132jmp f3133 134# B2B: <.iplt>:135# B2B-NEXT: [[IPLT]]:136