1# REQUIRES: x86 2 3# RUN: echo -e ".globl libfunc\n.text\nlibfunc:\nret" > %t.lib.s 4# RUN: llvm-mc -triple=x86_64-windows-gnu %t.lib.s -filetype=obj -o %t.lib.o 5# RUN: lld-link -lldmingw -dll -out:%t.lib.dll -entry:libfunc %t.lib.o -implib:%t.lib.dll.a 6 7# RUN: echo -e ".globl helper1\n.text\nhelper1:\ncall libfunc\nret" > %t.helper1.s 8# RUN: echo -e ".globl helper2\n.text\nhelper2:\nret\n.globl libfunc\n.globl __imp_libfunc\nlibfunc:\nret\n.data\n__imp_libfunc:\n.quad libfunc" > %t.helper2.s 9# RUN: llvm-mc -triple=x86_64-windows-gnu %t.helper1.s -filetype=obj -o %t.helper1.o 10# RUN: llvm-mc -triple=x86_64-windows-gnu %t.helper2.s -filetype=obj -o %t.helper2.o 11 12# RUN: llvm-ar rcs %t.helper.a %t.helper1.o %t.helper2.o 13 14# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.main.o 15 16# Simulate a setup, where two libraries provide the same import function; 17# %t.lib.dll.a is a pure import library which provides "libfunc". 18# %t.helper.a is a static library which contains "helper1" and "helper2". 19# 20# helper1 contains an undefined reference to libfunc. helper2 contains a 21# fake local implementation of libfunc, together with the __imp_libfunc 22# stub. 23# 24# %t.lib.dll.a is listed before %t.helper.a on the command line. After 25# including helper1, the library member that first declared the Lazy libfunc 26# (%t.lib.dll.a) gets enqueued to be loaded. Before that gets done, helper2 27# gets loaded, which also turns out to provide a definition of libfunc. 28# Once the import library member from %t.lib.dll.a gets loaded, libfunc 29# and __imp_libfunc already are defined. 30 31# Just check that this fails cleanly (doesn't crash). 32# RUN: not lld-link -lldmingw -out:%t.main.exe -entry:main %t.main.o %t.lib.dll.a %t.helper.a 33 34# Test with %t.helper.a on the command line; in this case we won't try to 35# include libfunc from %t.lib.dll.a and everything works fine. 36# RUN: lld-link -lldmingw -out:%t.main.exe -entry:main %t.main.o %t.helper.a %t.lib.dll.a 37 38 .globl main 39 .text 40main: 41 call helper1 42 call helper2 43 ret 44