I am normally using valgrind for my c/c++ programs but people have been recommending address sanitizer, so I wanted to test it out, but im having problems linking against it on a redhat system.
I got the following code:
$ cat heap-use-after-free.cpp
int main(int argc, char **argv) {
int *array = new int[100];
delete [] array;
return array[argc]; // BOOM
}
compiling like:
$ g++ -O -g -fsanitize=address heap-use-after-free.cpp
/usr/bin/ld: cannot find /usr/lib64/libasan.so.0.0.0
collect2: error: ld returned 1 exit status
On a redhat where I have installed libasan
sudo yum install libasan
[sudo] password for dingdongsong:
Loaded plugins: langpacks, product-id, rhnplugin, search-disabled-repos, subscription-manager
This system is receiving updates from RHN Classic or Red Hat Satellite.
rh-network-tools-rhel-x86_64-server-7-prod | 1.5 kB 00:00:00
rhel-x86_64-server-7-custom-prod | 1.0 kB 00:00:00
rhel-x86_64-server-7-epel-prod | 1.5 kB 00:00:00
rhel-x86_64-server-7-prod | 1.5 kB 00:00:00
rhel-x86_64-server-7-rhscl-1-prod | 1.5 kB 00:00:00
rhel-x86_64-server-7-thirdparty-oracle-java-prod | 1.5 kB 00:00:00
rhel-x86_64-server-extras-7-prod | 1.5 kB 00:00:00
rhel-x86_64-server-optional-7-prod | 1.5 kB 00:00:00
rhel-x86_64-server-supplementary-7-prod | 1.5 kB 00:00:00
Package libasan-4.9.2-6.2.el7.x86_64 already installed and latest version
Nothing to do
With the following libasan shared objects:
$ locate libasan
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libasan.a
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libasan.so
/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/32/libasan_preinit.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/libasan.so
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/libasan_preinit.o
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libasan.a
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libasan.so
/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libasan_preinit.o
/usr/lib64/libasan.so.1
/usr/lib64/libasan.so.1.0.0
Can someone point me in the right direction.
Thanks