public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
@ 2012-12-28 18:41 Pavel Chupin
  2013-01-05 19:18 ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Chupin @ 2012-12-28 18:41 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

Hi,
Attached patch fixes mingw build configured (for example) as:

../configure --prefix=`pwd`/../INSTALL --target=i686-linux-android
--host=i586-pc-mingw32msvc --build=i386-linux-gnu --enable-plugins
--enable-gold
make

Error message:

../../gold/plugin.cc:32:19: fatal error: dlfcn.h: No such file or directory

I'm fixing it like it's done in bfd configure: check for headers and
library, add/not-add -ldl on link.
Also adding windows.h case into plugin.cc to handle case when
mingw-dlfcn is not installed on the system.

ChangeLog:

2012-12-25  Pavel Chupin  <pavel.v.chupin@intel.com>

       Fix mingw gold build with plugins enabled
       * gold/Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
       * gold/aclocal.m4: Include libtool modules.
       * gold/configure.ac: Export lt_cv_dlopen_libs and add headers check.
       * gold/plugin.cc: Handle non-dlfcn case.
       * gold/Makefile.in: Regenerate.
       * gold/config.in: Regenerate.
       * gold/configure: Regenerate.
       * gold/testsuite/Makefile.in: Regenerate.

Ok for trunk?

--
Pavel Chupin
Intel Corporation

[-- Attachment #2: gold-mingw-plugins.patch --]
[-- Type: application/octet-stream, Size: 2757 bytes --]

commit a1acf449032c28dd029183afd5ed6241212c727f
Author: Pavel Chupin <pavel.v.chupin@intel.com>
Date:   Tue Dec 25 14:51:24 2012 +0400

    Fix mingw gold build with plugins enabled
    
    Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>

diff --git a/gold/Makefile.am b/gold/Makefile.am
index df8dcb5..0c13c10 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -37,7 +37,7 @@ AM_CPPFLAGS = \
 LIBIBERTY = ../libiberty/libiberty.a
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 if THREADS
diff --git a/gold/aclocal.m4 b/gold/aclocal.m4
index 8321894..9f95f1e 100644
--- a/gold/aclocal.m4
+++ b/gold/aclocal.m4
@@ -989,4 +989,9 @@ m4_include([../config/override.m4])
 m4_include([../config/po.m4])
 m4_include([../config/progtest.m4])
 m4_include([../config/zlib.m4])
+m4_include([../libtool.m4])
+m4_include([../ltoptions.m4])
+m4_include([../ltsugar.m4])
+m4_include([../ltversion.m4])
+m4_include([../lt~obsolete.m4])
 m4_include([../bfd/warning.m4])
diff --git a/gold/configure.ac b/gold/configure.ac
index 9d23835..ae4cc5a 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -290,6 +290,10 @@ AC_PROG_LN_S
 
 AC_GNU_SOURCE
 
+# required when plugins enabled
+LT_INIT([dlopen])
+AC_SUBST(lt_cv_dlopen_libs)
+
 ZW_GNU_GETTEXT_SISTER_DIR
 AM_PO_SUBDIRS
 
@@ -517,6 +521,9 @@ AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
+
+AC_CHECK_HEADERS(windows.h dlfcn.h)
+
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
diff --git a/gold/plugin.cc b/gold/plugin.cc
index c39e11e..93a8ba8 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -29,9 +29,45 @@
 #include <vector>
 
 #ifdef ENABLE_PLUGINS
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#else
+#error Unknown how to handle dynamic-load-libraries.
 #endif
 
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#define RTLD_NOW 0      /* Dummy value.  */
+static void *
+dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary (file);
+}
+
+static void *
+dlsym (void *handle, const char *name)
+{
+  return reinterpret_cast<void *>(GetProcAddress (static_cast<HMODULE>(handle), name));
+}
+
+static int ATTRIBUTE_UNUSED
+dlclose (void *handle)
+{
+  FreeLibrary (static_cast<HMODULE>(handle));
+  return 0;
+}
+
+static const char *
+dlerror (void)
+{
+  return "Unable to load DLL.";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
+#endif /* ENABLE_PLUGINS */
+
 #include "parameters.h"
 #include "errors.h"
 #include "fileread.h"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2012-12-28 18:41 [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case Pavel Chupin
@ 2013-01-05 19:18 ` Ian Lance Taylor
  2013-01-09 14:35   ` Pavel Chupin
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2013-01-05 19:18 UTC (permalink / raw)
  To: Pavel Chupin; +Cc: binutils

On Fri, Dec 28, 2012 at 10:41 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:

> Attached patch fixes mingw build configured (for example) as:
>
> ../configure --prefix=`pwd`/../INSTALL --target=i686-linux-android
> --host=i586-pc-mingw32msvc --build=i386-linux-gnu --enable-plugins
> --enable-gold
> make
>
> Error message:
>
> ../../gold/plugin.cc:32:19: fatal error: dlfcn.h: No such file or directory
>
> I'm fixing it like it's done in bfd configure: check for headers and
> library, add/not-add -ldl on link.
> Also adding windows.h case into plugin.cc to handle case when
> mingw-dlfcn is not installed on the system.
>
> ChangeLog:
>
> 2012-12-25  Pavel Chupin  <pavel.v.chupin@intel.com>
>
>        Fix mingw gold build with plugins enabled
>        * gold/Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>        * gold/aclocal.m4: Include libtool modules.
>        * gold/configure.ac: Export lt_cv_dlopen_libs and add headers check.
>        * gold/plugin.cc: Handle non-dlfcn case.
>        * gold/Makefile.in: Regenerate.
>        * gold/config.in: Regenerate.
>        * gold/configure: Regenerate.
>        * gold/testsuite/Makefile.in: Regenerate.

Sorry for the slow review.  The general idea is fine but the
formatting is wrong.  This is C++ code, not C: no space between
function name and left parenthesis.  Keep line lengths less than 80
columns--the body of dlsym needs a line break.  Don't define
dlclose--it's not called.  dlerror should return an ordinary error
string--no capitalization, no punctuation.

In configure.ac, the comment should be a complete sentence with proper
capitalization and punctuation.  It should explain why you are using
libtool.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-05 19:18 ` Ian Lance Taylor
@ 2013-01-09 14:35   ` Pavel Chupin
  2013-01-09 15:50     ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Chupin @ 2013-01-09 14:35 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1933 bytes --]

