Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ HelenOS.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -528,4 +528,11 @@
 ! [PLATFORM=sparc64&MACHINE=generic] CONFIG_AOUT_ISOFS_B (y)
 
+% Build shared libraries
+! CONFIG_BUILD_SHARED_LIBS (y/n)
+
+% Link against shared libraries
+! [CONFIG_BUILD_SHARED_LIBS=y] CONFIG_USE_SHARED_LIBS (n/y)
+! [CONFIG_BUILD_SHARED_LIBS=n] CONFIG_USE_SHARED_LIBS (n)
+
 % Run devman on startup
 ! CONFIG_START_DEVMAN (y/n)
Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ boot/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -55,4 +55,7 @@
 		cp "$$file" "$(DIST_PATH)/srv/" ; \
 	done
+	for file in $(RD_LIBS) ; do \
+		cp "$$file" "$(DIST_PATH)/lib/" ; \
+	done
 	for file in $(RD_APPS) ; do \
 		cp "$$file" "$(DIST_PATH)/app/" ; \
@@ -83,4 +86,5 @@
 	rm -f $(USPACE_PATH)/dist/srv/*
 	rm -rf $(USPACE_PATH)/dist/drv/*
+	rm -f $(USPACE_PATH)/dist/lib/*
 	rm -f $(USPACE_PATH)/dist/app/*
 	rm -f $(USPACE_PATH)/dist/cfg/net/*
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ boot/Makefile.common	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -118,4 +118,13 @@
 RD_DRV_CFG = 
 
+RD_LIBS = \
+	$(USPACE_PATH)/lib/test/libtest.so.0
+
+ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
+	RD_LIBS += $(USPACE_PATH)/lib/c/libc.so.0
+	RD_LIBS += $(USPACE_PATH)/lib/softint/libsoftint.so.0
+	RD_APPS += $(USPACE_PATH)/app/dltest/dltest
+endif
+
 RD_APPS_ESSENTIAL = \
 	$(USPACE_PATH)/app/bdsh/bdsh \
@@ -124,4 +133,7 @@
 
 RD_APPS_NON_ESSENTIAL = \
+	$(USPACE_PATH)/app/dltest/dltest \
+	$(USPACE_PATH)/app/dltest2/dltest2 \
+	$(USPACE_PATH)/app/dload/dload \
 	$(USPACE_PATH)/app/edit/edit \
 	$(USPACE_PATH)/app/kill/kill \
Index: boot/arch/mips32/src/Makefile
===================================================================
--- boot/arch/mips32/src/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ boot/arch/mips32/src/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -1,5 +1,4 @@
 #
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
+# Copyright (c) 2006 Martin Decky
 # All rights reserved.
 #
@@ -28,27 +27,150 @@
 #
 
-include Makefile.common
+include ../../../../version
+-include ../../../../Makefile.config
 
-.PHONY: all clean
+## Toolchain configuration
+#
 
-all: ../../../../version ../../../../Makefile.common ../../../../Makefile.config ../../../../config.h
-	-[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
-	$(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
+ifndef CROSS_PREFIX
+	CROSS_PREFIX = /usr/local
+endif
+
+BFD_ARCH = mips
+TARGET = mipsel-linux-gnu
+TOOLCHAIN_DIR = $(CROSS_PREFIX)/mipsel/bin
+
+ifeq ($(MACHINE),lgxemul)
+	BFD_NAME = elf32-tradlittlemips
+	BFD = ecoff-littlemips
+endif
+ifeq ($(MACHINE),bgxemul)
+	BFD_NAME = elf32-tradbigmips
+	BFD = ecoff-bigmips
+	TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips/bin
+	TARGET = mips-linux-gnu
+endif
+ifeq ($(MACHINE),msim)
+	BFD_NAME = elf32-tradlittlemips
+	BFD = binary
+endif
+
+ifeq ($(COMPILER),gcc_native)
+	CC = gcc
+	AS = as
+	LD = ld
+	OBJCOPY = objcopy
+	OBJDUMP = objdump
+endif
+
+ifeq ($(COMPILER),gcc_cross)
+	CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
+	AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
+	LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
+	OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
+	OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
+endif
+
+CFLAGS = -DRELEASE=$(RELEASE) -I. -I../../../generic -imacros ../../../../config.h -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mhard-float -mips3 -pipe
+
+SOURCES = \
+	main.c \
+	msim.c \
+	_components.c \
+	../../../generic/printf.c \
+	../../../generic/string.c \
+	asm.S \
+	boot.S
+
+COMPONENTS = \
+	$(KERNELDIR)/kernel.bin \
+	$(USPACEDIR)/srv/ns/ns \
+	$(USPACEDIR)/srv/loader/loader \
+	$(USPACEDIR)/app/init/init \
+	$(USPACEDIR)/srv/devmap/devmap \
+	$(USPACEDIR)/srv/bd/rd/rd \
+	$(USPACEDIR)/srv/vfs/vfs
+ifeq ($(RDFMT),tmpfs)
+	COMPONENTS += $(USPACEDIR)/srv/fs/tmpfs/tmpfs
+endif
+ifeq ($(RDFMT),fat)
+	COMPONENTS += $(USPACEDIR)/srv/fs/fat/fat
+endif
+
+RD_SRVS = \
+	$(USPACEDIR)/srv/fb/fb \
+	$(USPACEDIR)/srv/kbd/kbd \
+	$(USPACEDIR)/srv/console/console \
+	$(USPACEDIR)/srv/fs/devfs/devfs \
+	$(USPACEDIR)/srv/fs/tmpfs/tmpfs \
+	$(USPACEDIR)/srv/fs/fat/fat \
+	$(USPACEDIR)/srv/bd/file_bd/file_bd \
+	$(USPACEDIR)/srv/bd/gxe_bd/gxe_bd
+
+RD_APPS = \
+	$(USPACEDIR)/app/getvc/getvc \
+	$(USPACEDIR)/app/tetris/tetris \
+	$(USPACEDIR)/app/tester/tester \
+	$(USPACEDIR)/app/dload/dload \
+	$(USPACEDIR)/app/dltest/dltest \
+	$(USPACEDIR)/app/dltest2/dltest2 \
+	$(USPACEDIR)/app/trace/trace \
+	$(USPACEDIR)/app/bdsh/bdsh \
+	$(USPACEDIR)/app/klog/klog
+
+RD_LIBS = \
+	$(USPACEDIR)/lib/libc/shared/libc.so.0 \
+	$(USPACEDIR)/lib/libtest/libtest.so.0
+
+OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
+
+.PHONY: all clean depend
+
+all: image.boot
+
+-include Makefile.depend
+
+image.boot: image.raw
+	$(OBJCOPY) -O $(BFD) $< $@
+
+image.raw: depend _components.h _link.ld $(COMPONENT_OBJECTS) initrd.o $(OBJECTS)
+	$(LD) -no-check-sections -N -T _link.ld -o $@ $(COMPONENT_OBJECTS) initrd.o $(OBJECTS)
+
+depend:
+	-makedepend -f - -- $(DEFS) $(CFLAGS) -- $(SOURCES) > Makefile.depend 2> /dev/null
 
 clean:
-	rm -f $(USPACEDIR)/dist/srv/*
-	rm -f $(USPACEDIR)/dist/app/*
-	rm -f $(USPACEDIR)/dist/cfg/net/*
-
-	for file in $(RD_SRVS) ; do \
+	-for file in $(RD_SRVS) ; do \
 		rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \
 	done
-	for file in $(RD_APPS) ; do \
+	-for file in $(RD_APPS) ; do \
 		rm -f $(USPACEDIR)/dist/app/`basename $$file` ; \
 	done
-	for file in $(NET_CFG) ; do \
-		rm -f $(USPACEDIR)/dist/cfg/net/`basename $$file` ; \
+	-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o $(OBJECTS) initrd.img image.raw image.boot Makefile.depend
+
+_components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o: $(COMPONENTS) $(RD_SRVS) $(RD_LIBS) $(RD_APPS) _link.ld.in
+	for file in $(RD_SRVS) ; do \
+		cp $$file $(USPACEDIR)/dist/srv/ ; \
 	done
-	rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(RAW) $(COMPS).h $(COMPS).c $(LINK) $(INITRD).img $(INITRD).fs
-	find . -name '*.o' -follow -exec rm \{\} \;
-	find . -name '*.co' -follow -exec rm \{\} \;
+	for lib in $(RD_LIBS) ; do \
+		cp $$lib $(USPACEDIR)/dist/lib/ ; \
+	done
+	for file in $(RD_APPS) ; do \
+		cp $$file $(USPACEDIR)/dist/app/ ; \
+	done
+ifeq ($(RDFMT),tmpfs)
+	../../../../tools/mktmpfs.py $(USPACEDIR)/dist/ initrd.fs
+endif
+ifeq ($(RDFMT),fat)
+	../../../../tools/mkfat.py $(USPACEDIR)/dist/ initrd.fs
+endif
+	../../../../tools/mkhord.py 16384 initrd.fs initrd.img
+	rm initrd.fs
+	../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 16384 "unsigned int" $(COMPONENTS) ./initrd.img
+
+%.o: %.S
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+
+%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
Index: ot/arch/mips32/src/Makefile.build
===================================================================
--- boot/arch/mips32/src/Makefile.build	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,101 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-## Setup toolchain
-#
-
-include ../../../../version
-include ../../../../Makefile.common
-include ../../../../Makefile.config
-include Makefile.common
-include Makefile.toolchain
-
-## Sources
-#
-
-SOURCES = \
-	main.c \
-	msim.c \
-	_components.c \
-	../../../generic/printf.c \
-	../../../generic/string.c \
-	asm.S \
-	boot.S
-
-OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
-COMPONENT_OBJECTS := $(addsuffix .co,$(basename $(notdir $(COMPONENTS)))) $(INITRD).co
-
-.PHONY: all
-
-all: $(OUTPUT)
-
--include $(DEPEND)
-
-$(OUTPUT): $(RAW)
-	$(OBJCOPY) -O $(BFD) $< $@
-
-$(RAW): $(OBJECTS) $(COMPONENT_OBJECTS) $(LINK)
-	$(LD) -no-check-sections -N -T $(LINK) $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
-
-%.o: %.S $(DEPEND)
-	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
-ifeq ($(PRECHECK),y)
-	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
-endif
-
-%.o: %.c $(DEPEND)
-	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
-ifeq ($(PRECHECK),y)
-	$(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
-endif
-
-$(DEPEND):
-	rm -f $(USPACEDIR)/dist/srv/*
-	rm -f $(USPACEDIR)/dist/app/*
-	rm -f $(USPACEDIR)/dist/cfg/net/*
-
-	for file in $(RD_SRVS) ; do \
-		cp $$file $(USPACEDIR)/dist/srv/ ; \
-	done
-	for file in $(RD_APPS) ; do \
-		cp $$file $(USPACEDIR)/dist/app/ ; \
-	done
-	for file in $(NET_CFG) ; do \
-		cp $$file $(USPACEDIR)/dist/cfg/net/ ; \
-	done
-ifeq ($(RDFMT),tmpfs)
-	../../../../tools/mktmpfs.py $(USPACEDIR)/dist/ $(INITRD).fs
-endif
-ifeq ($(RDFMT),fat)
-	../../../../tools/mkfat.py $(USPACEDIR)/dist/ $(INITRD).fs
-endif
-	../../../../tools/mkhord.py 16384 $(INITRD).fs $(INITRD).img
-	../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 16384 "unsigned int" $(COMPONENTS) ./$(INITRD).img
-	makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
-	-[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
Index: ot/arch/mips32/src/Makefile.common
===================================================================
--- boot/arch/mips32/src/Makefile.common	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-
-## Common names
-#
-
-include ../../../Makefile.common
-
-DEPEND = Makefile.depend
-DEPEND_PREV = $(DEPEND).prev
-RAW = image.raw
-JOB = image.job
-OUTPUT = image.boot
-
-LINK = _link.ld
-COMPS = _components
-
-KERNELDIR = ../../../../kernel
-USPACEDIR = ../../../../uspace
-
-RD_SRVS += $(USPACEDIR)/srv/bd/gxe_bd/gxe_bd
Index: ot/arch/mips32/src/Makefile.toolchain
===================================================================
--- boot/arch/mips32/src/Makefile.toolchain	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#
-# Copyright (c) 2006 Martin Decky
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-BFD_ARCH = mips
-
-JOBFILE = ../../../../tools/jobfile.py
-
-ifeq ($(MACHINE),lgxemul)
-	BFD_NAME = elf32-tradlittlemips
-	BFD = ecoff-littlemips
-endif
-
-ifeq ($(MACHINE),bgxemul)
-	BFD_NAME = elf32-tradbigmips
-	BFD = ecoff-bigmips
-endif
-
-ifeq ($(MACHINE),msim)
-	BFD_NAME = elf32-tradlittlemips
-	BFD = binary
-endif
-
-CFLAGS = \
-	-DRELEASE=$(RELEASE) -I. -I../../../generic \
-	-imacros ../../../../config.h -nostdinc -nostdlib -fno-builtin \
-	-Werror-implicit-function-declaration -Wmissing-prototypes -Werror \
-	-O3 -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mhard-float \
-	-mips3 -pipe
-
-DEPEND_DEFS = $(CONFIG_DEFS)
Index: boot/grub/menu.lst
===================================================================
--- boot/grub/menu.lst	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ boot/grub/menu.lst	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,15 @@
+default 0
+timeout 10
+
+title=HelenOS
+	root (cd)
+	kernel /boot/kernel.bin
+	module /boot/ns
+	module /boot/init
+	module /boot/devmap
+	module /boot/rd
+	module /boot/vfs
+	module /boot/tmpfs
+	module /boot/fat
+	module /boot/loader
+	module /boot/initrd.img
Index: ntrib/arch/uspace/lib/libc/devmap_device_connect
===================================================================
--- contrib/arch/uspace/lib/libc/devmap_device_connect	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,2 +1,0 @@
-[devmap_get_phone] ;
-!dev.IPC_M_CONNECT_ME_TO
Index: ntrib/arch/uspace/lib/libc/devmap_device_get_count
===================================================================
--- contrib/arch/uspace/lib/libc/devmap_device_get_count	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,2 +1,0 @@
-[devmap_get_phone] ;
-!devmap.DEVMAP_DEVICE_GET_COUNT
Index: ntrib/arch/uspace/lib/libc/devmap_device_get_devices
===================================================================
--- contrib/arch/uspace/lib/libc/devmap_device_get_devices	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,3 +1,0 @@
-[devmap_get_phone] ;
-!devmap.DEVMAP_DEVICE_GET_DEVICES ;
-!devmap.IPC_M_DATA_READ
Index: ntrib/arch/uspace/lib/libc/devmap_device_get_handle
===================================================================
--- contrib/arch/uspace/lib/libc/devmap_device_get_handle	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,3 +1,0 @@
-[devmap_get_phone] ;
-!devmap.DEVMAP_DEVICE_GET_HANDLE ;
-!devmap.IPC_M_DATA_WRITE /* name */
Index: ntrib/arch/uspace/lib/libc/devmap_get_phone
===================================================================
--- contrib/arch/uspace/lib/libc/devmap_get_phone	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,2 +1,0 @@
-!ns.IPC_M_CONNECT_ME_TO /* devmap */ +
-NULL
Index: defaults/amd64/Makefile.config
===================================================================
--- defaults/amd64/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/amd64/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -3,5 +3,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -59,4 +59,7 @@
 CONFIG_VESA_BPP = 16
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/arm32/Makefile.config
===================================================================
--- defaults/arm32/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/arm32/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -3,5 +3,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -35,4 +35,7 @@
 CONFIG_HID_OUT = generic
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/ia32/Makefile.config
===================================================================
--- defaults/ia32/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/ia32/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -6,5 +6,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -65,4 +65,10 @@
 CONFIG_VESA_BPP = 16
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = y
+
+# Link against shared libraries
+CONFIG_USE_SHARED_LIBS = y
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/ia64/Makefile.config
===================================================================
--- defaults/ia64/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/ia64/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -3,5 +3,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -47,4 +47,7 @@
 CONFIG_HID_OUT = generic
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/mips32/Makefile.config
===================================================================
--- defaults/mips32/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/mips32/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -3,5 +3,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -41,4 +41,7 @@
 CONFIG_HID_OUT = generic
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/ppc32/Makefile.config
===================================================================
--- defaults/ppc32/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/ppc32/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -3,5 +3,5 @@
 
 # Ramdisk format
