Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/Makefile	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -41,12 +41,23 @@
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 
+LINKER_SCRIPTS = \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld \
+	$(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
+
 PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
-EXTRA_OUTPUT = $(LINKER_SCRIPT)
-EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPT)
+EXTRA_OUTPUT = $(LINKER_SCRIPTS)
+EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPTS)
 LIBRARY = libc
+SLIBRARY = libc.so.0.0
+LSONAME = libc.so0
+
 
 -include $(COMMON_MAKEFILE)
 -include $(CONFIG_MAKEFILE)
 -include arch/$(UARCH)/Makefile.inc
+
+EXTRA_CFLAGS += -I../../srv/loader/include
 
 GENERIC_SOURCES = \
@@ -98,4 +109,5 @@
 	generic/adt/measured_strings.c \
 	generic/adt/char_map.c \
+	generic/adt/prodcons.c \
 	generic/time.c \
 	generic/stdlib.c \
@@ -114,5 +126,16 @@
 	generic/arg_parse.c \
 	generic/sort.c \
-	generic/stats.c
+	generic/stats.c \
+	generic/assert.c
+
+ifeq ($(CONFIG_RTLD), y)
+	GENERIC_SOURCES += \
+		generic/dlfcn.c \
+		generic/rtld/rtld.c \
+		generic/rtld/elf_load.c \
+		generic/rtld/dynamic.c \
+		generic/rtld/module.c \
+		generic/rtld/symbol.c
+endif
 
 SOURCES = \
@@ -133,6 +156,15 @@
 	ln -sfn ../$< $@
 