On Sat, Jan 5, 2013 at 11:18 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Fri, Dec 28, 2012 at 10:41 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>
>> Attached patch fixes mingw build configured (for example) as:
>>
>> ../configure --prefix=`pwd`/../INSTALL --target=i686-linux-android
>> --host=i586-pc-mingw32msvc --build=i386-linux-gnu --enable-plugins
>> --enable-gold
>> make
>>
>> Error message:
>>
>> ../../gold/plugin.cc:32:19: fatal error: dlfcn.h: No such file or directory
>>
>> I'm fixing it like it's done in bfd configure: check for headers and
>> library, add/not-add -ldl on link.
>> Also adding windows.h case into plugin.cc to handle case when
>> mingw-dlfcn is not installed on the system.
>>
>> ChangeLog:
>>
>> 2012-12-25  Pavel Chupin  <pavel.v.chupin@intel.com>
>>
>>        Fix mingw gold build with plugins enabled
>>        * gold/Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>>        * gold/aclocal.m4: Include libtool modules.
>>        * gold/configure.ac: Export lt_cv_dlopen_libs and add headers check.
>>        * gold/plugin.cc: Handle non-dlfcn case.
>>        * gold/Makefile.in: Regenerate.
>>        * gold/config.in: Regenerate.
>>        * gold/configure: Regenerate.
>>        * gold/testsuite/Makefile.in: Regenerate.
>
> Sorry for the slow review.  The general idea is fine but the
> formatting is wrong.  This is C++ code, not C: no space between
> function name and left parenthesis.  Keep line lengths less than 80
> columns--the body of dlsym needs a line break.  Don't define
> dlclose--it's not called.  dlerror should return an ordinary error
> string--no capitalization, no punctuation.
>
> In configure.ac, the comment should be a complete sentence with proper
> capitalization and punctuation.  It should explain why you are using
> libtool.
>
> Thanks.
>
> Ian

Hi Ian,
Thanks for review. Please see modified patch attached.

--
Pavel Chupin
Intel Corporation

