September 2007 Archives
2007-09-27
GraphViz
Some notes on the great GraphViz package
Visualize a build dependency tree
maketograph.py
#! /usr/bin/python
import sys
import re
sys.stdout.write("digraph Makefile {\n")
regex = re.compile("^([^:]+): (.+)$")
for line in sys.stdin.read().split('\n'):
mo = regex.match(line)
if mo:
origin = mo.group(1)
targets = mo.group(2).split()
for target in targets:
sys.stdout.write('\t"%s" -> "%s";\n' % (target, origin))
sys.stdout.write("}")
the Makefile (compare to my last post)
all: main main2
main: main.c libhello.so
gcc -o $@ $< -L. -lhello
main2: main2.c libhello.so
gcc -o $@ $< -ldl
hello.o: hello.c hello.h
gcc -c -fPIC $<
libhello.so: hello.o
gcc -shared -o $@ $<
clean:
rm -fr libhello.so main *.o
creating the graph
$ ./maketograph.py < Makefile > Makefile.dot $ dot -Tpng Makefile.dot >| Makefile.png
The result:
further
- egypt - create call graph from gcc RTL dump
2007-09-27
libraries
Here are some notes on building an using libraries in their different flavours on POSIX systems.
the library
hello.htypedef void (*HelloFunc)(); void hello();
hello.c
#include <stdio.h>
#include "hello.h"
void hello()
{
printf("hello world\n");
}
building the library:
gcc -fPIC -c hello.c gcc -shared -o libhello.o hello.o
binding on load time
main.c
#include "hello.h"
int main()
{
hello();
return 0;
}
building main
gcc -o main main.c -L. -lhello
running main
$ LD_LIBRARY_PATH=. ./main hello world
binding on run time
main2.c
#include <dlfcn.h>
#include <stdio.h>
#include "hello.h"
int main()
{
void* handle = dlopen("./libhello.so", RTLD_NOW);
if (handle == NULL) {
printf("dlopen failed: %s\n", dlerror());
return 1;
}
void* symbol = dlsym(handle, "hello");
if (symbol == NULL) {
printf("dlsym failed: %s\n", dlerror());
return 1;
}
HelloFunc helloFunc = (HelloFunc) symbol;
helloFunc();
if (dlclose(handle) != 0) {
printf("dlclose failed: %s\n", dlerror());
return 1;
}
return 0;
}
building main
gcc -o main2 main2.c -ldl
running main
$ ./main2 hello world
static binding
building the library
gcc -c hello.c ar rc libhello.a hello.o ranlib libhello.a
building main
gcc -o main main.o libhello.a
running main
$ ./main hello world
further reading
tools:
- ldd - print shared library dependencies
- nm - list symbols from object files
- objdump - display information from object files
- readelf - Displays information about ELF files
More on libraries can be found here.
Update: Ian Lance Taylor has written a series of 20 articles on linkers and the ELF format. Here is the first one.
2007-09-27
Multiprozessoren und Multithreading
2007-09-10
Multiprozessoren und Multithreading
Den selben Vortrag habe ich wieder mit Markus zusammen auf der Chaos Singularity 08 gehalten.
2007-09-08
Earthlings
Ich hab kein ethisches Problem damit, Fleisch zu essen. Der laut dieser Dokumentation übliche Umgang mit den betroffenen Tieren zur Profitmaximierung stellt mich allerdings vor die Wahl, auf Fleisch und andere Tierprodukte zu verzichten, wenn deren Herkunft und die Umstände der Erzeugung unklar sind.
Diese Dokumentation prägt den Begriff des "Spezisismus", der analog zum Rassismus oder Sexismus die Geringschätzung und damit den Umgang des Menschen mit anderen Spezien dieser Erde beschreibt. Eine traurige Wahrheit über die Natur des Menschen. Seht selbst...