llvm.org GIT mirror llvm / dc8dd58
[ThinLTO] Remove dllimport attribute from locally defined symbols Summary: The LTO/ThinLTO driver currently creates invalid bitcode by setting symbols marked dllimport as dso_local. The compiler often has access to the definition (often dllexport) and the declaration (often dllimport) of an object at link-time, leading to a conflicting declaration. This patch resolves the inconsistency by removing the dllimport attribute. Reviewers: tejohnson, pcc, rnk, echristo Reviewed By: rnk Subscribers: dmikulin, wristow, mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, dang, llvm-commits Differential Revision: https://reviews.llvm.org/D55627 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349667 91177308-0d34-0410-b5e6-96231b3b80d8 Matthew Voss 8 months ago
2 changed file(s) with 37 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
692692 }
693693
694694 // Set the 'local' flag based on the linker resolution for this symbol.
695 if (Res.FinalDefinitionInLinkageUnit)
695 if (Res.FinalDefinitionInLinkageUnit) {
696696 GV->setDSOLocal(true);
697 if (GV->hasDLLImportStorageClass())
698 GV->setDLLStorageClass(GlobalValue::DLLStorageClassTypes::
699 DefaultStorageClass);
700 }
697701 }
698702 // Common resolution: collect the maximum size/alignment over all commons.
699703 // We also record if we see an instance of a common as prevailing, so that
0 ; RUN: opt -thinlto-bc -o %t0.bc %s
1 ; RUN: llvm-lto2 run -r %t0.bc,__imp_f,l \
2 ; RUN: -r %t0.bc,g,p \
3 ; RUN: -r %t0.bc,g,l \
4 ; RUN: -r %t0.bc,e,l \
5 ; RUN: -r %t0.bc,main,x \
6 ; RUN: -save-temps -o %t1 %t0.bc
7 ; RUN: llvm-dis %t1.1.3.import.bc -o - | FileCheck %s
8 source_filename = "test.cpp"
9 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
11
12 $g = comdat any
13 @g = global i8 42, comdat, !type !0
14
15 ; CHECK: define
16 ; CHECK-NOT: dllimport
17 ; CHECK-SAME: @f
18 define available_externally dllimport i8* @f() {
19 ret i8* @g
20 }
21
22 define i8* @e() {
23 ret i8* @g
24 }
25
26 define i32 @main() {
27 %1 = call i8* @f()
28 %2 = ptrtoint i8* %1 to i32
29 ret i32 %2
30 }
31 !0 = !{i32 0, !"typeid"}