Reputation: 11
I'm using CLion IDE, Cmake with GCC compiler and I'm trying to run binary with address sanitizer. I followed this: What's the proper way to enable AddressSanitizer in CMake that works in Xcode and added
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
to CMakeLists.txt file and then got an error when running the binary in CLion using the run button:
==22084==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
When I run the binary via terminal, it works as it should be. It doesn't work in CLion's run window. https://i.sstatic.net/Lnqmc.jpg
Edit: The solution was adding LD_PRELOAD=libasan.so.5
to environment variables of CLion.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(Playground)
set(CMAKE_CXX_STANDARD 14)
add_executable(Playground main.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
What's happening?
Adding these lines from the stackoverflow thread to CMakeLists.txt file didnt work too.
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fsanitize=address -fno-omit-frame-pointer")
and this line from this guide https://www.jetbrains.com/help/clion/google-sanitizers.html#LSanChapter also didnt work
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -O1")
Then I tried adding LD_TRACE_LOADED_OBJECTS=1
to CLion environment variables and nothing changed.
My ldd ./file
command output of the binary:
linux-vdso.so.1 (0x00007ffd82d96000)
libgtk3-nocsd.so.0 => /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007f7d532e1000)
libasan.so.5 => /lib/x86_64-linux-gnu/libasan.so.5 (0x00007f7d528af000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7d526bd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7d526b7000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7d52694000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7d52689000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7d52538000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7d5251d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d5350c000)
Upvotes: 1
Views: 2955
Reputation: 10752
First remove all of the set commands you added, and then add these commands before the compile:
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
Upvotes: 2
Reputation: 31020
The problem is caused by the LD_PRELOAD=libgtk3-nocsd.so.0
setting somewhere in your environment. Overwrite it or unset the variable in your CLion run configuration.
Upvotes: 0