\documentclass{beamer} \usetheme{linutronix} \usepackage{german} \usepackage[utf8]{inputenc} \usepackage{pgf} \usepackage{graphicx} \usepackage{lxextras} \title{Block \lq Applikationsentwicklung für (Embedded) LINUX\rq} \institute{Linutronix GmbH} \lstset{keywordstyle=\color{blue},commentstyle=\color{orange}} \begin{document} \maketitle % ----- Slide ------------------ \begin{frame} \frametitle{Übersicht} \tableofcontents \end{frame} \section{Toolchain} \subsection{Der GNU Compiler} \subsubsection{Hello world} \begin{frame}[fragile] \frametitle{Der GNU Compiler} \begin{lstlisting}[language=c] /* hello.c */ #include int main(void) { printf("Hello world\n"); return 0; } \end{lstlisting} \begin{lstlisting}[language=bash] # Uebersetzen des Testprogramms gcc -o hello hello.c \end{lstlisting} \end{frame} \subsubsection{Wichtige Optionen} \begin{frame}[fragile] \frametitle{Wichtige gcc Optionen} \begin{lstlisting}[language=bash] # Nur Objectfile erzeugen gcc -c -o hello.o hello.c # Uebersetzen mit Optimierungslevel 3 gcc -O3 -o hello hello.c # Ohne Optimierung und mit # Debugsymbolen uebersetzen gcc -O0 -g hello hello.c \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Wichtige gcc Optionen} \begin{lstlisting}[language=bash] # Gegen zusaetzliche Bibliothek linken (librt.so) gcc -lrt -o hello hello.c # Suchpfad fuer Bibliotheken hinzufuegen gcc -L /mypath -lrt -o hello hello.c # Suchpfad fuer Includes hinzufuegen gcc -I /mypath -o hello hello.c \end{lstlisting} \end{frame} \subsection{Die Binutils} \subsubsection{Übersicht} \begin{frame} \frametitle{Die Binutils} Eine Sammlung von Programmen zum Erstellen / Bearbeiten von Binaries. Die wichtigsten Tools sind: \begin{itemize} \item Der GNU Linker (ld) \item Der GNU Assembler (as) \end{itemize} \end{frame} \begin{frame} \frametitle{Weitere Programme der Binutils} \begin{itemize} \item \textbf{addr2line}: Ordnet Adressen Zeilennummern zu \item \textbf{gprof}: Profiler \item \textbf{nm}: Listet Symbole in Objectfiles \item \textbf{objcopy}: Kopiert und konvertiert Objectfiles \item \textbf{objdump}: Listet Informationen zu Objectfiles \end{itemize} \end{frame} \begin{frame} \frametitle{Weitere Programme der Binutils} \begin{itemize} \item \textbf{ranlib}: Generiert den Index zu einem Archivinhalt \item \textbf{readelf}: Zeigt Informationen zu ELF Files \item \textbf{size}: Listet die Sektionsgrößen für Object- oder ELF Files \item \textbf{strip}: Entfernt Symbole \end{itemize} \end{frame} \subsubsection{objdump} \begin{frame}[containsverbatim] \frametitle{Untersuchen von Binaries mit Objdump} \begin{lstlisting}[language=bash] jan@hopfropf:~$ objdump -x /bin/ls /bin/ls: file format elf64-x86-64 /bin/ls architecture: i386:x86-64, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x0000000000402490 Program Header: PHDR off 0x0000000000000040 vaddr [...] filesz 0x00000000000001f8 memsz [...] [...] Dynamic Section: NEEDED librt.so.1 [...] \end{lstlisting} \end{frame} \begin{frame}[containsverbatim] \frametitle{Untersuchen von Binaries mit Objdump} \begin{lstlisting}[language=bash] Version References: required from librt.so.1: 0x09691a75 0x00 07 GLIBC_2.2.5 [...] Sections: Idx Name Size VMA [...] 0 .interp 0000001c 000000000040 [...] CONTENTS, ALLOC, LOAD, [...] 1 .note.ABI-tag 00000020 000000000040 [...] CONTENTS, ALLOC, LOAD, [...] [...] \end{lstlisting} \end{frame} \begin{frame}[containsverbatim] \frametitle{Bibliotheksabhängigkeiten mit objdump bestimmen} \begin{lstlisting}[language=bash] jan@hopfropf:~$ objdump -x /bin/ls | grep NEEDED NEEDED librt.so.1 NEEDED libselinux.so.1 NEEDED libacl.so.1 NEEDED libc.so.6 \end{lstlisting} \end{frame} \subsubsection{objcopy} \begin{frame}[fragile] \frametitle{Binaries bearbeiten mit objcopy} \begin{lstlisting}[language=bash] # 64bit ELF ins SREC Format kopieren objcopy -I elf64-x86-64 -O srec hello hello.srec # SREC in 64 bit ELF kopieren objcopy -I srec -O elf64-x86-64 hello.srec hello \end{lstlisting} \end{frame} \subsubsection{addr2line} \begin{frame}[containsverbatim] \frametitle{Adressen zuordnen mit addr2line} \begin{lstlisting}[language=bash] objdump -D hello | less \end{lstlisting} \begin{verbatim} [...] 000000000040050c
: 40050c: 55 push %rbp 40050d: 48 89 e5 mov %rsp,%rbp [...] \end{verbatim} \begin{lstlisting}[language=bash] $ addr2line -e hello 40050c /home/jan/work/examples/hello.c:4 \end{lstlisting} \end{frame} \subsection{Buildprozess automatisieren (GNU make)} \subsubsection{Übersicht} \begin{frame} \frametitle{GNU make} \begin{alertblock}{Was ist GNU make?} GNU make kontrolliert und automatisiert Buildprozesse. \end{alertblock} \end{frame} \subsubsection{Anwendungsbeispiele} \begin{frame}[containsverbatim] \frametitle{Einfaches Beispiel} \begin{lstlisting}[language=make,showtabs=true,tabsize=4,tab=\rightarrowfill] % Makefile hello: hello.o gcc -o $@ $< hello.o: hello.c gcc -c -o $@ $< clean: rm -rf hello hello.o \end{lstlisting} \end{frame} \begin{frame} \frametitle{Aufgabe} \begin{itemize} \item Erstellen Sie ein Beispielprojekt mit einem Hallo Welt Programm und dem im Beispiel aufgeführten Makefile \item Übersetzen Sie das Programm \item Erstellen Sie eine Datei mit dem Namen clean und führen make clean aus (Was passiert?!) \end{itemize} \end{frame} \begin{frame}[containsverbatim] \frametitle{Problem} \begin{lstlisting}[language=bash] $ make gcc -c -o hello.o hello.c gcc -o hello hello.o $ touch clean $ make clean make: `clean' is up to date. \end{lstlisting} \end{frame} \begin{frame}[containsverbatim] \frametitle{PHONY targets} \begin{lstlisting}[language=make,showtabs=true,tabsize=4,tab=\rightarrowfill] hello: hello.o gcc -o $@ $< hello.o: hello.c gcc -c -o $@ $< .PHONY: clean clean: rm -rf hello hello.o \end{lstlisting} Aufgabe: Erweitern Sie Ihr Makefile um das PHONY target und führen Sie erneut make clean aus. \end{frame} \begin{frame}[containsverbatim] \frametitle{Regeln mit Pattern} \begin{lstlisting}[language=make,showtabs=true,tabsize=4,tab=\rightarrowfill] hello: hello.o gcc -o $@ $< %.o: %.c gcc -c -o $@ $< .PHONY: clean clean: rm -rf hello hello.o \end{lstlisting} \end{frame} \begin{frame}[containsverbatim] \frametitle{Variablen} \begin{lstlisting}[language=make,showtabs=true,tabsize=4,tab=\rightarrowfill] EXE = hello OBJ = $(EXE).o $(EXE): $(OBJ) gcc -o $@ $< %.o: %.c gcc -c -o $@ $< .PHONY: clean clean: rm -rf $(EXE) $(OBJ) \end{lstlisting} \end{frame} \begin{frame}[containsverbatim] \frametitle{Pattern substitution} \begin{lstlisting}[language=make,showtabs=true,tabsize=4,tab=\rightarrowfill] SRC = hello.c hello1.c OBJ = $(SRC:%.c=%.o) [...] \end{lstlisting} \end{frame} \end{document}