From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id BDB5B3858C5E for ; Thu, 9 Mar 2023 23:08:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDB5B3858C5E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by gnu.wildebeest.org (Postfix, from userid 1000) id D7E0430004F7; Fri, 10 Mar 2023 00:08:25 +0100 (CET) Date: Fri, 10 Mar 2023 00:08:25 +0100 From: Mark Wielaard To: Nix Cc: "Guillermo E. Martinez" , Nick Clifton , elfutils-devel@sourceware.org Subject: Re: [PATCH v3] strip: keep .ctf section in stripped file Message-ID: <20230309230825.GC726@gnu.wildebeest.org> References: <20230224164838.lyfxsjbcpttxdsaf@kamehouse> <492387583758712a4f5f1f2e2646a3ba6a7a23f1.camel@klomp.org> <8367d8ae-670d-b614-d922-211dcae11250@redhat.com> <0f9fdbd9eaaa8a8e42b426d86a5aa977eef2d8e4.camel@klomp.org> <20230303024058.42stfebtruwj4t3e@kamehouse> <8f58e4ca-16c9-4401-1985-262db0299cbb@redhat.com> <20230304140044.gp5fvjufvomr2vv3@kamehouse> <877cvr5e8x.fsf@esperi.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877cvr5e8x.fsf@esperi.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-3030.9 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Nix, On Wed, Mar 08, 2023 at 05:45:02PM +0000, Nix wrote: > > On Sat, 2023-03-04 at 08:00 -0600, Guillermo E. Martinez wrote: > >> On Fri, Mar 03, 2023 at 12:24:19PM +0000, Nick Clifton wrote: > >> > > > > I am mainly wondering why binutils strip already seems to keep ".ctf" > >> > > > > sections (even without -g). > >> > > >> > > Right. But I am wondering how that mechanism works with binutils strip. > >> > > Apparently we do something different in eu-strip which makes it > >> > > necessary to add a --keep-ctf option based on the section name. It > >> > > would be good if we figured out how/what we can do to keep the > >> > > different strip utilities in sync. > >> > > >> > I think that the function that does this is "is_strip_section_1" in > >> > >> That's right, this function decided whether the section will be striped > >> out by default, if it has set `SEC_DEBUGGING' in BFD section flags then > >> section is removed by the default. For `.ctf' this flag is not set > >> because in `_bfd_elf_make_section_from_shdr' when BFD sections are > >> building it uses the section's name: ".debug", ".gnu.debuglto_.debug_", > >> ".gnu.linkonce.wi.", ".zdebug", "lines", ".stab", etc, to set > >> `SEC_DEBUGGING' flag. > >> > >> > binutils/objcopy.c. If an input section has the BSF_DEBUGGING flag > >> > set (an internal flag to he BFD library, but basically it should be > >> > set for all debug sections, including .ctf sections I think), then > >> > the basic decision is to keep the section unless -g is used. > > > > OK, that is interesting. So given the .ctf section is NOT marked as > > SEC_DEBUGGING binutils strip basically never strips it. > > Can I chime in? Yes please! > This behaviour is in line with the intended purpose of CTF, which is to > give C programs introspection into into their type systems at all times, > via libctf, so we can use it for ABI checking, shared library interface > construction at runtime (for dlopen()) and things like that. This is why > keeping CTF small is basically our sole format priority: if it's big, > people will be tempted to strip it out, and the format becomes useless. > (This is also why it's not loadable -- libctf reads it itself so that > it doesn't cost time paging it in if it's not used.) > > (This is also why libctf doesn't follow gnu_debuglink pointers: it can > only read CTF from the ELF object itself.) Yes, this all makes sense. > > While eu-strip does strip it by default (since it is a non-loadable > > PROGBITS section), but keeps it with -g (which only strips the > > explicitly named .debug sections). > > It should probably keep it regardless, unless you do some sort of > "really brutal strip" that strips out literally everything not needed > for the program to start at all. It might well be necessary at runtime > (in future, anyway). Well, strip without any argument is "really brutal strip". Adding -g makes it a "soft" strip that only strips explicitly debug sections and symbols e.g. symtab is normally stripped, as are, at least with eu-strip, any PROGBIT sections that aren't needed at runtime, aka aren't marked as allocated and aren't (indirectly) referenced from any such section, but those are kept with -g. > > So binutils strip and eu-strip aren't totally identical with the > > default flags, but with --keep-section=.ctf and --remove-section=.ctf > > they seem to do the same thing. > > Yeah, this is a bug -- I simply forgot that eu-strip existed :/ sorry! I am not entirely sure where the bug is. I would call it a bug in binutils strip if it keeps such sections when -g isn't given. > > So I am not sure we really need a --keep-ctf flag for eu-strip (unless > > we also get it for binutils strip). My preference would be to just > > recommend a user use --keep-section=.ctf or --remove-section=.ctf to > > indicate what they want. > > My strong preference would be to make eu-strip do what binutils strip > does. If CTF is not in the binary, the whole format is useless. If > you've got room for the DWARF, the CTF is a strict subset of it anyway > (it's generated from it, after all). But why does binutils strip do that? To be honest it doesn't really make sense to me. I don't see the logic. If you really do want to keep the .ctf section even with eu-strip (without -g) then you really should mark the section in some way that shows it is needed (at runtime). Assuming you don't want to mark the section, my suggestion would be to use an explicit SHT_GNU_CTF section type. That will also help other tools to know that this isn't a generic PROGBITS section but has to be handled specially. Cheers, Mark