nim-lang / threading

New atomics, thread primitives, atomic refcounting for --gc:arc/orc.
MIT License
73 stars 12 forks source link

Threading/Channels can not be used with address or thread sanitizer on clang and gcc #65

Closed PhilippMDoerner closed 5 months ago

PhilippMDoerner commented 5 months ago

I'm not sure when this was introduced but apparently it has become impossible to compile with any sanitizer. Which I'm not sure how that hasn't been caught.

Nim version

Nim Compiler Version 2.0.4 [Linux: amd64] Compiled at 2024-03-28 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d31844c6bd9af4322efe55e24fefea544c active boot switches: -d:release

Example

Just importing the file is enough:

# somefile.nim
import threading/channels  

Thread Sanitizer Error

Compiling with thread-sanitizer via this command:

nim c --cc:clang --passc:"-fsanitize=thread -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" --passl:"-fsanitize=thread -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" somefile.nim

You will get this error:

/home/isofruit/.nimble/pkgs2/threading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c/threading/channels.nim:199:39: error: expected external declaration
  199 | __attribute__((no_sanitize("thread")))
      |                                       ^
1 error generated.
Error: execution of an external compiler program 'clang -c -w -ferror-limit=3 -pthread -fsanitize=thread -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g -O3   -I/home/isofruit/.choosenim/toolchains/nim-2.0.4/lib -I/home/isofruit/dev/playground/src -o /home/isofruit/.cache/nim/playground_r/@m..@s..@s..@s.nimble@spkgs2@sthreading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c@sthreading@schannels.nim.c.o /home/isofruit/.cache/nim/playground_r/@m..@s..@s..@s.nimble@spkgs2@sthreading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c@sthreading@schannels.nim.c' failed with exit code: 1

Address Sanitizer Error

Compiling with address sanitizer via this command:

nim c --cc:clang --passc:"-fsanitize=address -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" --passl:"-fsanitize=address -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" somefile.nim

You will get this error:

/home/isofruit/.cache/nim/playground_d/@m..@s..@s..@s.nimble@spkgs2@sthreading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c@sthreading@schannels.nim.c:21:39: error: expected external declaration
   21 | __attribute__((no_sanitize("thread")))
      |                                       ^
1 error generated.
Error: execution of an external compiler program 'clang -c -w -ferror-limit=3 -pthread -fsanitize=address -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer   -I/home/isofruit/.choosenim/toolchains/nim-2.0.4/lib -I/home/isofruit/dev/playground/src -o /home/isofruit/.cache/nim/playground_d/@m..@s..@s..@s.nimble@spkgs2@sthreading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c@sthreading@schannels.nim.c.o /home/isofruit/.cache/nim/playground_d/@m..@s..@s..@s.nimble@spkgs2@sthreading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c@sthreading@schannels.nim.c' failed with exit code: 1
PhilippMDoerner commented 5 months ago

It turns out this was an issue specifically with the version of threading called threading-0.2.0-3cd4360369b8abf1c53ddfd49ea8aef70208658c.

The version that you get as of today (09.05.2024), which is 9bf8bb66d31ed3b7f013ec683a58f0f2e387896b, does not have this issue.

It is inconvenient that these changes didn't lead to version changes in the lib itself, even if just patch changes, but so is life.