unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
@ 2022-11-23  7:09 caiyinyu
  2022-11-23  8:21 ` Xi Ruoyao via Libc-alpha
  2022-11-23 10:31 ` Florian Weimer via Libc-alpha
  0 siblings, 2 replies; 7+ messages in thread
From: caiyinyu @ 2022-11-23  7:09 UTC (permalink / raw)
  To: adhemerval.zanella; +Cc: libc-alpha, i.swmail, xry111, xuchenghua

From: Chenghua Xu <xuchenghua@loongson.cn>

This patch is used to fix address out-of-bounds error when building
firefox.
---
 sysdeps/loongarch/Makefile               | 18 ++++++++++++++++++
 sysdeps/loongarch/at_quick_exit.c        |  1 +
 sysdeps/loongarch/atexit.c               |  1 +
 sysdeps/loongarch/elf-init.c             |  1 +
 sysdeps/loongarch/fstat.c                |  1 +
 sysdeps/loongarch/fstat64.c              |  1 +
 sysdeps/loongarch/fstatat.c              |  1 +
 sysdeps/loongarch/fstatat64.c            |  1 +
 sysdeps/loongarch/lstat.c                |  1 +
 sysdeps/loongarch/lstat64.c              |  1 +
 sysdeps/loongarch/mknod.c                |  1 +
 sysdeps/loongarch/mknodat.c              |  1 +
 sysdeps/loongarch/pthread_atfork.c       |  1 +
 sysdeps/loongarch/stack_chk_fail_local.c |  1 +
 sysdeps/loongarch/stat.c                 |  1 +
 sysdeps/loongarch/stat64.c               |  1 +
 sysdeps/loongarch/warning-nop.c          |  1 +
 17 files changed, 34 insertions(+)
 create mode 100644 sysdeps/loongarch/at_quick_exit.c
 create mode 100644 sysdeps/loongarch/atexit.c
 create mode 100644 sysdeps/loongarch/elf-init.c
 create mode 100644 sysdeps/loongarch/fstat.c
 create mode 100644 sysdeps/loongarch/fstat64.c
 create mode 100644 sysdeps/loongarch/fstatat.c
 create mode 100644 sysdeps/loongarch/fstatat64.c
 create mode 100644 sysdeps/loongarch/lstat.c
 create mode 100644 sysdeps/loongarch/lstat64.c
 create mode 100644 sysdeps/loongarch/mknod.c
 create mode 100644 sysdeps/loongarch/mknodat.c
 create mode 100644 sysdeps/loongarch/pthread_atfork.c
 create mode 100644 sysdeps/loongarch/stack_chk_fail_local.c
 create mode 100644 sysdeps/loongarch/stat.c
 create mode 100644 sysdeps/loongarch/stat64.c
 create mode 100644 sysdeps/loongarch/warning-nop.c

diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
index 746d4c2c8f..ccda57e2d4 100644
--- a/sysdeps/loongarch/Makefile
+++ b/sysdeps/loongarch/Makefile
@@ -5,3 +5,21 @@ endif
 # LoongArch's assembler also needs to know about PIC as it changes the
 # definition of some assembler macros.
 ASFLAGS-.os += $(pic-ccflag)
