LLVM compilation error on MinGW / MSYS (CMake)

Hello,

I have the following error when building:

Creating library file: …/…/…/…/lib/libclang.dll.a
…/…/…/…/lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x48a): undefined reference to _imp__SymSetOptions@4' ../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x4aa): undefined reference to _imp__SymInitialize@12’
…/…/…/…/lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x4c3): undefined reference to _imp__SymGetModuleBase@8' ../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x4cd): undefined reference to _imp__SymFunctionTableAccess@8’
…/…/…/…/lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x501): undefined reference to _imp__StackWalk@36' ../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x590): undefined reference to _imp__SymGetModuleBase@8’
…/…/…/…/lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x622): undefined reference to _imp__SymGetSymFromAddr@16' ../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x6eb): undefined reference to _imp__SymGetLineFromAddr@16’
…/…/…/…/lib/libLLVMSupport.a(Process.cpp.obj):Process.cpp:(.text+0xc2): undefined reference to `GetProcessMemoryInfo@12’
collect2: ld returned 1 exit status
make[2]: *** [bin/libclang.dll] Error 1
make[1]: *** [tools/clang/tools/libclang/CMakeFiles/libclang.dir/all] Error 2

It occurs on r128334 and has been occuring for (at least) a week (but I didn’t have time to delve into it then).

From what I can see the Windows specific file lib/Support/Windows/Signals.inc and lib/Support/Windows/Process.inc reference functions that have not been defined anywhere (yet) when libLLVMSupport.a was built.

Searching through the repository did not yield any result on those symbols, so I would guess they are supposed to be defined in a windows library… somehow ?

A quick search on google brought that those are defined in libimagehlp.a (for Signals.cpp stuff) and libpsapi.a (for Process.cpp stuff) for mingw:

$ objdump -t /mingw/lib/libimagehlp.a | grep SymSetOp
[ 7](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _SymSetOptions@4
[ 8](sec 5)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __imp__SymSetOptions@4

$ objdump -t lib/libpsapi.a | grep GetProcessMemoryInfo
[ 7](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _GetProcessMemoryInfo@12
[ 8](sec 5)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 __imp__GetProcessMemoryInfo@12

Since those symbols are effectively defined in my libraries, I suppose it’s a Makefile issue, I use CMake to generate the Makefiles.

I don’t know much about static libraries (and not much about CMake either, I fear), so I don’t know if the symbols should be embedded directly into libLLVMSupport.a (which sounds logical) or if the inclusion is deferred to the clients, in case they actually need them… (in this example, libclang.dll)

Looking at the lib/Support/CMakeFiles/LLVMSupport.dir/link.txt only objects (no library) are referenced (I’ve attached it).

Any tips / patches appreciated :slight_smile:

Matthieu.

link.txt (3.13 KB)

Matthieu Monrocq
<matthieu.monrocq@gmail.com> writes:

I have the following error when building:

Creating library file: ../../../../lib/libclang.dll.a
../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x48a):
undefined reference to `_imp__SymSetOptions@4'

[snip]

Please check if this patch for tools/clang/CMakeLists.txt solves the
problem:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ebe3c4..a56d074 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -182,11 +182,9 @@ macro(add_clang_library name)
   if (LLVM_COMMON_LIBS)
     target_link_libraries(${name} ${LLVM_COMMON_LIBS})
   endif()
- if( NOT MINGW )
- get_system_libs(llvm_system_libs)
- if( llvm_system_libs )
- target_link_libraries(${name} ${llvm_system_libs})
- endif()
+ get_system_libs(llvm_system_libs)
+ if( llvm_system_libs )
+ target_link_libraries(${name} ${llvm_system_libs})
   endif()
   add_dependencies(${name} ClangDiagnosticCommon)
   if(MSVC)

Óscar Fuentes <ofv@wanadoo.es> writes:

Matthieu Monrocq
<matthieu.monrocq@gmail.com> writes:

I have the following error when building:

Creating library file: ../../../../lib/libclang.dll.a
../../../../lib/libLLVMSupport.a(Signals.cpp.obj):Signals.cpp:(.text+0x48a):
undefined reference to `_imp__SymSetOptions@4'

[snip]

Please check if this patch for tools/clang/CMakeLists.txt solves the
problem:

[snip]

It works for me. Committed in r128341.