diff --git a/ChangeLog b/ChangeLog
index ffbac170721b5a7ac0b4f3d35fecf67e8607a508..971862b5a63e8bf97b5463c0d5a84c85a42fb122 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-05-06  Niels M�ller  <nisse@lysator.liu.se>
+
+	* configure.ac: Fix link flags for shared libraries on Solaris,
+	which needs -h to set the soname. Patch contributed by Dagobert
+	Michelsen.
+
+2011-05-06  Niels M�ller  <nisse@lysator.liu.se>
+
+	* configure.ac: New configure option --enable-gcov.
+
 2011-04-27  Niels M�ller  <nisse@lysator.liu.se>
 
 	* tools/nettle-hash.c (find_algorithm): Require exact match.
diff --git a/configure.ac b/configure.ac
index 3147e8fc46ceffa82f91b47459f9fe00be817ea4..dd0185e25dd52d4916e9ed9927a5096f6196bf98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,7 +55,11 @@ AC_ARG_ENABLE(pic,
 AC_ARG_ENABLE(openssl,
   AC_HELP_STRING([--disable-openssl], [Do not include openssl glue in the benchmark program]),,
   [enable_openssl=yes])
-  
+
+AC_ARG_ENABLE(gcov,
+  AC_HELP_STRING([--enable-gcov], [Instrument for gcov (requires a modern gcc)]),,
+  [enable_gcov=no])
+
 LSH_RPATH_INIT([`echo $with_lib_path | sed 's/:/ /g'` \
     `echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed "s@^NONE@$ac_default_prefix/lib@g"` \
     /usr/local/lib /sw/local/lib /sw/lib \
@@ -272,6 +276,22 @@ case "$host_os" in
     LIBHOGWEED_LINK='$(CC) -dynamiclib $(LDFLAGS)'
     LIBHOGWEED_LIBS=''
     ;;
+  solaris*)
+    # Sun's ld uses -h to set the soname, and this option is passed
+    # through by both Sun's compiler and gcc. Might not work with GNU
+    # ld, but it's unusual to use GNU ld on Solaris.
+    LIBNETTLE_FORLINK=libnettle.so
+    LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
+    LIBNETTLE_FILE='$(LIBNETTLE_SONAME).$(LIBNETTLE_MINOR)'
+    LIBNETTLE_LINK='$(CC) $(LDFLAGS) -G -h $(LIBNETTLE_SONAME)'
+    LIBNETTLE_LIBS=''
+
+    LIBHOGWEED_FORLINK=libhogweed.so
+    LIBHOGWEED_SONAME='$(LIBHOGWEED_FORLINK).$(LIBHOGWEED_MAJOR)'
+    LIBHOGWEED_FILE='$(LIBHOGWEED_SONAME).$(LIBHOGWEED_MINOR)'
+    LIBHOGWEED_LINK='$(CC) $(LDFLAGS) -L. -G -h $(LIBHOGWEED_SONAME)'
+    LIBHOGWEED_LIBS='-lnettle -lgmp'
+    ;;
   *)
     LIBNETTLE_FORLINK=libnettle.so
     LIBNETTLE_SONAME='$(LIBNETTLE_FORLINK).$(LIBNETTLE_MAJOR)'
@@ -424,6 +444,10 @@ AC_SUBST(LIBHOGWEED_LIBS)
 
 AC_PATH_PROG(M4, m4, m4)
 
+if test "x$enable_gcov" = "xyes"; then
+  CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs"
+fi
+
 # Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 AC_C_INLINE