From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5CB673858D1E for ; Mon, 13 Mar 2023 15:45:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CB673858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678722351; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=NJmLhtTMi8akbnxiTX/D6e5kznG6J9zvO2eNWKhzSrg=; b=U8bZydXsHDITfy78wEFREmP5WbO/jugj3ZQBpPxlk1WACPXwliE+zrZWlFm2n+tzlVoUDP JcfZ4DfG5HusJ6lBCCUQf9TCobhCOMszhoc83i8+D9Kv0hVhlM+RYDCwoOmV5LNipIG0Q1 wIQhaSB6QHz0KacSU0gm9K1KaBU3RqI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-255-LnCiQs-6MnqSqGpjsHJWRA-1; Mon, 13 Mar 2023 11:45:47 -0400 X-MC-Unique: LnCiQs-6MnqSqGpjsHJWRA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C0CB3814589; Mon, 13 Mar 2023 15:45:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F3251121315; Mon, 13 Mar 2023 15:45:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32DFjib71845007 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 13 Mar 2023 16:45:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32DFjhsM1845006; Mon, 13 Mar 2023 16:45:43 +0100 Date: Mon, 13 Mar 2023 16:45:43 +0100 From: Jakub Jelinek To: Sergey Bugaev Cc: libc-alpha@sourceware.org, Florian Weimer Subject: Re: GCC miscompilation with __seg_fs Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Mar 13, 2023 at 06:24:47PM +0300, Sergey Bugaev wrote: > Hello, > > while exploring the generated assembly for an entirely unrelated > reason, I found out that GCC eliminates stores through THREAD_SELF > when it's declared using __seg_fs. This is easily reproducible outside > of glibc; here's a sample reproducer (I've also put it on Godbolt [0] > for easy exploration): Smaller testcase: typedef struct { void *tcb; int some_member; } tcbhead_t; void assign_through_self (void) { (*(tcbhead_t * __seg_fs *) __builtin_offsetof (tcbhead_t, tcb))->some_member = 42; } >From what I can see, GCC has been DSE removing these since https://gcc.gnu.org/r6-4645 when __seg_fs support has been introduced. One can work-around it using -fno-delete-null-pointer-checks. You could also hide the fact that it is based on 0 pointer from the compiler... While GCC has targetm.addr_space.zero_address_valid hook (which AFAIK only x86 overrides), we use it only in very few spots right now. Feel free to file a bug report in GCC bugzilla, but that won't improve anything on the already released compilers. Jakub