From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FMQcKpQAAGdkKAEAWB0awg (envelope-from ) for ; Fri, 04 Oct 2024 10:49:56 -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=BiwzuYJP; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 98BE01E355; Fri, 4 Oct 2024 10:49:56 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-7.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_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,URIBL_BLOCKED,URIBL_DBL_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=4.0.0 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 355BD1E05C for ; Fri, 4 Oct 2024 10:49:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC75138432E3 for ; Fri, 4 Oct 2024 14:49:54 +0000 (GMT) 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 8EE1D385E011 for ; Fri, 4 Oct 2024 14:49:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EE1D385E011 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 8EE1D385E011 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=1728053371; cv=none; b=bgYz5C6bWNWYkYEysd/9coaxuZDNpA4QzmYl7ctPrVuoiL1c+xJ3lwQuf6j69CdUwCXZ7GWfOTXAmb8rEUY529jF9ppKG3fizLqi8Vqcvr/cr9Dv9ocrRFvaCIIUHa3fABecZ7yuZ+8IR8ekVPbATOcWfW9IVGLaSeu97Aszfwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728053371; c=relaxed/simple; bh=j+Sn4wJ82Ky+sb5Cj0BePJ+214Rvkto1MdaGaJZmIig=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gV2a9i0wxThUfpPEre/ZygVPogdZVhUH5bDlwMukmQSTpLDu0/u9hvQOvkC818mj2MDdeM7Cc92l1lisbmMAV9YGZ77HQ2Li0V76DvhqLju7m+7xyrsHlnCeqmEEBoGU/ABxQusD/HU+6k1aSTtUbhxFzGthDxmQu3bfB1T24lo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728053365; 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: in-reply-to:in-reply-to:references:references; bh=oruZ1n84+PIgHe07RsyvONGbwjEKeEg5hcBqNfiyacU=; b=BiwzuYJPMffu216M6z5eEW7mBhUNx+dmfZzH4h6ewCuQaJu/Oq74OnLzPFxpjDPPyF8s9X gysBFi0qFVwAaToKcBddZqqTRg6idGI9qBI/zwhOG7wHwV7VShsWuAzLR8Tk/pZiseVfrN JOGh1fkaJyBU+MBAZnvm7YjQfPBMdX8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-481-mx-LwRC8MjiyPyDzSAtA1w-1; Fri, 04 Oct 2024 10:49:23 -0400 X-MC-Unique: mx-LwRC8MjiyPyDzSAtA1w-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-5c88d49ac78so1920636a12.3 for ; Fri, 04 Oct 2024 07:49:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728053362; x=1728658162; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oruZ1n84+PIgHe07RsyvONGbwjEKeEg5hcBqNfiyacU=; b=tHkV0fuzzyn4sRzEJ7tOt4vq6yd3msKjqUvRo+yFWzs8B6Tp8Qj0byo3eyHWSmZgcU wPHp1R0PzMfDzJa2AAyf8+xvhHFA3Mb7OG8Pis0Bgd+z94miDDSyEhXR3C69IpNQ146L M1FLxDdElLDNaUUVPhbfAZRY4EmGfcA+HCRaOl7LakY3ynPg+UUOM9ehYJZeaYs3YBOA 1sGLzLY4VHxmboZ/FUPq9NYNjEzrfR6FpLZwgvi+E326PXaoa4IIhTrfFa4InPJbN4wH 5VtfLoEROxLPombJCtuepOcz1v6PBRvqhE1aEHpAMotTn/tHIYiZz4iYFwNBwT1DU4NA gmNA== X-Forwarded-Encrypted: i=1; AJvYcCXsIPMfa2G2dKueOMatrXRS3IaAHoB0xY6Z9nwpAUmuyE6LuID1T5dRjMvKrCJWQulOicVtaaV3qaX/Rg==@sourceware.org X-Gm-Message-State: AOJu0YxSS1Zf5FHtXnrrVkxZfGfJ57YYDcUAs8onRyDMzzue8WZk9BrA V6Uy2eGlYgb7cPSFsF6AknzrUzm5MGOl/VB9d2jHXEhwFxYOD4LCO3Mwxos3nOng4CBaE8toWc2 2JRB2xQDmdhtaIV3loKtPcI0+DridJPbML03yxz6vO4O31WBh8mFiDBDELNrY2AxS+8Y= X-Received: by 2002:a17:907:9724:b0:a8a:7e24:3230 with SMTP id a640c23a62f3a-a991bd684d2mr237848266b.28.1728053361983; Fri, 04 Oct 2024 07:49:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfva0SHfppgs4DPPAo/5V3NeStNn6xLm2ceBARdo6niVG33tNLY+1U0hmfS8pZIWDz7iNDgg== X-Received: by 2002:a17:907:9724:b0:a8a:7e24:3230 with SMTP id a640c23a62f3a-a991bd684d2mr237844566b.28.1728053361318; Fri, 04 Oct 2024 07:49:21 -0700 (PDT) Received: from localhost (243.223.159.143.dyn.plus.net. [143.159.223.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a992e664a8fsm881766b.89.2024.10.04.07.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 07:49:21 -0700 (PDT) From: Andrew Burgess To: Guinevere Larsen , gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: Re: [PATCH] gdb, configure: Add disable-formats option for configure In-Reply-To: <20240925175340.1850969-1-guinevere@redhat.com> References: <20240925175340.1850969-1-guinevere@redhat.com> Date: Fri, 04 Oct 2024 15:49:20 +0100 Message-ID: <878qv3ylcf.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Hey Gwen, Sorry for starting a second review thread, but while responding to Eli I had some additional thoughts: Guinevere Larsen writes: > GDB has support for many file formats, some which might be very unlikely > to be found in some situations (such as the COFF format in linux). 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 also can 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. The default behavior when the switch > is omitted is to compile all file formats, keeping the original behavior > of the script. > > When enabling selected readers, the configure script will also look at > the selected targets and may choose to add some readers that are the > default - or only - format available for the target. If that happens, > the script will emit the following warning: > > FOO is required to support one or more targets requested. Adding it > > Users aren't able to force the disabling of those formats, since tdep > files may directly call functions from the required 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. I think it would be useful if the commit message actually mentioned the new configure option, and what values it takes. But in addition, I ran into a couple of issues, including a crash. I built gdbserver on a Windows machine, configured for x86_64-w64-mingw32, and I built GDB on a Linux machine configured _only_ for x86_64-redhat-linux with --enable-formats=elf. Then I start GDB and: (gdb) set target-file-system-kind dos-based (gdb) target remote 192.168.129.25:55443 Remote debugging using 192.168.129.25:55443 Reading C:/msys64/home/andrew/segv.exe from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading C:/msys64/home/andrew/segv.exe from remote target... Reading symbols from target:C:/msys64/home/andrew/segv.exe... warning: I'm sorry, Dave, I can't do that. Symbol format `pei-x86-64' unknown. Here's the first issue. I suspect that the above warning was probably never expected to actually be seen. But if we start removing file format support then it can show up more often. I think this message needs to be made clearer, and dare I say it, more professional? But moving on ... after downloading the library files, I ran straight into this crash: Fatal signal: Segmentation fault ----- Backtrace ----- 0x4fd7c3 gdb_internal_backtrace_1 ../../src/gdb/bt-utils.c:121 0x4fd7c3 _Z22gdb_internal_backtracev ../../src/gdb/bt-utils.c:167 0x5fa5a9 handle_fatal_signal ../../src/gdb/event-top.c:917 0x5fa63f handle_sigsegv ../../src/gdb/event-top.c:990 0x7fd7dce67b1f ??? /usr/src/debug/glibc-2.30-73-gd59630f995/nptl/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0x7200e7 _ZNK11obj_section4addrEv ../../src/gdb/objfiles.h:381 0x7200e7 sort_cmp ../../src/gdb/objfiles.c:823 0x723775 _ZN9__gnu_cxx5__ops15_Iter_comp_iterIPFbPK11obj_sectionS4_EEclIPPS2_SA_EEbT_T0_ /usr/include/c++/9/bits/predefined_ops.h:143 0x723775 _ZSt22__move_median_to_firstIPP11obj_sectionN9__gnu_cxx5__ops15_Iter_comp_iterIPFbPKS0_S7_EEEEvT_SB_SB_SB_T0_ /usr/include/c++/9/bits/stl_algo.h:81 0x723775 _ZSt27__unguarded_partition_pivotIPP11obj_sectionN9__gnu_cxx5__ops15_Iter_comp_iterIPFbPKS0_S7_EEEET_SB_SB_T0_ /usr/include/c++/9/bits/stl_algo.h:1920 0x723775 _ZSt16__introsort_loopIPP11obj_sectionlN9__gnu_cxx5__ops15_Iter_comp_iterIPFbPKS0_S7_EEEEvT_SB_T0_T1_ /usr/include/c++/9/bits/stl_algo.h:1952 0x722184 _ZSt6__sortIPP11obj_sectionN9__gnu_cxx5__ops15_Iter_comp_iterIPFbPKS0_S7_EEEEvT_SB_T0_ /usr/include/c++/9/bits/stl_algo.h:1967 0x722184 _ZSt4sortIPP11obj_sectionPFbPKS0_S4_EEvT_S7_T0_ /usr/include/c++/9/bits/stl_algo.h:4899 0x722184 update_section_map ../../src/gdb/objfiles.c:1090 0x722184 _Z15find_pc_sectionm ../../src/gdb/objfiles.c:1137 0x70f619 _Z35lookup_minimal_symbol_by_pc_sectionmP11obj_section18lookup_msym_preferP20bound_minimal_symbol ../../src/gdb/minsyms.c:771 0x82fccf _Z28find_pc_sect_compunit_symtabmP11obj_section ../../src/gdb/symtab.c:2914 0x61ee2c _Z12select_frameRK14frame_info_ptr ../../src/gdb/frame.c:1994 0x68a373 _Z11normal_stopv ../../src/gdb/infrun.c:9620 0x69a9c3 _Z12start_remotei ../../src/gdb/infrun.c:3832 0x7c3d03 _ZN13remote_target14start_remote_1Eii ../../src/gdb/remote.c:5350 0x7c43d6 _ZN13remote_target12start_remoteEii ../../src/gdb/remote.c:5441 0x7c43d6 _ZN13remote_target6open_1EPKcii ../../src/gdb/remote.c:6312 0x86c6de open_target ../../src/gdb/target.c:838 0x52c0a4 _Z8cmd_funcP16cmd_list_elementPKci ../../src/gdb/cli/cli-decode.c:2741 0x87aa7e _Z15execute_commandPKci ../../src/gdb/top.c:570 0x5fad3f _Z15command_handlerPKc ../../src/gdb/event-top.c:580 0x5fbe2d _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE ../../src/gdb/event-top.c:816 0x5fb6d6 gdb_rl_callback_handler ../../src/gdb/event-top.c:272 0x92bc87 rl_callback_read_char ../../../src/readline/readline/callback.c:290 0x5fa8dd gdb_rl_callback_read_char_wrapper_noexcept ../../src/gdb/event-top.c:197 0x5fb58d gdb_rl_callback_read_char_wrapper ../../src/gdb/event-top.c:236 0x8afccf stdin_event_handler ../../src/gdb/ui.c:154 Which appears to be crashing in: CORE_ADDR obj_section::addr () const { return bfd_section_vma (this->the_bfd_section) + this->offset (); } When trying to access 'this->offset ()' (I think): (top-gdb) list . 376 void set_offset (CORE_ADDR offset); 377 378 /* The memory address of the section (vma + offset). */ 379 CORE_ADDR addr () const 380 { 381 return bfd_section_vma (this->the_bfd_section) + this->offset (); 382 } 383 384 /* The one-passed-the-end memory address of the section 385 (vma + size + offset). */ (top-gdb) p this->objfile->sect_index_text $24 = -1 Though I don't understand why this is segfaulting rather than throwing an internal error from: #define SECT_OFF_TEXT(objfile) \ ((objfile->sect_index_text == -1) \ ? (internal_error (_("sect_index_text not initialized")), -1) \ : objfile->sect_index_text) Anyway, I think this probably needs investigating. My guess would be that, when GDB can't open the file, (e.g. "I'm sorry Dave, ...") then we shouldn't be processing the file beyond this point, but it looks like we might be trying to anyway ... which feels wrong. Thanks, Andrew > --- > gdb/Makefile.in | 22 +++++++----- > gdb/NEWS | 11 ++++++ > gdb/README | 5 +++ > gdb/configure | 82 +++++++++++++++++++++++++++++++++++++++++--- > gdb/configure.ac | 68 ++++++++++++++++++++++++++++++++++-- > gdb/configure.format | 41 ++++++++++++++++++++++ > gdb/configure.tgt | 6 ++-- > gdb/doc/gdb.texinfo | 7 ++++ > 8 files changed, 225 insertions(+), 17 deletions(-) > create mode 100644 gdb/configure.format > > diff --git a/gdb/Makefile.in b/gdb/Makefile.in > index bcf1ee45a70..009d68d6de2 100644 > --- a/gdb/Makefile.in > +++ b/gdb/Makefile.in > @@ -901,13 +901,24 @@ 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. > +FORMAT_OBS = @FORMAT_OBS@ > + > +# All files that relate to GDB's ability to read debug information. > +# Used with --enable-formats=all. > +ALL_FORMAT_OBS = \ > + coff-pe-read.o \ > + coffread.o \ > + dbxread.o \ > + mipsread.o \ > + xcoffread.o > + > # The following native-target dependent variables are defined on > # configure.nat. > NAT_FILE = @NAT_FILE@ > @@ -1064,8 +1075,6 @@ COMMON_SFILES = \ > c-varobj.c \ > charset.c \ > cli-out.c \ > - coff-pe-read.c \ > - coffread.c \ > complaints.c \ > completer.c \ > copying.c \ > @@ -1079,7 +1088,6 @@ COMMON_SFILES = \ > d-lang.c \ > d-namespace.c \ > d-valprint.c \ > - dbxread.c \ > dcache.c \ > debug.c \ > debuginfod-support.c \ > @@ -1171,7 +1179,6 @@ COMMON_SFILES = \ > memtag.c \ > minidebug.c \ > minsyms.c \ > - mipsread.c \ > namespace.c \ > objc-lang.c \ > objfiles.c \ > @@ -1264,7 +1271,6 @@ SFILES = \ > d-exp.y \ > dtrace-probe.c \ > elf-none-tdep.c \ > - elfread.c \ > f-exp.y \ > gcore-elf.c \ > gdb.c \ > @@ -1886,7 +1892,6 @@ ALLDEPFILES = \ > windows-tdep.c \ > x86-nat.c \ > x86-tdep.c \ > - xcoffread.c \ > xstormy16-tdep.c \ > xtensa-config.c \ > xtensa-linux-nat.c \ > @@ -1908,7 +1913,8 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \ > $(SUBDIR_CLI_OBS) \ > $(SUBDIR_MI_OBS) \ > $(SUBDIR_TARGET_OBS) \ > - $(SUBDIR_GCC_COMPILE_OBS) > + $(SUBDIR_GCC_COMPILE_OBS) \ > + $(FORMAT_OBS) > > SUBDIRS = doc @subdirs@ data-directory > CLEANDIRS = $(SUBDIRS) > diff --git a/gdb/NEWS b/gdb/NEWS > index cfc9cb05f77..8d127558a1d 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -92,6 +92,17 @@ vFile:stat > vFile:fstat but takes a filename rather than an open file > descriptor. > > +* Configure changes > + > +enable-formats=[FORMAT,]... > +enable-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. > + > *** Changes in GDB 15 > > * The MPX commands "show/set mpx bound" have been deprecated, as Intel > diff --git a/gdb/README b/gdb/README > index d85c37d5d17..342b2d07eb7 100644 > --- a/gdb/README > +++ b/gdb/README > @@ -403,6 +403,11 @@ more obscure GDB `configure' options are not listed here. > specified list of targets. The special value `all' configures > GDB for debugging programs running on any target it supports. > > +`--enable-formats=FORMAT,FORMAT,...' > +`--enable-formats=all` > + Configure GDB to be unable to read some binary file formats, such as > + coff, dbx or elf. > + > `--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/configure b/gdb/configure > index 53eaad4f0e2..792e5cefefe 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -706,6 +706,7 @@ LIBGUI > LTLIBLZMA > LIBLZMA > HAVE_LIBLZMA > +FORMAT_OBS > SER_HARDWIRE > WERROR_CFLAGS > WARN_CFLAGS > @@ -933,6 +934,7 @@ with_relocated_sources > with_auto_load_dir > with_auto_load_safe_path > enable_targets > +enable_formats > enable_64_bit_bfd > with_amd_dbgapi > enable_tui > @@ -1644,6 +1646,9 @@ Optional Features: > --disable-nls do not use Native Language Support > --enable-targets=TARGETS > alternative target configurations > + --enable-formats=FILE_FORMATS > + enable support for selected file formats(default > + 'all') > --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes) > --enable-tui enable full-screen terminal user interface (TUI) > --enable-gdbtk enable gdbtk graphical user interface (GUI) > @@ -11499,7 +11504,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11502 "configure" > +#line 11507 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -11605,7 +11610,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 11608 "configure" > +#line 11613 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -24833,6 +24838,20 @@ esac > fi > > > +all_formats= > +# Check whether --enable-formats was given. > +if test "${enable_formats+set}" = set; then : > + enableval=$enable_formats; case "${enableval}" in > + yes | "") as_fn_error $? "enable-formats option must specify file formats or 'all'" "$LINENO" 5 > + ;; > + no) enable_formats= ;; > + *) enable_formats=$enableval ;; > +esac > +else > + all_formats=true > +fi > + > + > # Check whether --enable-64-bit-bfd was given. > if test "${enable_64_bit_bfd+set}" = set; then : > enableval=$enable_64_bit_bfd; case $enableval in #( > @@ -24915,11 +24934,20 @@ fi > TARGET_OBS= > all_targets= > HAVE_NATIVE_GCORE_TARGET= > +# File formats that will ne enabled based on the selected > +# target(s). These are chosen because most, if not all, executables for > +# the target will follow this file format so it makes no sense to support > +# the target but not the debug information. > +target_formats= > +# If all targets were requested, this is all formats that should accompany > +# them. > +all_target_formats="elf xcoff mips coff" > > 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` > @@ -24941,6 +24969,19 @@ fi > *" ${i} "*) ;; > *) > TARGET_OBS="$TARGET_OBS ${i}" > + # Decide which file formats are absolutely required based on > + # the requested targets. Warn later that they are added, in > + # case the user manually requested them, or requested all. > + # It's fine to add xcoff multiple times since the loop that > + # adds it to FORMAT_OBS will ensure that it is only added once. > + echo $i > + case "${i}" in > + *"windows-tdep.o" ) target_formats="${target_formats} coff";; > + "linux-tdep.o" ) target_formats="${target_formats} elf";; > + "rs6000-aix-tdep.o" ) target_formats="${target_formats} xcoff";; > + "rs6000-lynx178-tdep.o" ) target_formats="${target_formats} xcoff";; > + "mips-tdep.o" ) target_formats="${target_formats} mips";; > + esac > ;; > esac > done > @@ -24964,6 +25005,7 @@ if test x${all_targets} = xtrue; then > else > TARGET_OBS='$(ALL_TARGET_OBS)' > fi > + target_readers=$all_target_readers > fi > > # AMD debugger API support. > @@ -31462,6 +31504,7 @@ fi > # Note that WIN32APILIBS is set by GDB_AC_COMMON. > WIN32LIBS="$WIN32LIBS $WIN32APILIBS" > > +support_elf=no > # Add ELF support to GDB, but only if BFD includes ELF support. > > OLD_CFLAGS=$CFLAGS > @@ -31514,7 +31557,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 > @@ -31578,9 +31621,11 @@ if test "$ac_res" != no; then : > fi > > fi > + support_elf=yes > fi > > # Add macho support to GDB, but only if BFD includes it. > +support_macho=no > > OLD_CFLAGS=$CFLAGS > OLD_LDFLAGS=$LDFLAGS > @@ -31632,9 +31677,38 @@ $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 > fi > > +FORMAT_OBS= > +enable_formats=$(echo $enable_formats | sed 's/,/ /g') > + > +if test "$all_formats" = "true"; then > + FORMAT_OBS='$(ALL_FORMAT_OBS)' > +else > + # 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 > + if ! echo "$enable_formats" | grep -wq "$req"; then > + echo "$req is required to support one or more targets requested. Adding it" > + enable_formats="${enable_formats} $req" > + fi > + done > + > + for format in $enable_formats > + do > + if test "$format" = "all"; then > + all_formats=true > + fi > + > + . ${srcdir}/configure.format > + done > +fi > + > +echo $FORMAT_OBS > + > + > + > # 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 8368fea0423..5f5187ecd0f 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -187,6 +187,16 @@ AS_HELP_STRING([--enable-targets=TARGETS], [alternative target configurations]), > *) enable_targets=$enableval ;; > esac]) > > +all_formats= > +AC_ARG_ENABLE(formats, > + AS_HELP_STRING([--enable-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_formats= ;; > + *) enable_formats=$enableval ;; > +esac], [all_formats=true]) > + > BFD_64_BIT > > # Provide defaults for some variables set by the per-host and per-target > @@ -206,11 +216,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 most, if not all, executables for > +# the target will follow this file format so it makes no sense to support > +# the target but not the debug information. > +target_formats= > +# If all targets were requested, this is all formats that should accompany > +# them. > +all_target_formats="elf xcoff mips coff" > > 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` > @@ -231,6 +250,19 @@ do > *" ${i} "*) ;; > *) > TARGET_OBS="$TARGET_OBS ${i}" > + # Decide which file formats are absolutely required based on > + # the requested targets. Warn later that they are added, in > + # case the user manually requested them, or requested all. > + # It's fine to add xcoff multiple times since the loop that > + # adds it to FORMAT_OBS will ensure that it is only added once. > + echo $i > + case "${i}" in > + *"windows-tdep.o" ) target_formats="${target_formats} coff";; > + "linux-tdep.o" ) target_formats="${target_formats} elf";; > + "rs6000-aix-tdep.o" ) target_formats="${target_formats} xcoff";; > + "rs6000-lynx178-tdep.o" ) target_formats="${target_formats} xcoff";; > + "mips-tdep.o" ) target_formats="${target_formats} mips";; > + esac > ;; > esac > done > @@ -1850,11 +1882,12 @@ fi > # Note that WIN32APILIBS is set by GDB_AC_COMMON. > WIN32LIBS="$WIN32LIBS $WIN32APILIBS" > > +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.]) > @@ -1862,15 +1895,46 @@ if test "$gdb_cv_var_elf" = yes; then > if test "$plugins" = "yes"; then > AC_SEARCH_LIBS(dlopen, dl) > fi > + support_elf=yes > 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 > fi > > +FORMAT_OBS= > +enable_formats=$(echo $enable_formats | sed 's/,/ /g') > + > +if test "$all_formats" = "true"; then > + FORMAT_OBS='$(ALL_FORMAT_OBS)' > +else > + # 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 > + if ! echo "$enable_formats" | grep -wq "$req"; then > + echo "$req is required to support one or more targets requested. Adding it" > + enable_formats="${enable_formats} $req" > + fi > + done > + > + for format in $enable_formats > + do > + if test "$format" = "all"; then > + all_formats=true > + fi > + > + . ${srcdir}/configure.format > + done > +fi > + > +echo $FORMAT_OBS > + > +AC_SUBST(FORMAT_OBS) > + > # Add any host-specific objects to GDB. > CONFIG_OBS="${CONFIG_OBS} ${gdb_host_obs}" > > diff --git a/gdb/configure.format b/gdb/configure.format > new file mode 100644 > index 00000000000..12dd2d25717 > --- /dev/null > +++ b/gdb/configure.format > @@ -0,0 +1,41 @@ > +# Copyright (C) 2024 Free Software Foundation, Inc. > +# > +# This file is part of GDB. > +# > +# 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 . > + > +# This file is used to decide which files need to be compiled to support > +# the requested file formats > + > +case $format in > + xcoff) FORMAT_OBS="$FORMAT_OBS xcoffread.o" ;; > + > + # Despite the naming convention implying coff-pe to be a separate > + # reader, it is in fact just a helper for coffread; > + coff) FORMAT_OBS="$FORMAT_OBS coffread.o coff-pe-read.o" ;; > + > + dbx) FORMAT_OBS="$FORMAT_OBS dbxread.o" ;; > + > + elf) if "$support_elf"="yes"; then > + FORMAT_OBS="$FORMAT_OBS elfread.o" > + fi > + ;; > + > + macho) if "$support_macho"="yes"; then > + FORMAT_OBS="$FORMAT_OBS machoread.o" > + fi > + ;; > + > + mips) FORMAT_OBS="$FORMAT_OBS mipsread.o" ;; > +esac > diff --git a/gdb/configure.tgt b/gdb/configure.tgt > index 8d85a597ec8..793793601c1 100644 > --- a/gdb/configure.tgt > +++ b/gdb/configure.tgt > @@ -507,7 +507,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" > ;; > @@ -523,8 +523,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 > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo > index 77a4021b36a..c569e68060e 100644 > --- a/gdb/doc/gdb.texinfo > +++ b/gdb/doc/gdb.texinfo > @@ -41177,6 +41177,13 @@ 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-formats=@r{[}@var{format}@r{]}@dots{} > +@itemx --enable-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. > + > @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 > -- > 2.46.1