[-- Attachment #2: gold-plugins-2.patch --]
[-- Type: application/octet-stream, Size: 2850 bytes --]

commit 96888b5f200b5f077d482dee99f70d8d915aee64
Author: Pavel Chupin <pavel.v.chupin@intel.com>
Date:   Tue Dec 25 14:51:24 2012 +0400

    Fix mingw gold build with plugins enabled
    
    Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>

diff --git a/gold/Makefile.am b/gold/Makefile.am
index df8dcb5..0c13c10 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -37,7 +37,7 @@ AM_CPPFLAGS = \
 LIBIBERTY = ../libiberty/libiberty.a
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @lt_cv_dlopen_libs@
 endif
 
 if THREADS
diff --git a/gold/aclocal.m4 b/gold/aclocal.m4
index 8321894..9f95f1e 100644
--- a/gold/aclocal.m4
+++ b/gold/aclocal.m4
@@ -989,4 +989,9 @@ m4_include([../config/override.m4])
 m4_include([../config/po.m4])
 m4_include([../config/progtest.m4])
 m4_include([../config/zlib.m4])
+m4_include([../libtool.m4])
+m4_include([../ltoptions.m4])
+m4_include([../ltsugar.m4])
+m4_include([../ltversion.m4])
+m4_include([../lt~obsolete.m4])
 m4_include([../bfd/warning.m4])
diff --git a/gold/configure.ac b/gold/configure.ac
index 9d23835..e79d463 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -290,6 +290,13 @@ AC_PROG_LN_S
 
 AC_GNU_SOURCE
 
+dnl When plugins enabled dynamic loader interface is required. Use libtool
+dnl to find library (if any available) which provides dlopen to link with.
+dnl On some systems like windows there is no dlopen available and no extra
+dnl lib required.
+LT_INIT([dlopen])
+AC_SUBST(lt_cv_dlopen_libs)
+
 ZW_GNU_GETTEXT_SISTER_DIR
 AM_PO_SUBDIRS
 
@@ -517,6 +524,9 @@ AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
+
+AC_CHECK_HEADERS(windows.h dlfcn.h)
+
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
diff --git a/gold/plugin.cc b/gold/plugin.cc
index c39e11e..ca497f7 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -29,9 +29,39 @@
 #include <vector>
 
 #ifdef ENABLE_PLUGINS
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#else
+#error Unknown how to handle dynamic-load-libraries.
 #endif
 
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#define RTLD_NOW 0      /* Dummy value.  */
+static void *
+dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary(file);
+}
+
+static void *
+dlsym(void *handle, const char *name)
+{
+  return reinterpret_cast<void *>(
+     GetProcAddress(static_cast<HMODULE>(handle),name));
+}
+
+static const char *
+dlerror(void)
+{
+  return "unable to load dll";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
+#endif /* ENABLE_PLUGINS */
+
 #include "parameters.h"
 #include "errors.h"
 #include "fileread.h"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-09 14:35   ` Pavel Chupin
@ 2013-01-09 15:50     ` Ian Lance Taylor
  2013-01-10  8:25       ` Pavel Chupin
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2013-01-09 15:50 UTC (permalink / raw)
  To: Pavel Chupin; +Cc: binutils

On Wed, Jan 9, 2013 at 6:35 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
> On Sat, Jan 5, 2013 at 11:18 PM, Ian Lance Taylor <iant@google.com> wrote:
>> On Fri, Dec 28, 2012 at 10:41 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>>
>>> Attached patch fixes mingw build configured (for example) as:
>>>
>>> ../configure --prefix=`pwd`/../INSTALL --target=i686-linux-android
>>> --host=i586-pc-mingw32msvc --build=i386-linux-gnu --enable-plugins
>>> --enable-gold
>>> make
>>>
>>> Error message:
>>>
>>> ../../gold/plugin.cc:32:19: fatal error: dlfcn.h: No such file or directory
>>>
>>> I'm fixing it like it's done in bfd configure: check for headers and
>>> library, add/not-add -ldl on link.
>>> Also adding windows.h case into plugin.cc to handle case when
>>> mingw-dlfcn is not installed on the system.
>>>
>>> ChangeLog:
>>>
>>> 2012-12-25  Pavel Chupin  <pavel.v.chupin@intel.com>
>>>
>>>        Fix mingw gold build with plugins enabled
>>>        * gold/Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>>>        * gold/aclocal.m4: Include libtool modules.
>>>        * gold/configure.ac: Export lt_cv_dlopen_libs and add headers check.
>>>        * gold/plugin.cc: Handle non-dlfcn case.
>>>        * gold/Makefile.in: Regenerate.
>>>        * gold/config.in: Regenerate.
>>>        * gold/configure: Regenerate.
>>>        * gold/testsuite/Makefile.in: Regenerate.
>>
>> Sorry for the slow review.  The general idea is fine but the
>> formatting is wrong.  This is C++ code, not C: no space between
>> function name and left parenthesis.  Keep line lengths less than 80
>> columns--the body of dlsym needs a line break.  Don't define
>> dlclose--it's not called.  dlerror should return an ordinary error
>> string--no capitalization, no punctuation.
>>
>> In configure.ac, the comment should be a complete sentence with proper
>> capitalization and punctuation.  It should explain why you are using
>> libtool.
>>
>> Thanks.
>>
>> Ian
>
> Hi Ian,
> Thanks for review. Please see modified patch attached.

Hmmmm, there is a problem here.  You have introduced the use of
libtool into configure.ac when it was not there before.  When I run
autoreconf, this causes automake to rebuild the linker Makefile to use
libtool rather than the simple commands that it used before.  I'm not
at all sure that that is a good idea.

Can we get this information without using libtool?

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-09 15:50     ` Ian Lance Taylor
@ 2013-01-10  8:25       ` Pavel Chupin
  2013-01-10 18:04         ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Chupin @ 2013-01-10  8:25 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

On Wed, Jan 9, 2013 at 7:50 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Wed, Jan 9, 2013 at 6:35 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>> On Sat, Jan 5, 2013 at 11:18 PM, Ian Lance Taylor <iant@google.com> wrote:
>>> On Fri, Dec 28, 2012 at 10:41 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>>>
>>>> Attached patch fixes mingw build configured (for example) as:
>>>>
>>>> ../configure --prefix=`pwd`/../INSTALL --target=i686-linux-android
>>>> --host=i586-pc-mingw32msvc --build=i386-linux-gnu --enable-plugins
>>>> --enable-gold
>>>> make
>>>>
>>>> Error message:
>>>>
>>>> ../../gold/plugin.cc:32:19: fatal error: dlfcn.h: No such file or directory
>>>>
>>>> I'm fixing it like it's done in bfd configure: check for headers and
>>>> library, add/not-add -ldl on link.
>>>> Also adding windows.h case into plugin.cc to handle case when
>>>> mingw-dlfcn is not installed on the system.
>>>>
>>>> ChangeLog:
>>>>
>>>> 2012-12-25  Pavel Chupin  <pavel.v.chupin@intel.com>
>>>>
>>>>        Fix mingw gold build with plugins enabled
>>>>        * gold/Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>>>>        * gold/aclocal.m4: Include libtool modules.
>>>>        * gold/configure.ac: Export lt_cv_dlopen_libs and add headers check.
>>>>        * gold/plugin.cc: Handle non-dlfcn case.
>>>>        * gold/Makefile.in: Regenerate.
>>>>        * gold/config.in: Regenerate.
>>>>        * gold/configure: Regenerate.
>>>>        * gold/testsuite/Makefile.in: Regenerate.
>>>
>>> Sorry for the slow review.  The general idea is fine but the
>>> formatting is wrong.  This is C++ code, not C: no space between
>>> function name and left parenthesis.  Keep line lengths less than 80
>>> columns--the body of dlsym needs a line break.  Don't define
>>> dlclose--it's not called.  dlerror should return an ordinary error
>>> string--no capitalization, no punctuation.
>>>
>>> In configure.ac, the comment should be a complete sentence with proper
>>> capitalization and punctuation.  It should explain why you are using
>>> libtool.
>>>
>>> Thanks.
>>>
>>> Ian
>>
>> Hi Ian,
>> Thanks for review. Please see modified patch attached.
>
> Hmmmm, there is a problem here.  You have introduced the use of
> libtool into configure.ac when it was not there before.  When I run
> autoreconf, this causes automake to rebuild the linker Makefile to use
> libtool rather than the simple commands that it used before.  I'm not
> at all sure that that is a good idea.
>
> Can we get this information without using libtool?
>
> Ian

Well, we need to find the library which provides dlopen somehow.
libtool is doing that the long and correct way, it checks the
architecture, and tries different options to determine available
library. libtool is shared between several projects so if any fix is
made it will be propagated. IMHO it is the best long term fix. I don't
know if it's possible to reuse only LT_INIT(dlopen) part of libtool,
my attempts failed.

My goal is to fix mingw build when there is no libdl. If we don't
really care about other libraries which may provide dlopen I can try
to implement the following:

1) Check for dlfcn.h header
2) If found just add hardcoded -ldl. If not found add nothing.

