Fix colon spaces, reorganize fib7 listing flow

This commit is contained in:
Théophile Bastian 2018-08-17 18:15:43 +02:00
parent 825b6c3e36
commit 31efc6b32a
2 changed files with 32 additions and 38 deletions

View file

@ -273,23 +273,20 @@ them.
caption={Original C},label={lst:ex1_c}] caption={Original C},label={lst:ex1_c}]
{src/fib7/fib7.c} {src/fib7/fib7.c}
\end{minipage} \hfill \begin{minipage}{0.45\textwidth} \end{minipage} \hfill \begin{minipage}{0.45\textwidth}
\lstinputlisting[language=C,caption={Processed DWARF}, \lstinputlisting[language={[x86masm]Assembler},
label={lst:ex1_dw}] caption={Generated assembly},label={lst:ex1_asm}]
{src/fib7/fib7.fde} {src/fib7/fib7.s}
\lstinputlisting[language=C,caption={Raw DWARF},label={lst:ex1_dwraw}]
{src/fib7/fib7.raw_fde}
\end{minipage} \end{minipage}
\end{figure} \end{figure}
\begin{figure}[h] \begin{figure}[h]
\begin{minipage}{0.45\textwidth} \begin{minipage}{0.45\textwidth}
\lstinputlisting[language={[x86masm]Assembler},lastline=11, \lstinputlisting[language=C,caption={Raw DWARF},label={lst:ex1_dwraw}]
caption={Generated assembly},label={lst:ex1_asm}] {src/fib7/fib7.raw_fde}
{src/fib7/fib7.s}
\end{minipage} \hfill \begin{minipage}{0.45\textwidth} \end{minipage} \hfill \begin{minipage}{0.45\textwidth}
\lstinputlisting[language={[x86masm]Assembler},firstline=12, \lstinputlisting[language=C,caption={Processed DWARF},
firstnumber=last] label={lst:ex1_dw}]
{src/fib7/fib7.s} {src/fib7/fib7.fde}
\end{minipage} \end{minipage}
\end{figure} \end{figure}
@ -413,7 +410,7 @@ pointer. The C function representing it will thus take as parameters an array
of the registers' values as well as an IP, and will return another array of of the registers' values as well as an IP, and will return another array of
registers values, which will represent the evaluated DWARF row. registers values, which will represent the evaluated DWARF row.
\subsection{Original language~: DWARF instructions} \subsection{Original language: DWARF instructions}
These are the DWARF instructions used for CFI description, that is, the These are the DWARF instructions used for CFI description, that is, the
instructions that contain the stack unwinding table informations. The following instructions that contain the stack unwinding table informations. The following
@ -427,50 +424,50 @@ here, those variations between eg. \dwcfa{advance\_loc1} and
operand~-- are irrelevant and will be eluded. operand~-- are irrelevant and will be eluded.
\begin{itemize} \begin{itemize}
\item{} \dwcfa{set\_loc(loc)}~: \item{} \dwcfa{set\_loc(loc)}:
start a new table row from address $loc$ start a new table row from address $loc$
\item{} \dwcfa{advance\_loc(delta)}~: \item{} \dwcfa{advance\_loc(delta)}:
start a new table row at address $prev\_loc + delta$ start a new table row at address $prev\_loc + delta$
\item{} \dwcfa{def\_cfa(reg, offset)}~: \item{} \dwcfa{def\_cfa(reg, offset)}:
sets this row's CFA at $(\reg{reg} + \textit{offset})$ sets this row's CFA at $(\reg{reg} + \textit{offset})$
\item{} \dwcfa{def\_cfa\_register(reg)}~: \item{} \dwcfa{def\_cfa\_register(reg)}:
sets CFA at $(\reg{reg} + \textit{prev\_offset})$ sets CFA at $(\reg{reg} + \textit{prev\_offset})$
\item{} \dwcfa{def\_cfa\_offset(offset)}~: \item{} \dwcfa{def\_cfa\_offset(offset)}:
sets CFA at $(\reg{prev\_reg} + \textit{offset})$ sets CFA at $(\reg{prev\_reg} + \textit{offset})$
\item{} \dwcfa{def\_cfa\_expression(expr)}~: \item{} \dwcfa{def\_cfa\_expression(expr)}:
sets CFA as the result of $expr$ sets CFA as the result of $expr$
\item{} \dwcfa{undefined(reg)}~: \item{} \dwcfa{undefined(reg)}:
sets the register \reg{reg} as undefined in this row sets the register \reg{reg} as undefined in this row
\item{} \dwcfa{same\_value(reg)}~: \item{} \dwcfa{same\_value(reg)}:
declares that the register \reg{reg} hasn't been touched, or was declares that the register \reg{reg} hasn't been touched, or was
restored to its previous value, in this row. An unwinding procedure can restored to its previous value, in this row. An unwinding procedure can
leave it as-is. leave it as-is.
\item{} \dwcfa{offset(reg, offset)}~: \item{} \dwcfa{offset(reg, offset)}:
the value of the register \reg{reg} is stored in memory at the address the value of the register \reg{reg} is stored in memory at the address
$CFA + \textit{offset}$. $CFA + \textit{offset}$.
\item{} \dwcfa{val\_offset(reg, offset)}~: \item{} \dwcfa{val\_offset(reg, offset)}:
the value of the register \reg{reg} is the value $CFA + \textit{offset}$ the value of the register \reg{reg} is the value $CFA + \textit{offset}$
\item{} \dwcfa{register(reg, model)}~: \item{} \dwcfa{register(reg, model)}:
the register \reg{reg} has, in this row, the value that $\reg{model}$ the register \reg{reg} has, in this row, the value that $\reg{model}$
had in the previous row had in the previous row
\item{} \dwcfa{expression(reg, expr)}~: \item{} \dwcfa{expression(reg, expr)}:
the value of \reg{reg} is stored in memory at the address defined by the value of \reg{reg} is stored in memory at the address defined by
$expr$ $expr$
\item{} \dwcfa{val\_expression(reg, expr)}~: \item{} \dwcfa{val\_expression(reg, expr)}:
\reg{reg} has the value of $expr$ \reg{reg} has the value of $expr$
\item{} \dwcfa{restore(reg)}~: \item{} \dwcfa{restore(reg)}:
\reg{reg} has the same value as in this FDE's preamble (CIE) in this \reg{reg} has the same value as in this FDE's preamble (CIE) in this
row. This is \emph{not implemented in this semantics} for simplicity row. This is \emph{not implemented in this semantics} for simplicity
and brevity (we would have to introduce CIE (preamble) and FDE (body) and brevity (we would have to introduce CIE (preamble) and FDE (body)
independently). This is also not much used in actual ELF independently). This is also not much used in actual ELF
files: the analysis in Section~\ref{ssec:instr_cov} found no such files: the analysis in Section~\ref{ssec:instr_cov} found no such
instruction, on a random uniform sample of 4000 ELF files. instruction, on a random uniform sample of 4000 ELF files.
\item{} \dwcfa{remember\_state()}~: \item{} \dwcfa{remember\_state()}:
push the state of all the registers of this row on an implicit stack push the state of all the registers of this row on an implicit stack
\item{} \dwcfa{restore\_state()}~: \item{} \dwcfa{restore\_state()}:
pop an entry of the implicit stack, and restore all registers in this pop an entry of the implicit stack, and restore all registers in this
row to the value held in the stack record. row to the value held in the stack record.
\item{} \dwcfa{nop()}~: \item{} \dwcfa{nop()}:
do nothing (padding) do nothing (padding)
\end{itemize} \end{itemize}
@ -516,7 +513,7 @@ to define $\reg{rax}$ to the value contained in memory 16 bytes below the CFA,
we would have $\reg{rax} \mapsto \valaddr{\reg{CFA}, -16}$, since the stack we would have $\reg{rax} \mapsto \valaddr{\reg{CFA}, -16}$, since the stack
grows downwards. grows downwards.
\subsection{Target language~: a C function body} \subsection{Target language: a C function body}
The target language of these semantics is a C function, to be interpreted with The target language of these semantics is a C function, to be interpreted with
respect to the C11 standard~\cite{c11std}. The function is supposed to be run respect to the C11 standard~\cite{c11std}. The function is supposed to be run
@ -532,7 +529,7 @@ unless the IP obtained after the first unwinding comes from another shared
object file, for instance a call to \prog{libc}. In this case, unwinding the object file, for instance a call to \prog{libc}. In this case, unwinding the
second frame will require loading the corresponding DWARF information. second frame will require loading the corresponding DWARF information.
The function is the following~: The function is the following:
\lstinputlisting[language=C]{src/dw_semantics/c_context.c} \lstinputlisting[language=C]{src/dw_semantics/c_context.c}
@ -553,7 +550,7 @@ kept in subscript.
\medskip \medskip
Thus, we define $\semI{\bullet}{s}(\bullet) : \DWARF \times \FDE \to \FDE$, for Thus, we define $\semI{\bullet}{s}(\bullet): \DWARF \times \FDE \to \FDE$, for
$s$ a stack of $\dwrow$, that is, $s$ a stack of $\dwrow$, that is,
\[ \[
s \in \rowstack := \dwrow^\ast s \in \rowstack := \dwrow^\ast
@ -642,7 +639,7 @@ this way.}
\medskip \medskip
We now define $\semC{\bullet} : \DWARF \to C$, in the context presented We now define $\semC{\bullet}: \DWARF \to C$, in the context presented
earlier. The translation from $\intermedlang$ to C is defined as follows: earlier. The translation from $\intermedlang$ to C is defined as follows:
\begin{itemize} \begin{itemize}

View file

@ -2,17 +2,14 @@
615: sub $0x28,%rsp ; Alloc stack 615: sub $0x28,%rsp ; Alloc stack
619: movl $0x1,(%rsp) ; fibo[0] 619: movl $0x1,(%rsp) ; fibo[0]
620: movl $0x1,0x4(%rsp) ; fibo[1] 620: movl $0x1,0x4(%rsp) ; fibo[1]
627: 628: mov %rsp,%rax ; BEGIN FOR
; Begin for loop
628: mov %rsp,%rax
62b: lea 0x18(%rax),%rcx 62b: lea 0x18(%rax),%rcx
62f: mov (%rax),%edx 62f: mov (%rax),%edx
631: add 0x4(%rax),%edx 631: add 0x4(%rax),%edx
634: mov %edx,0x8(%rax) 634: mov %edx,0x8(%rax)
637: add $0x4,%rax 637: add $0x4,%rax
63b: cmp %rcx,%rax 63b: cmp %rcx,%rax
63e: jne 62f <fib7+0x1a> 63e: jne 62f <fib7+0x1a> ; END FOR
; End for loop
640: mov 0x1c(%rsp),%esi 640: mov 0x1c(%rsp),%esi
644: lea 0xb9(%rip),%rdi 644: lea 0xb9(%rip),%rdi
64b: mov $0x0,%eax 64b: mov $0x0,%eax