From patchwork Wed Nov 30 06:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: caiyinyu X-Patchwork-Id: 61247 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 279413858408 for ; Wed, 30 Nov 2022 06:56:06 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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?b?5Zue5aSNOiBbUEFUQ0hdIExvb25nQXJjaDogVXNlIG1lZGl1bSBjbW9k?= =?utf-8?b?ZWwgYnVpbGQgbGliY19ub25zaGFyZWQuYS4=?= 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> X-CM-TRANSID: AQAAf8AxvVRp_oZjPVUiAA--.624S2 Message-Id: <6386FE6D.025D62.50083@loongson.cn> X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXrWxZry3Cr4ruw4kJF45trb_yoWrZrW8pr 97Zr13tFs7WrykKrZ5Ca15ZFn5XFsrKF9Fv3ZI93W7Crs0kr1Igr4rtasrua47Xa4kJ3sF vr1rZa47XFn5G3JanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj ya5I8CrVAYj202j2C_Jr0_Gr1l5I8CrVAKz4kIr2xC04v26r1j6r4UMc02F40E42I26xC2 a48xYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUUbTkYFVCjjxCrM7AC8VAFwI0_Jr 0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jrv_JF1l8cAv FVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCw A2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4UJVWx Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2 xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG67k08I80eVWUJVW8JwAqx4xG64kEw2xG 04xIwI0_Jr0_Gr1l5I8CrVCF0I0E4I0vr24lYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4 A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwAKzVCY07xG 64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67 AKxVWUGVWUWwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jb2-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 X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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: 从 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 > > > > 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. 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])