What do you think?

--
Pavel Chupin
Intel Corporation

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-10  8:25       ` Pavel Chupin
@ 2013-01-10 18:04         ` Ian Lance Taylor
  2013-01-11 12:31           ` Pavel Chupin
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2013-01-10 18:04 UTC (permalink / raw)
  To: Pavel Chupin; +Cc: binutils

On Thu, Jan 10, 2013 at 12:24 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
> On Wed, Jan 9, 2013 at 7:50 PM, Ian Lance Taylor <iant@google.com> wrote:
>>
>> Hmmmm, there is a problem here.  You have introduced the use of
>> libtool into configure.ac when it was not there before.  When I run
>> autoreconf, this causes automake to rebuild the linker Makefile to use
>> libtool rather than the simple commands that it used before.  I'm not
>> at all sure that that is a good idea.
>>
>> Can we get this information without using libtool?
>>
>> Ian
>
> Well, we need to find the library which provides dlopen somehow.
> libtool is doing that the long and correct way, it checks the
> architecture, and tries different options to determine available
> library. libtool is shared between several projects so if any fix is
> made it will be propagated. IMHO it is the best long term fix. I don't
> know if it's possible to reuse only LT_INIT(dlopen) part of libtool,
> my attempts failed.
>
> My goal is to fix mingw build when there is no libdl. If we don't
> really care about other libraries which may provide dlopen I can try
> to implement the following:
>
> 1) Check for dlfcn.h header
> 2) If found just add hardcoded -ldl. If not found add nothing.
>
> What do you think?

I'm fine with that since it is no worse than what we have today.

Ian

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-10 18:04         ` Ian Lance Taylor
@ 2013-01-11 12:31           ` Pavel Chupin
  2013-01-11 14:36             ` Ian Lance Taylor
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Chupin @ 2013-01-11 12:31 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]

