From patchwork Fri Feb 17 00:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 5531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp616635wrn; Thu, 16 Feb 2023 16:53:27 -0800 (PST) X-Google-Smtp-Source: AK7set961VXybjZaIFGmGo9W7TNzmltxhNAjkFBXDRV16KVKr3TjqrZiRE+icT7bUOEIewa1/2e2 X-Received: by 2002:a50:ec97:0:b0:4ac:bbb1:e61c with SMTP id e23-20020a50ec97000000b004acbbb1e61cmr7343126edr.1.1676595206870; Thu, 16 Feb 2023 16:53:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676595206; cv=none; d=google.com; s=arc-20160816; b=wVGCaajrGBxdYEBY8xCUjwJ2zNatuAlVTVynRBh9rD4ToQc0YCKtIzzeMtRCLxpgU9 y7EzYngKQClo0jmDWa6IfeV7SwN9pTS0nSnz+fsa2TKn/hr1c64njfAK2AH/yOyqHAmr uD3Roch+luK+2tfaCWVVlOMtQWbbTxiAMgxy3EXypdxku+9CGUW6cYmBalWJ5Zu7mQh+ wf6hA7WC7pwc0E4lZRoX/owo5ehauQW/bRrfu543AGC8ZGMovqVtjtk+yY6KWuFLZuPm RJ8uPRIhRKMzpMCacIcdFPCT0DHinIjocmTmGK61kgOOAlNxTwCF5lykwM5lyAdGcww9 imfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=r6AzWOiahMYkn0WHs9gt+KUTue+4yQDAGxqXThH4r30=; b=knwpe2V+Kg5zt06fup3ijrnP2Avy8lkjLBZuAFNDUOXZ71e4R0bOzHMpdEg9Orb9Ej p2DjIsMf+sO0Q+ieaq8u5w2FIBZRYOmC97yzRcRQ6yYekV3clFmNOdR2iss0Nb/sUwVX nLLVHW4pDb6qHZrj80nQOu0gcN++kkAcBeB1mpIEm4x0NyF6I7qOhwgMcq971j5MQaaM LsaK2oAtlAYTjykmdg4sspPbk3U/EohFZC4tO3RpBA7GqTbm1Nw3zw2zGiiq5P+a4l0I DsMlbB/Mr1nWZ8WmwnNnVR+IAlIu6JlErth0KT9z8jcVuU/Ec/SAnoCAWe98elpuh87j /H/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020aa7d64e000000b004aaa4ffa6d2si3691698edr.627.2023.02.16.16.53.04; Thu, 16 Feb 2023 16:53:26 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbjBQAuD (ORCPT + 99 others); Thu, 16 Feb 2023 19:50:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjBQAuC (ORCPT ); Thu, 16 Feb 2023 19:50:02 -0500 Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F20454D2B; Thu, 16 Feb 2023 16:49:58 -0800 (PST) X-QQ-mid: bizesmtp76t1676594968txapoplj Received: from localhost.localdomain ( [116.30.131.224]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 17 Feb 2023 08:49:27 +0800 (CST) X-QQ-SSF: 01200000000000C0T000000A0000000 X-QQ-FEAT: XBN7tc9DADICBB7k9+bU2BGS/LL6SOD01z1AvX6M7TbM1IcrrUquN8VoZSqxR z7Nk+jrerltyFZKM69igDS4EKfCoEx4eH6SS0q3im5pC77mpjTus7/qkaA/0Ohf5qWxBiSC 4Hu8t+EjNzV8mnlaxl1RoP2a/5sdzMO7dKFr4PtGFbPx5rSV0crjKNH4ttqQ0A/7z7SWxWg aMh+cL67CSCH4xi5C/PYiEmJeaIhgaE2hjsHbq5zyRgiIf199tLovOH5MfKhtGcX+ZRBUtS /F5sSaWtSDT54mwaeY3AWMVidSPEJQFeZ4yEZQ1Ona/TpGryQoxiRjY8ah9acgpXRU6BL00 6KmZ3DS5NXoEdmkiTnOykaFz6Cu8YR/8elR/E2knszdeujRYJlXTp5UEK5Y9VGt5LfrcCrG X-QQ-GoodBg: 0 From: Zhangjin Wu To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Cc: Thomas Bogendoerfer , Palmer Dabbelt , Willy Tarreau , Paul Burton , "Paul E . McKenney" , Paul Walmsley , Nicholas Mc Guire , Zhangjin Wu Subject: [RFC PATCH 0/5] Add dead syscalls elimination support Date: Fri, 17 Feb 2023 08:49:20 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758037495915515568?= X-GMAIL-MSGID: =?utf-8?q?1758037495915515568?= Hi, all CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION allows to eliminate dead code and data, this patchset allows to further eliminate dead syscalls which are not used in target system. It includes 5 patches: - syscall: Allow configure used system calls This adds a new CONFIG_SYSCALLS_USED option to allow users or tools to tell kernel what syscalls are used in target system. A list of used syscalls can be passed to it. - MIPS: Add dead syscalls elimination support Add CONFIG_SYSCALLS_USED support for mips, it simply adds a 'used' variant for the syscall*.tbl and accordingly updates the kernel apis and eventually the sys_call_table. The unused ones in the table are replaced by sys_ni_syscall and therefore if they are also not used by kernel itself, they will be eliminated by gc-sections. The old architectures use syscall*.tbl, so, they can use this method. - RISC-V: Enable dead code elimination Select HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv. - RISC-V: Add dead syscalls elimination support Add CONFIG_SYSCALLS_USED support for riscv, it simply adds a 'used' variant for the *syscall_table.c and eventually the sys_call_table. The new architectures use generic unistd.h, they can use this method. - nolibc: Record used syscalls in their own sections This allows to record syscalls used by a nolibc based application. It is possible to eliminate dead syscalls automatically while building the monolithic kernel+nolibc software. Testing shows, on both mips and riscv, with a small config, gc-sections shrinks ~10% and syscalls_used shrinks another ~5%. This patchset is only a prototype implementation, welcome your feedback and suggestion, Thanks. Related emails: - Re: Re: Kernel-only deployments https://lore.kernel.org/lkml/20230216130935.37976-1-falcon@tinylab.org/ - Re: Re: RISC-V: Enable dead code elimination https://lore.kernel.org/linux-riscv/Y+qSBu3YZH0JPY4I@spud/T/#t Best Regards, - Zhangjin Wu --- Zhangjin Wu (5): syscall: Allow configure used system calls MIPS: Add dead syscalls elimination support RISC-V: Enable dead code elimination RISC-V: Add dead syscalls elimination support nolibc: Record used syscalls in their own sections arch/mips/Kconfig | 1 + arch/mips/kernel/syscalls/Makefile | 24 ++++++++- arch/riscv/Kconfig | 2 + arch/riscv/kernel/Makefile | 5 +- arch/riscv/kernel/syscalls/Makefile | 38 ++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 2 +- init/Kconfig | 22 +++++++++ tools/include/nolibc/Makefile | 2 +- tools/include/nolibc/arch-aarch64.h | 17 ++++--- tools/include/nolibc/arch-arm.h | 15 +++--- tools/include/nolibc/arch-i386.h | 17 ++++--- tools/include/nolibc/arch-mips.h | 15 +++--- tools/include/nolibc/arch-riscv.h | 17 ++++--- tools/include/nolibc/arch-x86_64.h | 17 ++++--- tools/include/nolibc/arch.h | 2 + tools/include/nolibc/record.h | 77 +++++++++++++++++++++++++++++ 16 files changed, 226 insertions(+), 47 deletions(-) create mode 100644 arch/riscv/kernel/syscalls/Makefile create mode 100644 tools/include/nolibc/record.h