Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/Makefile	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -59,5 +59,5 @@
 -include arch/$(UARCH)/Makefile.inc
 
-EXTRA_CFLAGS += -Irtld/include -I../../srv/loader/include
+EXTRA_CFLAGS += -I../../srv/loader/include
 
 GENERIC_SOURCES = \
@@ -130,9 +130,9 @@
 	GENERIC_SOURCES += \
 		generic/dlfcn.c \
-		rtld/rtld.c \
-		rtld/elf_load.c \
-		rtld/dynamic.c \
-		rtld/module.c \
-		rtld/symbol.c
+		generic/rtld/rtld.c \
+		generic/rtld/elf_load.c \
+		generic/rtld/dynamic.c \
+		generic/rtld/module.c \
+		generic/rtld/symbol.c
 endif
 
Index: uspace/lib/c/arch/ia32/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -33,6 +33,6 @@
  */
 
-#ifndef ia32_DYNAMIC_H_
-#define ia32_DYNAMIC_H_
+#ifndef LIBC_ia32_RTLD_DYNAMIC_H_
+#define LIBC_ia32_RTLD_DYNAMIC_H_
 
 #include <sys/types.h>
Index: uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -33,6 +33,6 @@
  */
 
-#ifndef ia32_ELF_DYN_H_
-#define ia32_ELF_DYN_H_
+#ifndef LIBC_ia32_RTLD_ELF_DYN_H_
+#define LIBC_ia32_RTLD_ELF_DYN_H_
 
 /* 
Index: uspace/lib/c/arch/ia32/src/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcia32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
@@ -38,6 +38,6 @@
 #include <stdlib.h>
 
-#include <elf_dyn.h>
-#include <dynamic.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)
Index: uspace/lib/c/arch/ia32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcia32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
@@ -39,9 +39,8 @@
 
 #include <libarch/rtld/elf_dyn.h>
-#include <symbol.h>
-#include <rtld.h>
-#include <rtld_debug.h>
-
-#include <rtld_arch.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)
Index: uspace/lib/c/arch/mips32/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/mips32/include/rtld/dynamic.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/mips32/include/rtld/dynamic.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup libcmips32
  * @{
  */
@@ -33,6 +33,6 @@
  */
 
-#ifndef mips32_DYNAMIC_H_
-#define mips32_DYNAMIC_H_
+#ifndef LIBC_mips32_RTLD_DYNAMIC_H_
+#define LIBC_mips32_RTLD_DYNAMIC_H_
 
 #include <sys/types.h>
