Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp636507lqc; Fri, 8 Mar 2024 07:37:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJokajaMcbZ7B69YbFcJOGKJc7EYkZVWJqi9KjpBCoQFnMf1wZSfczAbfiZDDWBOXCuruYgMnG6LUfu1LlO1NnClRZRMd/4+6XekfQtw== X-Google-Smtp-Source: AGHT+IEvLhhbDSIfQ59dEMh9WlFgkePEfAxZP9w25H7dLyamtXKn7nDjOdUhk0OB6UeDb2jblYs7 X-Received: by 2002:a17:902:bc86:b0:1dc:16:9000 with SMTP id bb6-20020a170902bc8600b001dc00169000mr10583567plb.16.1709912272031; Fri, 08 Mar 2024 07:37:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709912272; cv=pass; d=google.com; s=arc-20160816; b=twxgWKKjFza/tWMHt/HaV/8Y/Rt8SSI+W5Ie6eXXvGVU7o7l/ZP5Kh7ZwT1xJG9IQb VsnOSbZD9AiDa3+Eduh95UNJsOp0By36b2bz2yy41vy4qDXMoIF8IGwlpHsddkOvn8mb EUOSZhpmkoHsSRGmmU8ZVl2fqzBBiyQOxHFDDDv6emXmMjbN5T/IqiMLKUip14I2MSid asL8DxQ8Xxq3nsns2Loe1EmChKsgDbHN9w4b3LXzkWEyRjzpGrOLes4h0bVka0oNMVeZ Z2JHdiOEDwcsG6n2ahPcxYGQZnlJTuUO3lINJo+xs2G5AlckJbX8o3WwUil1MrJU9DxC /iTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=ajIHYjU78uvahEMoVi5LqFhAwUIvgnFbGS/TJZZRlMM=; fh=E43YTtdJ4jiDLE6dn9bPz8McEkr0ccFMiolLlW0j/0Y=; b=q+gyvnZ2GNYxRwAi5ZlcqIqcaJ87gmwV8QISe/HONTbnormTIwPK5PY2dCD28lX1HY rLCyj7RbPANBJwOLxkHU9WwViXZUIaJbEGHay7faoQ4CZfa1pqII2q8lDP/ymfL6rHK7 oQwlLmpfZsOQLYGwJXiuyFev6cgBAXYoW7T3Dtls0pL42bPhFej6WbGkK1mvoXBXqUJv TO/lD2+P0H65iZvvqGU7GvyTkPxBHzYM5wor78JYAceMe2NORuguzRnnFKoWVHm0WxJV 713DHNtkIyFJVXt3cjF2oCm1JgwggLVfq8gV0BgbxW95Foe0eNAicfU+kBBKmXcyIwH7 xJMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b6d4bgcp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97243-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ix5-20020a170902f80500b001db7c124744si1408762plb.613.2024.03.08.07.37.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 07:37:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97243-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b6d4bgcp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-97243-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AB10B282967 for ; Fri, 8 Mar 2024 15:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47EB81F932; Fri, 8 Mar 2024 15:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b6d4bgcp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 383ED1865 for ; Fri, 8 Mar 2024 15:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709912265; cv=none; b=KdE+3dyqEmdyVXBI6idSUd5HlPs39ifBubeL232JLcxvoP+/1br3dMCfQXMnVtrgsIfhL0TUEd5b4qhPQ6DrqjIF7CxAsV+w2XBP/jFTtYqmk2Mczod6HlxPBNnKNhedn3rpipN/con/cuR8YVtKSJyeaVXtKWWIK1UCgKOLKyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709912265; c=relaxed/simple; bh=sdYpZP4YQbhCjgtJa85RLqgo9N8Ggjf5Cog+46o+OfE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=b6jxnXii9vYBHcAPwpmm4IapNJRSnWR7xhrvDDrR4Xd5/hDAhqGxulD2+NeVzidva90Ab912ereANUiWKSGilX4HOoHyZwcQX+KYgBbnpAfjSPaaVprCX7kAjLpcHMakokypLHzSEM/3zcknpqVhQZR/cuxi9aMaXKFrov/ioGU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b6d4bgcp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C394EC433F1 for ; Fri, 8 Mar 2024 15:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709912264; bh=sdYpZP4YQbhCjgtJa85RLqgo9N8Ggjf5Cog+46o+OfE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=b6d4bgcpBkFrtiWD78E4JynlmN3la5FqHYSQegJwAJJdqAuoSPNP05tdANziEWqEU MByCxsMnN4wuDpkwKHfFf0542KmJYUnqwPQSyNcai28r4V2wT5f4C0lwyK30BiKVez V0e1mOXFMTwE1PkCjYZKQqV5xqVPsBpOzBZRla4UaFSvCEVCV6bKjp7jqzK5PgiY3d TGAtr3N5wh/zvSAP06+TUp+M9VasmuxmKjH+bTRlKzQlN936yINN5QzFDgB1DSJjG6 5vgNObgcXIHgtYRpLZibTIHLU2MNV8wzUqCd+AOYbXCoX0TcW+t3YUXs7Bve6brpca Rgw6gaqH2Uzrw== Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d422b6253cso6071571fa.2 for ; Fri, 08 Mar 2024 07:37:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVkH9Gsykp0HXeS5eGYeJ3e+a5a/+aBzVY5xsKgdcXtv+fg5czSBQv1BZUKCymP4tFeHRWtrmYJw9zp+Z2o/pVuNkXp215MeabNjx3b X-Gm-Message-State: AOJu0Yw3jfZi56XcySds3ib0n9iQRifVOvH9MUO14DMnd3dYaHC1wuJj B80I7vzDJD3gYXvsJK2YbzSa0XoKY6cKb+6ccxcdFQPsvL7BXecKyHsrbyogaQQEdERzTu3WgCD 00WnVciPeW7OMsSbq1QKYdlAb0KY= X-Received: by 2002:a05:651c:220c:b0:2d3:a1fd:4ad2 with SMTP id y12-20020a05651c220c00b002d3a1fd4ad2mr4077110ljq.37.1709912262952; Fri, 08 Mar 2024 07:37:42 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240307151231.654025-1-liuyuntao12@huawei.com> <58cc1053-7208-4b22-99cb-210fdf700569@app.fastmail.com> In-Reply-To: From: Ard Biesheuvel Date: Fri, 8 Mar 2024 16:37:31 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH-next v2] arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION To: Arnd Bergmann Cc: Yuntao Liu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Fangrui Song , Russell King , Andrew Davis , Andrew Morton , "Kirill A. Shutemov" , Geert Uytterhoeven , Jonathan Corbet , Mike Rapoport , Rob Herring , Thomas Gleixner , Linus Walleij , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" On Fri, 8 Mar 2024 at 15:27, Ard Biesheuvel wrote: > > On Fri, 8 Mar 2024 at 14:16, Arnd Bergmann wrote: > > > > On Thu, Mar 7, 2024, at 16:12, Yuntao Liu wrote: > > > The current arm32 architecture does not yet support the > > > HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. arm32 is widely used in > > > embedded scenarios, and enabling this feature would be beneficial for > > > reducing the size of the kernel image. > > > > > > In order to make this work, we keep the necessary tables by annotating > > > them with KEEP, also it requires further changes to linker script to KEEP > > > some tables and wildcard compiler generated sections into the right place. > > > > > > It boots normally with defconfig, vexpress_defconfig and tinyconfig. > > > > > > The size comparison of zImage is as follows: > > > defconfig vexpress_defconfig tinyconfig > > > 5137712 5138024 424192 no dce > > > 5032560 4997824 298384 dce > > > 2.0% 2.7% 29.7% shrink > > > > > > When using smaller config file, there is a significant reduction in the > > > size of the zImage. > > > > > > We also tested this patch on a commercially available single-board > > > computer, and the comparison is as follows: > > > a15eb_config > > > 2161384 no dce > > > 2092240 dce > > > 3.2% shrink > > > > > > The zImage size has been reduced by approximately 3.2%, which is 70KB on > > > 2.1M. > > > > > > Signed-off-by: Yuntao Liu > > > > I've retested with both gcc-13 and clang-18, and so no > > more build issues. Your previous version already worked > > fine for me. > > > > I did some tests combining this with CONFIG_TRIM_UNUSED_KSYMS, > > which showed a significant improvement as expected. I also > > tried combining it with an experimental CONFIG_LTO_CLANG > > patch, but that did not show any further improvements. > > > > Tested-by: Arnd Bergmann > > Reviewed-by: Arnd Bergmann > > > > Adding Ard Biesheuvel and Fangrui Song to Cc, so they can comment > > on the ARM_VECTORS_TEXT workaround. I don't understand enough of > > the details of what is going on here. > > > > Thanks for the cc > > > Full quote of the patch below so they can see the whole thing. > > > > If they are also happy with the patch, I think you can send it > > into Russell's patch tracker at > > https://www.armlinux.org.uk/developer/patches/info.php > > > > No, not happy at all :-) > > The resulting kernel does not boot (built with GCC or Clang). And the > patch is buggy (see below) > > > > --- > > > v2: > > > - Support config XIP_KERNEL. > > > - Support LLVM compilation. > > > > > > v1: https://lore.kernel.org/all/20240220081527.23408-1-liuyuntao12@huawei.com/ > > > --- > > > arch/arm/Kconfig | 1 + > > > arch/arm/boot/compressed/vmlinux.lds.S | 4 ++-- > > > arch/arm/include/asm/vmlinux.lds.h | 18 +++++++++++++++++- > > > arch/arm/kernel/vmlinux-xip.lds.S | 8 ++++++-- > > > arch/arm/kernel/vmlinux.lds.S | 10 +++++++--- > > > 5 files changed, 33 insertions(+), 8 deletions(-) > > > > > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > > > index 0af6709570d1..de78ceb821df 100644 > > > --- a/arch/arm/Kconfig > > > +++ b/arch/arm/Kconfig > > > @@ -113,6 +113,7 @@ config ARM > > > select HAVE_KERNEL_XZ > > > select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M > > > select HAVE_KRETPROBES if HAVE_KPROBES > > > + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION > > > select HAVE_MOD_ARCH_SPECIFIC > > > select HAVE_NMI > > > select HAVE_OPTPROBES if !THUMB2_KERNEL > > > diff --git a/arch/arm/boot/compressed/vmlinux.lds.S > > > b/arch/arm/boot/compressed/vmlinux.lds.S > > > index 3fcb3e62dc56..da21244aa892 100644 > > > --- a/arch/arm/boot/compressed/vmlinux.lds.S > > > +++ b/arch/arm/boot/compressed/vmlinux.lds.S > > > @@ -89,7 +89,7 @@ SECTIONS > > > * The EFI stub always executes from RAM, and runs strictly before > > > the > > > * decompressor, so we can make an exception for its r/w data, and > > > keep it > > > */ > > > - *(.data.efistub .bss.efistub) > > > + *(.data.* .bss.*) > > Why is this necessary? There is a reason we don't allow .data in the > decompressor. > > > > __pecoff_data_end = .; > > > > > > /* > > > @@ -125,7 +125,7 @@ SECTIONS > > > > > > . = BSS_START; > > > __bss_start = .; > > > - .bss : { *(.bss) } > > > + .bss : { *(.bss .bss.*) } > > > _end = .; > > > > > > . = ALIGN(8); /* the stack must be 64-bit aligned */ > > > diff --git a/arch/arm/include/asm/vmlinux.lds.h > > > b/arch/arm/include/asm/vmlinux.lds.h > > > index 4c8632d5c432..dfe2b6ad6b51 100644 > > > --- a/arch/arm/include/asm/vmlinux.lds.h > > > +++ b/arch/arm/include/asm/vmlinux.lds.h > > > @@ -42,7 +42,7 @@ > > > #define PROC_INFO \ > > > . = ALIGN(4); \ > > > __proc_info_begin = .; \ > > > - *(.proc.info.init) \ > > > + KEEP(*(.proc.info.init)) \ > > > __proc_info_end = .; > > > > > > #define IDMAP_TEXT \ > > > @@ -87,6 +87,22 @@ > > > *(.vfp11_veneer) \ > > > *(.v4_bx) > > > > > > +/* > > > +When CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled, it is important > > > to > > > +annotate .vectors sections with KEEP. While linking with ld, it is > > > +acceptable to directly use KEEP with .vectors sections in ARM_VECTORS. > > > +However, when using ld.lld for linking, KEEP is not recognized within > > > the > > > +OVERLAY command; it is treated as a regular string. Hence, it is > > > advisable > > > +to define a distinct section here that explicitly retains the .vectors > > > +sections when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is turned on. > > > +*/ > > > +#define ARM_VECTORS_TEXT \ > > > + .vectors.text : { \ > > > + KEEP(*(.vectors)) \ > > > + KEEP(*(.vectors.bhb.loop8)) \ > > > + KEEP(*(.vectors.bhb.bpiall)) \ > > > + } > > > + > > This looks fishy to me. How is this supposed to work? You cannot emit > these sections into some random other place in the binary. > > And also, ARM_VECTORS_TEXT is never used (by accident, see below) > The below appears to work for me: --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -1076,7 +1076,12 @@ W(b) vector_irq W(b) vector_fiq + .text + .reloc ., R_ARM_NONE, .vectors #ifdef CONFIG_HARDEN_BRANCH_HISTORY + .reloc ., R_ARM_NONE, .vectors.bhb.loop8 + .reloc ., R_ARM_NONE, .vectors.bhb.bpiall + .section .vectors.bhb.loop8, "ax", %progbits W(b) vector_rst W(b) vector_bhb_loop8_und