On Thu, Jan 10, 2013 at 10:04 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Thu, Jan 10, 2013 at 12:24 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>> On Wed, Jan 9, 2013 at 7:50 PM, Ian Lance Taylor <iant@google.com> wrote:
>>>
>>> Hmmmm, there is a problem here.  You have introduced the use of
>>> libtool into configure.ac when it was not there before.  When I run
>>> autoreconf, this causes automake to rebuild the linker Makefile to use
>>> libtool rather than the simple commands that it used before.  I'm not
>>> at all sure that that is a good idea.
>>>
>>> Can we get this information without using libtool?
>>>
>>> Ian
>>
>> Well, we need to find the library which provides dlopen somehow.
>> libtool is doing that the long and correct way, it checks the
>> architecture, and tries different options to determine available
>> library. libtool is shared between several projects so if any fix is
>> made it will be propagated. IMHO it is the best long term fix. I don't
>> know if it's possible to reuse only LT_INIT(dlopen) part of libtool,
>> my attempts failed.
>>
>> My goal is to fix mingw build when there is no libdl. If we don't
>> really care about other libraries which may provide dlopen I can try
>> to implement the following:
>>
>> 1) Check for dlfcn.h header
>> 2) If found just add hardcoded -ldl. If not found add nothing.
>>
>> What do you think?
>
> I'm fine with that since it is no worse than what we have today.
>
> Ian

Ok. Please see patch attached.

ChangeLog:

2013-01-11  Pavel Chupin  <pavel.v.chupin@intel.com>

        Fix mingw gold build with plugins enabled
        * Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
        * configure.ac: Export lt_cv_dlopen_libs and add headers check.
        * plugin.cc: Handle non-dlfcn case.
        * Makefile.in: Regenerate.
        * config.in: Regenerate.
        * configure: Regenerate.
        * testsuite/Makefile.in: Regenerate.

--
Pavel Chupin
Intel Corporation

