File: lc-linker-option-lto.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,696 kB
  • sloc: cpp: 7,438,781; ansic: 1,393,871; asm: 1,012,926; python: 241,771; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 8,596; ml: 5,082; perl: 4,730; makefile: 3,591; awk: 3,523; javascript: 2,251; xml: 892; fortran: 672
file content (83 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
; REQUIRES: x86
; RUN: rm -rf %t; split-file %s %t

; RUN: llc -filetype=obj %t/q.ll -o %t/q.o
; RUN: llvm-ar cru %t/libq.a %t/q.o

; RUN: llc -filetype=obj %t/f.ll -o %t/f.nolto.o
; RUN: opt --thinlto-bc %t/f.ll -o %t/f.thinlto.o
; RUN: opt %t/f.ll -o %t/f.lto.o

; RUN: llc -filetype=obj %t/b.ll -o %t/b.nolto.o
; RUN: opt --thinlto-bc %t/b.ll -o %t/b.thinlto.o
; RUN: opt %t/b.ll -o %t/b.lto.o

; (1) NoLTO-NoLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.nolto.o %t/b.nolto.o -o %t/nolto-nolto.out
; RUN: llvm-objdump --syms %t/nolto-nolto.out | FileCheck %s

; (2) NoLTO-ThinLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.nolto.o %t/b.thinlto.o -o %t/nolto-thinlto.out
; RUN: llvm-objdump --syms %t/nolto-thinlto.out | FileCheck %s

; (3) ThinLTO-NoLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.thinlto.o %t/b.nolto.o -o %t/thinlto-nolto.out
; RUN: llvm-objdump --syms %t/thinlto-nolto.out | FileCheck %s

; (4) NoLTO-LTO
; RUN: %lld -dylib -lSystem -L%t %t/f.nolto.o %t/b.lto.o -o %t/nolto-lto.out
; RUN: llvm-objdump --syms %t/nolto-lto.out | FileCheck %s

; (5) LTO-NoLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.lto.o %t/b.nolto.o -o %t/lto-nolto.out
; RUN: llvm-objdump --syms %t/lto-nolto.out | FileCheck %s

; (6) LTO-ThinLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.lto.o %t/b.thinlto.o -o %t/lto-thinlto.out
; RUN: llvm-objdump --syms %t/lto-thinlto.out | FileCheck %s

; (7) ThinLTO-NoLTO
; RUN: %lld -dylib -lSystem -L%t %t/f.thinlto.o %t/b.lto.o -o %t/thinlto-lto.out
; RUN: llvm-objdump --syms %t/thinlto-lto.out | FileCheck %s

; We expect to resolve _weak1 from f.ll and _weak2 from b.ll as per the input order.
; As _weak2 from q.ll pulled in via LC_LINKER_OPTION is processed
; in the second pass, it won't prevail due to _weak2 from b.ll.

; CHECK:          w    O __TEXT,f _weak1
; CHECK:          w    O __TEXT,b _weak2

;--- q.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

define i32 @weak2() section "__TEXT,q" {
  ret i32 2
}

;--- f.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

!0 = !{!"-lq"}
!llvm.linker.options = !{!0}

define weak i32 @weak1() section "__TEXT,f" {
  %call = call i32 @weak2()
  %add = add nsw i32 %call, 1
  ret i32 %add
}

declare i32 @weak2(...)

;--- b.ll
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.15.0"

define weak i32 @weak1() section "__TEXT,b" {
  ret i32 3
}

define weak i32 @weak2() section "__TEXT,b" {
  ret i32 4
}