public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large
@ 2023-08-01 19:51 Fangrui Song
  2023-08-22  7:19 ` Fangrui Song
  2023-10-16 17:12 ` Uros Bizjak
  0 siblings, 2 replies; 9+ messages in thread
From: Fangrui Song @ 2023-08-01 19:51 UTC (permalink / raw)
  To: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz, Uros Bizjak
  Cc: 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 <maskray@google.com>

---
Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)
@@ -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 == 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);
@@ -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 == 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 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=
 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 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 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 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=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.41.0.585.gd2178a4bd4-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-08-01 19:51 [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large Fangrui Song
@ 2023-08-22  7:19 ` Fangrui Song
  2023-09-13 18:19   ` Fangrui Song
  2023-10-16 17:12 ` Uros Bizjak
  1 sibling, 1 reply; 9+ messages in thread
From: Fangrui Song @ 2023-08-22  7:19 UTC (permalink / raw)
  To: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz, Uros Bizjak

On Tue, Aug 1, 2023 at 12:51 PM Fangrui Song <maskray@google.com> wrote:
>
> 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 <maskray@google.com>
>
> ---
> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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
>
> [...]

Ping:)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-08-22  7:19 ` Fangrui Song
@ 2023-09-13 18:19   ` Fangrui Song
  2023-09-27 17:54     ` Fangrui Song
  0 siblings, 1 reply; 9+ messages in thread
From: Fangrui Song @ 2023-09-13 18:19 UTC (permalink / raw)
  To: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz, Uros Bizjak

On Tue, Aug 22, 2023 at 12:19 AM Fangrui Song <maskray@google.com> wrote:
>
> On Tue, Aug 1, 2023 at 12:51 PM Fangrui Song <maskray@google.com> wrote:
> >
> > 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 <maskray@google.com>
> >
> > ---
> > Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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
> >
> > [...]
>
> Ping:)

Ping:) https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625993.html

(I don't have write access to gcc.)


-- 
宋方睿

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-09-13 18:19   ` Fangrui Song
@ 2023-09-27 17:54     ` Fangrui Song
  0 siblings, 0 replies; 9+ messages in thread
From: Fangrui Song @ 2023-09-27 17:54 UTC (permalink / raw)
  To: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz, Uros Bizjak

On Wed, Sep 13, 2023 at 11:19 AM Fangrui Song <maskray@google.com> wrote:
>
> On Tue, Aug 22, 2023 at 12:19 AM Fangrui Song <maskray@google.com> wrote:
> >
> > On Tue, Aug 1, 2023 at 12:51 PM Fangrui Song <maskray@google.com> wrote:
> > >
> > > 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 <maskray@google.com>
> > >
> > > ---
> > > Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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
> > >
> > > [...]
> >
> > Ping:)
>
> Ping:) https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625993.html
>
> (I don't have write access to gcc.)
>
>
> --
> 宋方睿

Ping? :) https://gcc.gnu.org/pipermail/gcc-patches/2023-August/625993.html

(I don't have write access to gcc.)


-- 
宋方睿

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-08-01 19:51 [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large Fangrui Song
  2023-08-22  7:19 ` Fangrui Song
@ 2023-10-16 17:12 ` Uros Bizjak
  2023-10-16 18:24   ` [PATCH v5] " Fangrui Song
  1 sibling, 1 reply; 9+ messages in thread
From: Uros Bizjak @ 2023-10-16 17:12 UTC (permalink / raw)
  To: Fangrui Song
  Cc: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz

On Tue, Aug 1, 2023 at 9:51 PM Fangrui Song <maskray@google.com> wrote:
>
> 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 <maskray@google.com>
>
> ---
> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)

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 == 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 == 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)

... 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 == 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)

... 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=
>  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 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 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 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=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.41.0.585.gd2178a4bd4-goog
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-10-16 17:12 ` Uros Bizjak
@ 2023-10-16 18:24   ` Fangrui Song
  2023-10-16 19:10     ` Uros Bizjak
  0 siblings, 1 reply; 9+ messages in thread
From: Fangrui Song @ 2023-10-16 18:24 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz

On 2023-10-16, Uros Bizjak wrote:
>On Tue, Aug 1, 2023 at 9:51 PM Fangrui Song <maskray@google.com> wrote:
>>
>> 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 <maskray@google.com>
>>
>> ---
>> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)
>
>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 == 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 == 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)
>
>... 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 == 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)
>
>... and here.
>
>OK with these formatting changes.
>
>Thanks,
>Uros.

Thank you for the review!
Posted PATCH v5 https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633153.html
with the formatting.

I don't have write access to the gcc repository:)

