Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Oct 2019 19:03:03 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353959 - head/sys/amd64/include
Message-ID:  <201910231903.x9NJ33dI020909@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed Oct 23 19:03:03 2019
New Revision: 353959
URL: https://svnweb.freebsd.org/changeset/base/353959

Log:
  amd64: Add CFI directives for libc syscall stubs
  
  No functional change (in program code).  Additional DWARF metadata is
  generated in the .eh_frame section.  Also, it is now a compile-time
  requirement that machine/asm.h ENTRY() and END() macros are paired.  (This
  is subject to ongoing discussion and may change.)
  
  This DWARF metadata allows llvm-libunwind to unwind program stacks when the
  program is executing the function.  The goal is to collect accurate
  userspace stacktraces when programs have entered syscalls.
  
  (The motivation for "Call Frame Information," or CFI for short -- not to be
  confused with Control Flow Integrity -- is to sufficiently annotate assembly
  functions such that stack unwinders can unwind out of the local frame
  without the requirement of a dedicated framepointer register; i.e.,
  -fomit-frame-pointer.  This is necessary for C++ exception handling or
  collecting backtraces.)
  
  For the curious, a more thorough description of the metadata and some
  examples may be found at [1] and documentation at [2].  You can also look at
  'cc -S -o - foo.c | less' and search for '.cfi_' to see the CFI directives
  generated by your C compiler.
  
  [1]: https://www.imperialviolet.org/2017/01/18/cfi.html
  [2]: https://sourceware.org/binutils/docs/as/CFI-directives.html
  
  Reviewed by:	emaste, kib (with reservations)
  Differential Revision:	https://reviews.freebsd.org/D22122

Modified:
  head/sys/amd64/include/asm.h

Modified: head/sys/amd64/include/asm.h
==============================================================================
--- head/sys/amd64/include/asm.h	Wed Oct 23 18:27:30 2019	(r353958)
+++ head/sys/amd64/include/asm.h	Wed Oct 23 19:03:03 2019	(r353959)
@@ -60,25 +60,36 @@
 #define _START_ENTRY	.text; .p2align 4,0x90
 
 #define _ENTRY(x)	_START_ENTRY; \
-			.globl CNAME(x); .type CNAME(x),@function; CNAME(x):
+			.globl CNAME(x); .type CNAME(x),@function; CNAME(x):; \
+			.cfi_startproc
 
 #ifdef PROF
 #define	ALTENTRY(x)	_ENTRY(x); \
-			pushq %rbp; movq %rsp,%rbp; \
+			pushq %rbp; \
+			.cfi_def_cfa_offset 16; \
+			.cfi_offset %rbp, -16; \
+			movq %rsp,%rbp; \
 			call PIC_PLT(HIDENAME(mcount)); \
 			popq %rbp; \
+			.cfi_restore %rbp; \
+			.cfi_def_cfa_offset 8; \
 			jmp 9f
 #define	ENTRY(x)	_ENTRY(x); \
-			pushq %rbp; movq %rsp,%rbp; \
+			pushq %rbp; \
+			.cfi_def_cfa_offset 16; \
+			.cfi_offset %rbp, -16; \
+			movq %rsp,%rbp; \
 			call PIC_PLT(HIDENAME(mcount)); \
 			popq %rbp; \
+			.cfi_restore %rbp; \
+			.cfi_def_cfa_offset 8; \
 			9:
 #else
 #define	ALTENTRY(x)	_ENTRY(x)
 #define	ENTRY(x)	_ENTRY(x)
 #endif
 
-#define	END(x)		.size x, . - x
+#define	END(x)		.size x, . - x; .cfi_endproc
 /*
  * WEAK_REFERENCE(): create a weak reference alias from sym. 
  * The macro is not a general asm macro that takes arbitrary names,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910231903.x9NJ33dI020909>