Home | History | Annotate | Download | only in Linker
      1 ; Without -only-needed we should lazy link linkonce globals, and the
      2 ; metadata reference should not cause them to be linked.
      3 ; RUN: llvm-link -S %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s
      4 ; CHECK-NOT:@U_linkonce
      5 ; CHECK-NOT:@unused_linkonce()
      6 
      7 ; With -only-needed the metadata references should not cause any of the
      8 ; otherwise unreferenced globals to be linked. This also ensures that the
      9 ; metadata references don't provoke the module linker to create declarations,
     10 ; which are illegal for aliases and globals in comdats.
     11 ; Note that doing -only-needed with the comdat shown below leads to a only
     12 ; part of the comdat group being linked, which is not technically correct.
     13 ; RUN: llvm-link -S -only-needed %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s -check-prefix=ONLYNEEDED
     14 ; RUN: llvm-link -S -internalize -only-needed %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll | FileCheck %s -check-prefix=ONLYNEEDED
     15 ; ONLYNEEDED-NOT:@U
     16 ; ONLYNEEDED-NOT:@U_linkonce
     17 ; ONLYNEEDED-NOT:@unused()
     18 ; ONLYNEEDED-NOT:@unused_linkonce()
     19 ; ONLYNEEDED-NOT:@linkoncealias
     20 ; ONLYNEEDED-NOT:@linkoncefunc2()
     21 ; ONLYNEEDED-NOT:@weakalias
     22 ; ONLYNEEDED-NOT:@globalfunc1()
     23 ; ONLYNEEDED-NOT:@analias
     24 ; ONLYNEEDED-NOT:@globalfunc2()
     25 
     26 ; Test -only-needed link with the modules preserved instead of freeing to
     27 ; catch any cross-module references to metadata, which the bitcode writer
     28 ; will assert on.
     29 ; RUN: llvm-link -preserve-modules -o %t3.bc -only-needed %S/Inputs/only-needed-named-metadata.ll %S/only-needed-named-metadata.ll
     30 
     31 @X = global i32 5
     32 @U = global i32 6
     33 @U_linkonce = linkonce_odr hidden global i32 6
     34 define i32 @foo() { ret i32 7 }
     35 define i32 @unused() { ret i32 8 }
     36 define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
     37 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
     38 
     39 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
     40 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
     41 
     42 define void @globalfunc1() #0 {
     43 entry:
     44   ret void
     45 }
     46 
     47 define void @globalfunc2() #0 {
     48 entry:
     49   ret void
     50 }
     51 
     52 $linkoncefunc2 = comdat any
     53 define linkonce_odr void @linkoncefunc2() #0 comdat {
     54 entry:
     55   ret void
     56 }
     57 
     58 !llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
     59 !0 = !{i32 ()* @unused}
     60 !1 = !{i32* @U}
     61 !2 = !{i32 ()* @unused_linkonce}
     62 !3 = !{i32* @U_linkonce}
     63 !4 = !{void (...)* @weakalias}
     64 !5 = !{void (...)* @analias}
     65 !6 = !{void (...)* @linkoncealias}
     66