This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][PATCH] Make plugin not to depend on -ldl but dlopen()


Hello, binutils

I'm working on building binutils with plugin enabled on FreeBSD. However
since FreeBSD has dlopen() in libc not in libdl and binutils has
hardcoded linking to libdl, it cannot be built.

I found Dave writing in [1]:

>   I took a look at libltdl, and decided it was too much of a top-heavy
> and intrusive solution.

Yes, using full libltdl would be too much. But how about using its
library detecting feature? The patch bellow check if dynamic linking
function is named "dlopen" and replace "-ldl" with @lt_cv_dlopen_libs@.

I've test the patch agains current git master and it links dlopen() to
proper library on Linux (-dl) and FreeBSD (libc).

[1] http://sourceware.org/ml/binutils/2010-10/msg00226.html

Regards,
Naohiro

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 8f4fbee..4a26555 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -35,7 +35,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
 AM_CPPFLAGS = -DBINDIR='"$(bindir)"'
 if PLUGINS
 bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 # bfd.h goes here, for now
diff --git a/bfd/configure.in b/bfd/configure.in
index f443915..140c820 100644
--- a/bfd/configure.in
+++ b/bfd/configure.in
@@ -31,11 +31,12 @@ ACX_LARGEFILE
 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
 
 if test "$plugins" = "yes"; then
-  if test "$enable_dlopen" != "yes" ; then
+  if test "$enable_dlopen" != "yes" -o "$lt_cv_dlopen" != "dlopen" ; then
     AC_MSG_ERROR([
-      Building BFD with plugin support requires a host that supports -ldl.])
+      Building BFD with plugin support requires a host that supports dlopen().])
   fi
   enable_targets="$enable_targets plugin"
+  AC_SUBST(lt_cv_dlopen_libs)
 fi
 
 AC_ARG_ENABLE(64-bit-bfd,
diff --git a/gold/Makefile.am b/gold/Makefile.am
index 7d4b725..5b147e0 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = \
 LIBIBERTY = ../libiberty/libiberty.a
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 if THREADS
diff --git a/gold/configure.ac b/gold/configure.ac
index edc5917..867dc75 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -97,6 +97,8 @@ AC_ARG_ENABLE([plugins],
 if test "$plugins" = "yes"; then
   AC_DEFINE(ENABLE_PLUGINS, 1,
 	    [Define to enable linker plugins])
+  LT_INIT([dlopen])
+  AC_SUBST(lt_cv_dlopen_libs)
 fi
 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
 
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 6f74f71..685848f 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -28,7 +28,7 @@ TEST_NM = $(top_builddir)/../binutils/nm-new
 TEST_AS = $(top_builddir)/../gas/as-new
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 if THREADS

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]