diff --git a/slides/slides.tex b/slides/slides.tex index 260675e..4240dcc 100644 --- a/slides/slides.tex +++ b/slides/slides.tex @@ -226,9 +226,39 @@ $1 = 84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Compiling DWARF} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{Example} + +\begin{frame}{Compilation example: original C, DWARF} + \lstinputlisting[language=C]{src/fib7/fib7.cfde} +\end{frame} + +\begin{frame}[shrink]{Compilation example: generated C} + \lstinputlisting[language=C]{src/fib7/fib7.eh_elf_basic.c} +\end{frame} + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{Compilation Strategy} +\begin{frame}{Interface: libunwind} + \begin{itemize} + \item \alert{libunwind}: \textit{de facto} standard library for + unwinding + \item Uses DWARF in background + + \item \texttt{libunwind-eh\_elf}: alternative implementation using + \ehelfs{} + + \item{} Result: \alert{alternative implementation} of libunwind, nearly + plug-and-play for existing projects! + \begin{itemize} + \item[$\leadsto$] It is \alert{easy} to use \ehelfs{}: just + link against the right library! + \end{itemize} + \end{itemize} +\end{frame} + \begin{frame}{Compilation overview} \begin{itemize} \item Compiled to \alert{C code} @@ -301,6 +331,10 @@ $1 = 84 \end{center} \end{frame} +\begin{frame}{Example with outlining} + \lstinputlisting[language=C]{src/fib7/fib7.eh_elf_outline.c} +\end{frame} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Benchmarking} @@ -364,21 +398,6 @@ $1 = 84 \end{itemize} \end{frame} -\subsection{Libunwind} -\begin{frame}{libunwind implementation} - \begin{itemize} - \item \alert{libunwind}: \textit{de facto} standard library for - unwinding - \item Uses DWARF in background - \item \alert{Used by perf} as a backend for unwinding - - \pause{}\vspace{1em} \item{} Easiest way to use \ehelfs{} in perf: - \alert{implement an alternative libunwind} - \item{} Result: \alert{alternative implementation} of libunwind, nearly - plug-and-play! - \end{itemize} -\end{frame} - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Results} @@ -474,6 +493,7 @@ $1 = 84 \end{column} \end{columns} + \vspace{1.5em} \begin{center} \Huge\bfseries Thank you! diff --git a/slides/src/fib7/fib7.bin b/slides/src/fib7/fib7.bin new file mode 100755 index 0000000..0d9e2f3 Binary files /dev/null and b/slides/src/fib7/fib7.bin differ diff --git a/slides/src/fib7/fib7.c b/slides/src/fib7/fib7.c new file mode 100644 index 0000000..d4b3264 --- /dev/null +++ b/slides/src/fib7/fib7.c @@ -0,0 +1,17 @@ +#include + +void fib7() { + int fibo[8]; + fibo[0] = 1; + fibo[1] = 1; + for(int pos = 2; pos < 8; ++pos) + fibo[pos] = + fibo[pos - 1] + + fibo[pos - 2]; + printf("%d\n", fibo[7]); +} + +int main(void) { + fib7(); + return 0; +} diff --git a/slides/src/fib7/fib7.cfde b/slides/src/fib7/fib7.cfde new file mode 100644 index 0000000..e199a3f --- /dev/null +++ b/slides/src/fib7/fib7.cfde @@ -0,0 +1,13 @@ +#include DWARF + CFA ra +void fib7() { rsp+8 c-8 + int fibo[8]; rsp+48 c-8 + fibo[0] = 1; + fibo[1] = 1; + for(int pos = 2; pos < 8; ++pos) + fibo[pos] = + fibo[pos - 1] + + fibo[pos - 2]; + printf("%d\n", fibo[7]); + rsp+8 c-8 +} diff --git a/slides/src/fib7/fib7.eh_elf_basic.c b/slides/src/fib7/fib7.eh_elf_basic.c new file mode 100644 index 0000000..4c7dcc2 --- /dev/null +++ b/slides/src/fib7/fib7.eh_elf_basic.c @@ -0,0 +1,18 @@ +unwind_context_t _eh_elf( + unwind_context_t ctx, uintptr_t pc) +{ + unwind_context_t out_ctx; + switch(pc) { + // [...] Previous FDEs redacted + case 0x615 ... 0x618: + out_ctx.rsp = ctx.rsp + (8); + out_ctx.rip = + *((uintptr_t*)(out_ctx.rsp + (-8))); + out_ctx.flags = 3u; + return out_ctx; + // [...] Further lines and FDEs redacted + default: + out_ctx.flags = 128u; + return out_ctx; + } +} diff --git a/slides/src/fib7/fib7.eh_elf_outline.c b/slides/src/fib7/fib7.eh_elf_outline.c new file mode 100644 index 0000000..9d24bc0 --- /dev/null +++ b/slides/src/fib7/fib7.eh_elf_outline.c @@ -0,0 +1,16 @@ +unwind_context_t _eh_elf( + unwind_context_t ctx, uintptr_t pc) +{ + unwind_context_t out_ctx; + if(pc < 0x619) { /* [...] */ } else { + if(pc < 0x659) { // IP=0x619 ... 0x658 + goto _factor_4; + } // [...] + } + + _factor_4: + out_ctx.rsp = ctx.rsp + (48); + out_ctx.rip = *((uintptr_t*)(out_ctx.rsp + (-8))); + out_ctx.flags = 3u; + return out_ctx; +} diff --git a/slides/src/fib7/fib7.fde b/slides/src/fib7/fib7.fde new file mode 100644 index 0000000..1b6c08a --- /dev/null +++ b/slides/src/fib7/fib7.fde @@ -0,0 +1,5 @@ +[...] FDE [...] pc=615..65a + LOC CFA ra +0000000000000615 rsp+8 c-8 +0000000000000619 rsp+48 c-8 +0000000000000659 rsp+8 c-8 diff --git a/slides/src/fib7/fib7.raw_fde b/slides/src/fib7/fib7.raw_fde new file mode 100644 index 0000000..a90cfb4 --- /dev/null +++ b/slides/src/fib7/fib7.raw_fde @@ -0,0 +1,7 @@ +[...] FDE [...] pc=615..65a + DW_CFA_def_cfa: r7 (rsp) ofs 8 + DW_CFA_offset: r16 (rip) at cfa-8 + DW_CFA_advance_loc: 4 to 0619 + DW_CFA_def_cfa_offset: 48 + DW_CFA_advance_loc1: 64 to 0659 + DW_CFA_def_cfa_offset: 8 diff --git a/slides/src/fib7/fib7.s b/slides/src/fib7/fib7.s new file mode 100644 index 0000000..8450ed0 --- /dev/null +++ b/slides/src/fib7/fib7.s @@ -0,0 +1,18 @@ +0000000000000615 : + 615: sub $0x28,%rsp ; Alloc stack + 619: movl $0x1,(%rsp) ; fibo[0] + 620: movl $0x1,0x4(%rsp) ; fibo[1] + 628: mov %rsp,%rax ; BEGIN FOR + 62b: lea 0x18(%rax),%rcx + 62f: mov (%rax),%edx + 631: add 0x4(%rax),%edx + 634: mov %edx,0x8(%rax) + 637: add $0x4,%rax + 63b: cmp %rcx,%rax + 63e: jne 62f ; END FOR + 640: mov 0x1c(%rsp),%esi + 644: lea 0xb9(%rip),%rdi + 64b: mov $0x0,%eax + 650: callq 520 + 655: add $0x28,%rsp ; Restore rsp + 659: retq diff --git a/slides/src/fib7/fib7.st.bin b/slides/src/fib7/fib7.st.bin new file mode 100755 index 0000000..0d9e2f3 Binary files /dev/null and b/slides/src/fib7/fib7.st.bin differ