From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fT6GOWi5i2hODAEAWB0awg (envelope-from ) for ; Thu, 31 Jul 2025 14:43:52 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HwBKnuVu; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D90151E102; Thu, 31 Jul 2025 14:43:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 465431E091 for ; Thu, 31 Jul 2025 14:43:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20FB83858D1E for ; Thu, 31 Jul 2025 18:43:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20FB83858D1E Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HwBKnuVu Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id DC9173858D1E for ; Thu, 31 Jul 2025 18:42:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC9173858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DC9173858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753987365; cv=none; b=iFbXPHVU4h5Y/IUR1wFLp5TfBUdEy5ZQh5DZXSjC0EKWf0GLKkq8E3jAN5+nwFYcjqYSraPPpDVxdWKBOTPHgzP1590qtRA6wPF44JBnIzXn5c8+lHmDbXgqflzvmucrZO1mvF7ZKy/QPa7Dov61gSLl8LtkWVFFm/9J8eIHdbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753987365; c=relaxed/simple; bh=Xz/hXZERUnjH/8CzKOCjVo+rGRRc2yOY+SG3DD+3VI8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=HJT8J1a5L9P6cRygKMxMze2qvp+dd6LInMEuZZKGDa8Bye9YQ/EXhU1F+FN7qcOAS9BtGGDwsEV4LZgD2UF8YXniHj1sTTfJDfLqAUlPdK8VPcV1JC3VS2DYiForbzEKAjJR1v6bPsbCpp8a5mYlkwspfGHXJrpX2m2eSE9QaaA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC9173858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753987364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WFmKZQMTda3jF2dzZ72E4imUF2KJYsGXuFPK2sWLJ80=; b=HwBKnuVuwSF8pvRdFncQU7CY1q+RrxVypQiBm+/p9dmoh6xJhzWoMAfDigDfVU9ZFgjBIP T/Hypz26EcuiVJ/a+/RFyWP8QA4ZuDxlAdntazFcuFqrTHef8jA6jM53N98D8yVhQ18uSS wo1+Q0Jxm52AZJTxbrmGJoDxMKwBgkY= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-IHWni80EPHWMpGowPkO54Q-1; Thu, 31 Jul 2025 14:42:42 -0400 X-MC-Unique: IHWni80EPHWMpGowPkO54Q-1 X-Mimecast-MFC-AGG-ID: IHWni80EPHWMpGowPkO54Q_1753987361 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7e33f7a58f6so12401085a.3 for ; Thu, 31 Jul 2025 11:42:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753987361; x=1754592161; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WFmKZQMTda3jF2dzZ72E4imUF2KJYsGXuFPK2sWLJ80=; b=MHX+4/nZtY0tGhNEokXAIOcpzM1i1Ywvq4F5LVBEfX9YR5KAh+R+M4Ah0SrYhekqvD q5p0whGpfH0Zqma6onpH7TVNB1kSfijWxpzQsyYZ84Vxsp1AIR6ajFUDED+8cT7B7t11 0zD0fJ2EfMV4Aq79hvM1M/f8VTN6Ij0U0v1zl/qdK/ZBcdgAMlRwxDijvZkSZZtOd43H SCPwVp3sC2vGgit2r08STdidNQZHn7h/6bpTBHo7cZj/B4nvcy0X/HIMSU72woZ2Rili ufyyWuoiDXWkusBrzjH1R1UGI6HJBL8hoYpPxMF5cXppBt1/FBttLJHmOgQu+xv8yj+O Dy9A== X-Gm-Message-State: AOJu0YxNaC1P16YxDXueBOizwEGW36TTPgP/zkeIm1XJKhE0KkM9fbTV kcBD8nKk9T5Lr+rDcjzyZCXPuatuvynckkDeNhHyc/ZxaetYETxpd40bnFhO0Jibi0EMOusEopz FTfgurWJsKrBW0S+M9iSkZ1yZIfbgNyMy7t9o6xapzXBlFR318poFmBoQHiM7lnXtQNNMxcadUA 4U0f39p8WsNCIYqh1okhh2PSMtbkzNsK68Bb0gxqh2bahyLRPx X-Gm-Gg: ASbGncvQ/FVnnnyznqmLV7hyq9KL46EgdWZ0/8J8T1BsYnjKRu6N0rg3CFF3i6WEKNS xoEEKGk6APJmQZ3C++oVoV7LyRhFF0Bl8BNApRnQTZvm2bJS9UhsAmuaPZ+mIC9UAAuOmokUBAK u4qRaVf2FTGlx1Xs47B7dRpn1GAQGimMSUi6j/yllKlueXuB67DRLxNvH7341WA2e7rZEU0mbdO aWceufnHZ/UykW4coNWGisjbq7+Ulr/9tvi3wAByWr9RgT/wgbdQman3xm+9wn1JhdaoDbxDiNd Z//G/XYA7BtbGbLrBvtfXlPGL78H1ifMfdXHsBMnbkaPCBf9hZY= X-Received: by 2002:a05:620a:a80a:b0:7e3:4416:fdb with SMTP id af79cd13be357-7e66f3de639mr994836485a.62.1753987360481; Thu, 31 Jul 2025 11:42:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeqDcQoAriszX04la6i/4Rx20oe+UUdJc4+f2VgQjSyQbJDwv2c45apKkfggSUh1oDVh1vfw== X-Received: by 2002:a05:620a:a80a:b0:7e3:4416:fdb with SMTP id af79cd13be357-7e66f3de639mr994830785a.62.1753987359679; Thu, 31 Jul 2025 11:42:39 -0700 (PDT) Received: from ?IPV6:2804:14d:8084:9a69::1000? ([2804:14d:8084:9a69::1000]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7e681c8c727sm98368685a.78.2025.07.31.11.42.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Jul 2025 11:42:39 -0700 (PDT) Message-ID: Date: Thu, 31 Jul 2025 15:42:36 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH v6] gdb, configure: Add disable-formats option for configure To: gdb-patches@sourceware.org, guinevere@redhat.com Cc: Eli Zaretskii References: <20250526171111.2633770-1-guinevere@redhat.com> <20250707201657.972546-2-guinevere@redhat.com> From: Guinevere Larsen In-Reply-To: <20250707201657.972546-2-guinevere@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wyyEu_O7BSu_Ij6xkIrusUJQF8il6gWt_MTpg8KKY5Y_1753987361 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Ping :) -- Cheers, Guinevere Larsen She/Her/Hers On 7/7/25 5:16 PM, Guinevere Larsen wrote: > GDB has support for many binary file formats, some which might be very > unlikely to be found in some situations (such as the XCOFF format in > an x86 system). This commit introduces the option for a user to choose > which formats GDB will support at build configuration time. > > This is especially useful to avoid possible security concerns with > readers that aren't expected to be used at all, as they are one of > the simplest vectors for an attacker to try and hit GDB with. This > change can also reduce the size of the final binary, if that is a > concern. > > This commit adds a switch to the configure script allowing a user to > only enable selected file formats, called --enable-binary-file-formats. > The default behavior when the switch is omitted is to compile all file > formats, keeping the original behavior of the script. At the time of > this commit, the valid options for this option are: dbx, coff (which > includes coff-pe), xcoff, mips, elf, macho and all. All is treated > especially, activating all supported readers. > > A few targets may require specific binary file format support, as they > directly call functions defined by the file reader. Specifically, > windows targets require coff support, and rs6000 aix and lynx178 targets > require xcoff support. Considering that those formats are the main - or > only - one available in those targets, I believe it makes sense to > re-enable those readers. If that happens, the script will emit the > following warning: > > FOO is required to support one or more requested targets. Adding it > > Users aren't able to force the disabling of those formats, since GDB > will not compile without those readers. Ideally we'd like to be able > to disable even those formats, in case a user wants to build GDB only > to examine remote files for example, but the current infrastructure > for the file format readers doesn't allow us to do it. > > Mach-O and elf support are also dependent on BFD support being compiled > in. In case one of those was requested and BFD does not support them, > the following error is emitted: > > FOO was requested, but BFD does not support it. > > Finally, this configure switch is also printed by the "show > configuration" command in GDB. > > Reviewed-By: Eli Zaretskii > --- > > This is rebased on current master, there was a bit of a rebase conflict, > but nothing complicated. > > --- > gdb/Makefile.in | 20 ++++++---- > gdb/NEWS | 11 ++++++ > gdb/README | 24 ++++++++++++ > gdb/config.in | 3 ++ > gdb/configure | 96 +++++++++++++++++++++++++++++++++++++++++++-- > gdb/configure.ac | 80 ++++++++++++++++++++++++++++++++++++- > gdb/configure.tgt | 20 ++++++++-- > gdb/doc/gdb.texinfo | 8 ++++ > gdb/top.c | 5 +++ > 9 files changed, 250 insertions(+), 17 deletions(-) > > diff --git a/gdb/Makefile.in b/gdb/Makefile.in > index fc0c56564c2..294c9e19421 100644 > --- a/gdb/Makefile.in > +++ b/gdb/Makefile.in > @@ -907,13 +907,22 @@ ALL_TARGET_OBS = \ > vax-tdep.o \ > windows-tdep.o \ > x86-tdep.o \ > - xcoffread.o \ > xstormy16-tdep.o \ > xtensa-config.o \ > xtensa-linux-tdep.o \ > xtensa-tdep.o \ > z80-tdep.o > > +# Object files for reading specific types of debug information. > +coff_SRCS = coffread.c coff-pe-read.c > +dbx_SRCS = dbxread.c > +elf_SRCS = elfread.c > +macho_SRCS = machoread.c > +mips_SRCS = mipsread.c > +xcoff_SRCS = xcoffread.c > +FORMAT_SRCS = @FORMAT_SRCS@ > +FORMAT_OBS = $(patsubst %.c,%.o,$(FORMAT_SRCS)) > + > # The following native-target dependent variables are defined on > # configure.nat. > NAT_FILE = @NAT_FILE@ > @@ -1070,8 +1079,6 @@ COMMON_SFILES = \ > c-varobj.c \ > charset.c \ > cli-out.c \ > - coff-pe-read.c \ > - coffread.c \ > complaints.c \ > completer.c \ > copying.c \ > @@ -1085,7 +1092,6 @@ COMMON_SFILES = \ > d-lang.c \ > d-namespace.c \ > d-valprint.c \ > - dbxread.c \ > dcache.c \ > debug.c \ > debuginfod-support.c \ > @@ -1150,7 +1156,6 @@ COMMON_SFILES = \ > memtag.c \ > minidebug.c \ > minsyms.c \ > - mipsread.c \ > namespace.c \ > objc-lang.c \ > objfiles.c \ > @@ -1243,7 +1248,6 @@ SFILES = \ > d-exp.y \ > dtrace-probe.c \ > elf-none-tdep.c \ > - elfread.c \ > f-exp.y \ > gcore-elf.c \ > gdb.c \ > @@ -1870,7 +1874,6 @@ ALLDEPFILES = \ > x86-gnu-nat.c \ > x86-nat.c \ > x86-tdep.c \ > - xcoffread.c \ > xstormy16-tdep.c \ > xtensa-config.c \ > xtensa-linux-nat.c \ > @@ -1925,7 +1928,8 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \ > $(patsubst %.c,%.o,$(COMMON_SFILES)) \ > $(SUBDIR_CLI_OBS) \ > $(SUBDIR_MI_OBS) \ > - $(SUBDIR_TARGET_OBS) > + $(SUBDIR_TARGET_OBS) \ > + $(FORMAT_OBS) > > SUBDIRS = doc @subdirs@ data-directory > CLEANDIRS = $(SUBDIRS) > diff --git a/gdb/NEWS b/gdb/NEWS > index 4c9aed421bb..a8c17318d7e 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -224,6 +224,17 @@ vFile:stat > * Support for stabs debugging format and the a.out/dbx object format is > deprecated, and will be removed in GDB 18. > > +* Configure changes > + > +--enable-binary-file-formats=[FORMAT,...] > +--enable-binary-file-formats=all > + A user can now decide to only compile support for certain file formats. > + The available formats at this point are: dbx, coff, xcoff, elf, mach-o > + and mips. Some targets require specific file formats to be available, > + and in such cases, the configure script will warn the user and add > + support anyway. By default, all formats will be compiled in, to > + continue the behavior from before adding the switch. > + > * A new configure option was added, allowing support for the compile > subsystem to be disabled at configure time, in the form of > --disable-gdb-compile. > diff --git a/gdb/README b/gdb/README > index eca4181c751..d45e6d37c4a 100644 > --- a/gdb/README > +++ b/gdb/README > @@ -417,6 +417,30 @@ more obscure GDB `configure' options are not listed here. > There is no convenient way to generate a list of all available > targets. > > +`--enable-binary-file-formats=FORMAT,FORMAT,...' > +`--enable-binary-file-formats=all' > + Configure GDB to only be be able to read selected file formats. > + The special value "all" causes all file formats to be compiled > + in, and is the the default behavior of the option. This option > + is meant for advanced users who are sure of what they expect, > + if you are unsure which options you will need on your debugging > + sessions, we recommend that you not use this feature. The > + accepted options are: > + * coff: Main format on windows systems. This is required to > + compile with windows target support; > + * dbx (also known as a.out): is a legacy file format, this > + is recommended if you know you will be dealing with this > + file format; > + * elf: Main format of linux systems. This is heavily > + recommended when compiling with linux support; > + * macho: Main format on MacOS systems, this is heavily > + recommended when compiling for those targets; > + * mips (also known as ecoff): this is the main file format > + for targets running on MIPS CPUs. It is heavily recommended > + when supporting those targets. > + * xcoff: Main format of AIX systems, this is required to > + compile for AIX targets and rs6000 CPUs. > + > `--with-gdb-datadir=PATH' > Set the GDB-specific data directory. GDB will look here for > certain supporting files or scripts. This defaults to the `gdb' > diff --git a/gdb/config.in b/gdb/config.in > index 149aeaf979b..9208b21946e 100644 > --- a/gdb/config.in > +++ b/gdb/config.in > @@ -745,6 +745,9 @@ > /* Define to 1 if you have the ANSI C header files. */ > #undef STDC_HEADERS > > +/* Which file formats were requested at configure time. */ > +#undef SUPPORTED_FORMATS > + > /* automatically load a system-wide gdbinit file */ > #undef SYSTEM_GDBINIT > > diff --git a/gdb/configure b/gdb/configure > index 8fc3b04efbf..c8e22e0eabc 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -706,6 +706,7 @@ LIBGUI > LTLIBLZMA > LIBLZMA > HAVE_LIBLZMA > +FORMAT_SRCS > SER_HARDWIRE > WERROR_CFLAGS > WARN_CFLAGS > @@ -932,6 +933,7 @@ with_relocated_sources > with_auto_load_dir > with_auto_load_safe_path > enable_targets > +enable_binary_file_formats > enable_gdb_mdebug_support > enable_gdb_dwarf_support > with_amd_dbgapi > @@ -1645,6 +1647,9 @@ Optional Features: > --disable-nls do not use Native Language Support > --enable-targets=TARGETS > alternative target configurations > + --enable-binary-file-formats=FILE_FORMATS > + enable support for selected file formats (default > + 'all') > --enable-gdb-mdebug-support > Enable support for the mdebug debuginfo format > (default 'yes') > @@ -11507,7 +11512,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11510 "configure" > +#line 11515 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -11613,7 +11618,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11616 "configure" > +#line 11621 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -24882,6 +24887,18 @@ esac > fi > > > +# Check whether --enable-binary_file_formats was given. > +if test "${enable_binary_file_formats+set}" = set; then : > + enableval=$enable_binary_file_formats; case "${enableval}" in > + yes | "") as_fn_error $? "enable-formats option must specify file formats or 'all'" "$LINENO" 5 > + ;; > + no) enable_binary_file_formats= ;; > + *) enable_binary_file_formats=$enableval ;; > +esac > +else > + enable_binary_file_formats=all > +fi > + > > # Check whether to support mdebug/ecoff debug information. > # Check whether --enable-gdb-mdebug-support was given. > @@ -24985,11 +25002,20 @@ fi > TARGET_OBS= > all_targets= > HAVE_NATIVE_GCORE_TARGET= > +# File formats that will be enabled based on the selected > +# target(s). These are chosen because they are required to > +# compile one or more of the selected targets. > +target_formats= > +# If all targets were requested, this is all formats that should > +# accompany them. These are just the ones required for compilation > +# to succeed, not the formats suggested based on targets. > +all_target_formats="coff xcoff" > > for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'` > do > if test "$targ_alias" = "all"; then > all_targets=true > + target_formats=$all_target_formats > else > # Canonicalize the secondary target names. > result=`$ac_config_sub $targ_alias 2>/dev/null` > @@ -31628,6 +31654,12 @@ fi > # Note that WIN32APILIBS is set by GDB_AC_COMMON. > WIN32LIBS="$WIN32LIBS $WIN32APILIBS" > > +# Object files to be used when building with support for all file formats. > +# This should not have elf or macho, as support for those formats depends > +# on BFD enabling them as well. > +all_binary_file_srcs="\$(dbx_SRCS) \$(mips_SRCS) \$(coff_SRCS) \$(xcoff_SRCS)" > + > +support_elf=no > # Add ELF support to GDB, but only if BFD includes ELF support. > > OLD_CFLAGS=$CFLAGS > @@ -31680,7 +31712,7 @@ $as_echo "$gdb_cv_var_elf" >&6; } > LDFLAGS=$OLD_LDFLAGS > LIBS=$OLD_LIBS > if test "$gdb_cv_var_elf" = yes; then > - CONFIG_OBS="$CONFIG_OBS elfread.o stap-probe.o dtrace-probe.o \ > + CONFIG_OBS="$CONFIG_OBS stap-probe.o dtrace-probe.o \ > gcore-elf.o elf-none-tdep.o" > > $as_echo "#define HAVE_ELF 1" >>confdefs.h > @@ -31744,9 +31776,12 @@ if test "$ac_res" != no; then : > fi > > fi > + support_elf=yes > + all_binary_file_srcs="$all_binary_file_srcs \$(elf_SRCS)" > fi > > # Add macho support to GDB, but only if BFD includes it. > +support_macho=no > > OLD_CFLAGS=$CFLAGS > OLD_LDFLAGS=$LDFLAGS > @@ -31798,9 +31833,62 @@ $as_echo "$gdb_cv_var_macho" >&6; } > LDFLAGS=$OLD_LDFLAGS > LIBS=$OLD_LIBS > if test "$gdb_cv_var_macho" = yes; then > - CONFIG_OBS="$CONFIG_OBS machoread.o" > + support_macho=yes > + all_binary_file_srcs="$all_binary_file_srcs \$(macho_SRCS)" > fi > > +FORMAT_SRCS= > + > +if test "$enable_binary_file_formats" != "all"; then > + # Formats that are required by some requested target(s). > + # Warn users that they are added, so no one is surprised. > + for req in $target_formats; do > + case ,$enable_binary_file_formats, in > + *,$req,*) > + # Do nothing. > + ;; > + *) > + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \"$req is required to support one or more requested targets. Adding it\"" >&5 > +$as_echo "$as_me: WARNING: \"$req is required to support one or more requested targets. Adding it\"" >&2;} > + enable_binary_file_formats="${enable_binary_file_formats},$req" > + ;; > + esac > + done > + > + > +cat >>confdefs.h <<_ACEOF > +#define SUPPORTED_FORMATS "$enable_binary_file_formats" > +_ACEOF > + > +fi > + > +enable_binary_file_formats=$(echo $enable_binary_file_formats | sed 's/,/ /g') > + > +for format in $enable_binary_file_formats > +do > + if test "$format" = "elf"; then > + if test "$support_elf" != "yes"; then > + as_fn_error but BFD does not support it." "\"elf support was requested" "$LINENO" 5; > + fi > + elif test "$format" = "macho"; then > + if test "$support_macho" != "yes"; then > + as_fn_error but BFD does not support it." "\"Mach-O support was requested" "$LINENO" 5; > + fi > + fi > + > + if test "$format" = "all"; then > + FORMAT_SRCS="$all_binary_file_srcs" > + # We don't break here in case the user requested Mach-O or ELF, but > + # BFD is not configured to support it. If we were to break, we would > + # silently drop the requested support instead of erroring out. > + else > + fmt=$(echo "$format _SRCS" | sed 's/ //') > + FORMAT_SRCS="$FORMAT_SRCS \$($fmt)" > + fi > +done > + > + > + > # Add any host-specific objects to GDB. > CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}" > > diff --git a/gdb/configure.ac b/gdb/configure.ac > index 226e27e4fe5..edc6102c6da 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -191,6 +191,15 @@ AS_HELP_STRING([--enable-targets=TARGETS], [alternative target configurations]), > ;; > esac]) > > +AC_ARG_ENABLE(binary_file_formats, > + AS_HELP_STRING([--enable-binary-file-formats=FILE_FORMATS], > + [enable support for selected file formats (default 'all')]), > +[case "${enableval}" in > + yes | "") AC_MSG_ERROR(enable-formats option must specify file formats or 'all') > + ;; > + no) enable_binary_file_formats= ;; > + *) enable_binary_file_formats=$enableval ;; > +esac], [enable_binary_file_formats=all]) > > # Check whether to support mdebug/ecoff debug information. > AC_ARG_ENABLE(gdb-mdebug-support, > @@ -239,11 +248,20 @@ fi > TARGET_OBS= > all_targets= > HAVE_NATIVE_GCORE_TARGET= > +# File formats that will be enabled based on the selected > +# target(s). These are chosen because they are required to > +# compile one or more of the selected targets. > +target_formats= > +# If all targets were requested, this is all formats that should > +# accompany them. These are just the ones required for compilation > +# to succeed, not the formats suggested based on targets. > +all_target_formats="coff xcoff" > > for targ_alias in `echo $target_alias $enable_targets | sed 's/,/ /g'` > do > if test "$targ_alias" = "all"; then > all_targets=true > + target_formats=$all_target_formats > else > # Canonicalize the secondary target names. > result=`$ac_config_sub $targ_alias 2>/dev/null` > @@ -1952,11 +1970,17 @@ fi > # Note that WIN32APILIBS is set by GDB_AC_COMMON. > WIN32LIBS="$WIN32LIBS $WIN32APILIBS" > > +# Object files to be used when building with support for all file formats. > +# This should not have elf or macho, as support for those formats depends > +# on BFD enabling them as well. > +all_binary_file_srcs="\$(dbx_SRCS) \$(mips_SRCS) \$(coff_SRCS) \$(xcoff_SRCS)" > + > +support_elf=no > # Add ELF support to GDB, but only if BFD includes ELF support. > GDB_AC_CHECK_BFD([for ELF support in BFD], gdb_cv_var_elf, > [bfd_get_elf_phdr_upper_bound (NULL)], elf-bfd.h) > if test "$gdb_cv_var_elf" = yes; then > - CONFIG_OBS="$CONFIG_OBS elfread.o stap-probe.o dtrace-probe.o \ > + CONFIG_OBS="$CONFIG_OBS stap-probe.o dtrace-probe.o \ > gcore-elf.o elf-none-tdep.o" > AC_DEFINE(HAVE_ELF, 1, > [Define if ELF support should be included.]) > @@ -1964,15 +1988,67 @@ if test "$gdb_cv_var_elf" = yes; then > if test "$plugins" = "yes"; then > AC_SEARCH_LIBS(dlopen, dl) > fi > + support_elf=yes > + all_binary_file_srcs="$all_binary_file_srcs \$(elf_SRCS)" > fi > > # Add macho support to GDB, but only if BFD includes it. > +support_macho=no > GDB_AC_CHECK_BFD([for Mach-O support in BFD], gdb_cv_var_macho, > [bfd_mach_o_lookup_command (NULL, 0, NULL)], mach-o.h) > if test "$gdb_cv_var_macho" = yes; then > - CONFIG_OBS="$CONFIG_OBS machoread.o" > + support_macho=yes > + all_binary_file_srcs="$all_binary_file_srcs \$(macho_SRCS)" > +fi > + > +FORMAT_SRCS= > + > +if test "$enable_binary_file_formats" != "all"; then > + # Formats that are required by some requested target(s). > + # Warn users that they are added, so no one is surprised. > + for req in $target_formats; do > + case ,$enable_binary_file_formats, in > + *,$req,*) > + # Do nothing. > + ;; > + *) > + AC_MSG_WARN("$req is required to support one or more requested targets. Adding it") > + enable_binary_file_formats="${enable_binary_file_formats},$req" > + ;; > + esac > + done > + > + AC_DEFINE_UNQUOTED(SUPPORTED_FORMATS, "$enable_binary_file_formats", > + Which file formats were requested at configure time. ) > fi > > +enable_binary_file_formats=$(echo $enable_binary_file_formats | sed 's/,/ /g') > + > +for format in $enable_binary_file_formats > +do > + if test "$format" = "elf"; then > + if test "$support_elf" != "yes"; then > + AC_MSG_ERROR("elf support was requested, but BFD does not support it."); > + fi > + elif test "$format" = "macho"; then > + if test "$support_macho" != "yes"; then > + AC_MSG_ERROR("Mach-O support was requested, but BFD does not support it."); > + fi > + fi > + > + if test "$format" = "all"; then > + FORMAT_SRCS="$all_binary_file_srcs" > + # We don't break here in case the user requested Mach-O or ELF, but > + # BFD is not configured to support it. If we were to break, we would > + # silently drop the requested support instead of erroring out. > + else > + fmt=$(echo "$format _SRCS" | sed 's/ //') > + FORMAT_SRCS="$FORMAT_SRCS \$($fmt)" > + fi > +done > + > +AC_SUBST(FORMAT_SRCS) > + > # Add any host-specific objects to GDB. > CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}" > > diff --git a/gdb/configure.tgt b/gdb/configure.tgt > index 255c77e9f8c..332f5b7513c 100644 > --- a/gdb/configure.tgt > +++ b/gdb/configure.tgt > @@ -505,7 +505,7 @@ powerpc-*-openbsd*) > ;; > powerpc-*-aix* | rs6000-*-* | powerpc64-*-aix*) > # Target: PowerPC running AIX > - gdb_target_obs="rs6000-tdep.o rs6000-aix-tdep.o xcoffread.o \ > + gdb_target_obs="rs6000-tdep.o rs6000-aix-tdep.o \ > ppc-sysv-tdep.o solib-aix.o \ > ravenscar-thread.o ppc-ravenscar-thread.o" > ;; > @@ -522,8 +522,8 @@ powerpc*-*-linux*) > powerpc-*-lynx*178) > # Target: PowerPC running Lynx178. > gdb_target_obs="rs6000-tdep.o rs6000-lynx178-tdep.o \ > - xcoffread.o ppc-sysv-tdep.o \ > - ravenscar-thread.o ppc-ravenscar-thread.o" > + ppc-sysv-tdep.o ravenscar-thread.o \ > + ppc-ravenscar-thread.o" > ;; > powerpc*-*-*) > # Target: PowerPC running eabi > @@ -835,3 +835,17 @@ for t in x ${gdb_target_obs}; do > gdb_have_gcore=true > fi > done > + > +# Decide which file formats are absolutely required based on > +# the requested targets. Warn later that they are added, in > +# case the user didn't manually request them, or all readers. > +# It's fine to add the same format multiple times since the > +# loop that reads the options to FORMAT_OBS will ensure that > +# they are only added once. > +for i in $gdb_target_obs; do > + case "${i}" in > + *"windows-tdep.o" ) target_formats="${target_formats} coff";; > + "rs6000-aix-tdep.o" ) target_formats="${target_formats} xcoff";; > + "rs6000-lynx178-tdep.o" ) target_formats="${target_formats} xcoff";; > + esac > +done > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 35b770f8138..bcd88b7b6a5 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -41267,6 +41267,14 @@ Configure @value{GDBN} for cross-debugging programs running on the > specified list of targets. The special value @samp{all} configures > @value{GDBN} for debugging programs running on any target it supports. > > +@item --enable-binary-file-formats=@r{[}@var{format}@r{]}@dots{} > +@itemx --enable-binary-file-formats=all > +Configure @value{GDBN} to support certain binary file formats. If a > +format is the main (or only) file format for a given target, the > +configure script may add support to it anyway, and warn the user. > +If not given, all file formats that @value{GDBN} supports are compiled > +in. > + > @item --with-gdb-datadir=@var{path} > Set the @value{GDBN}-specific data directory. @value{GDBN} will look > here for certain supporting files or scripts. This defaults to the > diff --git a/gdb/top.c b/gdb/top.c > index 72d19530070..be54d30be49 100644 > --- a/gdb/top.c > +++ b/gdb/top.c > @@ -1595,6 +1595,11 @@ This GDB was configured as follows:\n\ > --with-system-gdbinit-dir=%s%s\n\ > "), SYSTEM_GDBINIT_DIR, SYSTEM_GDBINIT_DIR_RELOCATABLE ? " (relocatable)" : ""); > > +#ifdef SUPPORTED_FORMATS > + gdb_printf (stream, _("\ > + --enable-binary-file-formats=%s\n"), SUPPORTED_FORMATS); > +#endif > + > /* We assume "relocatable" will be printed at least once, thus we always > print this text. It's a reasonably safe assumption for now. */ > gdb_printf (stream, _("\n\ > > base-commit: 0a082f5cf8a5e42b7c947b377c117ec3451dcce8