61 lines · plain
1// REQUIRES: x862 3// Check that we can wrap a dllimported symbol, so that references to4// __imp_<symbol> gets redirected to a symbol that already exists or a defined5// local import instead.6 7// RUN: split-file %s %t.dir8// RUN: llvm-mc -filetype=obj -triple=i686-win32-gnu %t.dir/main.s -o %t.main.obj9// RUN: llvm-mc -filetype=obj -triple=i686-win32-gnu %t.dir/other.s -o %t.other.obj10 11// RUN: lld-link -dll -out:%t.dll %t.other.obj -noentry -safeseh:no -export:foo -export:bar -implib:%t.lib12// 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.map13// RUN: llvm-objdump -s -d --print-imm-hex %t.exe | FileCheck %s14 15// CHECK: Contents of section .rdata:16// CHECK-NEXT: 402000 0c10400017 18// CHECK: Disassembly of section .text:19// CHECK-EMPTY:20// CHECK: 00401000 <_entry>:21// CHECK-NEXT: 401000: ff 25 00 20 40 00 jmpl *0x40200022// CHECK-NEXT: 401006: ff 25 00 00 00 00 jmpl *0x023// CHECK-EMPTY:24// CHECK-NEXT: 0040100c <___wrap_foo>:25// CHECK-NEXT: 40100c: c3 retl26// CHECK-EMPTY:27// CHECK-NEXT: 0040100d <___wrap_bar>:28// CHECK-NEXT: 40100d: c3 retl29 30// The first jmpl instruction in _entry points at an address in 0x402000,31// which is the first 4 bytes of the .rdata section (above), which is a32// pointer that points at ___wrap_foo.33 34// The second jmpl instruction in _entry points to null because the referenced35// symbol `__imp____wrap_bar` is declared as a weak reference to prevent pull a36// reference from an external DLL.37 38#--- main.s39.global _entry40_entry:41 jmpl *__imp__foo42 jmpl *__imp__bar43 44.global ___wrap_foo45___wrap_foo:46 ret47 48.weak __imp____wrap_bar49.global ___wrap_bar50___wrap_bar:51 ret52 53#--- other.s54.global _foo55_foo:56 ret57 58.global _bar59_bar:60 ret61