[PATCH v7 2/6] x86/asm: Avoid emitting DWARF CFI for non-VDSO

Jens Remus posted 6 patches 4 days, 18 hours ago
There is a newer version of this series
[PATCH v7 2/6] x86/asm: Avoid emitting DWARF CFI for non-VDSO
Posted by Jens Remus 4 days, 18 hours ago
From: Josh Poimboeuf <jpoimboe@kernel.org>

It was decided years ago that .cfi_* annotations aren't maintainable in
the kernel.  They were replaced by objtool unwind hints.  For the kernel
proper, ensure the CFI_* macros don't do anything.

On the other hand the VDSO library *does* use them, so user space can
unwind through it.

Make sure these macros only work for VDSO.  They aren't actually being
used outside of VDSO anyway, so there's no functional change.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
 arch/x86/include/asm/dwarf2.h | 51 ++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h
index 09c9684d3ad6..7cc30500c095 100644
--- a/arch/x86/include/asm/dwarf2.h
+++ b/arch/x86/include/asm/dwarf2.h
@@ -6,6 +6,15 @@
 #warning "asm/dwarf2.h should be only included in pure assembly files"
 #endif
 
+#ifdef BUILD_VDSO
+
+	/*
+	 * For the vDSO, emit both runtime unwind information and debug
+	 * symbols for the .dbg file.
+	 */
+
+	.cfi_sections .eh_frame, .debug_frame
+
 #define CFI_STARTPROC		.cfi_startproc
 #define CFI_ENDPROC		.cfi_endproc
 #define CFI_DEF_CFA		.cfi_def_cfa
@@ -22,21 +31,31 @@
 #define CFI_ESCAPE		.cfi_escape
 #define CFI_SIGNAL_FRAME	.cfi_signal_frame
 
-#ifndef BUILD_VDSO
-	/*
-	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
-	 * The latter we currently just discard since we don't do DWARF
-	 * unwinding at runtime.  So only the offline DWARF information is
-	 * useful to anyone.  Note we should not use this directive if we
-	 * ever decide to enable DWARF unwinding at runtime.
-	 */
-	.cfi_sections .debug_frame
-#else
-	 /*
-	  * For the vDSO, emit both runtime unwind information and debug
-	  * symbols for the .dbg file.
-	  */
-	.cfi_sections .eh_frame, .debug_frame
-#endif
+#else /* !BUILD_VDSO */
+
+/*
+ * On x86, these macros aren't used outside VDSO.  As well they shouldn't be:
+ * they're fragile and very difficult to maintain.
+ */
+
+.macro nocfi args:vararg
+.endm
+
+#define CFI_STARTPROC		nocfi
+#define CFI_ENDPROC		nocfi
+#define CFI_DEF_CFA		nocfi
+#define CFI_DEF_CFA_REGISTER	nocfi
+#define CFI_DEF_CFA_OFFSET	nocfi
+#define CFI_ADJUST_CFA_OFFSET	nocfi
+#define CFI_OFFSET		nocfi
+#define CFI_REL_OFFSET		nocfi
+#define CFI_REGISTER		nocfi
+#define CFI_RESTORE		nocfi
+#define CFI_REMEMBER_STATE	nocfi
+#define CFI_RESTORE_STATE	nocfi
+#define CFI_UNDEFINED		nocfi
+#define CFI_ESCAPE		nocfi
+
+#endif /* !BUILD_VDSO */
 
 #endif /* _ASM_X86_DWARF2_H */
