This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Should strip discard the .ctf section ?


On 2019-10-08, Nick Alcock wrote:
On 8 Oct 2019, Nick Alcock verbalised:

(Hah! Thank you for spotting a horrible mistake on my part: see below.
Fix forthcoming.)

Oh wait no, I am hallucinating and forgetting my own code.

On 8 Oct 2019, Fangrui Song said:
--strip-all removes .symtab and .strtab. If .ctf references .symtab but
is not stripped along with .symtab and .strtab, the resulting .ctf will
just be broken.

... good point! This is clearly a horrible mistake on my part. Phew,
thank goodness you spotted this one early.

The gain here is mostly from sharing symbol name strings, so I think we
should be sharing with .dynstr, since that's where the symtab strings
are kept and frankly it's the only symtab with significant amounts of
useful content in a stripped executable. Illumos uses the concatenation
of .dynstr and .SUNW_ldynsym, the latter being an executable-only string
table used to allow symtab lookups to work on stripped executables. We
don't have .ldynsym (not yet, anyway) so sharing with .dynstr alone is
clearly right.

(It would be nice if we could share with both that *and* .strtab, but
since .strtab is hardly ever there I don't think this is likely to be
worth doing. We could share with .strtab in statically-linked
executables only but I don't think they're common enough to be worth
special-casing.)

It turns out that I thought of this already, and even wrote a comment
about it, and forgot that I'd done so. We specifically use the
symstrtab, i.e. whatever string table the symbol names are in, and use
the symtab's sh_link to find it at ctf_open time: so, on ELF, we end up
doing the right thing automatically. See the call to examine_strtab() in
elf_link_swap_symbols_out(), and the use of sh_link in
libctf/ctf-open-bfd.c:ctf_bfdopen_ctfsect().

Phew! Sorry for the mislead. We are fine here I think.

I will make a special note in the spec, since it is clear that this is
something that is easily got wrong! (In partial mitigation, I haven't
slept for two days...)

strip/objcopy --keep-section=.ctf is available now
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=64f52b3ec1853d14293d5a461d7abc8bde5e3f62

We can make --strip-all and --strip-debug remove .ctf and teach the
package managers to use --keep-section=.ctf

In an ideal world, I would want --strip-all to do
https://github.com/llvm/llvm-project/blob/master/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp#L498 (llvm-objcopy --strip-all),
but unfortunately strip/objcopy --strip-all keeps many non-SHF_ALLOC sections
https://github.com/llvm/llvm-project/blob/master/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp#L459 (llvm-objcopy --strip-all-gnu).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]