Skip to content

Commit

Permalink
rust: enable Control Flow Guard on gnullvm
Browse files Browse the repository at this point in the history
  • Loading branch information
mati865 committed Oct 28, 2024
1 parent 30d9a95 commit 9ed8862
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
31 changes: 31 additions & 0 deletions mingw-w64-rust/0002-allow-CFGuard-on-windows-gnullvm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 5d434118afbb3d56e358cc4ab45ea4ff2865a3c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= <mati865@gmail.com>
Date: Sun, 27 Oct 2024 19:34:00 +0100
Subject: [PATCH] allow CFGuard on windows-gnullvm

---
compiler/rustc_codegen_llvm/src/context.rs | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs
index 3fc153c6cd4..7634d3c88ad 100644
--- a/compiler/rustc_codegen_llvm/src/context.rs
+++ b/compiler/rustc_codegen_llvm/src/context.rs
@@ -280,8 +280,12 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

- // Control Flow Guard is currently only supported by the MSVC linker on Windows.
- if sess.target.is_like_msvc {
+ // Control Flow Guard is currently only supported by the MSVC and LLVM on Windows.
+ if sess.target.is_like_msvc
+ || (sess.target.options.os == "windows"
+ && sess.target.options.env == "gnu"
+ && sess.target.options.abi == "llvm")
+ {
unsafe {
match sess.opts.cg.control_flow_guard {
CFGuard::Disabled => {}
--
2.43.0

12 changes: 10 additions & 2 deletions mingw-w64-rust/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
$([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-rust-wasm")
"${MINGW_PACKAGE_PREFIX}-rust-src")
pkgver=1.82.0
pkgrel=1
pkgrel=2
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
Expand Down Expand Up @@ -48,6 +48,7 @@ source=("${rust_dist_server}/${_realname}c-${pkgver}-src.tar.gz"{,.asc}
"${embed_manifest_url}"
"config.toml"
"0001-rustc-llvm-fix-libs.patch"
"0002-allow-CFGuard-on-windows-gnullvm.patch"
"0004-compiler-Use-wasm-ld-for-wasm-targets.patch"
"0005-win32-config.patch"
"0008-disable-self-contained-for-gnu-targets.patch"
Expand All @@ -60,8 +61,9 @@ noextract=(${_realname}c-${pkgver}-src.tar.gz)
sha256sums=('7c53f4509eda184e174efa6ba7d5eeb586585686ce8edefc781a2b11a7cf512a'
'SKIP'
'24ef6d949c0b5b1940c1d6a7aad78d86012152fb8845a1644bc939350d7b75e2'
'21ca19cc4247376adf9a5a68ca43fe90baf9774e8c79a06f6df94bf807014613'
'bb0ebc4a8a3dcf06f3cbef0315f1f5ff0d803de944804ce9f912e25adf7dee90'
'7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0'
'23e5b6d546b6d1126e437fca33baee9576d67a74ff77ababb4c71272dba79a82'
'56882f1a0f1404c10c7726d6cc37444f2b343e72b969badfcb43760f80db0f32'
'7d1c4e49524b835a8eadc961b39f5594b12a522a1e24368999be2c7e85399e4e'
'98bc3f2bd7371a5b8d14fd7b03bf05574e206d1d9e52bcfbe66d71398504da3c'
Expand Down Expand Up @@ -112,6 +114,7 @@ prepare() {

if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
apply_patch_with_msg \
0002-allow-CFGuard-on-windows-gnullvm.patch \
0011-disable-uac-for-installer.patch \
0013-generate-import-libraries-on-gnullvm.patch
fi
Expand Down Expand Up @@ -191,6 +194,11 @@ build() {
sed -i '/target = \[/a\ "wasm32-unknown-unknown", "wasm32-wasip1", "wasm32-wasip1-threads", "wasm32-wasip2",' "../${_realname}c-${pkgver}-src/config.toml"
fi

# Enable CFGuard for gnullvm
if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
sed -i "s/^#control-flow-guard/control-flow-guard/g" "../${_realname}c-${pkgver}-src/config.toml"
fi

# Building out of tree is not officially supported so we have to workaround some things like vendored deps
cp -r ../${_realname}c-${pkgver}-src/.cargo .
sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml
Expand Down
4 changes: 2 additions & 2 deletions mingw-w64-rust/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ lld = false
codegen-tests = false
deny-warnings = false
backtrace-on-ice = true
# FIXME: CFG can be enabled only for MSVC targets as for https://github.com/rust-lang/rust/pull/74103
# control-flow-guard = true
# CFG is enabled for gnullvm targets only
#control-flow-guard = true

[dist]
compression-formats = ["gz"]
Expand Down

0 comments on commit 9ed8862

Please sign in to comment.