From patchwork Tue Aug 1 19:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 129456 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2897654vqg; Tue, 1 Aug 2023 12:51:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHFyOVE564+HofI87BNPgemNSj49Q4jxlLq8h69SV3LHRl9tRrOL+lJGCcusiTNGUiKlPUd X-Received: by 2002:a05:6402:1859:b0:522:203d:c9b1 with SMTP id v25-20020a056402185900b00522203dc9b1mr3254073edy.11.1690919517837; Tue, 01 Aug 2023 12:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690919517; cv=none; d=google.com; s=arc-20160816; b=PBNbY8MjSe15DIrBuN2plMdNQWCEJA3t0Vijx+xO1TtPCWpRYqMRFdBxdHJxSO0AIa ra6MRAN63JHUgm+OOt7CKQJU0BElEIykCHrjO14vaFNCajaXC5v+iqp/Zwjc2tTAWWDw Gb8hbaLf56d85EuGH2mg0D+4yBMLwV/DWGFwi2gnio6jjAnZ95kRHZBVoUWw1Sg5YPVs hi4OMDvjmt4Pt3QOzIFgGL3h67XaZX5+MYO0te2kCFaFu25nOsZbyAewD2/fs0fT/GMi Hh6EYJKduTdISVfZdqGVLfMWliswlu5pN63MrgtsfhelPA3k7uFkXX1V/zxMT6JljPRh FmcQ== 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:cc:to:subject :message-id:mime-version:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=6xRjRYT1kkctGI42eVJWV3lwwrYmTPQCoEnly2YmzTw=; fh=tF8iXPjhI1lU4YCWTbOTQMeSCEpMBvqOm16WNRvWI+w=; b=g9mgozhLu8tBYR4nfYKwaRGnznuMhPt8py53Eg5VKeifo9zvZq2e+/H9CeLI8b0R0J f+58DQ8pHdRiQzQ0QKSekD13VyodD7dUy6rRQyI+zvNOvbxdF+kUO3qR0hOn9YB+34ZH dQ3n9nOHEeqWjpXZSO2M4vl8bteqU5quIzGFngZnh+b1pd5hpDs3GFr5IQXKl4ndMBfV yWxlrVvAmSBh6DcbAJrWSJXEU2SjBscKTq1aoBiqfBUICotuL7bcojYMhJIDaLeMA3pk +5thHFlpbq5MLIM5FmN9BM650iltAajuD6oMlXr8pWO+Qm4CS01C+xuxQ72tajs8Mpow WRiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=D++C0DI8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ba30-20020a0564021ade00b00522b8b66749si4867056edb.492.2023.08.01.12.51.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 12:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=D++C0DI8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 650B5385841C for ; Tue, 1 Aug 2023 19:51:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 650B5385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690919516; bh=6xRjRYT1kkctGI42eVJWV3lwwrYmTPQCoEnly2YmzTw=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=D++C0DI8fxAbs+UF3dJxelnqLXNMSsZ9ZDTTGhmS5SKv3ELNbUm9872mCIBnyhvZ7 7aBtiDxbAasJOjTYqp5qnRnJMsq+ODTjnrKFocIJE5hsOIHtCDxjh1i30ZwMaHqTj1 SOKexZWydDqiRpvAzGpT2OnkOKx1ODEAA9BRY0X0= 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 897AA3858D28 for ; Tue, 1 Aug 2023 19:51:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 897AA3858D28 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d052f58b7deso6226135276.2 for ; Tue, 01 Aug 2023 12:51:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690919469; x=1691524269; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6xRjRYT1kkctGI42eVJWV3lwwrYmTPQCoEnly2YmzTw=; b=Te7nEKjj3yD6ihI+qW5ZCd9WR9NkcBR+XjXZX1cD3Ly7EfdmypCCRNWM1tHuEcu0Ny 4K7CAWHAyHRIIOV/OMxvKCt/cQW6+gGiVp7Aaw4hfGP8Ys21Dj8Ms++sbDrpWEBHGZYX vgbTFHTITNMqMLB3t8yF/rKD1C3i/DMfM1WmKntfGwElQACl5fzJJNVfKfGEyY5q1/j6 DsUEuvEczpO/yiw/b54ePB+qC8QbD1ZzCc8AMDvMAW0jULziBZ7yMzV9Dw0xIMo6oqvA ZB3eZ+XiApiw4z+fMk/ZYgZNhUvYrJ0VqAgyaEl6MZB+TM8fRW6qgQKWvI4oX/DFxceG sLAg== X-Gm-Message-State: ABy/qLYD1zW7dcxkmx56HJmjUv5GdUn3mZ3wM1fq3vGzXtWa30z60FBn VE3BA1C9BqCMDxHKYo8n3Fs1E4NTQe3OakPYSLxs4IXCBvsF2QOstyP98/AAzfEaUgPKrM9AMK2 /GECFk9lvRLkAlVdQ+D2olEmyybVqVmwBZAay2mabGcYgDJk/HCjX+TsPeYkjE0hOKA== X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:db01:d61b:177c:1a2b]) (user=maskray job=sendgmr) by 2002:a25:d24d:0:b0:d08:ea77:52d4 with SMTP id j74-20020a25d24d000000b00d08ea7752d4mr87335ybg.12.1690919468731; Tue, 01 Aug 2023 12:51:08 -0700 (PDT) Date: Tue, 1 Aug 2023 12:51:04 -0700 Mime-Version: 1.0 Message-ID: <20230801195104.2183011-1-maskray@google.com> Subject: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large To: gcc-patches@gcc.gnu.org, Florian Weimer , "H.J. Lu" , Jan Beulich , Jan Hubicka , Michael Matz , Uros Bizjak Cc: Fangrui Song 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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Fangrui Song via Gcc-patches From: Fangrui Song Reply-To: Fangrui Song Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773057624340347394 X-GMAIL-MSGID: 1773057624340347394 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 . --- gcc/config/i386/i386.cc | 15 +++++++++------ gcc/config/i386/i386.opt | 2 +- gcc/doc/invoke.texi | 6 +++--- gcc/testsuite/gcc.target/i386/large-data.c | 13 +++++++++++++ 4 files changed, 26 insertions(+), 10 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 eabc70011ea..37e810cc741 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -647,7 +647,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) @@ -858,8 +859,9 @@ 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) - && size > (unsigned int)ix86_section_threshold) + 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)); fputs (LARGECOMM_SECTION_ASM_OP, file); @@ -879,9 +881,10 @@ 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) - && size > (unsigned int)ix86_section_threshold) - switch_to_section (get_named_section (decl, ".lbss", 0)); + 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 switch_to_section (bss_section); ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index 1cc8563477a..52fad492353 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 104766f446d..bf6fe3e1a20 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -33207,9 +33207,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];