(Hmmm... in emacs, C-c . gnu RET C-M-\  doesn't fix the && || formatting errors.)

>> +    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=
>>  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 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 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 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=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.41.0.585.gd2178a4bd4-goog
>>

 From da49445a50c57b583201e3fb48fa91781b9ec761 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Thu, 27 Apr 2023 12:29:31 -0700
Subject: [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large

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 <maskray@google.com>

---
Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 .

Changes from v4 (https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633145.html)
* "When you split an expression into multiple lines, split it before an operator, not after one."
---
  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(-)
  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 8251b67e2d6..641e7680335 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 b8382c48099..0c3b8f4b621 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 eb714d18511..50745a3a195 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -33390,9 +33390,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 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=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.42.0.655.g421f12c284-goog


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-10-16 18:24   ` [PATCH v5] " Fangrui Song
@ 2023-10-16 19:10     ` Uros Bizjak
  2023-10-16 19:58       ` Fangrui Song
  0 siblings, 1 reply; 9+ messages in thread
From: Uros Bizjak @ 2023-10-16 19:10 UTC (permalink / raw)
  To: Fangrui Song
  Cc: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz

On Mon, Oct 16, 2023 at 8:24 PM Fangrui Song <maskray@google.com> wrote:
>
> On 2023-10-16, Uros Bizjak wrote:
> >On Tue, Aug 1, 2023 at 9:51 PM Fangrui Song <maskray@google.com> wrote:
> >>
> >> 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 <maskray@google.com>
> >>
> >> ---
> >> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)
> >
> >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 == 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 == 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)
> >
> >... 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 == 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)
> >
> >... and here.
> >
> >OK with these formatting changes.
> >
> >Thanks,
> >Uros.
>
> Thank you for the review!
> Posted PATCH v5 https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633153.html
> with the formatting.
>
> I don't have write access to the gcc repository:)

Please provide the ChangeLog entry (see [1,2]) and I'll commit the
patch for you.

[1] https://gcc.gnu.org/contribute.html
[2] https://gcc.gnu.org/codingconventions.html#ChangeLogs

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-10-16 19:10     ` Uros Bizjak
@ 2023-10-16 19:58       ` Fangrui Song
  2023-10-16 21:46         ` Uros Bizjak
  0 siblings, 1 reply; 9+ messages in thread
From: Fangrui Song @ 2023-10-16 19:58 UTC (permalink / raw)
  To: Uros Bizjak
  Cc: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz

On Mon, Oct 16, 2023 at 12:10 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Mon, Oct 16, 2023 at 8:24 PM Fangrui Song <maskray@google.com> wrote:
> >
> > On 2023-10-16, Uros Bizjak wrote:
> > >On Tue, Aug 1, 2023 at 9:51 PM Fangrui Song <maskray@google.com> wrote:
> > >>
> > >> 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 <maskray@google.com>
> > >>
> > >> ---
> > >> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)
> > >
> > >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 == 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 == 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)
> > >
> > >... 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 == 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)
> > >
> > >... and here.
> > >
> > >OK with these formatting changes.
> > >
> > >Thanks,
> > >Uros.
> >
> > Thank you for the review!
> > Posted PATCH v5 https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633153.html
> > with the formatting.
> >
> > I don't have write access to the gcc repository:)
>
> Please provide the ChangeLog entry (see [1,2]) and I'll commit the
> patch for you.
>
> [1] https://gcc.gnu.org/contribute.html
> [2] https://gcc.gnu.org/codingconventions.html#ChangeLogs
>
> Thanks,
> Uros.

It's so kind of you! Attached the ChangeLog:

gcc/
    * 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/:
    * gcc.target/i386/large-data.c: New test.


-- 
宋方睿

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] i386: Allow -mlarge-data-threshold with -mcmodel=large
  2023-10-16 19:58       ` Fangrui Song
@ 2023-10-16 21:46         ` Uros Bizjak
  0 siblings, 0 replies; 9+ messages in thread
From: Uros Bizjak @ 2023-10-16 21:46 UTC (permalink / raw)
  To: Fangrui Song
  Cc: gcc-patches, Florian Weimer, H.J. Lu, Jan Beulich, Jan Hubicka,
	Michael Matz

On Mon, Oct 16, 2023 at 9:58 PM Fangrui Song <maskray@google.com> wrote:
>
> On Mon, Oct 16, 2023 at 12:10 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Mon, Oct 16, 2023 at 8:24 PM Fangrui Song <maskray@google.com> wrote:
> > >
> > > On 2023-10-16, Uros Bizjak wrote:
> > > >On Tue, Aug 1, 2023 at 9:51 PM Fangrui Song <maskray@google.com> wrote:
> > > >>
> > > >> 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 <maskray@google.com>
> > > >>
> > > >> ---
> > > >> Changes from v1 (https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616947.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 != 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)
> > > >
> > > >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 == 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 == 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)
> > > >
> > > >... 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 == 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)
> > > >
> > > >... and here.
> > > >
> > > >OK with these formatting changes.
> > > >
> > > >Thanks,
> > > >Uros.
> > >
> > > Thank you for the review!
> > > Posted PATCH v5 https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633153.html
> > > with the formatting.
> > >
> > > I don't have write access to the gcc repository:)
> >
> > Please provide the ChangeLog entry (see [1,2]) and I'll commit the
> > patch for you.
> >
> > [1] https://gcc.gnu.org/contribute.html
> > [2] https://gcc.gnu.org/codingconventions.html#ChangeLogs
> >
> > Thanks,
> > Uros.
>
> It's so kind of you! Attached the ChangeLog:
>
> gcc/
>     * 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/:
>     * gcc.target/i386/large-data.c: New test.

Committed as [1].

[1] https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=1a64156c7e25813afa8d4d8bbeb0590cad91cf55

Uros.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-10-16 21:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01 19:51 [PATCH v4] i386: Allow -mlarge-data-threshold with -mcmodel=large Fangrui Song
2023-08-22  7:19 ` Fangrui Song
2023-09-13 18:19   ` Fangrui Song
2023-09-27 17:54     ` Fangrui Song
2023-10-16 17:12 ` Uros Bizjak
2023-10-16 18:24   ` [PATCH v5] " Fangrui Song
2023-10-16 19:10     ` Uros Bizjak
2023-10-16 19:58       ` Fangrui Song
2023-10-16 21:46         ` Uros Bizjak

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).