From: Andy Spencer Date: Sun, 16 Dec 2018 06:06:33 +0000 (+0000) Subject: Update C Compiling presentation. X-Git-Url: http://pileus.org/git/?p=~andy%2Fsfvlug;a=commitdiff_plain;h=4d380e0b82a77240bc5859c13161e90128d15f0d Update C Compiling presentation. --- diff --git a/.gitignore b/.gitignore index 0c0b127..e3102e2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # C output *.o *.a +*.so # Latex output *.aux @@ -14,3 +15,9 @@ *.snm *.toc *.vrb + +# CC presentation +cc/elf.pdf +cc/packages/ +cc/source/hello +cc/source/syscall diff --git a/cc/cc.pdf b/cc/cc.pdf new file mode 100644 index 0000000..c09f513 Binary files /dev/null and b/cc/cc.pdf differ diff --git a/cc/cc.tex b/cc/cc.tex index c0d47db..2781926 100644 --- a/cc/cc.tex +++ b/cc/cc.tex @@ -1,4 +1,4 @@ -\documentclass[13pt]{beamer} +\documentclass[13pt,aspectratio=169]{beamer} %%%%%%%%%%%%%%%%%%% % Commands/macros % @@ -18,6 +18,14 @@ \header{#1} } +\newcommand{\screen}[1]{ + \setlength{\leftmargin}{0pt} + \setlength{\rightmargin}{0pt} + \begin{center} + \includegraphics[height=3.0in,width=4.25in,keepaspectratio]{#1} + \end{center} +} + %%%%%%%%%%%%%%%% % Header/theme % %%%%%%%%%%%%%%%% @@ -27,8 +35,8 @@ %]{Torino} \setbeamertemplate{navigation symbols}{} \setbeamertemplate{footline}{} -\setbeamersize{text margin left=20mm} -\setbeamersize{text margin right=10mm} +\setbeamersize{text margin left=20mm} +\setbeamersize{text margin right=10mm} \setbeamerfont{frametitle}{size={\fontsize{15}{16}}} % Import packages @@ -58,7 +66,7 @@ } \title[C Compiling]{% - C Comipling and More! + C Compiling and More! } \author[Spencer]{% @@ -164,13 +172,17 @@ "Debugging With Attributed Record Formats"} \end{frame} +\begin{frame}{Executable formats} + \screen{elf.pdf} +\end{frame} + \begin{frame}{Dynamic vs static} \begin{itemize} \item Static linking \item Dynamic linking \item Modules \item System calls - \begin{itemize} + \end{itemize} \end{frame} %%%%%%%%%%%%%%%%% @@ -180,38 +192,62 @@ \section{Build systems} \begin{frame}{C is for CC} + \structure{Running CC manually} \begin{itemize} - \item C is for CC + \item Compiling manually... + \item Works for very small program. + \item cc hello.c + \item gcc -Wall -o hello hello.c \end{itemize} -\end{frame} -\begin{frame}{Scripts} + \structure{Scripting} \begin{itemize} - \item Scripts + \item Why not just write a script for this? + \item Dependency tracking, parallel execution. \end{itemize} \end{frame} \begin{frame}{Make} \begin{itemize} - \item Make + \item Generic dependency tracker. + \item Except GNU Make, which has tons of dumb rules. + \item Configured with -DOPTION or config.mk \end{itemize} \end{frame} \begin{frame}{autotools} + \structure{Overview} + \begin{itemize} + \item Designed to be "portable". + \item Good support for configuration. + \item Handles all the weird corner cases. + \item Nobody likes it but everybody uses it. + \end{itemize} + \structure{Usage} \begin{itemize} - \item autotools + \item {[./autogen.sh]} + \item ./configure --help + \item make + \item make install \end{itemize} \end{frame} \begin{frame}{kconfig} \begin{itemize} - \item kconfig + \item Started out in the Linux kernel. + \item Even better support for configuration. + \item Provides nice menu interfaces. \end{itemize} \end{frame} \begin{frame}{others} \begin{itemize} - \item others + \item cmake + \item scons + \item bazel + \item ant + \item maven + \item gradle \end{itemize} \end{frame} diff --git a/cc/elf.svg b/cc/elf.svg new file mode 100644 index 0000000..535e958 --- /dev/null +++ b/cc/elf.svg @@ -0,0 +1,340 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + .data + .rodata + .text + Program header table + ELF header + Section header table + + + + + + + + + + + + + ⎧⎪⎨⎪⎩ + ⎧⎨⎩ + diff --git a/cc/makefile b/cc/makefile index ae699e6..7ce937e 100644 --- a/cc/makefile +++ b/cc/makefile @@ -1,5 +1,8 @@ -build: +build: elf.pdf runlatex cc.tex +%.pdf: %.svg + inkscape --export-pdf=$@ $< + clean: rm -f *.aux *.log *.nav *.out *.pdf *.snm *.toc *.vrb diff --git a/cc/source/hello.c b/cc/source/hello.c new file mode 100644 index 0000000..099e13c --- /dev/null +++ b/cc/source/hello.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + printf("hello, sfvlug!\n"); + return 0; +} diff --git a/cc/source/makefile b/cc/source/makefile new file mode 100644 index 0000000..ce76496 --- /dev/null +++ b/cc/source/makefile @@ -0,0 +1,15 @@ +CC = gcc +LD = ld +CFLAGS = -Wall -g -static + +default: hello syscall + +syscall: syscall.c makefile + $(CC) $(CFLAGS) -c -o syscall.o syscall.c + $(LD) -static -o syscall syscall.o -lc + +hello: %: %.o + $(CC) $(CFLAGS) -o $@ $+ + +%.o: %.c makefile + $(CC) $(CFLAGS) -c -o $@ $< diff --git a/cc/source/syscall.c b/cc/source/syscall.c new file mode 100644 index 0000000..63a2b58 --- /dev/null +++ b/cc/source/syscall.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include + +void _start() +{ + syscall(SYS_write, 0, "hello, world!\n", 14); + syscall(SYS_exit, 0); +}