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

@@ -3156,8 +3156,9 @@ ctf_dedup_emit (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
return outputs;
}
/* Deduplicate strings. This must be done after parent serialization.
The child dict ctf_parent_strlen is not updated yet. */
/* Deduplicate strings. This must be done after parent serialization and child
preserialization. The child dict ctf_parent_strlen is not updated yet.
(ctf_arc_write_*() does the right thing.) */
int
ctf_dedup_strings (ctf_dict_t *fp)
@@ -3191,7 +3192,7 @@ ctf_dedup_strings (ctf_dict_t *fp)
if (ctf_list_empty_p (&atom->csa_refs))
continue;
if (atom->csa_external_offset
if ((!fp->ctf_serialize.cs_is_btf && atom->csa_external_offset)
|| atom->csa_str[0] == '\0'
|| atom->csa_flags & CTF_STR_ATOM_NO_DEDUP)
continue;
@@ -3240,7 +3241,7 @@ ctf_dedup_strings (ctf_dict_t *fp)
if (ctf_list_empty_p (&atom->csa_refs))
continue;
if (atom->csa_external_offset
if ((!fp->ctf_serialize.cs_is_btf && atom->csa_external_offset)
|| atom->csa_str[0] == '\0'
|| atom->csa_flags & CTF_STR_ATOM_NO_DEDUP)
continue;