Calling a function from Visual Studio dll - name mangling issues

I’m trying to call a function in a dll compiled with Visual Studio from JITed code. Unfortunately, the mangled name generated by the codegen does not match the one that ends up being exported by the dll. LLVM generates a *nix style mangled name() where it needs the windows mangled named.

my external header:

class __declspec(dllimport) mod_test
{
public:
static void test();
};

my generated module after compiling:

; ModuleID = ‘random’
target datalayout = “e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32”
target triple = “i686-pc-win32”

define void @_Z5hellov() nounwind {
entry:
call void @_ZN8mod_test4testEv()
ret void
}

declare void @_ZN8mod_test4testEv()

…while the exported name is ?test@mod_test@SAXXZ. I use clang as a library, without going through the Driver class. Since calls to the system libraries work fine, I’m quite sure that I’m not trying to do something that is not supported.

I would be grateful if anyone could shed some light on this.

Daan Nijs <nijs.daan@gmail.com> writes:

I'm trying to call a function in a dll compiled with Visual Studio from
JITed code. Unfortunately, the mangled name generated by the codegen does
not match the one that ends up being exported by the dll. LLVM generates a
*nix style mangled name() where it needs the windows mangled named.

Clang has no support for VC++ name mangling, nor for the VC++ C++ ABI in
general.

[snip]

Daan Nijs <nijs.daan@gmail.com> writes:

I'm trying to call a function in a dll compiled with Visual Studio from
JITed code. Unfortunately, the mangled name generated by the codegen does
not match the one that ends up being exported by the dll. LLVM generates a
*nix style mangled name() where it needs the windows mangled named.

Clang has no support for VC++ name mangling,

Wrong. I wrote the code myself. You can turn it on by passing "-Xclang
-cxx-abi -Xclang microsoft" on the driver command line. It's not
finished yet, though, so some stuff might not work.

nor for the VC++ C++ ABI in
general.

True, the rest isn't implemented yet. Because of this, I'm not sure
you'd really want to turn it on just yet.

Chip

Charles Davis <cdavis@mymail.mines.edu> writes: