我们使用以下代码来确定是否-fsanitize=address在编译时为clang和gcc指定了.我们如何确定是否-fsanitize=undefined已指定?
bool isSanitized = false;
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
isSanitized = true;
#endif
#elif defined(__SANITIZE_ADDRESS__)
isSanitized = true;
#endif
Run Code Online (Sandbox Code Playgroud) 我想在 gcc 中使用这种消毒剂。我怎样才能做到这一点?这样的手术可以吗?
我找到了 clang 的解决方案:
clang -fsanitize=memory -fno-omit-frame-pointer -g -O2 umr.cc但我不知道如何在 gcc 中使用它
我在共享库中有这个类:
class Interface {
int m_ref;
public:
FOO_EXPORT virtual ~Interface();
virtual void foo() = 0;
protected:
void ref() { ++m_ref; }
bool deref() { return --m_ref; }
};
// cpp file:
Interface::~Interface() {}
Run Code Online (Sandbox Code Playgroud)
哪里FOO_EXPORT是__attribute__((visibility=default))GCC 的,我正在使用-fvisibiliy=hidden -fvisibility-inlines-hidden.
但是当我使用Interface另一个库中的 时,我得到了 typeinfo 和 vtable 的未定义引用。
在 MSVC 上,其中FOO_EXPORT) declspec(dllexport/dllimport` 工作正常,因为导出虚拟函数时会导出 vtable。
我当然可以导出整个班级:
类 FOO_EXPORT 接口 {
但这也导出所有内联方法。
是否有一个中间立场,仅导出~Interface()vtable,而没有其他内容?
如果您知道:为什么 GCC 与 MSVC 不兼容?
在下面的代码片段中,有一个不是微不足道的错误,但我希望像 AddressSanitizer 这样的工具来捕捉它。
#include <vector>
#include <iostream>
int main ()
{
std::vector<int> toto;
toto.push_back(2);
int const& titi = toto[0];
toto.pop_back();
std::cout << titi << std::endl;
return 1;
}
Run Code Online (Sandbox Code Playgroud)
当作用域向量并在范围之外打印时,catch 引用会抛出一个错误,使用堆后释放。
但是当没有作用域时,std::vector实现可能不会在 pop_back 之后释放内存,因此引用仍然指向有效内存。
我四处搜索,发现您可以手动毒化内存,我想知道这是否已在 STL 中实现(https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning)
当我用 编译我的 C++ 代码时-fsanitize=address,我的软件会在它退出时打印出一个泄漏列表。有没有办法避免泄漏报告(我只对内存损坏感兴趣,而不是泄漏)?我去了带有ASAN flags page 的页面,但看起来这些标志中的任何一个都不匹配。
我正在研究一个 C++ cmake 项目。除了我自己的源代码,我的项目使用了很多第三方库。因此,我正在使用 /usr/local/lib 中存在的共享库(带有 .so 扩展名),并且对于某些代码存在于 /usr/local/include 中。(就像我使用 /usr/local/include/eigen3/ 中存在的特征库一样)。
如何确保 Address Sanitizer 只检查我的源代码,而不检查任何标准或第三方库?
PS:目前,我正在使用如下所示的地址消毒剂:
ADD_COMPILE_OPTIONS(-O0 -g -Wall -fsanitize=address -fno-omit-frame-pointer)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
Run Code Online (Sandbox Code Playgroud)
我正在使用 gcc 版本:
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
我对 ARM 汇编相对缺乏经验,需要帮助理解几行代码。我已经使用 Godbolt 和 ARM gcc 8.2 编译器编译 C++ 11 代码,并得到了这些汇编代码行:
.L10:
.word .LANCHOR0
Run Code Online (Sandbox Code Playgroud)
我读到这.LANCHOR0是部分锚点,但这是什么意思?
我理解,.wordand.data可以一起使用来声明变量并将值分配给内存空间,如下所示:
.data ! start a group of variable declarations
x: .word 23 ! int x = 23;
Run Code Online (Sandbox Code Playgroud)
但是,什么是
.L10:
.word .LANCHOR0
Run Code Online (Sandbox Code Playgroud)
做?这里前面没有标签.word。
.word其次,当一个行块由另一个像这样的汇编指令块执行时,这意味着什么?
.L7:
.word 131586
.word .LANCHOR0
_GLOBAL__sub_I_unsigned int atlantic_line_ns::getSimInstAddr<atlantic_line_ns::Cr>():
mov r2, #0
ldr r3, .L10
str r2, [r3]
str r2, [r3, #4]
bx lr
Run Code Online (Sandbox Code Playgroud)
提前致谢。
更新
多读一点 ARM 文档后,我明白了
.L7:
.word 131586
.word …Run Code Online (Sandbox Code Playgroud) -funwind-tables我已经搜索了一段时间关于和之间的区别-fasynchronous-unwind-tables,但似乎没有一个确切的答案可以给出明确的解释。
在其他世界:
异步展开表和展开表有什么区别?
异步的意义和优点是什么?
谢谢。
我找到的一些相关材料:
[git commit] libubacktrace:使用 -funwind-tables 而不是 -fexecptions
我试图找到ELF文件的基地址.我知道您可以使用readelf查找程序入口点和不同的部分详细信息(基址,大小,标志等).
例如,x86体系结构的程序基于链接器的0x8048000.使用readelf我可以看到程序入口点,但输出中没有特定字段告诉基地址.
$ readelf -e test
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048390
Start of program headers: 52 (bytes into file)
Start of section headers: 4436 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes) …Run Code Online (Sandbox Code Playgroud) 我使用地址清理程序来清理我的应用程序,该应用程序与 SOCI 链接。但是在使用 Oracle 时会提示 followijg 错误消息。
./SociUT: symbol lookup error: /home/testhome/libs/libsoci_oracle.d.so.1.4.18: undefined symbol: __asan_unregister_globals
Run Code Online (Sandbox Code Playgroud)
这是应用程序的构建输出
/home/rel/GCC/asan-gcc-4.9.3/bc0232/bin/g++ -std=c++11 -g3 -static-libasan -fsanitize=address -fno-omit-frame-pointer -L/home/mt_1/4/4.7.c/build/bc0397/tech/MB/link/API/63 -L/usr/lib64 -L/usr/lib64 -L/home/janaka077/mt-git/mt-database/mt_1/database_SOCI_Core/bin -L/usr/local/boost_1_59_0/stage/lib -L/usr/local/boost_1_59_0/stage/lib -L/usr/local/gtest-1.7.0/lib/.libs -o SociUT Main.o version.o -lmb.d -lrdmacm -libverbs -lxml2 -lmsoci.d -lboost_date_time -lboost_filesystem -lboost_system -lboost_serializion -lboost_thread -lboost_chrono -lgtest -lz -lnsl -lrt -ldl -lz -lcrypt -lnuma
Run Code Online (Sandbox Code Playgroud)