public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Clément Chigot" <chigot@adacore.com>
To: binutils@sourceware.org
Cc: "Clément Chigot" <chigot@adacore.com>
Subject: [PATCH] ld: build libdep plugin only when shared library support is enabled
Date: Thu, 13 Apr 2023 09:49:14 +0200	[thread overview]
Message-ID: <20230413074914.354662-1-chigot@adacore.com> (raw)

Otherwise, libtool will create a static plugin which cannot be loaded.
Even worse on Windows, it will create a .a file, resulting in a similar
bug than PR 27113: some tools will try to open it and Windows will raise
a popup error.
---
 ld/Makefile.am  |  5 +++++
 ld/Makefile.in  | 19 +++++++++++--------
 ld/configure    | 19 +++++++++++++++++--
 ld/configure.ac |  2 ++
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 0e9bed88f65..cedacf01239 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -1029,6 +1029,7 @@ libldtestplug4_la_CFLAGS= -g -O2
 libldtestplug4_la_LDFLAGS = -no-undefined -rpath /nowhere
 
 bfdplugindir = $(libdir)/bfd-plugins
+if ENABLE_SHARED
 bfdplugin_LTLIBRARIES = libdep.la
 libdep_la_SOURCES = libdep_plugin.c
 libdep_la_LDFLAGS = -no-undefined -rpath /nowhere -module -avoid-version
@@ -1036,6 +1037,9 @@ libdep_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
 	--tag=disable-static \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
 	$(libdep_la_LDFLAGS) $(LDFLAGS) -o $@
+else
+bfdplugin_LTLIBRARIES =
+endif
 
 # DOCUMENTATION TARGETS
 # Manual configuration file; not usually attached to normal configuration,