[-- Attachment #2: gold-plugins-3.patch --]
[-- Type: application/octet-stream, Size: 2242 bytes --]

commit 7d04eca24fb83cf38176490460ee77a7fc40d458
Author: Pavel Chupin <pavel.v.chupin@intel.com>
Date:   Fri Jan 11 14:00:44 2013 +0400

    Fix mingw gold build with plugins enabled
    
    Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>

diff --git a/gold/Makefile.am b/gold/Makefile.am
index df8dcb5..0c13c10 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -37,7 +37,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 804a474..9ab7973 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -505,6 +505,13 @@ AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
+
+dnl When plugins enabled dynamic loader interface is required. Check headers
+dnl which may provide this interface. In case of dlfcn.h add libdl to link.
+AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADERS(dlfcn.h,lt_cv_dlopen_libs="-ldl",lt_cv_dlopen_libs="")
+AC_SUBST(lt_cv_dlopen_libs)
+
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
diff --git a/gold/plugin.cc b/gold/plugin.cc
index c39e11e..ca497f7 100644
--- a/gold/plugin.cc
+++ b/gold/plugin.cc
@@ -29,9 +29,39 @@
 #include <vector>
 
 #ifdef ENABLE_PLUGINS
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#else
+#error Unknown how to handle dynamic-load-libraries.
 #endif
 
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#define RTLD_NOW 0      /* Dummy value.  */
+static void *
+dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary(file);
+}
+
+static void *
+dlsym(void *handle, const char *name)
+{
+  return reinterpret_cast<void *>(
+     GetProcAddress(static_cast<HMODULE>(handle),name));
+}
+
+static const char *
+dlerror(void)
+{
+  return "unable to load dll";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
+#endif /* ENABLE_PLUGINS */
+
 #include "parameters.h"
 #include "errors.h"
 #include "fileread.h"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-11 12:31           ` Pavel Chupin
@ 2013-01-11 14:36             ` Ian Lance Taylor
  2013-01-14 14:12               ` Pavel Chupin
  0 siblings, 1 reply; 9+ messages in thread
From: Ian Lance Taylor @ 2013-01-11 14:36 UTC (permalink / raw)
  To: Pavel Chupin; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 749 bytes --]

On Fri, Jan 11, 2013 at 4:31 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
> 2013-01-11  Pavel Chupin  <pavel.v.chupin@intel.com>
>
>         Fix mingw gold build with plugins enabled
>         * Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>         * configure.ac: Export lt_cv_dlopen_libs and add headers check.
>         * plugin.cc: Handle non-dlfcn case.
>         * Makefile.in: Regenerate.
>         * config.in: Regenerate.
>         * configure: Regenerate.
>         * testsuite/Makefile.in: Regenerate.

Thanks.  Using lt_cv_dlopen_libs isn't right, because the variable is
no longer being set by libtool.  There is in any case no need to cache
it for this usage, so I changed it to DLOPEN_LIBS.  Committed as
attached.

Ian

