From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1363) id B60313858C2A; Mon, 16 Oct 2023 21:44:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B60313858C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697492673; bh=Yaa77+Q188jDtNKt/0lMsu41JygS2+eMxFJJs/emXAM=; h=From:To:Subject:Date:From; b=NSCn4flTJ76hcRb6fjgpEz4wemtKC164p3ZsS0hu+AsYOm+FwjUKaWEF9PEuD1R3N GdvKhbAxsNVMvdci6TjZ3s36S/xk8kHl5+4JDrCalpw94NJuIzqXEOi1F94AQUYUcr T6lBnCWukR8TQD96JPKgVLLQKMrBLuADIIsAzXPQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Uros Bizjak To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4667] i386: Allow -mlarge-data-threshold with -mcmodel=large X-Act-Checkin: gcc X-Git-Author: Uros Bizjak X-Git-Refname: refs/heads/master X-Git-Oldrev: 328745607c5d403a1c7b6bc2ecaa1574ee42122f X-Git-Newrev: 1a64156c7e25813afa8d4d8bbeb0590cad91cf55 Message-Id: <20231016214433.B60313858C2A@sourceware.org> Date: Mon, 16 Oct 2023 21:44:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1a64156c7e25813afa8d4d8bbeb0590cad91cf55 commit r14-4667-g1a64156c7e25813afa8d4d8bbeb0590cad91cf55 Author: Uros Bizjak Date: Mon Oct 16 22:22:28 2023 +0200 i386: Allow -mlarge-data-threshold with -mcmodel=large From: Fangrui Song 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 gcc/ChangeLog: * config/i386/i386.cc (ix86_can_inline_p): Handle CM_LARGE and CM_LARGE_PIC. (x86_elf_aligned_decl_common): Ditto. (x86_output_aligned_bss): Ditto. * config/i386/i386.opt: Update doc for -mlarge-data-threshold=. * doc/invoke.texi: Update doc for -mlarge-data-threshold=. gcc/testsuite/ChangeLog: * gcc.target/i386/large-data.c: New test. Diff: --- gcc/config/i386/i386.cc | 9 ++++++--- gcc/config/i386/i386.opt | 2 +- gcc/doc/invoke.texi | 6 +++--- gcc/testsuite/gcc.target/i386/large-data.c | 13 +++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 8251b67e2d6d..641e76803355 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -663,7 +663,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) @@ -874,7 +875,8 @@ 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) + 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)); @@ -895,7 +897,8 @@ 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) + 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 diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index b8382c480998..0c3b8f4b6218 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 a26dc5aae69f..2a500c1baeea 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -33398,9 +33398,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 000000000000..bdd4acd30b8b --- /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];