From patchwork Sun Jun 28 07:02:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Huang X-Patchwork-Id: 137958 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 896C34BA23C4 for ; Sun, 28 Jun 2026 07:03:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 896C34BA23C4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=FA4NWDWf X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1236.google.com (mail-dl1-x1236.google.com [IPv6:2607:f8b0:4864:20::1236]) by sourceware.org (Postfix) with ESMTPS id 7F6484BA2E26 for ; Sun, 28 Jun 2026 07:02:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F6484BA2E26 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7F6484BA2E26 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1236 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782630170; cv=none; b=sNthirscTQZMmvJahPMXdvR50fVSLnUBzG15P3ceOskXQZY8lnwGhqHPbnWAeL12d4xqjxf9rEzQQpJzvxZmiP3By3Ets6wKnfNHi1S7npvXs4Ifk49TzVgjKpleWuqJlFxscrjYx8WlFqNIycI3RErNEATT6YgoSZU0Sj7mUkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782630170; c=relaxed/simple; bh=mQjNISz21ZHU3vo1ZpRIAySIBnrbX7rlFbruqSBOrIc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wAM7U43xhG94ORls+zubE+mJtS4PICv/S7c/6YTkQHOByiMcC7OWz6jQkXb4+TU/x1fr7mvrYduX02hQzz3VM+813khakSsaiJtCk2adsTUcbLTSi+6BQNDc3I5/46zCMub3YfSPLkvQ9VHb1gfWTWtLgnj2DmHasqwfZTGMsqo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=FA4NWDWf DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F6484BA2E26 Received: by mail-dl1-x1236.google.com with SMTP id a92af1059eb24-139f1dfc9faso1078073c88.0 for ; Sun, 28 Jun 2026 00:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1782630169; x=1783234969; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OSMQLIZvV36wQLDD4O0Jrz41/CcC2Q52Lcg9WoMbrJA=; b=FA4NWDWfPJ1QKyUAMNtgWciDXwWZbkofAMBcgYQMKJ6U+ygYrkajWojjQH2g7+fjRs RRm5uPxhR3aAK0B/tGe9Tyr7QRydYyK82H53vrx7jVWDa7puu0J/6S/rzYdUpxgre30F Y3pSfeZPPxP/XW67b2qRTCG+q6cPdvbvcuU6w5WwHRYu2JqjRkTrhiePh3GamtE/DvL4 vYlYr2/l1YUQGSbb9IZdVZLzDqxOI2DGeDD3EeZcXP6/ixb5iyeNjgMHMFqFrc789iNH khbL95YjsPLQ4SVh4QINlz00Ncv1lmsZEoRvLGFoqJQEN558U+8VGsVGuUBTuTriJUA/ +ubw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782630169; x=1783234969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OSMQLIZvV36wQLDD4O0Jrz41/CcC2Q52Lcg9WoMbrJA=; b=iARlP3tbAhDn0ZFc2UFws8tQ3xrLYR7ZQPv5AfqbL9xjM+NeMd8ZBjrP1/MtjrC5P0 dB1a9j5KYWLfs2TF80Gcuo0gcEZWgzd0GhsMKb+8OTI14T4N3cwx4P3P6kZp/hTXQWoM aUeUu7+JvuhWlrRhGP3huJO9TjOezF5EVx9NHqgseYPfR/Xk+A114NQfDga2RjEa2e61 NZVI/cVB+KvmTv34zOS1CyXjPSeEDKpBJui6iF0waN0/+FyxRLoEJsMe0PiBkFWRr2SU 8pjdGisvJzNnCDLONufET1lOL88NHq8O0rk6CMh5Jm4M1+V+oisygwM6a7aL9J/FAipe LwgQ== X-Gm-Message-State: AOJu0YxXH8DPFuEOWCXrL6sa1IXEr7gp4EX7JIYnEybtwEun6m1HP3JO LbOhmDIREOXaqorcHnCsXmMDmZjVpaKSVoMPZoZ5rJ7A2iceNfU1H9e4fIc7CZHpUPlrRvPs5na YGKidu+w2zsC5yQb3ZOim0d1ibxXbPx7ZBgXwv5EiWJBtbMXmgQhpl0VGtM0rTyO6AY9cfNV/r9 OnYueIrE+csl7KFU06P63WEAVQx3rpunGTFEB1AEN5kiUDnHwb X-Gm-Gg: AfdE7ckoUL0Z4PBMtUws+vBabt1v4jVZDkKYlTaJx49a+P5G7iuGEqALCwmDcde0tKw XBn5lqUv/GSRKq8cMraquUd1pzK1uFdCq989l2fHGKaaJ6RW9kVvoZ1Eolq6eWG+Qr/a2kVlFVg xkU4YSb66V9bv4lg/78G8TrQjogZ3iiAEQzSCyvF8hr3/Uy8Mq+42rYQ0Hl9krd5l2R4j0jfknX S/QpuOWJXWs1DnZkiHPZShRXD17NSDgKP4Fd6mk7aTLvbY1+fQXxkGFdPXftaKSt+zalhFgk3WD 7p5BTddC46Qfp3E+oL0GR5q2WdupNC5YyCYpiuKiYi+u7+knpJmQw8ut1Ryd+3aiJAAfo/yiwjv 0B0NdDXk0c6EfvvAmN1OkToM+CryXEHN6DAs4bCJ6kwhrM6rO+rHf1XOoX2qlmkKNnnEA3vb0Bd 9iOrGOUThK5u7vVvgAO8xZJdVxR2ScEg== X-Received: by 2002:a05:7022:322:b0:139:ed5d:5ca4 with SMTP id a92af1059eb24-139ed5d5d69mr5187664c88.45.1782630169141; Sun, 28 Jun 2026 00:02:49 -0700 (PDT) Received: from sw08.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c8afc91sm35435166eec.14.2026.06.28.00.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2026 00:02:48 -0700 (PDT) From: Jesse Huang To: libc-alpha@sourceware.org Cc: andrew@sifive.com, darius@bluespec.com, debug@rivosinc.com, jeffreyalaw@gmail.com, kito.cheng@sifive.com, palmer@dabbelt.com, schwab@suse.de, Jesse Huang Subject: [PATCH v5 01/16] riscv: Add --enable-cfi option for controlling CFI features Date: Sun, 28 Jun 2026 00:02:26 -0700 Message-Id: <20260628070241.88310-2-jesse.huang@sifive.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20260628070241.88310-1-jesse.huang@sifive.com> References: <20260628070241.88310-1-jesse.huang@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org --- INSTALL | 13 +++++++++++++ NEWS | 3 +++ configure | 12 ++++++++++++ configure.ac | 6 ++++++ manual/install.texi | 12 ++++++++++++ 5 files changed, 46 insertions(+) diff --git a/INSTALL b/INSTALL index cd4b6e5c2f..bb4e37ec6a 100644 --- a/INSTALL +++ b/INSTALL @@ -154,6 +154,19 @@ passed to 'configure'. For example: NOTE: '--enable-cet' is only supported on x86_64 and x32. +'--enable-cfi' + Enable RISC-V Control Flow Integrity Extensions (Zicfilp/Zicfiss) + support. When the GNU C Library is built with '--enable-cfi', the + resulting library is protected with landing pad and shadow stack. + This feature is currently supported on RV64 with GCC 15 and + binutils 2.45 or later. With '--enable-cfi', it is an error to + dlopen a non CFI enabled shared library in CFI enabled application. + The restriction can be loosened by setting to permissive mode with + the use of the glibc tunables, see glibc tunables section for more + information. + + NOTE: '--enable-cfi' is only supported on RV64. + '--disable-profile' Don't build libraries with profiling information. You may want to use this option if you don't plan to do profiling. diff --git a/NEWS b/NEWS index f9d90c5194..1bf3c220c5 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ Version 2.44 Major new features: +* Added --enable-cfi option to enable the RISC-V CFI extensions + (Zicfilp/Zicfiss) support on RV64 Linux. + * A new tunable, glibc.elf.thp, is added to map read-only segments with Transparent Huge Pages (THP) if THP isn't disable in kernel. When glibc.elf.thp is set to 1, malloc uses the actual kernel THP mode diff --git a/configure b/configure index 604279533a..892c4f066e 100755 --- a/configure +++ b/configure @@ -814,6 +814,7 @@ enable_nscd enable_pt_chown enable_mathvec enable_cet +enable_cfi enable_scv enable_fortify_source enable_sframe @@ -1493,6 +1494,7 @@ Optional Features: depends on architecture] --enable-cet enable Intel Control-flow Enforcement Technology (CET), x86 only + --enable-cfi enable Control Flow Integrity (CFI), RISC-V only --disable-scv syscalls will not use scv instruction, even if the kernel supports it, powerpc only --enable-fortify-source[=1|2|3] @@ -4813,6 +4815,16 @@ esac fi +# Check whether --enable-cfi was given. +if test ${enable_cfi+y} +then : + enableval=$enable_cfi; enable_cfi=$enableval +else case e in #( + e) enable_cfi=no ;; +esac +fi + + # Check whether --enable-scv was given. if test ${enable_scv+y} then : diff --git a/configure.ac b/configure.ac index 2fe7980fc9..bc57ce938b 100644 --- a/configure.ac +++ b/configure.ac @@ -393,6 +393,12 @@ AC_ARG_ENABLE([cet], [enable_cet=$enableval], [enable_cet=$libc_cv_compiler_default_cet]) +AC_ARG_ENABLE([cfi], + AS_HELP_STRING([--enable-cfi], + [enable Control Flow Integrity (CFI), RISC-V only]), + [enable_cfi=$enableval], + [enable_cfi=no]) + AC_ARG_ENABLE([scv], AS_HELP_STRING([--disable-scv], [syscalls will not use scv instruction, even if the kernel supports it, powerpc only]), diff --git a/manual/install.texi b/manual/install.texi index 48604a31df..daab54a3b7 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -185,6 +185,18 @@ non CET enabled shared library in CET enabled application. NOTE: @option{--enable-cet} is only supported on x86_64 and x32. +@item --enable-cfi +Enable RISC-V Control Flow Integrity Extensions (Zicfilp/Zicfiss) support. +When @theglibc{} is built with @option{--enable-cfi}, the resulting +library is protected with landing pad and shadow stack@. +This feature is currently supported on RV64 with GCC 15 and binutils 2.45 +or later. With @option{--enable-cfi}, it is an error to dlopen a non CFI +enabled shared library in CFI enabled application. The restriction can be +loosened by setting to permissive mode with the use of the glibc tunables, +see glibc tunables section for more information. + +NOTE: @option{--enable-cfi} is only supported on RV64. + @item --disable-profile Don't build libraries with profiling information. You may want to use this option if you don't plan to do profiling.