diff options
author | Conrad Meyer <cem@FreeBSD.org> | 2019-10-23 19:03:03 +0000 |
---|---|---|
committer | Conrad Meyer <cem@FreeBSD.org> | 2019-10-23 19:03:03 +0000 |
commit | 639ec13157130419cbdd630d0d5a29da92b9fe09 (patch) | |
tree | 32b873250a9a26463cd6bc309fff16882358fd17 | |
parent | 5ffc069a3aba3adc630fe8eedbf6c9ee14249c47 (diff) | |
download | src-639ec13157130419cbdd630d0d5a29da92b9fe09.tar.gz src-639ec13157130419cbdd630d0d5a29da92b9fe09.zip |
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
Notes
Notes:
svn path=/head/; revision=353959
-rw-r--r-- | sys/amd64/include/asm.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sys/amd64/include/asm.h b/sys/amd64/include/asm.h index bebc4df3d2c5..7b66e9446ff3 100644 --- a/sys/amd64/include/asm.h +++ b/sys/amd64/include/asm.h @@ -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, |