<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Importing symbols with __m128 type from MSVC .lib fails"
href="https://bugs.llvm.org/show_bug.cgi?id=37276">37276</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Importing symbols with __m128 type from MSVC .lib fails
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>COFF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>alexandre.ganea@ubisoft.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I'm trying to link against an external .lib that we have no control upon. The
library was compiled with MSVC. It contains functions using __m128. Our code
builds with clang-cl.
When the external library is linked in, functions using __m128 types fail to
resolve, even if they are there.
Given that __m128 is a built-in in clang, mangled symbols are generated (a bit)
differently than when compiling with MSVC.
Consider the following:
// =========================== lib.cpp
#include <intrin.h>
__declspec(dllexport) __m128 identity(const __m128& in)
{
__m128 a = _mm_set_ps1(1.0f);
return a;
}
// =========================== use_lib.cpp
#include <intrin.h>
#include <cstdio>
__declspec(dllimport) __m128 identity(const __m128& in);
int main()
{
__m128 in;
__m128 a = identity(in);
printf("%f\n", (float&)a);
return 0;
}
rem ================================= __build_msvc.bat
del *.dll *.exp *.lib *.exe *.obj
cl /c lib.cpp
lld-link lib.obj /dll
cl /c use_lib.cpp
lld-link /out:good.exe lib.lib use_lib.obj
rem ================================= __build_clang.bat
del *.dll *.exp *.lib *.exe *.obj
cl /c lib.cpp
lld-link lib.obj /dll
clang-cl /c use_lib.cpp
lld-link /out:fail.exe lib.lib use_lib.obj
The script __build_clang.bat above fails with:
C:\Program Files (x86)\LLVM\bin\lld-link.exe: error: undefined symbol:
__imp_?identity@@YAT__m128@@AEBT1@@Z
<span class="quote">>>> referenced by use_lib.obj:(main)</span >
The difference is that the clang-generated symbol is:
?identity@@YA?AT__m128@@AEBT1@@Z
While the MSVC-generated symbol is:
?identity@@YAT__m128@@AEBT1@@Z
Using <a href="http://demangler.com/">http://demangler.com/</a> or the UnDecorateSymbolName API, both resolve to
exactly the same thing:
union __m128 __cdecl identity(union __m128 const & __ptr64)
This issue seems to be caused by a side-effect in
MicrosoftCXXNameMangler::mangleType(),
<a href="https://github.com/llvm-mirror/clang/blob/928958d3756d7bc74399bb9d6489bb7b7361398a/lib/AST/MicrosoftMangle.cpp#L1752">https://github.com/llvm-mirror/clang/blob/928958d3756d7bc74399bb9d6489bb7b7361398a/lib/AST/MicrosoftMangle.cpp#L1752</a>
- I expect T (__m128) is probably not a TagType thus ?A is not generated.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>