0

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?

5
  • So you're saying the exact same code on a different platform (e.g. AMD64 vs ARM64) works? Aug 10, 2023 at 5:03
  • Yes. As far as I can tell, it works on every other Linux platform. I have tried aarch64, x86_64, and ppc64, running Debian and CentOS. (Sometimes the memory sanitizer isn't there, but the address one is, depending on the clang version.) These sanitizers are in wide use.
    – Mark Adler
    Aug 10, 2023 at 15:38
  • @JaromandaX The documentation says that mips64 is supported as well, though it didn't work on the one that I tried. riscv64 is not supported. The documentation says that the address sanitizer is supported on Linux, Darwin, FreeBSD, and Android, and that the memory sanitizer is supported on Linux, NetBSD, and FreeBSD.
    – Mark Adler
    Aug 10, 2023 at 15:55
  • I found a workaround, where I installed Ubuntu 22.04 on my RPi4. Now clang and its sanitizers work just honky-dory. However this question for Raspberry Pi OS remains.
    – Mark Adler
    Aug 11, 2023 at 6:59
  • suggests a bug in Debian for Pi Aug 11, 2023 at 7:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.