xref: /llvm-project/lld/test/MachO/lto-explicit-exports.ll (revision 5cf0b4d94ee0d202211cd79c9fb204cb97bc6d67)
1; REQUIRES: x86
2; RUN: rm -rf %t; split-file %s %t
3
4;; Check that `-exported_symbol` causes all non-exported symbols to be marked
5;; as hidden before LTO. We don't want to downgrade them to private extern only
6;; after LTO runs as that likely causes LTO to miss optimization opportunities.
7
8; RUN: llvm-as %t/foo.ll -o %t/foo.o
9; RUN: llvm-as %t/refs-foo.ll -o %t/refs-foo.o
10
11; RUN: %lld -lSystem -dylib %t/foo.o %t/refs-foo.o -o %t/test-fulllto \
12; RUN:  -save-temps -exported_symbol _refs_foo -exported_symbol _same_module_caller
13
14; RUN: llvm-dis %t/test-fulllto.0.2.internalize.bc -o - | FileCheck %s --check-prefix=FULLLTO
15; RUN: llvm-objdump --macho --syms %t/test-fulllto | FileCheck %s --check-prefix=FULLLTO-SYMS
16
17; FULLLTO: define internal void @foo()
18; FULLLTO: define internal void @same_module_callee()
19; FULLLTO: define dso_local void @same_module_caller()
20; FULLLTO: define dso_local void @refs_foo()
21
22;; LTO is able to elide the hidden symbols, and they will be entirely absent
23;; from the final symbol table.
24
25; FULLLTO-SYMS:       SYMBOL TABLE:
26; FULLLTO-SYMS:       g     F __TEXT,__text _refs_foo
27; FULLLTO-SYMS:       g     F __TEXT,__text _same_module_caller
28; FULLLTO-SYMS:       *UND* dyld_stub_binder
29; FULLLTO-SYMS-EMPTY:
30
31;; ThinLTO is unable to internalize symbols that are referenced from another
32;; module. Verify that we still mark the final symbol as private extern.
33
34; RUN: opt -module-summary %t/foo.ll -o %t/foo.thinlto.o
35; RUN: opt -module-summary %t/refs-foo.ll -o %t/refs-foo.thinlto.o
36
37; RUN: %lld -lSystem -dylib %t/foo.thinlto.o %t/refs-foo.thinlto.o -o %t/test-thinlto \
38; RUN:  -save-temps -exported_symbol _refs_foo -exported_symbol _same_module_caller
39
40; RUN: llvm-dis %t/foo.thinlto.o.2.internalize.bc -o - | FileCheck %s --check-prefix=THINLTO-FOO
41; RUN: llvm-dis %t/refs-foo.thinlto.o.2.internalize.bc -o - | FileCheck %s --check-prefix=THINLTO-REFS-FOO
42; RUN: llvm-objdump --macho --syms %t/test-thinlto | FileCheck %s --check-prefix=THINLTO-SYMS
43
44; THINLTO-FOO: define dso_local void @foo()
45; THINLTO-FOO: define internal void @same_module_callee()
46; THINLTO-REFS-FOO: declare dso_local void @foo()
47; THINLTO-REFS-FOO: define dso_local void @refs_foo()
48
49; THINLTO-SYMS: l     F __TEXT,__text .hidden _foo
50; THINLTO-SYMS: g     F __TEXT,__text _refs_foo
51; THINLTO-SYMS: g     F __TEXT,__text _same_module_caller
52
53;--- foo.ll
54
55target triple = "x86_64-apple-macosx10.15.0"
56target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
57
58define void @foo() {
59  ret void
60}
61
62define void @same_module_callee() {
63  ret void
64}
65
66define void @same_module_caller() {
67  call void @same_module_callee()
68  ret void
69}
70
71;--- refs-foo.ll
72
73target triple = "x86_64-apple-macosx10.15.0"
74target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
75
76declare void @foo()
77
78define void @refs_foo() {
79  call void @foo()
80  ret void
81}
82