From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by sourceware.org (Postfix) with ESMTPS id 8914A3857801 for ; Mon, 5 Oct 2020 16:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8914A3857801 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x341.google.com with SMTP id k18so200286wmj.5 for ; Mon, 05 Oct 2020 09:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y3B6L40c9KiIh7+isjG0WQ93/aQVKSnxjlsMjRvKxkc=; b=EFKT3yozIfpF0cIvKuUgOGYTue8eWLwO9CzQXAZ1Lrn+N2O5CZgaefXV9xN9+3njPA 3K2t+DaGRlDZ8s1GoLLAYee55bqq/xBokBbH7B2UToabeWmBqEoM8b7w+jTFYjTqP1qi Lshxm8WdmoA6788lFuu/SITXO8Yo9GcR5N9ywlWzcbTdMTCWMsM0kTepMoZPc+nGDo9E 7d9dUCNPjwXHBHwVksyyfalgVs2GBcK/DYqTQqwhTs54NTFiSL2h/R8tKBrlfaY7nlGA bSJNCElHJOHUeUGaunyS79yggEjfYQ3813zUUcMT4YIk/MSmvIhpoxrrho4hJ2aU4ZH/ M9Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y3B6L40c9KiIh7+isjG0WQ93/aQVKSnxjlsMjRvKxkc=; b=i+dde+hcYKBQxtScbiAgv+b+bHCdlY6m5FiWfpdr6BU5+uR1+lJHOkmGWEUlw2+73M fM4thEtOEN+ePGgGWr1hi+iFxRsV3TQ0xRxWjm8xn4WL4+5mtyQ3yxzTwM/sj/zRaH/Z Esbg1tdE2JA6N/H9zTFqvTyeskchH2V9u6LL/uju1Jp9ScqAo0NthwTpJaQyDXNkaqo1 XDM+gbYOuIl9MM62i1+4CNgZwOlkaAo689pTAOrnY1twoieD8G3XA1D6gkyduqNEq1ez C5yaGur4RI8HnKOYch4GY/fecmXQoxVEqRlDbZapHH0e1jcqC1Hc87FS+imGyjHBlhe5 /3aw== X-Gm-Message-State: AOAM532PeUairEYQfrTywnVKOx42x+XkW55zxsUsWPYByy2XZnMMtV2L E9t1qcPl7AfndB/KClQ4H8PzQjwa+4cZ8g== X-Google-Smtp-Source: ABdhPJzbW4lXJodvxOlxUQkHhH88jHlKgqc+HqKlDmkekcALw+SoF+Hr3FhnbYfg4X7e/eKZt9WFYw== X-Received: by 2002:a1c:2901:: with SMTP id p1mr300669wmp.170.1601916697950; Mon, 05 Oct 2020 09:51:37 -0700 (PDT) Received: from localhost (host109-151-14-50.range109-151.btcentralplus.com. [109.151.14.50]) by smtp.gmail.com with ESMTPSA id s12sm179973wmd.20.2020.10.05.09.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 09:51:37 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH] gnulib: Ensure all libraries are used when building gdb/gdbserver Date: Mon, 5 Oct 2020 17:51:34 +0100 Message-Id: <20201005165134.1620549-1-andrew.burgess@embecosm.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2020 16:51:41 -0000 An issue was reported here related to building GDB on MinGW: https://sourceware.org/pipermail/gdb/2020-September/048927.html It was suggested here: https://sourceware.org/pipermail/gdb/2020-September/048931.html that the solution might be to make use of $(LIB_GETRANDOM), a variable defined in the gnulib makefile, when linking GDB. In fact I think the issue is bigger than just LIB_GETRANDOM. When using the script binutils-gdb/gnulib/update-gnulib.sh to reimport gnulib there is a lot of output from gnulib's gnulib-tool. Part of that output is this: You may need to use the following makefile variables when linking. Use them in _LDADD when linking a program, or in _a_LDFLAGS or _la_LDFLAGS when linking a library. $(FREXPL_LIBM) $(FREXP_LIBM) $(INET_NTOP_LIB) $(LIBTHREAD) $(LIB_GETLOGIN) $(LIB_GETRANDOM) $(LIB_HARD_LOCALE) $(LIB_MBRTOWC) $(LIB_SETLOCALE_NULL) $(LTLIBINTL) when linking with libtool, $(LIBINTL) otherwise What I think this is telling us is that we should be including the value of all these variables on the link line for gdb and gdbserver. The problem though is that these variables are define in gnulib's makefile, but are not (necessarily) defined in GDB's makefile. One solution would be to recreate the checks that gnulib performs in order to recreate these variables in both gdb's and gdbserver's makefile. Though this shouldn't be too hard, most (if not all) of these checks are in the form macros defined in m4 files in the gnulib tree, so we could just reference these as needed. However, in this commit I propose a different solution. Currently, in the top level makefile, we give gdb and gdbserver a dependency on gnulib. Once gnulib has finished building gdb and gdbserver can start, these projects then have a hard coded (relative) path to the compiled gnulib library in their makefiles. In this commit I extend the gnulib makefile so that after building the gnulib library we generate a makefile fragment that defines a number of variables, these variables are: LIBGNU: The path to the archive containing gnulib. Can be used as a dependency as when this file changes gdb/gdbserver should be relinked. LIBGNU_EXTRA_LIBS: A list of linker -l.... flags that should be included in the link line of gdb/gdbserver. These are libraries that $(LIBGNU) depends on. INCGNU: A list of -I.... include paths that should be passed to the compiler, these are where the gnulib headers can be found. Now both gdb and gdbserver can include the makefile fragment and make use of these variables. As the makefile fragment is generated from within gnulib's makefile, it has full access to the variable list given above. The generated makefile fragment relies on the variable GNULIB_BUILDDIR being defined. This is checked for in the fragment, and was already defined in gdb and gdbserver. gdb/ChangeLog: * Makefile.in: Include Makefile.gnulib.inc. Don't define LIBGNU or INCGNU. Make use of LIBGNU_EXTRA_LIBS when linking. gdbserver/ChangeLog: * Makefile.in: Include Makefile.gnulib.inc. Don't define LIBGNU or INCGNU. Make use of LIBGNU_EXTRA_LIBS when linking. gnulib/ChangeLog: * Makefile.am: Add rule to generate Makefile.gnulib.inc. * Makefile.in: Regenerate. --- gdb/ChangeLog | 5 +++++ gdb/Makefile.in | 5 ++--- gdbserver/ChangeLog | 5 +++++ gdbserver/Makefile.in | 11 +++++------ gnulib/ChangeLog | 5 +++++ gnulib/Makefile.am | 36 ++++++++++++++++++++++++++++++++++++ gnulib/Makefile.in | 40 ++++++++++++++++++++++++++++++++++++++-- 7 files changed, 96 insertions(+), 11 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index dbede7a9cfc..18a426dc225 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -239,8 +239,7 @@ GDBFLAGS = # Helper code from gnulib. GNULIB_BUILDDIR = ../gnulib -LIBGNU = $(GNULIB_BUILDDIR)/import/libgnu.a -INCGNU = -I$(srcdir)/../gnulib/import -I$(GNULIB_BUILDDIR)/import +include $(GNULIB_BUILDDIR)/Makefile.gnulib.inc SUPPORT = ../gdbsupport LIBSUPPORT = $(SUPPORT)/libgdbsupport.a @@ -627,7 +626,7 @@ CLIBS = $(SIM) $(READLINE) $(OPCODES) $(LIBCTF) $(BFD) $(ZLIB) \ $(XM_CLIBS) $(GDBTKLIBS) \ @LIBS@ @GUILE_LIBS@ @PYTHON_LIBS@ \ $(LIBEXPAT) $(LIBLZMA) $(LIBBABELTRACE) $(LIBIPT) \ - $(WIN32LIBS) $(LIBGNU) $(LIBICONV) \ + $(WIN32LIBS) $(LIBGNU) $(LIBGNU_EXTRA_LIBS) $(LIBICONV) \ $(LIBMPFR) $(SRCHIGH_LIBS) $(LIBXXHASH) $(PTHREAD_LIBS) \ $(DEBUGINFOD_LIBS) CDEPS = $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE_DEPS) $(CTF_DEPS) \ diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in index b0bad0cdb09..54b3f3becc4 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -111,8 +111,7 @@ ustinc = @ustinc@ # gnulib GNULIB_BUILDDIR = ../gnulib -LIBGNU = $(GNULIB_BUILDDIR)/import/libgnu.a -INCGNU = -I$(srcdir)/../gnulib/import -I$(GNULIB_BUILDDIR)/import +include $(GNULIB_BUILDDIR)/Makefile.gnulib.inc # Where is the INTL library? Typically in ../intl. INTL = @LIBINTL@ @@ -352,16 +351,16 @@ gdbserver$(EXEEXT): $(sort $(OBS)) ${CDEPS} $(LIBGNU) $(LIBIBERTY) \ $(SILENCE) rm -f gdbserver$(EXEEXT) $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \ -o gdbserver$(EXEEXT) $(OBS) $(GDBSUPPORT) $(LIBGNU) \ - $(LIBIBERTY) $(INTL) $(GDBSERVER_LIBS) $(XM_CLIBS) \ - $(WIN32APILIBS) + $(LIBGNU_EXTRA_LIBS) $(LIBIBERTY) $(INTL) \ + $(GDBSERVER_LIBS) $(XM_CLIBS) $(WIN32APILIBS) gdbreplay$(EXEEXT): $(sort $(GDBREPLAY_OBS)) $(LIBGNU) $(LIBIBERTY) \ $(INTL_DEPS) $(GDBSUPPORT) $(SILENCE) rm -f gdbreplay$(EXEEXT) $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \ -o gdbreplay$(EXEEXT) $(GDBREPLAY_OBS) $(XM_CLIBS) \ - $(GDBSUPPORT) $(LIBGNU) $(LIBIBERTY) $(INTL) \ - $(WIN32APILIBS) + $(GDBSUPPORT) $(LIBGNU) $(LIBGNU_EXTRA_LIBS) \ + $(LIBIBERTY) $(INTL) $(WIN32APILIBS) IPA_OBJS = \ alloc-ipa.o \ diff --git a/gnulib/Makefile.am b/gnulib/Makefile.am index 3732e4d0dc2..29ac3f209e4 100644 --- a/gnulib/Makefile.am +++ b/gnulib/Makefile.am @@ -26,3 +26,39 @@ MAKEOVERRIDES = SUBDIRS = import + +# Generate a makefile snippet that lists all of the libraries that +# should be pulled in when linking against gnulib. Both GDB and +# GDBSERVER will include this snippet. +# +# The defined variables are: +# +# LIBGNU: The path to the archive containing gnulib. Can be used as a +# dependency as when this file changes gdb/gdbserver should be +# relinked. +# +# LIBGNU_EXTRA_LIBS: A list of linker -l.... flags that should be +# included in the link line of gdb/gdbserver. These are +# libraries that $(LIBGNU) depends on. +# +# INCGNU: A list of -I.... include paths that should be passed to the +# compiler, these are where the gnulib headers can be found. + +Makefile.gnulib.inc: $(builddir)/Makefile + $(AM_V_GEN) + @rm -f Makefile.gnulib.inc + @echo "ifndef GNULIB_BUILDDIR" > Makefile.gnulib.inc + @echo "\$$(error missing GNULIB_BUILDDIR)" >> Makefile.gnulib.inc + @echo "endif" >> Makefile.gnulib.inc + @echo "" >> Makefile.gnulib.inc + @echo "LIBGNU = \$$(GNULIB_BUILDDIR)/import/libgnu.a" \ + >> Makefile.gnulib.inc + @echo "LIBGNU_EXTRA_LIBS = $(FREXPL_LIBM) $(FREXP_LIBM) \ + $(INET_NTOP_LIB) $(LIBTHREAD) $(LIB_GETLOGIN) \ + $(LIB_GETRANDOM) $(LIB_HARD_LOCALE) $(LIB_MBRTOWC) \ + $(LIB_SETLOCALE_NULL)" | sed "s/ \+$$//" \ + >> Makefile.gnulib.inc + @echo "INCGNU = -I\$$(srcdir)/../gnulib/import -I\$$(GNULIB_BUILDDIR)/import" \ + >> Makefile.gnulib.inc + +all-local: Makefile.gnulib.inc diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in index bdd3c3f3fbc..40ff899c943 100644 --- a/gnulib/Makefile.in +++ b/gnulib/Makefile.in @@ -1750,7 +1750,7 @@ distclean-tags: -rm -f cscope.out cscope.in.out cscope.po.out cscope.files check-am: all-am check: check-recursive -all-am: Makefile config.h +all-am: Makefile config.h all-local installdirs: installdirs-recursive installdirs-am: install: install-recursive @@ -1854,7 +1854,7 @@ uninstall-am: .MAKE: $(am__recursive_targets) all install-am install-strip -.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am all-local \ am--refresh check check-am clean clean-cscope clean-generic \ cscope cscopelist-am ctags ctags-am distclean \ distclean-generic distclean-hdr distclean-tags dvi dvi-am html \ @@ -1870,6 +1870,42 @@ uninstall-am: .PRECIOUS: Makefile +# Generate a makefile snippet that lists all of the libraries that +# should be pulled in when linking against gnulib. Both GDB and +# GDBSERVER will include this snippet. +# +# The defined variables are: +# +# LIBGNU: The path to the archive containing gnulib. Can be used as a +# dependency as when this file changes gdb/gdbserver should be +# relinked. +# +# LIBGNU_EXTRA_LIBS: A list of linker -l.... flags that should be +# included in the link line of gdb/gdbserver. These are +# libraries that $(LIBGNU) depends on. +# +# INCGNU: A list of -I.... include paths that should be passed to the +# compiler, these are where the gnulib headers can be found. + +Makefile.gnulib.inc: $(builddir)/Makefile + $(AM_V_GEN) + @rm -f Makefile.gnulib.inc + @echo "ifndef GNULIB_BUILDDIR" > Makefile.gnulib.inc + @echo "\$$(error missing GNULIB_BUILDDIR)" >> Makefile.gnulib.inc + @echo "endif" >> Makefile.gnulib.inc + @echo "" >> Makefile.gnulib.inc + @echo "LIBGNU = \$$(GNULIB_BUILDDIR)/import/libgnu.a" \ + >> Makefile.gnulib.inc + @echo "LIBGNU_EXTRA_LIBS = $(FREXPL_LIBM) $(FREXP_LIBM) \ + $(INET_NTOP_LIB) $(LIBTHREAD) $(LIB_GETLOGIN) \ + $(LIB_GETRANDOM) $(LIB_HARD_LOCALE) $(LIB_MBRTOWC) \ + $(LIB_SETLOCALE_NULL)" | sed "s/ \+$$//" \ + >> Makefile.gnulib.inc + @echo "INCGNU = -I\$$(srcdir)/../gnulib/import -I\$$(GNULIB_BUILDDIR)/import" \ + >> Makefile.gnulib.inc + +all-local: Makefile.gnulib.inc + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: -- 2.25.4