1# REQUIRES: x86 2 3# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o 4# RUN: llvm-objcopy %t1.o %t1copy.o 5# RUN: llvm-objcopy --localize-symbol=h1 %t1.o %t1changed.o 6# RUN: ld.lld -r %t1.o -o %t1reloc.o 7# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-safe.s -o %t2.o 8# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s 9# RUN: ld.lld %t1copy.o %t2.o -o %t2 --icf=safe --print-icf-sections | FileCheck %s 10# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections -shared | FileCheck --check-prefix=EXPORT %s 11# RUN: ld.lld %t1.o %t2.o -o %t3 --icf=safe --print-icf-sections --export-dynamic | FileCheck --check-prefix=EXPORT %s 12# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections | FileCheck --check-prefix=ALL %s 13# RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s 14# RUN: ld.lld %t1changed.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s 15# RUN: ld.lld %t1reloc.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s 16 17# CHECK-NOT: {{.}} 18# CHECK: selected section {{.*}}:(.rodata.h3) 19# CHECK-NEXT: removing identical section {{.*}}:(.rodata.h4) 20# CHECK-NEXT: selected section {{.*}}:(.text.f3) 21# CHECK-NEXT: removing identical section {{.*}}:(.text.f4) 22# CHECK-NEXT: selected section {{.*}}:(.rodata.g3) 23# CHECK-NEXT: removing identical section {{.*}}:(.rodata.g4) 24# CHECK-NEXT: selected section {{.*}}:(.rodata.l3) 25# CHECK-NEXT: removing identical section {{.*}}:(.rodata.l4) 26# CHECK-NEXT: selected section {{.*}}:(.text) 27# CHECK-NEXT: removing identical section {{.*}}:(.text) 28# CHECK-NOT: {{.}} 29 30# With --icf=all address-significance implies keep-unique only for rodata, not 31# text. 32# ALL-NOT: {{.}} 33# ALL: selected section {{.*}}:(.rodata.h3) 34# ALL-NEXT: removing identical section {{.*}}:(.rodata.h4) 35# ALL-NEXT: selected section {{.*}}:(.text.f3) 36# ALL-NEXT: removing identical section {{.*}}:(.text.f4) 37# ALL-NEXT: selected section {{.*}}:(.text.f1) 38# ALL-NEXT: removing identical section {{.*}}:(.text.f2) 39# ALL-NEXT: removing identical section {{.*}}:(.text.non_addrsig1) 40# ALL-NEXT: removing identical section {{.*}}:(.text.non_addrsig2) 41# ALL-NEXT: selected section {{.*}}:(.rodata.g3) 42# ALL-NEXT: removing identical section {{.*}}:(.rodata.g4) 43# ALL-NEXT: selected section {{.*}}:(.rodata.l3) 44# ALL-NEXT: removing identical section {{.*}}:(.rodata.l4) 45# ALL-NEXT: selected section {{.*}}:(.text) 46# ALL-NEXT: removing identical section {{.*}}:(.text) 47# ALL-NOT: {{.}} 48 49# llvm-mc normally emits an empty .text section into every object file. Since 50# nothing actually refers to it via a relocation, it doesn't have any associated 51# symbols (thus nor can anything refer to it via a relocation, making it safe to 52# merge with the empty section in the other input file). Here we check that the 53# only two sections merged are the two empty sections and the sections with only 54# STB_LOCAL or STV_HIDDEN symbols. The dynsym entries should have prevented 55# anything else from being merged. 56# EXPORT-NOT: {{.}} 57# EXPORT: selected section {{.*}}:(.rodata.h3) 58# EXPORT-NEXT: removing identical section {{.*}}:(.rodata.h4) 59# EXPORT-NEXT: selected section {{.*}}:(.rodata.l3) 60# EXPORT-NEXT: removing identical section {{.*}}:(.rodata.l4) 61# EXPORT-NOT: {{.}} 62 63# If --icf=all is specified when exporting we can also merge the exported text 64# sections, but not the exported rodata. 65# ALL-EXPORT-NOT: {{.}} 66# ALL-EXPORT: selected section {{.*}}:(.rodata.h3) 67# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.rodata.h4) 68# ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f3) 69# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.f4) 70# ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f1) 71# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.f2) 72# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.non_addrsig1) 73# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text.non_addrsig2) 74# ALL-EXPORT-NEXT: selected section {{.*}}:(.rodata.l3) 75# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.rodata.l4) 76# ALL-EXPORT-NEXT: selected section {{.*}}:(.text) 77# ALL-EXPORT-NEXT: removing identical section {{.*}}:(.text) 78# ALL-EXPORT-NOT: {{.}} 79 80# SH_LINK_0: --icf=safe conservatively ignores SHT_LLVM_ADDRSIG [index [[#]]] with sh_link=0 (likely created using objcopy or ld -r) 81 82.globl _start 83_start: 84 85.section .text.f1,"ax",@progbits 86.globl f1 87f1: 88ret 89 90.section .text.f2,"ax",@progbits 91.globl f2 92f2: 93ret 94 95.section .text.f3,"ax",@progbits 96.globl f3 97f3: 98ud2 99 100.section .text.f4,"ax",@progbits 101.globl f4 102f4: 103ud2 104 105.section .rodata.g1,"a",@progbits 106.globl g1 107g1: 108.byte 1 109 110.section .rodata.g2,"a",@progbits 111.globl g2 112g2: 113.byte 1 114 115.section .rodata.g3,"a",@progbits 116.globl g3 117g3: 118.byte 2 119 120.section .rodata.g4,"a",@progbits 121.globl g4 122g4: 123.byte 2 124 125.section .rodata.l1,"a",@progbits 126l1: 127.byte 3 128 129.section .rodata.l2,"a",@progbits 130l2: 131.byte 3 132 133.section .rodata.l3,"a",@progbits 134l3: 135.byte 4 136 137.section .rodata.l4,"a",@progbits 138l4: 139.byte 4 140 141.section .rodata.h1,"a",@progbits 142.globl h1 143.hidden h1 144h1: 145.byte 5 146 147.section .rodata.h2,"a",@progbits 148.globl h2 149.hidden h2 150h2: 151.byte 5 152 153.section .rodata.h3,"a",@progbits 154.globl h3 155.hidden h3 156h3: 157.byte 6 158 159.section .rodata.h4,"a",@progbits 160.globl h4 161.hidden h4 162h4: 163.byte 6 164 165.addrsig 166.addrsig_sym f1 167.addrsig_sym f2 168.addrsig_sym g1 169.addrsig_sym g2 170.addrsig_sym l1 171.addrsig_sym l2 172.addrsig_sym h1 173.addrsig_sym h2 174