Few more fixes

This commit is contained in:
Théophile Bastian 2018-09-04 17:52:54 +02:00
parent c97ab68a0b
commit 0adff1d484
10 changed files with 129 additions and 15 deletions

View file

@ -226,9 +226,39 @@ $1 = 84
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Compiling DWARF} \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} \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{frame}{Compilation overview}
\begin{itemize} \begin{itemize}
\item Compiled to \alert{C code} \item Compiled to \alert{C code}
@ -301,6 +331,10 @@ $1 = 84
\end{center} \end{center}
\end{frame} \end{frame}
\begin{frame}{Example with outlining}
\lstinputlisting[language=C]{src/fib7/fib7.eh_elf_outline.c}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Benchmarking} \section{Benchmarking}
@ -364,21 +398,6 @@ $1 = 84
\end{itemize} \end{itemize}
\end{frame} \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} \section{Results}
@ -474,6 +493,7 @@ $1 = 84
\end{column} \end{column}
\end{columns} \end{columns}
\vspace{1.5em}
\begin{center} \begin{center}
\Huge\bfseries \Huge\bfseries
Thank you! Thank you!

BIN
slides/src/fib7/fib7.bin Executable file

Binary file not shown.

17
slides/src/fib7/fib7.c Normal file
View file

@ -0,0 +1,17 @@
#include <stdio.h>
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;
}

13
slides/src/fib7/fib7.cfde Normal file
View file

@ -0,0 +1,13 @@
#include <stdio.h> 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
}

View file

@ -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;
}
}

View file

@ -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;
}

5
slides/src/fib7/fib7.fde Normal file
View file

@ -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

View file

@ -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

18
slides/src/fib7/fib7.s Normal file
View file

@ -0,0 +1,18 @@
0000000000000615 <fib7>:
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 <fib7+0x1a> ; END FOR
640: mov 0x1c(%rsp),%esi
644: lea 0xb9(%rip),%rdi
64b: mov $0x0,%eax
650: callq 520 <printf@plt>
655: add $0x28,%rsp ; Restore rsp
659: retq

BIN
slides/src/fib7/fib7.st.bin Executable file

Binary file not shown.