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...)