+
+CFLAGS-elf-init.oS += -mcmodel=medium
+CFLAGS-atexit.oS += -mcmodel=medium
+CFLAGS-at_quick_exit.oS += -mcmodel=medium
+CFLAGS-stat.oS += -mcmodel=medium
+CFLAGS-fstat.oS += -mcmodel=medium
+CFLAGS-lstat.oS += -mcmodel=medium
+CFLAGS-stat64.oS += -mcmodel=medium
+CFLAGS-fstat64.oS += -mcmodel=medium
+CFLAGS-lstat64.oS += -mcmodel=medium
+CFLAGS-fstatat.oS += -mcmodel=medium
+CFLAGS-fstatat64.oS += -mcmodel=medium
+CFLAGS-mknod.oS += -mcmodel=medium
+CFLAGS-mknodat.oS += -mcmodel=medium
+CFLAGS-pthread_atfork.oS += -mcmodel=medium
+CFLAGS-warning-nop.oS += -mcmodel=medium
+CFLAGS-stack_chk_fail_local.oS += -mcmodel=medium
+ 
diff --git a/sysdeps/loongarch/at_quick_exit.c b/sysdeps/loongarch/at_quick_exit.c
new file mode 100644
index 0000000000..8d4b44a7eb
--- /dev/null
+++ b/sysdeps/loongarch/at_quick_exit.c
@@ -0,0 +1 @@
+#include <stdlib/at_quick_exit.c>
diff --git a/sysdeps/loongarch/atexit.c b/sysdeps/loongarch/atexit.c
new file mode 100644
index 0000000000..fc055a4851
--- /dev/null
+++ b/sysdeps/loongarch/atexit.c
@@ -0,0 +1 @@
+#include <stdlib/atexit.c>
diff --git a/sysdeps/loongarch/elf-init.c b/sysdeps/loongarch/elf-init.c
new file mode 100644
index 0000000000..5f261a9d16
--- /dev/null
+++ b/sysdeps/loongarch/elf-init.c
@@ -0,0 +1 @@
+#include <sysdeps/init_array/elf-init.c>
diff --git a/sysdeps/loongarch/fstat.c b/sysdeps/loongarch/fstat.c
new file mode 100644
index 0000000000..c4504eebe7
--- /dev/null
+++ b/sysdeps/loongarch/fstat.c
@@ -0,0 +1 @@
+#include <io/fstat.c>
diff --git a/sysdeps/loongarch/fstat64.c b/sysdeps/loongarch/fstat64.c
new file mode 100644
index 0000000000..143ca2b051
--- /dev/null
+++ b/sysdeps/loongarch/fstat64.c
@@ -0,0 +1 @@
+#include <io/fstat64.c>
diff --git a/sysdeps/loongarch/fstatat.c b/sysdeps/loongarch/fstatat.c
new file mode 100644
index 0000000000..0b0a334241
--- /dev/null
+++ b/sysdeps/loongarch/fstatat.c
@@ -0,0 +1 @@
+#include <io/fstatat.c>
diff --git a/sysdeps/loongarch/fstatat64.c b/sysdeps/loongarch/fstatat64.c
new file mode 100644
index 0000000000..e82b927477
--- /dev/null
+++ b/sysdeps/loongarch/fstatat64.c
@@ -0,0 +1 @@
+#include <io/fstatat64.c>
diff --git a/sysdeps/loongarch/lstat.c b/sysdeps/loongarch/lstat.c
new file mode 100644
index 0000000000..f47a56aff8
--- /dev/null
+++ b/sysdeps/loongarch/lstat.c
@@ -0,0 +1 @@
+#include <io/lstat.c>
diff --git a/sysdeps/loongarch/lstat64.c b/sysdeps/loongarch/lstat64.c
new file mode 100644
index 0000000000..d681165600
--- /dev/null
+++ b/sysdeps/loongarch/lstat64.c
@@ -0,0 +1 @@
+#include <io/lstat64.c>
diff --git a/sysdeps/loongarch/mknod.c b/sysdeps/loongarch/mknod.c
new file mode 100644
index 0000000000..1ed3681ffe
--- /dev/null
+++ b/sysdeps/loongarch/mknod.c
@@ -0,0 +1 @@
+#include <io/mknod.c>
diff --git a/sysdeps/loongarch/mknodat.c b/sysdeps/loongarch/mknodat.c
new file mode 100644
index 0000000000..82bc6ee637
--- /dev/null
+++ b/sysdeps/loongarch/mknodat.c
@@ -0,0 +1 @@
+#include <io/mknodat.c>
diff --git a/sysdeps/loongarch/pthread_atfork.c b/sysdeps/loongarch/pthread_atfork.c
new file mode 100644
index 0000000000..0f01d80512
--- /dev/null
+++ b/sysdeps/loongarch/pthread_atfork.c
@@ -0,0 +1 @@
+#include <nptl/pthread_atfork.c>
diff --git a/sysdeps/loongarch/stack_chk_fail_local.c b/sysdeps/loongarch/stack_chk_fail_local.c
new file mode 100644
index 0000000000..305871fbc0
--- /dev/null
+++ b/sysdeps/loongarch/stack_chk_fail_local.c
@@ -0,0 +1 @@
+#include <debug/stack_chk_fail_local.c>
diff --git a/sysdeps/loongarch/stat.c b/sysdeps/loongarch/stat.c
new file mode 100644
index 0000000000..36461b870e
--- /dev/null
+++ b/sysdeps/loongarch/stat.c
@@ -0,0 +1 @@
+#include <io/stat.c>
diff --git a/sysdeps/loongarch/stat64.c b/sysdeps/loongarch/stat64.c
new file mode 100644
index 0000000000..0897282e6a
--- /dev/null
+++ b/sysdeps/loongarch/stat64.c
@@ -0,0 +1 @@
+#include <io/stat64.c>
diff --git a/sysdeps/loongarch/warning-nop.c b/sysdeps/loongarch/warning-nop.c
new file mode 100644
index 0000000000..b76aae79f9
--- /dev/null
+++ b/sysdeps/loongarch/warning-nop.c
@@ -0,0 +1 @@
+#include <debug/warning-nop.c>
-- 
2.31.1


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

