xref: /llvm-project/lld/test/MachO/lto-internalize.ll (revision 8ce3750ff62d68e7428a828530b9b6a8cc93e813)
1; REQUIRES: x86
2
3;; Check that we internalize bitcode symbols (only) where possible, i.e. when
4;; they are not referenced by undefined symbols originating from non-bitcode
5;; files.
6
7; RUN: rm -rf %t; split-file %s %t
8; RUN: llvm-as %t/test.s -o %t/test.o
9; RUN: llvm-as %t/baz.s -o %t/baz.o
10; RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/regular.s -o %t/regular.o
11; RUN: %lld -lSystem %t/test.o %t/baz.o %t/regular.o -o %t/test -save-temps
12; RUN: llvm-dis < %t/test.0.2.internalize.bc | FileCheck %s
13; RUN: llvm-objdump --macho --syms %t/test | FileCheck %s --check-prefix=SYMTAB
14
15; CHECK: @comm = internal global
16; CHECK: @comm_hide = internal global
17
18;; Check that main is not internalized. This covers the case of bitcode symbols
19;; referenced by undefined symbols that don't belong to any InputFile.
20; CHECK: define dso_local void @main()
21
22;; Check that the foo and bar functions are correctly internalized.
23; CHECK: define internal void @bar()
24; CHECK: define internal void @foo()
25
26;; Check that a bitcode symbol that is referenced by a regular object file isn't
27;; internalized.
28; CHECK: define dso_local void @used_in_regular_obj()
29
30;; Check that a bitcode symbol that is defined in another bitcode file gets
31;; internalized.
32; CHECK: define internal void @baz()
33
34;; Check that all internalized symbols are not emitted to the symtab
35; SYMTAB-LABEL: SYMBOL TABLE:
36; SYMTAB-DAG:   g     F __TEXT,__text _main
37; SYMTAB-DAG:   g     F __TEXT,__text _used_in_regular_obj
38; SYMTAB-DAG:   g     F __TEXT,__text __mh_execute_header
39; SYMTAB-DAG:           *UND* dyld_stub_binder
40; SYMTAB-EMPTY:
41
42; RUN: %lld -lSystem -dylib %t/test.o %t/baz.o %t/regular.o -o %t/test.dylib -save-temps
43; RUN: llvm-dis < %t/test.dylib.0.2.internalize.bc | FileCheck %s --check-prefix=DYN
44; RUN: llvm-nm -m %t/test.dylib | FileCheck %s --check-prefix=DYN-SYMS \
45; RUN:   --implicit-check-not _foo
46
47; RUN: %lld -lSystem -export_dynamic %t/test.o %t/baz.o %t/regular.o -o %t/test.extdyn -save-temps
48; RUN: llvm-dis < %t/test.extdyn.0.2.internalize.bc
49; RUN: llvm-nm -m %t/test.extdyn | FileCheck %s --check-prefix=DYN-SYMS \
50; RUN:   --implicit-check-not _foo
51
52;; Note that only foo() gets internalized here; everything else that isn't
53;; hidden must be exported.
54; DYN: @comm = common dso_local global
55; DYN: @comm_hide = internal global
56; DYN: define dso_local void @main()
57; DYN: define dso_local void @bar()
58; DYN: define internal void @foo()
59; DYN: define dso_local void @used_in_regular_obj()
60; DYN: define dso_local void @baz()
61
62; DYN-SYMS-DAG: (__TEXT,__text) external _bar
63; DYN-SYMS-DAG: (__TEXT,__text) external _baz
64; DYN-SYMS-DAG: (__DATA,__common) external _comm
65; DYN-SYMS-DAG: (__TEXT,__text) external _main
66; DYN-SYMS-DAG: (__TEXT,__text) external _used_in_regular_obj
67
68;--- test.s
69target triple = "x86_64-apple-macosx10.15.0"
70target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
71
72;; Common symbols are always external.
73@comm = common global i8 0, align 1
74@comm_hide = common hidden global i8 0, align 1
75
76declare void @baz()
77
78define void @main() {
79  call void @bar()
80  call void @baz()
81  ret void
82}
83
84define void @bar() {
85  ret void
86}
87
88define hidden void @foo() {
89  ret void
90}
91
92define void @used_in_regular_obj() {
93  ret void
94}
95
96;--- baz.s
97target triple = "x86_64-apple-macosx10.15.0"
98target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
99
100define void @baz() {
101  ret void
102}
103
104;--- regular.s
105.data
106.quad _used_in_regular_obj
107