-RDFMT = fat
+RDFMT = tmpfs
 
 # Compiler
@@ -41,4 +41,7 @@
 CONFIG_BAT = y
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/sparc64/Makefile.config
===================================================================
--- defaults/sparc64/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/sparc64/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -56,4 +56,7 @@
 CONFIG_AOUT_ISOFS_B = y
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: defaults/special/Makefile.config
===================================================================
--- defaults/special/Makefile.config	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ defaults/special/Makefile.config	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -29,4 +29,7 @@
 CONFIG_TEST = y
 
+# Build shared libraries
+CONFIG_BUILD_SHARED_LIBS = n
+
 # Load disk drivers on startup
 CONFIG_START_BD = n
Index: kernel/arch/ia32/include/barrier.h
===================================================================
--- kernel/arch/ia32/include/barrier.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ kernel/arch/ia32/include/barrier.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -54,4 +54,5 @@
 NO_TRACE static inline void cpuid_serialization(void)
 {
+#ifndef __IN_SHARED_LIBC__
 	asm volatile (
 		"xorl %%eax, %%eax\n"
@@ -59,4 +60,14 @@
 		::: "eax", "ebx", "ecx", "edx", "memory"
 	);
+#else
+	/* Must not clobber PIC register ebx */
+	asm volatile (
+		"movl %%ebx, %%esi\n"
+		"xorl %%eax, %%eax\n"
+		"cpuid\n"
+		"movl %%esi, %%ebx\n"
+		::: "eax", "ecx", "edx", "esi", "memory"
+	);
+#endif
 }
 
Index: kernel/generic/include/syscall/syscall.h
===================================================================
--- kernel/generic/include/syscall/syscall.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ kernel/generic/include/syscall/syscall.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -90,4 +90,5 @@
 	SYS_SYSINFO_GET_DATA,
 	
+	SYS_DEBUG_PUTINT,
 	SYS_DEBUG_ENABLE_CONSOLE,
 	SYS_DEBUG_DISABLE_CONSOLE,
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ kernel/generic/src/syscall/syscall.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -55,4 +55,11 @@
 #include <console/console.h>
 #include <udebug/udebug.h>
+
+/** Print a hex integer into klog */
+static sysarg_t sys_debug_putint(sysarg_t i)
+{
+	printf("[task:0x%x]", i);
+	return 0;
+}
 
 /** Dispatch system call */
@@ -180,4 +187,5 @@
 	
 	/* Debug calls */
+	(syshandler_t) sys_debug_putint,
 	(syshandler_t) sys_debug_enable_console,
 	(syshandler_t) sys_debug_disable_console
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -35,4 +35,5 @@
 DIRS = \
 	app/bdsh \
+	app/dltest2 \
 	app/edit \
 	app/getterm \
@@ -92,4 +93,10 @@
 	drv/test2
 
+## Shared libraries
+ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
+	DIRS += \
+		app/dltest
+endif
+
 ## Networking
 #
@@ -146,4 +153,5 @@
 	lib/softint \
 	lib/softfloat \
+	lib/test \
 	lib/drv \
 	lib/packet \
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/Makefile.common	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -73,4 +73,12 @@
 endif
 
+ifneq ($(SLIBRARY),)
+	LARCHIVE = $(LIBRARY).la
+	LOUTPUT = $(SLIBRARY)
+	EXTRA_OUTPUT += $(LOUTPUT).disasm
+	EXTRA_CLEAN += $(LOUTPUT).map $(LOUTPUT).ldisasm \
+	    $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld
+endif
+
 DEPEND = Makefile.depend
 DEPEND_PREV = $(DEPEND).prev
@@ -90,7 +98,12 @@
 LIBNET_PREFIX = $(LIB_PREFIX)/net
 
+ifeq ($(DYNAMIC_LINKING),y)
+BASE_LIBS = $(LIBC_PREFIX)/libc.so.0 $(LIBSOFTINT_PREFIX)/libsoftint.a
+LFLAGS = -Bdynamic
+LINKER_SCRIPT ?= $(LIBC_PREFIX)/shared/arch/$(UARCH)/_link.ld
+else
 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
-
 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
+endif
 
 ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
@@ -102,10 +115,11 @@
 .PHONY: all clean
 
