From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id E005B3858291 for ; Mon, 13 Mar 2023 15:53:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E005B3858291 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1034.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so17322542pjg.4 for ; Mon, 13 Mar 2023 08:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678722818; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xmfch53MLmF78yaQQ98TwmRzZn1f0A0w8iltaHf9cJI=; b=KBlbXueSUG3cXpEoR/L8CJzyKT2fIqhoklhdsf/1Fz/xcFV4Mze2Bg2HHj+KnVxzM3 kyjtCunf3uCrHbdfuSwZj1PgmLsTKTdK0ekqlxKrg9SFgX1h0DVtzbI6aQuRSvhHPIIB CH+7rHj3RS9raOOhbrzB0RKZEDtzEsuGNYx6BWUCl1dfV1fU871Oa1MWMf9qhzIYU7Gy bxGjxCxIwGu2afmV793ZlBXDQAicNPYGARXJzCcWiRId6hK+nOKJ7amAiqwjaIxM+ik0 FWRxDLiQQ9eZ5CnP3wVqHN9TqH65Ck9eC08orqhyX7mffA2qJcnejyJSE+nh8E4q5UvS bYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678722818; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xmfch53MLmF78yaQQ98TwmRzZn1f0A0w8iltaHf9cJI=; b=MhJpS3j2c7i1Wz5KEmIF0U6o9ivJKeIVyH1wRP6IfRhu8ME2B4heCj/yFPfVD/P599 z7FjwN+NoLhiLO6iV41xpvhUNqvW5ywegQf9FjszG329e/13cjCjTJ8FvumOiZJNNrT3 IySQtwN9Z/ZK4iKFkjrDh6u859bkvO2wm4zzoaHZIw78LIjUJxk+f4HX3s0r4111F0Fx QpFJcKR4nKAAm+E0SgdycUmc3z+2e+2qDEseoSlzAH2ODE2j01H6XaEjxB39/KWBFZJ9 xQB/aPeys4QbZCiPygQYJTFBXITsRtKL5aJoRIUCZAIHEoKXx4FUB9bQkAM0TcWUYnLk eWlw== X-Gm-Message-State: AO0yUKW/tNrFopmT8lbZGllYh1f9qEb74hteJWIhfl+eekSr+DKl7Yxh sT+e2q8nSGft2WRkn5LhYxwglG+RtOXO6vQMpL4= X-Google-Smtp-Source: AK7set9p9aOPtwSzZiFo7Ls/a7G72KDzvVei4LIswf6FVdr5sFReLV3KULMPihjs60FIApuMx1DMnrbXfU/KZp+DRaI= X-Received: by 2002:a17:90a:f68e:b0:23b:419d:8efe with SMTP id cl14-20020a17090af68e00b0023b419d8efemr2226748pjb.3.1678722817781; Mon, 13 Mar 2023 08:53:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrew Pinski Date: Mon, 13 Mar 2023 08:53:26 -0700 Message-ID: Subject: Re: GCC miscompilation with __seg_fs To: Jakub Jelinek Cc: Sergey Bugaev , libc-alpha@sourceware.org, Florian Weimer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 8:46=E2=80=AFAM Jakub Jelinek via Libc-alpha wrote: > > 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_m= ember =3D 42; > } > > From what I can see, GCC has been DSE removing these since https://gcc.gn= u.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 onl= y > 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. I am 99% sure this is https://gcc.gnu.org/PR102733 or at least related to i= t. Thanks, Andrew Pinski > > Jakub >