Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp171546lqk; Sat, 9 Mar 2024 05:24:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWHXDj36l2jupArtfCvu+fic9EFC7E8F2+7NCwL5QOaq0jF4/UVUEEYtoGsgy9doJQyaj5y4SHbNzXhY3Wj7haYjpqGO79/1KljS/E16A== X-Google-Smtp-Source: AGHT+IGHO5O68iK7jQfgJ5yTH7VOgtv02t3M2h7N+wShcTipn4VQZi+T6uCDOqYxIfB7u+HCHsxE X-Received: by 2002:a50:8751:0:b0:567:3ed0:47ec with SMTP id 17-20020a508751000000b005673ed047ecmr1204583edv.23.1709990679337; Sat, 09 Mar 2024 05:24:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709990679; cv=pass; d=google.com; s=arc-20160816; b=NncRvT3ZX9rKM78AHueDThArtomm7u49MEhm8L1fxWopyiKxHl4HiFOUQo08B6yYGE mMsMd84V3/eN+KH16KetbkfnDgnG0IH0LKNoiWAo9IsWLlXHdHT17oHLaCBd/eQt4pWr OhfIum3VSHv62oJr8wqLnrskATBE/hVgyB8cXZt/+7h3GRDtb/N7FBbbYzZL6vxICQC8 E/iD80ymf7dSeaOiIAH+OSFxVZLXbIyflcNp+qy8Dw3t+R599X2PxOjnuE42uVff2XfT YHn28C/2h4cR//6IHIhEOQbyhQSH05XB4VqVjmKDI8mvXVkba/MthZfG/4aqrykniV62 6ICw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=0n+QRWf83S4qcqRBXfZTBaQlS0aIGikdW8Nfv2F/xeI=; fh=uiDA/g3BRYskFgLNfM8MDJyKo+OW8bipY8aXLyr5VMI=; b=KeUHCLIiS/dpRMDFr0T9hlqnxmPOpRF4FJ30gnGdxbr3o/qW9Sv16E8KXqMBU4wKW2 IlcrGnnS4zl79hY3QrPseflH98NCSuMsCAX9q3FSpRYGgaofx9bOkv+tRfx8MzZFGPGX FA8OAEyiEFhxByUpuCfqP5sZORPW53g4rvuekjbWND+g/fIyw180zfAVkevYY8OEJ4OD BU1ATafNnRPpRTT+pHd6xHWK+9c5uFUypixEUrKCaCGUjDoioTbsEqc/FxAET5Iv8Oa8 vGhiqWMwIiTK6+yCjsGJXC0A8wglA7Jjbc0frgwZE2fARRe1Mmj2hSrbMbzG1t5WXYqb f0vQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-97901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x1-20020aa7dac1000000b0056825d50d59si770433eds.591.2024.03.09.05.24.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 05:24:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-97901-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DCCE91F21659 for ; Sat, 9 Mar 2024 13:24:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92B523BBE7; Sat, 9 Mar 2024 13:24:32 +0000 (UTC) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1429C36AF9 for ; Sat, 9 Mar 2024 13:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709990672; cv=none; b=iu2GJc1N3fvyMEMmkMVdXkgwmW/UOjnVmZbengzmHAW4EgsDJUlSlaPUIaB98n1fk2LHXowopLT5i/k8lI4tQg2brcj5w9/s6t7Gk262xKtrEhh+45mJKj9Z/hd4Aj+FkjMrB2FhIOXfKDjbwEHjyhvnHQAl72jjGdLx1LoNKRc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709990672; c=relaxed/simple; bh=DZAXdDJegZdcErY4U3Wlr5RwaMFdtP3+j0WDzDiIPzc=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=NsE4kpq1DqZ7oeFqFSUqsA0SxkvyLTXWySuD6cMjEU316S6oFBtFU4abHnSM4Bj53agNhYbumULuFMKmwDGI2uSvlNy8sbmuWjko+pvZBHHOqXFZ1ichgYcGVDTdthk1QXfAMf01uB2URqNg3974Z3CmJozftk6pgS30hjnvK9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4TsNz50hyKz3F0D3; Sat, 9 Mar 2024 21:23:45 +0800 (CST) Received: from dggpemd100004.china.huawei.com (unknown [7.185.36.20]) by mail.maildlp.com (Postfix) with ESMTPS id A42571A016C; Sat, 9 Mar 2024 21:24:26 +0800 (CST) Received: from [10.67.109.211] (10.67.109.211) by dggpemd100004.china.huawei.com (7.185.36.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Sat, 9 Mar 2024 21:24:26 +0800 Message-ID: <346e15e5-49e9-4a7f-b163-c3316225baab@huawei.com> Date: Sat, 9 Mar 2024 21:24:26 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH-next v2] arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION Content-Language: en-US To: Arnd Bergmann , , , Ard Biesheuvel , Fangrui Song CC: Russell King , Andrew Davis , Andrew Morton , "Kirill A. Shutemov" , Geert Uytterhoeven , Jonathan Corbet , Mike Rapoport , Rob Herring , Thomas Gleixner , Linus Walleij , References: <20240307151231.654025-1-liuyuntao12@huawei.com> <58cc1053-7208-4b22-99cb-210fdf700569@app.fastmail.com> <42892794-7668-4eb0-8d2f-c78ca0daf370@huawei.com> <2a90581c-f1df-4d6b-8f0b-8e7cbf150ed9@app.fastmail.com> From: "liuyuntao (F)" In-Reply-To: <2a90581c-f1df-4d6b-8f0b-8e7cbf150ed9@app.fastmail.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemd100004.china.huawei.com (7.185.36.20) On 2024/3/9 16:20, Arnd Bergmann wrote: > On Sat, Mar 9, 2024, at 07:14, liuyuntao (F) wrote: >> On 2024/3/8 21:15, Arnd Bergmann wrote: >>> On Thu, Mar 7, 2024, at 16:12, Yuntao Liu wrote: >> >> Thanks for the tests, CONFIG_LD_DEAD_CODE_DATA_ELIMINATION and >> CONFIG_TRIM_UNUSED_KSYMS do indeed result in a significant improvement. >> I found that arm32 still doesn't support CONFIG_LTO_CLANG. I've done >> some work on it, but without success. I'd like to learn more about the >> CONFIG_LTO_CLANG patch. Do you have any relevant links? > > I did not try to get it to boot and gave up when I did not see > any size improvement. I think there were previous attempts to > do it elsewhere, which I did not try to find. > I tested this patch, the size improvement was only about one ten-thousandth, and the compilation time had increased by about a quarter, and the kernel did not boot. Strangely, LTO has actually increased the compilation time significantly, which seems contrary to its purpose. + +trim +dce +trim+dce no lto 5995384 5858720 5841024 5299032 lto 5990040 5854544 5839992 5289576 shrink 8.9‱ 7.1‱ 1.7‱ 17.8‱ + +trim +dce +trim+dce no lto 34.616 33.03 36.093 32.211 lto 46.881 45.324 47.247 43.246 increase 26.20% 27.10% 23.60% 25.50% > The patch below makes it build, but it still requires disabling > CONFIG_THUMB2_KERNEL, which totally defeats the purpose of shrinking > the kernel as it adds some 40% size overhead in the vmlinux. > There are probably also runtime bugs that get introduced by this. > > Arnd > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > index de78ceb821df..7ebfda4839e8 100644 > --- a/arch/arm/Kconfig > +++ b/arch/arm/Kconfig > @@ -2,6 +2,8 @@ > config ARM > bool > default y > + select ARCH_SUPPORTS_LTO_CLANG > + select ARCH_SUPPORTS_LTO_CLANG_THIN > select ARCH_32BIT_OFF_T > select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE if HAVE_KRETPROBES && FRAME_POINTER && !ARM_UNWIND > select ARCH_HAS_BINFMT_FLAT > diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile > index 726ecabcef09..f2ddce451ab9 100644 > --- a/arch/arm/boot/compressed/Makefile > +++ b/arch/arm/boot/compressed/Makefile > @@ -9,6 +9,8 @@ OBJS = > > HEAD = head.o > OBJS += misc.o decompress.o > +CFLAGS_REMOVE_misc.o += $(CC_FLAGS_LTO) > +CFLAGS_REMOVE_decompress.o += $(CC_FLAGS_LTO) Wow, I've encountered this issue before and didn't think to solve it in this way. You really have a thorough understanding of these parameters. On a side note, if CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled, but only a few rodata sections are removed and no functions are eliminated, are there any compiler or linker options that can control this behavior? thanks. > ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y) > OBJS += debug.o > AFLAGS_head.o += -DDEBUG > diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c > index d19d140a10c7..aee9e13023a8 100644 > --- a/arch/arm/mm/flush.c > +++ b/arch/arm/mm/flush.c > @@ -38,15 +38,14 @@ EXPORT_SYMBOL(arm_heavy_mb); > static void flush_pfn_alias(unsigned long pfn, unsigned long vaddr) > { > unsigned long to = FLUSH_ALIAS_START + (CACHE_COLOUR(vaddr) << PAGE_SHIFT); > - const int zero = 0; > > set_top_pte(to, pfn_pte(pfn, PAGE_KERNEL)); > > - asm( "mcrr p15, 0, %1, %0, c14\n" > - " mcr p15, 0, %2, c7, c10, 4" > + asm("mcrr p15, 0, %1, %0, c14" > : > - : "r" (to), "r" (to + PAGE_SIZE - 1), "r" (zero) > + : "r" (to), "r" (to + PAGE_SIZE - 1) > : "cc"); > + dsb(); > } > > static void flush_icache_alias(unsigned long pfn, unsigned long vaddr, unsigned long len) > @@ -68,11 +67,11 @@ void flush_cache_mm(struct mm_struct *mm) > } > > if (cache_is_vipt_aliasing()) { > - asm( "mcr p15, 0, %0, c7, c14, 0\n" > - " mcr p15, 0, %0, c7, c10, 4" > + asm("mcr p15, 0, %0, c7, c14, 0" > : > : "r" (0) > : "cc"); > + dsb(); > } > } > > @@ -84,11 +83,11 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned > } > > if (cache_is_vipt_aliasing()) { > - asm( "mcr p15, 0, %0, c7, c14, 0\n" > - " mcr p15, 0, %0, c7, c10, 4" > + asm("mcr p15, 0, %0, c7, c14, 0" > : > : "r" (0) > : "cc"); > + dsb(); > } > > if (vma->vm_flags & VM_EXEC)