From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2016.outbound.protection.outlook.com [40.92.22.16]) by sourceware.org (Postfix) with ESMTPS id D8F82385702E for ; Sun, 4 Apr 2021 07:12:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D8F82385702E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=i@maskray.me ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jeDatTeN2bHjcoqFGRSUCX1Gg8p2JowpMdlhLdaEvfWTCjAT8pOLKxU/H+5r3dKl72ABt0XsqS+Ir0ltfs8x6Y0AeoKx6fSlj2G94ojrTJSqeQAyfZ4x0wmQnpG36kFY8NIy6vCXPk/9+/4J/sUykI+XmBjrRQKZtNSgLXdmeHYPvIw+kdfnTZkX9w2UvznrVxA6r8pCpp2C/3ULGWq/5l6izbkCWoVZTsaIRpx4iCuZ5yuDkJNzHkWamkjBGIkWY+4uRU86HOoflpX9JZ6eT6PYHodk8B6TMqod7DGIYmtXcZGdmZ5msKRse1jbpXG1E/MgUCFJoqOiLeRayU3S6w== 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-SenderADCheck; bh=ViaSw/dBuSr3HjwK+bAfZk37pWAl49Fd/MDNXEUEEm0=; b=VhWFcPkmcIyDG1MZZj5Eh3JJdyRC+OLzpVOWbbJUPZ66gtoDBJWTBqE/nKF8A84m4Wzwvkw6DenkHOYRF7aLAjtZSkSlvlKvSOpeolaD3fqILd4cDUe9SG4hWe9Mwjyh1/cfdDH6ySDcWl2V1cFeLVL578Z37F0WiZVXovbku8Kzd7Vh8LoxGFvx8ypDH4FfB9kOtxQFiU6o5sRJW8eDmDcld/NHHZk8ZCtl7kdOX9lWmt/Ld0Lk3hfW4DqDT58G1n7gThFw5uQUEYHgoaO6GXFzdYMXCXpHYEJRXqB7nnl2wFCqYFWxZgG6sKZY7OuvoZTECuBKNfzS/0EcWZNKQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MW2NAM12FT030.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::4f) by MW2NAM12HT093.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::485) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8; Sun, 4 Apr 2021 07:12:19 +0000 Received: from MWHPR1201MB0110.namprd12.prod.outlook.com (2a01:111:e400:fc65::52) by MW2NAM12FT030.mail.protection.outlook.com (2a01:111:e400:fc65::278) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.8 via Frontend Transport; Sun, 4 Apr 2021 07:12:19 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:898BE861924B70252A0DA3C056180AEF22C101F1C161BDDFB22C7A3DB5F718F5; UpperCasedChecksum:F80B1DD202B575A51EBB6E47D0A18929CC9FE2E26FE55CFE7C3C1D133432CBB8; SizeAsReceived:9163; Count:50 Received: from MWHPR1201MB0110.namprd12.prod.outlook.com ([fe80::908b:cd46:355:b6b3]) by MWHPR1201MB0110.namprd12.prod.outlook.com ([fe80::908b:cd46:355:b6b3%7]) with mapi id 15.20.3999.032; Sun, 4 Apr 2021 07:12:19 +0000 X-Gm-Message-State: AOAM530cFxYA7Upx9jtPsWvFTyrobwIGAgVEJdl8yAeSNx/2G0g+ci0m tNdD6fPf4reI7OKr0zhQHYlP5vT2NTVsl5RLES0= X-Google-Smtp-Source: ABdhPJyrgUALWIVuW5DLJCeV+eykOt6YOnkwLtymBdOJWcNcb9n6dVoulmIcTvv95sn3IGRTrIo5hE9nJrtvyp/jub8= X-Received: by 2002:ac8:5212:: with SMTP id r18mr17337402qtn.290.1617519933931; Sun, 04 Apr 2021 00:05:33 -0700 (PDT) References: <87a6qf3f2w.fsf@mid.deneb.enyo.de> In-Reply-To: <87a6qf3f2w.fsf@mid.deneb.enyo.de> From: Fangrui Song Date: Sun, 4 Apr 2021 00:05:22 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: dlpi_tls_data is incorrect NULL when dlpi_tls_modid>0 To: Florian Weimer Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" X-TMN: [ljLJRFPtZXzHn/uCVyZw/zYyqpfLGorj] X-ClientProxiedBy: MN2PR20CA0007.namprd20.prod.outlook.com (2603:10b6:208:e8::20) To MWHPR1201MB0110.namprd12.prod.outlook.com (2603:10b6:301:56::8) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mail-qt1-f174.google.com (209.85.160.174) by MN2PR20CA0007.namprd20.prod.outlook.com (2603:10b6:208:e8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Sun, 4 Apr 2021 07:12:19 +0000 Received: by mail-qt1-f174.google.com with SMTP id j7so6492226qtx.5 for ; Sun, 04 Apr 2021 00:12:19 -0700 (PDT) X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 214e2bb6-fc9c-4329-4bec-08d8f738fc03 X-MS-TrafficTypeDiagnostic: MW2NAM12HT093: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /eTYeVh5PseevrP5BSf4HI3iCoVdEmtD5t/G/M+CT21sFGGxfM/PgRf5ikze/sxDsstqTiFgcqO7VP7XAtsaWU0ortVLwLC90lHAYkSufnsorxZtH57ycfx2Q0JHDR/Yw2ntSLM/VTd6/7puj2uZs0FYJMlrC9mNS5NHOjjU6amnR3SDKzYYQkhM/2s40FgV8QBN2x2woNr+1C1dZ2CDjfunHbEnGZ/BukpVvh4k7tqksZubF7tVb3E2f26qh4a3/QgohsjaZTYDR1Glz5Kk2vPS5BQUxPqn6Y5GNw8nIq01HlXznRIqQlt+AQviYu21B4CqZoi0lFrYNR272wp8BeJXG+oqV0HC3f8nIUDT0FWqBoSC4Xith1RXENt4zxWlZyX7LbH4/rgw3UrRNylVB8+fSk4UOgDRGo34+g/aprVCse9wxXRReZZkhU9XP37J X-MS-Exchange-AntiSpam-MessageData: efk3tRjqwN+BwlZkj/jVxluR1ue3XiAzMB078TFINtUMr7sGZtf2Dpn8IDWh3o6jItECh3tSe1WgF0XjkDeiPV8xmTsChZC3uRq/rYFaZwc27r5yCwTtD50YK9CO6awm9Sxu4aHGee5XBvCrVg2fcw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 214e2bb6-fc9c-4329-4bec-08d8f738fc03 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2021 07:12:19.3447 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: MW2NAM12FT030.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT093 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_NUMSUBJECT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Apr 2021 07:12:23 -0000 On Sat, Apr 3, 2021 at 2:14 AM Florian Weimer wrote: > > * Fangrui Song: > > > I was trying to clean up llvm-project/compiler-rt sanitizers GetTls > > function https://reviews.llvm.org/D98926 and my change was reverted > > due to an annoying Ubuntu 16.04 glibc 2.23 bug (seem so on both amd64 > > and ppc64le) > > dlpi_tls_data is incorrect NULL when dlpi_tls_modid>0. > > > > Thread 1 "tls_race.cpp.tm" hit Breakpoint 6, > > __sanitizer::CollectStaticTlsRanges (info=0x7fffffffe8d0, size=64, > > data=0x7fffffffe9d0) at > > /tmp/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp:294 > > 294 if (!info->dlpi_tls_data) > > (gdb) p *info > > $5 = {dlpi_addr = 0, dlpi_name = 0x7ffff7ffe6f8 "", dlpi_phdr = > > 0x400040, dlpi_phnum = 10, dlpi_adds = 10, dlpi_subs = 0, > > dlpi_tls_modid = 1, dlpi_tls_data = 0x0} > > > > This works fine on glibc 2.31. > > How have you verified this on glibc 2.31? As far as I can tell, the > TLS block address assignment happens lazily, and dl_iterate_phdr does > not trigger it. So it could be the result of different TLS access > patterns. The fix may be https://sourceware.org/bugzilla/show_bug.cgi?id=19826 + /* Set up the DTV entry. The simplified __tls_get_addr that + some platforms use in static programs requires it. */ + dtv[map->l_tls_modid].pointer.val = dest; With this change, static TLS blocks seem to have non-NULL dtv values. Previously, dlpi_tls_data returned by dl_iterate_phdr may be NULL, if the TLS data hasn't been touched by the program. In sanitizer runtime, I will add another dl_iterate_phdr with the callback doing __tls_get_addr({dlpi_tls_modid, 0}). This can ensure static (and also dynamic?) TLS blocks have non-NULL dtv values.