ThreadSanitizer: unexpected memory mapping error

Hey,

First time doing a small side-project with Zig and it requires using some threading. To help with that, I wanted to use the thread sanitizer option on the build but I get the above-mentioned error.

So far, my google foo has led me to believe that it is usually due to some issues with Clang and kernel versions (at least when using GCC/Clang as compilers). The issues have a few solutions suggested in modifying some other flags while the issue is not yet fixed (e.g. StackOverflow Question).

The issue here is right now I am not too sure how to proceed to get TSAN working properly, can anyone help me with that?

If you get: FATAL: ThreadSanitizer: unexpected memory mapping 0x####-0x#### it means that the Thread Sanitizer is active.


EDIT:
To disable it you need to make an unsafe release (Fast or Small).
To disable set b.addExecutable(.{ .sanitize_thread = false, });
or add the -fno-sanitize-thread flag.


See if ASLR is the problem (Note the simplicity of the program that produces the error): FATAL: ThreadSanitizer: unexpected memory mapping when running on Linux Kernels 6.6+

Not quite - the options to control thread sanitizer are:

  -fsanitize-thread         Enable Thread Sanitizer
  -fno-sanitize-thread      Disable Thread Sanitizer

The default is OFF. Optimization mode has nothing to do with it.

2 Likes

Hey,

Yes, indeed I had turned the TSAN on to see if it could help me with some data race I had going on.

Good suggestion to check if it’s a wider (non Zig specific issue) which it seems to be. I did compile with GCC that same hello world example in C and got the same error when trying to run.

I got the thread sanitizer working properly by adjusting the ASLR options as per the referenced post suggestion and it worked (for both the toy program and my small project).

Important things to note here are:

  1. that my issue was happening for linux platform;
  2. that I had to use different values for mmap_rnd_bits the hello world and my small project.

Thanks for the help. I will tag your suggestion as the solution.

2 Likes