[-- Attachment #2: foo.patch --]
[-- Type: application/octet-stream, Size: 3977 bytes --]

Index: Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/Makefile.am,v
retrieving revision 1.69
diff -u -r1.69 Makefile.am
--- Makefile.am	17 Dec 2012 16:56:02 -0000	1.69
+++ Makefile.am	11 Jan 2013 14:24:35 -0000
@@ -1,6 +1,7 @@
 ## Process this file with automake to generate Makefile.in
 #
-#   Copyright 2012 Free Software Foundation
+#  Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
+#  Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -37,7 +38,7 @@
 LIBIBERTY = ../libiberty/libiberty.a
 
 if PLUGINS
-LIBDL = -ldl
+LIBDL = @DLOPEN_LIBS@
 endif
 
 if THREADS
Index: configure.ac
===================================================================
RCS file: /cvs/src/src/gold/configure.ac,v
retrieving revision 1.83
diff -u -r1.83 configure.ac
--- configure.ac	7 Jan 2013 19:55:41 -0000	1.83
+++ configure.ac	11 Jan 2013 14:24:36 -0000
@@ -1,6 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl
-dnl   Copyright 2012 Free Software Foundation
+dnl   Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
+dnl   Free Software Foundation, Inc.
 dnl
 dnl This file is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -505,6 +506,13 @@
 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
 AC_CHECK_HEADERS(byteswap.h)
+
+dnl When plugins enabled dynamic loader interface is required. Check headers
+dnl which may provide this interface. In case of dlfcn.h add libdl to link.
+AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADERS(dlfcn.h, [DLOPEN_LIBS="-ldl"], [DLOPEN_LIBS=""])
+AC_SUBST(DLOPEN_LIBS)
+
 AC_CHECK_FUNCS(mallinfo posix_fallocate fallocate readv sysconf times)
 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
 
Index: plugin.cc
===================================================================
RCS file: /cvs/src/src/gold/plugin.cc,v
retrieving revision 1.55
diff -u -r1.55 plugin.cc
--- plugin.cc	24 Aug 2012 18:35:34 -0000	1.55
+++ plugin.cc	11 Jan 2013 14:24:36 -0000
@@ -1,6 +1,6 @@
 // plugin.cc -- plugin manager for gold      -*- C++ -*-
 
-// Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
 // Written by Cary Coutant <ccoutant@google.com>.
 
 // This file is part of gold.
@@ -29,9 +29,39 @@
 #include <vector>
 
 #ifdef ENABLE_PLUGINS
+#ifdef HAVE_DLFCN_H
 #include <dlfcn.h>
+#elif defined (HAVE_WINDOWS_H)
+#include <windows.h>
+#else
+#error Unknown how to handle dynamic-load-libraries.
 #endif
 
+#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
+
+#define RTLD_NOW 0      /* Dummy value.  */
+static void *
+dlopen(const char *file, int mode ATTRIBUTE_UNUSED)
+{
+  return LoadLibrary(file);
+}
+
+static void *
+dlsym(void *handle, const char *name)
+{
+  return reinterpret_cast<void *>(
+     GetProcAddress(static_cast<HMODULE>(handle),name));
+}
+
+static const char *
+dlerror(void)
+{
+  return "unable to load dll";
+}
+
+#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)  */
+#endif /* ENABLE_PLUGINS */
+
 #include "parameters.h"
 #include "errors.h"
 #include "fileread.h"
cvs diff: Diffing po
cvs diff: Diffing testsuite
Index: testsuite/Makefile.in
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.in,v
retrieving revision 1.215
diff -u -r1.215 Makefile.in
--- testsuite/Makefile.in	10 Jan 2013 00:18:15 -0000	1.215
+++ testsuite/Makefile.in	11 Jan 2013 14:24:36 -0000
@@ -1878,6 +1878,7 @@
 DATADIRNAME = @DATADIRNAME@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLOPEN_LIBS = @DLOPEN_LIBS@
 ECHO_C = @ECHO_C@
 ECHO_N = @ECHO_N@
 ECHO_T = @ECHO_T@

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case
  2013-01-11 14:36             ` Ian Lance Taylor
@ 2013-01-14 14:12               ` Pavel Chupin
  0 siblings, 0 replies; 9+ messages in thread
From: Pavel Chupin @ 2013-01-14 14:12 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

Thanks.

On Fri, Jan 11, 2013 at 6:36 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Fri, Jan 11, 2013 at 4:31 AM, Pavel Chupin <pavel.v.chupin@gmail.com> wrote:
>> 2013-01-11  Pavel Chupin  <pavel.v.chupin@intel.com>
>>
>>         Fix mingw gold build with plugins enabled
>>         * Makefile.am: Replace -ldl with @lt_cv_dlopen_libs@.
>>         * configure.ac: Export lt_cv_dlopen_libs and add headers check.
>>         * plugin.cc: Handle non-dlfcn case.
>>         * Makefile.in: Regenerate.
>>         * config.in: Regenerate.
>>         * configure: Regenerate.
>>         * testsuite/Makefile.in: Regenerate.
>
> Thanks.  Using lt_cv_dlopen_libs isn't right, because the variable is
> no longer being set by libtool.  There is in any case no need to cache
> it for this usage, so I changed it to DLOPEN_LIBS.  Committed as
> attached.
>
> Ian



-- 
Pavel Chupin
Intel Corporation

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-01-14 14:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-28 18:41 [PATCH mingw/gold] Fix mingw gold build with plugins enabled for non-dlfcn case Pavel Chupin
2013-01-05 19:18 ` Ian Lance Taylor
2013-01-09 14:35   ` Pavel Chupin
2013-01-09 15:50     ` Ian Lance Taylor
2013-01-10  8:25       ` Pavel Chupin
2013-01-10 18:04         ` Ian Lance Taylor
2013-01-11 12:31           ` Pavel Chupin
2013-01-11 14:36             ` Ian Lance Taylor
2013-01-14 14:12               ` Pavel Chupin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).