-all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
+all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(LOUTPUT) $(EXTRA_OUTPUT)
 	-[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
 
 clean:
-	rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
+	rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(LARCHIVE) $(LOUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
 	find . -name '*.o' -follow -exec rm \{\} \;
+	find . -name '*.lo' -follow -exec rm \{\} \;
 
 GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
@@ -130,4 +144,7 @@
 	-pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
 
+LIB_CFLAGS = $(CFLAGS) -fPIC -D__IN_SHARED_LIBC__
+LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
+
 ifeq ($(CONFIG_DEBUG),y)
 	GCC_CFLAGS += -Werror
@@ -175,4 +192,5 @@
 
 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+LOBJECTS := $(addsuffix .lo,$(basename $(SOURCES)))
 
 ifneq ($(BINARY),)
@@ -191,4 +209,22 @@
 endif
 
+ifneq ($(SLIBRARY),)
+%.disasm: $(LOUTPUT)
+ifeq ($(CONFIG_LINE_DEBUG),y)
+	$(OBJDUMP) -d -S $< > $@
+else
+	$(OBJDUMP) -d $< > $@
+endif
+
+$(LOUTPUT): $(LARCHIVE) $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld
+	$(LD) -T $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld $(LIB_LFLAGS) $(LARCHIVE) -o $@ -Map $(LOUTPUT).map
+endif
+
+$(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld: $(LIBC_PREFIX)/shared/arch/$(UARCH)/_lib.ld.in
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PREFIX=$(LIBC_PREFIX) -E -x c $< | grep -v "^\#" > $@
+
+$(LIBC_PREFIX)/shared/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/shared/arch/$(UARCH)/_link.ld.in
+	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PREFIX=$(LIBC_PREFIX) -E -x c $< | grep -v "^\#" > $@
+
 ifneq ($(LIBRARY),)
 %.a: $(OBJECTS)
@@ -196,4 +232,9 @@
 endif
 
+ifneq ($(SLIBRARY),)
+%.la: $(LOBJECTS)
+	$(AR) rc $@ $(LOBJECTS)
+endif
+
 %.o: %.S $(DEPEND)
 	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
@@ -210,4 +251,22 @@
 %.o: %.c $(DEPEND)
 	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
+ifeq ($(PRECHECK),y)
+	$(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
+endif
+
+%.lo: %.S $(DEPEND)
+	$(CC) $(DEFS) $(LIB_CFLAGS) -D__ASM__ -c $< -o $@
+ifeq ($(PRECHECK),y)
+	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
+endif
+
+%.lo: %.s $(DEPEND)
+	$(AS) $(AFLAGS) -o $@ $<
+ifeq ($(PRECHECK),y)
+	$(JOBFILE) $(JOB) $< $@ as asm
+endif
+
+%.lo: %.c $(DEPEND)
+	$(CC) $(DEFS) $(LIB_CFLAGS) -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
@@ -223,2 +282,3 @@
 $(OUTPUT): $(OBJECTS)
 
+$(LARCHIVE): $(LOBJECTS)
Index: uspace/app/dltest/Makefile
===================================================================
--- uspace/app/dltest/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/app/dltest/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+USPACE_PREFIX = ../..
+BINARY = dltest
+DYNAMIC_LINKING = y
+
+SOURCES = \
+	dltest.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/dltest/dltest.c
===================================================================
--- uspace/app/dltest/dltest.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/app/dltest/dltest.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,100 @@
+/*
+ * 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
+ * @brief	Test dynamic linking capabilities.
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+static void kputint(unsigned i)
+{
+//	unsigned dummy;
+//	asm volatile (
+//		"movl $30, %%eax;"
+//		"int $0x30"
+//		: "=d" (dummy) /* output - %edx clobbered */
+//		: "d" (i) /* input */
+//		: "%eax","%ecx" /* all scratch registers clobbered */
+//	);
+/*
+	asm volatile (
+		"mr %%r3, %0\n"
+		"li %%r9, 32\n"
+		"sc\n"
+		:
+		: "r" (i)
+		: "%r3","%r9"
+	);
+*/
+}
+
+typedef int (*fptr_t)(void);
+
+int main(int argc, char *argv[])
+{
+	void *a;
+	void *s;
+	fptr_t fun;
+	int i;
+
+	const char *lib_name;
+	const char *sym_name;
+
+	if (0) kputint(-1);
+	printf("Hello from dltest!\n");
+
+	lib_name = "libtest.so.0";
+	sym_name = "test_func";
+
+	a = dlopen(lib_name, 0);
+	if (a != NULL) {
+		s = dlsym(a, sym_name);
+		printf("symbol '%s' = 0x%lx\n", sym_name, (long) s);
+	} else {
+		printf("failed to dlopen() library '%s'\n", lib_name);
+		return -1;
+	}
+
+	printf("Run dynamically-resolved function '%s'...\n", sym_name);
+	fun = (fptr_t) s;
+	i = (*fun)();
+	printf("Done. (returned 0x%x)\n", i);
+	
+	return 0;
+}
+
+/** @}
+ */
+
Index: uspace/app/dltest2/Makefile
===================================================================
--- uspace/app/dltest2/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/app/dltest2/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+USPACE_PREFIX = ../..
+BINARY = dltest2
+
+SOURCES = \
+	dltest2.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/dltest2/dltest2.c
===================================================================
--- uspace/app/dltest2/dltest2.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/app/dltest2/dltest2.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,100 @@
+/*
+ * 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
+ * @brief	Test dynamic linking capabilities.
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+static void kputint(unsigned i)
+{
+//	unsigned dummy;
+//	asm volatile (
+//		"movl $30, %%eax;"
+//		"int $0x30"
+//		: "=d" (dummy) /* output - %edx clobbered */
+//		: "d" (i) /* input */
+//		: "%eax","%ecx" /* all scratch registers clobbered */
+//	);
+/*
+	asm volatile (
+		"mr %%r3, %0\n"
+		"li %%r9, 32\n"
+		"sc\n"
+		:
+		: "r" (i)
+		: "%r3","%r9"
+	);
+*/
+}
+
+typedef int (*fptr_t)(void);
+
+int main(int argc, char *argv[])
+{
+	void *a;
+	void *s;
+	fptr_t fun;
+	int i;
+
+	const char *lib_name;
+	const char *sym_name;
+
+	if (0) kputint(-1);
+	printf("Hello from dltest!\n");
+
+	lib_name = "libtest.so.0";
+	sym_name = "test_func";
+
+	a = dlopen(lib_name, 0);
+	if (a != NULL) {
+		s = dlsym(a, sym_name);
+		printf("symbol '%s' = 0x%lx\n", sym_name, (long) s);
+	} else {
+		printf("failed to dlopen() library '%s'\n", lib_name);
+		return -1;
+	}
+
+	printf("Run dynamically-resolved function '%s'...\n", sym_name);
+	fun = (fptr_t) s;
+	i = (*fun)();
+	printf("Done. (returned 0x%x)\n", i);
+	
+	return 0;
+}
+
+/** @}
+ */
+
Index: pace/app/netstart/self_test.c
===================================================================
--- uspace/app/netstart/self_test.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,334 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-/** @file
- * Networking self-tests implementation.
- *
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <stdio.h>
-
-#include <net_checksum.h>
-#include <adt/int_map.h>
-#include <adt/char_map.h>
-#include <adt/generic_char_map.h>
-#include <adt/measured_strings.h>
-#include <adt/dynamic_fifo.h>
-
-#include "self_test.h"
-
-/** Test the statement, compare the result and evaluate.
- *
- * @param[in] statement The statement to test.
- * @param[in] result    The expected result.
- *
- */
-#define TEST(statement, result) \
-	do { \
-		printf("\n\t%s == %s", #statement, #result); \
-		if ((statement) != (result)) { \
-			printf("\tfailed\n"); \
-			fprintf(stderr, "\nNetwork self-test failed\n"); \
-			return EINVAL; \
-		} else \
-			printf("\tOK"); \
-	} while (0)
-
-#define XMALLOC(var, type) \
-	do { \
-		(var) = (type *) malloc(sizeof(type)); \
-		if ((var) == NULL) { \
-			fprintf(stderr, "\nMemory allocation error\n"); \
-			return ENOMEM; \
-		} \
-	} while (0)
-
-GENERIC_CHAR_MAP_DECLARE(int_char_map, int);
-GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int);
-
-GENERIC_FIELD_DECLARE(int_field, int);
-GENERIC_FIELD_IMPLEMENT(int_field, int);
-
-INT_MAP_DECLARE(int_map, int);
-INT_MAP_IMPLEMENT(int_map, int);
-
-/** Self-test start function.
- *
- * Run all self-tests.
- *
- * @returns EOK on success.
- * @returns The first error occurred.
- *
- */
-int self_test(void)
-{
-	printf("Running networking self-tests\n");
-	
-	printf("\nChar map test");
-	char_map_t cm;
-	
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	TEST(char_map_initialize(&cm), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_add(&cm, "bla", 0, 1), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 1);
-	TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS);
-	TEST(char_map_update(&cm, "bla", 0, 2), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 2), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), 2);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "ucho", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EOK);
-	TEST(char_map_find(&cm, "ucho", 0), 3);
-	TEST(char_map_add(&cm, "blabla", 0, 5), EOK);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "bla", 0, 6), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 6);
-	TEST(char_map_exclude(&cm, "bla", 0), 6);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "auto", 0, 7), EOK);
-	TEST(char_map_find(&cm, "auto", 0), 7);
-	TEST(char_map_add(&cm, "kara", 0, 8), EOK);
-	TEST(char_map_find(&cm, "kara", 0), 8);
-	TEST(char_map_add(&cm, "nic", 0, 9), EOK);
-	TEST(char_map_find(&cm, "nic", 0), 9);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK);
-	TEST(char_map_find(&cm, "micni", 0), 9);
-	TEST(char_map_find(&cm, "micnicn", 5), 9);
-	TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
-	TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
-	
-	TEST((char_map_destroy(&cm), EOK), EOK);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	
-	printf("\nCRC computation test");
-	uint32_t value;
-	
-	TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926);
-	TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7);
-	TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd);
-	TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2);
-	TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3);
-	TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf);
-	TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706);
-	
-	printf("\nDynamic fifo test");
-	dyn_fifo_t fifo;
-	
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	TEST(dyn_fifo_initialize(&fifo, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 1);
-	TEST(dyn_fifo_pop(&fifo), ENOENT);
-	TEST(dyn_fifo_push(&fifo, 2, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 3, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 2);
-	TEST(dyn_fifo_pop(&fifo), 3);
-	TEST(dyn_fifo_push(&fifo, 4, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 5, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 6, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 7, 5), EOK);
-	TEST(dyn_fifo_pop(&fifo), 4);
-	TEST(dyn_fifo_pop(&fifo), 5);
-	TEST(dyn_fifo_push(&fifo, 8, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 9, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 10, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 11, 6), EOK);
-	TEST(dyn_fifo_pop(&fifo), 6);
-	TEST(dyn_fifo_pop(&fifo), 7);
-	TEST(dyn_fifo_push(&fifo, 12, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 13, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 14, 8), EOK);
-	TEST(dyn_fifo_pop(&fifo), 8);
-	TEST(dyn_fifo_pop(&fifo), 9);
-	TEST(dyn_fifo_pop(&fifo), 10);
-	TEST(dyn_fifo_pop(&fifo), 11);
-	TEST(dyn_fifo_pop(&fifo), 12);
-	TEST(dyn_fifo_pop(&fifo), 13);
-	TEST(dyn_fifo_pop(&fifo), 14);
-	TEST(dyn_fifo_destroy(&fifo), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	
-	printf("\nGeneric char map test");
-	
-	int *x;
-	int *y;
-	int *z;
-	int *u;
-	int *v;
-	int *w;
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_char_map_t icm;
-	icm.magic = 0;
-	
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	TEST(int_char_map_initialize(&icm), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_add(&icm, "bla", 0, x), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), x);
-	TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_add(&icm, "blabla", 0, v), EOK);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "bla", 0, w), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), w);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "auto", 0, u), EOK);
-	TEST(int_char_map_find(&icm, "auto", 0), u);
-	TEST((int_char_map_destroy(&icm), EOK), EOK);
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	
-	printf("\nGeneric field test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_field_t gf;
-	gf.magic = 0;
-	
-	TEST(int_field_add(&gf, x), EINVAL);
-	TEST(int_field_count(&gf), -1);
-	TEST(int_field_initialize(&gf), EOK);
-	TEST(int_field_count(&gf), 0);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_add(&gf, x), 0);
-	TEST(int_field_get_index(&gf, 0), x);
-	TEST((int_field_exclude_index(&gf, 0), EOK), EOK);
-	TEST(int_field_get_index(&gf, 0), NULL);
-	TEST(int_field_add(&gf, y), 1);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_add(&gf, z), 2);
-	TEST(int_field_get_index(&gf, 2), z);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_count(&gf), 3);
-	TEST(int_field_add(&gf, u), 3);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_add(&gf, v), 4);
-	TEST(int_field_get_index(&gf, 4), v);
-	TEST(int_field_add(&gf, w), 5);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST(int_field_count(&gf), 6);
-	TEST((int_field_exclude_index(&gf, 1), EOK), EOK);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST((int_field_exclude_index(&gf, 7), EOK), EOK);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST((int_field_exclude_index(&gf, 4), EOK), EOK);
-	TEST(int_field_get_index(&gf, 4), NULL);
-	TEST((int_field_destroy(&gf), EOK), EOK);
-	TEST(int_field_count(&gf), -1);
-	
-	printf("\nInt map test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_map_t im;
-	im.magic = 0;
-	
-	TEST(int_map_add(&im, 1, x), EINVAL);
-	TEST(int_map_count(&im), -1);
-	TEST(int_map_initialize(&im), EOK);
-	TEST(int_map_count(&im), 0);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, x), 0);
-	TEST(int_map_find(&im, 1), x);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, y), 1);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_add(&im, 4, z), 2);
-	TEST(int_map_get_index(&im, 2), z);
-	TEST(int_map_find(&im, 4), z);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_count(&im), 3);
-	TEST(int_map_add(&im, 2, u), 3);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_add(&im, 3, v), 4);
-	TEST(int_map_find(&im, 3), v);
-	TEST(int_map_get_index(&im, 4), v);
-	TEST(int_map_add(&im, 6, w), 5);
-	TEST(int_map_find(&im, 6), w);
-	TEST(int_map_count(&im), 6);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_find(&im, 2), u);
-	TEST((int_map_exclude(&im, 7), EOK), EOK);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_find(&im, 6), w);
-	TEST((int_map_exclude_index(&im, 4), EOK), EOK);
-	TEST(int_map_get_index(&im, 4), NULL);
-	TEST(int_map_find(&im, 3), NULL);
-	TEST((int_map_destroy(&im), EOK), EOK);
-	TEST(int_map_count(&im), -1);
-	
-	printf("\nMeasured strings test");
-	
-	measured_string_ref string =
-	    measured_string_create_bulk("I am a measured string!", 0);
-	printf("\n%x, %s at %x of %d\n", string, string->value, string->value,
-	    string->length);
-	
-	return EOK;
-}
-
-/** @}
- */
Index: pace/app/netstart/self_test.h
===================================================================
--- uspace/app/netstart/self_test.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-#ifndef __SELF_TEST_H__
-#define __SELF_TEST_H__
-
-extern int self_test(void);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -34,4 +34,5 @@
 INCLUDE_ARCH = include/arch
 INCLUDE_LIBARCH = include/libarch
+INCLUDE_RTLDARCH = rtld/include/arch
 
 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
