每当我运行任何 C++ 代码时,无论其内容如何,我有时都会随机收到以下错误:
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
Segmentation fault (core dumped)
我使用的是 Ubuntu 23.10,内核版本为:Linux 6.5.0-25-generic x86_64。使用 g++ 13.2.0 编译器。代码内容实际上并不重要,基本的 Hello World 程序会导致问题。我正在使用以下标志进行编译:
g++ test.cpp -std=c++23 -fsanitize=address -o test
问题似乎来自使用以下标志:
-fsanitize=address
我注意到,只有当我开始弄乱具有动态内存分配的代码时,这种情况才开始发生,有时我还会无缘无故地出现内存泄漏。我以为当我再次编写正常代码时问题就会消失,但事实并非如此。
当我尝试运行以下命令时:
ulimit -s unlimited
再次运行代码,我得到了一个新错误:
==18240==Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING.
==18240==ASan shadow was supposed to be located in the \[0x00007fff7000-0x10007fff7fff\] range.
==18240==This might be related to ELF_ET_DYN_BASE change in Linux 4.12.
==18240==See https://github.com/google/sanitizers/issues/856 for possible workarounds.
==18240==Process memory map follows:
0x0f0051f00000-0x0f0052000000
0x0f0052100000-0x0f0052200000
0x0f0052300000-0x0f0052400000
0x0f0052500000-0x0f0052600000
0x0f0052700000-0x0f0052800000
0x0f0052872000-0x0f0052c00000
0x0f0052c00000-0x0f0052c26000 /usr/lib/x86_64-linux-gnu/libc.so.6
0x0f0052c26000-0x0f0052da5000 /usr/lib/x86_64-linux-gnu/libc.so.6
0x0f0052da5000-0x0f0052dfa000 /usr/lib/x86_64-linux-gnu/libc.so.6
0x0f0052dfa000-0x0f0052dfe000 /usr/lib/x86_64-linux-gnu/libc.so.6
0x0f0052dfe000-0x0f0052e00000 /usr/lib/x86_64-linux-gnu/libc.so.6
0x0f0052e00000-0x0f0052e0d000
0x0f0053000000-0x0f005309c000 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32
0x0f005309c000-0x0f00531cd000 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32
0x0f00531cd000-0x0f005325a000 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32
0x0f005325a000-0x0f0053265000 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32
0x0f0053265000-0x0f0053268000 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32
0x0f0053268000-0x0f005326c000
0x0f0053400000-0x0f0053425000 /usr/lib/x86_64-linux-gnu/libasan.so.8.0.0
0x0f0053425000-0x0f0053534000 /usr/lib/x86_64-linux-gnu/libasan.so.8.0.0
0x0f0053534000-0x0f0053569000 /usr/lib/x86_64-linux-gnu/libasan.so.8.0.0
0x0f0053569000-0x0f005356d000 /usr/lib/x86_64-linux-gnu/libasan.so.8.0.0
0x0f005356d000-0x0f0053570000 /usr/lib/x86_64-linux-gnu/libasan.so.8.0.0
0x0f0053570000-0x0f0053aa4000
0x0f0053b57000-0x0f0053b6c000
0x0f0053b6c000-0x0f0053b6f000 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x0f0053b6f000-0x0f0053b8a000 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x0f0053b8a000-0x0f0053b8e000 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x0f0053b8e000-0x0f0053b8f000 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x0f0053b8f000-0x0f0053b90000 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x0f0053b90000-0x0f0053ba0000 /usr/lib/x86_64-linux-gnu/libm.so.6
0x0f0053ba0000-0x0f0053c20000 /usr/lib/x86_64-linux-gnu/libm.so.6
0x0f0053c20000-0x0f0053c79000 /usr/lib/x86_64-linux-gnu/libm.so.6
0x0f0053c79000-0x0f0053c7a000 /usr/lib/x86_64-linux-gnu/libm.so.6
0x0f0053c7a000-0x0f0053c7b000 /usr/lib/x86_64-linux-gnu/libm.so.6
0x0f0053c82000-0x0f0053c90000
0x0f0053c90000-0x0f0053c91000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
0x0f0053c91000-0x0f0053cbb000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
0x0f0053cbb000-0x0f0053cc5000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
0x0f0053cc5000-0x0f0053cc7000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
0x0f0053cc7000-0x0f0053cc9000 /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
0x5e446ea4f000-0x5e446ea50000 /home/x/Desktop/test
0x5e446ea50000-0x5e446ea51000 /home/x/Desktop/test
0x5e446ea51000-0x5e446ea52000 /home/x/Desktop/test
0x5e446ea52000-0x5e446ea53000 /home/x/Desktop/test
0x5e446ea53000-0x5e446ea54000 /home/x/Desktop/test
0x7ffce680d000-0x7ffce682e000 \[stack\]
0x7ffce68d0000-0x7ffce68d4000 \[vvar\]
0x7ffce68d4000-0x7ffce68d6000 \[vdso\]
0xffffffffff600000-0xffffffffff601000 \[vsyscall\]
==18240==End of process memory map.
有什么办法可以防止这种情况发生吗?
@TheFortyTwo 谢谢你的帖子。我也有同样的经历。我正在将消毒剂与 gtest 一起使用。大约每三次执行测试时,我都会收到无穷无尽的列表 AddressSanitizer:DEADLYSIGNAL。我还缩小了范围,使其独立于我的代码。
所以,我想它必须是
gtest
或消毒剂本身。我使用的是 Ubuntu 22.04.4 LTS,内核 6.5.0-25-generic 和 gcc(Ubuntu 11.4.0~22.04) 11.4.0。将尝试全新安装 VM。