September 2007 Archives

2007-09-30

Freiheit statt Angst


Posted by Alexander Bernauer | Permanent link | File under: /dev/radio

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:
the Makefile graph

further

  • egypt - create call graph from gcc RTL dump


Posted by Alexander Bernauer | Permanent link | File under: Notes

2007-09-27

libraries

Here are some notes on building an using libraries in their different flavours on POSIX systems.

the library

hello.h
typedef 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.


Posted by Alexander Bernauer | Permanent link | File under: Notes

2007-09-27

Multiprozessoren und Multithreading

Eine Radiosendung über das Chaos Seminar zum Thema Multiprozessoren und Multithreading.

Posted by Alexander Bernauer | Permanent link | File under: /dev/radio

2007-09-10

Multiprozessoren und Multithreading

Vortrag mit Markus Schaber beim CCC Ulm über Multiprozessoren und Multithreading.
Den selben Vortrag habe ich wieder mit Markus zusammen auf der Chaos Singularity 08 gehalten.

Posted by Alexander Bernauer | Permanent link | File under: Vortrag

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...


Posted by Alexander Bernauer | Permanent link | File under: sonstiges

2007-09-08

Cybermentor

Eine Radiosendung über das Cybermentor Projekt an der Uni Ulm.

Posted by Alexander Bernauer | Permanent link | File under: /dev/radio