public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: Fangrui Song <maskray@google.com>
Cc: gcc-patches@gcc.gnu.org, Jan Hubicka <hubicka@ucw.cz>
Subject: Re: [PATCH] i386: Allow -mlarge-data-threshold with -mcmodel=large
Date: Wed, 10 May 2023 11:57:52 +0200	[thread overview]
Message-ID: <CAFULd4Y7dVWcA01Udnh05tcTYJxbm-N3HiBwTBR4CBjN774_Bw@mail.gmail.com> (raw)
In-Reply-To: <20230428004726.3217666-1-maskray@google.com>

On Fri, Apr 28, 2023 at 2:47 AM Fangrui Song <maskray@google.com> wrote:
>
> 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.

The x86_64 psABI does not specify how -mlarge-threshold is handled
with -mcmodel=large and it also doesn't mention that -mcmodel=large
inherits handling from -mcmodel=medium. The ABI does say that the
-mcmodel=large is strictly only required if the text of a single
function becomes larger than what the medium model allows.

OTOH, the ABI also doesn't prohibit large sections with -mcmodel=large
and IMO, the introduction of -mlarge-threshold with -mcmodel=large
does not create an ABI change.

I think the best way is to first discuss the issue with the x86_64
psABI group, to clarify how -mlarge-threshold and large data is
handled under a large code model.

Uros.
>
> Signed-off-by: Fangrui Song <maskray@google.com>
> ---
>  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=<number>        Data greater than given threshold will go into .ldata section in x86-64 medium model.
> +-mlarge-data-threshold=<number>        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];
> --
> 2.40.1.495.gc816e09b53d-goog
>

  parent reply	other threads:[~2023-05-10  9:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28  0:47 Fangrui Song
2023-05-06 20:41 ` Fangrui Song
2023-05-10  9:57 ` Uros Bizjak [this message]
2023-05-13  2:57   ` Fangrui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFULd4Y7dVWcA01Udnh05tcTYJxbm-N3HiBwTBR4CBjN774_Bw@mail.gmail.com \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=maskray@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).