From owner-svn-src-all@freebsd.org Wed Oct 23 19:03:04 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F3DA615B375; Wed, 23 Oct 2019 19:03:03 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46z0Bb6D67z4Y8N; Wed, 23 Oct 2019 19:03:03 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9ECE01088; Wed, 23 Oct 2019 19:03:03 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9NJ33nt020910; Wed, 23 Oct 2019 19:03:03 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9NJ33dI020909; Wed, 23 Oct 2019 19:03:03 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201910231903.x9NJ33dI020909@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Wed, 23 Oct 2019 19:03:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353959 - head/sys/amd64/include X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/amd64/include X-SVN-Commit-Revision: 353959 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Oct 2019 19:03:04 -0000 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,