From patchwork Fri Apr 28 00:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 68425 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 787563858416 for ; Fri, 28 Apr 2023 00:48:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 787563858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682642884; bh=G10DXUmswi5mPr6CO9KfbikDw8xeSQ/BVhyKK5FACbk=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jmZsMElLWylg1qQHFSWoINR6Uk5WI5tUDmI5pNgU4uj6CWD+Ghb3/qCrvXHYDDR4s asS3PRywkA7RDXnn9UT+ho7+o3Xb3H6y8XgscyPv6AdShvSPa8CCwYrRS08Wt9tTrZ lZqceEcqJ+dcxCCqiJrx4jIqbVSfFeRg1AS0ivwY= 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 06B8B3858D37 for ; Fri, 28 Apr 2023 00:47:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06B8B3858D37 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a8023ccf1so2224165276.2 for ; Thu, 27 Apr 2023 17:47:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682642849; x=1685234849; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=G10DXUmswi5mPr6CO9KfbikDw8xeSQ/BVhyKK5FACbk=; b=AEG7y8dprKPap8uWx/NyJL+DFGg1clOQcdg23Pe1m1NscCiqrYq7wMqUIM8hKQ7PnO Yov/n/evRKTkhhVqnFQvkW3SjPkTJxk+ekMWq9rmRhqly7ko+GqLWfr+wZ8b5hV0RIFC ridmk/cbV/CjJ/w94KXL9zfhG3Zw+AV+y7HZ1vbteFNEkJaJaq8ZHyXcP8E6USLzG4cn ktwgGDkG9FRCx0vyiml02JE4M16CLTO17svPOqbQLSsxfpbLXNT5a+I13PYAWA1MH5tk Tik4vjgAjdE3aXRWJxiqMdlyXMNG4WeKOtjlLjVT0VT5K2TIfiHCGjCwPOTqRIc0hevt dmtQ== X-Gm-Message-State: AC+VfDwwwNxaQPfESbjzqrludFqGoxa8ftLPARc1TJGidkTmBTmdzkNO yoFPlb2R5yRKtJE57w9Z3TIe5jX0X5eMu03h9FTuBRfziNXnouGr8vR9TXcfcWxeqC0LfWt6qfw 23UP70bgWAXOshylo3ao2NPmufWcOhdnnZDPa9/EZubwjZFwJInjBUoXfBu0z86PvXg== X-Google-Smtp-Source: ACHHUZ7XEuoj2MFRB6hQ27IZQ5XELISJKdOPn5usHgFWHVZ9cbLWP1uFuL5lc7oqcjouZDmozLcr9FXbADBz X-Received: from maskray.svl.corp.google.com ([2620:15c:2d3:205:6009:5afe:9e8a:8531]) (user=maskray job=sendgmr) by 2002:a05:6902:100e:b0:b8f:47c4:58ed with SMTP id w14-20020a056902100e00b00b8f47c458edmr1977825ybt.9.1682642849265; Thu, 27 Apr 2023 17:47:29 -0700 (PDT) Date: Thu, 27 Apr 2023 17:47:26 -0700 Mime-Version: 1.0 Message-ID: <20230428004726.3217666-1-maskray@google.com> Subject: [PATCH] i386: Allow -mlarge-data-threshold with -mcmodel=large To: gcc-patches@gcc.gnu.org, Jan Hubicka , Uros Bizjak 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, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When using -mcmodel=medium, large data is placed into .l* sections. GNU ld places .l* sections into separate output sections. If small and medium code model object files are mixed, the .l* sections won't cause relocation overflow pressure on sections in -mcmodel=small object files. However, when using -mcmodel=large, -mlarge-data-threshold doesn't apply. This means that the .rodata/.data/.bss sections may cause relocation overflow pressure on sections in -mcmodel=small object files. This patch allows -mcmodel=large to generate .l* sections. Signed-off-by: Fangrui Song --- gcc/config/i386/i386.cc | 15 +++++++++------ gcc/config/i386/i386.opt | 2 +- gcc/doc/invoke.texi | 7 ++++--- gcc/testsuite/gcc.target/i386/large-data.c | 13 +++++++++++++ 4 files changed, 27 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 a3db55642e3..c68c66a5567 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 e5ee2d536fc..4a20eef92e5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -32927,9 +32927,10 @@ 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. This +value must be the same across all objects linked into the binary, and defaults +to 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];