From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 6346C385C6FB for ; Mon, 16 Oct 2023 17:12:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6346C385C6FB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6346C385C6FB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697476338; cv=none; b=HJxTpDQf2MLtGC5gB0IR9Q88hFeAC16A0GSTNHIE1v6rCFNzkejW+WUgSKjP4h3uVYMIAj7llOJBmsRJBECyyBvzwxUZy3Lx6/EhV2WwwLzUSHR6LkVU68VOgLrqmFz2OOvTkCIpMmqlcUPFkxSsUg86mSarY7/2kRfi4bY5PXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697476338; c=relaxed/simple; bh=eUBJqgtNtUdHD12e8DkhFuUWkds+SX5/aVXS93ZHxCE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=vbRifssTLrbJ9xfxFOC0d9+RksLwLE+pUC08gjQL+kPPjPzPE3ghE5BoMhUntra8je9B96iGHRI2RfNXm9sNP3vCZAFF0RsZnTMB2rSqA1l6YjMgeyXvGxpZUSuGnAOdJa/Ue2iV/4xYNKKyz42RMW7ZXSOagGchaqk4Yn9bARM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-53df747cfe5so8530664a12.2 for ; Mon, 16 Oct 2023 10:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697476335; x=1698081135; darn=gcc.gnu.org; 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=hVdye0Fp8pRLWJFe2ptcokEybm8ZSh1QJR2l76ZlqzQ=; b=MZqCiBEZEiTCQg1xjr5uTElhA67WDqvyl0C8M2xJBBaiucXLDcDfJuXURwLwPHzziI Tm9taKuRRY1zwKR8cmjFbAaltlGd/2Fvfp27+P+5g+7UfvazkZHccs1CveW4Klmjo4c7 MzLjaIGDfPO4f3dRiESUsTeL07sXfTg1iAo2mJXB2CBavyCb6D3WmIeoxOVAreolhEVx Nzej654mHpL4Z5AjqE9P30cLu8zDUTdIXY7MND+B6+ye4V3L5qYEWFPXbCPTG03/TwLI w7bQv7ss9yhBmG6NV2qbt2H07KK84oaa3A3YtwtlDOcFBPm9pTKsST7wFKiiKZ8NhIZf K1Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697476335; x=1698081135; 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=hVdye0Fp8pRLWJFe2ptcokEybm8ZSh1QJR2l76ZlqzQ=; b=cbYgsjqZclAr/J0Iv1bdk2ckzCykJtwiV7w2MAgsVE1Z7jjj7VcCHP3DeqVTFq76Qy W0A7PY6qpDsWtOQONiYgPZFEHxjMbej+8lq4PrCsW4vpGf3wiiYotyKUzGSOuTks8Kwn +b5YkNGxlFhTJR3DI5OvRefOrylXTB7tE2bC+nZY+ss0hV585/W0vd9pwcWEWcb7Mcw5 XQPCpSiHXqoTyBXgKO9l6Rn7q6vXwXCK/FZO7c16yiadujU0IEKeX6ojeJfej4kvF509 tCtOdVM6HvEyZJwH2QQBhjrS7/qHWmtAdVodfENB7VPLU9W05qtOeHBmuLGHgQBooFCP Wjvw== X-Gm-Message-State: AOJu0Yz2DxLmnFMlAa3FhJ36jA4NXq5F2R1eDwNKrLoS//Ib2c020oU6 6LwSarg134Mwsnu2TNYlWu+z9F+VKUCDoInZI5I= X-Google-Smtp-Source: AGHT+IHwBQGpSKPz/FJStLfXSC5EUKX99hlSlbnUhfeJvTKM3NWRGF195xJ3DpTVTn8/dcgki/P7BEtdMoQO85nsIwk= X-Received: by 2002:a50:c058:0:b0:53e:455c:6273 with SMTP id u24-20020a50c058000000b0053e455c6273mr7847804edd.2.1697476334815; Mon, 16 Oct 2023 10:12:14 -0700 (PDT) MIME-Version: 1.0 References: <20230801195104.2183011-1-maskray@google.com> In-Reply-To: <20230801195104.2183011-1-maskray@google.com> From: Uros Bizjak Date: Mon, 16 Oct 2023 19:12:03 +0200 Message-ID: Subject: Re: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large To: Fangrui Song Cc: gcc-patches@gcc.gnu.org, Florian Weimer , "H.J. Lu" , Jan Beulich , Jan Hubicka , Michael Matz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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 Tue, Aug 1, 2023 at 9:51=E2=80=AFPM Fangrui Song wr= ote: > > When using -mcmodel=3Dmedium, 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=3Dsmall= . > > However, when using -mcmodel=3Dlarge, -mlarge-data-threshold doesn't > apply. This means that the .rodata/.data/.bss sections may exert > relocation overflow pressure on sections in -mcmodel=3Dsmall object files= . > > This patch allows -mcmodel=3Dlarge 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/616= 947.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 !=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) Please split multi-line expression before the operator, not after it, as instructed in GNU Coding Standards [1] ... [1] https://www.gnu.org/prep/standards/html_node/Formatting.html > return false; > > if (exp =3D=3D 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 =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PIC) > - && size > (unsigned int)ix86_section_threshold) > + if ((ix86_cmodel =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PIC = || > + ix86_cmodel =3D=3D CM_LARGE || ix86_cmodel =3D=3D CM_LARGE_PIC) && > + size > (unsigned int)ix86_section_threshold) ... also here ... > { > 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 =3D=3D CM_MEDIUM || ix86_cmodel =3D=3D CM_MEDIUM_PIC) > - && 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_PIC = || > + ix86_cmodel =3D=3D CM_LARGE || ix86_cmodel =3D=3D CM_LARGE_PIC) &= & > + size > (unsigned int)ix86_section_threshold) ... and here. OK with these formatting changes. Thanks, Uros. > + 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=3D > Target RejectNegative Joined UInteger Var(ix86_section_threshold) Init(D= EFAULT_LARGE_SECTION_THRESHOLD) > --mlarge-data-threshold=3D Data greater than given thresho= ld will go into .ldata section in x86-64 medium model. > +-mlarge-data-threshold=3D Data greater than given thresho= ld will go into a large data section in x86-64 medium and large code models= . > > 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 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 defaul= t. > > @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 b= e the > -same across all objects linked into the binary, and defaults to 65535. > +When @option{-mcmodel=3Dmedium} or @option{-mcmodel=3Dlarge} is specifie= d, data > +objects larger than @var{threshold} are placed in large data sections. T= he > +default is 65535. > > @opindex mrtd > @item -mrtd > diff --git a/gcc/testsuite/gcc.target/i386/large-data.c b/gcc/testsuite/g= cc.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=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.41.0.585.gd2178a4bd4-goog >