From patchwork Tue Sep 3 17:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13789121 Received: from pfhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 31D9918EFC8; Tue, 3 Sep 2024 17:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383700; cv=none; b=oDNSGDZTyHiceoVHYLQebc69ZjA24e5n/jR4GMNyBx3u862A9JHHWf4SkF1KU0TOij5e6fEp6emmf/MVEuNYgKR6pO+2zwx8B9jG2r0sQIo3lkhwHsZ6ceATOCbILw+FMX7uktUutyqxeGuRxqNkN4EF0zRRFGY6S+MJijwnyJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383700; c=relaxed/simple; bh=MR0QUePB8OZ1VODonfrqqwGNaA0pJ9XHlCOwwVcwVbA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NaqkXR4O1D7918QEOYaxwxRyKwumkppaUsF7MGaqli4pcsrp6uJL+NnBr/9PbK/lvLA4slteIO6zdRPyJEM8Cl6dmih6bw9HNTuQGmZ6GPTji/0TAgXg9lojjh6YpNW70wm/oxG0ICjcgbCEDAJsBNciY3ZXYi8ofKSpRys1kRk= 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=ENWVfqdh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=n5RuJ26W; arc=none smtp.client-ip=103.168.172.155 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="ENWVfqdh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="n5RuJ26W" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5B5741140386; Tue, 3 Sep 2024 13:14:57 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 03 Sep 2024 13:14:57 -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=1725383697; x=1725470097; bh=GaNfLFB6/4i23a17e2/18ZaAcRG0PU148d7jkLs6on8=; b= ENWVfqdhswzFfJ0Riyd/SoKDjHaJVVN+1M20NyyK028ZsUTWD6+mynQFpC5OdzEV r63YtduuzZcIddkwmWdpviKtIvkB/ffH6yYFNwUhjFwReqjwgT+8TPb5B2x/58QY kqWtE+4rSDlRKI2UED/MzLMfouWjvYCejqU3asiWPq4yNywRyNzsI4PBiOFlpeNw gnfGZhYY+AtKBYw+QZJL6lLvwSs5SBLbG5VHmfdfoIE8mMcrlVnnxoEHxcYZfuza vyV5+k6RjFNLQVq8MhbVlraW69DHrF9/pGx5uNRwBc0tW2snPR/N1UqF1p9+22Z9 IfPxS/tulN4LyLtW6RTwvQ== 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=1725383697; x= 1725470097; bh=GaNfLFB6/4i23a17e2/18ZaAcRG0PU148d7jkLs6on8=; b=n 5RuJ26W3y2ljmUy6Kj+9cDtJ6jntB9XvUhoUeGEYWgCCRwijtXDzbDKCY9EFOpNM XTJNhIibnJrDVgKFC4duaZYBMWQVkme3EqL/DeHgT3zhcbpDXuS9aUN3GkmQhWMn YsKEATM5ABRaSDmU2aRLe4T5XYxhiVcmfugFNuPgB71ZZPIcZ7U6syubRthQqjh5 8CKOmy/f9o1LVCiuxeJwuYrXSd2RUfTqE5QWV7lvbysy/PZk4I3ezt0ug720laBD GamwcPHgDkR6R5IS9PqhO5dzy+Ixesygjk9ygfwWSBvkS/aaHl6COBWNbOnpomGE tiD4v4A+1i8JWJGax89+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehhedguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheplfhirgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflh ihghhorghtrdgtohhmqeenucggtffrrghtthgvrhhnpedtkeeiueegtdffteeuffejledv keekffegudelgedufeektdeghffhhfeigeeigfenucffohhmrghinhepghhnuhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjihgr gihunhdrhigrnhhgsehflhihghhorghtrdgtohhmpdhnsggprhgtphhtthhopeegtddpmh houggvpehsmhhtphhouhhtpdhrtghpthhtohepsggvnhhnohdrlhhoshhsihhnsehprhho thhonhdrmhgvpdhrtghpthhtohepthhssghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvg hnrdguvgdprhgtphhtthhopehjohhhrghnnhgvshesshhiphhsohhluhhtihhonhhsrdhn vghtpdhrtghpthhtoheplhhlvhhmsehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpth htohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthhtoheprhhitghhrghruges nhhougdrrghtpdhrtghpthhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtg hpthhtohepsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthht ohepnhgrthhhrghnsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Sep 2024 13:14:53 -0400 (EDT) From: Jiaxun Yang Date: Tue, 03 Sep 2024 18:14:34 +0100 Subject: [PATCH 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: <20240903-mips-rust-v1-1-0fdf0b2fd58f@flygoat.com> References: <20240903-mips-rust-v1-0-0fdf0b2fd58f@flygoat.com> In-Reply-To: <20240903-mips-rust-v1-0-0fdf0b2fd58f@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=4568; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=MR0QUePB8OZ1VODonfrqqwGNaA0pJ9XHlCOwwVcwVbA=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrTrLmws/AZvTVOTty7y77KvuPfXsePt2XnsPWa3t0dx8 3d/bNHpKGVhEONikBVTZAkRUOrb0HhxwfUHWX9g5rAygQxh4OIUgImkSDP84S6+efXswwsSHcLX NoZ/1jBZsrZn9vnV/8/HpAXNUONd6s3IME1D3M2xqtK/Vfb0ip/zjTR4Z4pKK6isenArzuLGZ50 qJgA= 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 --- Makefile | 4 ++++ 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, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 2c1db7a6f793..1310e7910fc4 100644 --- a/Makefile +++ b/Makefile @@ -560,6 +560,7 @@ KBUILD_RUSTFLAGS := $(rust_common_flags) \ -Zfunction-sections=n \ -Wclippy::float_arithmetic + KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_RUSTFLAGS_KERNEL := @@ -807,6 +808,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..eb3ff6cf8501 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 + supports generating Rust target files 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..414e5b01d575 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 if X86_32 || X86_64 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 Tue Sep 3 17:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13789122 Received: from pfhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 AFFDA18FC89; Tue, 3 Sep 2024 17:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383704; cv=none; b=lKY5sPrawxIdv+fa0oeXhuaZiOcMWsLy65O5jVIJTuYACilLR843chwp+0QerHOgeaSPyRtYSI75LCEjCjjjl/Qyke6gmwXhlcCnRKFm3FFsmuzYKHiVWtwRGIC71DNrmv9ft0SYM2mvs57ykVKC3a8/yIA32/IZbHU8dginMAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383704; c=relaxed/simple; bh=CIsXpNL4Xqbe4+3LwKSPPuuUUgffBKKKBhZHlqW00Cg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m231KttlSN4y+68m9MxVrpKwSYz9vJch/BQfCiDi9D+5amneXfxuStOPNs0424WIB1H0QGWdx1mwvA3QVeg8iZ6gvRWiRwq+wHc2QvT9meV3q1O4HxsKUv6sqDOXF8n4xvuGshzFM2s3JRSICuBkAImG060SfNN+X3716WxP5b0= 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=YDbD8uF7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kIkyhErU; arc=none smtp.client-ip=103.168.172.155 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="YDbD8uF7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kIkyhErU" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 08C6C114037B; Tue, 3 Sep 2024 13:15:02 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Tue, 03 Sep 2024 13:15:02 -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=1725383702; x=1725470102; bh=t3nDXJLzevMZ4WniFU7yDbmtsQYuSVyzF0RKOG2Eq3Y=; b= YDbD8uF7KodEPa+ofyavsEOzxJCqurTp3SI0bB46dt7aDK1sX5kQBrGwupxnMynh iGkmM2nm4qNMOiBMhFGF2ZkADqslUgiXdmdQ6XnE5AJUT0XcVHv5mkXQ4W9OoXaH DDabE7QpdTvT8lNpzXoL9C96lBtrQQZKGfmUOmbl3afjhIyzJpg4t9pBNyxgiyd8 hGOjL+4uN6/ZprxVArrdD6FBodiaHuHWPGYmKjjwFNP90BozeTEeEi8jYkLdQ/WP G6VwAcccN5kWe6jQPEBeFbrf0kFm8nV2+O00QeTAPg5Ml7yy2/A1hSg9aSjtLx/X 4WbKJrHSlByR3y44o9GP6g== 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=1725383702; x= 1725470102; bh=t3nDXJLzevMZ4WniFU7yDbmtsQYuSVyzF0RKOG2Eq3Y=; b=k IkyhErU6eL1hFHh3bFi8To9J6+sFo5ltkScOzTF/q2TO51XVl8j6EHZmG2fbrSh/ wmF9j0rGtO+i9Axlyu/xqYzszxuYvKz7bIzS9d7uenNBq+6xRp/80cj0SmOJ32Me YMM91QTY8lMsyutWSmBATG/f+kpswrhl4Q7PJwfbwJL9l5Y+UMCpBobo1c7yYevG y69PDitFPDonrXoMM1XKKqGmhwvV8XQFZQUYUjITwKnqWtKBBoUy4l1+Of3BC5fP riyCDurWZoRDd63h9OyYZnDAlclfZLvpsxvUdKLuPvHTqcVPZ52rkKygHOmriq0p yc+njotyHIwmP/umq3G8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehhedguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheplfhirgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflh ihghhorghtrdgtohhmqeenucggtffrrghtthgvrhhnpedvkeeihfefveekueevteefleff keegudeghfdtuddugefhueevgeffgedukeejleenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehjihgrgihunhdrhigrnhhgsehflhihghhorght rdgtohhmpdhnsggprhgtphhtthhopeegtddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepsggvnhhnohdrlhhoshhsihhnsehprhhothhonhdrmhgvpdhrtghpthhtohepthhs sghoghgvnhgusegrlhhphhgrrdhfrhgrnhhkvghnrdguvgdprhgtphhtthhopehjohhhrg hnnhgvshesshhiphhsohhluhhtihhonhhsrdhnvghtpdhrtghpthhtoheplhhlvhhmsehl ihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepghgrrhihsehgrghrhihguhhord hnvghtpdhrtghpthhtoheprhhitghhrghrugesnhhougdrrghtpdhrtghpthhtohepthhg lhigsehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtohepsghjohhrnhefpghghhesph hrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtohepnhgrthhhrghnsehkvghrnhgvlhdr ohhrgh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Sep 2024 13:14:57 -0400 (EDT) From: Jiaxun Yang Date: Tue, 03 Sep 2024 18:14:35 +0100 Subject: [PATCH 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: <20240903-mips-rust-v1-2-0fdf0b2fd58f@flygoat.com> References: <20240903-mips-rust-v1-0-0fdf0b2fd58f@flygoat.com> In-Reply-To: <20240903-mips-rust-v1-0-0fdf0b2fd58f@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=6582; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=CIsXpNL4Xqbe4+3LwKSPPuuUUgffBKKKBhZHlqW00Cg=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrTrLmztR2edEbzKcelDgmzRh5tFU2fd27y66MKPxq7+x 6yCNrdjO0pZGMS4GGTFFFlCBJT6NjReXHD9QdYfmDmsTCBDGLg4BWAib+4y/NMya+8+epvzINv7 btHfobmnhGV2FJqdzFU/UT1r6pH0rAhGhqUXrnoLvp13pdiOz6fiwZJ3P8O6l0ioVttlbWLKWWx zmRUA 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 only thing we can do is to rename mips_instruction type. Rename it as mips_insn, which is not conflicting with anything and fits the name of header. Signed-off-by: Jiaxun Yang --- 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 Tue Sep 3 17:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13789123 Received: from pfout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 7254D18DF91; Tue, 3 Sep 2024 17:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383709; cv=none; b=RfxWFZi5AohX5UQvs4lWdJeBp/eCX113QUCSN+22lQZ4QskC0ewRY4nMmCtkG92B5A64q50avMzMYWeQ/jE9eLODMSQ+oVXKRplreTzsLPY2sxhgp93ktSyc0u8YnxHIJqJXkvduqfEfjKPgF/ptkPrwTqCViLU4bYnRGssQSEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725383709; c=relaxed/simple; bh=dTzaFLygGDWP88YqbuvgFJnSRc3/FfsgZOCccEPIFZI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FUhR/NLQ/CU6NXhQVREQGivfxXbSQrRopDv52AmTEhCQISHaPzPBzJF+hv0ZSrI4+qvLlHoYc2gkgp9gCMIjSRS4a+ieZmKG/LxtV8Lz+tozds951PObbJjej36/8j4lUOymu6Bd1r6g5lGNK04BAuJQNggpuq+W7zbouTNiu8I= 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=PGuwc2O7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BY+gPJ6x; arc=none smtp.client-ip=103.168.172.150 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="PGuwc2O7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BY+gPJ6x" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 79CAF13804B3; Tue, 3 Sep 2024 13:15:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 03 Sep 2024 13:15:06 -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=1725383706; x=1725470106; bh=HuOQA+LeEAdoUFaZ37LQtKXkaxwkMq+TFIrVUVu3PCI=; b= PGuwc2O7DwWjBrPB/HKNhxJICtLiALHZ1BvRvWhStXJ8gnqzOKoSj6tt+R5nVX6t p1dIbQsCr7zQf8DsXXR2Oek+J1+vqhuJGF14O5PpfQ3garbuuuQsNwvQOUQ9MBwP RVlx3czKkoMfBGWyhpFJ96WqloomWnOyjPJpFlCcflJ/OK436iABaL8nhj2//JjS kz34DAHoDTKfm6cVaVWlm60akXnBTuMneRKZRYI5G7xBGLtGDRL/gHnRxCIA+AmH 6Zuo52n3sA0k3y3cWIZVJ6gTZ2Tl2azNohLUV3Lj0rF/bAPMZUIwgjfp3x2Di48X px2go0KzFiAvMF7Z46iNRg== 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=1725383706; x= 1725470106; bh=HuOQA+LeEAdoUFaZ37LQtKXkaxwkMq+TFIrVUVu3PCI=; b=B Y+gPJ6xKRVodzijUaby+sjD5jFg9SiXGR3XGY0bQRk7ETcC3+NDuiQ3zjkau9P+v KCWNkVHKJGqyqOgV9+HE7lFl6BZ7oh6H274Jsjxai939dpWUMOS/0cAE/LghvvKv qT4Vqwgvx7GZY4xwZVdoafNHeMd0PFS/JbePDE6NOoHTMxSDAKsMped2ViA3i3U3 3BPGLFqY8pf43twKczdhuu+xqIMBYqa5zomCDIVaGFVvwVYuTK25DFVlpVdAP8zx NCXRnGZfkXHLtRDk6xmpwh6DoindffxQZA2EQYTn1Q8qWpgqQWJ7DCiFrwPfm634 j51/RoFZfHvXNJDVzryYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehhedgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthekredtredt jeenucfhrhhomheplfhirgiguhhnucgjrghnghcuoehjihgrgihunhdrhigrnhhgsehflh ihghhorghtrdgtohhmqeenucggtffrrghtthgvrhhnpeeluddtieeghedvgeekvdduveff tdehtddttdejvedutdfgkedtkefgtdegtdeiveenucffohhmrghinhepghhithhhuhgsrd gtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep jhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomhdpnhgspghrtghpthhtohepge dtpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegsvghnnhhordhlohhsshhinhes phhrohhtohhnrdhmvgdprhgtphhtthhopehtshgsohhgvghnugesrghlphhhrgdrfhhrrg hnkhgvnhdruggvpdhrtghpthhtohepjhhohhgrnhhnvghssehsihhpshholhhuthhiohhn shdrnhgvthdprhgtphhtthhopehllhhvmheslhhishhtshdrlhhinhhugidruggvvhdprh gtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphhtthhopehrihgthhgr rhgusehnohgurdgrthdprhgtphhtthhopehtghhlgieslhhinhhuthhrohhnihigrdguvg dprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothhonhhmrghilhdrtghomhdprhgt phhtthhopehnrghthhgrnheskhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Sep 2024 13:15:02 -0400 (EDT) From: Jiaxun Yang Date: Tue, 03 Sep 2024 18:14:36 +0100 Subject: [PATCH 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: <20240903-mips-rust-v1-3-0fdf0b2fd58f@flygoat.com> References: <20240903-mips-rust-v1-0-0fdf0b2fd58f@flygoat.com> In-Reply-To: <20240903-mips-rust-v1-0-0fdf0b2fd58f@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=5640; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=dTzaFLygGDWP88YqbuvgFJnSRc3/FfsgZOCccEPIFZI=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhrTrLmy/VbhlTd99/7KW13KPufKGBw0FkU1B7Dszj5oUa Qn6Pl/ZUcrCIMbFICumyBIioNS3ofHigusPsv7AzGFlAhnCwMUpABPZNZeR4eFshrNzVwhttrhd 0yf5Z2d9yQ2X7gU8oWbsP76u15z0Q42RoefwMqE02eP7ns+pn328K6qhZqVvJm/ItXsCWye+OCD HzwwA 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 --- Documentation/rust/arch-support.rst | 1 + .../translations/zh_CN/rust/arch-support.rst | 1 + arch/mips/Kconfig | 2 + scripts/generate_rust_target.rs | 64 ++++++++++++++++++++++ 4 files changed, 68 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..2b8054f17c47 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,63 @@ 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("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"); }