libctf: strings: no external strings in BTF

One of the things BTF doesn't have is the concept of external strings which
can be shared with the ELF strtab.  Therefore, even if the linker has
reported strings which the dict is reusing, when we generate the strtab for
a BTF dict we should emit those strings into it (and we should certainly
not cause the presence of external strings to prevent BTF emission!)

Note that since already-written strtab entries are never erased, writing a
dict as BTF and then CTF will cause external strings to be emitted even for
the CTF.  This sort of repeated writing in different formats seems to be
very rare: in any case, the problem can be avoided by simply doing the CTF
writeout first (the following BTF writeout will spot the missing external-
in-CTF strings and add them).

We also throw away the internal-only function ctf_strraw_explicit(), which
was used to add strings with a hardwired strtab: it was only ever used to
write out the variable section, which is gone in v4.
This commit is contained in:
Nick Alcock
2025-04-25 12:56:58 +01:00
parent c14bdfc7a4
commit 5ec23dfb74
4 changed files with 36 additions and 39 deletions

View File

@@ -1447,6 +1447,11 @@ ctf_link_add_strtab (ctf_dict_t *fp, ctf_link_strtab_string_f *add_string,
if (fp->ctf_stypes > 0)
return ctf_set_errno (fp, ECTF_RDONLY);
/* If emitting BTF, there is no external string table. */
if (fp->ctf_serialize.cs_is_btf)
return 0;
while ((str = add_string (&offset, arg)) != NULL)
{
ctf_link_out_string_cb_arg_t iter_arg = { str, offset, 0 };