From patchwork Tue Sep 1 14:16:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 142639 X-Patchwork-Delegate: carlos@redhat.com 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 C634F4BA23ED for ; Tue, 1 Sep 2026 14:17:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C634F4BA23ED Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CMfHp9OF; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=l2TLU+wx; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bK09dBua; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T1whKXPt X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id A42214BA2E30 for ; Tue, 1 Sep 2026 14:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A42214BA2E30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A42214BA2E30 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788272223; cv=none; b=B2qJ2rxc1kSiNeIzt954LKXl37neg/ce8yLpssZFdHvR83IT3rzHmpr0pWXQjpAYnYa1qsxauSr9Phhqm5QEwmaTo0ersMDnOQQMiygBTEL17hd64jwRFW80xT1g5tEq25ulxDHDO+/o51Ec2rRkdyqv8YBvbGGd7S6MKaK1w1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788272223; c=relaxed/simple; bh=DoVI3dv8PQ7Hhg31ctBKGCuVfn3fivqw1kD2CcrBU/k=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=VZdkEFiPTvOeVA7bB3nf2J/S84d1jjtIHK1vH0Tp9tNRAi/ifdC8BxPqHYclwx44eT43gSWs3P9Loc401L1VaEPwRqHGR9zSd+6gwYrHtXAugvkpPr7eLBmnh7SQEKfou8UZEQ1lfNplsMXiWOQks3ESq/7JNJLg9kNqTdJPpKA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=CMfHp9OF; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=l2TLU+wx; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bK09dBua; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T1whKXPt DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A42214BA2E30 Received: from hawking.suse.de (unknown [10.168.4.11]) by smtp-out1.suse.de (Postfix) with ESMTP id 9547222621 for ; Tue, 1 Sep 2026 14:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788272218; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=KybbQAyb09cgSBN6j8gv4EljabRmMNHM2p5LDn8VqJw=; b=CMfHp9OFuD9bXqINHHWfOv/7cLdTzVMEsyZQHGSFyYc0+un7st8xdfEtSnaV1DAOFtyPhY mABTjqMo6fG43aw/jgA9BS4WTNYUrt+5e/u/4wZ/++HdpxW1vFlgbJPFE0SS6v3R8mcwXi sOQ0ZvK+18nbYbvrp+iDv69CWrmwa74= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788272218; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=KybbQAyb09cgSBN6j8gv4EljabRmMNHM2p5LDn8VqJw=; b=l2TLU+wxL/53FeNVCPQPkFWk7wzY3eR3+kmF6+uuS4DLGU8hvyzm1XkXUPLRdiLBJChYva blDen2R2p3CtmXCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788272214; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=KybbQAyb09cgSBN6j8gv4EljabRmMNHM2p5LDn8VqJw=; b=bK09dBua3KqQo6ckPK1IqOdNfKCcgL4u87+vNLugGVnoLChfVHiW/DYh7UuiZnpo2eg4SU J39dAfH9rMZbwL7ce5wNByWXynwAiys7fMeePIxSUl5l0gAKqyRVQkT/6m8CJ3cOr7FBE0 V19iZqxQI7g+3DJGAWwTQbdFJdHF3sI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788272214; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=KybbQAyb09cgSBN6j8gv4EljabRmMNHM2p5LDn8VqJw=; b=T1whKXPt4a+sUJ/pXx2EpfMizzcMKCggU+E2o5V6f6o0JFJ4ZRqywreB8Xe2ctMnWTJfcN juO30lNfQ7FHCwDw== Received: by hawking.suse.de (Postfix, from userid 17005) id 33F5E4AAD9A; Tue, 1 Sep 2026 16:16:53 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] x86_64: add CFI annotations to swapcontext (bug 34575) Date: Tue, 01 Sep 2026 16:16:53 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Score: -4.20 X-Spam-Level: X-Spamd-Result: default: False [-4.20 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-0.999]; NEURAL_HAM_SHORT(-0.20)[-0.997]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, suse.de:email, hawking.suse.de:helo] X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 The annotations allow the unwinder to always find the return address in one of the contexts. Also mark __start_context as outermost frame, which is used by makecontext as the return address for the context. --- .../unix/sysv/linux/x86_64/__start_context.S | 2 ++ sysdeps/unix/sysv/linux/x86_64/swapcontext.S | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/sysdeps/unix/sysv/linux/x86_64/__start_context.S b/sysdeps/unix/sysv/linux/x86_64/__start_context.S index 2eb5e16d02..5943a84f7c 100644 --- a/sysdeps/unix/sysv/linux/x86_64/__start_context.S +++ b/sysdeps/unix/sysv/linux/x86_64/__start_context.S @@ -75,6 +75,8 @@ END(__push___start_context) ENTRY(__start_context) + /* Mark as outermost frame. */ + cfi_undefined (rip) /* This removes the parameters passed to the function given to 'makecontext' from the stack. RBX contains the address on the stack pointer for the next context. */ diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S index 4c9c08a828..258c75562c 100644 --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S @@ -54,6 +54,14 @@ ENTRY(__swapcontext) movq %rcx, oRIP(%rdi) leaq 8(%rsp), %rcx /* Exclude the return address. */ movq %rcx, oRSP(%rdi) + cfi_def_cfa (%rdi, oRIP) + cfi_offset (%rbx, oRBX-oRIP) + cfi_offset (%rbp, oRBP-oRIP) + cfi_offset (%r12, oR12-oRIP) + cfi_offset (%r13, oR13-oRIP) + cfi_offset (%r14, oR14-oRIP) + cfi_offset (%r15, oR15-oRIP) + cfi_offset (%rip, 0) /* We have separate floating-point register content memory on the stack. We use the __fpregs_mem block in the context. Set the @@ -68,6 +76,7 @@ ENTRY(__swapcontext) /* The syscall destroys some registers, save them. */ movq %rsi, %r12 movq %rdi, %r9 + cfi_def_cfa (%r9, oRIP) /* Save the current signal mask and install the new one with rt_sigprocmask (SIG_BLOCK, newset, oldset,_NSIG/8). */ @@ -84,6 +93,7 @@ ENTRY(__swapcontext) but leaving RDI and RSI available for use later can avoid shuffling values. */ movq %r12, %rdx + cfi_def_cfa (%rdx, oRIP) /* Restore the floating-point context. Not the registers, only the rest. */ @@ -99,6 +109,12 @@ ENTRY(__swapcontext) movq oR13(%rdx), %r13 movq oR14(%rdx), %r14 movq oR15(%rdx), %r15 + cfi_restore (%rbx) + cfi_restore (%rbp) + cfi_restore (%r12) + cfi_restore (%r13) + cfi_restore (%r14) + cfi_restore (%r15) #if SHSTK_ENABLED /* Check if shadow stack is enabled. */ @@ -191,6 +207,7 @@ L(skip_unwind_shadow_stack): /* Get the return address set with getcontext. */ movq oRIP(%rdx), %r10 + cfi_register (%rip, %r10) /* Setup finally %rdx. */ movq oRDX(%rdx), %rdx @@ -210,6 +227,7 @@ L(skip_unwind_shadow_stack): L(jmp): /* Jump to the new context directly. */ jmp *%r10 + cfi_offset (%rip, 0) L(no_shstk): #endif @@ -217,6 +235,8 @@ L(no_shstk): getcontext. Therefore push the address on the stack. */ movq oRIP(%rdx), %rcx pushq %rcx + cfi_def_cfa (%rsp, 8) + cfi_offset (%rip, -8) /* Setup registers used for passing args. */ movq oRDI(%rdx), %rdi