From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by sourceware.org (Postfix) with ESMTPS id 0A96F3858CDB for ; Sat, 13 May 2023 02:58:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A96F3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-3f38a9918d1so1166471cf.1 for ; Fri, 12 May 2023 19:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683946681; x=1686538681; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P1rdTkGiADUz8/GjyNNAEYcFHGOG12jkCIeDc7Wlt/8=; b=oLu7EXDGy8esej4qzU0S+LVAMhsqxjdS14A7dhPyp/6CSG8juZu/RXJKksP83OGDVk XMdy5E7l1ash9GitMJ8X1DtsfSYRWHpzsXKHcwfsP1bNe8xhzwNEXwIUFDASzX1P/usN WRm1wN8DRFhwUxuf+xdJoLP24OATbUmYJ9OJCc7tl1Lb+Bi3tUszdIEClaodz5X5bvoC tq4b6GXUezGjpEQex4XdalCXyynnw04Nawfmap38J+uLfe+D6nzEymEVzBig3vLmAKNQ 1LzK9ADN2SlxSbD+oM7e7jl8CdKc7ZtN0QvnXPaXQ4j5cjxjXNiqH8GPkzWb+/2RO8R4 dcKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683946681; x=1686538681; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P1rdTkGiADUz8/GjyNNAEYcFHGOG12jkCIeDc7Wlt/8=; b=Yv8ubVgVqQT4HFlhNndK6lQ6y+v8bmLlO+WaOKnLBzFMPS893b7/ZXriOStzNLEG0P WvwTDo+gV+A660Q1DaQ/epA7E6bwf0YvdI+CxbJ51s3eLHV6cUM6BjppgyqBTGXH2Wll 1hypTwYIob/6TO2/OihNOV/r/kLkUsVRB3cXuVzeYSce9x59Uya2F23nrnleRGwG46// n2qzVN3lMrMBOMIZFy+v9HR5CyyHJg4P1lSB7b2A1kqQdSHU3Kp/meZ2GdDCt043D6rq iFshNGB8vlQjGVhBVL3SESNbuJ//jRJIRhEyzagwhgd+Tdzact0QL3MuTmbeunxAFiZu b2Gg== X-Gm-Message-State: AC+VfDyKDM45bzcrUvcXnUYl7gbJ5AIGuGMKQ2Yk9eVKxCj/OnWu+K/y qFUpPU+VGQlUj7pOc6Ch5AjrbY6lBc3BnjI9nuKWng== X-Google-Smtp-Source: ACHHUZ7d5JWfSNWsxvVeMfgSfcSNrhyuY7iAruW3GZKgGLi7IqhJUmVRfxgnvtTTQ3m7bNaDrS4BtK5892+2MJENw9E= X-Received: by 2002:a05:622a:1982:b0:3de:1aaa:42f5 with SMTP id u2-20020a05622a198200b003de1aaa42f5mr563644qtc.15.1683946681184; Fri, 12 May 2023 19:58:01 -0700 (PDT) MIME-Version: 1.0 References: <20230428004726.3217666-1-maskray@google.com> In-Reply-To: From: Fangrui Song Date: Fri, 12 May 2023 19:57:50 -0700 Message-ID: Subject: Re: [PATCH] i386: Allow -mlarge-data-threshold with -mcmodel=large To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org, Jan Hubicka Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-23.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,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,USER_IN_DEF_SPF_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 List-Id: On Wed, May 10, 2023 at 2:58=E2=80=AFAM Uros Bizjak wro= te: > > On Fri, Apr 28, 2023 at 2:47=E2=80=AFAM Fangrui Song = wrote: > > > > When using -mcmodel=3Dmedium, 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=3Dsmall object fil= es. > > > > However, when using -mcmodel=3Dlarge, -mlarge-data-threshold doesn't ap= ply. This > > means that the .rodata/.data/.bss sections may cause relocation overflo= w > > pressure on sections in -mcmodel=3Dsmall object files. > > > > This patch allows -mcmodel=3Dlarge to generate .l* sections. > > The x86_64 psABI does not specify how -mlarge-threshold is handled > with -mcmodel=3Dlarge and it also doesn't mention that -mcmodel=3Dlarge > inherits handling from -mcmodel=3Dmedium. The ABI does say that the > -mcmodel=3Dlarge 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=3Dlarge > and IMO, the introduction of -mlarge-threshold with -mcmodel=3Dlarge > 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. Thank you for the suggestion. I started https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU ("Large data sections for the large code model") and created https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/42/ to clarify large data sections usage. In the psABI, "Table 4.4: Additional Special Sections for the Large Code Model" lists the large data sections. Perhaps it should be "Table 4.4: Additional Special Sections for the Medium and Large Code Models". > > > > 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 !=3D CM_MEDIUM && ix86_cmodel !=3D CM_MEDIUM_PIC) > > + if (ix86_cmodel !=3D CM_MEDIUM && ix86_cmodel !=3D CM_MEDIUM_PIC && > > + ix86_cmodel !=3D CM_LARGE && ix86_cmodel !=3D CM_LARGE_PIC) > > return false; > > > > if (exp =3D=3D 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 =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PI= C) > > - && size > (unsigned int)ix86_section_threshold) > > + if ((ix86_cmodel =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PI= C || > > + ix86_cmodel =3D=3D CM_LARGE || ix86_cmodel =3D=3D 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 =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PI= C) > > - && size > (unsigned int)ix86_section_threshold) > > - switch_to_section (get_named_section (decl, ".lbss", 0)); > > + if ((ix86_cmodel =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PI= C || > > + ix86_cmodel =3D=3D CM_LARGE || ix86_cmodel =3D=3D 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=3D > > Target RejectNegative Joined UInteger Var(ix86_section_threshold) Init= (DEFAULT_LARGE_SECTION_THRESHOLD) > > --mlarge-data-threshold=3D Data greater than given thres= hold will go into .ldata section in x86-64 medium model. > > +-mlarge-data-threshold=3D Data greater than given thres= hold will go into a large data section in x86-64 medium and large code mode= ls. > > > > mcmodel=3D > > 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 def= ault. > > > > @opindex mlarge-data-threshold > > @item -mlarge-data-threshold=3D@var{threshold} > > -When @option{-mcmodel=3Dmedium} 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=3Dmedium} or @option{-mcmodel=3Dlarge} is specif= ied, 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=3Dlarge -mlarge-data-threshold=3D4" } */ > > +/* { 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[] =3D "abc", rodata_b[] =3D "abcd"; > > +char data_a[4] =3D {1}, data_b[5] =3D {1}; > > +char bss_a[4], bss_b[5]; > > -- > > 2.40.1.495.gc816e09b53d-goog > > --=20 =E5=AE=8B=E6=96=B9=E7=9D=BF