从gcc / clang获取libasan的位置 [英] Get location of libasan from gcc/clang

查看:1118
本文介绍了从gcc / clang获取libasan的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 -fsanitize = address 进行编译时,GCC / Clang隐式使用了ASAN动态库,该库为ASAN提供运行时支持。如果您构建的库是由另一个应用程序动态加载的,则必须设置 LD_PRELOAD 包括此动态库,以便它在应用程序启动时运行。

When I compile with -fsanitize=address, GCC/Clang implicitly make use of an ASAN dynamic library which provides runtime support for ASAN. If your built library is dynamically loaded by another application, it is necessary to set LD_PRELOAD to include this dynamic library, so that it gets run at application start up time.

GCC / Clang希望使用 libasan.so 的哪个副本通常并不明显,因为可能会有多个副本系统上的ASAN(如果已安装多个编译器。)是否有可靠的方法来确定需要加载的共享库的位置?

It is often not obvious which copy of libasan.so GCC/Clang expects to use, because there may be multiple copies of ASAN on your system (if you have multiple compilers installed.) Is there a reliable way to determine the location of the shared library you need to load?

推荐答案

您可以使用-打印文件名标志:

GCC_ASAN_PRELOAD=$(gcc -print-file-name=libasan.so)
CLANG_ASAN_PRELOAD=$(clang -print-file-name=libclang_rt.asan-x86_64.so)

您还可以通过 ldd 从库本身提取libasan路径:

You could also extract libasan path from the library itself via ldd:

$ echo 'void foo() {}' | gcc -x c -fPIC -shared -fsanitize=address -
$ ldd a.out | grep libasan.so | awk '{print $3}'
/usr/lib/x86_64-linux-gnu/libasan.so.4

这篇关于从gcc / clang获取libasan的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