Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp8903063rwr; Thu, 11 May 2023 07:36:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5opmSVjvrmqT5NP4yGXzdZ0BuM3nu42Xmzk40fihb+MZRSaDYCgktAFHYlZFhcsme9ZOP5 X-Received: by 2002:a17:902:f547:b0:1aa:fbaa:ee01 with SMTP id h7-20020a170902f54700b001aafbaaee01mr26283936plf.48.1683815810329; Thu, 11 May 2023 07:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683815810; cv=none; d=google.com; s=arc-20160816; b=0Qo0ruR+8p54ACGhVOJIK5RUgPRuZC0S+plFwGZQh0GEZ3kZbKBIP8OCRtkoibemsp mvHUxhqOqvLbtJJMnbE92UXfgW7aIb8Pb0EkkFh6DK7Grk1qJnIcVAu1eYfbQ1sM7Kbw AZLD9T0YpbU8RBe/9bPOvcgzdBXUWs+dsg6fP7jDNhpqymif9RAK1mE2gIBkhYWvNnDX KEFh8q2hYiZv528Lpb0geYCf/CuuiuWVl/ocJCuP/gtMbyB3ZdDrPvgfvuatd0AuOsLI MxdqBRvPvyErfgpRqfLKP6T9aB6P0X/+A4Hvep+uE09KyoQ5kRcM5dqyOvXLMFAEs8Rf Gg2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VQWrbQyQZhlirYLdqanbcNg2P7jQBUh8fdQxrXJmbe4=; b=bye9/4RKzdL7eogb8nVaq9v2d1LT1U4nxkb7wkacp+LyybLG0+SjJC6ql0xoJO8JVl Y4l+OKANG7ZYfwJtS7iIRaC10uHmELyHwLvESkLsuh70BFlcOWiRJj2X/iICYbuL6hK9 AxrGTTLyN9JN46E3wnLod8oi7OtQVHtVd7nVoFd9jkDfWtbfpKakW7RS+FWi2L5Rh+l9 3wBSR3yXX2BLA6Bdd2DCkz7QSxr6AT24WwE/KeCen5fziRaWT9PVzMYg/jHp+Sq5GO3G bGQTzwslCQgMO6iidtjEeuwodYiUwZjSFo2GSBiwiuCQejtMRbQK7axCaH0ysQgRFLe8 TemA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aQAlhdry; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc12-20020a17090b3b8c00b0024de98a941esi20921428pjb.189.2023.05.11.07.36.34; Thu, 11 May 2023 07:36:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aQAlhdry; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238444AbjEKOYA (ORCPT + 99 others); Thu, 11 May 2023 10:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238169AbjEKOXj (ORCPT ); Thu, 11 May 2023 10:23:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8EB6210D; Thu, 11 May 2023 07:23:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3DBAF63335; Thu, 11 May 2023 14:23:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEFB6C433EF; Thu, 11 May 2023 14:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683815006; bh=EAl7BYyGkHSJ9u4z4v03MJVzoloTTUlxQ/6IkxdvXp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQAlhdryVtLrijn4plCYeD8GrNC3jkYYQfYYiLdqFuCbLL01xeMxATi5/b0BGkM3s 9pL1vpl41G7btsU04qC3KrO87rvLds7PncrgXtCzI0TzlLyAxUfqxe9l6sJ8pXHMhd yhQTtQsY8s1Rz8rB2ADYYC5lq2GjgG6p1lMoJRviovB4jhO0IgiPOanGPdogFRFGKf M8lKdsRm3s25cOtf3C6WMjn6jdc7/xNC+H3pGs4NafKn5ftut5UIqYwf1d8y4dUyr/ 48sWhQwCzLUjfP7GoO7r/wnUGOitDR2Mu+i737iw2WCUlf+W9v8lzun7HeOBvYMGVS PA6Eg16UdnlTQ== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Arnd Bergmann Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH 4/4] riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION Date: Thu, 11 May 2023 22:12:11 +0800 Message-Id: <20230511141211.2418-5-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230511141211.2418-1-jszhang@kernel.org> References: <20230511141211.2418-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When trying to run linux with various opensource riscv core on resource limited FPGA platforms, for example, those FPGAs with less than 16MB SDRAM, I want to save mem as much as possible. One of the major technologies is kernel size optimizations, I found that riscv does not currently support HAVE_LD_DEAD_CODE_DATA_ELIMINATION, which passes -fdata-sections, -ffunction-sections to CFLAGS and passes the --gc-sections flag to the linker. This not only benefits my case on FPGA but also benefits defconfigs. Here are some notable improvements from enabling this with defconfigs: nommu_k210_defconfig: text data bss dec hex 1112009 410288 59837 1582134 182436 before 962838 376656 51285 1390779 1538bb after rv32_defconfig: text data bss dec hex 8804455 2816544 290577 11911576 b5c198 before 8692295 2779872 288977 11761144 b375f8 after defconfig: text data bss dec hex 9438267 3391332 485333 13314932 cb2b74 before 9285914 3350052 483349 13119315 c82f53 after Signed-off-by: Jisheng Zhang --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/vmlinux.lds.S | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index f0663b52d052..a5feab2c3037 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -110,6 +110,7 @@ config RISCV select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL select HAVE_KRETPROBES if !XIP_KERNEL + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_PCI diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index e5f9f4677bbf..492dd4b8f3d6 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -85,11 +85,11 @@ SECTIONS INIT_DATA_SECTION(16) .init.pi : { - *(.init.pi*) + KEEP(*(.init.pi*)) } .init.bss : { - *(.init.bss) /* from the EFI stub */ + KEEP(*(.init.bss*)) /* from the EFI stub */ } .exit.data : { @@ -112,7 +112,7 @@ SECTIONS . = ALIGN(8); .alternative : { __alt_start = .; - *(.alternative) + KEEP(*(.alternative)) __alt_end = .; } __init_end = .; -- 2.40.1