[llvm-bugs] [Bug 37276] New: Importing symbols with __m128 type from MSVC .lib fails

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 27 14:11:26 PDT 2018


            Bug ID: 37276
           Summary: Importing symbols with __m128 type from MSVC .lib
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: COFF
          Assignee: unassignedbugs at nondot.org
          Reporter: alexandre.ganea at ubisoft.com
                CC: llvm-bugs at lists.llvm.org

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:
>>> referenced by use_lib.obj:(main)

The difference is that the clang-generated symbol is:
While the MSVC-generated symbol is:                  

Using http://demangler.com/ 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


- I expect T (__m128) is probably not a TagType thus ?A is not generated.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180427/93ad8556/attachment.html>

More information about the llvm-bugs mailing list