Index: uspace/lib/c/arch/ia32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -144,5 +144,5 @@
 
 			sym_def = symbol_def_find(str_tab + sym->st_name,
-			    m, ssf_noroot, &dest);
+			    m, ssf_noexec, &dest);
 
 			if (sym_def) {
Index: uspace/lib/c/generic/dlfcn.c
===================================================================
--- uspace/lib/c/generic/dlfcn.c	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/generic/dlfcn.c	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -60,7 +60,7 @@
 	if (m == NULL) {
 		printf("NULL. module_load('%s')\n", path);
-		m = module_load(runtime_env, path);
+		m = module_load(runtime_env, path, mlf_local);
 		printf("module_load_deps(m)\n");
-		module_load_deps(m);
+		module_load_deps(m, mlf_local);
 		/* Now relocate. */
 		printf("module_process_relocs(m)\n");
@@ -82,5 +82,5 @@
 
 	printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
-	sd = symbol_bfs_find(sym_name, (module_t *) mod, ssf_none, &sm);
+	sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
 	if (sd != NULL) {
 		return symbol_get_addr(sd, sm);
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/generic/rtld/module.c	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -117,5 +117,5 @@
 		}
 	}
-	
+
 	return NULL; /* Not found */
 }
@@ -127,5 +127,5 @@
  * Currently this trivially tries to load '/<name>'.
  */
