Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2375269lqt; Mon, 22 Apr 2024 09:02:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmf7BjIE5+acdwbXyYWPai9fxVU1tAZ7rBrVhIwU35CnxR3e7KA0e3VXTn38PmBYhVBlXhlT5sWsKEnom+6dR3pQRWOcxNputUtFk11w== X-Google-Smtp-Source: AGHT+IEEWGs1CENLdan7rY5Wgw4ug7zaKX+A7ZaeawhhDqvwL1Mg9s1/wZPdH3akuxGw3pDgqdTM X-Received: by 2002:a05:690c:f12:b0:61b:33c8:7bce with SMTP id dc18-20020a05690c0f1200b0061b33c87bcemr11112421ywb.31.1713801764606; Mon, 22 Apr 2024 09:02:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713801764; cv=pass; d=google.com; s=arc-20160816; b=FPpOZ4FHPc2wjBWrRPzMQFT4a1SrnXJpJNx59GKaU2VAs4vhug+iXDPCQTHyU/RpT7 cttuIKsWmBzpNAmNlKy0KO+8jKYdBvnN6QllteDuVR0oLq/EAO94HAIYeGvBIKgWgFdR uuvJ0H8sjJAmQdhL2ZqDkAxbrSYwex/5QQ9mPDAAIYlWeVtmdkTQWDLEusQIEhyBVbgd W6MmxEEerbnxSXVt0rpgx44GGR8NfAYSurj6G1muwlBLxU3fVDTRMjJZEkzny/vPqHGQ /mePCg3J6B4j9FaB4FqRdnpNAuTUy5iF2uw3B/bWGLQxUFuHuGSjGgrCvE245Ez/tTdw BboA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=LrOoJq1VxeBzetwZgH5nZOqmResAbghIXFCz8lSPvtk=; fh=gKuwfY1ZqE8V9gIxD7JgJqS6oZe28qyvusUOQcN+GCI=; b=DUSaPzilyxLDjnWj9BIAOuU0bq2F4zMeHgXneZzCv0NbZRB+WW2P5iDPB2J7m2hV97 F0/3rd7iFb+tppxsn7BNMyCc4Zh9pr1LHPep4SwVEKaQzx/jUti3AGixvWlKmCjIV2c9 sCgmkhJ4FqMqfFvN6TX6eu8UesGI7aUq4ZKXRCUGx6dtm0pEsfRaPtXqsk2ga/qNRcNU s3UFQiLFqywF5P/FF8pkEcknoghNHxcYleZ+rMIVnOgM5pxL0JB5KGpTtK0iYA8yjM3a 7h0OUvEcO61uo8Z1Z2O3awSSEehdFhPXKFGGt/vaNVJUZByCOpuxYaqITl0s0jl/NvJF FN4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o3OP/BYs"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153669-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153669-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k132-20020a816f8a000000b00617c8099ac1si5087416ywc.550.2024.04.22.09.02.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 09:02:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153669-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o3OP/BYs"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-153669-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153669-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1CA471C21051 for ; Mon, 22 Apr 2024 16:02:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5506A153583; Mon, 22 Apr 2024 16:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o3OP/BYs" 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 657591534E2; Mon, 22 Apr 2024 16:02:34 +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=1713801754; cv=none; b=d23KIbqXBf/ZAnRsjBJI1iWiEnGESHKeArLuhwCFVlHUgdxxiSGfq7Yd46TcQNUIAqH0jq8bdCED2d453ZR1vYo2l5lZpRjWjZWRLfEQNcxwL00eMuR/mX7sDO4aE+lVm8sJgdO6cHGm4Loc0sYoOMWAtEZiw7CXxWghf/vrXyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713801754; c=relaxed/simple; bh=kKEgwTQB6MqW0mu0bWbxcpzTqMyAS35I7Efi1ILhfsI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=qkfVODL7vnbhEB/i+6PBZJ7tydq16Y/FgIFkBf1A9lgJp8eYBpuB3BZuYnozuwNgomBEai+IPrIKlnnpj3/BDMZEW/olmtJ34o7/PpgBL/Vh84KzQ+SbOnTdwd8pkb7MbD1qeXhB2wStV1qbxd0mhMn+eS9y/3YFNbzVa6V7IC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o3OP/BYs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02D32C113CC; Mon, 22 Apr 2024 16:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713801754; bh=kKEgwTQB6MqW0mu0bWbxcpzTqMyAS35I7Efi1ILhfsI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=o3OP/BYsZRigokLjxaTOJ6S0laERho7w/857iL496omGhqU82zk9SZuT5ZMRM5OeA V+m5/F51fkyDmH45SYrbvx11IaXxS2bDdmA9iMORBpXmM+sbGS7XmuPMrmCxNlbXHu Si64KIfdIDBaWnBkeR2nzvz2kPvsBQQGniTjC8G58db+JHxTUl7XGVK6dnemXvEpzK At5ZiZzvXEM6aoRp3tMgvQIQwbZnvn4RlKMFPOypi8IAlyvTOwRlmQ3rM2ZJ0/eRcT +1kbEm+ar/mqD1R6/Kyr1GENUUG8svwWE6oI3GJ+6xJca1bT8L+qaYfs7Kz6Tw4dI1 qmh6qjePhMfRQ== Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2ddc2ea2091so7882461fa.1; Mon, 22 Apr 2024 09:02:32 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVmRucXeB5AYvGbF7ffcC5OM+1MRVLVwhZaAWJZq4noEAu0MB3itif/ZGnc+EO5kXCB4o3mu8fgYS+qyvSHbyD3Yp7wCnXiaerV50BY X-Gm-Message-State: AOJu0YzKgEr+s3uPj24bOkd800okdOsZrZYRueOMKnEjRu6IStWST3si tNdTlgX0FJYGlf2tflGhCSvs8NReOTYUMDVx5mgDMuCKuXXfh9RL+uhp5Emx/RLv4BT/pbFbZek cBKJa1bRawkcyyU+SDA/f297Wxo4= X-Received: by 2002:a2e:b8d0:0:b0:2dc:de74:dfd6 with SMTP id s16-20020a2eb8d0000000b002dcde74dfd6mr7640386ljp.10.1713801751709; Mon, 22 Apr 2024 09:02:31 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422060556.1226848-1-liuyuntao12@huawei.com> In-Reply-To: <20240422060556.1226848-1-liuyuntao12@huawei.com> From: Masahiro Yamada Date: Tue, 23 Apr 2024 01:01:55 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION To: Yuntao Liu Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nathan@kernel.org, nicolas@fjasle.eu, peterz@infradead.org, jpoimboe@kernel.org, leitao@debian.org, petr.pavlu@suse.com, richard.weiyang@gmail.com, ruanjinjie@huawei.com, ndesaulniers@google.com, jgross@suse.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 22, 2024 at 3:41=E2=80=AFPM Yuntao Liu = wrote: > > The current x86 architecture does not yet support the > HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. x86 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= . > > Enabling CONFIG_UNWINDER_ORC or CONFIG_MITIGATION_RETPOLINE will enable > the objtool's --orc and --retpoline parameters, which will alter the > layout of the binary file, thereby preventing gc-sections from functionin= g > properly. Therefore, HAVE_LD_DEAD_CODE_DATA_ELIMINATION should only be > selected when they are not enabled. > > Enabling CONFIG_LTO_CLANG or CONFIG_X86_KERNEL_IBT will use vmlinux.o > instead of performing the slow LTO link again. This can also prevent > gc-sections from functioning properly. Therefore, using this optimization > when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is not enabled. > > The size comparison of zImage is as follows: > x86_def_defconfig i386_defconfig tinyconfig > 10892288 10826240 607232 no dce > 10748928 10719744 529408 dce > 1.3% 0.98% 12.8% shrink > > When using smaller config file, there is a significant reduction in the > size of the zImage. > --- > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh > index 7862a8101747..7287b5a9f17d 100755 > --- a/scripts/link-vmlinux.sh > +++ b/scripts/link-vmlinux.sh > @@ -60,7 +60,7 @@ vmlinux_link() > # skip output file argument > shift > > - if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IB= T; then > + if [ is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_= IBT ] && [ ! is_enabled CONFIG_LD_DEAD_CODE_DATA_ELIMINATION ]; then > # Use vmlinux.o instead of performing the slow LTO link a= gain. > objs=3Dvmlinux.o > libs=3D > -- This is wrong. You should not put is_enabled inside [ ... ] (is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT) && ! is_enabled CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is still weird. When CONFIG_LTO_CLANG=3Dy and CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=3Dy, the result of LTO will be discarded. --=20 Best Regards Masahiro Yamada