Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLD] please support MSVC ABI in GNU toolchain and support GNU ABI in MSVC toolchain #60847

Open
vhyijk opened this issue Feb 18, 2023 · 4 comments
Labels

Comments

@vhyijk
Copy link

vhyijk commented Feb 18, 2023

Because of the two different name mangling rules (Visual C++ and MinGW-w64) on Windows, LLD cannot link against MSVC libraries in MinGW toolchain (x86_64-w64-windows-gnu) or link against GNU libraries in MSVC toolchain (x86_64-pc-windows-msvc).
Hope to support MSVC ABI in GNU toolchain and support GNU ABI in MSVC toolchain.

@vhyijk vhyijk changed the title For LLD, please support MSVC-ABI libs in GNU toolchain and support GNU-ABI libs in MSVC toolchain [LLD] please support MSVC-ABI libs in GNU toolchain and support GNU-ABI libs in MSVC toolchain Feb 18, 2023
@vhyijk vhyijk changed the title [LLD] please support MSVC-ABI libs in GNU toolchain and support GNU-ABI libs in MSVC toolchain [LLD] please support MSVC ABI in GNU toolchain and support GNU ABI in MSVC toolchain Feb 18, 2023
@alvinhochun
Copy link
Contributor

What exactly is the use case you have in mind?

@llvmbot
Copy link
Member

llvmbot commented Feb 18, 2023

@llvm/issue-subscribers-lld-coff

@vhyijk
Copy link
Author

vhyijk commented Feb 20, 2023

What exactly is the use case you have in mind?

This problem does only appear on Windows.
MSVC and GCC have different C++ name mangling rules. For example, I have a C++ function int func(int , int);. MSVC will mangle it into ?func@@YAHHH@Z but GCC will mangle it into _Z4funcii.
When I use Clang as GCC (gcc.exe), I cannot link against the libraries compiled by MSVC. When I use Clang as MSVC (cl.exe & link.exe), I cannot link against the libraries compiled by GCC, either.
On Windows, I have known LLVM supports both MinGW ABI (aka. Itanium C++ ABI) and MSVC ABI but I cannot use these two ABIs at the same time.

@alvinhochun
Copy link
Contributor

When I use Clang as GCC (gcc.exe), I cannot link against the libraries compiled by MSVC. When I use Clang as MSVC (cl.exe & link.exe), I cannot link against the libraries compiled by GCC, either.

Please mind that in almost all cases you do not want to mix MSVC static libraries (objects) with MinGW, even if they are plain C. Doing so is unsupported and is most certainly going to cause issues.

Linking against MSVC dynamic libraries (DLLs) through a import lib from MinGW code (and vice versa) does work, however this applies to C linkage only. When exporting APIs that are expected to be usable from different compilers, they should be limited to C ABI and use extern "C" linkage, which also disables name mangling.

On Windows, I have known LLVM supports both MinGW ABI (aka. Itanium C++ ABI) and MSVC ABI but I cannot use these two ABIs at the same time.

You can use those two ABIs together provided that they live in separate DLLs and you don't try to pass any C++ types between them 1. The MinGW C++ ABI is very much incompatible with the MSVC ABI, and name mangling is only a very small part of it. Making the name mangling "compatible" does not magically make them compatible. (For simple functions it may happen to work, but definitely not when C++ types starts getting involved.)

Footnotes

  1. COM objects implemented in C++ can cross the MSVC and MinGW ABI boundary, but only if you treat them strictly as COM objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants