From patchwork Mon Aug 12 23:29:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13761135 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95C11199380 for ; Mon, 12 Aug 2024 23:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723505360; cv=none; b=ZwtofjXkN2tv9iz2VthBW4gbLFKUzHc2g/Zg0GmR4BhsfyWfM8oj2uJ2UZ/ZFA2QqlC4N2vOQnafjwfdwXHvculrBFNZ3/XS+NMbXhhX/5fAOEgsxVVtBXR8cxG7K+YxHC01QvT31TpqOrhlGDHkvS983Vn5qJYTlqhsO/rTrV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723505360; c=relaxed/simple; bh=WNJRbJEWl/JK8Az8ghGCXWH3fm68Jwe8K6UK0+dCVTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=C0FgDvGZdWaZgy8kQFImTKH7yPTSzK5jvecljMEHiyeMPs4I0mE13q5GfJSW8RkJcbN21a5lfhBQIpyPDJxVawZKp1IbPStOJGxIijypCgetBhw6/F5mDs+z8HrPDH5TEWJzEUK5MCdUfrCxs0yAOLLK2uzeZnymrmDRgwlgs+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nI++Z9P0; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nI++Z9P0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65194ea3d4dso95893447b3.0 for ; Mon, 12 Aug 2024 16:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723505357; x=1724110157; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7N7Zf7M9w/vAcr3WmdKFD5NuAFU2ocCw/qlD1RHyGfQ=; b=nI++Z9P0Hbtgv6lZRMacQqBuLNhX/D9QUqU0JgQ/McFHvX75Mi9UKlyVfZ/pCERJ+T nZjivdKRBO0qIuLWfznqWg7H3ee31ctoIjGH1Men+tiN+WoAkzReKLwJUlBF8mH7jb+2 v62bjSR6LGhGsY7CvoDYeUXwPq/ZtxaGR4u4+WdhUdOMhnCJzVKwzmFzO0AlnlWZw6Gz c014NdptgSHwl50dIrfPB7k76dMvcagTp/MR+nEUnyR+WQxJUtBTkckEIGvsg+12Sp3Q AQZKclb2jhdwPztccN6+xKeSiFiqf6+UqwZ989tgKHxkk/m+HeXf4GUbe6yWNII9XWK2 hxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723505357; x=1724110157; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7N7Zf7M9w/vAcr3WmdKFD5NuAFU2ocCw/qlD1RHyGfQ=; b=EAv9SG0wi53/yl0/yABMJ6kz8P8NhmIRhpzhwkYS1J9ke2meoHEHsC/qov7PQDmKSP cJhj0yRKLP53dLjZORxYohxBpYWTV0GhKt/RWy1jZW2BXRCEhk9BjTHuBhQo5IUK3tqf 2hdC5EzgR4g/WaNL32QIDD+3puu5ZtbmNDdUlHrpE84utzpJMtr3c6/kYHco+M3n8uiQ Sr8wPwR0sWW66+w7xM++OJq5E+/HeotTyZll4tGMOwuatb0EOgfY0hmK0KcMnsW/Hug6 rxqF291gkZnB4Q3HkQMtmfQu4dZVufWO2FNjqGlZqasiS2/CRwrYN7+8VLSTTfFs9xkI LyEA== X-Forwarded-Encrypted: i=1; AJvYcCXBnv+COS76N/wMZpG2hztLU+l2hM2bc8qq3hvOadKb5pK3cphCKMA+6mxL7b4q8JV0XiKVpJAH9FP7IM3pREHx85c44j3ghl4l09M0 X-Gm-Message-State: AOJu0Yyx+fRNLlRIRZ2ZoDec8yqb2oj/0qUYyTdff+AR+4wdZ73EHbRA OS2WxYhOHKv+hTJWv+shrUAf7kQXtWmDXqRaWQ7hN+RUet0wb+To1p59nE6v+g69Kf0u33OOyoo Lckh6wg== X-Google-Smtp-Source: AGHT+IGRZ7bB9Rd9wSfHyVUbB3/tTwK9kGhukQq3NaerqGLW14qddIs8Na8NhFcz/b5szJZ/mPTFY0ftUxja X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a0d:e943:0:b0:68f:dfc2:98ee with SMTP id 00721157ae682-6a9755e3147mr733687b3.5.1723505357680; Mon, 12 Aug 2024 16:29:17 -0700 (PDT) Date: Mon, 12 Aug 2024 23:29:01 +0000 In-Reply-To: <20240812232910.2026387-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240812232910.2026387-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240812232910.2026387-2-mmaurer@google.com> Subject: [PATCH v2 1/3] kbuild: rust: Define probing macros for rustc From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, Masahiro Yamada , Alex Gaynor , Wedson Almeida Filho , Nathan Chancellor Cc: aliceryhl@google.com, samitolvanen@google.com, Matthew Maurer , Nicolas Schier , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev Creates flag probe macro variants for `rustc`. These are helpful because: 1. `rustc` support will soon be a minimum rather than a pinned version. 2. We already support multiple LLVMs linked into `rustc`, and these are needed to probe what LLVM parameters `rustc` will accept. Signed-off-by: Matthew Maurer --- scripts/Kconfig.include | 8 ++++++++ scripts/Makefile.compiler | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 3500a3d62f0d..becad3d0b1fd 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -64,3 +64,11 @@ ld-version := $(shell,set -- $(ld-info) && echo $2) cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1)) m32-flag := $(cc-option-bit,-m32) m64-flag := $(cc-option-bit,-m64) + +# $(rustc-option,) +# Return y if the Rust compiler supports , n otherwise +# Calls to this should be guarded so that they are not evaluated if +# CONFIG_HAVE_RUST is not set. +# If you are testing for unstable features, consider `rustc-min-version` +# instead, as features may have different completeness while available. +rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null -o .tmp_$$/tmp.rlib) diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index 92be0c9a13ee..485d66768a32 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -72,3 +72,18 @@ clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1) # ld-option # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) + +# __rustc-option +# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage) +__rustc-option = $(call try-run,\ + $(1) $(2) $(3) --crate-type=rlib /dev/null -o "$$TMP",$(3),$(4)) + +# rustc-option +# Usage: rustflags-y += $(call rustc-option,-Cinstrument-coverage,-Zinstrument-coverage) +rustc-option = $(call __rustc-option, $(RUSTC),\ + $(KBUILD_RUSTFLAGS),$(1),$(2)) + +# rustc-option-yn +# Usage: flag := $(call rustc-option-yn,-Cinstrument-coverage) +rustc-option-yn = $(call try-run,\ + $(RUSTC) $(KBUILD_RUSTFLAGS) $(1) --crate-type=rlib /dev/null -o "$$TMP",y,n) From patchwork Mon Aug 12 23:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Maurer X-Patchwork-Id: 13761136 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C01E6198822 for ; Mon, 12 Aug 2024 23:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723505363; cv=none; b=T1Xb0ZRP0dvX4g8BRsSBal1qytE3Od8D8Kl3HReTLkLYDhL8AGxF+EYfdyxeouDO1T8orve1ZcuTxyza1Ft9xOk1QQWEodbd7fBrvLY3LFwxjbhij72fGz4DRninRB1NXKC5EoZSEw7qC+lH2gOHK9+I4gTCOpxT5xq/FdCNvyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723505363; c=relaxed/simple; bh=7F7SE7aoRT7voG2xQs8VDom1T/z2v/0g5da5noTFJXA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TycIU3Jglh8s7gNFJnHTuBSMDBgkKxsIlNxTKqkx3wFjXHnBbX5+D4uaD776Dk0TY8GOvAn/uBnVhgB8uewOG7ZZMjWU6Q79gChJJUnax8xk5Xd4zRGiXfIKJaeqW7gUFK4Y/iP3OaXozTHqqIt5L+YAfOSCYbSHjkNiVLTZK00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dMMgEMHW; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dMMgEMHW" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e05e3938a37so8213782276.2 for ; Mon, 12 Aug 2024 16:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723505360; x=1724110160; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NYZAmb95Zdt4FYIjmbgakWRAyFL76pOHkgozh+PgbQY=; b=dMMgEMHW8++lX3cEYyw98Q+7HJSpNlQm6QTusiHYrSZIJcumHQMYoutrW/V9kncxc7 sSsDTjBMM7ncY34uPUdJJH/2LlJm/FBb3zL81OuIevcvuApgTXF3KYbSM48T6cxnO6yS ofYGsLb7PET0k+2AeqCjoqy7ql9aSgWB4DQsiUMncs/cccYjvAXAtOJN3zRwIrMePknD amkCmrLny22vOV2xyvRN5n4tJk05Cb3z8MFZxMI8IMSq8dj3XZbb+RN68h96HypZuyzp pb4EMmRL2Rbk8L/65qS+Wkz722gL5ysLSRbSCH6A/zQibkITpjxEout5IC9/g3iy43Lp WAkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723505360; x=1724110160; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NYZAmb95Zdt4FYIjmbgakWRAyFL76pOHkgozh+PgbQY=; b=qj70gL2CjA5XTUmZGhcsjIDO12drmg1E2rnejZ5rEza0RVytTL5VddiptL1VmeoVDq RXL8OrzRYMj1Q2U2MnvtQuY4OxHgRPMRmxGbQCairp0p5QonIWKzGErp+vWJVdQa8P6T P4e0NLJ5Lsj5DtKlqc0XpSj2iMNnLDDrCT250D6CP63hR/l9vUYxBo0Slou53T49veML mxFOz82aVJSZ573h48qD0A2a0WnGG8A3zfy9ePxHyS+405UFTzH9p7TaPYvP5hfxKkRw 0/EscYWuzwO80UGq92C94OIEUku14K0A0ldj61UAzfAx+3YBY38x8402IU8J3UKZzVl0 dzhQ== X-Forwarded-Encrypted: i=1; AJvYcCWIEsD4tgyVDQyKlBa1ZaE9MSafGfx4T7kkI8KWdakUtcL9+bt1FhrkFGOjm0L8s3peUIHOImjM6tfCnWs=@vger.kernel.org X-Gm-Message-State: AOJu0YxgBictp/MEeBxasvC8lL57ynrxeKtsY1jveGTmg1HPilU+4C4p GeT7SLiuh0Q21OCasm6v+cGXZza+uIUryUbiiGGE8KUgTvqoCYrhWP2Ad0QPMqfdybNuPy6tbsC bMFldVQ== X-Google-Smtp-Source: AGHT+IE1MApIbnBSlutXKaHC7CEgt9yRvSYQdwzC6dANObTA6whJsq38wsLYhU4NYJw1r2PDYod/5O8g467o X-Received: from anyblade.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:1791]) (user=mmaurer job=sendgmr) by 2002:a05:6902:145:b0:e03:2f90:e81d with SMTP id 3f1490d57ef6-e113d2867a6mr91705276.11.1723505359845; Mon, 12 Aug 2024 16:29:19 -0700 (PDT) Date: Mon, 12 Aug 2024 23:29:02 +0000 In-Reply-To: <20240812232910.2026387-1-mmaurer@google.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240812232910.2026387-1-mmaurer@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240812232910.2026387-3-mmaurer@google.com> Subject: [PATCH v2 2/3] kbuild: rust: Enable KASAN support From: Matthew Maurer To: dvyukov@google.com, ojeda@kernel.org, Masahiro Yamada , Andrey Ryabinin , Alex Gaynor , Wedson Almeida Filho , Nathan Chancellor Cc: aliceryhl@google.com, samitolvanen@google.com, Matthew Maurer , Nicolas Schier , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kbuild@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev Rust supports KASAN via LLVM, but prior to this patch, the flags aren't set properly. Suggested-by: Miguel Ojeda Signed-off-by: Matthew Maurer --- scripts/Makefile.kasan | 51 +++++++++++++++++++++++---------- scripts/Makefile.lib | 3 ++ scripts/generate_rust_target.rs | 1 + 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 390658a2d5b7..bfd37be9cc45 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -12,6 +12,9 @@ endif KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) +rustc-param = $(call rustc-option, -Cllvm-args=-$(1),) + +check-args = $(foreach arg,$(2),$(call $(1),$(arg))) ifdef CONFIG_KASAN_STACK stack_enable := 1 @@ -28,6 +31,7 @@ else endif CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address +RUSTFLAGS_KASAN_MINIMAL := -Zsanitizer=kernel-address -Zsanitizer-recover=kernel-address # -fasan-shadow-offset fails without -fsanitize CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ @@ -35,44 +39,61 @@ CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ $(call cc-option, -fsanitize=kernel-address \ -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) +# The minimum supported `rustc` version has a minimum supported LLVM +# version late enough that we can assume support for -asan-mapping-offset +RUSTFLAGS_KASAN_SHADOW := $(RUSTFLAGS_KASAN_MINIMAL) \ + -Cllvm-args=-asan-mapping-offset=$(KASAN_SHADOW_OFFSET) + +KASAN_PARAMS := + ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) + # We still need to consider this case for Rust because we want Rust code + # to match the behavior of possibly old C compilers when linked together. + ifdef CONFIG_RUST + RUSTFLAGS_KASAN := $(RUSTFLAGS_KASAN_MINIMAL) + endif else - # Now add all the compiler specific options that are valid standalone - CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ - $(call cc-param,asan-globals=1) \ - $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ - $(call cc-param,asan-instrument-allocas=1) + KASAN_PARAMS += asan-globals=1 asan-instrumentation-with-call-threshold=$(call_threshold) asan-instrument-allocas=1 + CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) + ifdef CONFIG_RUST + RUSTFLAGS_KASAN := $(RUSTFLAGS_KASAN_SHADOW) + endif endif -CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable)) +KASAN_PARAMS += asan-stack=$(stack_enable) # Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*() # instead. With compilers that don't support this option, compiler-inserted # memintrinsics won't be checked by KASAN on GENERIC_ENTRY architectures. -CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1) +KASAN_PARAMS += asan-kernel-mem-intrinsic-prefix=1 endif # CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_SW_TAGS ifdef CONFIG_KASAN_INLINE - instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)) + KASAN_PARAMS += hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) else - instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) + KASAN_PARAMS += hwasan-instrument-with-calls=1 endif -CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ - $(call cc-param,hwasan-instrument-stack=$(stack_enable)) \ - $(call cc-param,hwasan-use-short-granules=0) \ - $(call cc-param,hwasan-inline-all-checks=0) \ - $(instrumentation_flags) +KASAN_PARAMS += hwasan-instrument-stack=$(stack_enable) hwasan-use-short-granules=0 hwasan-inline-all-checks=0 $(instrumentation_params) +CFLAGS_KASAN := -fsanitize=kernel-hwaddress # Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) endif +ifdef CONFIG_RUST + RUSTFLAGS_KASAN := -Zsanitizer=kernel-hwaddress -Zsanitizer-recover=kernel-hwaddress +endif + endif # CONFIG_KASAN_SW_TAGS -export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE +# Add all as-supported KASAN LLVM parameters requested by the configuration +CFLAGS_KASAN += $(call check-args, cc-param, $(KASAN_PARAMS)) +RUSTFLAGS_KASAN += $(call check-args, rustc-param, $(KASAN_PARAMS)) + +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE RUSTFLAGS_KASAN diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index fe3668dc4954..27999da3d382 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -167,6 +167,9 @@ ifneq ($(CONFIG_KASAN_HW_TAGS),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) +_rust_flags += $(if $(patsubst n%,, \ + $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \ + $(RUSTFLAGS_KASAN)) endif endif diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 8a0644c0beed..1a4d468c575f 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -187,6 +187,7 @@ fn main() { } ts.push("features", features); ts.push("llvm-target", "x86_64-linux-gnu"); + ts.push("supported-sanitizers", ["kernel-address"]); ts.push("target-pointer-width", "64"); } else if cfg.has("X86_32") { // This only works on UML, as i386 otherwise needs regparm support in rustc