On my Pi 4 Model B with 4GB running the 64-bit Raspberry Pi OS:
$ uname -a
Linux pi4b 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
I have installed Clang 16 from llvm.org:
$ 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
When I try to compile and run a simple hello world C program with a sanitizer, I get:
$ clang-16 -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=25778)
<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=25782)
<empty stack>
I have also tried it with other recommended compiler options:
$ clang-16 -fno-omit-frame-pointer -fsanitize=memory -fPIE -pie -g -O2 -o hello hello.c && ./hello
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=25796)
<empty stack>
Same thing with Clang versions 17 and 18. Clang versions:
$ 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-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
This looks like some sort of memory allocation problem, though virtual memory shows unlimited:
$ 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
I noticed this in the memory sanitizer documentation:
MemorySanitizer maps (but not reserves) 64 Terabytes of virtual address space. This means that tools like ulimit may not work as usually expected.
Also for the address sanitizer:
On 64-bit platforms AddressSanitizer maps (but not reserves) 16+ Terabytes of virtual address space. This means that tools like ulimit may not work as usually expected.
Does anyone know of memory allocation constraints that may be unique to Raspberry Pi OS? These sanitizers seem to work just fine on other Linux systems. Or more generally, does anyone know what's going on here and how to fix this?