From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id AEF6A3857C44 for ; Wed, 7 Oct 2020 15:33:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AEF6A3857C44 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-wr1-x443.google.com with SMTP id n15so2719804wrq.2 for ; Wed, 07 Oct 2020 08:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cgE/XvMvStinJUxD2CW5er6ZcGyFUuH5GmVprg0rQJk=; b=Ew6R7nBXwV6p57H1emc/tA+00ktCoTuJSKOmokpa11My9KLvY8FZYDGEFepAFuVFy/ TIh9sUd6N6C9vSeJaFwb0reD3Xe+YBNT8Kp+O6Y0HK1qoDYruWYQ3aJOD8jPO5v0AR8R 5H0H1EomAUb7AvygoE93Yhp8SgITwc5IIOC41bRpYn/e/gB03AmAC3nZiAZNOC51NcBT 2riBg9Ngpj8dZV1fBvGYTPfHI7YRFSgHIwHJzAg6wqGwsQeB4MLk+526qzk6AQJDIigt ykUxbtsysjo8SU6GhwWNWmFvpbSN/Hh2NeQKJeApxaueHFPJQzF2KiJcYiQq2/vDoVPv Dw0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cgE/XvMvStinJUxD2CW5er6ZcGyFUuH5GmVprg0rQJk=; b=L2OTtRsTdW5JZ/aKAZFX3bhos81VELy1HP9x8NPSjxEUmsSAJJ/kAptdBeqMV0We4g Is/a/JFX5Hgx1YNuX68ZCJKSP++vc8QJ98E+IORs1uKQeZughDSpTLaDNWx+0rmUTbwr 4KDCA+kZygaG8bT6aJOZWl/9/5vYW1p7V21lqvP9n2VHMS3Vli3bikZ+qg/hxkfFdiDi F3II/SfXxJDQEI+Cw5aQl325/Udr1arHKn0dNkh0PkJdo9uufBUEeNhKTnTuPgKs7j9j uF50dWYw+B8+FFKBGOj+1TC9avjBUMJb7n7wbaMtglFs9goKDSODGvjSbDV6S8I7Wyv/ t0Og== X-Gm-Message-State: AOAM531+q5HxErUvi0Oldp85K3XHoaiXzdB3ps1ExIlcasjq8uTbEvhT eTW8sW29oIcevq9RJlFjxaPfSEUGG+BkZQ== X-Google-Smtp-Source: ABdhPJxl74ShgSe/EAig0IM0G4sXGileCZaknvUXadLKBU6sBafTwq/UepM4oNNwB111Srty5rWj1w== X-Received: by 2002:adf:b18e:: with SMTP id q14mr4108033wra.176.1602084800855; Wed, 07 Oct 2020 08:33:20 -0700 (PDT) Received: from localhost (host109-151-14-50.range109-151.btcentralplus.com. [109.151.14.50]) by smtp.gmail.com with ESMTPSA id b200sm3415455wme.44.2020.10.07.08.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 08:33:20 -0700 (PDT) Date: Wed, 7 Oct 2020 16:33:19 +0100 From: Andrew Burgess To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gnulib: Ensure all libraries are used when building gdb/gdbserver Message-ID: <20201007153319.GL605036@embecosm.com> References: <20201005165134.1620549-1-andrew.burgess@embecosm.com> <2feb66c2-8f65-7cbf-d1be-ae3d04b45d9a@simark.ca> <20201006121751.GK605036@embecosm.com> <95d52add-47c2-9621-7e60-1ff9a4331324@simark.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <95d52add-47c2-9621-7e60-1ff9a4331324@simark.ca> X-Operating-System: Linux/5.8.12-100.fc31.x86_64 (x86_64) X-Uptime: 16:31:06 up 4 days, 6:43, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: Wed, 07 Oct 2020 15:33:27 -0000 * Simon Marchi [2020-10-06 10:10:25 -0400]: > On 2020-10-06 8:17 a.m., Andrew Burgess wrote: > > The problem here was me unconditionally trying to include > > Makefile.gnulib.inc from the gdb and gdbserver Makefile. The very > > first time you run 'make clean' after applying the patch > > Makefile.gnulib.inc doesn't exist, but the gdb/gdbserver makefiles > > still try to pull the file in unconditionally. > > If the file is generated at configure-time, I think it would be ok for > Makefile.gnulib.inc to be included unconditionally. As when you run > "make clean" after pulling some changes, you're supposed to do to it > from the top level, so Makefile.gnulib.inc will be created before "make > clean" runs in GDB. OK, I made the include compulsory. > > Finally, I don't know if the change was intentional, but the file was > previously named Makefile.gnulib.inc and is now named Makefile.gnulib. > I liked Makefile.gnulib.inc, as it shows it's not a "top-level" > Makefile, it's meant to be included. I just thought 'Makefile.gnulib.inc.in' was a bit much (in the source tree), but I don't really mind. I changed back to use this filename. The patch below has these two fixes. I'll apply in a couple of days unless anyone objects. Thanks, Andrew -- >From 573756867de5b836fc5418499e5037207d692207 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 6 Oct 2020 10:09:06 +0100 Subject: [PATCH] gnulib: Ensure all libraries are used when building gdb/gdbserver 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 configure script to install a new makefile fragment in the gnulib build directory. This new file will have the usual variable substitutions applied to it, and so can include the complete list (see above) of all the extra libraries that are needed when linking against gnulib. In fact the new makefile fragment defines three variables, these 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. This list is taken from the output of gnulib-tool, which is run by our gnulib/update-gnulib.sh script. 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. The makefile fragment relies on the variable GNULIB_BUILDDIR being defined. This is checked for in the fragment, and was already defined in the makefiles of 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.gnulib.inc.in: New file. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac: Install the new file. --- gdb/ChangeLog | 5 ++++ gdb/Makefile.in | 5 ++-- gdbserver/ChangeLog | 5 ++++ gdbserver/Makefile.in | 11 ++++----- gnulib/ChangeLog | 7 ++++++ gnulib/Makefile.gnulib.inc.in | 44 +++++++++++++++++++++++++++++++++++ gnulib/Makefile.in | 4 +++- gnulib/configure | 4 ++++ gnulib/configure.ac | 2 ++ 9 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 gnulib/Makefile.gnulib.inc.in 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.gnulib.inc.in b/gnulib/Makefile.gnulib.inc.in new file mode 100644 index 00000000000..f3fd72b5781 --- /dev/null +++ b/gnulib/Makefile.gnulib.inc.in @@ -0,0 +1,44 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# 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. This list is taken from +# the output of gnulib-tool, which is run by our +# gnulib/update-gnulib.sh script. +# +# INCGNU: A list of -I.... include paths that should be passed to the +# compiler, these are where the gnulib headers can be found. + +ifndef GNULIB_BUILDDIR +$(error missing GNULIB_BUILDDIR) +endif + +LIBGNU = $(GNULIB_BUILDDIR)/import/libgnu.a +LIBGNU_EXTRA_LIBS = @FREXPL_LIBM@ @FREXP_LIBM@ @INET_NTOP_LIB@ \ + @LIBTHREAD@ @LIB_GETLOGIN@ @LIB_GETRANDOM@ \ + @LIB_HARD_LOCALE@ @LIB_MBRTOWC@ \ + @LIB_SETLOCALE_NULL@ @LIBINTL@ +INCGNU = -I$(srcdir)/../gnulib/import -I$(GNULIB_BUILDDIR)/import diff --git a/gnulib/Makefile.in b/gnulib/Makefile.in index bdd3c3f3fbc..c1c21680944 100644 --- a/gnulib/Makefile.in +++ b/gnulib/Makefile.in @@ -277,7 +277,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = Makefile.gnulib.inc CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -1642,6 +1642,8 @@ $(srcdir)/config.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) distclean-hdr: -rm -f config.h stamp-h1 +Makefile.gnulib.inc: $(top_builddir)/config.status $(srcdir)/Makefile.gnulib.inc.in + cd $(top_builddir) && $(SHELL) ./config.status $@ # This directory's subdirectories are mostly independent; you can cd # into them and run 'make' without going through this Makefile. diff --git a/gnulib/configure b/gnulib/configure index 5c6add6e371..6c58a46e42e 100644 --- a/gnulib/configure +++ b/gnulib/configure @@ -30802,6 +30802,9 @@ fi # Checks for libraries. # # ---------------------- # +ac_config_files="$ac_config_files Makefile.gnulib.inc" + + ac_config_files="$ac_config_files Makefile import/Makefile" ac_config_commands="$ac_config_commands default" @@ -31634,6 +31637,7 @@ do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;; "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "Makefile.gnulib.inc") CONFIG_FILES="$CONFIG_FILES Makefile.gnulib.inc" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "import/Makefile") CONFIG_FILES="$CONFIG_FILES import/Makefile" ;; "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; diff --git a/gnulib/configure.ac b/gnulib/configure.ac index acc1b1a322e..052b8bd8dc5 100644 --- a/gnulib/configure.ac +++ b/gnulib/configure.ac @@ -56,6 +56,8 @@ AC_CHECK_TOOL(AR, ar) # Checks for libraries. # # ---------------------- # +AC_CONFIG_FILES(Makefile.gnulib.inc) + AC_OUTPUT(Makefile import/Makefile, [ case x$CONFIG_HEADERS in -- 2.25.4