-$(LINKER_SCRIPT): $(LINKER_SCRIPT).in
+$(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
 	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DLOADER -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-shlib.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DSHLIB -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
+	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -DDLEXE -E -x c $< | grep -v "^\#" > $@
 
 $(COMMON_HEADER_ARCH): $(COMMON_HEADER)
Index: uspace/lib/c/arch/abs32le/Makefile.inc
===================================================================
--- uspace/lib/c/arch/abs32le/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/abs32le/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.c \
+	arch/$(UARCH)/src/entryjmp.c \
 	arch/$(UARCH)/src/thread_entry.c \
 	arch/$(UARCH)/src/fibril.c \
Index: uspace/lib/c/arch/abs32le/_link.ld.in
===================================================================
--- uspace/lib/c/arch/abs32le/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/abs32le/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.text : {
 		*(.text .text.*);
Index: uspace/lib/c/arch/abs32le/src/entryjmp.c
===================================================================
--- uspace/lib/c/arch/abs32le/src/entryjmp.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/abs32le/src/entryjmp.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <bool.h>
+#include <entry_point.h>
+
+/** Jump to program entry point. */
+void entry_point_jmp(void *entry_point, void *pcb)
+{
+	while (true);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/c/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/amd64/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
Index: uspace/lib/c/arch/amd64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/amd64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/amd64/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,5 +3,10 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 	debug PT_NOTE;
@@ -9,6 +14,13 @@
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/amd64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/amd64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/amd64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %rdi	contains entry_point
+# %rsi	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# pcb must be passed in %rdi, use %rdx as a scratch register
+	mov %rdi, %rdx
+	mov %rsi, %rdi
+
+	# jump to entry point
+	jmp %rdx
Index: uspace/lib/c/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/arm32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/arm32/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -30,4 +30,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/arm32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/arm32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/arm32/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/arm32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/arm32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/arm32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# r0	contains entry_point
+# r1	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# load ras_page address to r2
+	ldr r2, =ras_page
+	ldr r2, [r2]
+	# pcb is passed to the entry point in r1 (where it already is)
+	mov r15, r0
Index: uspace/lib/c/arch/ia32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.common	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/Makefile.common	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -28,5 +28,5 @@
 
 CLANG_ARCH = i386
-GCC_CFLAGS += -march=pentium
+GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
@@ -35,5 +36,7 @@
 	arch/$(UARCH)/src/setjmp.S \
 	arch/$(UARCH)/src/stacktrace.c \
-	arch/$(UARCH)/src/stacktrace_asm.S
+	arch/$(UARCH)/src/stacktrace_asm.S \
+	arch/$(UARCH)/src/rtld/dynamic.c \
+	arch/$(UARCH)/src/rtld/reloc.c
 
 .PRECIOUS: arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ia32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -1,14 +1,32 @@
+#ifndef SHLIB
 STARTUP(LIBC_PATH/arch/UARCH/src/entry.o)
 ENTRY(__entry)
+#endif
 
 PHDRS {
+#if defined(LOADER) || defined(DLEXE)
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
+#if defined(SHLIB) || defined(DLEXE)
+	dynamic PT_DYNAMIC;
+#endif
 	debug PT_NOTE;
 }
 
 SECTIONS {
+#if defined(LOADER) || defined(DLEXE)
+	.interp : {
+		*(.interp);
+	} :interp
+#endif
+#ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
@@ -19,6 +37,40 @@
 		*(.rodata .rodata.*);
 	} :text
+
+#if defined(SHLIB) || defined(DLEXE)
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
 	
+	.plt : {
+		*(.plt);
+	} :text
+	
+	.dynsym : {
+		*(.dynsym);
+	} :text
+	
+	.dynstr : {
+		*(.dynstr);
+	} :text
+	
+	.hash : {
+		*(.hash);
+	} :text
+#endif
 	. = . + 0x1000;
+	
+#if defined(SHLIB) || defined(DLEXE)
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+#endif
 	
 	.data : {
@@ -26,4 +78,18 @@
 	} :data
 	
+#if defined(SHLIB) || defined(DLEXE)
+	.data.rel : {
+                *(.data.rel .data.rel.*);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+#endif
+	
+#ifndef DLEXE
 	.tdata : {
 		_tdata_start = .;
@@ -37,6 +103,8 @@
 	
 	_tls_alignment = ALIGNOF(.tdata);
+#endif
 	
 	.bss : {
+		*(.dynbss);
 		*(COMMON);
 		*(.bss);
Index: uspace/lib/c/arch/ia32/include/config.h
===================================================================
--- uspace/lib/c/arch/ia32/include/config.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/config.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -36,6 +36,9 @@
 #define LIBC_ia32_CONFIG_H_
 
-#define PAGE_WIDTH	12
-#define PAGE_SIZE	(1 << PAGE_WIDTH)
+#define PAGE_WIDTH  12
+#define PAGE_SIZE   (1 << PAGE_WIDTH)
+
+#define USER_ADDRESS_SPACE_START_ARCH  UINT32_C(0x00000000)
+#define USER_ADDRESS_SPACE_END_ARCH    UINT32_C(0x7fffffff)
 
 #endif
Index: uspace/lib/c/arch/ia32/include/ddi.h
===================================================================
--- uspace/lib/c/arch/ia32/include/ddi.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/ddi.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -37,5 +37,5 @@
 #include <libarch/types.h>
 
-#define IO_SPACE_BOUNDARY	((void *) (64 * 1024))
+#define IO_SPACE_BOUNDARY  ((void *) (64 * 1024))
 
 static inline uint8_t pio_read_8(ioport8_t *port)
Index: uspace/lib/c/arch/ia32/include/faddr.h
===================================================================
--- uspace/lib/c/arch/ia32/include/faddr.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/faddr.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -38,5 +38,5 @@
 #include <libarch/types.h>
 
-#define FADDR(fptr)		((uintptr_t) (fptr))
+#define FADDR(fptr)  ((uintptr_t) (fptr))
 
 #endif
Index: uspace/lib/c/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia32/include/fibril.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/include/fibril.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -42,5 +42,5 @@
  * panic sooner or later
  */
-#define SP_DELTA     (12)
+#define SP_DELTA  12
 
 #define context_set(c, _pc, stack, size, ptls) \
@@ -51,6 +51,7 @@
 		(c)->ebp = 0; \
 	} while (0)
-	
-/* We include only registers that must be preserved
+
+/*
+ * We include only registers that must be preserved
  * during function call
  */
Index: uspace/lib/c/arch/ia32/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32_RTLD_DYNAMIC_H_
+#define LIBC_ia32_RTLD_DYNAMIC_H_
+
+#include <sys/types.h>
+
+typedef struct {
+	/* Empty. */
+} dyn_info_arch_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32_RTLD_ELF_DYN_H_
+#define LIBC_ia32_RTLD_ELF_DYN_H_
+
+/* 
+ * ia32 dynamic relocation types
+ */
+
+#define R_386_32	1
+#define R_386_PC32	2
+#define R_386_COPY	5
+#define R_386_GLOB_DAT	6
+#define R_386_JUMP_SLOT	7
+#define R_386_RELATIVE	8
+
+#define R_386_TLS_DTPMOD32 35
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ia32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Use standard ia32 prologue not to confuse anybody
+	push %ebp
+	movl %esp, %ebp
+
+	# %eax := entry_point
+	movl 0x8(%ebp), %eax
+
+	# %edi := pcb
+	# pcb is passed to the entry point in %edi
+	mov 0xc(%ebp), %edi
+
+	# Save a tiny bit of stack space
+	pop %ebp
+
+	jmp *%eax
Index: uspace/lib/c/arch/ia32/src/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @brief
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rtld/elf_dyn.h>
+#include <rtld/dynamic.h>
+
+void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info)
+{
+	(void) dp;
+	(void) bias;
+	(void) info;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @brief
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libarch/rtld/elf_dyn.h>
+#include <rtld/symbol.h>
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/rtld_arch.h>
+
+void module_process_pre_arch(module_t *m)
+{
+	/* Unused */
+}
+
+
+/**
+ * Process (fixup) all relocations in a relocation table.
+ */
+void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
+{
+	unsigned i;
+
+	size_t rt_entries;
+	size_t r_offset;
+	elf_word r_info;
+	unsigned rel_type;
+	elf_word sym_idx;
+	uint32_t sym_addr;
+	
+	elf_symbol_t *sym_table;
+	elf_symbol_t *sym;
+	uint32_t *r_ptr;
+	uint32_t sym_size;
+	char *str_tab;
+	
+	elf_symbol_t *sym_def;
+	module_t *dest;
+
+	DPRINTF("parse relocation table\n");
+
+	sym_table = m->dyn.sym_tab;
+	rt_entries = rt_size / sizeof(elf_rel_t);
+	str_tab = m->dyn.str_tab;
+
+	DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
+	
+	for (i = 0; i < rt_entries; ++i) {
+//		DPRINTF("symbol %d: ", i);
+		r_offset = rt[i].r_offset;
+		r_info = rt[i].r_info;
+
+		sym_idx = ELF32_R_SYM(r_info);
+		sym = &sym_table[sym_idx];
+
+/*		DPRINTF("name '%s', value 0x%x, size 0x%x\n",
+		    str_tab + sym->st_name,
+		    sym->st_value,
+		    sym->st_size);
+*/
+		rel_type = ELF32_R_TYPE(r_info);
+		r_ptr = (uint32_t *)(r_offset + m->bias);
+
+		if (sym->st_name != 0) {
+//			DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
+			sym_def = symbol_def_find(str_tab + sym->st_name,
+			    m, &dest);
+//			DPRINTF("dest name: '%s'\n", dest->dyn.soname);
+//			DPRINTF("dest bias: 0x%x\n", dest->bias);
+			if (sym_def) {
+				sym_addr = (uint32_t)
+				    symbol_get_addr(sym_def, dest);
+//				DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
+			} else {
+				printf("Definition of '%s' not found.\n",
+				    str_tab + sym->st_name);
+				continue;
+			}
+		} else {
+			sym_addr = 0;
+			sym_def = NULL;
+		}
+
+		switch (rel_type) {
+		case R_386_GLOB_DAT:
+		case R_386_JUMP_SLOT:
+			DPRINTF("fixup R_386_GLOB_DAT/JUMP_SLOT (b+v)\n");
+			*r_ptr = sym_addr;
+			break;
+
+		case R_386_32:
+			DPRINTF("fixup R_386_32 (b+v+a)\n");
+			*r_ptr += sym_addr;
+			break;
+
+		case R_386_PC32:
+			DPRINTF("fixup R_386_PC32 (b+v+a-p)\n");
+			*r_ptr += sym_addr - (uint32_t) r_ptr;
+			break;
+
+		case R_386_COPY:
+			/*
+			 * Copy symbol data from shared object to specified
+			 * location.
+			 */
+			DPRINTF("fixup R_386_COPY (s)\n");
+			sym_size = sym->st_size;
+			if (sym_size != sym_def->st_size) {
+				printf("Warning: Mismatched symbol sizes.\n");
+				/* Take the lower value. */
+				if (sym_size > sym_def->st_size)
+					sym_size = sym_def->st_size;
+			}
+			memcpy(r_ptr, (const void *)sym_addr, sym_size);
+			break;
+			
+		case R_386_RELATIVE:
+			DPRINTF("fixup R_386_RELATIVE (b+a)\n");
+			*r_ptr += m->bias;
+			break;
+
+		case R_386_TLS_DTPMOD32:
+			/*
+			 * We can ignore this as long as the only module
+			 * with TLS variables is libc.so.
+			 */
+			DPRINTF("Ignoring R_386_TLS_DTPMOD32\n");
+			break;
+
+		default:
+			printf("Error: Unknown relocation type %d\n",
+			    rel_type);
+			exit(1);
+		}
+
+	}
+
+}
+
+void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size)
+{
+	/* Unused */
+	(void)m; (void)rt; (void)rt_size;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/stacktrace.c
===================================================================
--- uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/stacktrace.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -35,16 +35,16 @@
  */
 
+#include <libarch/config.h>
 #include <sys/types.h>
 #include <bool.h>
-
 #include <stacktrace.h>
 
-#define FRAME_OFFSET_FP_PREV	0
-#define FRAME_OFFSET_RA		4
+#define FRAME_OFFSET_FP_PREV  0
+#define FRAME_OFFSET_RA       4
 
 bool stacktrace_fp_valid(stacktrace_t *st, uintptr_t fp)
 {
 	(void) st;
-	return fp != 0;
+	return (fp != 0) && (fp <= USER_ADDRESS_SPACE_END_ARCH);
 }
 
Index: uspace/lib/c/arch/ia32/src/syscall.S
===================================================================
--- uspace/lib/c/arch/ia32/src/syscall.S	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/syscall.S	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -32,4 +32,5 @@
 __syscall_fast_func:
 	.long __syscall_slow
+	.size __syscall_fast_func, . - __syscall_fast_func
 
 .text
@@ -71,4 +72,6 @@
  */
 .global __syscall_fast
+	.type __syscall_fast, @function
+
 __syscall_fast:
 	pushl %ebx
@@ -95,2 +98,4 @@
 	popl %ebx
 	ret
+
+	.size __syscall_fast, . - __syscall_fast
Index: uspace/lib/c/arch/ia32/src/tls.c
===================================================================
--- uspace/lib/c/arch/ia32/src/tls.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia32/src/tls.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -37,4 +37,5 @@
 #include <tls.h>
 #include <sys/types.h>
+#include <align.h>
 
 tcb_t * __alloc_tls(void **data, size_t size)
@@ -48,4 +49,31 @@
 }
 
+/*
+ * Rtld TLS support
+ */
+
+typedef struct {
+	unsigned long int ti_module;
+	unsigned long int ti_offset;
+} tls_index;
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti);
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti)
+{
+	size_t tls_size;
+	uint8_t *tls;
+
+	/* Calculate size of TLS block */
+	tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment);
+
+	/* The TLS block is just before TCB */
+	tls = (uint8_t *)__tcb_get() - tls_size;
+
+	return tls + ti->ti_offset;
+}
+
 /** @}
  */
Index: uspace/lib/c/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.S \
Index: uspace/lib/c/arch/ia64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,29 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
 	text PT_LOAD FLAGS(5);
+#else
+	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x800000000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
+	/*
+	 * XXX This is just a work around. Problem: .init section does not
+	 * have the proper alignment.
+	 */
+	. = ALIGN(., 16);
+
 	.init : {
 		*(.init);
@@ -22,5 +40,6 @@
 	
 	.got : {
-		_gp = .;
+		/* Tell the linker where we expect GP to point. */
+		__gp = .;
 		*(.got .got.*);
 	} :data
Index: uspace/lib/c/arch/ia64/src/entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entry.s	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/src/entry.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -39,5 +39,5 @@
 __entry:
 	alloc loc0 = ar.pfs, 0, 1, 2, 0
-	movl gp = _gp
+	movl gp = __gp
 	
 	# Pass PCB pointer as the first argument to __main
Index: uspace/lib/c/arch/ia64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ia64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ia64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# in0 (r32)	contains entry_point
+# in1 (r33)	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Pass pcb to the entry point in r2
+
+	mov b6 = r32
+	mov r2 = r33 ;;
+	br b6 ;;
Index: uspace/lib/c/arch/ia64/src/thread_entry.s
===================================================================
--- uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ia64/src/thread_entry.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -37,5 +37,5 @@
 	alloc loc0 = ar.pfs, 0, 1, 1, 0
 
-	movl gp = _gp
+	movl gp = __gp
 	
 	#
Index: uspace/lib/c/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/mips32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/mips32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70004000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/mips32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/mips32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/mips32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.text
+.section .text
+.global entry_point_jmp
+.set noreorder
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# $a0 (=$4)	contains entry_point
+# $a1 (=$5)	contains pcb
+#
+# Jump to program entry point
+.ent entry_point_jmp
+entry_point_jmp:
+	# tmp := entry_point
+	move $25, $a0
+
+	# Pass pcb to the entry point in $a0
+	move $a0, $a1
+	jr $25
+	nop
+.end
Index: uspace/lib/c/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ppc32/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ppc32/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/syscall.c \
Index: uspace/lib/c/arch/ppc32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ppc32/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/ppc32/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
 	. = 0x1000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/ppc32/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/ppc32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/ppc32/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %r3	contains entry_point
+# %r4	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	mtctr %r3
+	mr %r6, %r4	# Pass pcb to the entry point in %r6
+	bctr
Index: uspace/lib/c/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/sparc64/Makefile.inc	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/sparc64/Makefile.inc	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -29,4 +29,5 @@
 ARCH_SOURCES = \
 	arch/$(UARCH)/src/entry.s \
+	arch/$(UARCH)/src/entryjmp.s \
 	arch/$(UARCH)/src/thread_entry.s \
 	arch/$(UARCH)/src/fibril.S \
Index: uspace/lib/c/arch/sparc64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/sparc64/_link.ld.in	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/arch/sparc64/_link.ld.in	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -3,11 +3,23 @@
 
 PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
 	text PT_LOAD FLAGS(5);
+#endif
 	data PT_LOAD FLAGS(6);
 }
 
 SECTIONS {
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp
+	
+	. = 0x70004000 + SIZEOF_HEADERS;
+#else
 	. = 0x4000 + SIZEOF_HEADERS;
-	
+#endif
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/sparc64/src/entryjmp.s
===================================================================
--- uspace/lib/c/arch/sparc64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/arch/sparc64/src/entryjmp.s	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+.globl entry_point_jmp
+
+## void entry_point_jmp(void *entry_point, void *pcb);
+#
+# %o0	contains entry_point
+# %o1	contains pcb
+#
+# Jump to program entry point
+entry_point_jmp:
+	# Pass pcb pointer to entry point in %o1. As it is already
+	# there, no action is needed.
+	call %o0
+	nop
+	# fixme: use branch instead of call
Index: uspace/lib/c/generic/adt/prodcons.c
===================================================================
--- uspace/lib/c/generic/adt/prodcons.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/adt/prodcons.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <adt/prodcons.h>
+#include <adt/list.h>
+#include <fibril_synch.h>
+
+void prodcons_initialize(prodcons_t *pc)
+{
+	list_initialize(&pc->list);
+	fibril_mutex_initialize(&pc->mtx);
+	fibril_condvar_initialize(&pc->cv);
+}
+
+void prodcons_produce(prodcons_t *pc, link_t *item)
+{
+	fibril_mutex_lock(&pc->mtx);
+	
+	list_append(item, &pc->list);
+	fibril_condvar_signal(&pc->cv);
+	
+	fibril_mutex_unlock(&pc->mtx);
+}
+
+link_t *prodcons_consume(prodcons_t *pc)
+{
+	fibril_mutex_lock(&pc->mtx);
+	
+	while (list_empty(&pc->list))
+		fibril_condvar_wait(&pc->cv, &pc->mtx);
+	
+	link_t *head = pc->list.next;
+	list_remove(head);
+	
+	fibril_mutex_unlock(&pc->mtx);
+	
+	return head;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/as.c
===================================================================
--- uspace/lib/c/generic/as.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/as.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -52,5 +52,5 @@
  *
  */
-void *as_area_create(void *address, size_t size, int flags)
+void *as_area_create(void *address, size_t size, unsigned int flags)
 {
 	return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
@@ -68,5 +68,5 @@
  *
  */
-int as_area_resize(void *address, size_t size, int flags)
+int as_area_resize(void *address, size_t size, unsigned int flags)
 {
 	return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
@@ -96,5 +96,5 @@
  *
  */
-int as_area_change_flags(void *address, int flags)
+int as_area_change_flags(void *address, unsigned int flags)
 {
 	return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
Index: uspace/lib/c/generic/assert.c
===================================================================
--- uspace/lib/c/generic/assert.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/assert.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stacktrace.h>
+
+void assert_abort(const char *cond, const char *file, unsigned int line)
+{
+	printf("Assertion failed (%s) in file \"%s\", line %u.\n",
+	    cond, file, line);
+	stacktrace_print();
+	abort();
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/async.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -102,4 +102,6 @@
 #include <arch/barrier.h>
 #include <bool.h>
+#include <stdlib.h>
+#include <malloc.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/async_sess.c
===================================================================
--- uspace/lib/c/generic/async_sess.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/async_sess.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -105,4 +105,5 @@
 #include <errno.h>
 #include <assert.h>
+#include <async.h>
 #include "private/async_sess.h"
 
Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/dlfcn.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#include <rtld/module.h>
+#include <rtld/symbol.h>
+
+void *dlopen(const char *path, int flag)
+{
+	module_t *m;
+
+	if (runtime_env == NULL) {
+		printf("Dynamic linker not set up -- initializing.\n");
+		rtld_init_static();
+	}
+
+	printf("dlopen(\"%s\", %d)\n", path, flag);
+
+	printf("module_find('%s')\n", path);
+	m = module_find(path);
+	if (m == NULL) {
+		printf("NULL. module_load('%s')\n", path);
+		m = module_load(path);
+		printf("module_load_deps(m)\n");
+		module_load_deps(m);
+		/* Now relocate. */
+		printf("module_process_relocs(m)\n");
+		module_process_relocs(m);
+	} else {
+		printf("not NULL\n");
+	}
+
+	return (void *) m;
+}
+
+/*
+ * @note Symbols with NULL values are not accounted for.
+ */
+void *dlsym(void *mod, const char *sym_name)
+{
+	elf_symbol_t *sd;
+	module_t *sm;
+
+	printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
+	sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
+	if (sd != NULL) {
+		return symbol_get_addr(sd, sm);
+	}
+
+	return NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/errno.c
===================================================================
--- uspace/lib/c/generic/errno.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/errno.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -36,5 +36,10 @@
 #include <fibril.h>
 
-int _errno;
+static fibril_local int fibril_errno;
+
+int *__errno(void)
+{
+	return &fibril_errno;
+}
 
 /** @}
Index: uspace/lib/c/generic/event.c
===================================================================
--- uspace/lib/c/generic/event.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/event.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -41,14 +41,28 @@
 #include <kernel/ipc/event_types.h>
 
-/** Subscribe for event notifications.
+/** Subscribe event notifications.
  *
- * @param evno   Event number.
- * @param method Use this method for notifying me.
+ * @param evno    Event type to subscribe.
+ * @param imethod Use this interface and method for notifying me.
  *
  * @return Value returned by the kernel.
+ *
  */
-int event_subscribe(event_type_t e, sysarg_t method)
+int event_subscribe(event_type_t evno, sysarg_t imethod)
 {
-	return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) e, (sysarg_t) method);
+	return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno,
+	    (sysarg_t) imethod);
+}
+
+/** Unmask event notifications.
+ *
+ * @param evno Event type to unmask.
+ *
+ * @return Value returned by the kernel.
+ *
+ */
+int event_unmask(event_type_t evno)
+{
+	return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno);
 }
 
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -43,4 +43,5 @@
 #include <stacktrace.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include "private/async.h"
 
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/io/io.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -173,4 +173,5 @@
 		}
 		*flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY);
+		break;
 	default:
 		errno = EINVAL;
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/libc.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -53,4 +53,8 @@
 #include "private/io.h"
 
+#ifdef CONFIG_RTLD
+#include <rtld/rtld.h>
+#endif
+
 static bool env_setup = false;
 
@@ -77,4 +81,9 @@
 	char **argv;
 	
+#ifdef __IN_SHARED_LIBC__
+	if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
+		runtime_env = (runtime_env_t *) __pcb->rtld_runtime;
+	}
+#endif
 	/*
 	 * Get command line arguments and initialize
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/malloc.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -44,4 +44,5 @@
 #include <mem.h>
 #include <futex.h>
+#include <stdlib.h>
 #include <adt/gcdlcm.h>
 #include "private/malloc.h"
Index: uspace/lib/c/generic/rtld/dynamic.c
===================================================================
--- uspace/lib/c/generic/rtld/dynamic.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/rtld/dynamic.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+
+#include <rtld/elf_dyn.h>
+#include <rtld/dynamic.h>
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+
+void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
+{
+	elf_dyn_t *dp = dyn_ptr;
+
+	void *d_ptr;
+	elf_word d_val;
+
+	elf_word soname_idx;
+	elf_word rpath_idx;
+
+	DPRINTF("memset\n");
+	memset(info, 0, sizeof(dyn_info_t));
+
+	soname_idx = 0;
+	rpath_idx = 0;
+
+	DPRINTF("pass 1\n");
+	while (dp->d_tag != DT_NULL) {
+		d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
+		d_val = dp->d_un.d_val;
+		DPRINTF("tag=%u ptr=0x%x val=%u\n", (unsigned)dp->d_tag,
+			(unsigned)d_ptr, (unsigned)d_val);
+
+		switch (dp->d_tag) {
+
+		case DT_PLTRELSZ:	info->plt_rel_sz = d_val; break;
+		case DT_PLTGOT:		info->plt_got = d_ptr; break;
+		case DT_HASH:		info->hash = d_ptr; break;
+		case DT_STRTAB:		info->str_tab = d_ptr; break;
+		case DT_SYMTAB:		info->sym_tab = d_ptr; break;
+		case DT_RELA:		info->rela = d_ptr; break;
+		case DT_RELASZ:		info->rela_sz = d_val; break;
+		case DT_RELAENT:	info->rela_ent = d_val; break;
+		case DT_STRSZ:		info->str_sz = d_val; break;
+		case DT_SYMENT:		info->sym_ent = d_val; break;
+		case DT_INIT:		info->init = d_ptr; break;
+		case DT_FINI:		info->fini = d_ptr; break;
+		case DT_SONAME:		soname_idx = d_val; break;
+		case DT_RPATH:		rpath_idx = d_val; break;
+		case DT_SYMBOLIC:	info->symbolic = true; break;
+		case DT_REL:		info->rel = d_ptr; break;
+		case DT_RELSZ:		info->rel_sz = d_val; break;
+		case DT_RELENT:		info->rel_ent = d_val; break;
+		case DT_PLTREL:		info->plt_rel = d_val; break;
+		case DT_TEXTREL:	info->text_rel = true; break;
+		case DT_JMPREL:		info->jmp_rel = d_ptr; break;
+		case DT_BIND_NOW:	info->bind_now = true; break;
+
+		default:
+			if (dp->d_tag >= DT_LOPROC && dp->d_tag <= DT_HIPROC)
+				dyn_parse_arch(dp, bias, info);
+			break;
+		}
+
+		++dp;
+	}
+
+	info->soname = info->str_tab + soname_idx;
+	info->rpath = info->str_tab + rpath_idx;
+
+	/* This will be useful for parsing dependencies later */
+	info->dynamic = dyn_ptr;
+
+	DPRINTF("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n",
+		(uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname);
+	DPRINTF("soname='%s'\n", info->soname);
+	DPRINTF("rpath='%s'\n", info->rpath);
+	DPRINTF("hash=0x%x\n", (uintptr_t)info->hash);
+	DPRINTF("dt_rela=0x%x\n", (uintptr_t)info->rela);
+	DPRINTF("dt_rela_sz=0x%x\n", (uintptr_t)info->rela_sz);
+	DPRINTF("dt_rel=0x%x\n", (uintptr_t)info->rel);
+	DPRINTF("dt_rel_sz=0x%x\n", (uintptr_t)info->rel_sz);
+
+	/*
+	 * Now that we have a pointer to the string table,
+	 * we can parse DT_NEEDED fields (which contain offsets into it).
+	 */
+
+	DPRINTF("pass 2\n");
+	dp = dyn_ptr;
+	while (dp->d_tag != DT_NULL) {
+		d_val = dp->d_un.d_val;
+
+		switch (dp->d_tag) {
+		case DT_NEEDED:
+			/* Assume just for now there's only one dependency */
+			info->needed = info->str_tab + d_val;
+			DPRINTF("needed:'%s'\n", info->needed);
+			break;
+
+		default: break;
+		}
+
+		++dp;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/elf_load.c
===================================================================
--- uspace/lib/c/generic/rtld/elf_load.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/rtld/elf_load.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,1 @@
+../../../../srv/loader/elf_load.c
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/rtld/module.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <adt/list.h>
+#include <loader/pcb.h>
+
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/dynamic.h>
+#include <rtld/rtld_arch.h>
+#include <rtld/module.h>
+#include <elf_load.h>
+
+/** (Eagerly) process all relocation tables in a module.
+ *
+ * Currently works as if LD_BIND_NOW was specified.
+ */
+void module_process_relocs(module_t *m)
+{
+	DPRINTF("module_process_relocs('%s')\n", m->dyn.soname);
+
+	/* Do not relocate twice. */
+	if (m->relocated) return;
+
+	module_process_pre_arch(m);
+
+	if (m->dyn.plt_rel == DT_REL) {
+		DPRINTF("table type DT_REL\n");
+		if (m->dyn.rel != NULL) {
+			DPRINTF("non-empty\n");
+			rel_table_process(m, m->dyn.rel, m->dyn.rel_sz);
+		}
+		/* FIXME: this seems wrong */
+		if (m->dyn.jmp_rel != NULL) {
+		DPRINTF("table type jmp-rel\n");
+			DPRINTF("non-empty\n");
+			rel_table_process(m, m->dyn.jmp_rel, m->dyn.plt_rel_sz);
+		}
+	} else { /* (m->dyn.plt_rel == DT_RELA) */
+		DPRINTF("table type DT_RELA\n");
+		if (m->dyn.rela != NULL) {
+			DPRINTF("non-empty\n");
+			rela_table_process(m, m->dyn.rela, m->dyn.rela_sz);
+		}
+	}
+
+	m->relocated = true;
+}
+
+/** Find module structure by soname/pathname.
+ *
+ * Used primarily to see if a module has already been loaded.
+ * Modules are compared according to their soname, i.e. possible
+ * path components are ignored.
+ */
+module_t *module_find(const char *name)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+	const char *p, *soname;
+
+	DPRINTF("module_find('%s')\n", name);
+
+	/*
+	 * If name contains slashes, treat it as a pathname and
+	 * construct soname by chopping off the path. Otherwise
+	 * treat it as soname.
+	 */
+	p = str_rchr(name, '/');
+	soname = p ? (p + 1) : name;
+
+	/* Traverse list of all modules. Not extremely fast, but simple */
+	DPRINTF("head = %p\n", head);
+	for (cur = head->next; cur != head; cur = cur->next) {
+		DPRINTF("cur = %p\n", cur);
+		m = list_get_instance(cur, module_t, modules_link);
+		if (str_cmp(m->dyn.soname, soname) == 0) {
+			return m; /* Found */
+		}
+	}
+	
+	return NULL; /* Not found */
+}
+
+#define NAME_BUF_SIZE 64
+
+/** Load a module.
+ *
+ * Currently this trivially tries to load '/<name>'.
+ */
+module_t *module_load(const char *name)
+{
+	elf_info_t info;
+	char name_buf[NAME_BUF_SIZE];
+	module_t *m;
+	int rc;
+	
+	m = malloc(sizeof(module_t));
+	if (!m) {
+		printf("malloc failed\n");
+		exit(1);
+	}
+
+	if (str_size(name) > NAME_BUF_SIZE - 2) {
+		printf("soname too long. increase NAME_BUF_SIZE\n");
+		exit(1);
+	}
+
+	/* Prepend soname with '/lib/' */
+	str_cpy(name_buf, NAME_BUF_SIZE, "/lib/");
+	str_cpy(name_buf + 5, NAME_BUF_SIZE - 5, name);
+
+	/* FIXME: need to real allocation of address space */
+	m->bias = runtime_env->next_bias;
+	runtime_env->next_bias += 0x100000;
+
+	DPRINTF("filename:'%s'\n", name_buf);
+	DPRINTF("load '%s' at 0x%x\n", name_buf, m->bias);
+
+	rc = elf_load_file(name_buf, m->bias, ELDF_RW, &info);
+	if (rc != EE_OK) {
+		printf("Failed to load '%s'\n", name_buf);
+		exit(1);
+	}
+
+	if (info.dynamic == NULL) {
+		printf("Error: '%s' is not a dynamically-linked object.\n",
+		    name_buf);
+		exit(1);
+	}
+
+	/* Pending relocation. */
+	m->relocated = false;
+
+	DPRINTF("parse dynamic section\n");
+	/* Parse ELF .dynamic section. Store info to m->dyn. */
+	dynamic_parse(info.dynamic, m->bias, &m->dyn);
+
+	/* Insert into the list of loaded modules */
+	list_append(&m->modules_link, &runtime_env->modules_head);
+
+	return m;
+}
+
+/** Load all modules on which m (transitively) depends.
+ */
+void module_load_deps(module_t *m)
+{
+	elf_dyn_t *dp;
+	char *dep_name;
+	module_t *dm;
+	size_t n, i;
+
+	DPRINTF("module_load_deps('%s')\n", m->dyn.soname);
+
+	/* Count direct dependencies */
+	
+	dp = m->dyn.dynamic;
+	n = 0;
+
+	while (dp->d_tag != DT_NULL) {
+		if (dp->d_tag == DT_NEEDED) ++n;
+		++dp;
+	}
+
+	/* Create an array of pointers to direct dependencies */
+
+	m->n_deps = n;
+
+	if (n == 0) {
+		/* There are no dependencies, so we are done. */
+		m->deps = NULL;
+		return;
+	}
+
+	m->deps = malloc(n * sizeof(module_t *));
+	if (!m->deps) {
+		printf("malloc failed\n");
+		exit(1);
+	}
+
+	i = 0; /* Current dependency index */
+	dp = m->dyn.dynamic;
+
+	while (dp->d_tag != DT_NULL) {
+		if (dp->d_tag == DT_NEEDED) {
+			dep_name = m->dyn.str_tab + dp->d_un.d_val;
+
+			DPRINTF("%s needs %s\n", m->dyn.soname, dep_name);
+			dm = module_find(dep_name);
+			if (!dm) {
+				dm = module_load(dep_name);
+				module_load_deps(dm);
+			}
+
+			/* Save into deps table */
+			m->deps[i++] = dm;
+		}
+		++dp;
+	}
+}
+
+/** Process relocations in modules.
+ *
+ * Processes relocations in @a start and all its dependencies.
+ * Modules that have already been relocated are unaffected.
+ *
+ * @param	start	The module where to start from.
+ */
+void modules_process_relocs(module_t *start)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+
+	for (cur = head->next; cur != head; cur = cur->next) {
+		m = list_get_instance(cur, module_t, modules_link);
+
+		/* Skip rtld, since it has already been processed */
+		if (m != &runtime_env->rtld) {
+			module_process_relocs(m);
+		}
+	}
+}
+
+/** Clear BFS tags of all modules.
+ */
+void modules_untag(void)
+{
+	link_t *head = &runtime_env->modules_head;
+
+	link_t *cur;
+	module_t *m;
+
+	for (cur = head->next; cur != head; cur = cur->next) {
+		m = list_get_instance(cur, module_t, modules_link);
+		m->bfs_tag = false;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/rtld.c
===================================================================
--- uspace/lib/c/generic/rtld/rtld.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <rtld/rtld.h>
+
+runtime_env_t *runtime_env;
+static runtime_env_t rt_env_static;
+
+/** Initialize the loder for use in a statically-linked binary. */
+void rtld_init_static(void)
+{
+	runtime_env = &rt_env_static;
+	list_initialize(&runtime_env->modules_head);
+	runtime_env->next_bias = 0x2000000;
+	runtime_env->program = NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/rtld/symbol.c
===================================================================
--- uspace/lib/c/generic/rtld/symbol.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/generic/rtld/symbol.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rtld/rtld.h>
+#include <rtld/rtld_debug.h>
+#include <rtld/symbol.h>
+#include <elf.h>
+
+/*
+ * Hash tables are 32-bit (elf_word) even for 64-bit ELF files.
+ */
+static elf_word elf_hash(const unsigned char *name)
+{
+	elf_word h = 0, g;
+
+	while (*name) {
+		h = (h << 4) + *name++;
+		g = h & 0xf0000000;
+		if (g != 0) h ^= g >> 24;
+		h &= ~g;
+	}
+
+	return h;
+}
+
+static elf_symbol_t *def_find_in_module(const char *name, module_t *m)
+{
+	elf_symbol_t *sym_table;
+	elf_symbol_t *s, *sym;
+	elf_word nbucket;
+	/*elf_word nchain;*/
+	elf_word i;
+	char *s_name;
+	elf_word bucket;
+
+	DPRINTF("def_find_in_module('%s', %s)\n", name, m->dyn.soname);
+
+	sym_table = m->dyn.sym_tab;
+	nbucket = m->dyn.hash[0];
+	/*nchain = m->dyn.hash[1]; XXX Use to check HT range*/
+
+	bucket = elf_hash((unsigned char *)name) % nbucket;
+	i = m->dyn.hash[2 + bucket];
+
+	sym = NULL;
+	while (i != STN_UNDEF) {
+		s = &sym_table[i];
+		s_name = m->dyn.str_tab + s->st_name;
+
+		if (str_cmp(name, s_name) == 0) {
+			sym = s;
+			break;
+		}
+
+		i = m->dyn.hash[2 + nbucket + i];
+	}
+
+	if (!sym)
+		return NULL;	/* Not found */
+
+	if (sym->st_shndx == SHN_UNDEF) {
+		/* Not a definition */
+		return NULL;
+	}
+
+	return sym; /* Found */
+}
+
+/** Find the definition of a symbol in a module and its deps.
+ *
+ * Search the module dependency graph is breadth-first, beginning
+ * from the module @a start. Thus, @start and all its dependencies
+ * get searched.
+ *
+ * @param name		Name of the symbol to search for.
+ * @param start		Module in which to start the search..
+ * @param mod		(output) Will be filled with a pointer to the module 
+ *			that contains the symbol.
+ */
+elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod)
+{
+	module_t *m, *dm;
+	elf_symbol_t *sym, *s;
+	link_t queue_head;
+	size_t i;
+
+	/*
+	 * Do a BFS using the queue_link and bfs_tag fields.
+	 * Vertices (modules) are tagged the moment they are inserted
+	 * into the queue. This prevents from visiting the same vertex
+	 * more times in case of circular dependencies.
+	 */
+
+	/* Mark all vertices (modules) as unvisited */	
+	modules_untag();
+
+	/* Insert root (the program) into the queue and tag it */
+	list_initialize(&queue_head);
+	start->bfs_tag = true;
+	list_append(&start->queue_link, &queue_head);
+
+	/* If the symbol is found, it will be stored in 'sym' */
+	sym = NULL;
+
+	/* While queue is not empty */
+	while (!list_empty(&queue_head)) {
+		/* Pop first element from the queue */
+		m = list_get_instance(queue_head.next, module_t, queue_link);
+		list_remove(&m->queue_link);
+
+		s = def_find_in_module(name, m);
+		if (s != NULL) {
+			/* Symbol found */
+			sym = s;
+			*mod = m;
+			break;
+		}
+
+		/*
+		 * Insert m's untagged dependencies into the queue
+		 * and tag them.
+		 */
+		for (i = 0; i < m->n_deps; ++i) {
+			dm = m->deps[i];
+
+			if (dm->bfs_tag == false) {
+				dm->bfs_tag = true;
+				list_append(&dm->queue_link, &queue_head);
+			}
+		}
+	}
+
+	/* Empty the queue so that we leave it in a clean state */
+	while (!list_empty(&queue_head))
+		list_remove(queue_head.next);
+
+	if (!sym) {
+		return NULL; /* Not found */
+	}
+
+	return sym; /* Symbol found */
+}
+
+
+/** Find the definition of a symbol..
+ *
+ * By definition in System V ABI, if module origin has the flag DT_SYMBOLIC,
+ * origin is searched first. Otherwise, or if the symbol hasn't been found,
+ * the module dependency graph is searched breadth-first, beginning
+ * from the executable program.
+ *
+ * @param name		Name of the symbol to search for.
+ * @param origin	Module in which the dependency originates.
+ * @param mod		(output) Will be filled with a pointer to the module 
+ *			that contains the symbol.
+ */
+elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod)
+{
+	elf_symbol_t *s;
+
+	if (origin->dyn.symbolic) {
+		/* 
+		 * Origin module has a DT_SYMBOLIC flag.
+		 * Try this module first
+		 */
+		 s = def_find_in_module(name, origin);
+		 if (s != NULL) {
+			/* Found */
+			*mod = origin;
+			return s;
+		 }
+	}
+
+	/* Not DT_SYMBOLIC or no match. Now try other locations. */
+
+	if (runtime_env->program) {
+		/* Program is dynamic -- start with program as root. */
+		return symbol_bfs_find(name, runtime_env->program, mod);
+	} else {
+		/* Program is static -- start with @a origin as root. */
+		return symbol_bfs_find(name, origin, mod);
+	}
+}
+
+void *symbol_get_addr(elf_symbol_t *sym, module_t *m)
+{
+	if (sym->st_shndx == SHN_ABS) {
+		/* Do not add bias to absolute symbols */
+		return (void *) sym->st_value;
+	} else {
+		return (void *) (sym->st_value + m->bias);
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/stacktrace.c
===================================================================
--- uspace/lib/c/generic/stacktrace.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/stacktrace.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -61,9 +61,11 @@
 	stacktrace_prepare();
 	stacktrace_print_fp_pc(stacktrace_fp_get(), stacktrace_pc_get());
+	
 	/*
 	 * Prevent the tail call optimization of the previous call by
 	 * making it a non-tail call.
 	 */
-	(void) stacktrace_fp_get();
+	
+	printf("-- end of stack trace --\n");
 }
 
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/generic/str.c	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -1215,21 +1215,21 @@
 void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
 {
-	if (val > 10000000000000000000ULL) {
-		*rv = val / 1000000000000000000ULL;
+	if (val > UINT64_C(10000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000000);
 		*suffix = 'Z';
-	} else if (val > 1000000000000000000ULL) {
-		*rv = val / 1000000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000);
 		*suffix = 'E';
-	} else if (val > 1000000000000000ULL) {
-		*rv = val / 1000000000000ULL;
+	} else if (val > UINT64_C(1000000000000000)) {
+		*rv = val / UINT64_C(1000000000000);
 		*suffix = 'T';
-	} else if (val > 1000000000000ULL) {
-		*rv = val / 1000000000ULL;
+	} else if (val > UINT64_C(1000000000000)) {
+		*rv = val / UINT64_C(1000000000);
 		*suffix = 'G';
-	} else if (val > 1000000000ULL) {
-		*rv = val / 1000000ULL;
+	} else if (val > UINT64_C(1000000000)) {
+		*rv = val / UINT64_C(1000000);
 		*suffix = 'M';
-	} else if (val > 1000000ULL) {
-		*rv = val / 1000ULL;
+	} else if (val > UINT64_C(1000000)) {
+		*rv = val / UINT64_C(1000);
 		*suffix = 'k';
 	} else {
@@ -1239,4 +1239,31 @@
 }
 
+void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
+    bool fixed)
+{
+	if (val > UINT64_C(1152921504606846976)) {
+		*rv = val / UINT64_C(1125899906842624);
+		*suffix = "EiB";
+	} else if (val > UINT64_C(1125899906842624)) {
+		*rv = val / UINT64_C(1099511627776);
+		*suffix = "TiB";
+	} else if (val > UINT64_C(1099511627776)) {
+		*rv = val / UINT64_C(1073741824);
+		*suffix = "GiB";
+	} else if (val > UINT64_C(1073741824)) {
+		*rv = val / UINT64_C(1048576);
+		*suffix = "MiB";
+	} else if (val > UINT64_C(1048576)) {
+		*rv = val / UINT64_C(1024);
+		*suffix = "KiB";
+	} else {
+		*rv = val;
+		if (fixed)
+			*suffix = "B  ";
+		else
+			*suffix = "B";
+	}
+}
+
 /** @}
  */
Index: uspace/lib/c/include/adt/fifo.h
===================================================================
--- uspace/lib/c/include/adt/fifo.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/fifo.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -51,10 +51,10 @@
 typedef unsigned long fifo_index_t;
 
-#define FIFO_CREATE_STATIC(name, t, itms)		\
-	struct {					\
-		t fifo[(itms)];				\
-		fifo_count_t items;			\
-		fifo_index_t head;			\
-		fifo_index_t tail;			\
+#define FIFO_CREATE_STATIC(name, t, itms) \
+	struct { \
+		t fifo[(itms)]; \
+		fifo_count_t items; \
+		fifo_index_t head; \
+		fifo_index_t tail; \
 	} name
 
Index: uspace/lib/c/include/adt/list.h
===================================================================
--- uspace/lib/c/include/adt/list.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/list.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -47,4 +47,5 @@
  *
  * @param name Name of the new statically allocated list.
+ *
  */
 #define LIST_INITIALIZE(name)  link_t name = { \
@@ -58,4 +59,5 @@
  *
  * @param link Pointer to link_t structure to be initialized.
+ *
  */
 static inline void link_initialize(link_t *link)
@@ -70,4 +72,5 @@
  *
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_initialize(link_t *head)
@@ -83,4 +86,5 @@
  * @param link Pointer to link_t structure to be added.
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_prepend(link_t *link, link_t *head)
@@ -98,4 +102,5 @@
  * @param link Pointer to link_t structure to be added.
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline void list_append(link_t *link, link_t *head)
@@ -123,5 +128,7 @@
  * Remove item from doubly-linked circular list.
  *
- * @param link Pointer to link_t structure to be removed from the list it is contained in.
+ * @param link Pointer to link_t structure to be removed from the list
+ *             it is contained in.
+ *
  */
 static inline void list_remove(link_t *link)
@@ -137,4 +144,5 @@
  *
  * @param head Pointer to link_t structure representing head of the list.
+ *
  */
 static inline int list_empty(link_t *head)
@@ -142,5 +150,4 @@
 	return ((head->next == head) ? 1 : 0);
 }
-
 
 /** Split or concatenate headless doubly-linked circular list
@@ -151,6 +158,9 @@
  * concatenates splitted lists and splits concatenated lists.
  *
- * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
- * @param part2 Pointer to link_t structure leading the second (half of the headless) list. 
+ * @param part1 Pointer to link_t structure leading the first
+ *              (half of the headless) list.
+ * @param part2 Pointer to link_t structure leading the second
+ *              (half of the headless) list.
+ *
  */
 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
@@ -165,11 +175,13 @@
 }
 
-
 /** Split headless doubly-linked circular list
  *
  * Split headless doubly-linked circular list.
  *
- * @param part1 Pointer to link_t structure leading the first half of the headless list.
- * @param part2 Pointer to link_t structure leading the second half of the headless list. 
+ * @param part1 Pointer to link_t structure leading
+ *              the first half of the headless list.
+ * @param part2 Pointer to link_t structure leading
+ *              the second half of the headless list.
+ *
  */
 static inline void headless_list_split(link_t *part1, link_t *part2)
@@ -182,6 +194,9 @@
  * Concatenate two headless doubly-linked circular lists.
  *
- * @param part1 Pointer to link_t structure leading the first headless list.
- * @param part2 Pointer to link_t structure leading the second headless list. 
+ * @param part1 Pointer to link_t structure leading
+ *              the first headless list.
+ * @param part2 Pointer to link_t structure leading
+ *              the second headless list.
+ *
  */
 static inline void headless_list_concat(link_t *part1, link_t *part2)
@@ -190,9 +205,14 @@
 }
 
-#define list_get_instance(link, type, member)  ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
-
-extern int list_member(const link_t *link, const link_t *head);
-extern void list_concat(link_t *head1, link_t *head2);
-extern unsigned int list_count(const link_t *link);
+#define list_get_instance(link, type, member) \
+	((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
+
+#define list_foreach(list, iterator) \
+	for (link_t *iterator = (list).next; \
+	    iterator != &(list); iterator = iterator->next)
+
+extern int list_member(const link_t *, const link_t *);
+extern void list_concat(link_t *, link_t *);
+extern unsigned int list_count(const link_t *);
 
 #endif
Index: uspace/lib/c/include/adt/measured_strings.h
===================================================================
--- uspace/lib/c/include/adt/measured_strings.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/adt/measured_strings.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -61,4 +61,5 @@
 extern measured_string_t *measured_string_create_bulk(const uint8_t *, size_t);
 extern measured_string_t *measured_string_copy(measured_string_t *);
+
 extern int measured_strings_receive(measured_string_t **, uint8_t **, size_t);
 extern int measured_strings_reply(const measured_string_t *, size_t);
Index: uspace/lib/c/include/adt/prodcons.h
===================================================================
--- uspace/lib/c/include/adt/prodcons.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/adt/prodcons.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_PRODCONS_H_
+#define LIBC_PRODCONS_H_
+
+#include <adt/list.h>
+#include <fibril_synch.h>
+
+typedef struct {
+	fibril_mutex_t mtx;
+	fibril_condvar_t cv;
+	link_t list;
+} prodcons_t;
+
+extern void prodcons_initialize(prodcons_t *);
+extern void prodcons_produce(prodcons_t *, link_t *);
+extern link_t *prodcons_consume(prodcons_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/as.h
===================================================================
--- uspace/lib/c/include/as.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/as.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -54,11 +54,11 @@
 }
 
-extern void *as_area_create(void *address, size_t size, int flags);
-extern int as_area_resize(void *address, size_t size, int flags);
-extern int as_area_change_flags(void *address, int flags);
-extern int as_area_destroy(void *address);
-extern void *set_maxheapsize(size_t mhs);
-extern void * as_get_mappable_page(size_t sz);
-extern int as_get_physical_mapping(void *address, uintptr_t *frame);
+extern void *as_area_create(void *, size_t, unsigned int);
+extern int as_area_resize(void *, size_t, unsigned int);
+extern int as_area_change_flags(void *, unsigned int);
+extern int as_area_destroy(void *);
+extern void *set_maxheapsize(size_t);
+extern void * as_get_mappable_page(size_t);
+extern int as_get_physical_mapping(void *, uintptr_t *);
 
 #endif
Index: uspace/lib/c/include/assert.h
===================================================================
--- uspace/lib/c/include/assert.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/assert.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -40,5 +40,5 @@
  *
  * If NDEBUG is not set, the assert() macro
- * evaluates expr and if it is false prints 
+ * evaluates expr and if it is false prints
  * error message and terminate program.
  *
@@ -47,16 +47,10 @@
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #ifndef NDEBUG
 
 #define assert(expr) \
 	do { \
-		if (!(expr)) { \
-			printf("Assertion failed (%s) at file '%s', " \
-			    "line %d.\n", #expr, __FILE__, __LINE__); \
-			abort(); \
-		} \
+		if (!(expr)) \
+			assert_abort(#expr, __FILE__, __LINE__); \
 	} while (0)
 
@@ -67,4 +61,7 @@
 #endif /* NDEBUG */
 
+extern void assert_abort(const char *, const char *, unsigned int)
+    __attribute__((noreturn));
+
 #endif
 
Index: uspace/lib/c/include/dlfcn.h
===================================================================
--- uspace/lib/c/include/dlfcn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/dlfcn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld
+ * @{
+ */
+/** @file
+ * @brief UNIX-like dynamic linker interface.
+ */
+
+#ifndef LIBC_DLFCN_H_
+#define LIBC_DLFCN_H_
+
+void *dlopen(const char *, int);
+void *dlsym(void *, const char *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/c/include/entry_point.h
===================================================================
--- uspace/lib/c/include/entry_point.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/entry_point.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ENTRY_POINT_H_
+#define LIBC_ENTRY_POINT_H_
+
+/* Defined in arch/ARCH/src/entryjmp.[c|s] */
+void entry_point_jmp(void *, void *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/errno.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -39,7 +39,7 @@
 #include <fibril.h>
 
-#define errno _errno
+#define errno  (*(__errno()))
 
-extern int _errno;
+extern int *__errno(void) __attribute__((const));
 
 #define EMFILE        (-18)
Index: uspace/lib/c/include/event.h
===================================================================
--- uspace/lib/c/include/event.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/event.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -39,4 +39,5 @@
 
 extern int event_subscribe(event_type_t, sysarg_t);
+extern int event_unmask(event_type_t);
 
 #endif
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/fibril.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -70,9 +70,9 @@
 	int (*func)(void *);
 	tcb_t *tcb;
-
+	
 	struct fibril *clean_after_me;
 	int retval;
 	int flags;
-
+	
 	fibril_owner_info_t *waits_for;
 } fibril_t;
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/fibril_synch.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -36,12 +36,12 @@
 #define LIBC_FIBRIL_SYNCH_H_
 
-#include <async.h>
 #include <fibril.h>
 #include <adt/list.h>
 #include <libarch/tls.h>
 #include <sys/time.h>
+#include <bool.h>
 
 typedef struct {
-	fibril_owner_info_t oi;		/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	int counter;
 	link_t waiters;
@@ -64,5 +64,5 @@
 
 typedef struct {
-	fibril_owner_info_t oi;	/* Keep this the first thing. */
+	fibril_owner_info_t oi;  /**< Keep this the first thing. */
 	unsigned writers;
 	unsigned readers;
Index: uspace/lib/c/include/loader/pcb.h
===================================================================
--- uspace/lib/c/include/loader/pcb.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/loader/pcb.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -72,4 +72,6 @@
 	/** Pointer to ELF dynamic section of the program. */
 	void *dynamic;
+	/** Pointer to dynamic linker state structure (runtime_env_t). */
+	void *rtld_runtime;
 } pcb_t;
 
Index: uspace/lib/c/include/macros.h
===================================================================
--- uspace/lib/c/include/macros.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/macros.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -39,9 +39,6 @@
 #define max(a, b)  ((a) > (b) ? (a) : (b))
 
-#define SIZE2KB(size)  ((size) >> 10)
-#define SIZE2MB(size)  ((size) >> 20)
-
-#define KB2SIZE(kb)  ((kb) << 10)
-#define MB2SIZE(mb)  ((mb) << 20)
+#define KiB2SIZE(kb)  ((kb) << 10)
+#define MiB2SIZE(mb)  ((mb) << 20)
 
 #define STRING(arg)      STRING_ARG(arg)
Index: uspace/lib/c/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/include/rtld/dynamic.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/dynamic.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_DYNAMIC_H_
+#define LIBC_RTLD_DYNAMIC_H_
+
+#include <bool.h>
+#include <rtld/elf_dyn.h>
+#include <libarch/rtld/dynamic.h>
+
+/**
+ * Holds the data extracted from an ELF Dynamic section.
+ *
+ * The data is already pre-processed: Pointers are adjusted
+ * to their final run-time values by adding the load bias
+ * and indices into the symbol table are converted to pointers.
+ */
+typedef struct dyn_info {
+	/** Type of relocations used for the PLT, either DT_REL or DT_RELA */
+	int plt_rel;
+
+	/** Relocation table without explicit addends */
+	void *rel;
+	size_t rel_sz;
+	size_t rel_ent;
+
+	/** Relocation table with explicit addends */
+	void *rela;
+	size_t rela_sz;
+	size_t rela_ent;
+
+	/** PLT relocation table */
+	void *jmp_rel;
+	size_t plt_rel_sz;
+
+	/** Pointer to PLT/GOT (processor-specific) */
+	void *plt_got;
+
+	/** Hash table */
+	elf_word *hash;
+
+	/** String table */
+	char *str_tab;
+	size_t str_sz;
+
+	/** Symbol table */
+	void *sym_tab;
+	size_t sym_ent;
+
+	void *init;		/**< Module initialization code */
+	void *fini;		/**< Module cleanup code */
+
+	const char *soname;	/**< Library identifier */
+	char *rpath;		/**< Library search path list */
+
+	bool symbolic;
+	bool text_rel;
+	bool bind_now;
+
+	/* Assume for now that there's at most one needed library */
+	char *needed;
+
+	/** Pointer to the module's dynamic section */
+	elf_dyn_t *dynamic;
+
+	/** Architecture-specific info. */
+	dyn_info_arch_t arch;
+} dyn_info_t;
+
+void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info);
+void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/include/rtld/elf_dyn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/elf_dyn.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_ELF_DYN_H_
+#define LIBC_RTLD_ELF_DYN_H_
+
+#include <arch/elf.h>
+#include <sys/types.h>
+
+#include <elf.h>
+#include <libarch/rtld/elf_dyn.h>
+
+#define ELF32_R_SYM(i) ((i)>>8)
+#define ELF32_R_TYPE(i) ((unsigned char)(i))
+
+struct elf32_dyn {
+	elf_sword d_tag;
+	union {
+		elf_word d_val;
+		elf32_addr d_ptr;
+	} d_un;
+};
+
+struct elf32_rel {
+	elf32_addr r_offset;
+	elf_word r_info;
+};
+
+struct elf32_rela {
+	elf32_addr r_offset;
+	elf_word r_info;
+	elf_sword r_addend;
+};
+
+#ifdef __32_BITS__
+typedef struct elf32_dyn elf_dyn_t;
+typedef struct elf32_rel elf_rel_t;
+typedef struct elf32_rela elf_rela_t;
+#endif
+
+/*
+ * Dynamic array tags
+ */
+#define DT_NULL		0
+#define DT_NEEDED	1
+#define DT_PLTRELSZ	2
+#define DT_PLTGOT	3
+#define DT_HASH		4
+#define DT_STRTAB	5
+#define DT_SYMTAB	6
+#define DT_RELA		7
+#define DT_RELASZ	8
+#define DT_RELAENT	9
+#define DT_STRSZ	10
+#define DT_SYMENT	11
+#define DT_INIT		12
+#define DT_FINI		13
+#define DT_SONAME	14
+#define DT_RPATH	15
+#define DT_SYMBOLIC	16
+#define DT_REL		17
+#define DT_RELSZ	18
+#define DT_RELENT	19
+#define DT_PLTREL	20
+#define DT_DEBUG	21
+#define DT_TEXTREL	22
+#define DT_JMPREL	23
+#define DT_BIND_NOW	24
+#define DT_LOPROC	0x70000000
+#define DT_HIPROC	0x7fffffff
+
+/*
+ * Special section indexes
+ */
+#define SHN_UNDEF	0
+#define SHN_LORESERVE	0xff00
+#define SHN_LOPROC	0xff00
+#define SHN_HIPROC	0xff1f
+#define SHN_ABS		0xfff1
+#define SHN_COMMON	0xfff2
+#define SHN_HIRESERVE	0xffff
+
+/*
+ * Special symbol table index
+ */
+#define STN_UNDEF	0
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/module.h
===================================================================
--- uspace/lib/c/include/rtld/module.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/module.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_MODULE_H_
+#define LIBC_RTLD_MODULE_H_
+
+#include <sys/types.h>
+#include <rtld/dynamic.h>
+#include <adt/list.h>
+
+typedef struct module {
+	dyn_info_t dyn;
+	size_t bias;
+
+	/** Array of pointers to directly dependent modules */
+	struct module **deps;
+	/** Number of fields in deps */
+	size_t n_deps;
+
+	/** True iff relocations have already been processed in this module. */
+	bool relocated;
+
+	/** Link to list of all modules in runtime environment */
+	link_t modules_link;
+
+	/** Link to BFS queue. Only used when doing a BFS of the module graph */
+	link_t queue_link;
+	/** Tag for modules already processed during a BFS */
+	bool bfs_tag;
+} module_t;
+
+void module_process_relocs(module_t *m);
+module_t *module_find(const char *name);
+module_t *module_load(const char *name);
+void module_load_deps(module_t *m);
+
+void modules_process_relocs(module_t *start);
+void modules_untag(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld.h
===================================================================
--- uspace/lib/c/include/rtld/rtld.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/rtld.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_H_
+#define LIBC_RTLD_H_
+
+#include <sys/types.h>
+#include <adt/list.h>
+
+#include <rtld/dynamic.h>
+#include <rtld/module.h>
+
+typedef struct {
+	elf_dyn_t *rtld_dynamic;
+	module_t rtld;
+
+	module_t *program;
+
+	/** List of all loaded modules including rtld and the program */
+	link_t modules_head;
+
+	/** Temporary hack to place each module at different address. */
+	uintptr_t next_bias;
+} runtime_env_t;
+
+extern runtime_env_t *runtime_env;
+
+extern void rtld_init_static(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld_arch.h
===================================================================
--- uspace/lib/c/include/rtld/rtld_arch.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/rtld_arch.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_RTLD_ARCH_H_
+#define LIBC_RTLD_RTLD_ARCH_H_
+
+#include <rtld/rtld.h>
+#include <loader/pcb.h>
+
+void module_process_pre_arch(module_t *m);
+
+void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size);
+void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size);
+
+void program_run(void *entry, pcb_t *pcb);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/rtld_debug.h
===================================================================
--- uspace/lib/c/include/rtld/rtld_debug.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/rtld_debug.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_RTLD_DEBUG_H_
+#define LIBC_RTLD_RTLD_DEBUG_H_
+
+/* Define to enable debugging mode. */
+#undef RTLD_DEBUG
+
+#ifdef RTLD_DEBUG
+	#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
+#else
+	#define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
+#endif
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/rtld/symbol.h
===================================================================
--- uspace/lib/c/include/rtld/symbol.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
+++ uspace/lib/c/include/rtld/symbol.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_RTLD_SYMBOL_H_
+#define LIBC_RTLD_SYMBOL_H_
+
+#include <rtld/rtld.h>
+#include <elf.h>
+
+elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod);
+elf_symbol_t *symbol_def_find(const char *name, module_t *origin, module_t **mod);
+void *symbol_get_addr(elf_symbol_t *sym, module_t *m);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision 72cd53d4a534c31423276f4e863f774083b559ee)
+++ uspace/lib/c/include/str.h	(revision 04c418dcaeffd13ea8028c1076db5abe46f4c748)
@@ -89,5 +89,6 @@
 extern int str_size_t(const char *, char **, unsigned int, bool, size_t *);
 
-extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
+extern void order_suffix(const uint64_t, uint64_t *, char *);
+extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
 
 /*
