xref: /minix3/external/gpl3/binutils/patches/0004-libdl-and-reconf.patch (revision c81f587520dfe822d879c1d3a93696669d98c7a2)
1diff --git a/bfd/Makefile.am b/bfd/Makefile.am
2index 49f9662..2ac03e9 100644
3--- a/bfd/Makefile.am
4+++ b/bfd/Makefile.am
5@@ -35,7 +35,7 @@ AM_CFLAGS = $(WARN_CFLAGS)
6 AM_CPPFLAGS = -DBINDIR='"$(bindir)"'
7 if PLUGINS
8 bfdinclude_HEADERS += $(INCDIR)/plugin-api.h
9-LIBDL = -ldl
10+LIBDL = @lt_cv_dlopen_libs@
11 endif
12
13 # bfd.h goes here, for now
14diff --git a/bfd/Makefile.in b/bfd/Makefile.in
15index 5718fab..7b0f863 100644
16--- a/bfd/Makefile.in
17+++ b/bfd/Makefile.in
18@@ -293,6 +293,7 @@ libdir = @libdir@
19 libexecdir = @libexecdir@
20 localedir = @localedir@
21 localstatedir = @localstatedir@
22+lt_cv_dlopen_libs = @lt_cv_dlopen_libs@
23 mandir = @mandir@
24 mkdir_p = @mkdir_p@
25 oldincludedir = @oldincludedir@
26@@ -336,7 +337,7 @@ libbfd_la_LDFLAGS = $(am__append_1) -release `cat libtool-soversion` \
27 @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libbfd.la
28 AM_CFLAGS = $(WARN_CFLAGS)
29 AM_CPPFLAGS = -DBINDIR='"$(bindir)"'
30-@PLUGINS_TRUE@LIBDL = -ldl
31+@PLUGINS_TRUE@LIBDL = @lt_cv_dlopen_libs@
32
33 # bfd.h goes here, for now
34 BFD_H = bfd.h
35diff --git a/bfd/configure b/bfd/configure
36index d81719d..fdf5356 100755
37--- a/bfd/configure
38+++ b/bfd/configure
39@@ -606,6 +606,7 @@ havevecs
40 tdefaults
41 bfd_ufile_ptr
42 bfd_file_ptr
43+lt_cv_dlopen_libs
44 supports_plugins
45 bfd_default_target_size
46 bfd_machines
47diff --git a/bfd/configure.in b/bfd/configure.in
48index 612d032..530bbcb 100644
49--- a/bfd/configure.in
50+++ b/bfd/configure.in
51@@ -1100,6 +1100,7 @@ else
52   supports_plugins=0
53 fi
54 AC_SUBST(supports_plugins)
55+AC_SUBST(lt_cv_dlopen_libs)
56
57 # Determine the host dependant file_ptr a.k.a. off_t type.  In order
58 # prefer: off64_t - if ftello64 and fseeko64, off_t - if ftello and
59diff --git a/gold/Makefile.am b/gold/Makefile.am
60index df8dcb5..f6ced44 100644
61--- a/gold/Makefile.am
62+++ b/gold/Makefile.am
63@@ -37,7 +38,7 @@ AM_CPPFLAGS = \
64 LIBIBERTY = ../libiberty/libiberty.a
65
66 if PLUGINS
67-LIBDL = -ldl
68+LIBDL = @DLOPEN_LIBS@
69 endif
70
71 if THREADS
72diff --git a/gold/Makefile.in b/gold/Makefile.in
73index 216532a..f12832b 100644
74--- a/gold/Makefile.in
75+++ b/gold/Makefile.in
76@@ -272,6 +273,7 @@ CYGPATH_W = @CYGPATH_W@
77 DATADIRNAME = @DATADIRNAME@
78 DEFS = @DEFS@
79 DEPDIR = @DEPDIR@
80+DLOPEN_LIBS = @DLOPEN_LIBS@
81 ECHO_C = @ECHO_C@
82 ECHO_N = @ECHO_N@
83 ECHO_T = @ECHO_T@
84@@ -398,7 +400,7 @@ AM_CPPFLAGS = \
85 	-DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@
86
87 LIBIBERTY = ../libiberty/libiberty.a
88-@PLUGINS_TRUE@LIBDL = -ldl
89+@PLUGINS_TRUE@LIBDL = @DLOPEN_LIBS@
90 @THREADS_TRUE@THREADSLIB = -lpthread
91 AM_YFLAGS = -d
92
93diff --git a/gold/config.in b/gold/config.in
94index 42252bf..d46fd75 100644
95--- a/gold/config.in
96+++ b/gold/config.in
97@@ -73,6 +73,9 @@
98    don't. */
99 #undef HAVE_DECL_VSNPRINTF
100
101+/* Define to 1 if you have the <dlfcn.h> header file. */
102+#undef HAVE_DLFCN_H
103+
104 /* Define to 1 if you have the <ext/hash_map> header file. */
105 #undef HAVE_EXT_HASH_MAP
106
107@@ -184,6 +187,9 @@
108 /* Define to 1 if you have the <unistd.h> header file. */
109 #undef HAVE_UNISTD_H
110
111+/* Define to 1 if you have the <windows.h> header file. */
112+#undef HAVE_WINDOWS_H
113+
114 /* Define to 1 if you have the <zlib.h> header file. */
115 #undef HAVE_ZLIB_H
116
117diff --git a/gold/configure b/gold/configure
118index 9e1ee27..7e58cdf 100755
119--- a/gold/configure
120+++ b/gold/configure
121@@ -596,6 +596,7 @@ MAINTAINER_MODE_FALSE
122 MAINTAINER_MODE_TRUE
123 HAVE_PUBNAMES_FALSE
124 HAVE_PUBNAMES_TRUE
125+DLOPEN_LIBS
126 CXXCPP
127 HAVE_ZLIB_FALSE
128 HAVE_ZLIB_TRUE
129@@ -7139,6 +7140,35 @@ fi
130
131 done
132
133+
134+for ac_header in windows.h
135+do :
136+  ac_fn_cxx_check_header_mongrel "$LINENO" "windows.h" "ac_cv_header_windows_h" "$ac_includes_default"
137+if test "x$ac_cv_header_windows_h" = x""yes; then :
138+  cat >>confdefs.h <<_ACEOF
139+#define HAVE_WINDOWS_H 1
140+_ACEOF
141+
142+fi
143+
144+done
145+
146+for ac_header in dlfcn.h
147+do :
148+  ac_fn_cxx_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default"
149+if test "x$ac_cv_header_dlfcn_h" = x""yes; then :
150+  cat >>confdefs.h <<_ACEOF
151+#define HAVE_DLFCN_H 1
152+_ACEOF
153+ DLOPEN_LIBS="-ldl"
154+else
155+  DLOPEN_LIBS=""
156+fi
157+
158+done
159+
160+
161+
162 for ac_func in mallinfo posix_fallocate fallocate readv sysconf times
163 do :
164   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
165diff --git a/gold/configure.ac b/gold/configure.ac
166index 804a474..b03c09d 100644
167--- a/gold/configure.ac
168+++ b/gold/configure.ac
169@@ -505,6 +506,13 @@ AC_LANG_PUSH(C++)
170 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
171 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
172 AC_CHECK_HEADERS(byteswap.h)
173+
174+dnl When plugins enabled dynamic loader interface is required. Check headers
175+dnl which may provide this interface. In case of dlfcn.h add libdl to link.
176+AC_CHECK_HEADERS(windows.h)
177+AC_CHECK_HEADERS(dlfcn.h, [DLOPEN_LIBS="-ldl"], [DLOPEN_LIBS=""])
178+AC_SUBST(DLOPEN_LIBS)
179+
180 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
181 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
182
183diff --git a/gold/plugin.cc b/gold/plugin.cc
184index c39e11ec..9176e06 100644
185--- a/gold/plugin.cc
186+++ b/gold/plugin.cc
187@@ -29,9 +29,39 @@
188 #include <vector>
189
190 #ifdef ENABLE_PLUGINS
191+#ifdef HAVE_DLFCN_H
192 #include <dlfcn.h>
193+#elif defined (HAVE_WINDOWS_H)
194+#include <windows.h>
195+#else
196+#error Unknown how to handle dynamic-load-libraries.
197 #endif
198
199+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
200+
201+#define RTLD_NOW 0      /* Dummy value.  */
202+static void *
203+dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
204+{
205+  return LoadLibrary(file);
206+}
207+
208+static void *
209+dlsym(void *handle, const char *name)
210+{
211+  return reinterpret_cast<void *>(
212+     GetProcAddress(static_cast<HMODULE>(handle),name));
213+}
214+
215+static const char *
216+dlerror(void)
217+{
218+  return "unable to load dll";
219+}
220+
221+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
222+#endif /* ENABLE_PLUGINS */
223+
224 #include "parameters.h"
225 #include "errors.h"
226 #include "fileread.h"
227diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
228index 6e22934..b2eb352 100644
229--- a/gold/testsuite/Makefile.in
230+++ b/gold/testsuite/Makefile.in
231@@ -1878,6 +1878,7 @@ CYGPATH_W = @CYGPATH_W@
232 DATADIRNAME = @DATADIRNAME@
233 DEFS = @DEFS@
234 DEPDIR = @DEPDIR@
235+DLOPEN_LIBS = @DLOPEN_LIBS@
236 ECHO_C = @ECHO_C@
237 ECHO_N = @ECHO_N@
238 ECHO_T = @ECHO_T@
239