From 0bf402d505d293fd9ceaa6bf7ca7bd4d910fd545 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 11 Jan 2013 14:36:36 +0000 Subject: [PATCH] Fix mingw gold build with plugins enabled * Makefile.am: Replace -ldl with @DLOPEN_LIBS@. * configure.ac: Export DLOPEN_LIBS and add headers check. * plugin.cc: Handle non-dlfcn case. * Makefile.in: Regenerate. * config.in: Regenerate. * configure: Regenerate. * testsuite/Makefile.in: Regenerate. --- gold/ChangeLog | 11 +++++++++++ gold/Makefile.am | 5 +++-- gold/Makefile.in | 6 ++++-- gold/config.in | 6 ++++++ gold/configure | 30 ++++++++++++++++++++++++++++++ gold/configure.ac | 10 +++++++++- gold/plugin.cc | 32 +++++++++++++++++++++++++++++++- gold/testsuite/Makefile.in | 1 + 8 files changed, 95 insertions(+), 6 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index 72271fa3ea..916250d26c 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,14 @@ +2013-01-11 Pavel Chupin + + Fix mingw gold build with plugins enabled + * Makefile.am: Replace -ldl with @DLOPEN_LIBS@. + * configure.ac: Export DLOPEN_LIBS and add headers check. + * plugin.cc: Handle non-dlfcn case. + * Makefile.in: Regenerate. + * config.in: Regenerate. + * configure: Regenerate. + * testsuite/Makefile.in: Regenerate. + 2013-01-09 Sriraman Tallam * output.h (sort_attached_input_sections): Change to be public. diff --git a/gold/Makefile.am b/gold/Makefile.am index df8dcb5201..f6ced44c7e 100644 --- a/gold/Makefile.am +++ b/gold/Makefile.am @@ -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 @@ AM_CPPFLAGS = \ LIBIBERTY = ../libiberty/libiberty.a if PLUGINS -LIBDL = -ldl +LIBDL = @DLOPEN_LIBS@ endif if THREADS diff --git a/gold/Makefile.in b/gold/Makefile.in index 216532a5d2..f12832b17d 100644 --- a/gold/Makefile.in +++ b/gold/Makefile.in @@ -16,7 +16,8 @@ @SET_MAKE@ # -# 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 @@ -272,6 +273,7 @@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLOPEN_LIBS = @DLOPEN_LIBS@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ @@ -398,7 +400,7 @@ AM_CPPFLAGS = \ -DTOOLLIBDIR="\"$(tooldir)/lib\"" @INCINTL@ LIBIBERTY = ../libiberty/libiberty.a -@PLUGINS_TRUE@LIBDL = -ldl +@PLUGINS_TRUE@LIBDL = @DLOPEN_LIBS@ @THREADS_TRUE@THREADSLIB = -lpthread AM_YFLAGS = -d diff --git a/gold/config.in b/gold/config.in index 42252bf5a5..d46fd75748 100644 --- a/gold/config.in +++ b/gold/config.in @@ -73,6 +73,9 @@ don't. */ #undef HAVE_DECL_VSNPRINTF +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + /* Define to 1 if you have the header file. */ #undef HAVE_EXT_HASH_MAP @@ -184,6 +187,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + /* Define to 1 if you have the header file. */ #undef HAVE_ZLIB_H diff --git a/gold/configure b/gold/configure index 9e1ee27306..7e58cdfd52 100755 --- a/gold/configure +++ b/gold/configure @@ -596,6 +596,7 @@ MAINTAINER_MODE_FALSE MAINTAINER_MODE_TRUE HAVE_PUBNAMES_FALSE HAVE_PUBNAMES_TRUE +DLOPEN_LIBS CXXCPP HAVE_ZLIB_FALSE HAVE_ZLIB_TRUE @@ -7139,6 +7140,35 @@ fi done + +for ac_header in windows.h +do : + ac_fn_cxx_check_header_mongrel "$LINENO" "windows.h" "ac_cv_header_windows_h" "$ac_includes_default" +if test "x$ac_cv_header_windows_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_WINDOWS_H 1 +_ACEOF + +fi + +done + +for ac_header in dlfcn.h +do : + ac_fn_cxx_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default" +if test "x$ac_cv_header_dlfcn_h" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DLFCN_H 1 +_ACEOF + DLOPEN_LIBS="-ldl" +else + DLOPEN_LIBS="" +fi + +done + + + for ac_func in mallinfo posix_fallocate fallocate readv sysconf times do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/gold/configure.ac b/gold/configure.ac index 804a474a9b..b03c09de0d 100644 --- a/gold/configure.ac +++ b/gold/configure.ac @@ -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_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, [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]) diff --git a/gold/plugin.cc b/gold/plugin.cc index c39e11ecf9..9176e066ef 100644 --- a/gold/plugin.cc +++ b/gold/plugin.cc @@ -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 . // This file is part of gold. @@ -29,9 +29,39 @@ #include #ifdef ENABLE_PLUGINS +#ifdef HAVE_DLFCN_H #include +#elif defined (HAVE_WINDOWS_H) +#include +#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( + GetProcAddress(static_cast(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" diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 6e22934f93..b2eb352ded 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -1878,6 +1878,7 @@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLOPEN_LIBS = @DLOPEN_LIBS@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@