Message ID | 20230201073859.3920910-1-maskray@google.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp135061wrn; Tue, 31 Jan 2023 23:40:06 -0800 (PST) X-Google-Smtp-Source: AK7set/9B6nmK+iMQ9l5rZv9H2HyXK2gceoeflLEU4EGe7j/sXF//I/Ts93pyW2Y5nCMSIryurYk X-Received: by 2002:a05:6402:1c07:b0:499:70a8:f915 with SMTP id ck7-20020a0564021c0700b0049970a8f915mr857087edb.21.1675237206038; Tue, 31 Jan 2023 23:40:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675237206; cv=none; d=google.com; s=arc-20160816; b=IVFtx3Hw6dr0T9vjv79bkg3IXxOnYnorQzkpz5pIUGt9nByQiht4d3MAZuJut+qpWy 9irKUXuXCk9TtblIRNg9mG6K0O80twWCn2cKzfE6WLj4Tcs0xKTn0q3bzyPwH85eF1nc Y9M1vMU2yExv61IKgm8c6R+4c57LST2iuq+aKT8CvcmCqrxOvi94bpdQvDwKV4C/ftlF GhFtt9jHP1G/yPLfY36gwKmFRckt3KzQbw53c++GiZlOhpmQXy2gOBSMJmHIR7hSUBna KcBD5uDWeap+s4ChQbnbj/n7zb6VvdKvg7TnY7NBBUGR5xDaGkwqV0IZWbd0i89ZDkay Ooow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:cc:to:subject:message-id:mime-version :date:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PDkDPvXKrp847a8vZ+j4k75GKoQstCbQK2bCA7LHOTw=; b=UY8jTtX5Z9Cu9x+q5ZLGctAQcONNXX/1XdN5o+Zm3ULsgFogCsz77uetVdnCGnifm1 axnX6pZgH39ZcIynmASUZRC/dvRFX3BLFtXr/S/cAxJw5p1TSyijb2vPtCjcLjNR9haP 7QoMFQ4YSgY++9RyDi6SeAEggFz/8dbN/ZTz1Yo8upU0Mu6KOrAhLaXCk0WFeqKfpnN2 Eq0Dy/UDi7mO/vYBz1sQUvGG4gUnxA157PKQ0AykbnB/VN53kixPy038eA7TizhMGN4W SjhzxPMKf5WcWcJhS31FQ58hKOG4aB9xWuUebw1iw2EWnhcv2RKHMCBQdc/jaFsaFXAt qGLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=P5KUPU6T; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z4-20020a50eb44000000b00469bac8510csi3670830edp.583.2023.01.31.23.40.05 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 23:40:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=P5KUPU6T; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA668385B501 for <ouuuleilei@gmail.com>; Wed, 1 Feb 2023 07:40:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA668385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675237200; bh=PDkDPvXKrp847a8vZ+j4k75GKoQstCbQK2bCA7LHOTw=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=P5KUPU6TbzHJ49XwYGnOHYEoImrdfgUiOlA7yx37ONSuIXwCpr0XEe30smEsR1HM9 KphZTn8PXp0dlubtqOIRWoPsCCDGqBQmXxr0HLYrW+GE5zD7Mh2E3KD/V/aiqnSo2h 23dWlFKjnnFB5mzgrVCUgGoGXq31nR+a1BVVgbak= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by sourceware.org (Postfix) with ESMTPS id 5C6EA3858D38 for <gcc-patches@gcc.gnu.org>; Wed, 1 Feb 2023 07:39:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C6EA3858D38 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4fee82718afso192044547b3.5 for <gcc-patches@gcc.gnu.org>; Tue, 31 Jan 2023 23:39:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PDkDPvXKrp847a8vZ+j4k75GKoQstCbQK2bCA7LHOTw=; b=qj3EaFej95yicgHXGyMQ5tsJBGtLioru+/y09RO13okir7766FqtVc6Skrp5jybZaB /Wvc5t3/7a0L96HzkHkDpIEN96tUZ0c5skoPTrl1wnUj7zNnxT7n/DJW9m3n5QOET/vg a8KERSzlrPnJgCtqfmGC/w770TFLmO/l4nGwzHFImsfTHPGOR1U0/1XDBS7YWeLKCGkj 4hYLQeXz6ZBm54QoEcjbFTnLbqKxyeR4LEm0ooCQeFXMpDzx+aLi/2n9YWM6YgZ2Fn0c ThAB/oQQF2RkxmNm7NnPtQIPabtSZk5K7cuop7NlkQHwXEezEcpg2tYaNggrvWL59Ecz WTBw== X-Gm-Message-State: AO0yUKV11Pm+5u4Go5QWUEchSrJEn50lhWjI39oOrhTo2e3Q8Rj7BXJr wVtNomMknPKj1W9f56O3MMzxQYQhCKmGadw/nSgEf9UyAC5pusxBqShV1rwTq0e4yV+0bJ2TWZE S/wVR85k3s0xxp6V0mKPUrrX+uFX0aodgOwltWVCW3Dam7iWnfqCWlDhDnNQMCAMpbQ== X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:4b25:4a18:11d7:112]) (user=maskray job=sendgmr) by 2002:a81:e30a:0:b0:507:77a2:f50f with SMTP id q10-20020a81e30a000000b0050777a2f50fmr155599ywl.420.1675237142646; Tue, 31 Jan 2023 23:39:02 -0800 (PST) Date: Tue, 31 Jan 2023 23:38:59 -0800 Mime-Version: 1.0 Message-ID: <20230201073859.3920910-1-maskray@google.com> Subject: [PATCH] x86: Use DW_EH_PE_indirect|DW_EH_PE_pcrel encodings for -fno-pic code To: gcc-patches@gcc.gnu.org Cc: Fangrui Song <maskray@google.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-19.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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> From: Fangrui Song via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Fangrui Song <maskray@google.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756613528095415310?= X-GMAIL-MSGID: =?utf-8?q?1756613528095415310?= |
Series |
x86: Use DW_EH_PE_indirect|DW_EH_PE_pcrel encodings for -fno-pic code
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Fangrui Song
Feb. 1, 2023, 7:38 a.m. UTC
Follow aarch64 and riscv ports by using (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel for -fno-pic code. This avoids a canonical PLT entry for a personality reference in .eh_frame and a copy relocation for a typeinfo reference in .gcc_except_table, when the definition is in libstdc++.so.6. gcc/ PR target/108622 * config/i386/i386.cc (asm_preferred_eh_data_format): Always use the PIC encoding. Use DW_EH_PE_indirect if global. --- gcc/config/i386/i386.cc | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
Comments
On Tue, Jan 31, 2023 at 11:38:59PM -0800, Fangrui Song via Gcc-patches wrote: > Follow aarch64 and riscv ports by using (global ? DW_EH_PE_indirect : 0) > | DW_EH_PE_pcrel for -fno-pic code. This avoids a canonical PLT entry > for a personality reference in .eh_frame and a copy relocation for a > typeinfo reference in .gcc_except_table, when the definition is in > libstdc++.so.6. > > gcc/ > > PR target/108622 > * config/i386/i386.cc (asm_preferred_eh_data_format): Always use the > PIC encoding. Use DW_EH_PE_indirect if global. Not a review, just comments: > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > index 3cacf738c4a..b572dd46a62 100644 > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -22851,22 +22851,13 @@ ix86_stack_protect_fail (void) > int > asm_preferred_eh_data_format (int code, int global) > { > - /* PE-COFF is effectively always -fPIC because of the .reloc section. */ > - if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access) > - { > - int type = DW_EH_PE_sdata8; > - if (ptr_mode == SImode > - || ix86_cmodel == CM_SMALL_PIC > - || (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) > - type = DW_EH_PE_sdata4; > - return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type; > - } > - > - if (ix86_cmodel == CM_SMALL > - || (ix86_cmodel == CM_MEDIUM && code)) > - return DW_EH_PE_udata4; > - > - return DW_EH_PE_absptr; > + int type = DW_EH_PE_sdata8; > + if (ptr_mode == SImode || ix86_cmodel == CM_SMALL || > + ix86_cmodel == CM_SMALL_PIC || > + (ix86_cmodel == CM_MEDIUM && code) || > + (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) The above is incorrectly formatted, the GCC Coding Conventions say || etc. shouldn't be at the end of lines, but rather at the start of the next ones. And, while I can understand the rationale for global cases (though am not sure I agree, as currently the user can choose by using -mno-direct-extern-access or not using it, the above change disallows the choice), for !global I miss the point altogether. In non-PIC (and non-PECOFF maybe, don't know that format well) code if code references a local symbol, it will never generate a copy relocation and so DW_EH_PE_udata4 could be just fine and cheaper to handle on the consumer sides. Jakub
On Wed, Feb 01, 2023 at 10:01:36AM +0100, Jakub Jelinek via Gcc-patches wrote: > And, while I can understand the rationale for global cases > (though am not sure I agree, as currently the user can choose > by using -mno-direct-extern-access or not using it, the above change > disallows the choice), for !global I miss the point altogether. > In non-PIC (and non-PECOFF maybe, don't know that format well) > code if code references a local symbol, it will never generate > a copy relocation and so DW_EH_PE_udata4 could be just fine and cheaper > to handle on the consumer sides. Plus, e.g. for the typeinfo references, if using the default -mdirect-extern-access and RTTI is used, there will be copy relocations anyway and so the .eh_frame growth will be just waste of .got space. Jakub
> The above is incorrectly formatted, the GCC Coding Conventions say || etc. shouldn't be at the end of lines, but rather at the start of the next ones. Ack. > And, while I can understand the rationale for global cases > (though am not sure I agree, as currently the user can choose > by using -mno-direct-extern-access or not using it, the above change > disallows the choice), for !global I miss the point altogether. > In non-PIC (and non-PECOFF maybe, don't know that format well) > code if code references a local symbol, it will never generate > a copy relocation and so DW_EH_PE_udata4 could be just fine and cheaper > to handle on the consumer sides. On Wed, Feb 1, 2023 at 1:09 AM Jakub Jelinek <jakub@redhat.com> wrote: > > On Wed, Feb 01, 2023 at 10:01:36AM +0100, Jakub Jelinek via Gcc-patches wrote: > > And, while I can understand the rationale for global cases > > (though am not sure I agree, as currently the user can choose > > by using -mno-direct-extern-access or not using it, the above change > > disallows the choice), for !global I miss the point altogether. > > In non-PIC (and non-PECOFF maybe, don't know that format well) > > code if code references a local symbol, it will never generate > > a copy relocation and so DW_EH_PE_udata4 could be just fine and cheaper > > to handle on the consumer sides. > > Plus, e.g. for the typeinfo references, if using the default > -mdirect-extern-access and RTTI is used, there will be copy relocations > anyway and so the .eh_frame growth will be just waste of .got space. > > Jakub > There is a copy relocation but the canonical PLT entry for __gxx_personality_v0 can be removed. -fno-pic C++ exception code is less common nowadays, so there seems little value to keep a complex condition (if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access)) to optimize a bit for the object file size (I think you mean .data space instead of .got space). The .eh_frame growth is nearly negligible as well.
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 3cacf738c4a..b572dd46a62 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -22851,22 +22851,13 @@ ix86_stack_protect_fail (void) int asm_preferred_eh_data_format (int code, int global) { - /* PE-COFF is effectively always -fPIC because of the .reloc section. */ - if (flag_pic || TARGET_PECOFF || !ix86_direct_extern_access) - { - int type = DW_EH_PE_sdata8; - if (ptr_mode == SImode - || ix86_cmodel == CM_SMALL_PIC - || (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) - type = DW_EH_PE_sdata4; - return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type; - } - - if (ix86_cmodel == CM_SMALL - || (ix86_cmodel == CM_MEDIUM && code)) - return DW_EH_PE_udata4; - - return DW_EH_PE_absptr; + int type = DW_EH_PE_sdata8; + if (ptr_mode == SImode || ix86_cmodel == CM_SMALL || + ix86_cmodel == CM_SMALL_PIC || + (ix86_cmodel == CM_MEDIUM && code) || + (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) + type = DW_EH_PE_sdata4; + return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type; } /* Implement targetm.vectorize.builtin_vectorization_cost. */