[PATCH] Fix dllexport mangling issue

klutzy klutzytheklutzy at gmail.com
Mon Mar 3 21:46:03 PST 2014


On Sun, Mar 2, 2014 at 12:28 PM, Nico Rieck <nico.rieck at gmail.com> wrote:
> On 01.03.2014 08:29, klutzy wrote:
>> When a symbol is dllexported, LLVM wrongly mangled its name (`func` to
>> `_func` or `_func at 16` for example). It caused linker error since linker
>> doesn't accept mangled name for dllexport.
>
> What version or kind of linker is this? Any further information? As it
> stands, this patch is wrong. Clang generates the same symbol names for
> functions and export directives as MSVC. Note that passing export
> symbols via command line is a bit different from embedded directives.

I'm using mingw-w64 (32-bit) toolchain. gcc doesn't add underscore for
`-export`:

    $ cat test.c
    __declspec(dllexport) void c_func(void) {}
    $ gcc -o test.s -S test.c
    $ cat test.s
    (...)
    _c_func:
    (...)
        .section .drectve
        .ascii " -export:\"c_func\""

However llvm generated " -export:_c_func", which causes link failure.

But my patch was anyway wrong :( It doesn't work with stdcall/fastcall:
For `__stdcall void std_func()`, gcc generates " -export:\"std_func at 0\"".
For fastcall, gcc generates " -export:\"@fast_func at 0\"".
(I wrongly guessed that gcc exports unmangled symbols, which is only
true for cdecl case.)

Is underscore required for msvc? (I was not so aware of it, sorry!)
If so, it would be needed to remove underscore only for mingw target.

>
>> This patch fixes Bug 10174.
>
> That bug seems bogus to me.
>
> -Nico
>



More information about the llvm-commits mailing list