From: <caiyinyu@loongson.cn>
To: Xi Ruoyao <xry111@xry111.site>, Florian Weimer <fweimer@redhat.com>
Cc: "adhemerval.zanella@linaro.org" <adhemerval.zanella@linaro.org>,
"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
"i.swmail@xen0n.name" <i.swmail@xen0n.name>,
"xuchenghua@loongson.cn" <xuchenghua@loongson.cn>
Subject: 回复: [PATCH] LoongArch: Use medium cmodel build libc_nonshared.a.
Date: Wed, 30 Nov 2022 14:55:37 +0800 [thread overview]
Message-ID: <6386FE6D.025D62.50083@loongson.cn> (raw)
In-Reply-To: <33054b9098f4ef690cd1639e96b2c148e9e9e490.camel@xry111.site>
[-- Attachment #1: Type: text/plain, Size: 4200 bytes --]
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
next prev parent reply other threads:[~2022-11-30 6:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 7:09 caiyinyu
2022-11-23 8:21 ` Xi Ruoyao
2022-11-23 10:31 ` Florian Weimer
2022-11-23 11:18 ` Xi Ruoyao
2022-11-30 6:55 ` caiyinyu [this message]
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6386FE6D.025D62.50083@loongson.cn \
--to=caiyinyu@loongson.cn \
--cc=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=i.swmail@xen0n.name \
--cc=libc-alpha@sourceware.org \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).