-- 
2.51.0
Re: [PATCH v7 2/6] x86/asm: Avoid emitting DWARF CFI for non-VDSO
Posted by H. Peter Anvin 4 days, 10 hours ago
On 2026-02-03 09:19, Jens Remus wrote:
> From: Josh Poimboeuf <jpoimboe@kernel.org>
> 
> It was decided years ago that .cfi_* annotations aren't maintainable in
> the kernel.  They were replaced by objtool unwind hints.  For the kernel
> proper, ensure the CFI_* macros don't do anything.
> 
> On the other hand the VDSO library *does* use them, so user space can
> unwind through it.
> 
> Make sure these macros only work for VDSO.  They aren't actually being
> used outside of VDSO anyway, so there's no functional change.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
> ---
>  arch/x86/include/asm/dwarf2.h | 51 ++++++++++++++++++++++++-----------
>  1 file changed, 35 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h
> index 09c9684d3ad6..7cc30500c095 100644
> --- a/arch/x86/include/asm/dwarf2.h
> +++ b/arch/x86/include/asm/dwarf2.h
> @@ -6,6 +6,15 @@
>  #warning "asm/dwarf2.h should be only included in pure assembly files"
>  #endif
>  
> +#ifdef BUILD_VDSO
> +
> +	/*
> +	 * For the vDSO, emit both runtime unwind information and debug
> +	 * symbols for the .dbg file.
> +	 */
> +
> +	.cfi_sections .eh_frame, .debug_frame
> +
>  #define CFI_STARTPROC		.cfi_startproc
>  #define CFI_ENDPROC		.cfi_endproc
>  #define CFI_DEF_CFA		.cfi_def_cfa
> @@ -22,21 +31,31 @@
>  #define CFI_ESCAPE		.cfi_escape
>  #define CFI_SIGNAL_FRAME	.cfi_signal_frame
>  
> -#ifndef BUILD_VDSO
> -	/*
> -	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
> -	 * The latter we currently just discard since we don't do DWARF
> -	 * unwinding at runtime.  So only the offline DWARF information is
> -	 * useful to anyone.  Note we should not use this directive if we
> -	 * ever decide to enable DWARF unwinding at runtime.
> -	 */
> -	.cfi_sections .debug_frame
> -#else
> -	 /*
> -	  * For the vDSO, emit both runtime unwind information and debug
> -	  * symbols for the .dbg file.
> -	  */
> -	.cfi_sections .eh_frame, .debug_frame
> -#endif
> +#else /* !BUILD_VDSO */
> +
> +/*
> + * On x86, these macros aren't used outside VDSO.  As well they shouldn't be:
> + * they're fragile and very difficult to maintain.
> + */
> +
> +.macro nocfi args:vararg
> +.endm
> +
> +#define CFI_STARTPROC		nocfi
> +#define CFI_ENDPROC		nocfi
> +#define CFI_DEF_CFA		nocfi
> +#define CFI_DEF_CFA_REGISTER	nocfi
> +#define CFI_DEF_CFA_OFFSET	nocfi
> +#define CFI_ADJUST_CFA_OFFSET	nocfi
> +#define CFI_OFFSET		nocfi
> +#define CFI_REL_OFFSET		nocfi
> +#define CFI_REGISTER		nocfi
> +#define CFI_RESTORE		nocfi
> +#define CFI_REMEMBER_STATE	nocfi
> +#define CFI_RESTORE_STATE	nocfi
> +#define CFI_UNDEFINED		nocfi
> +#define CFI_ESCAPE		nocfi
> +
> +#endif /* !BUILD_VDSO */
>  
>  #endif /* _ASM_X86_DWARF2_H */

I guess patch 3 justifies this.

Acked-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Re: [PATCH v7 2/6] x86/asm: Avoid emitting DWARF CFI for non-VDSO
Posted by Jens Remus 1 day, 21 hours ago
On 2/4/2026 1:43 AM, H. Peter Anvin wrote:
> On 2026-02-03 09:19, Jens Remus wrote:
>> From: Josh Poimboeuf <jpoimboe@kernel.org>
>>
>> It was decided years ago that .cfi_* annotations aren't maintainable in
>> the kernel.  They were replaced by objtool unwind hints.  For the kernel
>> proper, ensure the CFI_* macros don't do anything.
>>
>> On the other hand the VDSO library *does* use them, so user space can
>> unwind through it.
>>
>> Make sure these macros only work for VDSO.  They aren't actually being
>> used outside of VDSO anyway, so there's no functional change.
>>
>> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
>> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
>> ---
>>  arch/x86/include/asm/dwarf2.h | 51 ++++++++++++++++++++++++-----------
>>  1 file changed, 35 insertions(+), 16 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h
>> index 09c9684d3ad6..7cc30500c095 100644
>> --- a/arch/x86/include/asm/dwarf2.h
>> +++ b/arch/x86/include/asm/dwarf2.h
>> @@ -6,6 +6,15 @@
>>  #warning "asm/dwarf2.h should be only included in pure assembly files"
>>  #endif
>>  
>> +#ifdef BUILD_VDSO
>> +
>> +	/*
>> +	 * For the vDSO, emit both runtime unwind information and debug
>> +	 * symbols for the .dbg file.
>> +	 */
>> +
>> +	.cfi_sections .eh_frame, .debug_frame
>> +
>>  #define CFI_STARTPROC		.cfi_startproc
>>  #define CFI_ENDPROC		.cfi_endproc
>>  #define CFI_DEF_CFA		.cfi_def_cfa
>> @@ -22,21 +31,31 @@
>>  #define CFI_ESCAPE		.cfi_escape
>>  #define CFI_SIGNAL_FRAME	.cfi_signal_frame

I missed that this is new on tip:x86/entry and thus also needs to be
added below in the !BUILD_VDSO case.

>>  
>> -#ifndef BUILD_VDSO
>> -	/*
>> -	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
>> -	 * The latter we currently just discard since we don't do DWARF
>> -	 * unwinding at runtime.  So only the offline DWARF information is
>> -	 * useful to anyone.  Note we should not use this directive if we
>> -	 * ever decide to enable DWARF unwinding at runtime.
>> -	 */
>> -	.cfi_sections .debug_frame
>> -#else
>> -	 /*
>> -	  * For the vDSO, emit both runtime unwind information and debug
>> -	  * symbols for the .dbg file.
>> -	  */
>> -	.cfi_sections .eh_frame, .debug_frame
>> -#endif
>> +#else /* !BUILD_VDSO */
>> +
>> +/*
>> + * On x86, these macros aren't used outside VDSO.  As well they shouldn't be:
>> + * they're fragile and very difficult to maintain.
>> + */
>> +
>> +.macro nocfi args:vararg
>> +.endm
>> +
>> +#define CFI_STARTPROC		nocfi
>> +#define CFI_ENDPROC		nocfi
>> +#define CFI_DEF_CFA		nocfi
>> +#define CFI_DEF_CFA_REGISTER	nocfi
>> +#define CFI_DEF_CFA_OFFSET	nocfi
>> +#define CFI_ADJUST_CFA_OFFSET	nocfi
>> +#define CFI_OFFSET		nocfi
>> +#define CFI_REL_OFFSET		nocfi
>> +#define CFI_REGISTER		nocfi
>> +#define CFI_RESTORE		nocfi
>> +#define CFI_REMEMBER_STATE	nocfi
>> +#define CFI_RESTORE_STATE	nocfi
>> +#define CFI_UNDEFINED		nocfi
>> +#define CFI_ESCAPE		nocfi

