Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision 729f774f860bfd8dc1a857e7bc279ff2a55a959a)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
@@ -36,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/include/rtld/dynamic.h
===================================================================
--- uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
+++ uspace/lib/c/arch/ia32/include/rtld/dynamic.h	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
@@ -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 ia32_DYNAMIC_H_
+#define ia32_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 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
+++ uspace/lib/c/arch/ia32/include/rtld/elf_dyn.h	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
@@ -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 ia32_ELF_DYN_H_
+#define ia32_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/rtld/dynamic.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
+++ uspace/lib/c/arch/ia32/src/rtld/dynamic.c	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
@@ -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 rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <elf_dyn.h>
+#include <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 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 7fb3f1c0cd0601d504202af56df44cb8372b7dfe)
@@ -0,0 +1,183 @@
+/*
+ * 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 <libarch/rtld/elf_dyn.h>
+#include <symbol.h>
+#include <rtld.h>
+#include <rtld_debug.h>
+
+#include <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;
+}
+
+/** @}
+ */
