95 lines · plain
1## Check that BOLT handles correctly folding functions with --icf=safe that can be referenced by non-control flow instructions,2## when binary is built with -fno-PIC/-fno-PIE.3 4# REQUIRES: system-linux, asserts5# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t1.o6# RUN: %clang %cflags %t1.o -o %t.exe -Wl,-q -no-pie7# RUN: llvm-bolt --no-threads %t.exe --icf -debug-only=bolt-icf -o %t.bolt 2>&1 | FileCheck --check-prefix=ICFCHECK %s8# RUN: llvm-bolt --no-threads %t.exe --icf=safe -debug-only=bolt-icf -o %t.bolt 2>&1 | FileCheck --check-prefix=SAFEICFCHECK %s9 10# ICFCHECK: ICF iteration 111# ICFCHECK-NEXT: folding barAddFunc into fooAddFunc12# ICFCHECK-NEXT: folding barMulFunc into fooMulFunc13 14# SAFEICFCHECK: skipping function with reference taken fooMulFunc15# SAFEICFCHECK-NEXT: skipping function with reference taken barMulFunc16# SAFEICFCHECK-NEXT: skipping function with reference taken barAddFunc17# SAFEICFCHECK-NEXT: ICF iteration 118 19## clang++ main.cpp -c -o -fno-PIC20## Similar code gets generated for external reference function.21## Other functions removed for brevity.22## const static int (*const funcGlobalBarAdd)(int, int) = barAdd;23## const int (*const funcGlobalBarMul)(int, int) = barMul;24## int main(int argc, char **argv) {25## int temp = helper1(funcGlobalBarAdd, FooVar, BarVar)26## return temp;27## }28## Manually modified to remove "extra" assembly.29 .globl fooMulFunc30 .type fooMulFunc,@function31fooMulFunc:32 imull -8(%rbp), %eax33 retq34 .size fooMulFunc, .-fooMulFunc35 36 .globl barMulFunc37 .type barMulFunc,@function38barMulFunc:39 imull -8(%rbp), %eax40 retq41 .size barMulFunc, .-barMulFunc42 43 .globl fooAddFunc44 .type fooAddFunc,@function45fooAddFunc:46 addl -8(%rbp), %eax47 retq48 .size fooAddFunc, .-fooAddFunc49 50 .globl barAddFunc51 .type barAddFunc,@function52barAddFunc:53 addl -8(%rbp), %eax54 retq55 .size barAddFunc, .-barAddFunc56 57 .globl helperFunc58 .type helperFunc,@function59helperFunc:60 movabsq $barAddFunc, %rax61 cmpq %rax, -16(%rbp)62 retq63 .size helperFunc, .-helperFunc64 65 .globl main66 .type main,@function67main:68 movl FooVar, %esi69 movl BarVar, %edx70 movabsq $barAddFunc, %rdi71 callq helperFunc72 movabsq $fooMulFunc, %rdi73 movabsq $barMulFunc, %rsi74 retq75 .size main, .-main76 77 .type FooVar,@object78 .data79 .globl FooVar80FooVar:81 .long 182 .size FooVar, 483 84 .type BarVar,@object85 .globl BarVar86BarVar:87 .long 288 .size BarVar, 489 90 .type .L.str,@object91 .section .rodata.str1.1,"aMS",@progbits,192.L.str:93 .asciz "val: %d\n"94 .size .L.str, 995