llvm.org GIT mirror llvm / 073f01b
[LTO] Handle __imp_ (dllimport) symbols consistently with lld Summary: Similar to what lld already does for dllimport symbols which are prefaced with __imp_ (see lld patch r240620), strip off the __imp_ prefix in LTO. Otherwise we can get 2 separate GlobalResolution for a single symbol, the dllimport declaration, and the definition, which leads to incorrect LTO handling. Fixes PR38105. Reviewers: pcc Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D49138 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337762 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 1 year, 1 month ago
3 changed file(s) with 55 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
427427 assert(ResI != ResE);
428428 SymbolResolution Res = *ResI++;
429429
430 auto &GlobalRes = GlobalResolutions[Sym.getName()];
430 StringRef Name = Sym.getName();
431 Triple TT(RegularLTO.CombinedModule->getTargetTriple());
432 // Strip the __imp_ prefix from COFF dllimport symbols (similar to the
433 // way they are handled by lld), otherwise we can end up with two
434 // global resolutions (one with and one for a copy of the symbol without).
435 if (TT.isOSBinFormatCOFF() && Name.startswith("__imp_"))
436 Name = Name.substr(strlen("__imp_"));
437 auto &GlobalRes = GlobalResolutions[Name];
431438 GlobalRes.UnnamedAddr &= Sym.isUnnamedAddr();
432439 if (Res.Prevailing) {
433440 assert(!GlobalRes.Prevailing &&
0 ; ModuleID = 'b.obj'
1 source_filename = "b.cpp"
2 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-pc-windows-msvc19.11.0"
4
5 ; Function Attrs: norecurse nounwind readnone sspstrong uwtable
6 define dso_local i32 @"?foo@@YAHXZ"() local_unnamed_addr {
7 entry:
8 ret i32 42
9 }
10
11 !llvm.module.flags = !{!1}
12
13 !1 = !{i32 1, !"ThinLTO", i32 0}
14
15 ^0 = module: (path: "b.obj", hash: (0, 0, 0, 0, 0))
16 ^1 = gv: (name: "?foo@@YAHXZ", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1), insts: 1, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0)))) ; guid = 2709792123250749187
0 ; Test requiring LTO to remove the __imp_ prefix for locally imported COFF
1 ; symbols (mirroring how lld handles these symbols).
2 ; RUN: llvm-as %s -o %t.obj
3 ; RUN: llvm-as %S/Inputs/dllimport.ll -o %t2.obj
4 ; RUN: llvm-lto2 run -r=%t.obj,main,px -r %t.obj,__imp_?foo@@YAHXZ -r %t2.obj,?foo@@YAHXZ,p -o %t3 %t.obj %t2.obj -save-temps
5 ; RUN: llvm-dis %t3.0.0.preopt.bc -o - | FileCheck %s
6
7 ; CHECK: define dso_local i32 @"?foo@@YAHXZ"()
8
9 ; ModuleID = 'a.obj'
10 source_filename = "a.cpp"
11 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
12 target triple = "x86_64-pc-windows-msvc19.11.0"
13
14 ; Function Attrs: norecurse nounwind sspstrong uwtable
15 define dso_local i32 @main() local_unnamed_addr {
16 entry:
17 %call = tail call i32 @"?foo@@YAHXZ"()
18 ret i32 %call
19 }
20
21 declare dllimport i32 @"?foo@@YAHXZ"() local_unnamed_addr
22
23 !llvm.module.flags = !{!1}
24
25 !1 = !{i32 1, !"ThinLTO", i32 0}
26
27 ^0 = module: (path: "a.obj", hash: (0, 0, 0, 0, 0))
28 ^1 = gv: (name: "?foo@@YAHXZ") ; guid = 2709792123250749187
29 ^2 = gv: (name: "main", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 1, live: 0, dsoLocal: 1), insts: 2, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0), calls: ((callee: ^1))))) ; guid = 15822663052811949562