From patchwork Thu Sep 5 13:33:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13792368 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 3B87919D89F; Thu, 5 Sep 2024 13:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543206; cv=none; b=XNH51kXC3kiwvkdQWCepL3VYY3j8048stjL1vT6bTRKU54Xpp3DvanOVGq4424MIdmfksKtHlBRTyI+8PvK0aiJhmO16sZrsXewhrNCUZqkzVJa63HZN5SvHRXEVwNqpCMepkz7qOpspQEP0fx7F5eosg1+pXS9vWGGmJn0OUCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543206; c=relaxed/simple; bh=q9PK02pd92y+v95I+RdQsTEBNzvKFSGnPjB2K/vbR1o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IAAt5gD8leOJOq7T834PNDM1KYmbdLF62IQwsIKOUc6mexVjvpkVOb4ccVJiQAZo8UkvZqS1PFJQjZAqFa4sBYltyzRVdHS0YSRPUrks3Gf6NvRIYZMB3QOilQ+KvUp4W3Ju5zSqNYRCVRePAgA2E/YB05Sbg62N+sNYc/BYQlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=1Pws76qz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=A49hOezD; arc=none smtp.client-ip=103.168.172.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="1Pws76qz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A49hOezD" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 65A101380053; Thu, 5 Sep 2024 09:33:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 09:33:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1725543202; x=1725629602; bh=qimAV3wto6Axv7quLFDukEk8DBO0+3lc2rfy5X5Nb2s=; b= 1Pws76qzQNZM1pa1R+KK6JsBF3Al4dbNjWYmyzUrwIUI+NvaGLSjzc5SdBBrL39W tBgJ6p27gWFXKgrRj0xqk262W5X55vQJLXODRqhx5hcnrdqpWkmPvTmyvHorVOJ+ AO0I5/7PqWAj02Dtup8WABYQTdo5Hp/kZv/m4fjuqONmUbOVQq+Y+LeMIh5vtsSU op8kjSpIgRx9/H/Ow+4K3vrtC/qCUXiyclB3RxgJ+WpfUw34RhGEAEFTl0Tbfs/D A3HPt/5CMUWW0QiDEBRmMwdAOS9qDts5Rfv6T9J5Eoyo+XF6BXouex0eACOY9aVW /mV4m8YtpqDGjwE/dyUgFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725543202; x= 1725629602; bh=qimAV3wto6Axv7quLFDukEk8DBO0+3lc2rfy5X5Nb2s=; b=A 49hOezDYQg+JjV7UcPnkQoEUBGJ/TDSUkAYROcKNbAG/N7BwFq63a61MsUc9Pgh7 UWJhAMLP9XgkfxL1c/P/TgttJ4nE/q3aSl5vhek7IvXzFaZ3usBMYs9D4rkoydZm Im/6kP2dBgnW+259kyYfXye/gsj5YBxQ4abq8mPDtiJ3MPKZXSGtcBGXIptjf2eL 88v+NsneTSV1KCmgNwarWwH/kalUekqAwqKDh9Jtw25/fzMI5V8NfKgt5JOJpqox o+dfu+eMHIJnJjR2fabdRm6XoiAy8an3bKMZRFucnbBuU9/H9X2TS5BcOQYN+1K7 rLlziB0/4kstO41pINU5Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnheptdekieeugedtffetueffjeelvdek keffgeduleegudefkedtgefhhffhieegiefgnecuffhomhgrihhnpehgnhhurdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhirgig uhhnrdihrghnghesfhhlhihgohgrthdrtghomhdpnhgspghrtghpthhtohepgedtpdhmoh guvgepshhmthhpohhuthdprhgtphhtthhopehnuggvshgruhhlnhhivghrshesghhoohhg lhgvrdgtohhmpdhrtghpthhtohepmhhinhhgohesrhgvughhrghtrdgtohhmpdhrtghpth htoheprhhoshhtvgguthesghhoohgumhhishdrohhrghdprhgtphhtthhopehmhhhirhgr mhgrtheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprgdrhhhinhgusghorhhgsehsrg hmshhunhhgrdgtohhmpdhrtghpthhtohepsghjohhrnhefpghghhesphhrohhtohhnmhgr ihhlrdgtohhmpdhrtghpthhtohepgiekieeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoh epfigvughsohhnrghfsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhinhhugidqmhhi phhssehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 09:33:18 -0400 (EDT) From: Jiaxun Yang Date: Thu, 05 Sep 2024 14:33:05 +0100 Subject: [PATCH v2 1/3] rust: Introduce HAVE_GENERATE_RUST_TARGET config option Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-mips-rust-v2-1-409d66819418@flygoat.com> References: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> In-Reply-To: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Thomas Bogendoerfer , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Jonathan Corbet , Alex Shi , Yanteng Si , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-um@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mips@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, llvm@lists.linux.dev, Jiaxun Yang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4405; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=q9PK02pd92y+v95I+RdQsTEBNzvKFSGnPjB2K/vbR1o=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSbm8WZX2o4zdgxVyZfmPWpzcW7/39KRB/htN5QpH9If eOqrW9/dJSyMIhxMciKKbKECCj1bWi8uOD6g6w/MHNYmUCGMHBxCsBEPFkYGdaoZFjN/TVR8sSp hWK3ZWLWFqvr9p4Tjn/lcuuZ8Jp7K8wZGe5GJrZPidTY8fb3KsaNHVolOa+WCTmGOZ17yFpbmPl 1BhcA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 scripts/generate_rust_target.rs is used by several architectures to generate target.json target spec file. However the enablement of this feature was controlled by target specific Makefile pieces spreading everywhere. Introduce HAVE_GENERATE_RUST_TARGET config option as a centralized switch to control the per-arch usage of generate_rust_target.rs. Signed-off-by: Jiaxun Yang --- v2: - Reword Kconfig help - Remove x86 specific condition for UM --- Makefile | 3 +++ arch/Kconfig | 8 ++++++++ arch/um/Kconfig | 1 + arch/x86/Makefile | 1 - arch/x86/Makefile.um | 1 - rust/Makefile | 2 +- scripts/Makefile | 4 +--- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 2c1db7a6f793..b183855c34ea 100644 --- a/Makefile +++ b/Makefile @@ -807,6 +807,9 @@ KBUILD_CFLAGS += -Os KBUILD_RUSTFLAGS += -Copt-level=s endif +ifdef CONFIG_HAVE_GENERATE_RUST_TARGET +KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json +endif # Always set `debug-assertions` and `overflow-checks` because their default # depends on `opt-level` and `debug-assertions`, respectively. KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) diff --git a/arch/Kconfig b/arch/Kconfig index 4e2eaba9e305..0865ff4796e7 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -377,6 +377,14 @@ config HAVE_RUST This symbol should be selected by an architecture if it supports Rust. +config HAVE_GENERATE_RUST_TARGET + bool + depends on HAVE_RUST + help + This symbol should be selected by an architecture if it + needs generating Rust target.json file with + scripts/generate_rust_target.rs. + config HAVE_FUNCTION_ARG_ACCESS_API bool help diff --git a/arch/um/Kconfig b/arch/um/Kconfig index dca84fd6d00a..6b1c8ae2422d 100644 --- a/arch/um/Kconfig +++ b/arch/um/Kconfig @@ -32,6 +32,7 @@ config UML select TTY # Needed for line.c select HAVE_ARCH_VMAP_STACK select HAVE_RUST + select HAVE_GENERATE_RUST_TARGET select ARCH_HAS_UBSAN config MMU diff --git a/arch/x86/Makefile b/arch/x86/Makefile index a1883a30a5d8..cbd707f88a63 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -75,7 +75,6 @@ export BITS # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 # KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 # diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um index a46b1397ad01..2106a2bd152b 100644 --- a/arch/x86/Makefile.um +++ b/arch/x86/Makefile.um @@ -9,7 +9,6 @@ core-y += arch/x86/crypto/ # ifeq ($(CONFIG_CC_IS_CLANG),y) KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 endif diff --git a/rust/Makefile b/rust/Makefile index 99204e33f1dd..fe3640b98011 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -378,7 +378,7 @@ $(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--re $(obj)/core.o: private rustc_target_flags = $(core-cfgs) $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE +$(call if_changed_rule,rustc_library) -ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) +ifdef CONFIG_HAVE_GENERATE_RUST_TARGET $(obj)/core.o: scripts/target.json endif diff --git a/scripts/Makefile b/scripts/Makefile index dccef663ca82..33258a856a1a 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -12,13 +12,11 @@ hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_builder hostprogs-always-$(CONFIG_RUST_KERNEL_DOCTESTS) += rustdoc_test_gen -ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),) -always-$(CONFIG_RUST) += target.json +always-$(CONFIG_HAVE_GENERATE_RUST_TARGET) += target.json filechk_rust_target = $< < include/config/auto.conf $(obj)/target.json: scripts/generate_rust_target include/config/auto.conf FORCE $(call filechk,rust_target) -endif hostprogs += generate_rust_target generate_rust_target-rust := y From patchwork Thu Sep 5 13:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13792369 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 C26B219DF51; Thu, 5 Sep 2024 13:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543209; cv=none; b=o4PDqPn13R8Pc1h5pIbLSBX5905QllX0SlDZd5rWWlRQRY5I7+0iBRdudCvwXok0JFC5JyXjlNTg44FMfu2VWIUfLkDq6rGaLZn3PJShSKQGMXTQ0KKqsiUf42K6zyhX4zoVAr6Md+0l6RqeMBsfHYtNBYBAOZnpIVAhERh6FsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543209; c=relaxed/simple; bh=3K6o6Y8Ib1fJ7SBPgZmUC+L5hQTpFLi2ds4RhATIGXI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m0i+4X2eCbpPMiKTLSaq0P/mgbqDWZTqh3ptycVcFf1n87vZRD9JfY4hPWbzqwc9KplQiUjgklYyiOEGpHiCN/FWHJmBOXmoH0kHBPODag83Geq+FhxqF5R4HIW4oRzQELzRxI2MclA3AcBLJT3Z5QNgsgsz96YR9rxLx0zewyQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=APa+NfSb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eJpDy1DI; arc=none smtp.client-ip=103.168.172.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="APa+NfSb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eJpDy1DI" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id DB9FF1380377; Thu, 5 Sep 2024 09:33:26 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 05 Sep 2024 09:33:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1725543206; x=1725629606; bh=rDJZVFYK8cRPG/ZY0D6is9Wvxf+gYsggMAPKn3+QD4o=; b= APa+NfSb+NaPKLm/clSjNyyRQ+CvPj7uuwwrPW1ZvdkK+YXVQ38ALEw8V2j2gwvb WUo6+NQeww4TmPli3EpBhYThuH313PSGFAcP66DxKlAWJnH0bdtL4S2VplUnl+Q/ DTEdLI5X6VM4LFZfvw5UaPaM+bznr5/cZuKN3+jSp9KBtgpP2DcuoYUjGwNoS/lA mdWEsv9SrtVqpGZ7fBFFKY/oeRgfZBRvUr6jKW9sg79oROLF3rppu3LU105xE9Qb JsFnnf6A4qIVYduWsZpDM6NSQStF/n8ft51q0SHDfZPiJBy5B9ZDcPdEw69I8Fof r3cNf3pf8y6j/dUcXGazWg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725543206; x= 1725629606; bh=rDJZVFYK8cRPG/ZY0D6is9Wvxf+gYsggMAPKn3+QD4o=; b=e JpDy1DI6b/4LuKdnbm6qIF11FgQAC9BWgQXFmtlK+asFVAv4hBzZ0qxEdDQfEFYk FDNWTAUfKziw5y3BpdZPLNDS9voQOVqJ85dc5Pt1ZsdFscsArZqpPwSPyW/x1TB8 KvnRH3vCUQBmaR+BO5YO3Hz4/6aEeBVZNisFbhJu4hwL+vAOHgKXywZT6nTjqdyp 2rdWFOrMDkhxOP/Bno7tyN0N3gpvEQiznnGrlKFycyNegUdL8+F3pIJILgU23FgP 2H3TM6uDwECYk+nV2oNPJL/2b+pSyfbBmD2SEbhz2xqnEOCUUizN2WjWWPU7RWlI SUPbEcvcwzUV2p46EqMhw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr tghomhdpnhgspghrtghpthhtohepgedtpdhmohguvgepshhmthhpohhuthdprhgtphhtth hopehnuggvshgruhhlnhhivghrshesghhoohhglhgvrdgtohhmpdhrtghpthhtohepmhhi nhhgohesrhgvughhrghtrdgtohhmpdhrtghpthhtoheprhhoshhtvgguthesghhoohgumh hishdrohhrghdprhgtphhtthhopehmhhhirhgrmhgrtheskhgvrhhnvghlrdhorhhgpdhr tghpthhtoheprgdrhhhinhgusghorhhgsehsrghmshhunhhgrdgtohhmpdhrtghpthhtoh epsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtohepgiek ieeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepfigvughsohhnrghfsehgmhgrihhlrd gtohhmpdhrtghpthhtoheplhhinhhugidqmhhiphhssehvghgvrhdrkhgvrhhnvghlrdho rhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 09:33:22 -0400 (EDT) From: Jiaxun Yang Date: Thu, 05 Sep 2024 14:33:06 +0100 Subject: [PATCH v2 2/3] MIPS: Rename mips_instruction type to workaround bindgen issue Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-mips-rust-v2-2-409d66819418@flygoat.com> References: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> In-Reply-To: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Thomas Bogendoerfer , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Jonathan Corbet , Alex Shi , Yanteng Si , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-um@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mips@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, llvm@lists.linux.dev, Jiaxun Yang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6623; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=3K6o6Y8Ib1fJ7SBPgZmUC+L5hQTpFLi2ds4RhATIGXI=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSbm8WdVK9V5xz5aygReSNuw6mU0DcnMi6Eru0zOrTLe 0pilWJ8RykLgxgXg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAEyk2ZGR4W/ywviWDQnXtuRG zMt6/J556pQLkY6c12unHT/tsziB8yojw+fu/Z1+G7Zm9+h+6A4RON69jd/l/cdWs0PzWUN1+iP +cgAA X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 We have a union and a type both named after mips_instruction, rust bindgen is not happy with this kind of naming alias. Given that union mips_instruction is a part of UAPI, the best thing we can do is to rename mips_instruction type. Rename it as mips_insn, which is not conflicting with anything and aligned with struct name here. Signed-off-by: Jiaxun Yang --- v2: Reword commit messsage --- arch/mips/include/asm/dsemul.h | 2 +- arch/mips/include/asm/inst.h | 6 +++--- arch/mips/kernel/ftrace.c | 2 +- arch/mips/kernel/kprobes.c | 2 +- arch/mips/math-emu/cp1emu.c | 18 +++++++++--------- arch/mips/math-emu/dsemul.c | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/mips/include/asm/dsemul.h b/arch/mips/include/asm/dsemul.h index 08bfe8fa3b40..870597d6d1ad 100644 --- a/arch/mips/include/asm/dsemul.h +++ b/arch/mips/include/asm/dsemul.h @@ -34,7 +34,7 @@ struct task_struct; * * Return: Zero on success, negative if ir is a NOP, signal number on failure. */ -extern int mips_dsemul(struct pt_regs *regs, mips_instruction ir, +extern int mips_dsemul(struct pt_regs *regs, mips_insn ir, unsigned long branch_pc, unsigned long cont_pc); /** diff --git a/arch/mips/include/asm/inst.h b/arch/mips/include/asm/inst.h index 2f98ced30263..0616b8eb7401 100644 --- a/arch/mips/include/asm/inst.h +++ b/arch/mips/include/asm/inst.h @@ -71,12 +71,12 @@ #define I_FMA_FFMT_SFT 0 #define MIPSInst_FMA_FFMT(x) (MIPSInst(x) & 0x00000007) -typedef unsigned int mips_instruction; +typedef unsigned int mips_insn; /* microMIPS instruction decode structure. Do NOT export!!! */ struct mm_decoded_insn { - mips_instruction insn; - mips_instruction next_insn; + mips_insn insn; + mips_insn next_insn; int pc_inc; int next_pc_inc; int micro_mips_mode; diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c index 8c401e42301c..153c9666a77c 100644 --- a/arch/mips/kernel/ftrace.c +++ b/arch/mips/kernel/ftrace.c @@ -248,7 +248,7 @@ int ftrace_disable_ftrace_graph_caller(void) #define S_R_SP (0xafb0 << 16) /* s{d,w} R, offset(sp) */ #define OFFSET_MASK 0xffff /* stack offset range: 0 ~ PT_SIZE */ -unsigned long ftrace_get_parent_ra_addr(unsigned long self_ra, unsigned long +static long ftrace_get_parent_ra_addr(unsigned long self_ra, unsigned long old_parent_ra, unsigned long parent_ra_addr, unsigned long fp) { unsigned long sp, ip, tmp; diff --git a/arch/mips/kernel/kprobes.c b/arch/mips/kernel/kprobes.c index dc39f5b3fb83..7a1b1c3674da 100644 --- a/arch/mips/kernel/kprobes.c +++ b/arch/mips/kernel/kprobes.c @@ -90,7 +90,7 @@ int arch_prepare_kprobe(struct kprobe *p) } if (copy_from_kernel_nofault(&prev_insn, p->addr - 1, - sizeof(mips_instruction)) == 0 && + sizeof(kprobe_opcode_t)) == 0 && insn_has_delayslot(prev_insn)) { pr_notice("Kprobes for branch delayslot are not supported\n"); ret = -EINVAL; diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c index 265bc57819df..bcd6a6f0034c 100644 --- a/arch/mips/math-emu/cp1emu.c +++ b/arch/mips/math-emu/cp1emu.c @@ -43,10 +43,10 @@ /* Function which emulates a floating point instruction. */ static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *, - mips_instruction); + mips_insn); static int fpux_emu(struct pt_regs *, - struct mips_fpu_struct *, mips_instruction, void __user **); + struct mips_fpu_struct *, mips_insn, void __user **); /* Control registers */ @@ -846,7 +846,7 @@ do { \ * Emulate a CFC1 instruction. */ static inline void cop1_cfc(struct pt_regs *xcp, struct mips_fpu_struct *ctx, - mips_instruction ir) + mips_insn ir) { u32 fcr31 = ctx->fcr31; u32 value = 0; @@ -903,7 +903,7 @@ static inline void cop1_cfc(struct pt_regs *xcp, struct mips_fpu_struct *ctx, * Emulate a CTC1 instruction. */ static inline void cop1_ctc(struct pt_regs *xcp, struct mips_fpu_struct *ctx, - mips_instruction ir) + mips_insn ir) { u32 fcr31 = ctx->fcr31; u32 value; @@ -973,7 +973,7 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx, { unsigned long contpc = xcp->cp0_epc + dec_insn.pc_inc; unsigned int cond, cbit, bit0; - mips_instruction ir; + mips_insn ir; int likely, pc_inc; union fpureg *fpr; u32 __user *wva; @@ -1461,7 +1461,7 @@ DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg); DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg); static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx, - mips_instruction ir, void __user **fault_addr) + mips_insn ir, void __user **fault_addr) { unsigned int rcsr = 0; /* resulting csr */ @@ -1680,7 +1680,7 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx, * Emulate a single COP1 arithmetic instruction. */ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx, - mips_instruction ir) + mips_insn ir) { int rfmt; /* resulting format */ unsigned int rcsr = 0; /* resulting csr */ @@ -2899,9 +2899,9 @@ int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx, dec_insn.micro_mips_mode = 1; } else { if ((get_user(dec_insn.insn, - (mips_instruction __user *) xcp->cp0_epc)) || + (mips_insn __user *) xcp->cp0_epc)) || (get_user(dec_insn.next_insn, - (mips_instruction __user *)(xcp->cp0_epc+4)))) { + (mips_insn __user *)(xcp->cp0_epc+4)))) { MIPS_FPU_EMU_INC_STATS(errors); return SIGBUS; } diff --git a/arch/mips/math-emu/dsemul.c b/arch/mips/math-emu/dsemul.c index e02bd20b60a6..d4ea2cf89006 100644 --- a/arch/mips/math-emu/dsemul.c +++ b/arch/mips/math-emu/dsemul.c @@ -61,8 +61,8 @@ * couldn't already. */ struct emuframe { - mips_instruction emul; - mips_instruction badinst; + mips_insn emul; + mips_insn badinst; }; static const int emupage_frame_count = PAGE_SIZE / sizeof(struct emuframe); @@ -206,11 +206,11 @@ void dsemul_mm_cleanup(struct mm_struct *mm) bitmap_free(mm_ctx->bd_emupage_allocmap); } -int mips_dsemul(struct pt_regs *regs, mips_instruction ir, +int mips_dsemul(struct pt_regs *regs, mips_insn ir, unsigned long branch_pc, unsigned long cont_pc) { int isa16 = get_isa16_mode(regs->cp0_epc); - mips_instruction break_math; + mips_insn break_math; unsigned long fr_uaddr; struct emuframe fr; int fr_idx, ret; From patchwork Thu Sep 5 13:33:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13792370 Received: from fout3-smtp.messagingengine.com (fout3-smtp.messagingengine.com [103.168.172.146]) (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 53F7F19D884; Thu, 5 Sep 2024 13:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543213; cv=none; b=F6xeRMu9iZ6lwLlx4HEvlRFjczPxn21BIdenmNh0zIsKgTT5mr3ITx6RQvmtpEWi14rXJLAd0ojjzFqYWqfWJB2i8UCSOG/JNuwfmWldkQVkn0NA715XdSfbOGrt0sr5pPLJziif8lgY5lkHyGiSn3B8c6vEhG4JJw+AtXznV3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725543213; c=relaxed/simple; bh=dVkj/exm1KSiU0b/0TGp9u+BBn+LGdFz9eAdIeMiN8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hj4Tjc+1JK6hx8TySB4BIZyKDFy6ltUcsVuyhMDtRdfEHP+uAg/OCIGTfwuO/zdB6JKFeKKvczX09dtgprkbvly139dXIgcov03wO8Twqzbs+UFcij4qWDoOaIhPZcWVEGixxzeaZAc6JKVYgflp7WHxh+QPLdOGTw9oUihmKEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com; spf=pass smtp.mailfrom=flygoat.com; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b=DUFu6lhN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hCRduZd0; arc=none smtp.client-ip=103.168.172.146 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=flygoat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flygoat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="DUFu6lhN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hCRduZd0" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 8E231138026D; Thu, 5 Sep 2024 09:33:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 05 Sep 2024 09:33:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1725543211; x=1725629611; bh=z2B0F8060umJHdopRQNGtZEBNjqM4wVRBCzxrvcUhSw=; b= DUFu6lhN0qGUhUYatTxIHgIP6kNGLyzy1blThsogwkg/3YJpEEBIwCKMlq7I0x1Z oNoQpZ7ZheO+hVtlcv1fYCYq0CtsOuy+HKefI8MWS0ZeJaelN7SuOW8O6ZUXrlJt uU4qjMH6EuOul/uAKLiSvEeJkShmOkA9Jwwy5p5M8Yfz+uWlTrRBo53fEH9KXY40 0yZ8ycmK43QeHVOIt6J3CqM05Ukl9bQwSMsHXMWXLdv9hq7IJunrKt8nVwKIE3DC 72Br4R32cdWaCV0zXCznxc+4/lCjeg6gjLTlIKzV6RrV9Gr4lm3Z+PX45ocQkjOy gcwLmR3WuFRHE21bU32Ccw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725543211; x= 1725629611; bh=z2B0F8060umJHdopRQNGtZEBNjqM4wVRBCzxrvcUhSw=; b=h CRduZd0GkqMWAd0FuBYs1gHD3z8D+TUxc1eo7fMCVsiIYH3kObPBA/342p5kcXg9 GxyRnK1t0guZHd7ZQo3Piq60+XURaNkjhXRwue3GC1TftadQbqdPLOdBMqc8r+H1 jn3e3/jAR/HKeqwpz5wqlAhRDiTw8ey7B33eHHw9GLZjYB3397AgnhERzjZ95wjI TPzwx2CbDmQR45ldUA8hCNeuRkHLP8qudFe7IFqWE22Sb53Kr/UVw3L2tMB+BYzs K+bU/hx8BZfGXIbONG2oJj4BQljaPFU/pqrMIrd+khsmwZq1Kze1Ph5WKIxnvkfI fd//X7b4hXlRN0BZQ0hUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtkeertdertdej necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepledutdeigeehvdegkedvudevffdt hedttddtjeevuddtgfektdekgfdtgedtieevnecuffhomhgrihhnpehgihhthhhusgdrtg homhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehj ihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhnsggprhgtphhtthhopeegtd dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepnhguvghsrghulhhnihgvrhhssehg ohhoghhlvgdrtghomhdprhgtphhtthhopehmihhnghhosehrvgguhhgrthdrtghomhdprh gtphhtthhopehrohhsthgvughtsehgohhoughmihhsrdhorhhgpdhrtghpthhtohepmhhh ihhrrghmrghtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrrdhhihhnuggsohhrgh esshgrmhhsuhhnghdrtghomhdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothho nhhmrghilhdrtghomhdprhgtphhtthhopeigkeeisehkvghrnhgvlhdrohhrghdprhgtph htthhopeifvggushhonhgrfhesghhmrghilhdrtghomhdprhgtphhtthhopehlihhnuhig qdhmihhpshesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Sep 2024 09:33:27 -0400 (EDT) From: Jiaxun Yang Date: Thu, 05 Sep 2024 14:33:07 +0100 Subject: [PATCH v2 3/3] rust: Enable for MIPS Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240905-mips-rust-v2-3-409d66819418@flygoat.com> References: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> In-Reply-To: <20240905-mips-rust-v2-0-409d66819418@flygoat.com> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Thomas Bogendoerfer , Steven Rostedt , Masami Hiramatsu , Mark Rutland , Jonathan Corbet , Alex Shi , Yanteng Si , Nick Desaulniers , Bill Wendling , Justin Stitt Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-um@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mips@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, llvm@lists.linux.dev, Jiaxun Yang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5800; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=dVkj/exm1KSiU0b/0TGp9u+BBn+LGdFz9eAdIeMiN8A=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrSbm8Xny0wpaS6zMgrh3PNl5YuLz+8Zsv5d7N0mF9oho p24+WxwRykLgxgXg6yYIkuIgFLfhsaLC64/yPoDM4eVCWQIAxenAExEIJaRoe9RxA3OG0se3WJ6 lOPL4i1dUTfX6Kdsc/8qDvWVAusyXjAydDeeWrP5vHfo5tqXnse38Po/+p/++EsJD/+NDq7tRj0 H+AE= X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 Enable rust for linux by implement generate_rust_target.rs and select relevant Kconfig options. We don't use builtin target as there is no sutiable baremetal target for us that can cover all ISA variants supported by kernel. Link: https://github.com/Rust-for-Linux/linux/issues/107 Signed-off-by: Jiaxun Yang --- v2: - Add micromips flags - Sync issues with upstream --- Documentation/rust/arch-support.rst | 1 + .../translations/zh_CN/rust/arch-support.rst | 1 + arch/mips/Kconfig | 2 + scripts/generate_rust_target.rs | 68 ++++++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst index 750ff371570a..ab6c0ae5a407 100644 --- a/Documentation/rust/arch-support.rst +++ b/Documentation/rust/arch-support.rst @@ -17,6 +17,7 @@ Architecture Level of support Constraints ============= ================ ============================================== ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- +``mips`` Maintained \- ``riscv`` Maintained ``riscv64`` only. ``um`` Maintained \- ``x86`` Maintained ``x86_64`` only. diff --git a/Documentation/translations/zh_CN/rust/arch-support.rst b/Documentation/translations/zh_CN/rust/arch-support.rst index abd708d48f82..1eaa6c3297ac 100644 --- a/Documentation/translations/zh_CN/rust/arch-support.rst +++ b/Documentation/translations/zh_CN/rust/arch-support.rst @@ -21,6 +21,7 @@ ============= ================ ============================================== ``arm64`` Maintained 只有小端序 ``loongarch`` Maintained \- +``mips`` Maintained \- ``riscv`` Maintained 只有 ``riscv64`` ``um`` Maintained 只有 ``x86_64`` ``x86`` Maintained 只有 ``x86_64`` diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 43da6d596e2b..a91f0a4fd8e9 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -90,6 +90,8 @@ config MIPS select HAVE_PERF_USER_STACK_DUMP select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RSEQ + select HAVE_RUST + select HAVE_GENERATE_RUST_TARGET select HAVE_SPARSE_SYSCALL_NR select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 863720777313..bbdf8a4dd169 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -141,6 +141,13 @@ fn has(&self, option: &str) -> bool { let option = "CONFIG_".to_owned() + option; self.0.contains_key(&option) } + + /// Returns the value of the option in the configuration. + /// The argument must be passed without the `CONFIG_` prefix. + fn get(&self, option: &str) -> Option<&String> { + let option = "CONFIG_".to_owned() + option; + self.0.get(&option) + } } fn main() { @@ -203,6 +210,67 @@ fn main() { ts.push("target-pointer-width", "32"); } else if cfg.has("LOONGARCH") { panic!("loongarch uses the builtin rustc loongarch64-unknown-none-softfloat target"); + } else if cfg.has("MIPS") { + let mut features = "+soft-float,+noabicalls".to_string(); + + if cfg.has("CPU_MICROMIPS") { + features += ",+micromips"; + } + + if cfg.has("64BIT") { + ts.push("arch", "mips64"); + ts.push("abi", "abi64"); + cfg.get("TARGET_ISA_REV").map(|isa_rev| { + let feature = match isa_rev.as_str() { + "1" => ",+mips64", + "2" => ",+mips64r2", + "5" => ",+mips64r5", + "6" => ",+mips64r6", + _ => ",+mips3", + }; + features += feature; + }); + + ts.push("features", features); + if cfg.has("CPU_BIG_ENDIAN") { + ts.push( + "data-layout", + "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128", + ); + ts.push("llvm-target", "mips64-unknown-linux-gnuabi64"); + } else { + ts.push( + "data-layout", + "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128", + ); + ts.push("llvm-target", "mips64el-unknown-linux-gnuabi64"); + } + ts.push("target-pointer-width", "64"); + } else { + ts.push("arch", "mips"); + cfg.get("TARGET_ISA_REV").map(|isa_rev| { + let feature = match isa_rev.as_str() { + "1" => ",+mips32", + "2" => ",+mips32r2", + "5" => ",+mips32r5", + "6" => ",+mips32r6", + _ => ",+mips2", + }; + features += feature; + }); + + ts.push("features", features); + if cfg.has("CPU_BIG_ENDIAN") { + ts.push("data-layout", + "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"); + ts.push("llvm-target", "mips-unknown-linux-gnu"); + } else { + ts.push("data-layout", + "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64"); + ts.push("llvm-target", "mipsel-unknown-linux-gnu"); + } + ts.push("target-pointer-width", "32"); + } } else { panic!("Unsupported architecture"); }