google / sanitizers

AddressSanitizer, ThreadSanitizer, MemorySanitizer
Other
11.41k stars 1.03k forks source link

Sanitizer CHECK failed: sanitizer_allocator_primary64.h:133 #1674

Open madler opened 1 year ago

madler commented 1 year ago

On a fresh install from apt.llvm.org of clang 16.0.6 on an aarch64 Linux (Raspberry Pi OS Debian on a Pi 4 model B with 4GB), compiling and running a hello world C program, with virtual memory set to unlimited:

$ clang-16 -fno-omit-frame-pointer -fsanitize=memory -fPIE -pie -g -O2  -o hello hello.c /lib/clang/16.0.6/lib/linux/libclang_rt.msan-aarch64.a && ./hello
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=22650)
    <empty stack>

$ clang-16 -fsanitize=address -o hello hello.c && ./hello
AddressSanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0x600000000000, 0xfffffffffffffff4) (tid=22698)
    <empty stack>

$ clang-16 --version
Debian clang version 16.0.6 (++20230710041823+7cbf1a259152-1~exp1~20230710161844.102)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) 0
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 13113
max locked memory           (kbytes, -l) 485674
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1024
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 13113
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited

Same thing with clang 17 and 18:

$ clang-17 --version
Debian clang version 17.0.0 (++20230808113611+f8468c316fbe-1~exp1~20230808113625.17)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-17 -fsanitize=memory -o hello hello.c && ./hello
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=22774)
    <empty stack>

$ clang-18 --version
Debian clang version 18.0.0 (++20230808111734+af635a5547ec-1~exp1~20230808111853.822)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-18 -fsanitize=memory -o hello hello.c && ./hello
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=22779)
    <empty stack>

The system this is on:

$ uname -a
Linux pi4b 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux
deepthigith commented 8 months ago

I am facing the same issue on enabling sanitizers for gcc on aarch64 linux. The issue was observed with the following command :- "aarch64-poky-linux-gcc -O1 -fsanitize=address -fno-omit-frame-pointer -o test test.c" I analyzed and tried to port the patch that fixes the issue for llvm. However, the file "sanitizer_runtime_select_allocator.h" is missing in gcc source. Hence, could not port the complete patch to test the fix on gcc. Can you please help me in resolving the issue on gcc.