3434; RUN: -r=main.bc,main,px \
3535; RUN: -r=main.bc,small_func, \
3636; RUN: -r=main.bc,large_func, \
37+ ; RUN: -r=main.bc,read_write_global_vars, \
38+ ; RUN: -r=main.bc,external_func, \
3739; RUN: -r=lib.bc,callee,pl \
3840; RUN: -r=lib.bc,large_indirect_callee,px \
3941; RUN: -r=lib.bc,large_indirect_bar,px \
4042; RUN: -r=lib.bc,small_func,px \
4143; RUN: -r=lib.bc,large_func,px \
44+ ; RUN: -r=lib.bc,read_write_global_vars,px \
4245; RUN: -r=lib.bc,large_indirect_callee_alias,px \
4346; RUN: -r=lib.bc,large_indirect_bar_alias,px \
4447; RUN: -r=lib.bc,calleeAddrs,px -r=lib.bc,calleeAddrs2,px -o summary main.bc lib.bc 2>&1 | FileCheck %s --check-prefix=DUMP
7174; MAIN-DIS: [[LARGEINDIRECT:\^[0-9]+]] = gv: (guid: 14343440786664691134, summaries: (function: (module: [[LIBMOD]], flags: ({{.*}} importType: declaration), insts: 8, {{.*}})))
7275; MAIN-DIS: gv: (guid: 16730173943625350469, summaries: (alias: (module: [[LIBMOD]], flags: ({{.*}} importType: declaration), aliasee: [[LARGEINDIRECT]])))
7376
77+ ; RUN: opt -passes=function-import -import-all-index -summary-file=main.bc.thinlto.bc main.bc -o main-after-import.bc
78+ ; RUN: llvm-dis -o - main-after-import.bc | FileCheck %s --check-prefix=MAIN-IMPORT
79+
80+ ; Tests that dso_local attribute is applied on a global var from its summary.
81+ MAIN-IMPORT: @read_write_global_vars = external dso_local global [1 x ptr ]
82+
7483; Run in-process ThinLTO and tests that
7584; 1. `callee` remains internalized even if the symbols of its callers
7685; (large_func, large_indirect_callee, large_indirect_bar) are exported as
7786; declarations and visible to main module.
7887; 2. the debugging logs from `function-import` pass are expected.
88+ ; Set relocation model to static so the dso_local attribute from a summary is
89+ ; applied on the global variable declaration.
7990
8091; RUN: llvm-lto2 run \
92+ ; RUN: -relocation-model=static \
8193; RUN: -debug-only=function-import \
8294; RUN: -save-temps \
8395; RUN: -thinlto-threads=1 \
8799; RUN: -r=main.bc,main,px \
88100; RUN: -r=main.bc,small_func, \
89101; RUN: -r=main.bc,large_func, \
102+ ; RUN: -r=main.bc,read_write_global_vars, \
103+ ; RUN: -r=main.bc,external_func, \
90104; RUN: -r=lib.bc,callee,pl \
91105; RUN: -r=lib.bc,large_indirect_callee,px \
92106; RUN: -r=lib.bc,large_indirect_bar,px \
93107; RUN: -r=lib.bc,small_func,px \
94108; RUN: -r=lib.bc,large_func,px \
109+ ; RUN: -r=lib.bc,read_write_global_vars,px \
95110; RUN: -r=lib.bc,large_indirect_callee_alias,px \
96111; RUN: -r=lib.bc,large_indirect_bar_alias,px \
97112; RUN: -r=lib.bc,calleeAddrs,px -r=lib.bc,calleeAddrs2,px -o in-process main.bc lib.bc 2>&1 | FileCheck %s --check-prefix=IMPORTDUMP
103118; IMPORTDUMP-DAG: Is importing function definition 13568239288960714650 small_indirect_callee from lib.cc
104119; IMPORTDUMP-DAG: Is importing function definition 6976996067367342685 small_func from lib.cc
105120; IMPORTDUMP-DAG: Is importing function declaration 2418497564662708935 large_func from lib.cc
106- ; IMPORTDUMP-DAG: Not importing global 7680325410415171624 calleeAddrs from lib.cc
121+ ; IMPORTDUMP-DAG: Is importing global declaration 7680325410415171624 calleeAddrs from lib.cc
107122; IMPORTDUMP-DAG: Is importing alias declaration 16730173943625350469 large_indirect_callee_alias from lib.cc
108123; IMPORTDUMP-DAG: Is importing alias declaration 13590951773474913315 large_indirect_bar_alias from lib.cc
109124; IMPORTDUMP-DAG: Not importing function 13770917885399536773 large_indirect_bar
115130; IMPORT-DAG: define available_externally void @small_func
116131; IMPORT-DAG: define available_externally hidden void @small_indirect_callee
117132; IMPORT-DAG: declare void @large_func
133+ ; Tests that dso_local attribute is applied on a global var from its summary.
134+ ; IMPORT-DAG: @read_write_global_vars = external dso_local global [1 x ptr]
118135; IMPORT-NOT: large_indirect_callee
119136; IMPORT-NOT: large_indirect_callee_alias
120137; IMPORT-NOT: large_indirect_bar
126143target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
127144target triple = "x86_64-unknown-linux-gnu"
128145
146+ @read_write_global_vars = external global [1 x ptr ]
147+
129148define i32 @main () {
130149 call void @small_func ()
131150 call void @large_func ()
151+ %num = call ptr @external_func (ptr @read_write_global_vars )
152+ store ptr %num , ptr getelementptr inbounds ([1 x ptr ], ptr @read_write_global_vars , i64 0 , i64 0 )
153+ %res1 = call i32 @external_func (ptr @read_write_global_vars )
132154 ret i32 0
133155}
134156
@@ -137,6 +159,8 @@ declare void @small_func()
137159; large_func without attributes
138160declare void @large_func ()
139161
162+ declare ptr @external_func (ptr )
163+
140164;--- lib.ll
141165source_filename = "lib.cc"
142166target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
@@ -149,6 +173,10 @@ target triple = "x86_64-unknown-linux-gnu"
149173; large_indirect_bar_alias is visible to main.ll but its aliasee isn't.
150174@calleeAddrs2 = global [1 x ptr ] [ptr @large_indirect_bar_alias ]
151175
176+ ; @read_write_global_vars is not read-only nor write-only (in main.ll). It's not
177+ ; a constant global var and has references, so it's not importable as a definition.
178+ @read_write_global_vars = dso_local global [1 x ptr ] [ptr @large_indirect_callee ]
179+
152180define void @callee () #1 {
153181 ret void
154182}
0 commit comments