From patchwork Mon Oct 16 18:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 153714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3645084vqb; Mon, 16 Oct 2023 11:22:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwumD4rp1ECeLF4L8qwNv0YPkKE7oNIYATxZ0pC0EnAjZWl94MY/8j6TewADfvOUeMk9b+ X-Received: by 2002:ad4:5f4a:0:b0:66d:132b:1c96 with SMTP id p10-20020ad45f4a000000b0066d132b1c96mr222208qvg.28.1697480541782; Mon, 16 Oct 2023 11:22:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697480541; cv=pass; d=google.com; s=arc-20160816; b=Avq2JuwLRGITlnvPZKFsP9jxooyLOt6GuVsdfrSQKMEhpxmt19C3nLx/EX2fvR0wPd 6KQbJT+a0Ps8Mfrq4v2pbboTiSpz2x5P3Qg8L6Om//rCZyJAc6CpcDrSfnoN4CDrUP4q 7JjZ2fRg4kU0QoxteaQIr4LamhDiT4JDvieJgl+MQr3pEgbsoENpzB59rRUY/hy+e2hB cgkPRf+9TXpd7fg12URME1bIZ1jdR24KGx5qLCDetYKU+5Pkm/6Kl2/LljyTU53XG3SK qupAY6vVAbHwkSV4w4dAJDyRw22AukQvC5VfW5WYvvFiuoQNeZvSullXB6JZlcaBD2w3 XoUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:from:subject:message-id :mime-version:date:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=WSHAuBUuagEfbGo2BcsIMYIDfNPPpDCe3dCY8SEJE0w=; fh=ZUJ7xWLUMXU6XAi0omaiY6/sRoePTZOo05Ie8NQ+f6o=; b=CTCWROo4gtSjUeS8k0V3JDI9jNAd/+tRz2NmLmEhvm7Uq+pkMhMs5KgFALGeRUK6lA 2aMzp/eMpxndFo54N0db2sziaTAKiFA/VxJmkPc34QJuHHPX/LKxn5+zh4Mfxs3r/ltP aZQFDOkuJrrxp/8d7JJZj7ampQy4D8+WO6bFTYlQ2NfXhnzG5PNqSbwcTuWHqWepSXOe tLJEQy4oZWXM4vu9jGkJ7iqXcYlmd8Ze2uP7ynPMfO11eX661wT8RoDQJiCdRqZ/oQvO AmxGhEkLCCI77a3P12KFLnS5F6mv13+IuIGM3sLzdDRvywqA90lvrfAoxsDzVke8uGDs d/mA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Abv3o+WQ; arc=pass (i=1); 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ec16-20020ad44e70000000b0066cee119735si5723609qvb.552.2023.10.16.11.22.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 11:22:21 -0700 (PDT) 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=@google.com header.s=20230601 header.b=Abv3o+WQ; arc=pass (i=1); 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C5423857C45 for ; Mon, 16 Oct 2023 18:22:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id AE2D83858C3A for ; Mon, 16 Oct 2023 18:21:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE2D83858C3A Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--maskray.bounces.google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE2D83858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b4a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697480515; cv=none; b=e6Hj2RZS229EwiqhEbzHTmIIH0UV6bl3e8jbw9J0I+oVDaFPlcSI9nu/08ofb54GoBvbXGB2p/nEBC22a8UWLo0PFSgVvKRCtEVJJRbG7ftDk4aN/eQTKvl5Vll2MA0/OApRuY4+zD0/ssB2ZYqy45eEJkN4aWWf/D9i0d5TC1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697480515; c=relaxed/simple; bh=9NVqTBJNQaYc8teaHhNnFBrOZbs/Al2CPh/18/CEC0I=; h=DKIM-Signature:Date:Mime-Version:Message-ID:Subject:From:To; b=T7Pg8QkdDoRqSEeNpb6+7H53SuJQaP1piLclm8E6KsD+RAI5EwDe+Icpamm0GXZJLDoOIMx2ZcEeOs80PjO3gxhsHDiRJWC9g+WCH8JOTJv0zwXfnBi19a6MSagaUQcD/V8Bey0KPzwdQ/sGyG2JBtf55XVHWUP3w3u130ih+ZI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9a3add086dso5966837276.3 for ; Mon, 16 Oct 2023 11:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697480512; x=1698085312; darn=gcc.gnu.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WSHAuBUuagEfbGo2BcsIMYIDfNPPpDCe3dCY8SEJE0w=; b=Abv3o+WQWI4eC829M3uMFdSqiop+byY6a6T0HPwgRJWtcYIBdSiLfkyfrEmbXgWMap 3tiC4lUTUjh8ePKXmtibRH6SNE1tLRqfkG7tw+3rqfeBrRW+gcx/GKbRwC8Bg89vtw6Z IiLF5a9EwG5tG/Ru/xg/azg3mgkeNzo6wCmYFL/t39tCceHmX6EeFkabexj//gLDDyGy 2iMipE8JlvBT8tzV+I3Bb5mNibYPOW7eHC5nm6lIxWFS2M5CwZr2NcSbxyw4r+q9gMRS ODaBMIQp+GxWkAMvHv9HCIiuTWKfIM88ZXXoKwuadLUwwJZJ4M2VMuNqTR7qxD1Dxq4h nHng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697480512; x=1698085312; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WSHAuBUuagEfbGo2BcsIMYIDfNPPpDCe3dCY8SEJE0w=; b=F5WgmwhdYk2JjSSUVdnUf2X9PSJPY1xM7D6mAn1g/vU5Mz0yRrumatgfIWJqmUSmAH T7aP/aogzi66WEKzMMLJ4KkwBN4uLG2VaXj4ih+gE71Z6dFRq9Wi/BIzr/gFcU3V+1vg 2+b5hrAdi80ze+eCvOpskfj0yNCFLbbq5+xiRxqw+m1DiY11Q5ta5WdolAG1O2x0/SsA eZSV5WvT6eIYMV0rHQ3pw45YEFcLQ6466HZf1yd/jGWGXu4FtFG++SQmKMoPF991LOP4 EaJlQlGLQUUS3ypPCL2YIIvUvFwKZYyCQXlikCa67soAvAnTZYX/v9Q3GcMxVRp3RTOx U/Ug== X-Gm-Message-State: AOJu0Yzt+EXh5THfOmb9Ae5w9ICwYw3B29W7lvwKZZT82UEZpRK6QdQT 0feXvAqKU+KxzMfUFEoAtxTGhnYb4i3lN4ZBoh45m6YHIAznAZ556ohGck4wEYfSy5EeghnwiMY v0BNG/2ZkaAhwD/7Mwht+ZhpN1Zxc5T8hVtxECUZC1FeLISk9qUi6KjHypMREb/20dg== X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:1972:b984:359b:c069]) (user=maskray job=sendgmr) by 2002:a25:c243:0:b0:d89:4d2c:d846 with SMTP id s64-20020a25c243000000b00d894d2cd846mr651584ybf.12.1697480511926; Mon, 16 Oct 2023 11:21:51 -0700 (PDT) Date: Mon, 16 Oct 2023 11:21:38 -0700 Mime-Version: 1.0 Message-ID: <20231016182138.1304513-1-maskray@google.com> Subject: [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large From: Fangrui Song To: gcc-patches@gcc.gnu.org Cc: Fangrui Song X-Spam-Status: No, score=-19.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779937356606480641 X-GMAIL-MSGID: 1779937356606480641 When using -mcmodel=medium, large data objects larger than the -mlarge-data-threshold threshold are placed into large data sections (.lrodata, .ldata, .lbss and some variants). GNU ld and ld.lld 17 place .l* sections into separate output sections. If small and medium code model object files are mixed, the .l* sections won't exert relocation overflow pressure on sections in object files built with -mcmodel=small. However, when using -mcmodel=large, -mlarge-data-threshold doesn't apply. This means that the .rodata/.data/.bss sections may exert relocation overflow pressure on sections in -mcmodel=small object files. This patch allows -mcmodel=large to generate .l* sections and drops an unneeded documentation restriction that the value must be the same. Link: https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU ("Large data sections for the large code model") Signed-off-by: Fangrui Song --- Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.html): * Clarify commit message. Add link to https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU Changes from v2 * Drop an uneeded limitation in the documentation. Changes from v3 * Change scan-assembler directives to use \. to match literal . Changes from v4 (https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633145.html) * "When you split an expression into multiple lines, split it before an operator, not after one." --- gcc/config/i386/i386.cc | 9 ++++++--- gcc/config/i386/i386.opt | 2 +- gcc/doc/invoke.texi | 6 +++--- gcc/testsuite/gcc.target/i386/large-data.c | 13 +++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/large-data.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 8251b67e2d6..641e7680335 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -663,7 +663,8 @@ ix86_can_inline_p (tree caller, tree callee) static bool ix86_in_large_data_p (tree exp) { - if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC) + if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC + && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC) return false; if (exp == NULL_TREE) @@ -874,7 +875,8 @@ x86_elf_aligned_decl_common (FILE *file, tree decl, const char *name, unsigned HOST_WIDE_INT size, unsigned align) { - if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC) + if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC + || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) && size > (unsigned int)ix86_section_threshold) { switch_to_section (get_named_section (decl, ".lbss", 0)); @@ -895,7 +897,8 @@ void x86_output_aligned_bss (FILE *file, tree decl, const char *name, unsigned HOST_WIDE_INT size, unsigned align) { - if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC) + if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC + || ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC) && size > (unsigned int)ix86_section_threshold) switch_to_section (get_named_section (decl, ".lbss", 0)); else diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index b8382c48099..0c3b8f4b621 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -282,7 +282,7 @@ Branches are this expensive (arbitrary units). mlarge-data-threshold= Target RejectNegative Joined UInteger Var(ix86_section_threshold) Init(DEFAULT_LARGE_SECTION_THRESHOLD) --mlarge-data-threshold= Data greater than given threshold will go into .ldata section in x86-64 medium model. +-mlarge-data-threshold= Data greater than given threshold will go into a large data section in x86-64 medium and large code models. mcmodel= Target RejectNegative Joined Enum(cmodel) Var(ix86_cmodel) Init(CM_32) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index eb714d18511..50745a3a195 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -33390,9 +33390,9 @@ the cache line size. @samp{compat} is the default. @opindex mlarge-data-threshold @item -mlarge-data-threshold=@var{threshold} -When @option{-mcmodel=medium} is specified, data objects larger than -@var{threshold} are placed in the large data section. This value must be the -same across all objects linked into the binary, and defaults to 65535. +When @option{-mcmodel=medium} or @option{-mcmodel=large} is specified, data +objects larger than @var{threshold} are placed in large data sections. The +default is 65535. @opindex mrtd @item -mrtd diff --git a/gcc/testsuite/gcc.target/i386/large-data.c b/gcc/testsuite/gcc.target/i386/large-data.c new file mode 100644 index 00000000000..bdd4acd30b8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/large-data.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O2 -mcmodel=large -mlarge-data-threshold=4" } */ +/* { dg-final { scan-assembler {\.lbss} } } */ +/* { dg-final { scan-assembler {\.bss} } } */ +/* { dg-final { scan-assembler {\.ldata} } } */ +/* { dg-final { scan-assembler {\.data} } } */ +/* { dg-final { scan-assembler {\.lrodata} } } */ +/* { dg-final { scan-assembler {\.rodata} } } */ + +const char rodata_a[] = "abc", rodata_b[] = "abcd"; +char data_a[4] = {1}, data_b[5] = {1}; +char bss_a[4], bss_b[5];