[cfe-users] ASAN with MinGW
Michael Hartmann via cfe-users
cfe-users at lists.llvm.org
Mon Jul 13 00:26:01 PDT 2020
Dear LLVM community,
I am looking for a free C/C++ compiler for Windows including support for
sanitizers. For that I want to use clang in a MinGW environment. I am
using winlibs (http://winlibs.com) which comes with clang 10. Compiling
works like a charm but when I try to use for example the address
sanitizes (ASAN) I get the error message:
> clang -Wall -fsanitize=address test.c
ld: cannot find
[...]\mingw64\lib\clang\10.0.0\lib\windows\libclang_rt.asan_dynamic-x86_64.dll.a:
No such file or directory
ld: cannot find
[...]\mingw64\lib\clang\10.0.0\lib\windows\libclang_rt.asan_dynamic_runtime_thunk-x86_64.a:
No such file or directory
ld: cannot find
[...]\mingw64\lib\clang\10.0.0\lib\windows\libclang_rt.asan_dynamic_runtime_thunk-x86_64.a:
No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
If I am not mistaken, the shared and static libraries for the ASAN run
time enviorment are missing. Indeed, I checked that the files
libclang_rt.asan_dynamic-x86_64.dll.a and
libclang_rt.asan_dynamic_runtime_thunk-x86_64.a do not exist in the
MinGW distribution that I am using.
I also tried to compile the runtime myself. I checked out the llvm repo
and tried to compile the targets in rt-build. However, I
get the following error message:
> ninja
[8/15] Linking CXX shared library
lib\windows\libclang_rt.asan_dynamic-x86_64.dll
FAILED: lib/windows/libclang_rt.asan_dynamic-x86_64.dll
lib/windows/libclang_rt.asan_dynamic-x86_64.dll.a
cmd.exe /C "cd . && [...]\mingw64\bin\clang++.exe -Wall -std=c++14
-Wno-unused-parameter -m64 -nodefaultlibs -shared -o
lib\windows\libclang_rt.asan_dynamic-x86_64.dll
-Wl,--out-implib,lib\windows\libclang_rt.asan_dynamic-x86_64.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
@CMakeFiles\clang_rt.asan-dynamic-x86_64.rsp && cd ."
Warning: .drectve
`/alternatename:__sanitizer_report_error_summary=__sanitizer_report_error_summary__def
/export:__sanitizer_report_error_summary__dll=__sanitizer_report_error_summary
' unrecognized
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: .drectve
`/alternatename:__sanitizer_cov_trace_pc_guard=__sanitizer_cov_trace_pc_guard__def
/export:__sanitizer_cov_trace_pc_guard__dll=__sanitizer_cov_trace_pc_guard
/alternatename:__sanitizer_cov_trace_pc_guard_init=__sanitizer_cov_trace_pc_guard_init__def
/export:__sanitizer_cov_trace_pc_guard_init__dll=__sanitizer_cov_trace_pc_guard_init
/alternatename:__sanitizer_cov_trace_cmp=__sanitizer_cov_trace_cmp__def
/export:__sanitizer_cov_trace_cmp__dll=__sanitizer_cov_trace_cmp
/alternatename:__sanitizer_cov_trace_cmp1=__sanitizer_cov_trace_cmp1__def
/export:__sanitizer_cov_trace_cmp1__dll=__sanitizer_cov_trace_cmp1
/alternatename:__sanitizer_cov_trace_cmp2=__sanitizer_cov_trace_cmp2__def
/export:__sanitizer_cov_trace_cmp2__dll=__sanitizer_cov_trace_cmp2
/alternatename:__sanitizer_cov_trace_cmp4=__sanitizer_cov_trace_cmp4__def
/export:__sanitizer_cov_trace_cmp4__dll=__sanitizer_cov_trace_cmp4
/alternatename:__sanitizer_cov_trace_cmp8=__sanitizer_cov_trace_cmp8__def
/export:__sanitizer_cov_trace_cmp8__dll=__sanitizer_cov_trace_cmp8
/alternatename:__sanitizer_cov_trace_const_cmp1=__sanitizer_cov_trace_const_cmp1__def
/export:__sanitizer_cov_trace_const_cmp1__dll=__sanitizer_cov_trace_const_cmp1
/alternatename:__sanitizer_cov_trace_const_cmp2=__sanitizer_cov_trace_const_cmp2__def
/export:__sanitizer_cov_trace_const_cmp2__dll=__sanitizer_cov_trace_const_cmp2
/alternatename:__sanitizer_cov_trace_const_cmp4=__sanitizer_cov_trace_const_cmp4__def
/export:__sanitizer_cov_trace_const_cmp4__dll=__sanitizer_cov_trace_const_cmp4
/alternatename:__sanitizer_cov_trace_const_cmp8=__sanitizer_cov_trace_const_cmp8__def
/export:__sanitizer_cov_trace_const_cmp8__dll=__sanitizer_cov_trace_const_cmp8
/alternatename:__sanitizer_cov_trace_switch=__sanitizer_cov_trace_switch__def
/export:__sanitizer_cov_trace_switch__dll=__sanitizer_cov_trace_switch
/alternatename:__sanitizer_cov_trace_div4=__sanitizer_cov_trace_div4__def
/export:__sanitizer_cov_trace_div4__dll=__sanitizer_cov_trace_div4
/alternatename:__sanitizer_cov_trace_div8=__sanitizer_cov_trace_div8__def
/export:__sanitizer_cov_trace_div8__dll=__sanitizer_cov_trace_div8
/alternatename:__sanitizer_cov_trace_gep=__sanitizer_cov_trace_gep__def
/export:__sanitizer_cov_trace_gep__dll=__sanitizer_cov_trace_gep
/alternatename:__sanitizer_cov_trace_pc_indir=__sanitizer_cov_trace_pc_indir__def
/export:__sanitizer_cov_trace_pc_indir__dll=__sanitizer_cov_trace_pc_indir
/alternatename:__sanitizer_cov_8bit_counters_init=__sanitizer_cov_8bit_counters_init__def
/export:__sanitizer_cov_8bit_counters_init__dll=__sanitizer_cov_8bit_counters_init
/alternatename:__sanitizer_cov_pcs_init=__sanitizer_cov_pcs_init__def
/export:__sanitizer_cov_pcs_init__dll=__sanitizer_cov_pcs_init '
unrecognized
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: .drectve
`/alternatename:__ubsan_handle_cfi_bad_type=__ubsan_handle_cfi_bad_type_default
' unrecognized
Warning: .drectve
`/alternatename:__sanitizer_malloc_hook=__sanitizer_malloc_hook__def
/export:__sanitizer_malloc_hook__dll=__sanitizer_malloc_hook
/alternatename:__sanitizer_free_hook=__sanitizer_free_hook__def
/export:__sanitizer_free_hook__dll=__sanitizer_free_hook ' unrecognized
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: .drectve
`/alternatename:__sanitizer_weak_hook_strcmp=__sanitizer_weak_hook_strcmp__def
/export:__sanitizer_weak_hook_strcmp__dll=__sanitizer_weak_hook_strcmp
/alternatename:__sanitizer_weak_hook_strncmp=__sanitizer_weak_hook_strncmp__def
/export:__sanitizer_weak_hook_strncmp__dll=__sanitizer_weak_hook_strncmp
/alternatename:__sanitizer_weak_hook_strstr=__sanitizer_weak_hook_strstr__def
/export:__sanitizer_weak_hook_strstr__dll=__sanitizer_weak_hook_strstr
/alternatename:__sanitizer_weak_hook_memcmp=__sanitizer_weak_hook_memcmp__def
/export:__sanitizer_weak_hook_memcmp__dll=__sanitizer_weak_hook_memcmp '
unrecognized
Warning: .drectve `/alternatename:__asan_on_error=__asan_on_error__def
/export:__asan_on_error__dll=__asan_on_error ' unrecognized
Warning: corrupt .drectve at end of def file
Warning: .drectve `/include:__asan_dso_reg_hook ' unrecognized
[..]\mingw64\bin\ld:
lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_common.cpp.obj:[...]\compiler-rt\build/../lib/sanitizer_common/sanitizer_common.cpp:93:
undefined reference to `__sanitizer_report_error_summary'
[..]\mingw64\bin\ld:
lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_printf.cpp.obj:[...]\compiler-rt\build/../lib/sanitizer_common/sanitizer_printf.cpp:240:
undefined reference to `__sanitizer_on_print'
The problem seems to be caused by weak references which are used by
ASAN. In particular, it seems that the compiler directive /alternatename
is not available. I guess that this option might be available with the
Visual Studio compatible frontend of clang.
I also extensively searched the web but only found outdated information.
Can anyone tell me how I can get ASAN (and hopefully other sanitizers)
working in a MinGW enviroment?
Thank you very much and kind regards,
--Michael
More information about the cfe-users
mailing list