@@ -45,12 +46,18 @@
 	$(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld
 
-PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
+PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(INCLUDE_RTLDARCH) $(COMMON_HEADER_ARCH)
 EXTRA_OUTPUT = $(LINKER_SCRIPTS)
-EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPTS)
+EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(INCLUDE_RTLDARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPTS)
 LIBRARY = libc
+SLIBRARY = libc.so.0.0
+LSONAME = libc.so.0
+
 
 -include $(COMMON_MAKEFILE)
 -include $(CONFIG_MAKEFILE)
 -include arch/$(UARCH)/Makefile.inc
+-include rtld/arch/$(UARCH)/Makefile.inc
+
+EXTRA_CFLAGS += -Irtld/include -I../../srv/loader/include
 
 GENERIC_SOURCES = \
@@ -64,4 +71,5 @@
 	generic/device/hw_res.c \
 	generic/device/char_dev.c \
+	generic/dlfcn.c \
 	generic/event.c \
 	generic/errno.c \
@@ -119,4 +127,9 @@
 	generic/stats.c \
 	generic/assert.c \
+	rtld/rtld.c \
+	rtld/elf_load.c \
+	rtld/dynamic.c \
+	rtld/module.c \
+	rtld/symbol.c
 
 SOURCES = \
@@ -131,4 +144,7 @@
 $(INCLUDE_LIBARCH): arch/$(UARCH)/include
 	ln -sfn ../$< $@
+
+$(INCLUDE_RTLDARCH): rtld/arch/$(UARCH)/include
+	ln -sfn ../../$< $@
 
 $(INCLUDE_KERNEL)/arch: ../../../kernel/generic/include/arch $(INCLUDE_KERNEL)
Index: uspace/lib/c/Makefile.toolchain
===================================================================
--- uspace/lib/c/Makefile.toolchain	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/Makefile.toolchain	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,94 @@
+#
+# Copyright (C) 2005 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+CFLAGS = -I$(LIBC_PREFIX)/include -O3 -imacros $(LIBC_PREFIX)/../../../config.h \
+	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
+	-finput-charset=UTF-8 -fno-builtin -Wall -Wextra -Wno-unused-parameter \
+	-Wmissing-prototypes -Werror-implicit-function-declaration -nostdlib \
+	-nostdinc -pipe -g -D__$(ENDIANESS)__
+LFLAGS = -M -N $(SOFTINT_PREFIX)/libsoftint.a
+AFLAGS =
+
+## Cross-toolchain prefix
+#
+
+ifndef CROSS_PREFIX
+	CROSS_PREFIX = /usr/local
+endif
+
+## Setup platform configuration
+#
+
+-include $(LIBC_PREFIX)/../../../Makefile.config
+-include $(LIBC_PREFIX)/../../../config.defs
+-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.inc
+
+## Simple detection of the host system
+#
+HOST = $(shell uname)
+
+## On Solaris, some utilities have different names
+#
+ifeq ($(HOST),SunOS)
+	BINUTILS_PREFIX = "g"
+else
+	BINUTILS_PREFIX = ""
+endif
+
+## Toolchain configuration
+#
+
+ifeq ($(COMPILER),gcc_native)
+	CC = gcc
+	AS = $(BINUTILS_PREFIX)as
+	LD = $(BINUTILS_PREFIX)ld
+	AR = $(BINUTILS_PREFIX)ar
+	OBJCOPY = $(BINUTILS_PREFIX)objcopy
+	OBJDUMP = $(BINUTILS_PREFIX)objdump
+	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
+endif
+
+ifeq ($(COMPILER),icc_native)
+	CC = icc
+	AS = as
+	LD = ld
+	AR = ar
+	OBJCOPY = objcopy
+	OBJDUMP = objdump
+	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
+endif
+
+ifeq ($(COMPILER),gcc_cross)
+	CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
+	AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
+	LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
+	AR = $(TOOLCHAIN_DIR)/$(TARGET)-ar
+	OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
+	OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
+	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
+endif
Index: uspace/lib/c/arch/amd64/include/limits.h
===================================================================
--- uspace/lib/c/arch/amd64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/amd64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcamd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_amd64_LIMITS_H_
+#define LIBC_amd64_LIMITS_H_
+
+# define LONG_MIN MIN_INT64
+# define LONG_MAX MAX_INT64
+# define ULONG_MIN MIN_UINT64
+# define ULONG_MAX MAX_UINT64
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/arm32/include/limits.h
===================================================================
--- uspace/lib/c/arch/arm32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/arm32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2007 Michal Kebrt
+ * 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 libcarm32	
+ * @{
+ */
+/** @file 
+ *  @brief Limits declarations.
+ */
+
+#ifndef LIBC_arm32__LIMITS_H_
+#define LIBC_arm32__LIMITS_H_
+
+#define LONG_MIN MIN_INT32
+#define LONG_MAX MAX_INT32
+#define ULONG_MIN MIN_UINT32
+#define ULONG_MAX MAX_UINT32
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/include/limits.h
===================================================================
--- uspace/lib/c/arch/ia32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/ia32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32__LIMITS_H_
+#define LIBC_ia32__LIMITS_H_
+
+# define LONG_MIN MIN_INT32
+# define LONG_MAX MAX_INT32
+# define ULONG_MIN MIN_UINT32
+# define ULONG_MAX MAX_UINT32
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/include/stackarg.h
===================================================================
--- uspace/lib/c/arch/ia32/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/ia32/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcia32
+ * @{
+ */
+/** @file
+ */
+
+/*
+ * Variable argument list manipulation macros
+ * for architectures using stack to pass arguments.
+ */
+ 
+#ifndef LIBC_ia32_STACKARG_H_
+#define LIBC_ia32_STACKARG_H_
+
+#include <sys/types.h>
+
+/* dont allow to define it second time in stdarg.h */
+#define __VARARGS_DEFINED
+
+typedef struct va_list {
+	int pos;
+	uint8_t *last;
+} va_list;
+
+#define va_start(ap, lst) \
+	(ap).pos = sizeof(lst); 			\
+	(ap).last = (uint8_t *) &(lst)
+
+#define va_arg(ap, type) 		\
+	(*((type *)((ap).last + ((ap).pos  += sizeof(type) ) - sizeof(type))))
+
+#define va_end(ap)
+
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ia32/src/syscall.S
===================================================================
--- uspace/lib/c/arch/ia32/src/syscall.S	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/arch/ia32/src/syscall.S	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -32,4 +32,5 @@
 __syscall_fast_func:
 	.long __syscall_slow
+	.size __syscall_fast_func, . - __syscall_fast_func
 
 .text
@@ -71,4 +72,6 @@
  */
 .global __syscall_fast
+	.type __syscall_fast, @function
+
 __syscall_fast:
 	pushl %ebx
@@ -95,2 +98,4 @@
 	popl %ebx
 	ret
+
+	.size __syscall_fast, . - __syscall_fast
Index: uspace/lib/c/arch/ia32/src/tls.c
===================================================================
--- uspace/lib/c/arch/ia32/src/tls.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/arch/ia32/src/tls.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -37,4 +37,5 @@
 #include <tls.h>
 #include <sys/types.h>
+#include <align.h>
 
 tcb_t * __alloc_tls(void **data, size_t size)
@@ -48,4 +49,31 @@
 }
 
+//#ifdef __SHARED__
+
+typedef struct {
+	unsigned long int ti_module;
+	unsigned long int ti_offset;
+} tls_index;
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti);
+
+void __attribute__ ((__regparm__ (1)))
+    *___tls_get_addr(tls_index *ti)
+{
+	size_t tls_size;
+	uint8_t *tls;
+
+	/* Calculate size of TLS block */
+	tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment);
+
+	/* The TLS block is just before TCB */
+	tls = (uint8_t *)__tcb_get() - tls_size;
+
+	return tls + ti->ti_offset;
+}
+
+//#endif
+
 /** @}
  */
Index: uspace/lib/c/arch/ia64/include/limits.h
===================================================================
--- uspace/lib/c/arch/ia64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/ia64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcia64	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia64_LIMITS_H_
+#define LIBC_ia64_LIMITS_H_
+
+# define LONG_MIN MIN_INT64
+# define LONG_MAX MAX_INT64
+# define ULONG_MIN MIN_UINT64
+# define ULONG_MAX MAX_UINT64
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/mips32/include/limits.h
===================================================================
--- uspace/lib/c/arch/mips32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/mips32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcmips32	
+ * @{
+ */
+/** @file
+ * @ingroup libcmips32eb	
+ */
+
+#ifndef LIBC_mips32__LIMITS_H_
+#define LIBC_mips32__LIMITS_H_
+
+# define LONG_MIN MIN_INT32
+# define LONG_MAX MAX_INT32
+# define ULONG_MIN MIN_UINT32
+# define ULONG_MAX MAX_UINT32
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/mips32/include/stackarg.h
===================================================================
--- uspace/lib/c/arch/mips32/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/mips32/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcmips32	
+ * @{
+ */
+/** @file
+ * @ingroup libcmips32eb	
+ */
+
+#ifndef LIBC_mips32_STACKARG_H_
+#define LIBC_mips32_STACKARG_H_
+
+/* dont allow to define it second time in stdarg.h */
+#define __VARARGS_DEFINED
+
+#include <sys/types.h>
+
+/**
+ * va_arg macro for MIPS32 - problem is that 64 bit values must be aligned on an 8-byte boundary (32bit values not)
+ * To satisfy this, paddings must be sometimes inserted. 
+ */
+
+typedef uint8_t* va_list;
+
+#define va_start(ap, lst) \
+	((ap) = (va_list)&(lst) + sizeof(lst))
+
+#define va_arg(ap, type)	\
+	(((type *)((ap) = (va_list)( (sizeof(type) <= 4) ? ((uint32_t)((ap) + 2*4 - 1) & (~3)) : ((uint32_t)((ap) + 2*8 -1) & (~7)) )))[-1])
+
+#define va_end(ap)
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/mips32/src/tls.c
===================================================================
--- uspace/lib/c/arch/mips32/src/tls.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/arch/mips32/src/tls.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -47,4 +47,24 @@
 }
 
+typedef struct {
+	unsigned long ti_module;
+	unsigned long ti_offset;
+} tls_index;
+
+void *__tls_get_addr(tls_index *ti);
+
+/* mips32 uses TLS variant 1 */
+void *__tls_get_addr(tls_index *ti)
+{
+	uint8_t *tls;
+	uint32_t v;
+
+	tls = (uint8_t *)__tcb_get() + sizeof(tcb_t);
+
+	/* Hopefully this is right. No docs found. */
+	v = (uint32_t) (tls + ti->ti_offset + 0x8000);
+	return (void *) v;
+}
+
 /** @}
  */
Index: uspace/lib/c/arch/mips32eb/include/limits.h
===================================================================
--- uspace/lib/c/arch/mips32eb/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/mips32eb/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+../../mips32/include/limits.h
Index: uspace/lib/c/arch/mips32eb/include/stackarg.h
===================================================================
--- uspace/lib/c/arch/mips32eb/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/mips32eb/include/stackarg.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+../../mips32/include/stackarg.h
Index: uspace/lib/c/arch/ppc32/include/limits.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/ppc32/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ppc32_LIMITS_H_
+#define LIBC_ppc32_LIMITS_H_
+
+#define LONG_MIN MIN_INT32
+#define LONG_MAX MAX_INT32
+#define ULONG_MIN MIN_UINT32
+#define ULONG_MAX MAX_UINT32
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/ppc32/src/tls.c
===================================================================
--- uspace/lib/c/arch/ppc32/src/tls.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/arch/ppc32/src/tls.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2006 Ondrej Palkovsky
+ * Copyright (c) 2008 Jiri Svoboda
  * All rights reserved.
  *
@@ -34,4 +35,5 @@
 
 #include <tls.h>
+#include <align.h>
 #include <sys/types.h>
 
@@ -46,4 +48,37 @@
 }
 
