Bug 14672 - ThreadSanitizer (-fsanitize=thread) segfault before reaching main()
Summary: ThreadSanitizer (-fsanitize=thread) segfault before reaching main()
Status: RESOLVED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: devtools / tool chain (show other bugs)
Version: 3.4.1
Hardware: x86 x86_64
: Medium+ normal
Target Milestone: 4.0 M4
Assignee: Randy MacLeod
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2021-12-30 16:35 UTC by Tony Battersby
Modified: 2022-04-12 00:33 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments
Trivial test program that segfaults before reaching main (1.47 KB, application/gzip)
2021-12-30 16:35 UTC, Tony Battersby
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tony Battersby 2021-12-30 16:35:25 UTC
Created attachment 4847 [details]
Trivial test program that segfaults before reaching main

Since Yocto 3.4, any C program that is compiled with -fsanitize=thread segfaults in libtsan before it even gets to main().  Even the trivial program:

int main(int argc, char **argv){return 0;}

Kernel dmesg output:
tsan-test[10113]: segfault at 600000000008 ip 00007f386a5bbb7f sp 00007fffa57e2900 error 6 in libtsan.so.0.0.0[7f386a543000+b4000]
Code: f7 c2 ff 1f 00 00 0f 84 7f 00 00 00 48 c1 e8 32 25 ff 1f 00 00 48 69 c0 00 00 13 01 48 8d 14 d0 48 b8 00 00 00 00 00 60 00 00 <48> c7 04 02 00 00 00 00 8b 43 1c 85 c0 75 3d 8b 93 70 02 00 00 48

I have attached a recipe with the test program to reproduce the problem.

ThreadSanitizer worked in Yocto 3.3.3 with gcc 10.2.  It broke when we upgraded to Yocto 3.4.1 with gcc 11.2.  I also tested poky master and master-next on 2021-12-30; they also fail.

Note that AddressSanitizer and UndefinedBehaviorSanitizer seem to be working OK so far in Yocto 3.4.1.  It is just ThreadSanitizer that is not working.
Comment 1 Randy MacLeod 2022-01-06 15:34:54 UTC
We should add a test case.
Comment 2 Sundeep KOKKONDA 2022-03-10 09:04:36 UTC
The issue is in the 'GetAltStackSize' function from below file.
..\libsanitizer\sanitizer_common\sanitizer_posix_libcdep.cpp

This function calls recursively and causing the SIGSEGV fault. The fix for this issue is available in below patch.
https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp;h=ddf6844bed13efeb3f7f87aee664b6b96682a8f6;hp=d1d8e509c4dbaa2cb1a0d020959765c20fa7a895;hb=90e46074e6b3561ae7d8ebd205127f286cc0c6b6;hpb=8bf5b49ebd2176b8c535147377381dd07fbdd643

This change is not yet included in the current released version of GCC. Updating to next GCC version (GCC-11.3, yet to be released) will fix the issue.
Comment 3 Sundeep KOKKONDA 2022-03-11 09:15:39 UTC
The next GCC release is not near so the patch is backported and submitted to upstream. Below are the details.
https://lists.openembedded.org/g/openembedded-core/message/163047