diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5cd5be0 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + latexmk -xelatex -pdf slides.tex + +clean: + rm -f *aux *bbl *bcf *blg *_latexmk *fls *log *out *.run.xml diff --git a/img/call_stack.png b/img/call_stack.png new file mode 100644 index 0000000..391387f Binary files /dev/null and b/img/call_stack.png differ diff --git a/img/dw_spec.png b/img/dw_spec.png new file mode 100644 index 0000000..ad23073 Binary files /dev/null and b/img/dw_spec.png differ diff --git a/img/dwarf_logo.gif b/img/dwarf_logo.gif new file mode 100644 index 0000000..0cd4d5d Binary files /dev/null and b/img/dwarf_logo.gif differ diff --git a/img/dwarf_logo.png b/img/dwarf_logo.png new file mode 100644 index 0000000..88e10fd Binary files /dev/null and b/img/dwarf_logo.png differ diff --git a/img/keep_breathing.jpg b/img/keep_breathing.jpg new file mode 100644 index 0000000..bf7382e Binary files /dev/null and b/img/keep_breathing.jpg differ diff --git a/slides.tex b/slides.tex new file mode 100644 index 0000000..d7dc6d6 --- /dev/null +++ b/slides.tex @@ -0,0 +1,524 @@ +% vim: spell spelllang=en + +\documentclass[11pt,xcolor={usenames,dvipsnames}]{beamer} +\usetheme{Warsaw} +\usepackage[utf8]{inputenc} +\usepackage[english]{babel} +\usepackage[T1]{fontenc} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{booktabs} +\usepackage{makecell} +\usepackage{ifthen} +\usepackage{colortbl} + +\usepackage{texlib/my_listings} +%\usepackage{texlib/my_hyperref} +\usepackage{texlib/specific} +\usepackage{texlib/common} +\usepackage{texlib/todo} + +\usepackage{inconsolata} +\lstset{basicstyle=\footnotesize\ttfamily} + +\renewcommand\theadalign{c} +\renewcommand\theadfont{\scriptsize\bfseries} + +\setbeamertemplate{navigation symbols}{} +\setbeamertemplate{headline}{} + +\newcommand{\thenalert}[1]{\only<1>{#1}\only<2>{\alert{#1}}} +\newcommand{\slidecountline}{ + \ifthenelse{\theframenumber = 0} + {} + {\insertframenumber/\inserttotalframenumber}} +\newcommand{\sectionline}{ + \ifthenelse{\thesection = 0} + {} + {\Roman{section}~-- \insertsection}} + +\AtBeginSection[]{ + \begin{frame} + \vfill + \centering + \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title} + \usebeamerfont{title}\insertsectionhead\par% + \end{beamercolorbox} + \vfill + \end{frame} +} + +\lstdefinelanguage{gdb}{ + morekeywords={gdb}, + sensitive=false, +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\author[\slidecountline]{Théophile \textsc{Bastian} \\ + \footnotesize{under the supervision of Francesco Zappa Nardelli}} +\title[\sectionline] + {Speeding up stack unwinding by compiling DWARF debug data} +\date{March\ --\ August 2018} +%\subject{} +%\logo{} +\institute{Team PARKAS, INRIA, Paris} + +\begin{document} + +\begin{frame} + \addtocounter{framenumber}{-1} + \titlepage{} + + \vspace{-2em} + \begin{center} + \begin{align*} + \text{Slides: } &\text{\url{https://tobast.fr/m2/slides.pdf}} \\ + \text{Report: } &\text{\url{https://tobast.fr/m2/report.pdf}} + \end{align*} + \end{center} +\end{frame} + +\begin{frame}{~} + \addtocounter{framenumber}{-1} + \tableofcontents[hideallsubsections] +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Stack unwinding data} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{Introduction} + +\begin{frame}[fragile]{We often use stack unwinding!} + \begin{columns}[c] + \begin{column}{0.70\textwidth} + \begin{lstlisting}[language=gdb, numbers=none, escapechar=|] +Program received signal SIGSEGV. +0x54625 in fct_b at segfault.c:5 +5 printf("%l\n", *b); + +|\pause| (gdb) backtrace +#0 0x54625 in fct_b at segfault.c:5 +#1 0x54663 in fct_a at segfault.c:10 +#2 0x54674 in main at segfault.c:14 + +|\pause| (gdb) frame 1 +#1 0x54663 in fct_a at segfault.c:10 +10 fct_b((int*) a); + +|\pause| (gdb) print a +$1 = 84 + \end{lstlisting} + \vspace{-1em} + \pause{} + \begin{center} + \textbf{\Large How does it work?!} + \end{center} + \end{column} + \begin{column}{0.35\textwidth} + \pause{} + \includegraphics[width=0.95\linewidth]{img/call_stack} + \end{column} + \end{columns} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{Stack frames and unwinding} + +\begin{frame}{Call stack and registers} + \begin{columns}[c] + \begin{column}{0.55\textwidth} + \begin{center} + \large\bf + How do we get the grandparent RA\@? + + \medskip + + Isn't it as trivial as \texttt{pop()}? + + \vspace{2em} + + \only<2>{We only have \reg{rsp} and \reg{rip}.} + + \end{center} + \end{column} + \begin{column}{0.45\textwidth} + \includegraphics[width=0.95\linewidth]{img/call_stack} + \end{column} + \end{columns} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{DWARF tables} + +\newcolumntype{a}{>{\columncolor{RedOrange}}l} + +\begin{frame}{DWARF unwinding data} + \vspace{2em} + \tt \footnotesize + \begin{tabular}{ + >{\columncolor{YellowGreen}}l + >{\columncolor{Thistle}}l + l l l l l l + >{\columncolor{Apricot}}l} +~LOC & CFA & rbx & rbp & r12 & r13 & r14 & r15 & ra \\ +0084950 & rsp+8 & u & u & u & u & u & u & c-8 \\ +0084952 & rsp+16 & u & u & u & u & u & c-16 & c-8 \\ +0084954 & rsp+24 & u & u & u & u & c-24 & c-16 & c-8 \\ +0084956 & rsp+32 & u & u & u & c-32 & c-24 & c-16 & c-8 \\ +0084958 & rsp+40 & u & u & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084959 & rsp+48 & u & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +\rowcolor{Aquamarine} 008495a & rsp+56 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084962 & rsp+64 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a19 & rsp+56 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a1d & rsp+48 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a1e & rsp+40 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a20 & rsp+32 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a22 & rsp+24 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a24 & rsp+16 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a26 & rsp+8 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ +0084a30 & rsp+64 & c-56 & c-48 & c-40 & c-32 & c-24 & c-16 & c-8 \\ + \end{tabular} + + \pause{} + + \vspace{-3cm} + \hfill\includegraphics[height=3cm, angle=45, origin=c]{img/dwarf_logo} + \hspace{-1cm} +\end{frame} + +\begin{frame}[t, fragile]{The real DWARF} + \begin{lstlisting}[numbers=none, language=] +00009b30 48 009b34 FDE cie=0000 pc=0084950..0084b37 + DW_CFA_advance_loc: 2 to 0000000000084952 + DW_CFA_def_cfa_offset: 16 + DW_CFA_offset: r15 (r15) at cfa-16 + DW_CFA_advance_loc: 2 to 0000000000084954 + DW_CFA_def_cfa_offset: 24 + DW_CFA_offset: r14 (r14) at cfa-24 + DW_CFA_advance_loc: 2 to 0000000000084956 + DW_CFA_def_cfa_offset: 32 + DW_CFA_offset: r13 (r13) at cfa-32 + DW_CFA_advance_loc: 2 to 0000000000084958 + DW_CFA_def_cfa_offset: 40 + DW_CFA_offset: r12 (r12) at cfa-40 + DW_CFA_advance_loc: 1 to 0000000000084959 + [...] + \end{lstlisting} + + \begin{itemize} + \item[\textbf{$\longrightarrow$}] \textbf{\alert{constructed} on-demand + by a \alert{Turing-complete bytecode}!} + \end{itemize} + + \pause{} + + \vspace{-5.5cm} + \begin{center} + \bf \fontsize{8cm}{1cm}\colorbox{white}{\alert{Slow!}} + \end{center} +\end{frame} + +\begin{frame}{Why does slow matter?} + \begin{itemize} + + \item{} After all, we're talking about \alert{debugging procedures} ran + by a \alert{human being} (slower than the machine). + + \ldots{}or are we? + \end{itemize} + + \pause{} + \begin{center} + \textbf{\Large{}No!} + \end{center} + + \begin{itemize} + \pause{}\item{} Pretty much any \alert{program analysis tool} + \pause{}\item{} \alert{Profiling} with polling profilers + + \pause{}\item{} \alert{Exception handling} in C++ + + \end{itemize} + + \vspace{2em} + + \begin{center} + \textbf{\Large{}Debug data is not only for debugging} + \end{center} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Compiling stack unwinding data ahead-of-time} + +\subsection*{} + +\begin{frame}{Compilation overview} + \begin{itemize} + \item Compiled to \alert{C code} + \item C code then \alert{compiled to native binary} (gcc) + \begin{itemize} + \item[$\leadsto$] gcc optimisations for free + \end{itemize} + \item Compiled as \alert{separate \texttt{.so} files}, called \ehelfs{} + \bigskip{} + \item Morally a \alert{monolithic switch} on IPs + \item Each case contains assembly that computes a \alert{row of the + table} + \end{itemize} +\end{frame} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\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}{Compilation choices} + \textbf{In order to keep the compiler \alert{simple} and \alert{easily + testable}, the whole DWARF5 instruction set is not supported.} + + \begin{itemize} + \item Focus on \alert{x86\_64} + \item Focus on unwinding return address \\ + \vspace{0.3ex} + $\leadsto$ \textit{Allows building a backtrace} + \begin{itemize} + \item \alert{suitable for perf, not for gdb} + \item Only supports \alert{unwinding registers}: \reg{rip}, \reg{rsp}, + \reg{rbp}, \reg{rbx} + \item Supports the \alert{wide majority} ($> 99.9\%$) of instructions + used + \item Among \alert{4000} randomly sampled filed, only \alert{24} + containing unsupported instructions + \end{itemize} + \end{itemize} +\end{frame} + +\begin{frame}{Interface: libunwind} + \begin{itemize} + \item \alert{libunwind}: \textit{de facto} standard library for + unwinding + \item Relies on DWARF + + \bigskip{} + + \item \texttt{libunwind-eh\_elf}: alternative implementation using + \ehelfs{} + + \item[$\leadsto$] \alert{alternative implementation} of libunwind, + almost 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} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\subsection{Outlining} + +\begin{frame}{Size optimisation: outlining} + \begin{itemize} + \item This \alert{works}, but \alert{takes space}: about \alert{7 times + larger in size} than regular DWARF\@. + + \item DWARF optimisation strategy: \alert{alter previous row}. \\ + Causes slowness: we cannot do that. + + \item Remark: a lot of lines appear often. + \begin{itemize} + \item[$\leadsto$] \textbf{\emph{outline} them!} + \end{itemize} + + \pause{} + + \item On libc, $20\,827$ rows $\rightarrow$ $302$ outlined ($1.5\,\%$) + \item Turn the big switch into a binary search \alert{if/else tree} + \end{itemize} + + \pause{} + + \bigskip{} + \begin{center} + $\leadsto$ only \textbf{2.5 times bigger than DWARF} + \end{center} +\end{frame} + +\begin{frame}{Example with outlining} + \lstinputlisting[language=C]{src/fib7/fib7.eh_elf_outline.c} +\end{frame} + +\subsection{A word on formalization} + +\begin{frame}[t]{A word on formalization} + \begin{itemize} + \item First task: \alert{writing semantics} for DWARF, written as + mapping to C code. + \item DWARF5 specification: \alert{plain English}, no proper semantics + \item Compiled code is in substance equivalent to semantics + \item What remains to prove is mostly \alert{simple or classic + optimisations} + \end{itemize} + + \pause{} + \vspace{-3cm} + \begin{center} + \includegraphics[width=0.8\linewidth, angle=10]{img/dw_spec.png} + \end{center} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Benchmarking} + +\begin{frame}{Benchmarking requirements} + \begin{enumerate} + \item Thousands of samples (single unwind: $10\,\mu{}s$) + \item Interesting enough program to unwind: nested functions, complex + FDEs + \item Mitigate caching: don't always unwind from the \emph{same} point + \item Yet be fair: don't always unwind from totally different places + \item Distribute evenly: if possible, also from within libraries + \end{enumerate} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}{perf instrumentation} + \textbf{\alert{perf} is the state-of-the-art polling profiler for Linux.} + \begin{itemize} + \item{} used to get readings of the time spent in each function + \item{} works by regularly stopping the program, unwinding its stack, + then aggregating the gathered data + \end{itemize} + + \pause{}\bigskip{} + \textbf{Instrumenting perf matches all the requirements!} + + \begin{itemize} + \item{} \alert{Plug \ehelfs{} into perf}: use \ehelfs{} instead of + DWARF to unwind the stack + \item{} Implement \alert{unwinding performance counters} inside perf + \bigskip{} + + \item{} Use perf on \alert{hackbench}, a kernel stress-test program + \begin{itemize} + \item Small program + \item Lots of calls + \item Relies on libc, libpthread + \end{itemize} + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Results} + +\begin{frame}{Time performance} + \small + \centering + \begin{tabular}{l r r r r r} + \toprule + \thead{Unwinding method} & \thead{Frames \\ unwound} + & \thead{Tot.\ time \\ ($\mu s$)} + & \thead{Avg. \\ time / frame \\ ($ns$)} + & \thead{Time \\ ratio} \\ + \midrule + \alert{\ehelfs{}} + & 23506 % Frames unwound + & 14837 % Total time + & 631 % Avg time + & 1 + \\ + \prog{libunwind}, \alert{cached} + & 27058 % Frames unwound + & 441601 % Total time + & 16320 % Avg time + & \alert{25.9} + \\ + \prog{libunwind}, \alert{uncached} + & 27058 % Frames unwound + & 671292 % Total time + & 24809 % Avg time + & \alert{39.3} + \\ + \bottomrule + \end{tabular} +\end{frame} + +\begin{frame}{Space performance} + \begin{center} + \begin{tabular}{r r r r r r} + \toprule + \thead{Object} + & \thead{\% of binary size} + & \thead{Growth factor} \\ + \midrule + libc + & 21.88 & 2.41 \\ + libpthread + & 43.71 & 2.19 \\ + ld + & 22.09 & 2.97 \\ + hackbench + & 93.87 & 4.99 \\ + \midrule + Total + & 22.81 & \alert{2.44} \\ + \bottomrule + \end{tabular} + \end{center} +\end{frame} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section*{} +\setcounter{section}{0} + +\begin{frame}{What next?} + \begin{itemize} + \item Implement a release-ready, packageable, easy to use version of + perf with \ehelfs{} and submit it for inclusion + + \item{} Measure \alert{C++ exceptions overhead} precisely in common + software + + \item{} Implement \alert{\ehelfs{}} support for \alert{C++ runtime} + exception handling, and other systems where unwinding is a + performance bottleneck + + \medskip + + \item \alert{Outlining} was effective for + compactness\ldots{} Try outlining DWARF bytecode\@? + + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} + \vspace{5mm} + \includegraphics[width=\linewidth]{img/keep_breathing} + \vspace{-1cm} + + \begin{center} + \large + \begin{align*} + \textbf{Slides: } &\text{\url{https://tobast.fr/m2/slides.pdf}} \\ + \textbf{Report: } &\text{\url{https://tobast.fr/m2/report.pdf}} + \end{align*} + \end{center} + +\end{frame} + +\end{document} diff --git a/src/fib7/fib7.bin b/src/fib7/fib7.bin new file mode 100755 index 0000000..0d9e2f3 Binary files /dev/null and b/src/fib7/fib7.bin differ diff --git a/src/fib7/fib7.c b/src/fib7/fib7.c new file mode 100644 index 0000000..d4b3264 --- /dev/null +++ b/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/src/fib7/fib7.cfde b/src/fib7/fib7.cfde new file mode 100644 index 0000000..b00df18 --- /dev/null +++ b/src/fib7/fib7.cfde @@ -0,0 +1,11 @@ + DWARF + CFA ra +void fib7() { 0x615 rsp+8 c-8 + int fibo[8]; 0x620 rsp+48 c-8 + fibo[0] = 1; + fibo[1] = 1; + for(...) + ... + printf("%d\n", fibo[7]); + 0x659 rsp+8 c-8 +} diff --git a/src/fib7/fib7.eh_elf_basic.c b/src/fib7/fib7.eh_elf_basic.c new file mode 100644 index 0000000..b8fa79b --- /dev/null +++ b/src/fib7/fib7.eh_elf_basic.c @@ -0,0 +1,15 @@ +unwind_context_t _eh_elf( + unwind_context_t ctx, uintptr_t pc) +{ + unwind_context_t out_ctx; + switch(pc) { + ... + 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; + ... + } +} diff --git a/src/fib7/fib7.eh_elf_outline.c b/src/fib7/fib7.eh_elf_outline.c new file mode 100644 index 0000000..576f333 --- /dev/null +++ b/src/fib7/fib7.eh_elf_outline.c @@ -0,0 +1,21 @@ +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_1; + } + ... + } + + _factor_1: + 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/src/fib7/fib7.fde b/src/fib7/fib7.fde new file mode 100644 index 0000000..1b6c08a --- /dev/null +++ b/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/src/fib7/fib7.raw_fde b/src/fib7/fib7.raw_fde new file mode 100644 index 0000000..a90cfb4 --- /dev/null +++ b/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/src/fib7/fib7.s b/src/fib7/fib7.s new file mode 100644 index 0000000..8450ed0 --- /dev/null +++ b/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/src/fib7/fib7.st.bin b/src/fib7/fib7.st.bin new file mode 100755 index 0000000..0d9e2f3 Binary files /dev/null and b/src/fib7/fib7.st.bin differ diff --git a/src/unwind_context.c b/src/unwind_context.c new file mode 100644 index 0000000..eb54302 --- /dev/null +++ b/src/unwind_context.c @@ -0,0 +1,4 @@ +typedef struct { + uint8_t flags; // State (registers filled, error) + uintptr_t rip, rsp, rbp, rbx; // Registers' values +} unwind_context_t; diff --git a/texlib/common.sty b/texlib/common.sty new file mode 100644 index 0000000..90aaae4 --- /dev/null +++ b/texlib/common.sty @@ -0,0 +1,12 @@ +%% Common, non-specific useful commands + +\newcommand{\ie}{\textit{ie.}} +\newcommand{\eg}{\textit{eg.}} +\newcommand{\wrt}{\textit{wrt.}} + +\newcommand{\set}[1]{\left\{ #1 \right\}} +\newcommand{\card}[1]{\left\vert{} #1 \right\vert} +\newcommand{\abs}[1]{\left\vert{} #1 \right\vert} + +\newcommand{\tnhead}[2]{\multicolumn{1}{#1}{#2}} % Table neutral head +\newcommand{\spaced}[2]{\hspace{#1} #2 \hspace{#1}} diff --git a/texlib/my_listings.sty b/texlib/my_listings.sty new file mode 100644 index 0000000..f720a6d --- /dev/null +++ b/texlib/my_listings.sty @@ -0,0 +1,63 @@ +\usepackage{listings} +\usepackage{algorithmicx} +\usepackage{algpseudocode} +\usepackage{color} +\usepackage{xcolor} +\usepackage{courier} +\definecolor{color_comment}{HTML}{2D6F19} +\definecolor{color_linenum}{HTML}{9E9E9E} +\definecolor{color_strings}{HTML}{D300F3} + + +\lstset{ % +% backgroundcolor=\color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor} + basicstyle=\footnotesize\ttfamily, % the size of the fonts that are used for the code + breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace + breaklines=true, % sets automatic line breaking + captionpos=b, % sets the caption-position to bottom + commentstyle=\color{color_comment}, % comment style +% deletekeywords={...}, % if you want to delete keywords from the given language +% escapeinside={\%*}{*)}, % if you want to add LaTeX within your code + extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8 + frame=none, % adds a frame around the code + keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible) + keywordstyle=\color{blue}, % keyword style + morekeywords={*,...}, % if you want to add more keywords to the set + numbers=left, % where to put the line-numbers; possible values are (none, left, right) + numbersep=5pt, % how far the line-numbers are from the code + numberstyle=\tiny\color{color_linenum}, % the style that is used for the line-numbers + rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here)) + showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces' + showstringspaces=false, % underline spaces within strings only + showtabs=false, % show tabs within strings adding particular underscores + stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered + stringstyle=\color{color_strings}, % string literal style + tabsize=4, % sets default tabsize to 2 spaces +% title=\lstname, % show the filename of files included with \lstinputlisting; also try caption instead of title +% inputencoding=utf8/latin1 % To accept utf8 encoding +} + +\lstset{literate= + {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 + {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 + {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1 + {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1 + {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1 + {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1 + {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1 + {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1 + {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1 + {ű}{{\H{u}}}1 {Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1 + {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1 + {€}{{\EUR}}1 {£}{{\pounds}}1 {¬}{{$\lnot$}}1 {∞}{{$\infty$}}1 +} + +\newcommand{\true}{\lstinline$true$} +\newcommand{\false}{\lstinline$false$} + +\newcommand{\lstbash}[1]{\lstinline[language=bash]$#1$} +\newcommand{\lstocaml}[1]{\lstinline[language=Caml]$#1$} +\newcommand{\lstcpp}[1]{\lstinline[language=C++]$#1$} +\newcommand{\lstc}[1]{\lstinline[language=C]$#1$} +\newcommand{\lstpython}[1]{\lstinline[language=python]$#1$} + diff --git a/texlib/report.bib b/texlib/report.bib new file mode 100644 index 0000000..9c5c47b --- /dev/null +++ b/texlib/report.bib @@ -0,0 +1,102 @@ +@manual{dwarf5std, + title = {DWARF Debugging Information Format version 5}, + organization = {DWARF Debugging Information Format Committee}, + author = {DWARF5}, + url = {http://dwarfstd.org}, + year = {2017}, +} + +@manual{c11std, + title = {ISO/IEC 9899:2011}, + organization = {International Organization for Standardization}, + author = {C11}, +} + +@manual{systemVabi, + title = {System V Application Binary Interface, AMD64 + architecture}, + url = {https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf}, +} + + +@online{libunwind, + title = {Libunwind webpage}, + url = {http://www.nongnu.org/libunwind/}, +} + +@inproceedings{oakley2011exploiting, + title={Exploiting the Hard-Working DWARF: Trojan and Exploit Techniques with No Native Executable Code.}, + author={Oakley, James and Bratus, Sergey}, + booktitle={WOOT}, + pages={91--102}, + year={2011} +} + +@article{dinechin2000exn, + title={C++ exception handling}, + author={De Dinechin, Christophe}, + journal={IEEE Concurrency}, + volume={8}, + number={4}, + pages={72--79}, + year={2000}, + publisher={IEEE} +} + +@article{koening1990exception, + title={Exception handling for C++}, + author={Koening, Andrew and Stroustrup, Bjarne}, + journal={Journal of Object-Oriented Programming}, + volume={3}, + number={2}, + pages={16--33}, + year={1990}, + publisher={SIGS Publications}, + url={http://www.stroustrup.com/except89.pdf} +} + + +@online{niditoexn, + title={Exceptions in C with Longjmp and Setjmp}, + author={Nidito, Francesco}, + url={https://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html}, + urldate={2018-08-04} +} + +@online{hackbenchsrc, + title={Hackbench}, + author={Zhang, Yanmin}, + url={https://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c}, + year={2008} +} + +@inproceedings{csmith, + author = {Xuejun Yang and + Yang Chen and + Eric Eide and + John Regehr}, + title = {Finding and understanding bugs in {C} compilers}, + booktitle = {Proceedings of the 32nd {ACM} {SIGPLAN} Conference on Programming + Language Design and Implementation, {PLDI} 2011, San Jose, CA, USA, + June 4-8, 2011}, + pages = {283--294}, + year = {2011}, + crossref = {DBLP:conf/pldi/2011}, + url = {http://doi.acm.org/10.1145/1993498.1993532}, + doi = {10.1145/1993498.1993532}, + timestamp = {Mon, 05 Jun 2017 12:39:37 +0200}, + biburl = {https://dblp.org/rec/bib/conf/pldi/YangCER11}, + bibsource = {dblp computer science bibliography, https://dblp.org} +} + +@article{kell2016libcrunch, + title={Dynamically diagnosing type errors in unsafe code}, + author={Kell, Stephen}, + journal={ACM SIGPLAN Notices}, + volume={51}, + number={10}, + pages={800--819}, + year={2016}, + publisher={ACM} +} + diff --git a/texlib/specific.sty b/texlib/specific.sty new file mode 100644 index 0000000..cfada16 --- /dev/null +++ b/texlib/specific.sty @@ -0,0 +1,42 @@ +%% Specific commands for this project + +\newcommand{\stackfhead}[1] + {\tnhead{l}{\hspace{-5ex}$\reg{rsp} #1$ \hspace{2em}}} + +\newcommand{\prog}[1]{\texttt{#1}} +\newcommand{\ehelf}{\texttt{eh\_elf}} +\newcommand{\ehelfs}{\texttt{eh\_elfs}} +\newcommand{\ehframe}{\lstc{.eh_frame}} + +\newcommand{\mhex}[1]{0\texttt{x}#1} + +%% DWARF semantics +\newcommand{\dwcfa}[1]{\texttt{DW\_CFA\_#1}} +\newcommand{\reg}[1]{\%#1} + +\newcommand{\DWARF}{\operatorname{DWARF}} + +\newcommand{\FDE}{\operatorname{FDE}} +\newcommand{\dwrow}{\operatorname{Row}} +\newcommand{\spexpr}{\mathbb{E}} +\newcommand{\regs}{\mathbb{R}} +\newcommand{\values}{\mathbb{V}} + +\newcommand{\valaddr}[1]{\operatorname{Addr}\left(#1\right)} +\newcommand{\valval}[1]{\operatorname{Val}\left(#1\right)} +\newcommand{\valexpr}{\operatorname{Expr}} + +\newcommand{\intermedlang}{\mathcal{I}} + +\newcommand{\semI}[2]{{\left\llbracket{} #1 \right\rrbracket}^\intermedlang_{#2}} +\newcommand{\semC}[1]{{\left\llbracket{} #1 \right\rrbracket}^{C}} +\newcommand{\semR}[1]{{\left\llbracket{} #1 \right\rrbracket}^{R}} + +\newcommand{\rowstack}{\mathbb{S}} + +\newcommand{\insarrow}[1]{\xleftarrow{\text{#1}}} +\newcommand{\extrarrow}[1]{\xrightarrow{\text{#1}}} + +\newcommand{\contsem}[1]{\semI{d}{s}\left(#1\right)} + +\newcommand{\eqspace}{\quad = \quad} diff --git a/texlib/todo.sty b/texlib/todo.sty new file mode 100644 index 0000000..05076cb --- /dev/null +++ b/texlib/todo.sty @@ -0,0 +1,11 @@ +\RequirePackage{xcolor} + +\definecolor{todobg}{HTML}{FF5F00} +\definecolor{todofg}{HTML}{3700DA} +\definecolor{notebg}{HTML}{87C23C} +\definecolor{notefg}{HTML}{BC3423} + +\newcommand{\qtodo}[1]{\colorbox{todobg}{\textcolor{todofg}{#1}}} +\newcommand{\todo}[1]{\qtodo{\textbf{TODO:}\,#1}} +\newcommand{\qnote}[1]{\colorbox{notebg}{\textcolor{notefg}{#1}}} +\newcommand{\tnote}[1]{\qnote{\textbf{NOTE:}\,#1}}