* Re: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
  2022-11-23  7:09 [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a caiyinyu
@ 2022-11-23  8:21 ` Xi Ruoyao via Libc-alpha
  2022-11-23 10:31 ` Florian Weimer via Libc-alpha
  1 sibling, 0 replies; 7+ messages in thread
From: Xi Ruoyao via Libc-alpha @ 2022-11-23  8:21 UTC (permalink / raw)
  To: caiyinyu, adhemerval.zanella; +Cc: libc-alpha, i.swmail, xuchenghua

On Wed, 2022-11-23 at 15:09 +0800, caiyinyu wrote:
> From: Chenghua Xu <xuchenghua@loongson.cn>
> 
> This patch is used to fix address out-of-bounds error when building
> firefox.

This can be much simpler:

diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
index 746d4c2c8f..3822eb3df1 100644
--- a/sysdeps/loongarch/Makefile
+++ b/sysdeps/loongarch/Makefile
@@ -5,3 +5,7 @@ endif
 # LoongArch's assembler also needs to know about PIC as it changes the
 # definition of some assembler macros.
 ASFLAGS-.os += $(pic-ccflag)
+
+# All the objects in lib*_nonshared.a need to be compiled with medium code
+# model or large applications may fail to link.
+CFLAGS-.oS += -mcmodel=medium

And we need a check in configure.ac: GCC 12 does not support -
mcmodel=medium.

A remaining question: should we use -mcmodel=extreme here?  I guess one
day we'll see an extra large application which cannot be linked with
even medium code model...

> ---
>  sysdeps/loongarch/Makefile               | 18 ++++++++++++++++++
>  sysdeps/loongarch/at_quick_exit.c        |  1 +
>  sysdeps/loongarch/atexit.c               |  1 +
>  sysdeps/loongarch/elf-init.c             |  1 +
>  sysdeps/loongarch/fstat.c                |  1 +
>  sysdeps/loongarch/fstat64.c              |  1 +
>  sysdeps/loongarch/fstatat.c              |  1 +
>  sysdeps/loongarch/fstatat64.c            |  1 +
>  sysdeps/loongarch/lstat.c                |  1 +
>  sysdeps/loongarch/lstat64.c              |  1 +
>  sysdeps/loongarch/mknod.c                |  1 +
>  sysdeps/loongarch/mknodat.c              |  1 +
>  sysdeps/loongarch/pthread_atfork.c       |  1 +
>  sysdeps/loongarch/stack_chk_fail_local.c |  1 +
>  sysdeps/loongarch/stat.c                 |  1 +
>  sysdeps/loongarch/stat64.c               |  1 +
>  sysdeps/loongarch/warning-nop.c          |  1 +
>  17 files changed, 34 insertions(+)
>  create mode 100644 sysdeps/loongarch/at_quick_exit.c
>  create mode 100644 sysdeps/loongarch/atexit.c
>  create mode 100644 sysdeps/loongarch/elf-init.c
>  create mode 100644 sysdeps/loongarch/fstat.c
>  create mode 100644 sysdeps/loongarch/fstat64.c
>  create mode 100644 sysdeps/loongarch/fstatat.c
>  create mode 100644 sysdeps/loongarch/fstatat64.c
>  create mode 100644 sysdeps/loongarch/lstat.c
>  create mode 100644 sysdeps/loongarch/lstat64.c
>  create mode 100644 sysdeps/loongarch/mknod.c
>  create mode 100644 sysdeps/loongarch/mknodat.c
>  create mode 100644 sysdeps/loongarch/pthread_atfork.c
>  create mode 100644 sysdeps/loongarch/stack_chk_fail_local.c
>  create mode 100644 sysdeps/loongarch/stat.c
>  create mode 100644 sysdeps/loongarch/stat64.c
>  create mode 100644 sysdeps/loongarch/warning-nop.c
> 
> diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
> index 746d4c2c8f..ccda57e2d4 100644
> --- a/sysdeps/loongarch/Makefile
> +++ b/sysdeps/loongarch/Makefile
> @@ -5,3 +5,21 @@ endif
>  # LoongArch's assembler also needs to know about PIC as it changes
> the
>  # definition of some assembler macros.
>  ASFLAGS-.os += $(pic-ccflag)
> +
> +CFLAGS-elf-init.oS += -mcmodel=medium
> +CFLAGS-atexit.oS += -mcmodel=medium
> +CFLAGS-at_quick_exit.oS += -mcmodel=medium
> +CFLAGS-stat.oS += -mcmodel=medium
> +CFLAGS-fstat.oS += -mcmodel=medium
> +CFLAGS-lstat.oS += -mcmodel=medium
> +CFLAGS-stat64.oS += -mcmodel=medium
> +CFLAGS-fstat64.oS += -mcmodel=medium
> +CFLAGS-lstat64.oS += -mcmodel=medium
> +CFLAGS-fstatat.oS += -mcmodel=medium
> +CFLAGS-fstatat64.oS += -mcmodel=medium
> +CFLAGS-mknod.oS += -mcmodel=medium
> +CFLAGS-mknodat.oS += -mcmodel=medium
> +CFLAGS-pthread_atfork.oS += -mcmodel=medium
> +CFLAGS-warning-nop.oS += -mcmodel=medium
> +CFLAGS-stack_chk_fail_local.oS += -mcmodel=medium
> + 
> diff --git a/sysdeps/loongarch/at_quick_exit.c
> b/sysdeps/loongarch/at_quick_exit.c
> new file mode 100644
> index 0000000000..8d4b44a7eb
> --- /dev/null
> +++ b/sysdeps/loongarch/at_quick_exit.c
> @@ -0,0 +1 @@
> +#include <stdlib/at_quick_exit.c>
> diff --git a/sysdeps/loongarch/atexit.c b/sysdeps/loongarch/atexit.c
> new file mode 100644
> index 0000000000..fc055a4851
> --- /dev/null
> +++ b/sysdeps/loongarch/atexit.c
> @@ -0,0 +1 @@
> +#include <stdlib/atexit.c>
> diff --git a/sysdeps/loongarch/elf-init.c b/sysdeps/loongarch/elf-
> init.c
> new file mode 100644
> index 0000000000..5f261a9d16
> --- /dev/null
> +++ b/sysdeps/loongarch/elf-init.c
> @@ -0,0 +1 @@
> +#include <sysdeps/init_array/elf-init.c>
> diff --git a/sysdeps/loongarch/fstat.c b/sysdeps/loongarch/fstat.c
> new file mode 100644
> index 0000000000..c4504eebe7
> --- /dev/null
> +++ b/sysdeps/loongarch/fstat.c
> @@ -0,0 +1 @@
> +#include <io/fstat.c>
> diff --git a/sysdeps/loongarch/fstat64.c b/sysdeps/loongarch/fstat64.c
> new file mode 100644
> index 0000000000..143ca2b051
> --- /dev/null
> +++ b/sysdeps/loongarch/fstat64.c
> @@ -0,0 +1 @@
> +#include <io/fstat64.c>
> diff --git a/sysdeps/loongarch/fstatat.c b/sysdeps/loongarch/fstatat.c
> new file mode 100644
> index 0000000000..0b0a334241
> --- /dev/null
> +++ b/sysdeps/loongarch/fstatat.c
> @@ -0,0 +1 @@
> +#include <io/fstatat.c>
> diff --git a/sysdeps/loongarch/fstatat64.c
> b/sysdeps/loongarch/fstatat64.c
> new file mode 100644
> index 0000000000..e82b927477
> --- /dev/null
> +++ b/sysdeps/loongarch/fstatat64.c
> @@ -0,0 +1 @@
> +#include <io/fstatat64.c>
> diff --git a/sysdeps/loongarch/lstat.c b/sysdeps/loongarch/lstat.c
> new file mode 100644
> index 0000000000..f47a56aff8
> --- /dev/null
> +++ b/sysdeps/loongarch/lstat.c
> @@ -0,0 +1 @@
> +#include <io/lstat.c>
> diff --git a/sysdeps/loongarch/lstat64.c b/sysdeps/loongarch/lstat64.c
> new file mode 100644
> index 0000000000..d681165600
> --- /dev/null
> +++ b/sysdeps/loongarch/lstat64.c
> @@ -0,0 +1 @@
> +#include <io/lstat64.c>
> diff --git a/sysdeps/loongarch/mknod.c b/sysdeps/loongarch/mknod.c
> new file mode 100644
> index 0000000000..1ed3681ffe
> --- /dev/null
> +++ b/sysdeps/loongarch/mknod.c
> @@ -0,0 +1 @@
> +#include <io/mknod.c>
> diff --git a/sysdeps/loongarch/mknodat.c b/sysdeps/loongarch/mknodat.c
> new file mode 100644
> index 0000000000..82bc6ee637
> --- /dev/null
> +++ b/sysdeps/loongarch/mknodat.c
> @@ -0,0 +1 @@
> +#include <io/mknodat.c>
> diff --git a/sysdeps/loongarch/pthread_atfork.c
> b/sysdeps/loongarch/pthread_atfork.c
> new file mode 100644
> index 0000000000..0f01d80512
> --- /dev/null
> +++ b/sysdeps/loongarch/pthread_atfork.c
> @@ -0,0 +1 @@
> +#include <nptl/pthread_atfork.c>
> diff --git a/sysdeps/loongarch/stack_chk_fail_local.c
> b/sysdeps/loongarch/stack_chk_fail_local.c
> new file mode 100644
> index 0000000000..305871fbc0
> --- /dev/null
> +++ b/sysdeps/loongarch/stack_chk_fail_local.c
> @@ -0,0 +1 @@
> +#include <debug/stack_chk_fail_local.c>
> diff --git a/sysdeps/loongarch/stat.c b/sysdeps/loongarch/stat.c
> new file mode 100644
> index 0000000000..36461b870e
> --- /dev/null
> +++ b/sysdeps/loongarch/stat.c
> @@ -0,0 +1 @@
> +#include <io/stat.c>
> diff --git a/sysdeps/loongarch/stat64.c b/sysdeps/loongarch/stat64.c
> new file mode 100644
> index 0000000000..0897282e6a
> --- /dev/null
> +++ b/sysdeps/loongarch/stat64.c
> @@ -0,0 +1 @@
> +#include <io/stat64.c>
> diff --git a/sysdeps/loongarch/warning-nop.c
> b/sysdeps/loongarch/warning-nop.c
> new file mode 100644
> index 0000000000..b76aae79f9
> --- /dev/null
> +++ b/sysdeps/loongarch/warning-nop.c
> @@ -0,0 +1 @@
> +#include <debug/warning-nop.c>

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
  2022-11-23  7:09 [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a caiyinyu
  2022-11-23  8:21 ` Xi Ruoyao via Libc-alpha
@ 2022-11-23 10:31 ` Florian Weimer via Libc-alpha
  2022-11-23 11:18   ` Xi Ruoyao via Libc-alpha
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Weimer via Libc-alpha @ 2022-11-23 10:31 UTC (permalink / raw)
  To: caiyinyu; +Cc: adhemerval.zanella, libc-alpha, i.swmail, xry111, xuchenghua

> From: Chenghua Xu <xuchenghua@loongson.cn>
>
> This patch is used to fix address out-of-bounds error when building
> firefox.

The .c files shouldn't be necessary.  The CFLAGS additions should
perhaps be made subdirectory-specific.  And I think these days,
libc_nonshared.a is much, much small (and we could size it down even
further).

But shouldn't the medium model be the GCC default if it is required for
building applications?

Thanks,
Florian


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

* Re: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
  2022-11-23 10:31 ` Florian Weimer via Libc-alpha
@ 2022-11-23 11:18   ` Xi Ruoyao via Libc-alpha
  2022-11-30  6:55     ` 回复: " caiyinyu
  2022-11-30  7:40     ` [PATCH] LoongArch: Use medium cmodel " Florian Weimer via Libc-alpha
  0 siblings, 2 replies; 7+ messages in thread
From: Xi Ruoyao via Libc-alpha @ 2022-11-23 11:18 UTC (permalink / raw)
  To: Florian Weimer, caiyinyu
  Cc: adhemerval.zanella, libc-alpha, i.swmail, xuchenghua

On Wed, 2022-11-23 at 11:31 +0100, Florian Weimer wrote:
> > From: Chenghua Xu <xuchenghua@loongson.cn>
> > 
> > This patch is used to fix address out-of-bounds error when building
> > firefox.
> 
> The .c files shouldn't be necessary.  The CFLAGS additions should
> perhaps be made subdirectory-specific.  And I think these days,
> libc_nonshared.a is much, much small (and we could size it down even
> further).

In my build libc_nonshared.a only contains:

- at_quick_exit.oS
- atexit.oS
- pthread_atfork.oS
- stack_chk_fail_local.oS

> But shouldn't the medium model be the GCC default if it is required for
> building applications?

Small code model can support a 128MiB .text section, and most
applications have a .text section < 128MiB.  But Firefox libxul.so can
be extremely large.

It's not worthy to pay the cost everywhere just for satisfying a monster
application.


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* 回复: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
  2022-11-23 11:18   ` Xi Ruoyao via Libc-alpha
@ 2022-11-30  6:55     ` caiyinyu
       [not found]       ` <7ffa022e80ba4ab8942995da0d5c8371f180cb1b.camel@xry111.site>
  2022-11-30  7:40     ` [PATCH] LoongArch: Use medium cmodel " Florian Weimer via Libc-alpha
  1 sibling, 1 reply; 7+ messages in thread
From: caiyinyu @ 2022-11-30  6:55 UTC (permalink / raw)
  To: Xi Ruoyao, Florian Weimer
  Cc: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
	i.swmail@xen0n.name, xuchenghua@loongson.cn

Sorry for the delay.

+# All the objects in lib*_nonshared.a need to be compiled with medium code
+# model or large applications may fail to link.
+CFLAGS-.oS += -mcmodel=medium

We just need add -mcmodel=medium to four files not all.

Here are my patches: 

diff --git a/sysdeps/loongarch/Makefile b/sysdeps/loongarch/Makefile
index 746d4c2c8f..be7fb38714 100644
--- a/sysdeps/loongarch/Makefile
+++ b/sysdeps/loongarch/Makefile
@@ -5,3 +5,10 @@ endif
 # LoongArch's assembler also needs to know about PIC as it changes the
 # definition of some assembler macros.
 ASFLAGS-.os += $(pic-ccflag)
+
+ifeq (yes,$(enable_cmodel_medium))
+CFLAGS-atexit.oS += -mcmodel=medium
+CFLAGS-at_quick_exit.oS += -mcmodel=medium
+CFLAGS-pthread_atfork.oS += -mcmodel=medium
+CFLAGS-stack_chk_fail_local.oS += -mcmodel=medium
+endif
diff --git a/sysdeps/loongarch/configure b/sysdeps/loongarch/configure
index 3046915ce2..6372449ea2 100644
--- a/sysdeps/loongarch/configure
+++ b/sysdeps/loongarch/configure
@@ -72,3 +72,25 @@ if test "$libc_cv_static_pie_on_loongarch" = yes; then
   $as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h

 fi
+
+  # Check if gcc supports option -mcmodel=medium.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports option -mcmodel=medium" >&5
+$as_echo_n "checking whether $CC supports option -mcmodel=medium... " >&6; }
+if ${libc_cv_loongarch_cmodel_medium+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+    if { ac_try='${CC-cc} -c $CFLAGS -mcmodel=medium /dev/null 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    libc_cv_loongarch_cmodel_medium=yes
+  else
+    libc_cv_loongarch_cmodel_medium=no
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_loongarch_cmodel_medium" >&5
+$as_echo "$libc_cv_loongarch_cmodel_medium" >&6; }
+config_vars="$config_vars
+enable_cmodel_medium = $libc_cv_loongarch_cmodel_medium"
diff --git a/sysdeps/loongarch/configure.ac b/sysdeps/loongarch/configure.ac
index 06dd408ad9..7170dc7d59 100644
--- a/sysdeps/loongarch/configure.ac
+++ b/sysdeps/loongarch/configure.ac
@@ -51,3 +51,13 @@ EOF
 if test "$libc_cv_static_pie_on_loongarch" = yes; then
   AC_DEFINE(SUPPORT_STATIC_PIE)
 fi
+
+  # Check if gcc supports option -mcmodel=medium.
+AC_CACHE_CHECK(whether $CC supports option -mcmodel=medium,
+              libc_cv_loongarch_cmodel_medium, [dnl
+  if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS -mcmodel=medium /dev/null 1>&AS_MESSAGE_LOG_FD); then
+    libc_cv_loongarch_cmodel_medium=yes
+  else
+    libc_cv_loongarch_cmodel_medium=no
+  fi])
+LIBC_CONFIG_VAR([enable_cmodel_medium], [$libc_cv_loongarch_cmodel_medium])


从 Windows 版邮件发送

发件人: Xi Ruoyao
发送时间: 2022年11月23日 19:18
收件人: Florian Weimer; caiyinyu
抄送: adhemerval.zanella@linaro.org; libc-alpha@sourceware.org; i.swmail@xen0n.name; xuchenghua@loongson.cn
主题: Re: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.

On Wed, 2022-11-23 at 11:31 +0100, Florian Weimer wrote:
> > From: Chenghua Xu <xuchenghua@loongson.cn>
> > 
> > This patch is used to fix address out-of-bounds error when building
> > firefox.
> 
> The .c files shouldn't be necessary.  The CFLAGS additions should
> perhaps be made subdirectory-specific.  And I think these days,
> libc_nonshared.a is much, much small (and we could size it down even
> further).

In my build libc_nonshared.a only contains:

- at_quick_exit.oS
- atexit.oS
- pthread_atfork.oS
- stack_chk_fail_local.oS

> But shouldn't the medium model be the GCC default if it is required for
> building applications?

Small code model can support a 128MiB .text section, and most
applications have a .text section < 128MiB.  But Firefox libxul.so can
be extremely large.

It's not worthy to pay the cost everywhere just for satisfying a monster
application.


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


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

* Re: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
  2022-11-23 11:18   ` Xi Ruoyao via Libc-alpha
  2022-11-30  6:55     ` 回复: " caiyinyu
@ 2022-11-30  7:40     ` Florian Weimer via Libc-alpha
  1 sibling, 0 replies; 7+ messages in thread
From: Florian Weimer via Libc-alpha @ 2022-11-30  7:40 UTC (permalink / raw)
  To: Xi Ruoyao; +Cc: caiyinyu, adhemerval.zanella, libc-alpha, i.swmail, xuchenghua

* Xi Ruoyao:

> On Wed, 2022-11-23 at 11:31 +0100, Florian Weimer wrote:
>> But shouldn't the medium model be the GCC default if it is required for
>> building applications?
>
> Small code model can support a 128MiB .text section, and most
> applications have a .text section < 128MiB.  But Firefox libxul.so can
> be extremely large.
>
> It's not worthy to pay the cost everywhere just for satisfying a
> monster application.

I see, I wasn't aware that the limit was that large.

Thanks,
Florian


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

* 回复: 回复: [PATCH] LoongArch: Use mediumcmodel build libc_nonshared.a.
       [not found]       ` <7ffa022e80ba4ab8942995da0d5c8371f180cb1b.camel@xry111.site>
@ 2022-11-30  8:40         ` caiyinyu
  0 siblings, 0 replies; 7+ messages in thread
From: caiyinyu @ 2022-11-30  8:40 UTC (permalink / raw)
  To: Xi Ruoyao, Florian Weimer
  Cc: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
	i.swmail@xen0n.name, xuchenghua@loongson.cn, sunxu@loongson.cn

OK, I will use CFLAGS-.oS += -mcmodel=medium and have-cmodel-medium.

从 Windows 版邮件发送

发件人: Xi Ruoyao
发送时间: 2022年11月30日 15:34
收件人: caiyinyu@loongson.cn; Florian Weimer
抄送: adhemerval.zanella@linaro.org; libc-alpha@sourceware.org; i.swmail@xen0n.name; xuchenghua@loongson.cn
主题: Re: 回复: [PATCH] LoongArch: Use mediumcmodel build libc_nonshared.a.

On Wed, 2022-11-30 at 14:55 +0800, caiyinyu@loongson.cn wrote:
> +# All the objects in lib*_nonshared.a need to be compiled with medium
> code
> +# model or large applications may fail to link.
> +CFLAGS-.oS += -mcmodel=medium
>  
> We just need add -mcmodel=medium to four files not all.

I still prefer "all", to prevent subtle breakages if someone adds a file
into or removes a file from libc_nonshared.a.  Currently other .oS files
are in libsupport_nonshared.a which is used by the test suite and not
installed.

/* snip */

> +LIBC_CONFIG_VAR([enable_cmodel_medium],

It looks like we are using "-" instead of "_" in the first parameter of
LIBC_CONFIG_VAR calls everywhere.  Note that it's a variable name in a
Makefile, not a shell script.

And I'd remove the "enable" prefix: this prefix makes the variable looks
like "something can be turned on/off by `--{enable,disable}-cmodel-
medium'" but it's not true.

So I think "cmodel-medium" or "have-cmodel-medium" would be a better
name.

> [$libc_cv_loongarch_cmodel_medium])

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


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

end of thread, other threads:[~2022-11-30  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23  7:09 [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a caiyinyu
2022-11-23  8:21 ` Xi Ruoyao via Libc-alpha
2022-11-23 10:31 ` Florian Weimer via Libc-alpha
2022-11-23 11:18   ` Xi Ruoyao via Libc-alpha
2022-11-30  6:55     ` 回复: " caiyinyu
     [not found]       ` <7ffa022e80ba4ab8942995da0d5c8371f180cb1b.camel@xry111.site>
2022-11-30  8:40         ` 回复: 回复: [PATCH] LoongArch: Use mediumcmodel " caiyinyu
2022-11-30  7:40     ` [PATCH] LoongArch: Use medium cmodel " Florian Weimer via Libc-alpha

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