|
1 | 1 | // REQUIRES: x86
|
2 | 2 |
|
3 | 3 | // Check that we can wrap a dllimported symbol, so that references to
|
4 |
| -// __imp_<symbol> gets redirected to a defined local import instead. |
| 4 | +// __imp_<symbol> gets redirected to a symbol that already exists or a defined |
| 5 | +// local import instead. |
5 | 6 |
|
6 | 7 | // RUN: split-file %s %t.dir
|
7 | 8 | // RUN: llvm-mc -filetype=obj -triple=i686-win32-gnu %t.dir/main.s -o %t.main.obj
|
8 | 9 | // RUN: llvm-mc -filetype=obj -triple=i686-win32-gnu %t.dir/other.s -o %t.other.obj
|
9 | 10 |
|
10 |
| -// RUN: lld-link -dll -out:%t.dll %t.other.obj -noentry -safeseh:no -export:foo -implib:%t.lib |
11 |
| -// RUN: lld-link -out:%t.exe %t.main.obj %t.lib -entry:entry -subsystem:console -debug:symtab -safeseh:no -wrap:foo -lldmap:%t.map |
| 11 | +// RUN: lld-link -dll -out:%t.dll %t.other.obj -noentry -safeseh:no -export:foo -export:bar -implib:%t.lib |
| 12 | +// RUN: lld-link -out:%t.exe %t.main.obj %t.lib -entry:entry -subsystem:console -debug:symtab -safeseh:no -wrap:foo -wrap:bar -lldmap:%t.map |
12 | 13 | // RUN: llvm-objdump -s -d --print-imm-hex %t.exe | FileCheck %s
|
13 | 14 |
|
14 | 15 | // CHECK: Contents of section .rdata:
|
15 |
| -// CHECK-NEXT: 402000 06104000 |
| 16 | +// CHECK-NEXT: 402000 0c104000 |
16 | 17 |
|
17 | 18 | // CHECK: Disassembly of section .text:
|
18 | 19 | // CHECK-EMPTY:
|
19 | 20 | // CHECK: 00401000 <_entry>:
|
20 | 21 | // CHECK-NEXT: 401000: ff 25 00 20 40 00 jmpl *0x402000
|
| 22 | +// CHECK-NEXT: 401006: ff 25 00 00 00 00 jmpl *0x0 |
21 | 23 | // CHECK-EMPTY:
|
22 |
| -// CHECK-NEXT: 00401006 <___wrap_foo>: |
23 |
| -// CHECK-NEXT: 401006: c3 retl |
| 24 | +// CHECK-NEXT: 0040100c <___wrap_foo>: |
| 25 | +// CHECK-NEXT: 40100c: c3 retl |
| 26 | +// CHECK-EMPTY: |
| 27 | +// CHECK-NEXT: 0040100d <___wrap_bar>: |
| 28 | +// CHECK-NEXT: 40100d: c3 retl |
24 | 29 |
|
25 |
| -// The jmpl instruction in _entry points at an address in 0x402000, |
| 30 | +// The first jmpl instruction in _entry points at an address in 0x402000, |
26 | 31 | // which is the first 4 bytes of the .rdata section (above), which is a
|
27 | 32 | // pointer that points at ___wrap_foo.
|
28 | 33 |
|
| 34 | +// The second jmpl instruction in _entry points to null because the referenced |
| 35 | +// symbol `__imp____wrap_bar` is declared as a weak reference to prevent pull a |
| 36 | +// reference from an external DLL. |
| 37 | + |
29 | 38 | #--- main.s
|
30 | 39 | .global _entry
|
31 | 40 | _entry:
|
32 | 41 | jmpl *__imp__foo
|
| 42 | + jmpl *__imp__bar |
33 | 43 |
|
34 | 44 | .global ___wrap_foo
|
35 | 45 | ___wrap_foo:
|
36 | 46 | ret
|
37 | 47 |
|
| 48 | +.weak __imp____wrap_bar |
| 49 | +.global ___wrap_bar |
| 50 | +___wrap_bar: |
| 51 | + ret |
| 52 | + |
38 | 53 | #--- other.s
|
39 | 54 | .global _foo
|
40 |
| - |
41 | 55 | _foo:
|
42 | 56 | ret
|
| 57 | + |
| 58 | +.global _bar |
| 59 | +_bar: |
| 60 | + ret |
0 commit comments