#define CFI_SIGNAL_FRAME		nocfi

>> +
>> +#endif /* !BUILD_VDSO */
>>  
>>  #endif /* _ASM_X86_DWARF2_H */
> 
> I guess patch 3 justifies this.
> 
> Acked-by: H. Peter Anvin (Intel) <hpa@zytor.com>
> 

Regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/

Re: [PATCH v7 2/6] x86/asm: Avoid emitting DWARF CFI for non-VDSO
Posted by H. Peter Anvin 4 days, 17 hours ago
On February 3, 2026 9:19:53 AM PST, Jens Remus <jremus@linux.ibm.com> wrote:
>From: Josh Poimboeuf <jpoimboe@kernel.org>
>
>It was decided years ago that .cfi_* annotations aren't maintainable in
>the kernel.  They were replaced by objtool unwind hints.  For the kernel
>proper, ensure the CFI_* macros don't do anything.
>
>On the other hand the VDSO library *does* use them, so user space can
>unwind through it.
>
>Make sure these macros only work for VDSO.  They aren't actually being
>used outside of VDSO anyway, so there's no functional change.
>
>Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
>Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>Signed-off-by: Jens Remus <jremus@linux.ibm.com>
>---
> arch/x86/include/asm/dwarf2.h | 51 ++++++++++++++++++++++++-----------
> 1 file changed, 35 insertions(+), 16 deletions(-)
>
>diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h
>index 09c9684d3ad6..7cc30500c095 100644
>--- a/arch/x86/include/asm/dwarf2.h
>+++ b/arch/x86/include/asm/dwarf2.h
>@@ -6,6 +6,15 @@
> #warning "asm/dwarf2.h should be only included in pure assembly files"
> #endif
> 
>+#ifdef BUILD_VDSO
>+
>+	/*
>+	 * For the vDSO, emit both runtime unwind information and debug
>+	 * symbols for the .dbg file.
>+	 */
>+
>+	.cfi_sections .eh_frame, .debug_frame
>+
> #define CFI_STARTPROC		.cfi_startproc
> #define CFI_ENDPROC		.cfi_endproc
> #define CFI_DEF_CFA		.cfi_def_cfa
>@@ -22,21 +31,31 @@
> #define CFI_ESCAPE		.cfi_escape
> #define CFI_SIGNAL_FRAME	.cfi_signal_frame
> 
>-#ifndef BUILD_VDSO
>-	/*
>-	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
>-	 * The latter we currently just discard since we don't do DWARF
>-	 * unwinding at runtime.  So only the offline DWARF information is
>-	 * useful to anyone.  Note we should not use this directive if we
>-	 * ever decide to enable DWARF unwinding at runtime.
>-	 */
>-	.cfi_sections .debug_frame
>-#else
>-	 /*
>-	  * For the vDSO, emit both runtime unwind information and debug
>-	  * symbols for the .dbg file.
>-	  */
>-	.cfi_sections .eh_frame, .debug_frame
>-#endif
>+#else /* !BUILD_VDSO */
>+
>+/*
>+ * On x86, these macros aren't used outside VDSO.  As well they shouldn't be:
>+ * they're fragile and very difficult to maintain.
>+ */
>+
>+.macro nocfi args:vararg
>+.endm
>+
>+#define CFI_STARTPROC		nocfi
>+#define CFI_ENDPROC		nocfi
>+#define CFI_DEF_CFA		nocfi
>+#define CFI_DEF_CFA_REGISTER	nocfi
>+#define CFI_DEF_CFA_OFFSET	nocfi
>+#define CFI_ADJUST_CFA_OFFSET	nocfi
>+#define CFI_OFFSET		nocfi
>+#define CFI_REL_OFFSET		nocfi
>+#define CFI_REGISTER		nocfi
>+#define CFI_RESTORE		nocfi
>+#define CFI_REMEMBER_STATE	nocfi
>+#define CFI_RESTORE_STATE	nocfi
>+#define CFI_UNDEFINED		nocfi
>+#define CFI_ESCAPE		nocfi
>+
>+#endif /* !BUILD_VDSO */
> 
> #endif /* _ASM_X86_DWARF2_H */

Maybe we should move these into x86/entry/vdso/common instead?