2015-06-18 04:40:43 +08:00
|
|
|
# RUN: yaml2obj < %p/Inputs/export.yaml > %t.obj
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 \
|
2015-06-29 06:16:41 +08:00
|
|
|
# RUN: /export:mangled
|
2015-06-18 04:40:43 +08:00
|
|
|
# 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
|
2015-06-18 13:22:15 +08:00
|
|
|
|
2015-06-29 22:27:10 +08:00
|
|
|
# RUN: yaml2obj < %p/Inputs/export2.yaml > %t5.obj
|
|
|
|
# RUN: rm -f %t5.lib
|
|
|
|
# RUN: llvm-ar cru %t5.lib %t5.obj
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t5.dll /dll %t.obj %t5.lib /export:mangled2
|
2015-06-29 22:27:10 +08:00
|
|
|
# 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
|
2015-06-29 22:27:10 +08:00
|
|
|
|
2015-06-18 13:22:15 +08:00
|
|
|
# RUN: llvm-as -o %t.lto.obj %p/Inputs/export.ll
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t.lto.dll /dll %t.lto.obj /export:exportfn1 /export:exportfn2
|
2015-06-18 13:22:15 +08:00
|
|
|
# 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
|
2015-06-18 04:40:43 +08:00
|
|
|
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t.dll /dll %t.obj /implib:%t2.lib \
|
2015-06-29 06:16:41 +08:00
|
|
|
# RUN: /export:exportfn1 /export:exportfn2
|
2015-07-17 00:45:01 +08:00
|
|
|
# RUN: yaml2obj < %p/Inputs/import.yaml > %t2.obj
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t2.exe /entry:main %t2.obj %t2.lib
|
2015-06-19 04:27:09 +08:00
|
|
|
# RUN: llvm-readobj -coff-imports %t2.exe | FileCheck -check-prefix=IMPORT %s
|
|
|
|
|
2015-08-07 00:47:46 +08:00
|
|
|
# RUN: lld-link /out:%t2.lto.exe /entry:main %t2.obj %t.lto.lib
|
2015-06-18 13:22:15 +08:00
|
|
|
# RUN: llvm-readobj -coff-imports %t2.lto.exe | FileCheck -check-prefix=IMPORT %s
|
|
|
|
|
2015-06-18 04:40:43 +08:00
|
|
|
IMPORT: Symbol: exportfn1
|
|
|
|
IMPORT: Symbol: exportfn2
|