-module_t *module_load(rtld_t *rtld, const char *name)
+module_t *module_load(rtld_t *rtld, const char *name, mlflags_t flags)
 {
 	elf_finfo_t info;
@@ -133,6 +133,6 @@
 	module_t *m;
 	int rc;
-	
-	m = malloc(sizeof(module_t));
+
+	m = calloc(1, sizeof(module_t));
 	if (!m) {
 		printf("malloc failed\n");
@@ -141,4 +141,6 @@
 
 	m->rtld = rtld;
+	if ((flags & mlf_local) != 0)
+		m->local = true;
 
 	if (str_size(name) > NAME_BUF_SIZE - 2) {
@@ -185,5 +187,5 @@
 /** Load all modules on which m (transitively) depends.
  */
-void module_load_deps(module_t *m)
+void module_load_deps(module_t *m, mlflags_t flags)
 {
 	elf_dyn_t *dp;
@@ -230,6 +232,6 @@
 			dm = module_find(m->rtld, dep_name);
 			if (!dm) {
-				dm = module_load(m->rtld, dep_name);
-				module_load_deps(dm);
+				dm = module_load(m->rtld, dep_name, flags);
+				module_load_deps(dm, flags);
 			}
 
Index: uspace/lib/c/generic/rtld/rtld.c
===================================================================
--- uspace/lib/c/generic/rtld/rtld.c	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -80,4 +80,6 @@
 	prog_mod.dyn.soname = "[program]";
 	prog_mod.rtld = env;
+	prog_mod.exec = true;
+	prog_mod.local = false;
 
 	/* Initialize list of loaded modules */
@@ -96,5 +98,5 @@
 
 	DPRINTF("Load all program dependencies\n");
-	module_load_deps(&prog_mod);
+	module_load_deps(&prog_mod, 0);
 
 	/*
Index: uspace/lib/c/generic/rtld/symbol.c
===================================================================
--- uspace/lib/c/generic/rtld/symbol.c	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/generic/rtld/symbol.c	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -112,11 +112,9 @@
  * @param name		Name of the symbol to search for.
  * @param start		Module in which to start the search..
- * @param flags		@c ssf_none or @c ssf_noroot to not look for the symbol
- *			in @a start
  * @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,
-    symbol_search_flags_t flags, module_t **mod)
+    module_t **mod)
 {
 	module_t *m, *dm;
@@ -150,12 +148,10 @@
 
 		/* If ssf_noroot is specified, do not look in start module */
-		if (m != start || (flags & ssf_noroot) == 0) { 
-			s = def_find_in_module(name, m);
-			if (s != NULL) {
-				/* Symbol found */
-				sym = s;
-				*mod = m;
-				break;
-			}
+		s = def_find_in_module(name, m);
+		if (s != NULL) {
+			/* Symbol found */
+			sym = s;
+			*mod = m;
+			break;
 		}
 
@@ -189,11 +185,10 @@
  *
  * 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.
+ * origin is searched first. Otherwise, search global modules in the default
+ * order.
  *
  * @param name		Name of the symbol to search for.
  * @param origin	Module in which the dependency originates.
- * @param flags		@c ssf_none or @c ssf_noroot to not look for the symbol
+ * @param flags		@c ssf_none or @c ssf_noexec to not look for the symbol
  *			in the executable program.
  * @param mod		(output) Will be filled with a pointer to the module 
@@ -205,26 +200,51 @@
 	elf_symbol_t *s;
 
-	if (origin->dyn.symbolic) {
-		/* 
+	DPRINTF("symbol_def_find('%s', origin='%s'\n",
+	    name, origin->dyn.soname);
+	if (origin->dyn.symbolic && (!origin->exec || (flags & ssf_noexec) == 0)) {
+		DPRINTF("symbolic->find '%s' in module '%s'\n", name, origin->dyn.soname);
+		/*
 		 * Origin module has a DT_SYMBOLIC flag.
 		 * Try this module first
 		 */
-		 s = def_find_in_module(name, origin);
-		 if (s != NULL) {
+		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 (origin->rtld->program) {
-		/* Program is dynamic -- start with program as root. */
-		return symbol_bfs_find(name, origin->rtld->program, flags, mod);
-	} else {
-		/* Program is static -- start with @a origin as root. */
-		return symbol_bfs_find(name, origin, ssf_none, mod);
-	}
+	list_foreach(origin->rtld->modules, modules_link, module_t, m) {
+		DPRINTF("module '%s' local?\n", m->dyn.soname);
+		if (!m->local && (!m->exec || (flags & ssf_noexec) == 0)) {
+			DPRINTF("!local->find '%s' in module '%s'\n", name, m->dyn.soname);
+			s = def_find_in_module(name, m);
+			if (s != NULL) {
+				/* Found */
+				*mod = m;
+				return s;
+			}
+		}
+	}
+
+	/* Finally, try origin. */
+
+	DPRINTF("try finding '%s' in origin '%s'\n", name,
+	    origin->dyn.soname);
+
+	if (!origin->exec || (flags & ssf_noexec) == 0) {
+		s = def_find_in_module(name, origin);
+		if (s != NULL) {
+			/* Found */
+			*mod = origin;
+			return s;
+		}
+	}
+
+	DPRINTF("'%s' not found\n", name);
+	return NULL;
 }
 
Index: uspace/lib/c/include/rtld/module.h
===================================================================
--- uspace/lib/c/include/rtld/module.h	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/include/rtld/module.h	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -44,6 +44,6 @@
 extern void module_process_relocs(module_t *);
 extern module_t *module_find(rtld_t *, const char *);
-extern module_t *module_load(rtld_t *, const char *);
-extern void module_load_deps(module_t *);
+extern module_t *module_load(rtld_t *, const char *, mlflags_t);
+extern void module_load_deps(module_t *, mlflags_t);
 
 extern void modules_process_relocs(rtld_t *, module_t *);
Index: uspace/lib/c/include/rtld/symbol.h
===================================================================
--- uspace/lib/c/include/rtld/symbol.h	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/include/rtld/symbol.h	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -43,10 +43,9 @@
 	/** No flags */
 	ssf_none = 0,
-	/** Do not search tree root */
-	ssf_noroot = 0x1
+	/** Do not search in the executable */
+	ssf_noexec = 0x1
 } symbol_search_flags_t;
 
-extern elf_symbol_t *symbol_bfs_find(const char *, module_t *,
-    symbol_search_flags_t, module_t **);
+extern elf_symbol_t *symbol_bfs_find(const char *, module_t *, module_t **);
 extern elf_symbol_t *symbol_def_find(const char *, module_t *,
     symbol_search_flags_t, module_t **);
Index: uspace/lib/c/include/types/rtld/module.h
===================================================================
--- uspace/lib/c/include/types/rtld/module.h	(revision 634e020ca4b381b0399365dd09c5ca7895e43a1c)
+++ uspace/lib/c/include/types/rtld/module.h	(revision 5035ba05f0dcb66a61ad5e5722c225bf1d375437)
@@ -39,4 +39,10 @@
 #include <sys/types.h>
 
+typedef enum {
+	/** Do not export symbols to global namespace */
+	mlf_local = 0x1
+} mlflags_t;
+
+/** Dynamically linked module */
 typedef struct module {
 	dyn_info_t dyn;
@@ -60,4 +66,8 @@
 	/** Tag for modules already processed during a BFS */
 	bool bfs_tag;
+	/** If @c true, does not export symbols to global namespace */
+	bool local;
+	/** This is the dynamically linked executable */
+	bool exec;
 } module_t;
 
