Skip to content

Commit 6a323e7

Browse files
authored
[LLD] [COFF] Add tests to observe details about LTO and __imp_ prefixes. NFC. (#72764)
The commit 3ab6209 had the undesired effect of retaining every `__imp_` symbol, even if it isn't referenced in any way. Add a testcase to observe this behaviour, to serve as a reference point if this behaviour were to be improved later. Port the testcase from b963c0b from the llvm/LTO testsuite into LLD as a preparation for changing that fix; the moved testcase has a comment for one case which doesn't work currently. The testcase is ported mostly as is, but with symbol mangling simplified, rewriting function names from MSVC C++ mangling to plain C, and unnecessary debug info is removed. Add a case of a dllimported data symbol, in addition to the existing call of a dllimported function. Also extend the testcase to test combinations of both regular object files and LTO objects. Leave out one combination which currently fails, with a comment.
1 parent 6d23aaa commit 6a323e7

File tree

4 files changed

+66
-48
lines changed

4 files changed

+66
-48
lines changed

lld/test/COFF/lto-dllimport.ll

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; REQUIRES: x86
2+
; RUN: split-file %s %t.dir
3+
4+
; RUN: llvm-as %t.dir/main.ll -o %t.main.bc
5+
; RUN: llvm-as %t.dir/other.ll -o %t.other.bc
6+
; RUN: llc %t.dir/main.ll -o %t.main.obj --filetype=obj
7+
; RUN: llc %t.dir/other.ll -o %t.other.obj --filetype=obj
8+
9+
; RUN: lld-link %t.main.obj %t.other.obj -entry:main -out:%t.exe
10+
; RUN: lld-link %t.main.bc %t.other.bc -entry:main -out:%t.exe
11+
; RUN: lld-link %t.main.bc %t.other.obj -entry:main -out:%t.exe
12+
13+
;; This test currently fails if combining the regular object file main.obj
14+
;; with the bitcode object file other.bc.
15+
; RUN-skipped: lld-link %t.main.obj %t.other.bc -entry:main -out:%t.exe
16+
17+
;--- main.ll
18+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
19+
target triple = "x86_64-pc-windows-msvc19.11.0"
20+
21+
define dso_local i32 @main() local_unnamed_addr {
22+
entry:
23+
%call = tail call i32 @foo()
24+
%0 = load i32, ptr @variable, align 4
25+
%add = add nsw i32 %0, %call
26+
ret i32 %add
27+
}
28+
29+
@variable = external dllimport local_unnamed_addr global i32, align 4
30+
31+
declare dllimport i32 @foo() local_unnamed_addr
32+
33+
!llvm.module.flags = !{!1}
34+
35+
!1 = !{i32 1, !"ThinLTO", i32 0}
36+
37+
;--- other.ll
38+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
39+
target triple = "x86_64-pc-windows-msvc19.11.0"
40+
41+
define dso_local i32 @foo() local_unnamed_addr {
42+
entry:
43+
ret i32 42
44+
}
45+
46+
@variable = dso_local local_unnamed_addr global i32 1, align 4
47+
48+
!llvm.module.flags = !{!1}
49+
50+
!1 = !{i32 1, !"ThinLTO", i32 0}

lld/test/COFF/lto-imp-prefix.ll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
; RUN: llvm-as %t.dir/main.ll -o %t.main.obj
66
; RUN: llvm-as %t.dir/other.ll -o %t.other.obj
77

8-
; RUN: lld-link /entry:entry %t.main.obj %t.other.obj /out:%t.exe /subsystem:console
8+
; RUN: lld-link /entry:entry %t.main.obj %t.other.obj /out:%t.exe /subsystem:console /debug:symtab
9+
10+
;; The current implementation for handling __imp_ symbols retains all of them.
11+
;; Observe that this currently produces __imp_unusedFunc even if nothing
12+
;; references unusedFunc in any form.
13+
14+
; RUN: llvm-nm %t.exe | FileCheck %s
15+
16+
; CHECK: __imp_unusedFunc
917

1018
;--- main.ll
1119
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
@@ -33,6 +41,13 @@ entry:
3341
ret void
3442
}
3543

44+
@__imp_unusedFunc = global ptr @unusedFuncReplacement
45+
46+
define internal void @unusedFuncReplacement() {
47+
entry:
48+
ret void
49+
}
50+
3651
define void @other() {
3752
entry:
3853
ret void

llvm/test/LTO/X86/Inputs/dllimport.ll

Lines changed: 0 additions & 17 deletions
This file was deleted.

llvm/test/LTO/X86/dllimport.ll

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)