llvm-project/lld/test/COFF/dll.test

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.9 KiB
Plaintext
Raw Normal View History

# REQUIRES: x86
# RUN: yaml2obj %p/Inputs/export.yaml -o %t.obj
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
# RUN: /export:mangled
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=EXPORT %s
EXPORT: Export Table:
EXPORT: DLL name: dll.test.tmp.dll
EXPORT: Ordinal RVA Name
EXPORT-NEXT: 0 0
COFF: Improve dllexported name mangling compatibility. The rules for dllexported symbols are overly complicated due to x86 name decoration, fuzzy symbol resolution, and the fact that one symbol can be resolved by so many different names. The rules are probably intended to be "intuitive", so that users don't have to understand the name mangling schemes, but it seems that it can lead to unintended symbol exports. To make it clear what I'm trying to do with this patch, let me write how the export rules are subtle and complicated. - x86 name decoration: If machine type is i386 and export name is given by a command line option, like /export:foo, the real symbol name the linker has to search for is _foo because all symbols are decorated with "_" prefixes. This doesn't happen on non-x86 machines. This automatic name decoration happens only when the name is not C++ mangled. However, the symbol name exported from DLLs are ones without "_" on all platforms. Moreover, if the option is given via .drectve section, no symbol decoration is done (the reason being that the .drectve section is created by a compiler and the compiler should always know the exact name of the symbol, I guess). - Fuzzy symbol resolution: In addition to x86 name decoration, the linker has to look for cdecl or C++ mangled symbols for a given /export. For example, it searches for not only _foo but also _foo@<number> or ??foo@... for /export:foo. Previous implementation didn't get it right. I'm trying to make it as compatible with MSVC linker as possible with this patch however the rules are. The new code looks a bit messy to me, but I don't think it can be simpler due to the ad-hoc-ness of the rules. llvm-svn: 246424
2015-08-31 16:43:21 +08:00
EXPORT-NEXT: 1 0x1008 exportfn1
EXPORT-NEXT: 2 0x1010 exportfn2
EXPORT-NEXT: 3 0x1010 exportfn3
EXPORT-NEXT: 4 0x1010 mangled
# RUN: yaml2obj %p/Inputs/export2.yaml -o %t4.obj
# RUN: rm -f %t4.lib
# RUN: llvm-ar cru %t4.lib %t4.obj
# RUN: lld-link /out:%t5.dll /dll %t.obj %t4.lib /export:mangled2
# RUN: llvm-objdump -p %t5.dll | FileCheck --check-prefix=EXPORT2 %s
EXPORT2: Export Table:
EXPORT2: DLL name: dll.test.tmp5.dll
EXPORT2: Ordinal RVA Name
EXPORT2-NEXT: 0 0
COFF: Improve dllexported name mangling compatibility. The rules for dllexported symbols are overly complicated due to x86 name decoration, fuzzy symbol resolution, and the fact that one symbol can be resolved by so many different names. The rules are probably intended to be "intuitive", so that users don't have to understand the name mangling schemes, but it seems that it can lead to unintended symbol exports. To make it clear what I'm trying to do with this patch, let me write how the export rules are subtle and complicated. - x86 name decoration: If machine type is i386 and export name is given by a command line option, like /export:foo, the real symbol name the linker has to search for is _foo because all symbols are decorated with "_" prefixes. This doesn't happen on non-x86 machines. This automatic name decoration happens only when the name is not C++ mangled. However, the symbol name exported from DLLs are ones without "_" on all platforms. Moreover, if the option is given via .drectve section, no symbol decoration is done (the reason being that the .drectve section is created by a compiler and the compiler should always know the exact name of the symbol, I guess). - Fuzzy symbol resolution: In addition to x86 name decoration, the linker has to look for cdecl or C++ mangled symbols for a given /export. For example, it searches for not only _foo but also _foo@<number> or ??foo@... for /export:foo. Previous implementation didn't get it right. I'm trying to make it as compatible with MSVC linker as possible with this patch however the rules are. The new code looks a bit messy to me, but I don't think it can be simpler due to the ad-hoc-ness of the rules. llvm-svn: 246424
2015-08-31 16:43:21 +08:00
EXPORT2-NEXT: 1 0x1010 exportfn3
EXPORT2-NEXT: 2 0x101c mangled2
# RUN: llvm-as -o %t.lto.obj %p/Inputs/export.ll
# RUN: lld-link -opt:noicf /out:%t.lto.dll /dll %t.lto.obj /export:exportfn1 /export:exportfn2
# RUN: llvm-objdump -p %t.lto.dll | FileCheck --check-prefix=EXPORT-LTO %s
EXPORT-LTO: Export Table:
EXPORT-LTO: DLL name: dll.test.tmp.lto.dll
EXPORT-LTO: Ordinal RVA Name
EXPORT-LTO-NEXT: 0 0
EXPORT-LTO-NEXT: 1 0x1010 exportfn1
EXPORT-LTO-NEXT: 2 0x1020 exportfn2
EXPORT-LTO-NEXT: 3 0x1030 exportfn3
# RUN: lld-link /out:%t.dll /dll %t.obj /implib:%t2.lib \
# RUN: /export:exportfn1 /export:exportfn2
# RUN: yaml2obj %p/Inputs/import.yaml -o %t2.obj
# RUN: lld-link /out:%t2.exe /entry:main %t2.obj %t2.lib
# RUN: llvm-readobj --coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s
# RUN: lld-link /out:%t2.lto.exe /entry:main %t2.obj %t.lto.lib
# RUN: llvm-readobj --coff-imports %t2.lto.exe | FileCheck -check-prefix=IMPORT %s
IMPORT: Symbol: exportfn1
IMPORT: Symbol: exportfn2