@@ -1111,6 +1115,7 @@ install-data-local: install-bfdpluginLTLIBRARIES
 	for f in ldscripts/* ; do \
 	  $(INSTALL_DATA) $$f $(DESTDIR)$(scriptdir)/$$f ; \
 	done
+	test -d $(DESTDIR)$(bfdplugindir) || $(MKDIR_P) $(DESTDIR)$(bfdplugindir)
 	rm -f $(DESTDIR)$(bfdplugindir)/libdep.la
 	rm -f $(DESTDIR)$(bfdplugindir)/libdep.dll.a
 
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 15f88bf606d..855d6efc6f8 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -172,8 +172,9 @@ am__installdirs = "$(DESTDIR)$(bfdplugindir)" "$(DESTDIR)$(bindir)" \
 	"$(DESTDIR)$(infodir)" "$(DESTDIR)$(man1dir)"
 LTLIBRARIES = $(bfdplugin_LTLIBRARIES) $(noinst_LTLIBRARIES)
 libdep_la_LIBADD =
-am_libdep_la_OBJECTS = libdep_plugin.lo
+@ENABLE_SHARED_TRUE@am_libdep_la_OBJECTS = libdep_plugin.lo
 libdep_la_OBJECTS = $(am_libdep_la_OBJECTS)
+@ENABLE_SHARED_TRUE@am_libdep_la_rpath = -rpath $(bfdplugindir)
 libldtestplug_la_LIBADD =
 am_libldtestplug_la_OBJECTS = libldtestplug_la-testplug.lo
 libldtestplug_la_OBJECTS = $(am_libldtestplug_la_OBJECTS)
@@ -1044,13 +1045,14 @@ libldtestplug4_la_SOURCES = testplug4.c
 libldtestplug4_la_CFLAGS = -g -O2
 libldtestplug4_la_LDFLAGS = -no-undefined -rpath /nowhere
 bfdplugindir = $(libdir)/bfd-plugins
-bfdplugin_LTLIBRARIES = libdep.la
-libdep_la_SOURCES = libdep_plugin.c
-libdep_la_LDFLAGS = -no-undefined -rpath /nowhere -module -avoid-version
-libdep_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
-	--tag=disable-static \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(libdep_la_LDFLAGS) $(LDFLAGS) -o $@
+@ENABLE_SHARED_FALSE@bfdplugin_LTLIBRARIES = 
+@ENABLE_SHARED_TRUE@bfdplugin_LTLIBRARIES = libdep.la
+@ENABLE_SHARED_TRUE@libdep_la_SOURCES = libdep_plugin.c
+@ENABLE_SHARED_TRUE@libdep_la_LDFLAGS = -no-undefined -rpath /nowhere -module -avoid-version
+@ENABLE_SHARED_TRUE@libdep_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+@ENABLE_SHARED_TRUE@	--tag=disable-static \
+@ENABLE_SHARED_TRUE@	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+@ENABLE_SHARED_TRUE@	$(libdep_la_LDFLAGS) $(LDFLAGS) -o $@
 
 MAINTAINERCLEANFILES = configdoc.texi ld.1 ld.info
 
@@ -2755,6 +2757,7 @@ install-data-local: install-bfdpluginLTLIBRARIES
 	for f in ldscripts/* ; do \
 	  $(INSTALL_DATA) $$f $(DESTDIR)$(scriptdir)/$$f ; \
 	done
+	test -d $(DESTDIR)$(bfdplugindir) || $(MKDIR_P) $(DESTDIR)$(bfdplugindir)
 	rm -f $(DESTDIR)$(bfdplugindir)/libdep.la
 	rm -f $(DESTDIR)$(bfdplugindir)/libdep.dll.a
 diststuff: info $(EXTRA_DIST)
diff --git a/ld/configure b/ld/configure
index 03b9e46f56d..607c7fce6b4 100755
--- a/ld/configure
+++ b/ld/configure
@@ -676,6 +676,8 @@ INCINTL
 LIBINTL_DEP
 LIBINTL
 USE_NLS
+ENABLE_SHARED_FALSE
+ENABLE_SHARED_TRUE
 WARN_WRITE_STRINGS
 NO_WERROR
 WARN_CFLAGS_FOR_BUILD
@@ -11625,7 +11627,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11628 "configure"
+#line 11630 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11731,7 +11733,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11734 "configure"
+#line 11736 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16051,6 +16053,15 @@ if test -z "$host" ; then
     as_fn_error $? "Unrecognized host system type; please check config.sub." "$LINENO" 5
 fi
 
+ if test "${enable_shared}" = yes; then
+  ENABLE_SHARED_TRUE=
+  ENABLE_SHARED_FALSE='#'
+else
+  ENABLE_SHARED_TRUE='#'
+  ENABLE_SHARED_FALSE=
+fi
+
+
 # host-specific stuff:
 
 ALL_LINGUAS="bg da de es fi fr ga id it ja pt_BR ru sr sv tr uk vi zh_CN zh_TW"
@@ -17678,6 +17689,10 @@ if test -z "${ENABLE_LIBCTF_TRUE}" && test -z "${ENABLE_LIBCTF_FALSE}"; then
   as_fn_error $? "conditional \"ENABLE_LIBCTF\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${ENABLE_SHARED_TRUE}" && test -z "${ENABLE_SHARED_FALSE}"; then
+  as_fn_error $? "conditional \"ENABLE_SHARED\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then
   as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/ld/configure.ac b/ld/configure.ac
index 77edac3258c..4c63fa56184 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -338,6 +338,8 @@ if test -z "$host" ; then
     AC_MSG_ERROR(Unrecognized host system type; please check config.sub.)
 fi
 
+AM_CONDITIONAL(ENABLE_SHARED, test "${enable_shared}" = yes)
+
 # host-specific stuff:
 
 ALL_LINGUAS="bg da de es fi fr ga id it ja pt_BR ru sr sv tr uk vi zh_CN zh_TW"
-- 
2.25.1


             reply	other threads:[~2023-04-13  7:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13  7:49 Clément Chigot [this message]
2023-04-13  8:54 ` Howard Chu
2023-04-13  8:59   ` Clément Chigot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230413074914.354662-1-chigot@adacore.com \
    --to=chigot@adacore.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).