Index: uspace/lib/c/arch/mips32/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/arch/mips32/include/rtld/elf_dyn.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/mips32/include/rtld/elf_dyn.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup libcmips32
  * @{
  */
@@ -33,6 +33,6 @@
  */
 
-#ifndef mips32_ELF_DYN_H_
-#define mips32_ELF_DYN_H_
+#ifndef LIBC_mips32_RTLD_ELF_DYN_H_
+#define LIBC_mips32_RTLD_ELF_DYN_H_
 
 /*
Index: uspace/lib/c/arch/mips32/src/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/mips32/src/rtld/dynamic.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/mips32/src/rtld/dynamic.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcmips32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
Index: uspace/lib/c/arch/mips32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/mips32/src/rtld/reloc.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/mips32/src/rtld/reloc.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcmips32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
Index: uspace/lib/c/arch/ppc32/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/rtld/dynamic.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ppc32/include/rtld/dynamic.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup libcppc32
  * @{
  */
@@ -33,6 +33,6 @@
  */
 
-#ifndef ppc32_DYNAMIC_H_
-#define ppc32_DYNAMIC_H_
+#ifndef LIBC_ppc32_RTLD_DYNAMIC_H_
+#define LIBC_ppc32_RTLD_DYNAMIC_H_
 
 #include <sys/types.h>
Index: uspace/lib/c/arch/ppc32/include/rtld/elf_dyn.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/rtld/elf_dyn.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ppc32/include/rtld/elf_dyn.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup generic	
+/** @addtogroup libcppc32
  * @{
  */
@@ -33,8 +33,8 @@
  */
 
-#ifndef ppc32_ELF_DYN_H_
-#define ppc32_ELF_DYN_H_
+#ifndef LIBC_ppc32_RTLD_ELF_DYN_H_
+#define LIBC_ppc32_RTLD_ELF_DYN_H_
 
-/* 
+/*
  * ppc32 dynamic relocation types
  */
Index: uspace/lib/c/arch/ppc32/src/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/ppc32/src/rtld/dynamic.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ppc32/src/rtld/dynamic.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcppc32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
Index: uspace/lib/c/arch/ppc32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ppc32/src/rtld/reloc.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/arch/ppc32/src/rtld/reloc.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup rtld rtld
+/** @addtogroup libcppc32
  * @brief
  * @{
- */ 
+ */
 /**
  * @file
Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/generic/dlfcn.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -39,7 +39,6 @@
 #include <dlfcn.h>
 
-/* From librtld. */
-#include <module.h>
-#include <symbol.h>
+#include <rtld/module.h>
+#include <rtld/symbol.h>
 
 void *dlopen(const char *path, int flag)
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ uspace/lib/c/generic/libc.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -54,8 +54,6 @@
 
 #ifdef CONFIG_RTLD
-/* From librtld. */
-#include <rtld.h>
+#include <rtld/rtld.h>
 #endif
-//#include <string.h>
 
 static bool env_setup = false;
Index: uspace/lib/c/generic/rtld/dynamic.c
===================================================================
--- uspace/lib/c/generic/rtld/dynamic.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/generic/rtld/dynamic.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/generic/rtld/elf_load.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/generic/rtld/module.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/generic/rtld/symbol.c	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/include/rtld/dynamic.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/dynamic.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/elf_dyn.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/module.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/rtld.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/rtld_arch.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/rtld_debug.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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 8a1fb098bbfa685e158cd315fe823dd431647b01)
+++ uspace/lib/c/include/rtld/symbol.h	(revision 8a1fb098bbfa685e158cd315fe823dd431647b01)
@@ -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/rtld/dynamic.c
===================================================================
--- uspace/lib/c/rtld/dynamic.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,143 +1,0 @@
-/*
- * 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 <string.h>
-
-#include <elf_dyn.h>
-#include <dynamic.h>
-#include <rtld.h>
-#include <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/rtld/elf_load.c
===================================================================
--- uspace/lib/c/rtld/elf_load.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../srv/loader/elf_load.c
Index: uspace/lib/c/rtld/include/dynamic.h
===================================================================
--- uspace/lib/c/rtld/include/dynamic.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/*
- * 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 DYNAMIC_H_
-#define DYNAMIC_H_
-
-#include <bool.h>
-#include <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/rtld/include/elf_dyn.h
===================================================================
--- uspace/lib/c/rtld/include/elf_dyn.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/*
- * 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 ELF_DYN_H_
-#define 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/rtld/include/module.h
===================================================================
--- uspace/lib/c/rtld/include/module.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*
- * 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 MODULE_H_
-#define MODULE_H_
-
-#include <sys/types.h>
-#include <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/rtld/include/rtld.h
===================================================================
--- uspace/lib/c/rtld/include/rtld.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/*
- * 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 RTLD_H_
-#define RTLD_H_
-
-#include <sys/types.h>
-#include <adt/list.h>
-
-#include <dynamic.h>
-#include <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/rtld/include/rtld_arch.h
===================================================================
--- uspace/lib/c/rtld/include/rtld_arch.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * 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 RTLD_ARCH_H_
-#define RTLD_ARCH_H_
-
-#include <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/rtld/include/rtld_debug.h
===================================================================
--- uspace/lib/c/rtld/include/rtld_debug.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,50 +1,0 @@
-/*
- * 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 generic	
- * @{
- */
-/** @file
- */
-
-#ifndef RTLD_DEBUG_H_
-#define 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/rtld/include/symbol.h
===================================================================
--- uspace/lib/c/rtld/include/symbol.h	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * 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 SYMBOL_H_
-#define SYMBOL_H_
-
-#include <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/rtld/module.c
===================================================================
--- uspace/lib/c/rtld/module.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,282 +1,0 @@
-/*
- * 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.h>
-#include <rtld_debug.h>
-#include <dynamic.h>
-#include <elf_load.h>
-#include <rtld_arch.h>
-#include <module.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/rtld/rtld.c
===================================================================
--- uspace/lib/c/rtld/rtld.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * 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.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/rtld/symbol.c
===================================================================
--- uspace/lib/c/rtld/symbol.c	(revision 54146a0e4e89ae79bdb89d2cd48c51829a471c3d)
+++ 	(revision )
@@ -1,233 +1,0 @@
-/*
- * 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 <string.h>
-
-#include <rtld.h>
-#include <rtld_debug.h>
-#include <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);
-	}
-}
-
-/** @}
- */
