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 @X = global i32 5
     27 @U = global i32 6
     28 @U_linkonce = linkonce_odr hidden global i32 6
     29 define i32 @foo() { ret i32 7 }
     30 define i32 @unused() { ret i32 8 }
     31 define linkonce_odr hidden i32 @unused_linkonce() { ret i32 8 }
     32 @linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc2 to void (...)*)
     33 
     34 @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*)
     35 @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*)
     36 
     37 define void @globalfunc1() #0 {
     38 entry:
     39   ret void
     40 }
     41 
     42 define void @globalfunc2() #0 {
     43 entry:
     44   ret void
     45 }
     46 
     47 $linkoncefunc2 = comdat any
     48 define linkonce_odr void @linkoncefunc2() #0 comdat {
     49 entry:
     50   ret void
     51 }
     52 
     53 !llvm.named = !{!0, !1, !2, !3, !4, !5, !6}
     54 !0 = !{i32 ()* @unused}
     55 !1 = !{i32* @U}
     56 !2 = !{i32 ()* @unused_linkonce}
     57 !3 = !{i32* @U_linkonce}
     58 !4 = !{void (...)* @weakalias}
     59 !5 = !{void (...)* @analias}
     60 !6 = !{void (...)* @linkoncealias}
     61