From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id F23283858D33 for ; Wed, 30 Nov 2022 06:55:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F23283858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [114.246.94.134]) by gateway (Coremail) with SMTP id _____8AxRPBt_oZju0oCAA--.5447S3; Wed, 30 Nov 2022 14:55:41 +0800 (CST) Received: from [IPv6:::ffff:192.168.3.4] (unknown [114.246.94.134]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxvVRp_oZjPVUiAA--.624S2; Wed, 30 Nov 2022 14:55:37 +0800 (CST) MIME-Version: 1.0 To: Xi Ruoyao , Florian Weimer Cc: "adhemerval.zanella@linaro.org" , "libc-alpha@sourceware.org" , "i.swmail@xen0n.name" , "xuchenghua@loongson.cn" From: Subject: =?utf-8?Q?=E5=9B=9E=E5=A4=8D:_[PATCH]_LoongArch:_Use_medium_cmodel_build_?= =?utf-8?Q?libc=5Fnonshared.a.?= Date: Wed, 30 Nov 2022 14:55:37 +0800 Importance: normal X-Priority: 3 In-Reply-To: <33054b9098f4ef690cd1639e96b2c148e9e9e490.camel@xry111.site> References: <20221123070905.1618136-1-caiyinyu@loongson.cn> <87zgcim07m.fsf@oldenburg.str.redhat.com> <33054b9098f4ef690cd1639e96b2c148e9e9e490.camel@xry111.site> Content-Type: multipart/alternative; boundary="_E1043F67-106A-4CFB-8616-D3BD3E16F2AB_" X-CM-TRANSID:AQAAf8AxvVRp_oZjPVUiAA--.624S2 Message-Id:<6386FE6D.025D62.50083@loongson.cn> X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXrWxZry3Cr4ruw4kJF45trb_yoWrZrW8p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I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jb2-nUUU UU= X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,BODY_8BITS,GIT_PATCH_0,HTML_MESSAGE,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_PASS,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: --_E1043F67-106A-4CFB-8616-D3BD3E16F2AB_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 +=3D -mcmodel=3Dmedium We just need add -mcmodel=3Dmedium to four files not all. Here are my patches:=20 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 +=3D $(pic-ccflag) + +ifeq (yes,$(enable_cmodel_medium)) +CFLAGS-atexit.oS +=3D -mcmodel=3Dmedium +CFLAGS-at_quick_exit.oS +=3D -mcmodel=3Dmedium +CFLAGS-pthread_atfork.oS +=3D -mcmodel=3Dmedium +CFLAGS-stack_chk_fail_local.oS +=3D -mcmodel=3Dmedium +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" =3D yes; then $as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h fi + + # Check if gcc supports option -mcmodel=3Dmedium. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports o= ption -mcmodel=3Dmedium" >&5 +$as_echo_n "checking whether $CC supports option -mcmodel=3Dmedium... " >&= 6; } +if ${libc_cv_loongarch_cmodel_medium+:} false; then : + $as_echo_n "(cached) " >&6 +else + if { ac_try=3D'${CC-cc} -c $CFLAGS -mcmodel=3Dmedium /dev/null 1>&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=3D$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? =3D $ac_status" >&5 + test $ac_status =3D 0; }; }; then + libc_cv_loongarch_cmodel_medium=3Dyes + else + libc_cv_loongarch_cmodel_medium=3Dno + 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=3D"$config_vars +enable_cmodel_medium =3D $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" =3D yes; then AC_DEFINE(SUPPORT_STATIC_PIE) fi + + # Check if gcc supports option -mcmodel=3Dmedium. +AC_CACHE_CHECK(whether $CC supports option -mcmodel=3Dmedium, + libc_cv_loongarch_cmodel_medium, [dnl + if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS -mcmodel=3Dmedium /dev/null 1>&AS_= MESSAGE_LOG_FD); then + libc_cv_loongarch_cmodel_medium=3Dyes + else + libc_cv_loongarch_cmodel_medium=3Dno + fi]) +LIBC_CONFIG_VAR([enable_cmodel_medium], [$libc_cv_loongarch_cmodel_medium]) =E4=BB=8E Windows =E7=89=88=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81 =E5=8F=91=E4=BB=B6=E4=BA=BA: Xi Ruoyao =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2022=E5=B9=B411=E6=9C=8823=E6=97=A5 1= 9:18 =E6=94=B6=E4=BB=B6=E4=BA=BA: Florian Weimer; caiyinyu =E6=8A=84=E9=80=81: adhemerval.zanella@linaro.org; libc-alpha@sourceware.or= g; i.swmail@xen0n.name; xuchenghua@loongson.cn =E4=B8=BB=E9=A2=98: Re: [PATCH] LoongArch: Use medium cmodel build libc_non= shared.a. On Wed, 2022-11-23 at 11:31 +0100, Florian Weimer wrote: > > From: Chenghua Xu > >=20 > > This patch is used to fix address out-of-bounds error when building > > firefox. >=20 > The .c files shouldn't be necessary.=C2=A0 The CFLAGS additions should > perhaps be made subdirectory-specific.=C2=A0 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. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University --_E1043F67-106A-4CFB-8616-D3BD3E16F2AB_--