+/*
+static void kputint(unsigned i)
+{
+	asm volatile (
+		"mr %%r3, %0\n"
+		"li %%r9, 32\n"
+		"sc\n"
+		:
+		: "r" (i)
+		: "%r3","%r9"
+	) ;
+}
+*/
+
+typedef struct {
+	unsigned long int ti_module;
+	unsigned long int ti_offset;
+} tls_index;
+
+void *__tls_get_addr(tls_index *ti);
+
+/* ppc32 uses TLS variant 1 */
+void *__tls_get_addr(tls_index *ti)
+{
+	uint8_t *tls;
+
+	/* The TLS section is just after TCB */
+	tls = (uint8_t *)__tcb_get() + sizeof(tcb_t);
+
+	/* Hopefully this is right. No docs found. */
+	return tls + ti->ti_offset + 32768;
+}
+
 /** @}
  */
Index: uspace/lib/c/arch/sparc64/include/limits.h
===================================================================
--- uspace/lib/c/arch/sparc64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/arch/sparc64/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 libcsparc64	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_sparc64_LIMITS_H_
+#define LIBC_sparc64_LIMITS_H_
+
+#define LONG_MIN MIN_INT64
+#define LONG_MAX MAX_INT64
+#define ULONG_MIN MIN_UINT64
+#define ULONG_MAX MAX_UINT64
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/generic/dlfcn.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+/* From librtld. */
+#include <module.h>
+#include <symbol.h>
+
+void *dlopen(const char *path, int flag)
+{
+	module_t *m;
+
+	if (runtime_env == NULL) {
+		printf("Dynamic linker not set up -- initializing.\n");
+		rtld_init_static();
+	}
+
+	printf("dlopen(\"%s\", %d)\n", path, flag);
+
+	printf("module_find('%s')\n", path);
+	m = module_find(path);
+	if (m == NULL) {
+		printf("NULL. module_load('%s')\n", path);
+		m = module_load(path);
+		printf("module_load_deps(m)\n");
+		module_load_deps(m);
+		/* Now relocate. */
+		printf("module_process_relocs(m)\n");
+		module_process_relocs(m);
+	} else {
+		printf("not NULL\n");
+	}
+
+	return (void *) m;
+}
+
+/*
+ * @note Symbols with NULL values are not accounted for.
+ */
+void *dlsym(void *mod, const char *sym_name)
+{
+	elf_symbol_t *sd;
+	module_t *sm;
+
+	printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
+	sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
+	if (sd != NULL) {
+		return symbol_get_addr(sd, sm);
+	}
+
+	return NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/err.c
===================================================================
--- uspace/lib/c/generic/err.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/generic/err.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* TODO
+void errx(int __status, __const char *__format, ...)
+{
+	_exit(0);
+}
+*/
+
+/** @}
+ */
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/generic/libc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -53,4 +53,8 @@
 #include "private/io.h"
 
+/* From librtld. */
+#include <rtld.h>
+//#include <string.h>
+
 static bool env_setup = false;
 
@@ -77,4 +81,9 @@
 	char **argv;
 	
+#ifdef __IN_SHARED_LIBC__
+	if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
+		runtime_env = (runtime_env_t *) __pcb->rtld_runtime;
+	}
+#endif
 	/*
 	 * Get command line arguments and initialize
Index: uspace/lib/c/include/as.h
===================================================================
--- uspace/lib/c/include/as.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/include/as.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -56,5 +56,5 @@
 extern void *as_area_create(void *address, size_t size, int flags);
 extern int as_area_resize(void *address, size_t size, int flags);
-extern int as_area_change_flags(void *address, int flags);
+int as_area_change_flags(void *address, int flags);
 extern int as_area_destroy(void *address);
 extern void *set_maxheapsize(size_t mhs);
Index: uspace/lib/c/include/dlfcn.h
===================================================================
--- uspace/lib/c/include/dlfcn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/include/dlfcn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup rtld
+ * @{
+ */
+/** @file
+ * @brief UNIX-like dynamic linker interface.
+ */
+
+#ifndef LIBC_DLFCN_H_
+#define LIBC_DLFCN_H_
+
+void *dlopen(const char *, int);
+void *dlsym(void *, const char *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/c/include/limits.h
===================================================================
--- uspace/lib/c/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/include/limits.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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_LIMITS_H_
+#define LIBC_LIMITS_H_
+
+#include <stdint.h>
+#include <libarch/limits.h>
+
+/* char */
+#define SCHAR_MIN MIN_INT8
+#define SCHAR_MAX MAX_INT8
+#define UCHAR_MIN MIN_UINT8
+#define UCHAR_MAX MAX_UINT8
+
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN UCHAR_MIN
+# define CHAR_MAX UCHAR_MAX
+#else
+# define CHAR_MIN SCHAR_MIN
+# define CHAR_MAX SCHAR_MAX
+#endif
+
+/* short int */
+#define SHRT_MIN MIN_INT16
+#define SHRT_MAX MAX_INT16
+#define USHRT_MIN MIN_UINT16
+#define USHRT_MAX MAX_UINT16
+
+#define INT_MIN MIN_INT32
+#define INT_MAX MAX_INT32
+#define UINT_MIN MIN_UINT32
+#define UINT_MAX MAX_UINT32
+
+#define LLONG_MIN MIN_INT64
+#define LLONG_MAX MAX_INT64
+#define ULLONG_MIN MIN_UINT64
+#define ULLONG_MAX MAX_UINT64
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/loader/pcb.h
===================================================================
--- uspace/lib/c/include/loader/pcb.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/c/include/loader/pcb.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -72,4 +72,6 @@
 	/** Pointer to ELF dynamic section of the program. */
 	void *dynamic;
+	/** Pointer to dynamic linker state structure (runtime_env_t). */
+	void *rtld_runtime;
 } pcb_t;
 
