From patchwork Tue Jun 13 03:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 1794284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=oFP3Hj6c; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QgDYJ0Bjyz20Wq for ; Tue, 13 Jun 2023 13:28:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5E023858416 for ; Tue, 13 Jun 2023 03:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5E023858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686626929; bh=l/h96LXfjzwdmqGRRdT1RJ7i6Bb/wJaF5Kydi+1sQSo=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=oFP3Hj6c9ECD9w3M1Id5CuA4hXOAW/5uO49MHE/IM7Tvj4cURDwxGLrU+r8uVQOWG b7pz3n8Sl+Ztk7UpP6P7xo5XxfpJjZtFlqRsX17D55RBAkSh43CJJsjnZVRoFH2ZUn BQeJPiPk34WjHRhyh503dleYFqVle9KZLqizVrEE= 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 CBE283858D32 for ; Tue, 13 Jun 2023 03:28:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBE283858D32 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56cf9a86277so39612027b3.3 for ; Mon, 12 Jun 2023 20:28:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686626909; x=1689218909; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=l/h96LXfjzwdmqGRRdT1RJ7i6Bb/wJaF5Kydi+1sQSo=; b=aUrKQ/BBs1XjzIOdCKRVEfWflQ7pOVICtfvJQx0p0kKxDLAtVEWKhzWj7zzBehuIZv qQg7/v8yaXd/G7AsWMxSyxpqi9bzs1CQb88q5zaTEhqimPx1jhgXPiENzQyS5pM2o9lo aiBMoiakyr33EPU+5GnzcrCd/QGe6O+E4hgLfWm85r65rfTYmeeY+zFkwAoSWrvELgIF N67p4In0B5FNwvRdD7HeScGssbl9j8hzzunHwqVHRFbN1Mky9ZKroH+T7MdqUIfdpNi4 myEGfknAyaYu11ZQ9lDNC/Y1ietlars4BDdn0A5XEtJpjDtSS0bOqISGXMMVYs5XogY7 VIYQ== X-Gm-Message-State: AC+VfDyzG/bb4g4ajNpRjC3k6E4rlCSS5+Piyz8sDFbuiRxpYaQOPZ9O Jzqv/Y/RWR83TU4Erxg7KbziC5DaeXiTr+B6QvcZX/qeReLl9IdeNFg+U2A3URri0+M6z082r3x GYN9mgkfZYq5x7kz/Xd8IZoGZcNjIqD6YcQaR4iHx2yw2lba/eN8OPYt+uDU/cbiz6g== X-Google-Smtp-Source: ACHHUZ6pEKSpb8J/Sa3K18WNPKOjBWs8icc110hjTUpSYpi9O0LUuttHXkOXmDdwyE+W56KCP8UwZ1bhgmHr X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:d3d9:7807:8619:e7a4]) (user=maskray job=sendgmr) by 2002:a81:ec14:0:b0:568:9e88:6aa4 with SMTP id j20-20020a81ec14000000b005689e886aa4mr251728ywm.6.1686626909015; Mon, 12 Jun 2023 20:28:29 -0700 (PDT) Date: Mon, 12 Jun 2023 20:28:23 -0700 Mime-Version: 1.0 Message-ID: <20230613032823.264347-1-maskray@google.com> Subject: [PATCH v3] 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.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. --- 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 d4ff56ee8dd..ca92a5b65ce 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -637,7 +637,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) @@ -848,8 +849,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); @@ -869,9 +871,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 d74f6b1f8fc..de8e722cd62 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 9130104af22..a31f33e7193 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -33006,9 +33006,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..09a917431d4 --- /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];