Message ID | AM0PR03MB4882B0699CF9DFC4A63861EB82D99@AM0PR03MB4882.eurprd03.prod.outlook.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA8E7385734C for <patchwork@sourceware.org>; Thu, 26 May 2022 14:19:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140131.outbound.protection.outlook.com [40.107.14.131]) by sourceware.org (Postfix) with ESMTPS id AF50D3857C4A for <gcc-patches@gcc.gnu.org>; Thu, 26 May 2022 14:18:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF50D3857C4A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=Syrmia.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Syrmia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOadc5zWw1qEdlMNB7o0R1PA8d3dCNp4kD9oRTq2aemx9FvibhMzI57/AocEegURW7mQXOfP35g77+SRg94SFUyC2sz/1pxH6iYDvFuoxaD2lwUvEpgx/LZ0GSNytuVSUykH4O32Me5CRbrs0oKkr9QZp9IxHfn3lA0zV93gGdBkiI0xUaKeLDev30uuRFs6RinnjcgmpaC2CCp1RKFTr/IRiPfWVKKpDfCaOPUctFF9eIqcdoiTP0pglLpGezbC0dcP5ah5PK22h1OkUOxf3UcUGANajD+kU68VqOxQ7k82VfsX3rTrX5vW3NT9zMI6VhNJUhfwdNnHhx3kkjuTAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lwCdqBbUd89J7bnth9xOPALYXgj+YmjvKnr4YK3073U=; b=lEm+De/pRbR26XA5iDORb8S+Uzm23pWTtvciV6in5twBI5eCeWbO3mLHfm5/k50y9KwCB9PAj6J7XEgDbagKpFt9G9uMuKpl9N5LhE/ALz5o91QadDVgMX0xV2xesAOxj+ulAauBNzJZl0Ph44Or2fAioe3YqU8MgIWAoRNaRGrNGf/JzvyjdwvhKiSFPN1lgchw9QND2QCTByVD7b/PtFFyrKQTrnmiM6TECt/bwvTWivWDDqJ+5LX9Xwb0ADA/RYsZLR95raQnXYCADeeDFPWez8vuBRXZ1cvbhUfRM5SNXYVgKjl0cbiJ4ZoIqah1retV6D7fBMBBj+4heFU5kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lwCdqBbUd89J7bnth9xOPALYXgj+YmjvKnr4YK3073U=; b=B48SkqqH8y3bhlTWnAvA2pgy4DGOigQIKUINulkpIPjg1rVEpW/hbYifW5RP+LnqUyf1uTYMkCHRh+DFl2lddvwiczGsYq06hjHmxpLiJ4Y8mpGPPQoWFhjn25ov+uCo35H4pcgBODqOmPs6U1VIiVqRpNBNaSHxZbzSmfxB2S8= Received: from AM0PR03MB4882.eurprd03.prod.outlook.com (2603:10a6:208:fb::17) by VI1PR03MB4079.eurprd03.prod.outlook.com (2603:10a6:803:76::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Thu, 26 May 2022 14:18:49 +0000 Received: from AM0PR03MB4882.eurprd03.prod.outlook.com ([fe80::b5d4:70dc:8a0:6d02]) by AM0PR03MB4882.eurprd03.prod.outlook.com ([fe80::b5d4:70dc:8a0:6d02%4]) with mapi id 15.20.5293.013; Thu, 26 May 2022 14:18:49 +0000 From: Dimitrije Milosevic <Dimitrije.Milosevic@Syrmia.com> To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org> Subject: [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and LSAN Thread-Topic: [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and LSAN Thread-Index: AQHYcQpr7Y8+Hv+/20ugpWhdXMb6nQ== Date: Thu, 26 May 2022 14:18:48 +0000 Message-ID: <AM0PR03MB4882B0699CF9DFC4A63861EB82D99@AM0PR03MB4882.eurprd03.prod.outlook.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 567efbc5-5b6b-5c45-5ae4-23c42f5615b1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=Syrmia.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8c7dcbb2-43ec-4bd8-00bb-08da3f22a703 x-ms-traffictypediagnostic: VI1PR03MB4079:EE_ x-microsoft-antispam-prvs: <VI1PR03MB4079A36EFCBB1A92F81FE7B682D99@VI1PR03MB4079.eurprd03.prod.outlook.com> x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: q34Eh87AGR61Nj0sJVUj5vbF+RvotOh56YOaAvq3xiCJh+gG2tB8hBiWY14Gerf/0KnsF2WyiLbcwx2bSJTyKOna2Tiyv2dEvvN0erO2MsoRLPlEmuYVlBo0l/3aE7F3Vx8x1tZ0IyWDxgV68ZNr11W+cViWNMtQv4C6Lq6RpEeqaV/ts1WJeGRtU19a9eDzE4+Qh+tJL/Gl208VQArBhSupbcmLRJSTZZm51uIEvMf99zz9P0uvVgYHxdku9UTFPLwMPwkvQtzPas5HO6ScZD7KQJmUftZpNjC1vftoGCZMSIuqIO1DvXfjeca+PCU/YOYSsUbuqZNszAe0cG+QTyAjzSrsMyWXcVDGCyGCLtXtuDUocXxoOdI2KWhWc0L3AFNMnkQyA6UY08fHAUIVKkv49D5zrv0d/KbWTMCbwAR6K+1g/G2H8CsHztIyxeMVEBkxBDAUX3gwOXw6bmXOPz6xIQvQK5945rYSb4YogjbIzLGn+UAHezBWAiLpEpoA7GSdGybaLMO6Yaq+w8yvFv3ejdYyCrv8kTyn/wwfaepWA3NJrjKRyEFZ2hBFe4a+XsCxCcAkjAZGma3vitGdmBpv64P3Eaus+2gblLufiymiz+6GoAz6dGtpAlKpGmikNSW9fc1J3qf7/xKWefj1WU6zxXpmMd6BArutAfx6W9W5WgLpxGxpgpmwBVEe3Pbrctc5fPice/1rcmUvB6TFuw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR03MB4882.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(346002)(39840400004)(376002)(396003)(366004)(136003)(107886003)(41300700001)(7696005)(5660300002)(2906002)(52536014)(122000001)(186003)(55016003)(9686003)(6506007)(26005)(8936002)(38070700005)(83380400001)(33656002)(508600001)(38100700002)(71200400001)(66446008)(76116006)(91956017)(4326008)(66556008)(64756008)(86362001)(66476007)(66946007)(6916009)(316002)(19627405001)(8676002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?shH6UbDqU0ZlGvVcbH/ZU55?= =?iso-8859-1?q?kd1KKq9PsRg7cYd50gir9tKPBSc7zm3QhsFsIdQwwlZQiV7NBatvSpmfS328?= =?iso-8859-1?q?xJxBvp27xZe3bmkawCwi3r97qOb64ATvy82I3KKR1ovEv29plid3wBLb8lVK?= =?iso-8859-1?q?pBw3z2EBPkUnScOCfiJZVfBzgUs8PPWed5OxaoJwN+rZAjfBN/BXqayf398W?= =?iso-8859-1?q?WAv9ZDTgKluIi2KuFLbShbJvqd7dLY44QdKhGJEJe1rP4D91z/iK4vt1hGNO?= =?iso-8859-1?q?VAmO3dTlu811qqrvox9UiYn/yhWdQmjTejfwU/Iu4yypaVvkMpZQXL0zYz4M?= =?iso-8859-1?q?rmMCaFfYx1Ew6VlZmWvzZThIKh3uxAifRaJRdohYs5x7UOcWR+jKm3iIwoWL?= =?iso-8859-1?q?Xm8/+tjbphXRpLAB4+Yt6WJZ20+5GTSZiCEPnaPSHAPnXAiRvkp9Ow86sKlg?= =?iso-8859-1?q?oL3Jp7SNCLWIKhOgsl1VsUq9rn1BTBYn9p3MScckt+93jmSE7Hnmg84FE1s+?= =?iso-8859-1?q?s7J65IGIZz7lUdGTodSxrnntwStANKI6WwX6Jb4UILmPX7NMxr5/tztS0jId?= =?iso-8859-1?q?Z783h4VMFhwOZmBvngKvKkwecTjjOFxTemKNhSIk4IEcRDAvcsBaPrhBlcEV?= =?iso-8859-1?q?qpkr9uyZ35EI+iEkU7JIgZtpvUAXrAuOfB45A5lkVs0LuKnl3RA/EBIPfLab?= =?iso-8859-1?q?WrwDfzreaieQrKgNh5Jpajg0qMXKKqKkCF+driQDty1DEP0GztMI42646d+D?= =?iso-8859-1?q?USMb+JF04+QkLyyFKBITne1AMkqY7xWUXJoYlPCY742KbZMTi9UjXRAal57Z?= =?iso-8859-1?q?PAKVllP0/CJf8RmzPHdqfaeVNawQgF/a9mnH85tGdG1HQfb9JCjI9H54h0vU?= =?iso-8859-1?q?244D3ICxUXVVl+KY3CyuN8hdRTbfCdRo75QKaNeE90CIODwVtLznKRR2mO5q?= =?iso-8859-1?q?iCYlzFfRyIO15uvRgpFtGZKIXvB3A2/wlbjBwluLc9Xi6tNLmejyS31/mTn9?= =?iso-8859-1?q?AlgM8otPCiL6JZlTkzW7kIcDtJ0nTX3GlOpRjhxAhG70CqLpMZtqyYqEyP0E?= =?iso-8859-1?q?tm4xDmi6byL3ZUZ4Evt0abACP5nt7T4gZBB6Q+R/Q4+NaGQhCgr/O/WczeQj?= =?iso-8859-1?q?8wF/JQqEI6FUXPEgEhHv4OSLZmv1qebGJXMu8gHwIYy03zk+vAmpFVxWI2Uj?= =?iso-8859-1?q?nHIYLo2c5S+hWmBZRjY3+k1/Ts5wiwQIQutbLma63LdyTXaxlO73rh7vzKhV?= =?iso-8859-1?q?s9k0IdQ9m5AG3IFaTMWCUgjwwjkzAtQ3ConnA5RY9DPyUQD3acftNSoCXPS7?= =?iso-8859-1?q?5h7uum7xvT+CmLjYaUZ0DXO5LZ84ZzzNfz+c8NqKHyU3aXI3GC893yE1z0BP?= =?iso-8859-1?q?zk9uy6vUAkZRwOQNtjo6oh6B3RImWriLYwQ3fJ6/Oc0hvebhDfopH//nU/G7?= =?iso-8859-1?q?rREivXvu+V3GZUytCKnbnfuYqgndfwTEamy0eACDeWQcbi/vtCiexfxN1T5s?= =?iso-8859-1?q?qt0QAP27tSMgXTjuEhO9h049f0c55GsW070V/FbvjtItggcyfIM3bOX1ylNT?= =?iso-8859-1?q?UJwyB6OBLQGATOnZ9IauJrCcmztCGpZ0LRzslatBGeZtnMEqLwapiD2YEEyt?= =?iso-8859-1?q?yKIcBEmIVweRQTogi79pc0HZSkfp9XgdP6rGcypuCSLJJwBjE+2hAb6paMfY?= =?iso-8859-1?q?gB5gGlTPbkreSMktZWR84NhmQPI2Rv/D+0tQaBIfKnqFBZXoS68/FGfYS4hW?= =?iso-8859-1?q?Bg+wmqwKcqfVAw5T5ZYv1q6EV9ArA2e37oct1LukQJkbcTTYDmmcnk8qhDrZ?= =?iso-8859-1?q?KpmpVaXc=3D?= MIME-Version: 1.0 X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM0PR03MB4882.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c7dcbb2-43ec-4bd8-00bb-08da3f22a703 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 May 2022 14:18:48.9463 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: jVzdYi59rRRfTpGkhpbwmWE8WLMyW6mWVcZcbzAJSmNtu/0EKRYWeNn+3fZB73qjbe1E9qCz4lCMVFZXNQ4xrA+VrNxTtnSbFVCVtGPX4zo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB4079 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: Djordje Todorovic <Djordje.Todorovic@syrmia.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
Mips: Enable asynchronous unwind tables with both ASAN and LSAN
|
|
Commit Message
Dimitrije Milošević
May 26, 2022, 2:18 p.m. UTC
Enable asynchronous unwind tables with both ASAN and TSAN for correct back-trace. LLVM currently enables asynchronous unwind tables for: ASAN, HWSAN, TSAN, MSAN, and DFSAN. HWSAN is currently available only on AArch64, while MSAN and DFSAN are not available at all. Also, LLVM checks is '-ffreestanding' is not passed in. '-ffreestanding' is only available in C-family frontends, hence why no such check is included. TODO: Not sure if any tests should be added. gcc/ChangeLog: * config/mips/mips.cc (mips_option_override): Enable asyncronous unwind tables with both ASAN and TSAN. --- gcc/config/mips/mips.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) ---
Comments
Hi Xi, thanks for pointing this out. I'd definitely say that the https://clang.llvm.org/docs/ThreadSanitizer.html documentation is outdated. According to https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual#supported-platforms TSAN is supported on Mips64. Furthermore, there are actual code segments (in compiler-rt/lib/tsan/rtl/tsan_platforms.h, for example) related to Mips64. I didn't add the 64-bit target check, however. Here is the updated version of the patch. gcc/ChangeLog: * config/mips/mips.cc (mips_option_override): Enable asyncronous unwind tables with both ASAN and TSAN. --- gcc/config/mips/mips.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index e64928f4113..2dce4007678 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20115,10 +20115,16 @@ mips_option_override (void) target_flags |= MASK_64BIT; } - /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in - order for tracebacks to be complete but not if any - -fasynchronous-unwind-table were already specified. */ - if (flag_sanitize & SANITIZE_USER_ADDRESS + /* -fsanitize=address, and -fsanitize=thread need to turn + on -fasynchronous-unwind-tables in order for tracebacks + to be complete but not if any -fasynchronous-unwind-table + were already specified. */ + /* FIXME: HWSAN is currently only available on AArch64, + but could also utilize -fasynchronous-unwind-tables. + FIXME: We would also like to check if -ffreestanding is passed in. + However, it is only available in C-ish frontends. */ + if (((flag_sanitize & SANITIZE_USER_ADDRESS) + || (TARGET_64BIT && (flag_sanitize & SANITIZE_THREAD))) && !global_options_set.x_flag_asynchronous_unwind_tables) flag_asynchronous_unwind_tables = 1; ---
On Mon, 2022-05-30 at 07:10 +0000, Dimitrije Milosevic wrote: > Hi Xi, thanks for pointing this out. I'd definitely say that the > https://clang.llvm.org/docs/ThreadSanitizer.html documentation is > outdated. According > tohttps://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual#s > upported-platforms TSAN is supported on Mips64. Furthermore, there are > actual code segments (in compiler-rt/lib/tsan/rtl/tsan_platforms.h, > for example) related to Mips64. > I didn't add the 64-bit target check, however. Here is the updated > version of the patch. Well, so should we add TSAN_SUPPORTED=yes for MIPS64 in libsanitizer/configure.tgt first? I'll try this on my MIPS64 in a few days.
Definitely, a patch is on the way.
> Well, so should we add TSAN_SUPPORTED=yes for MIPS64 in > libsanitizer/configure.tgt first? I'll try this on my MIPS64 in a few > days. Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables enabled, but I got some strange test failures for tls_race.c: FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test Output was: ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, 0xffec35f784) (tid=748216) #0 __tsan::CheckUnwind() ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 (libtsan.so.2+0xa30ec) #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination.cpp:86 (libtsan.so.2+0xeb8cc) #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, unsigned long) ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 (libtsan.so.2+0xa0cac) #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, unsigned long long, __sanitizer::ThreadType) ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 (libtsan.so.2+0xc0e88) #4 __tsan_thread_start_func ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 (libtsan.so.2+0x3e5dc) #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 (libc.so.6+0xc75f4) I've tried to diagnose the root cause but failed.
On Saturday, June 11, 2022 2:03 PM, Xi wrote: > Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables enabled, > but I got some strange test failures for tls_race.c: > > FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test > Output was: > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, 0xffec35f784) (tid=748216) > #0 __tsan::CheckUnwind() ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 (libtsan.so.2+0xa30ec) > #1 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination.cpp:86 (libtsan.so.2+0xeb8cc) > #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, unsigned long) ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 (libtsan.so.2+0xa0cac) > #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, unsigned long long, __sanitizer::ThreadType) ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 (libtsan.so.2+0xc0e88) > #4 __tsan_thread_start_func ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 (libtsan.so.2+0x3e5dc) > #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 (libc.so.6+0xc75f4) > > I've tried to diagnose the root cause but failed. Hi Xi, thanks for looking into this. I've tried running the testsuite on a cross-toolchain (as I do not currently have access to a physical machine) for a MIPS64R6 and the test passes successfully. Could you please verify that the test fails solely based on this change? Kind regards, Dimitrije
On Mon, 2022-07-04 at 14:28 +0000, Dimitrije Milosevic wrote: > On Saturday, June 11, 2022 2:03 PM, Xi wrote: > > Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables > > enabled, > > but I got some strange test failures for tls_race.c: > > > > FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test > > Output was: > > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 > > "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, > > 0xffec35f784) (tid=748216) > > #0 __tsan::CheckUnwind() > > ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 > > (libtsan.so.2+0xa30ec) > > #1 __sanitizer::CheckFailed(char const*, int, char const*, > > unsigned long long, unsigned long long) > > ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination. > > cpp:86 (libtsan.so.2+0xeb8cc) > > #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, > > unsigned long) > > ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 > > (libtsan.so.2+0xa0cac) > > #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, > > unsigned long long, __sanitizer::ThreadType) > > ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 > > (libtsan.so.2+0xc0e88) > > #4 __tsan_thread_start_func > > ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 > > (libtsan.so.2+0x3e5dc) > > #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 > > (libc.so.6+0xc75f4) > > > > I've tried to diagnose the root cause but failed. > > Hi Xi, thanks for looking into this. I've tried running the testsuite > on a cross-toolchain (as I do not currently have access to a physical > machine) > for a MIPS64R6 and the test passes successfully. Could you please > verify that the test fails solely based on this change? I guess you mean you are running MIPS64R6 target code with qemu? I'm not 100% sure because maybe something is wrong in my system. I'm now retrying on gcc230.fsffrance.org (an EdgeRouter 4 in Cfarm) but building GCC on it is really slow. The changes I've tested: diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 5eb845960e1..a7f0580e9ba 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20115,10 +20115,11 @@ mips_option_override (void) target_flags |= MASK_64BIT; } - /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in - order for tracebacks to be complete but not if any - -fasynchronous-unwind-table were already specified. */ - if (flag_sanitize & SANITIZE_USER_ADDRESS + /* For -fsanitize=address or -fsanitize=thread, it's needed to turn + on -fasynchronous-unwind-tables in order for tracebacks + to be complete but not if any -fasynchronous-unwind-table + were already specified. */ + if (flag_sanitize & (SANITIZE_USER_ADDRESS | SANITIZE_THREAD) && !global_options_set.x_flag_asynchronous_unwind_tables) flag_asynchronous_unwind_tables = 1; diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt index fb89df4935c..52546bbe4e3 100644 --- a/libsanitizer/configure.tgt +++ b/libsanitizer/configure.tgt @@ -55,6 +55,9 @@ case "${target}" in arm*-*-linux*) ;; mips*-*-linux*) + if test x$ac_cv_sizeof_void_p = x8; then + TSAN_SUPPORTED=yes + fi ;; aarch64*-*-linux*) if test x$ac_cv_sizeof_void_p = x8; then
On Mon, Jul 4, 2022 at 6:54 PM Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On Mon, 2022-07-04 at 14:28 +0000, Dimitrije Milosevic wrote: > > On Saturday, June 11, 2022 2:03 PM, Xi wrote: > > > Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables > > > enabled, > > > but I got some strange test failures for tls_race.c: > > > > > > FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test > > > Output was: > > > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 > > > "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, > > > 0xffec35f784) (tid=748216) > > > #0 __tsan::CheckUnwind() > > > ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 > > > (libtsan.so.2+0xa30ec) > > > #1 __sanitizer::CheckFailed(char const*, int, char const*, > > > unsigned long long, unsigned long long) > > > ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination. > > > cpp:86 (libtsan.so.2+0xeb8cc) > > > #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, > > > unsigned long) > > > ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 > > > (libtsan.so.2+0xa0cac) > > > #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, > > > unsigned long long, __sanitizer::ThreadType) > > > ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 > > > (libtsan.so.2+0xc0e88) > > > #4 __tsan_thread_start_func > > > ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 > > > (libtsan.so.2+0x3e5dc) > > > #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 > > > (libc.so.6+0xc75f4) > > > > > > I've tried to diagnose the root cause but failed. > > > > Hi Xi, thanks for looking into this. I've tried running the testsuite > > on a cross-toolchain (as I do not currently have access to a physical > > machine) > > for a MIPS64R6 and the test passes successfully. Could you please > > verify that the test fails solely based on this change? > > I guess you mean you are running MIPS64R6 target code with qemu? I'm > not 100% sure because maybe something is wrong in my system. I'm now > retrying on gcc230.fsffrance.org (an EdgeRouter 4 in Cfarm) but building > GCC on it is really slow. > > The changes I've tested: > > diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc > index 5eb845960e1..a7f0580e9ba 100644 > --- a/gcc/config/mips/mips.cc > +++ b/gcc/config/mips/mips.cc > @@ -20115,10 +20115,11 @@ mips_option_override (void) > target_flags |= MASK_64BIT; > } > > - /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in > - order for tracebacks to be complete but not if any > - -fasynchronous-unwind-table were already specified. */ > - if (flag_sanitize & SANITIZE_USER_ADDRESS > + /* For -fsanitize=address or -fsanitize=thread, it's needed to turn > + on -fasynchronous-unwind-tables in order for tracebacks > + to be complete but not if any -fasynchronous-unwind-table > + were already specified. */ > + if (flag_sanitize & (SANITIZE_USER_ADDRESS | SANITIZE_THREAD) > && !global_options_set.x_flag_asynchronous_unwind_tables) > flag_asynchronous_unwind_tables = 1; > > diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt > index fb89df4935c..52546bbe4e3 100644 > --- a/libsanitizer/configure.tgt > +++ b/libsanitizer/configure.tgt > @@ -55,6 +55,9 @@ case "${target}" in > arm*-*-linux*) > ;; > mips*-*-linux*) > + if test x$ac_cv_sizeof_void_p = x8; then > + TSAN_SUPPORTED=yes > + fi > ;; > aarch64*-*-linux*) > if test x$ac_cv_sizeof_void_p = x8; then > -- > Xi Ruoyao <xry111@xry111.site> > School of Aerospace Science and Technology, Xidian University Drive-by comment. Clang considers that asan/msan/tsan/dataflow/etc enables -fasynchronous-unwind-tables by default so I assume this GCC change is fine. With https://reviews.llvm.org/D102046 ("[sanitizer] Fall back to fast unwinder"), compiler-rt may fall back to the frame pointer based unwinder. There is not strong need to have the default -fasynchronous-unwind-tables or -funwind-tables behavior. However, most targets still default to omit frame pointer, so it's a bit unfortunately that we need to enable unwind tables to get good diagnostics.
On Mon, 2022-07-04 at 21:21 -0700, Fangrui Song wrote: > Clang considers that asan/msan/tsan/dataflow/etc enables > -fasynchronous-unwind-tables by default so I assume this GCC change is > fine. I agree it's fine, but the problem is TSAN is currently "unsupported" within GCC (i. e. when you build gcc libtsan is not built). So it does not make any benefit to commit this change before making TSAN supported on GCC side. Dimitrije told me TSAN should be supported on 64-bit MIPS, but I can't make it work fine with GCC. I'll need some time to debug... > With https://reviews.llvm.org/D102046 ("[sanitizer] Fall back to fast > unwinder"), compiler-rt may fall back to the frame pointer based > unwinder. There is not strong need to have the default > -fasynchronous-unwind-tables or -funwind-tables behavior. > However, most targets still default to omit frame pointer, so it's a > bit unfortunately that we need to enable unwind tables to get good > diagnostics.
Hi Xi. Correct, I am using a simulator. Here are my changes: diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt index fb89df4935c..6855a6ca9e7 100644 --- a/libsanitizer/configure.tgt +++ b/libsanitizer/configure.tgt @@ -55,6 +55,10 @@ case "${target}" in arm*-*-linux*) ;; mips*-*-linux*) + if test x$ac_cv_sizeof_void_p = x8; then + TSAN_SUPPORTED=yes + TSAN_TARGET_DEPENDENT_OBJECTS=tsan_rtl_mips64.lo + fi ;; aarch64*-*-linux*) if test x$ac_cv_sizeof_void_p = x8; then Nit: Updated the code in gcc/config/mips/mips.cc a little bit, but no functional change compared to your version. diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 8a55d2fb8f7..4ccc9e75482 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20118,13 +20118,12 @@ mips_option_override (void) /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in order for tracebacks to be complete but not if any -fasynchronous-unwind-table were already specified. */ - /* FIXME: TSAN could also utilize -fasynchronous-unwind-tables, but - should be first enabled for MIPS64. - FIXME: HWSAN could also utilize -fasynchronous-unwind-tables, but, + /* FIXME: HWSAN could also utilize -fasynchronous-unwind-tables, but, currently, it is only available on AArch64. FIXME: We would also like to check if -ffreestanding is passed in. However, it is only available in C-ish frontends. */ - if ((flag_sanitize & SANITIZE_USER_ADDRESS) + if (((flag_sanitize & SANITIZE_USER_ADDRESS) + || (TARGET_64BIT && (flag_sanitize & SANITIZE_THREAD))) && !global_options_set.x_flag_asynchronous_unwind_tables) flag_asynchronous_unwind_tables = 1; From: Xi Ruoyao <xry111@xry111.site> Sent: Tuesday, July 5, 2022 3:54 AM To: Dimitrije Milosevic <Dimitrije.Milosevic@Syrmia.com>; gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org> Cc: Djordje Todorovic <Djordje.Todorovic@syrmia.com> Subject: Re: [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and TSAN On Mon, 2022-07-04 at 14:28 +0000, Dimitrije Milosevic wrote: > On Saturday, June 11, 2022 2:03 PM, Xi wrote: > > Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables > > enabled, > > but I got some strange test failures for tls_race.c: > > > > FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test > > Output was: > > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 > > "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, > > 0xffec35f784) (tid=748216) > > #0 __tsan::CheckUnwind() > > ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 > > (libtsan.so.2+0xa30ec) > > #1 __sanitizer::CheckFailed(char const*, int, char const*, > > unsigned long long, unsigned long long) > > ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination. > > cpp:86 (libtsan.so.2+0xeb8cc) > > #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, > > unsigned long) > > ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 > > (libtsan.so.2+0xa0cac) > > #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, > > unsigned long long, __sanitizer::ThreadType) > > ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 > > (libtsan.so.2+0xc0e88) > > #4 __tsan_thread_start_func > > ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 > > (libtsan.so.2+0x3e5dc) > > #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 > > (libc.so.6+0xc75f4) > > > > I've tried to diagnose the root cause but failed. > > Hi Xi, thanks for looking into this. I've tried running the testsuite > on a cross-toolchain (as I do not currently have access to a physical > machine) > for a MIPS64R6 and the test passes successfully. Could you please > verify that the test fails solely based on this change? I guess you mean you are running MIPS64R6 target code with qemu? I'm not 100% sure because maybe something is wrong in my system. I'm now retrying on gcc230.fsffrance.org (an EdgeRouter 4 in Cfarm) but building GCC on it is really slow. The changes I've tested: diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 5eb845960e1..a7f0580e9ba 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20115,10 +20115,11 @@ mips_option_override (void) target_flags |= MASK_64BIT; } - /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in - order for tracebacks to be complete but not if any - -fasynchronous-unwind-table were already specified. */ - if (flag_sanitize & SANITIZE_USER_ADDRESS + /* For -fsanitize=address or -fsanitize=thread, it's needed to turn + on -fasynchronous-unwind-tables in order for tracebacks + to be complete but not if any -fasynchronous-unwind-table + were already specified. */ + if (flag_sanitize & (SANITIZE_USER_ADDRESS | SANITIZE_THREAD) && !global_options_set.x_flag_asynchronous_unwind_tables) flag_asynchronous_unwind_tables = 1; diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt index fb89df4935c..52546bbe4e3 100644 --- a/libsanitizer/configure.tgt +++ b/libsanitizer/configure.tgt @@ -55,6 +55,9 @@ case "${target}" in arm*-*-linux*) ;; mips*-*-linux*) + if test x$ac_cv_sizeof_void_p = x8; then + TSAN_SUPPORTED=yes + fi ;; aarch64*-*-linux*) if test x$ac_cv_sizeof_void_p = x8; then
On Tue, 2022-07-05 at 12:51 +0800, Xi Ruoyao via Gcc-patches wrote: > I agree it's fine, but the problem is TSAN is currently "unsupported" > within GCC (i. e. when you build gcc libtsan is not built). So it > does > not make any benefit to commit this change before making TSAN > supported > on GCC side. > > Dimitrije told me TSAN should be supported on 64-bit MIPS, but I can't > make it work fine with GCC. I'll need some time to debug... Hi Fangrui, On my system dlpi_tls_modid for libtsan.so.2 is 2, instead of 1. GetStaticTlsBoundary seems assuming the dlpi_tls_modid for libtsan.so to be 1, and returning wrong values if the assumption is broken. Is it unsafe to make such an assumption? Or, am I being haunted by a glibc bug?
On Mon, 2022-07-04 at 21:21 -0700, Fangrui Song wrote: > > > > > > > FAIL: c-c++-common/tsan/tls_race.c -O0 output pattern test > > > > Output was: > > > > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452 > > > > "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0, > > > > 0xffec35f784) (tid=748216) > > > > #0 __tsan::CheckUnwind() > > > > ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627 > > > > (libtsan.so.2+0xa30ec) > > > > #1 __sanitizer::CheckFailed(char const*, int, char const*, > > > > unsigned long long, unsigned long long) > > > > ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination. > > > > cpp:86 (libtsan.so.2+0xeb8cc) > > > > #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long, > > > > unsigned long) > > > > ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452 > > > > (libtsan.so.2+0xa0cac) > > > > #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int, > > > > unsigned long long, __sanitizer::ThreadType) > > > > ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197 > > > > (libtsan.so.2+0xc0e88) > > > > #4 __tsan_thread_start_func > > > > ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009 > > > > (libtsan.so.2+0x3e5dc) > > > > #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442 > > > > (libc.so.6+0xc75f4) > > > > > > > > I've tried to diagnose the root cause but failed. > > > > > > Hi Xi, thanks for looking into this. I've tried running the testsuite > > > on a cross-toolchain (as I do not currently have access to a physical > > > machine) > > > for a MIPS64R6 and the test passes successfully. Could you please > > > verify that the test fails solely based on this change? I've got a clue about why this happens. See https://reviews.llvm.org/D129112. It depends on how the dynamic linker arranges TLS blocks so different version of Glibc may produce different results.
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index e64928f4113..ea2a038216c 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20115,10 +20115,15 @@ mips_option_override (void) target_flags |= MASK_64BIT; } - /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in - order for tracebacks to be complete but not if any - -fasynchronous-unwind-table were already specified. */ - if (flag_sanitize & SANITIZE_USER_ADDRESS + /* -fsanitize=address, and -fsanitize=thread need to turn + on -fasynchronous-unwind-tables in order for tracebacks + to be complete but not if any -fasynchronous-unwind-table + were already specified. */ + /* FIXME: HWSAN is currently only available on AArch64, + but could also utilize -fasynchronous-unwind-tables. + FIXME: We would also like to check if -ffreestanding is passed in. + However, it is only available in C-ish frontends. */ + if (flag_sanitize & (SANITIZE_USER_ADDRESS | SANITIZE_THREAD) && !global_options_set.x_flag_asynchronous_unwind_tables) flag_asynchronous_unwind_tables = 1;