Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 32573ffe2f11f1f46237edf372866632f5d0f7f2)
+++ uspace/Makefile	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -41,5 +41,4 @@
 	app/corecfg \
 	app/devctl \
-	app/dltest \
 	app/dnscfg \
 	app/dnsres \
@@ -166,4 +165,5 @@
 	drv/platform/icp
 
+
 ## Platform-specific hardware support
 #
@@ -209,4 +209,12 @@
 		drv/fb/amdm37x_dispc \
 		srv/hw/irc/icp-ic
+endif
+
+## Dynamic linking tests
+#
+ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
+	DIRS += \
+		app/dltest \
+		app/dltests
 endif
 
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 32573ffe2f11f1f46237edf372866632f5d0f7f2)
+++ uspace/Makefile.common	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -199,5 +199,4 @@
 ifeq ($(STATIC_BUILD),y)
 	BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
-	LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
 	ifeq ($(MATH),y)
 		BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
@@ -205,9 +204,15 @@
 else
 	BASE_LIBS = $(LIBC_PREFIX)/libc.so.0 $(LIBSOFTINT_PREFIX)/libsoftint.so.0
-	LFLAGS += -Bdynamic
-	LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
+	LINK_DYNAMIC = y
 	ifeq ($(MATH),y)
 		BASE_LIBS += $(LIBMATH_PREFIX)/libmath.so.0
 	endif
+endif
+
+ifeq ($(LINK_DYNAMIC),y)
+	LFLAGS += -Bdynamic
+	LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
+else
+	LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
 endif
 
Index: uspace/app/dltest/Makefile
===================================================================
--- uspace/app/dltest/Makefile	(revision 32573ffe2f11f1f46237edf372866632f5d0f7f2)
+++ uspace/app/dltest/Makefile	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -28,5 +28,9 @@
 
 USPACE_PREFIX = ../..
-EXTRA_CFLAGS = -I$(LIBDLTEST_PREFIX)
+EXTRA_CFLAGS = -I$(LIBDLTEST_PREFIX) -DDLTEST_LINKED
+LIBS = $(LIBDLTEST_PREFIX)/libdltest.so.0.0
+# Need a dynamic link, but possibly still use static libc
+LINK_DYNAMIC = y
+
 BINARY = dltest
 
Index: uspace/app/dltest/dltest.c
===================================================================
--- uspace/app/dltest/dltest.c	(revision 32573ffe2f11f1f46237edf372866632f5d0f7f2)
+++ uspace/app/dltest/dltest.c	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -45,4 +45,5 @@
 void *handle;
 
+
 /** Test dlsym() function */
 static bool test_dlsym(void)
@@ -255,4 +256,149 @@
 }
 
+#ifdef DLTEST_LINKED
+
+/** Test directly calling function that returns a constant */
+static bool test_lnk_dl_get_constant(void)
+{
+	int val;
+
+	printf("Call linked dl_get_constant...\n");
+
+	val = dl_get_constant();
+
+	printf("Got %d, expected %d... ", val, dl_constant);
+	if (val != dl_constant) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test dircetly calling a function that returns contents of a private
+ * initialized variable.
+ */
+static bool test_lnk_dl_get_private_var(void)
+{
+	int val;
+
+	printf("Call linked dl_get_private_var...\n");
+
+	val = dl_get_private_var();
+
+	printf("Got %d, expected %d... ", val, dl_private_var_val);
+	if (val != dl_private_var_val) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test dircetly calling a function that returns contents of a private
+ * uninitialized variable.
+ */
+static bool test_lnk_dl_get_private_uvar(void)
+{
+	int val;
+
+	printf("Call linked dl_get_private_uvar...\n");
+
+	val = dl_get_private_uvar();
+
+	printf("Got %d, expected %d... ", val, 0);
+	if (val != 0) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test directly calling a function that returns the contents of a public
+ * initialized variable.
+ */
+static bool test_lnk_dl_get_public_var(void)
+{
+	int val;
+
+	printf("Call linked dl_get_public_var...\n");
+
+	val = dl_get_public_var();
+
+	printf("Got %d, expected %d... ", val, dl_public_var_val);
+	if (val != dl_public_var_val) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test directly calling a function that returns the contents of a public
+ * uninitialized variable.
+ */
+static bool test_lnk_dl_get_public_uvar(void)
+{
+	int val;
+
+	printf("Call linked dl_get_public_uvar...\n");
+
+	val = dl_get_public_uvar();
+
+	printf("Got %d, expected %d... ", val, 0);
+	if (val != 0) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test directly reading a public initialized variable. */
+static bool test_lnk_read_public_var(void)
+{
+	int val;
+
+	printf("Read linked dl_public_var...\n");
+
+	val = dl_public_var;
+
+	printf("Got %d, expected %d... ", val, dl_public_var_val);
+	if (val != dl_public_var_val) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+/** Test directly reading a public uninitialized variable. */
+static bool test_lnk_read_public_uvar(void)
+{
+	int val;
+
+	printf("Read linked dl_public_uvar...\n");
+
+	val = dl_public_uvar;
+
+	printf("Got %d, expected %d... ", val, 0);
+	if (val != 0) {
+		printf("FAILED\n");
+		return false;
+	}
+
+	printf("Passed\n");
+	return true;
+}
+
+#endif
+
 int main(int argc, char *argv[])
 {
@@ -293,4 +439,26 @@
 		return 1;
 
+#ifdef DLTEST_LINKED
+	if (!test_lnk_dl_get_constant())
+		return 1;
+
+	if (!test_lnk_dl_get_private_var())
+		return 1;
+
+	if (!test_lnk_dl_get_private_uvar())
+		return 1;
+
+	if (!test_lnk_dl_get_public_var())
+		return 1;
+
+	if (!test_lnk_dl_get_public_uvar())
+		return 1;
+
+	if (!test_lnk_read_public_var())
+		return 1;
+
+	if (!test_lnk_read_public_uvar())
+		return 1;
+#endif
 //	printf("dlclose()... ");
 //	dlclose(handle);
Index: uspace/app/dltests/Makefile
===================================================================
--- uspace/app/dltests/Makefile	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
+++ uspace/app/dltests/Makefile	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2016 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 = ../..
+EXTRA_CFLAGS = -I$(LIBDLTEST_PREFIX)
+BINARY = dltests
+
+SOURCES = \
+	dltests.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/dltests/dltests.c
===================================================================
--- uspace/app/dltests/dltests.c	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
+++ uspace/app/dltests/dltests.c	(revision 7c4b26cbe3d53c6c9fa1c8f7bf78a840f7c05528)
@@ -0,0 +1,1 @@
+../dltest/dltest.c
