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]

Re: [patch bfd]: Fix PR ld/12742 for windows targets


On Fri, Mar 9, 2012 at 2:54 PM, Kai Tietz <ktietz70@googlemail.com> wrote:
> Hi,
>
> this patch adds compatible implementation of dlfcn API on Windows
> targets, if this header/API isn't present.
>
> ChangeLog
>
> 2012-03-09 ÂKai Tietz Â<ktietz@redhat.com>
>
> Â Â Â ÂPR ld/12742
> Â Â Â Â* configure.in (AC_CHECK_HEADERS): Test for windows.h and dlfcn.h.
> Â Â Â Â* plugin.c: Guard include of dlfcn.h if HAVE_DLFCN_H is defined.
> Â Â Â ÂAdd windows.h header include if HAVE_WINDOWS_H is defined.
> Â Â Â Â(dlerror): New static function if windows variant is used instead
> Â Â Â Âof dlfcn.h.
> Â Â Â Â(dlclose): Likewise.
> Â Â Â Â(dlopen): Likewise.
> Â Â Â Â(dlsym): Likewise.
> Â Â Â Â* configure: Regenerated.
> Â Â Â Â* config.in: Regenerated.
>
> Tested for i686-w64-mingw32 and x86_64-w64-mingw32. ÂOk for apply?
>
> Regards,
> Kai
>
> Index: config.in
> ===================================================================
> RCS file: /cvs/src/src/bfd/config.in,v
> retrieving revision 1.49
> diff -u -p -r1.49 config.in
> --- config.in  12 May 2011 07:41:40 -0000   Â1.49
> +++ config.in  9 Mar 2012 19:38:18 -0000
> @@ -245,6 +245,9 @@
> Â/* Define if <sys/procfs.h> has win32_pstatus_t. */
> Â#undef HAVE_WIN32_PSTATUS_T
>
> +/* Define to 1 if you have the <windows.h> header file. */
> +#undef HAVE_WINDOWS_H
> +
> Â/* Define to 1 if you have the <zlib.h> header file. */
> Â#undef HAVE_ZLIB_H
>
> Index: configure
> ===================================================================
> RCS file: /cvs/src/src/bfd/configure,v
> retrieving revision 1.359
> diff -u -p -r1.359 configure
> --- configure  25 Feb 2012 19:51:31 -0000   Â1.359
> +++ configure  9 Mar 2012 19:38:21 -0000
> @@ -13508,6 +13508,22 @@ fi
>
> Âfi
>
> +
> +for ac_header in windows.h dlfcn.h
> +do :
> + Âas_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
> +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header"
> "$ac_includes_default"
> +eval as_val=\$$as_ac_Header
> + Â if test "x$as_val" = x""yes; then :
> + Âcat >>confdefs.h <<_ACEOF
> +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
> +_ACEOF
> +
> +fi
> +
> +done
> +
> +
> Â{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether string.h
> and strings.h may both be included" >&5
> Â$as_echo_n "checking whether string.h and strings.h may both be
> included... " >&6; }
> Âif test "${gcc_cv_header_string+set}" = set; then :
> Index: configure.in
> ===================================================================
> RCS file: /cvs/src/src/bfd/configure.in,v
> retrieving revision 1.307
> diff -u -p -r1.307 configure.in
> --- configure.in    Â25 Feb 2012 19:51:32 -0000   Â1.307
> +++ configure.in    Â9 Mar 2012 19:38:21 -0000
> @@ -190,6 +190,9 @@ AC_CHECK_HEADERS(fcntl.h sys/file.h sys/
> ÂGCC_HEADER_STDINT(bfd_stdint.h)
> ÂAC_HEADER_TIME
> ÂAC_HEADER_DIRENT
> +
> +AC_CHECK_HEADERS(windows.h dlfcn.h)
> +
> ÂACX_HEADER_STRING
> ÂAC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid fileno)
> ÂAC_CHECK_FUNCS(strtoull)
> Index: plugin.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/plugin.c,v
> retrieving revision 1.14
> diff -u -p -r1.14 plugin.c
> --- plugin.c  Â11 Jul 2011 15:03:07 -0000   Â1.14
> +++ plugin.c  Â9 Mar 2012 19:38:22 -0000
> @@ -25,7 +25,13 @@
> Â#if BFD_SUPPORTS_PLUGINS
>
> Â#include <assert.h>
> +#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
> Â#include <stdarg.h>
> Â#include "plugin-api.h"
> Â#include "sysdep.h"
> @@ -34,6 +40,37 @@
> Â#include "libiberty.h"
> Â#include <dirent.h>
>
> +#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 GetProcAddress (handle, name);
> +}
> +
> +static int ATTRIBUTE_UNUSED
> +dlclose (void *handle)
> +{
> + ÂFreeLibrary (handle);
> + Âreturn 0;
> +}
> +
> +static const char *
> +dlerror (void)
> +{
> + Âreturn "Unable to load DLL.";
> +}
> +
> +#endif /* !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H) Â*/
> +
> Â#define bfd_plugin_close_and_cleanup
> _bfd_generic_close_and_cleanup
> Â#define bfd_plugin_bfd_free_cached_info
> _bfd_generic_bfd_free_cached_info
> Â#define bfd_plugin_new_section_hook
> _bfd_generic_new_section_hook

If filename is NULL, I believe LoadLibrary will treat the filename as
an ordinal. Perhaps you should explicitly test the char* against NULL
(unless, of course, you want to return the function at ordinal 0):

> +dlopen (const char *file, int mode ATTRIBUTE_UNUSED)
> +{
> + Âreturn LoadLibrary (file);
> +}

I think you wil get expected behavior if there are no ordinals, which
means you might have an intermittent problem.


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