Index: uspace/lib/c/libc.so.0
===================================================================
--- uspace/lib/c/libc.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/libc.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+libc.so.0.0
Index: uspace/lib/c/rtld/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/rtld/arch/ia32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ia32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+CFLAGS += -D__32_BITS__
+
+ARCH_SOURCES += \
+	rtld/arch/$(UARCH)/src/dynamic.c \
+	rtld/arch/$(UARCH)/src/reloc.c
Index: uspace/lib/c/rtld/arch/ia32/include/dynamic.h
===================================================================
--- uspace/lib/c/rtld/arch/ia32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ia32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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/rtld/arch/ia32/include/elf_dyn.h
===================================================================
--- uspace/lib/c/rtld/arch/ia32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ia32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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/rtld/arch/ia32/src/dynamic.c
===================================================================
--- uspace/lib/c/rtld/arch/ia32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ia32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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/rtld/arch/ia32/src/reloc.c
===================================================================
--- uspace/lib/c/rtld/arch/ia32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ia32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 <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;
+}
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/rtld/arch/mips32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/mips32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+CFLAGS += -D__32_BITS__
+
+ARCH_SOURCES += \
+	rtld/arch/$(UARCH)/src/dynamic.c \
+	rtld/arch/$(UARCH)/src/reloc.c
Index: uspace/lib/c/rtld/arch/mips32/include/dynamic.h
===================================================================
--- uspace/lib/c/rtld/arch/mips32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/mips32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 mips32_DYNAMIC_H_
+#define mips32_DYNAMIC_H_
+
+#include <sys/types.h>
+
+typedef struct {
+	/** Number of local entries in GOT. */
+	uint32_t lgotno;
+	/** Index of first GOT-mapped dynamic symbol. */
+	uint32_t gotsym;
+	/** Number of entries in dynamic symbol table. */
+	uint32_t sym_no;
+	/** ???. */
+	uint32_t base;
+} dyn_info_arch_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/mips32/include/elf_dyn.h
===================================================================
--- uspace/lib/c/rtld/arch/mips32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/mips32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,58 @@
+/*
+ * 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 mips32_ELF_DYN_H_
+#define mips32_ELF_DYN_H_
+
+/*
+ * mips32 program header types
+ */
+#define DT_MIPS_BASE_ADDRESS	0x70000006
+#define DT_MIPS_LOCAL_GOTNO	0x7000000a
+#define DT_MIPS_SYMTABNO	0x70000011
+#define DT_MIPS_GOTSYM		0x70000013
+
+/* 
+ * mips32 relocation types
+ */
+
+#define R_MIPS_NONE		0
+#define R_MIPS_REL32		3
+
+#define R_MIPS_TLS_DTPMOD32	333 /* fixme */
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/mips32/src/dynamic.c
===================================================================
--- uspace/lib/c/rtld/arch/mips32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/mips32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,61 @@
+/*
+ * 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 *d_ptr;
+	elf_word d_val;
+
+//	d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
+	d_val = dp->d_un.d_val;
+
+	switch (dp->d_tag) {
+	case DT_MIPS_BASE_ADDRESS: info->arch.base = d_val; break;
+	case DT_MIPS_LOCAL_GOTNO: info->arch.lgotno = d_val; break;
+	case DT_MIPS_SYMTABNO:	info->arch.sym_no = d_val; break;
+	case DT_MIPS_GOTSYM:	info->arch.gotsym = d_val; break;
+	default: break;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/mips32/src/reloc.c
===================================================================
--- uspace/lib/c/rtld/arch/mips32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/mips32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,265 @@
+/*
+ * 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 <symbol.h>
+#include <rtld.h>
+#include <rtld_debug.h>
+
+#include <rtld_arch.h>
+
+void module_process_pre_arch(module_t *m)
+{
+	elf_symbol_t *sym_table;
+	elf_symbol_t *sym_def;
+	elf_symbol_t *sym;
+	uint32_t gotsym;
+	uint32_t lgotno;
+	uint32_t *got;
+	char *str_tab;
+	unsigned i, j;
+
+	uint32_t sym_addr;
+	module_t *dest;
+
+	got = (uint32_t *) m->dyn.plt_got;
+	sym_table = m->dyn.sym_tab;
+	str_tab = m->dyn.str_tab;
+	gotsym = m->dyn.arch.gotsym;
+	lgotno = m->dyn.arch.lgotno;
+
+	DPRINTF("** Relocate GOT entries **\n");
+	DPRINTF("MIPS base = 0x%x\n", m->dyn.arch.base);
+
+	/*
+	 * Local entries.
+	 */
+	for (i = 0; i < gotsym; i++) {
+		/* FIXME: really subtract MIPS base? */
+		got[i] += m->bias - m->dyn.arch.base;
+	}
+
+	DPRINTF("sym_ent = %d, gotsym = %d\n", m->dyn.arch.sym_no, gotsym);
+	DPRINTF("lgotno = %d\n", lgotno);
+
+	/*
+	 * Iterate over GOT-mapped symbol entries.
+	 */
+	for (j = gotsym; j < m->dyn.arch.sym_no; j++) {
+		/* Corresponding (global) GOT entry. */
+		i = lgotno + j - gotsym;
+
+		DPRINTF("relocate GOT entry %d\n", i);
+//		getchar();
+//		getchar();
+
+		sym = &sym_table[j];
+		if (ELF32_R_TYPE(sym->st_info) == STT_FUNC) {
+			if (sym->st_shndx == SHN_UNDEF) {
+				if (sym->st_value == 0) {
+					/* 1 */
+				} else {
+					if (got[i] == sym->st_value) {
+						/* 2 */
+						DPRINTF("(2)\n");
+						got[i] += m->bias - m->dyn.arch.base;
+						continue;
+					} else {
+						/* 3 */
+						DPRINTF("(3)\n");
+						got[i] = sym->st_value + m->bias - m->dyn.arch.base;
+						continue;
+					}
+				}
+			} else {
+				/* 2 */
+				DPRINTF("(2)\n");
+				got[i] += m->bias - m->dyn.arch.base;
+				continue;
+			}
+		} else {
+			if (sym->st_shndx == SHN_UNDEF ||
+			    sym->st_shndx == SHN_COMMON) {
+				/* 1 */
+			} else {
+				/* 1 */
+			}
+		}
+		
+		DPRINTF("(1) symbol name='%s'\n", str_tab + sym->st_name);
+		sym_def = symbol_def_find(str_tab + sym->st_name, m, &dest);
+		if (sym_def) {
+			sym_addr = (uintptr_t) symbol_get_addr(sym_def, dest);
+			DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
+		} else {
+			DPRINTF("symbol definition not found\n");
+			continue;
+		}
+		DPRINTF("write 0x%x at 0x%x\n", sym_addr, (uint32_t) &got[i]);
+		got[i] = sym_addr;
+	}
+
+	DPRINTF("** Done **\n");
+}
+
+/**
+ * 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;
+	uintptr_t sym_addr;
+	
+	elf_symbol_t *sym_table;
+	elf_symbol_t *sym;
+	uint32_t *r_ptr;
+/*	uint16_t *r_ptr16;*/
+	char *str_tab;
+	
+	elf_symbol_t *sym_def;
+	module_t *dest;
+
+	uint32_t *got;
+	uint32_t gotsym;
+	uint32_t lgotno;
+	uint32_t ea;
+
+	DPRINTF("parse relocation table\n");
+
+	sym_table = m->dyn.sym_tab;
+	rt_entries = rt_size / sizeof(elf_rela_t);
+	str_tab = m->dyn.str_tab;
+	got = (uint32_t *) m->dyn.plt_got;
+	gotsym = m->dyn.arch.gotsym;
+	lgotno = m->dyn.arch.lgotno;
+
+	DPRINTF("got=0x%x, gotsym=%d\n", (uintptr_t) got, gotsym);
+
+	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);
+		/*r_ptr16 = (uint16_t *)(r_offset + m->bias);*/
+
+		if (sym->st_name != 0) {
+			DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
+			DPRINTF("dest name: '%s'\n", dest->dyn.soname);
+			DPRINTF("dest bias: 0x%x\n", dest->bias);
+			if (sym_def) {
+				sym_addr = (uintptr_t) symbol_get_addr(sym_def,
+				    dest);
+				DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
+			} else {
+				DPRINTF("symbol definition not found\n");
+				continue;
+			}
+		} else {
+			sym_def = NULL;
+			sym_addr = 0;
+		}
+
+		DPRINTF("switch(%u)\n", rel_type);
+
+		switch (rel_type) {
+		case R_MIPS_NONE:
+			DPRINTF("Ignoring R_MIPS_NONE\n");
+			break;
+
+		case R_MIPS_REL32:
+			DPRINTF("fixup R_MIPS_REL32 (r - ea + s)\n");
+			if (sym_idx < gotsym)
+				ea = sym_addr;
+			else
+				ea = got[lgotno + sym_idx - gotsym];
+
+			*r_ptr += sym_addr - ea;
+			DPRINTF("p = 0x%x, val := 0x%x\n", (uint32_t) r_ptr,
+			    *r_ptr);
+//			getchar();
+			break;
+
+		/* No other non-TLS relocation types should appear. */
+
+		case R_MIPS_TLS_DTPMOD32:
+			/*
+			 * We can ignore this as long as the only module
+			 * with TLS variables is libc.so.
+			 */
+			DPRINTF("Ignoring R_MIPS_DTPMOD32\n");
+			break;
+
+		default:
+			printf("Error: Unknown relocation type %d.\n",
+			    rel_type);
+			exit(1);
+			break;
+		}
+	}
+
+
+	printf("relocation done\n");
+}
+
+void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size)
+{
+	/* Unused */
+	(void)m; (void)rt; (void)rt_size;
+}
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/c/rtld/arch/ppc32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ppc32/Makefile.inc	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+CFLAGS += -D__32_BITS__
+
+ARCH_SOURCES += \
+	rtld/arch/$(UARCH)/src/dynamic.c \
+	rtld/arch/$(UARCH)/src/reloc.c
Index: uspace/lib/c/rtld/arch/ppc32/include/dynamic.h
===================================================================
--- uspace/lib/c/rtld/arch/ppc32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ppc32/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 ppc32_DYNAMIC_H_
+#define ppc32_DYNAMIC_H_
+
+#include <sys/types.h>
+
+typedef struct {
+	/* Empty. */
+} dyn_info_arch_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/ppc32/include/elf_dyn.h
===================================================================
--- uspace/lib/c/rtld/arch/ppc32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ppc32/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,56 @@
+/*
+ * 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 ppc32_ELF_DYN_H_
+#define ppc32_ELF_DYN_H_
+
+/* 
+ * ppc32 dynamic relocation types
+ */
+
+#define R_PPC_ADDR32	1
+#define R_PPC_ADDR16_LO	4
+#define R_PPC_ADDR16_HI	5
+#define R_PPC_ADDR16_HA	6
+#define R_PPC_REL24	10
+#define R_PPC_COPY	19
+#define R_PPC_JMP_SLOT	21
+#define R_PPC_RELATIVE	22
+
+#define R_PPC_DTPMOD32	68
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/rtld/arch/ppc32/src/dynamic.c
===================================================================
--- uspace/lib/c/rtld/arch/ppc32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ppc32/src/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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/rtld/arch/ppc32/src/reloc.c
===================================================================
--- uspace/lib/c/rtld/arch/ppc32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/arch/ppc32/src/reloc.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,300 @@
+/*
+ * 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 <symbol.h>
+#include <rtld.h>
+#include <rtld_debug.h>
+#include <smc.h>
+
+#include <rtld_arch.h>
+
+#define __L(ptr) ((uint32_t)(ptr) & 0x0000ffff)
+#define __HA(ptr) ((uint32_t)(ptr) >> 16)
+
+// ldis r11, .PLTtable@ha
+static inline uint32_t _ldis(unsigned rD, uint16_t imm16)
+{
+	/* Special case of addis: ldis rD,SIMM == addis rD,0,SIMM */
+	return 0x3C000000 | (rD << 21) | imm16;
+}
+
+static inline uint32_t _lwz(unsigned rD, uint16_t disp16, unsigned rA)
+{
+	return 0x80000000 | (rD << 21) | (rA << 16) | disp16;
+}
+
+static inline uint32_t _mtctr(unsigned rS)
+{
+	/* mtctr rD == mtspr 9, rD */
+	return 0x7c0003a6 | (rS << 21) | (9/*CTR*/ << 16);
+}
+
+static inline uint32_t _bctr()
+{
+	/* bcctr 0x1f, 0 */
+	return 0x4c000420 | (0x1f/*always*/ << 21);
+}
+
+/* branch */
+static inline uint32_t _b(uint32_t *addr, uint32_t *location)
+{
+	uint32_t raddr = ((uint32_t)addr - (uint32_t)location) & 0x03fffffc;
+	return 0x48000000 | raddr;
+}
+
+
+/*
+ * Fill in PLT
+ */
+void module_process_pre_arch(module_t *m)
+{
+	uint32_t *plt;
+//	uint32_t *_plt_ent;
+	
+	/* No lazy linking -- no pre-processing yet. */
+	return;
+
+	plt = m->dyn.plt_got;
+	if (!plt) {
+		/* Module has no PLT */
+		return;
+	}
+
+	// PLT entries start here. However, each occupies 2 words
+//	_plt_ent = plt + 18;
+
+	// By definition of the ppc ABI, there's 1:1 correspondence
+	// between JMPREL entries and PLT entries
+	unsigned plt_n = m->dyn.plt_rel_sz / sizeof(elf_rela_t);
+
+	uint32_t *_plt_table;
+//	uint32_t *_plt_call;
+//	uint32_t *_plt_resolve;
+
+//	_plt_resolve = plt;
+//	_plt_call = plt + 6;
+	_plt_table = plt + 18 + plt_n;
+
+/* .PLTcall: */
+	plt[6] = _ldis(11, __HA(_plt_table));	// ldis r11, .PLTtable@ha
+	plt[7] = _lwz(11, __L(_plt_table), 11);	// lwz r11, .PLTtable@l(r11)
+	plt[8] = _mtctr(11);			// mtctr r11
+	plt[9] = _bctr();
+
+/* .PLTi, i = 0..N-1 */
+//	kputint(-4);
+/*	for (i = 0; i < plt_n; ++i) {
+		//_plt_table[i] == function address;
+		plt[18+i] = _b(_plt_call, &plt[18+i]);	// b .PLTcall
+	}*/
+}
+
+void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
+{
+	/* Unused */
+	(void)m; (void)rt; (void)rt_size;
+}
+
+/**
+ * Process (fixup) all relocations in a relocation table.
+ */
+void rela_table_process(module_t *m, elf_rela_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;
+	uintptr_t sym_addr;
+	uintptr_t r_addend;
+	
+	elf_symbol_t *sym_table;
+	elf_symbol_t *sym;
+	uint32_t *r_ptr;
+	uint16_t *r_ptr16;
+	char *str_tab;
+	
+	elf_symbol_t *sym_def;
+	module_t *dest;
+
+	uint32_t *plt;
+//	uint32_t *_plt_table;
+	uint32_t *_plt_ent;
+	uint32_t plt_n;
+	uint32_t pidx;
+	uint32_t t_addr;
+	uint32_t sym_size;
+
+	plt = m->dyn.plt_got;
+	plt_n = m->dyn.plt_rel_sz / sizeof(elf_rela_t);
+	_plt_ent = plt+ 18;
+//	_plt_table = plt + 18 + plt_n;
+
+	DPRINTF("parse relocation table\n");
+
+	sym_table = m->dyn.sym_tab;
+	rt_entries = rt_size / sizeof(elf_rela_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;
+		r_addend = rt[i].r_addend;
+
+		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);
+		r_ptr16 = (uint16_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 = (uintptr_t) symbol_get_addr(
+				    sym_def, dest);
+				DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
+			} else {
+				DPRINTF("symbol definition not found\n");
+				continue;
+			}
+		} else {
+			sym_def = NULL;
+			sym_addr = 0;
+		}
+
+		switch (rel_type) {
+		case R_PPC_ADDR16_LO:
+			DPRINTF("fixup R_PPC_ADDR16_LO (#lo(s+a))\n");
+			*r_ptr16 = (sym_addr + r_addend) & 0xffff;
+			break;
+
+		case R_PPC_ADDR16_HI:
+			DPRINTF("fixup R_PPC_ADDR16_HI (#hi(s+a))\n");
+			*r_ptr16 = (sym_addr + r_addend) >> 16;
+			break;
+
+		case R_PPC_ADDR16_HA:
+			DPRINTF("fixup R_PPC_ADDR16_HA (#ha(s+a))\n");
+			t_addr = sym_addr + r_addend;
+			*r_ptr16 = (t_addr >> 16) + ((t_addr & 0x8000) ? 1 : 0);
+			break;
+
+		case R_PPC_JMP_SLOT:
+			DPRINTF("fixup R_PPC_JMP_SLOT (b+v)\n");
+			pidx = (r_ptr - _plt_ent) / 2;
+			if (pidx >= plt_n) {
+				DPRINTF("error: proc index out of range\n");
+				exit(1);
+			}
+			plt[18+2*pidx] = _b((void *)sym_addr, &plt[18+2*pidx]);
+			break;
+
+		case R_PPC_ADDR32:
+			DPRINTF("fixup R_PPC_ADDR32 (b+v+a)\n");
+			*r_ptr = r_addend + sym_addr;
+			break;
+
+		case R_PPC_COPY:
+			/*
+			 * Copy symbol data from shared object to specified
+			 * location.
+			 */
+			DPRINTF("fixup R_PPC_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_PPC_RELATIVE:
+			DPRINTF("fixup R_PPC_RELATIVE (b+a)\n");
+			*r_ptr = r_addend + m->bias;
+			break;
+
+		case R_PPC_REL24:
+			DPRINTF("fixup R_PPC_REL24 (s+a-p)>>2\n");
+			*r_ptr = (sym_addr + r_addend - (uint32_t)r_ptr) >> 2;
+			break;
+
+		case R_PPC_DTPMOD32:
+			/*
+			 * We can ignore this as long as the only module
+			 * with TLS variables is libc.so.
+			 */
+			DPRINTF("Ignoring R_PPC_DTPMOD32\n");
+			break;
+
+		default:
+			printf("Error: Unknown relocation type %d.\n",
+			    rel_type);
+			exit(1);
+			break;
+		}
+	}
+
+	/*
+	 * Synchronize the used portion of PLT. This is necessary since
+	 * we are writing instructions.
+	 */
+	smc_coherence(&plt[18], plt_n * 2 * sizeof(uint32_t));
+}
+
+/** @}
+ */
Index: uspace/lib/c/rtld/dynamic.c
===================================================================
--- uspace/lib/c/rtld/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/dynamic.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,143 @@
+/*
+ * 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/elf_load.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+../../../srv/loader/elf_load.c
Index: uspace/lib/c/rtld/include/dynamic.h
===================================================================
--- uspace/lib/c/rtld/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/dynamic.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef DYNAMIC_H_
+#define DYNAMIC_H_
+
+#include <bool.h>
+#include <elf_dyn.h>
+#include <arch/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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/elf_dyn.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef ELF_DYN_H_
+#define ELF_DYN_H_
+
+#include <arch/elf.h>
+#include <sys/types.h>
+
+#include <elf.h>
+#include <arch/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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/module.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/rtld.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/rtld_arch.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/rtld_debug.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/include/symbol.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/module.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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.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);
+	printf("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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/rtld.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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.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 f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/rtld/symbol.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,233 @@
+/*
+ * 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);
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/c/shared/arch/ia32/_lib.ld.in
===================================================================
--- uspace/lib/c/shared/arch/ia32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/ia32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,84 @@
+ENTRY(__entry)
+
+PHDRS {
+        text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+
+	.bss : {
+                *(COMMON);
+                *(.bss);
+	} :data
+
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+	
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: uspace/lib/c/shared/arch/ia32/_link.ld.in
===================================================================
--- uspace/lib/c/shared/arch/ia32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/ia32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,94 @@
+STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
+ENTRY(__entry)
+
+PHDRS {
+        text PT_LOAD FLAGS(5);
+	interp PT_INTERP;
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.interp : {
+		*(.interp);
+	} :interp
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+
+	.bss : {
+                *(COMMON);
+                *(.bss);
+	} :data
+
+/*	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+*/	
+	/DISCARD/ : {
+		*(.comment);
+	}
+
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: uspace/lib/c/shared/arch/mips32/_lib.ld.in
===================================================================
--- uspace/lib/c/shared/arch/mips32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/mips32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,95 @@
+ENTRY(__entry)
+
+PHDRS {
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x4000 + SIZEOF_HEADERS;
+	
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+	        *(.text);
+		*(.rodata*);
+		*(.MIPS.stubs);
+	} :text
+
+	.hash : {
+		*(.hash);
+	} : text
+
+	.reginfo : {
+		*(.reginfo);
+	} : text
+
+	.rel.plt : {
+		*(.rel.plt);
+	} : text
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} : text
+
+	.dynsym : {
+		*(.dynsym);
+	} : text
+
+	.dynstr : {
+		*(.dynstr);
+	} : text
+
+	. = . + 0x4000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+		*(.data.rel*);
+	} :data
+
+	.got : {
+		_gp = .;
+		*(.got);
+	} :data
+
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+
+	.sbss : {
+		*(.scommon);
+		*(.sbss);
+	}	
+	.bss : {
+		*(.bss);
+		*(COMMON);
+	} :data
+
+	. = ALIGN(0x4000);
+	_heap = .;
+
+/*	/DISCARD/ : {
+		*(*);
+	}*/
+}
Index: uspace/lib/c/shared/arch/mips32/_link.ld.in
===================================================================
--- uspace/lib/c/shared/arch/mips32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/mips32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,104 @@
+STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
+ENTRY(__entry)
+
+PHDRS {
+	interp PT_INTERP;
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x4000 + SIZEOF_HEADERS;
+
+	.interp : {
+		*(.interp);
+	} :text :interp
+
+	/* Align on word boundary -- instructions will follow. */
+	. = ALIGN(4);
+	
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+	        *(.text);
+		*(.rodata*);
+		*(.MIPS.stubs);
+	} :text
+
+	.hash : {
+		*(.hash);
+	} : text
+
+	.reginfo : {
+		*(.reginfo);
+	} : text
+
+	.rel.plt : {
+		*(.rel.plt);
+	} : text
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} : text
+
+	.dynsym : {
+		*(.dynsym);
+	} : text
+
+	.dynstr : {
+		*(.dynstr);
+	} : text
+
+	. = . + 0x4000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+		*(.data.rel*);
+	} :data
+
+	.got : {
+		_gp = .;
+		*(.got);
+	} :data
+/*
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+*/
+	.sbss : {
+		*(.scommon);
+		*(.sbss);
+	}	
+	.bss : {
+		*(.bss);
+		*(COMMON);
+	} :data
+
+	. = ALIGN(0x4000);
+	_heap = .;
+
+/*	/DISCARD/ : {
+		*(*);
+	}*/
+}
Index: uspace/lib/c/shared/arch/ppc32/_lib.ld.in
===================================================================
--- uspace/lib/c/shared/arch/ppc32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/ppc32/_lib.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,85 @@
+ENTRY(__entry)
+
+PHDRS {
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+		*(.sdata);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+	.bss : {
+		*(.sbss);
+		*(COMMON);
+		*(.bss);
+	} :data
+
+	.plt : {
+		*(.plt);
+	} :data
+
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: uspace/lib/c/shared/arch/ppc32/_link.ld.in
===================================================================
--- uspace/lib/c/shared/arch/ppc32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/c/shared/arch/ppc32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,100 @@
+STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
+ENTRY(__entry)
+
+PHDRS {
+	interp PT_INTERP;
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.interp : {
+		*(.interp);
+	} :text :interp
+
+	/* Align on word boundary -- instructions will follow. */
+	. = ALIGN(4);
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	} :text
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+		*(.sdata);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+
+/*	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+*/
+	.bss : {
+		*(.sbss);
+		*(COMMON);
+		*(.bss);
+	} :data
+
+	.plt : {
+		*(.plt);
+	} :data
+
+	/DISCARD/ : {
+		*(.comment);
+		*(.gnu.attributes);
+	}
+
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: pace/lib/packet/include/netdb.h
===================================================================
--- uspace/lib/packet/include/netdb.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,109 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 netdb
- *  @{
- */
-
-/** @file
- *  Structures and interfaces according to the BSD netdb.h file.
- */
-
-#ifndef __NET_NETDB_H__
-#define __NET_NETDB_H__
-
-#include <sys/types.h>
-
-/** Structure returned by network data base library.
- *  All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
- */
-struct	hostent {
-	/** Official host name.
-	 */
-	char * h_name;
-	/** Alias list.
-	 */
-	char **	h_aliases;
-	/** Host address type.
-	 */
-	int h_addrtype;
-	/** Address length.
-	 */
-	int h_length;
-	/** List of addresses from name server.
-	 */
-	char **	h_addr_list;
-	/** Address, for backward compatiblity.
-	 */
-#define	h_addr	h_addr_list[0]
-};
-
-/** @name Host entry address types definitions.
- */
-/*@{*/
-
-/** Authoritative Answer Host not found address type.
- */
-#define	HOST_NOT_FOUND	1
-
-/** Non-Authoritive Host not found, or SERVERFAIL address type.
- */
-#define	TRY_AGAIN	2
-
-/** Non recoverable errors, FORMERR, REFUSED, NOTIMP address type.
- */
-#define	NO_RECOVERY	3
-
-/** Valid name, no data record of requested type address type.
- */
-#define	NO_DATA		4
-
-/** No address, look for MX record address type.
- */
-#define	NO_ADDRESS	NO_DATA
-
-/*@}*/
-
-/** Returns host entry by the host address.
- *  @param[in] address The host address.
- *  @param[in] len The address length.
- *  @param[in] type The address type.
- *  @returns Host entry information.
- */
-//struct hostent *	gethostbyaddr(const void * address, int len, int type);
-
-/** Returns host entry by the host name.
- *  @param[in] name The host name.
- *  @returns Host entry information.
- */
-//struct hostent *	gethostbyname(const char * name);
-
-#endif
-
-/** @}
- */
Index: pace/lib/packet/include/tcp_codes.h
===================================================================
--- uspace/lib/packet/include/tcp_codes.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 tcp
- *  @{
- */
-
-/** @file
- *  TCP options definitions.
- */
-
-#ifndef __NET_TCP_CODES_H__
-#define __NET_TCP_CODES_H__
-
-/** End of list TCP option.
- */
-#define TCPOPT_END_OF_LIST				0x0
-
-/** No operation TCP option.
- */
-#define TCPOPT_NO_OPERATION				0x1
-
-/** Maximum segment size TCP option.
- */
-#define TCPOPT_MAX_SEGMENT_SIZE			0x2
-
-/** Maximum segment size TCP option length.
- */
-#define TCPOPT_MAX_SEGMENT_SIZE_LENGTH	4
-
-/** Window scale TCP option.
- */
-#define TCPOPT_WINDOW_SCALE				0x3
-
-/** Window scale TCP option length.
- */
-#define TCPOPT_WINDOW_SCALE_LENGTH		3
-
-/** Selective acknowledgement permitted TCP option.
- */
-#define TCPOPT_SACK_PERMITTED			0x4
-
-/** Selective acknowledgement permitted TCP option length.
- */
-#define TCPOPT_SACK_PERMITTED_LENGTH	2
-
-/** Selective acknowledgement TCP option.
- *  Has variable length.
- */
-#define TCPOPT_SACK						0x5
-
-/** Timestamp TCP option.
- */
-#define TCPOPT_TIMESTAMP				0x8
-
-/** Timestamp TCP option length.
- */
-#define TCPOPT_TIMESTAMP_LENGTH			10
-
-#endif
-
-/** @}
- */
Index: uspace/lib/softint/Makefile
===================================================================
--- uspace/lib/softint/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/lib/softint/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -31,4 +31,6 @@
 EXTRA_CFLAGS = -Iinclude
 LIBRARY = libsoftint
+SLIBRARY = libsoftint.so.0.0
+LSONAME = libsoftint.so.0
 
 SOURCES = \
Index: uspace/lib/softint/libsoftint.so.0
===================================================================
--- uspace/lib/softint/libsoftint.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/softint/libsoftint.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+libsoftint.so.0.0
Index: uspace/lib/test/Makefile
===================================================================
--- uspace/lib/test/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = libtest
+SLIBRARY = libtest.so.0.0
+LSONAME = libtest.so.0
+
+SOURCES = \
+	libtest.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/test/arch/ia32/_link.ld.in
===================================================================
--- uspace/lib/test/arch/ia32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/arch/ia32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,85 @@
+ENTRY(__entry)
+
+PHDRS {
+        text PT_LOAD FLAGS(5);
+	interp PT_INTERP;
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} :text
+
+	.dynamic : {
+		*(.dynamic);
+	} :text :dynamic
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.data : {
+		*(.data);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+
+	.bss : {
+                *(COMMON);
+                *(.bss);
+	} :data
+/*
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+*/	
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: uspace/lib/test/arch/mips32/_link.ld.in
===================================================================
--- uspace/lib/test/arch/mips32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/arch/mips32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,91 @@
+ENTRY(__entry)
+
+PHDRS {
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x4000 + SIZEOF_HEADERS;
+	
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+	        *(.text);
+		*(.rodata*);
+		*(.MIPS.stubs);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.plt : {
+		*(.plt);
+	} :text
+
+	.hash : {
+		*(.hash);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	.dynamic : {
+		*(.dynamic);
+	} :text :dynamic
+
+	. = . + 0x4000;
+
+	.data : {
+		*(.data);
+		*(.data.rel*);
+	} :data
+
+	.got : {
+		_gp = .;
+		*(.got);
+	} :data
+/*
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+*/
+	.sbss : {
+		*(.scommon);
+		*(.sbss);
+	}
+	.bss : {
+		*(.bss);
+		*(COMMON);
+	} :data
+
+	. = ALIGN(0x4000);
+	_heap = .;
+
+	/DISCARD/ : {
+		*(*);
+	}
+}
Index: uspace/lib/test/arch/ppc32/_link.ld.in
===================================================================
--- uspace/lib/test/arch/ppc32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/arch/ppc32/_link.ld.in	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,85 @@
+ENTRY(__entry)
+
+PHDRS {
+	text PT_LOAD FLAGS(5);
+	data PT_LOAD FLAGS(6);
+	dynamic PT_DYNAMIC;
+}
+
+SECTIONS {
+	. = 0x1000 + SIZEOF_HEADERS;
+
+	.init : {
+		*(.init);
+	} :text
+	.text : {
+		*(.text);
+		*(.text.*);
+		*(.rodata*);
+	} :text
+
+	.rel.plt : {
+		*(.rel.plt);
+	}
+	/* 
+	 *.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt 
+	 * without alignment gap or DT_REL will be broken
+	 */
+	.rel.dyn : {
+		*(.rel.*);
+	} :text
+
+	.dynsym : {
+		*(.dynsym);
+	} :text
+
+	.dynstr : {
+		*(.dynstr);
+	} :text
+
+	. = . + 0x1000;
+
+	.dynamic : {
+		*(.dynamic);
+	} :data :dynamic
+
+	.data : {
+		*(.data);
+		*(.sdata);
+	} :data
+
+	.data.rel : {
+                *(.data.rel);
+	} :data
+
+	.got : {
+                *(.got);
+	} :data
+	.got.plt : {
+                *(.got.plt);
+	} :data
+/*
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		_tdata_end = .;
+	} :data
+	.tbss : {
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
+	.bss : {
+		*(.sbss);
+		*(COMMON);
+		*(.bss);
+	} :data
+*/
+	.plt : {
+		*(.plt);
+	} :data
+
+	. = ALIGN(0x1000);
+	_heap = .;
+}
Index: uspace/lib/test/libtest.c
===================================================================
--- uspace/lib/test/libtest.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/libtest.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -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 rtld
+ * @brief
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include "libtest.h"
+
+//static void kputint(unsigned i)
+//{
+//	unsigned dummy;
+//	asm volatile (
+//		"movl $30, %%eax;"
+//		"int $0x30"
+//		: "=d" (dummy) /* output - %edx clobbered */
+//		: "d" (i) /* input */
+//		: "%eax","%ecx" /* all scratch registers clobbered */
+//	);
+//}
+
+int number = 137;
+
+int test_fun2(void);
+
+int test_fun2(void)
+{
+	return 42;
+//	return number;
+}
+
+int test_func(void)
+{
+//	printf("Hello, this is 'test_func()' in libtest.so!\n");
+//	kputint(42);
+//	return 42;
+//	while(1);
+//	return test_fun2();
+	printf("Hello from libtest/test_func()!\n");
+	return 42;
+}
+
+/** @}
+ */
Index: uspace/lib/test/libtest.h
===================================================================
--- uspace/lib/test/libtest.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/libtest.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBTEST_H_
+#define LIBTEST_H_
+
+int test_func(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/test/libtest.so.0
===================================================================
--- uspace/lib/test/libtest.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/lib/test/libtest.so.0	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,1 @@
+libtest.so.0.0
Index: uspace/srv/hid/kbd/port/i8042.h
===================================================================
--- uspace/srv/hid/kbd/port/i8042.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
+++ uspace/srv/hid/kbd/port/i8042.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 kbd_port
+ * @ingroup  kbd
+ * @{
+ */
+
+/** @file
+ * @brief i8042 port driver.
+ */
+
+#ifndef KBD_PORT_i8042_H_
+#define KBD_PORT_i8042_H_
+
+#include <libarch/ddi.h>
+#include <libarch/types.h>
+
+struct i8042 {
+	ioport8_t data;
+	uint8_t pad[3];
+	ioport8_t status;
+} __attribute__ ((packed));
+typedef struct i8042 i8042_t;
+
+#endif
+
+/**
+ * @}
+ */ 
Index: uspace/srv/loader/Makefile
===================================================================
--- uspace/srv/loader/Makefile	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/srv/loader/Makefile	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -39,5 +39,5 @@
 LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld
 
-EXTRA_CFLAGS = -Iinclude
+EXTRA_CFLAGS = -Iinclude -I../../lib/c/rtld/include
 
 BINARY = loader
Index: uspace/srv/loader/elf_load.c
===================================================================
--- uspace/srv/loader/elf_load.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/srv/loader/elf_load.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -103,5 +103,6 @@
  *
  */
-int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info)
+int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
+    elf_info_t *info)
 {
 	elf_ld_t elf;
@@ -118,4 +119,5 @@
 	elf.fd = fd;
 	elf.info = info;
+	elf.flags = flags;
 
 	rc = elf_load(&elf, so_bias);
@@ -124,19 +126,4 @@
 
 	return rc;
-}
-
-/** Run an ELF executable.
- *
- * Transfers control to the entry point of an ELF executable loaded
- * earlier with elf_load_file(). This function does not return.
- *
- * @param info Info structure filled earlier by elf_load_file()
- *
- */
-void elf_run(elf_info_t *info, pcb_t *pcb)
-{
-	entry_point_jmp(info->entry, pcb);
-
-	/* not reached */
 }
 
@@ -153,4 +140,5 @@
 	pcb->entry = info->entry;
 	pcb->dynamic = info->dynamic;
+	pcb->rtld_runtime = NULL;
 }
 
@@ -306,11 +294,20 @@
 		break;
 	case PT_INTERP:
-		/* Assume silently interp == "/rtld.so" */
-		elf->info->interp = "/rtld.so";
+		/* Assume silently interp == "/app/dload" */
+		elf->info->interp = "/app/dload";
 		break;
 	case PT_DYNAMIC:
+		/* Record pointer to dynamic section into info structure */
+		elf->info->dynamic =
+		    (void *)((uint8_t *)entry->p_vaddr + elf->bias);
+		DPRINTF("dynamic section found at 0x%x\n",
+			(uintptr_t)elf->info->dynamic);
+		break;
+	case 0x70000000:
+		/* FIXME: MIPS reginfo */
+		break;
 	case PT_SHLIB:
-	case PT_LOPROC:
-	case PT_HIPROC:
+//	case PT_LOPROC:
+//	case PT_HIPROC:
 	default:
 		DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
@@ -383,5 +380,6 @@
 	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
 	if (a == (void *)(-1)) {
-		DPRINTF("Memory mapping failed.\n");
+		DPRINTF("memory mapping failed (0x%x, %d)\n",
+			base+bias, mem_sz);
 		return EE_MEMORY;
 	}
@@ -425,4 +423,11 @@
 	}
 
+	/*
+	 * The caller wants to modify the segments first. He will then
+	 * need to set the right access mode and ensure SMC coherence.
+	 */
+	if ((elf->flags & ELDF_RW) != 0) return EE_OK;
+
+//	printf("set area flags to %d\n", flags);
 	rc = as_area_change_flags(seg_ptr, flags);
 	if (rc != 0) {
Index: uspace/srv/loader/include/elf_load.h
===================================================================
--- uspace/srv/loader/include/elf_load.h	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/srv/loader/include/elf_load.h	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -43,4 +43,9 @@
 #include "elf.h"
 
+typedef enum {
+	/** Leave all segments in RW access mode. */
+	ELDF_RW = 1
+} eld_flags_t;
+
 /**
  * Some data extracted from the headers are stored here
@@ -67,4 +72,7 @@
 	uintptr_t bias;
 
+	/** Flags passed to the ELF loader. */
+	eld_flags_t flags;
+
 	/** A copy of the ELF file header */
 	elf_header_t *header;
@@ -74,6 +82,6 @@
 } elf_ld_t;
 
-int elf_load_file(const char *file_name, size_t so_bias, elf_info_t *info);
-void elf_run(elf_info_t *info, pcb_t *pcb);
+int elf_load_file(const char *file_name, size_t so_bias, eld_flags_t flags,
+    elf_info_t *info);
 void elf_create_pcb(elf_info_t *info, pcb_t *pcb);
 
Index: uspace/srv/loader/main.c
===================================================================
--- uspace/srv/loader/main.c	(revision 3f461ecf935dddebd8b8b62ca732ea02b8580294)
+++ uspace/srv/loader/main.c	(revision f7981780b553fa33f466e5900f1947df6d56a64a)
@@ -55,4 +55,5 @@
 #include <macros.h>
 #include <loader/pcb.h>
+#include <entry_point.h>
 #include <errno.h>
 #include <async.h>
@@ -63,5 +64,13 @@
 #include <elf_load.h>
 
+/* From librtld */
+#include <rtld.h>
+#include <dynamic.h>
+#include <elf_load.h>
+#include <module.h>
+
 #define DPRINTF(...)
+
+static int ldr_load_dyn_linked(elf_info_t *p_info);
 
 /** Pathname of the file that will be loaded */
@@ -89,10 +98,11 @@
 
 static elf_info_t prog_info;
-static elf_info_t interp_info;
-
-static bool is_dyn_linked;
 
 /** Used to limit number of connections to one. */
 static bool connected = false;
+
+/** State structure of the dynamic linker. */
+runtime_env_t dload_re;
+static module_t prog_mod;
 
 static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request)
@@ -283,5 +293,5 @@
 	int rc;
 	
-	rc = elf_load_file(pathname, 0, &prog_info);
+	rc = elf_load_file(pathname, 0, 0, &prog_info);
 	if (rc != EE_OK) {
 		DPRINTF("Failed to load executable '%s'.\n", pathname);
@@ -302,23 +312,64 @@
 	if (prog_info.interp == NULL) {
 		/* Statically linked program */
-		is_dyn_linked = false;
 		async_answer_0(rid, EOK);
 		return 0;
 	}
 	
-	rc = elf_load_file(prog_info.interp, 0, &interp_info);
-	if (rc != EE_OK) {
-		DPRINTF("Failed to load interpreter '%s.'\n",
-		    prog_info.interp);
-		async_answer_0(rid, EINVAL);
-		return 1;
-	}
-	
-	is_dyn_linked = true;
-	async_answer_0(rid, EOK);
-	
+	DPRINTF("Binary is dynamically linked.\n");
+	DPRINTF(" - pcb address: %p\n", &pcb);
+	DPRINTF( "- prog dynamic: %p\n", prog_info.dynamic);
+
+	rc = ldr_load_dyn_linked(&prog_info);
+
+	async_answer_0(rid, rc);
 	return 0;
 }
 
+static int ldr_load_dyn_linked(elf_info_t *p_info)
+{
+	runtime_env = &dload_re;
+
+	DPRINTF("Load dynamically linked program.\n");
+
+	/*
+	 * First we need to process dynamic sections of the executable
+	 * program and insert it into the module graph.
+	 */
+
+	DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
+	dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
+	prog_mod.bias = 0;
+	prog_mod.dyn.soname = "[program]";
+
+	/* Initialize list of loaded modules */
+	list_initialize(&runtime_env->modules_head);
+	list_append(&prog_mod.modules_link, &runtime_env->modules_head);
+
+	/* Pointer to program module. Used as root of the module graph. */
+	runtime_env->program = &prog_mod;
+
+	/* Work around non-existent memory space allocation. */
+	runtime_env->next_bias = 0x1000000;
+
+	/*
+	 * Now we can continue with loading all other modules.
+	 */
+
+	DPRINTF("Load all program dependencies\n");
+	module_load_deps(&prog_mod);
+
+	/*
+	 * Now relocate/link all modules together.
+	 */
+
+	/* Process relocations in all modules */
+	DPRINTF("Relocate all modules\n");
+	modules_process_relocs(&prog_mod);
+
+	/* Pass runtime evironment pointer through PCB. */
+	pcb.rtld_runtime = (void *) runtime_env;
+
+	return 0;
+}
 
 /** Run the previously loaded program.
@@ -332,4 +383,6 @@
 	const char *cp;
 	
+	DPRINTF("Set task name\n");
+
 	/* Set the task name. */
 	cp = str_rchr(pathname, '/');
@@ -337,16 +390,9 @@
 	task_set_name(cp);
 	
-	if (is_dyn_linked == true) {
-		/* Dynamically linked program */
-		DPRINTF("Run ELF interpreter.\n");
-		DPRINTF("Entry point: %p\n", interp_info.entry);
-		
-		async_answer_0(rid, EOK);
-		elf_run(&interp_info, &pcb);
-	} else {
-		/* Statically linked program */
-		async_answer_0(rid, EOK);
-		elf_run(&prog_info, &pcb);
-	}
+	/* Run program */
+	DPRINTF("Reply OK\n");
+	async_answer_0(rid, EOK);
+	DPRINTF("Jump to entry point at %p\n", pcb.entry);
+	entry_point_jmp(prog_info.entry, &pcb);
 	
 	/* Not reached */
