diff options
-rw-r--r-- | libctf/ctf-open.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 21ec4cf..558b13d 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -2621,8 +2621,6 @@ ctf_import_internal (ctf_dict_t *fp, ctf_dict_t *pfp, int unreffed) ctf_dict_t *old_parent = fp->ctf_parent; const char *old_parent_name = fp->ctf_parent_name; int old_unreffed = fp->ctf_parent_unreffed; - int is_btf = 0; - size_t expected_prov_strings = 0; if (pfp == NULL || pfp == fp->ctf_parent) return 0; @@ -2669,7 +2667,10 @@ ctf_import_internal (ctf_dict_t *fp, ctf_dict_t *pfp, int unreffed) { /* If we are importing into a parent dict, the child dict had better be empty. Set its starting type ID, which need not be zero: the - parent can already have types. */ + parent can already have types. We assign typemax rather than + idmax because when this is a new dict we want the types to count + up from the number of types currently in the parent, not the number + in the parent when it was opened. */ if (fp->ctf_typemax != 0) { @@ -2679,19 +2680,19 @@ ctf_import_internal (ctf_dict_t *fp, ctf_dict_t *pfp, int unreffed) return (ctf_set_errno (fp, EINVAL)); } fp->ctf_header->cth_parent_ntypes = pfp->ctf_typemax; - - /* We expect one provisional string in this new dict, for the name of - the (non-reffed, non-written-out) void type. */ - expected_prov_strings++; } } /* No importing dicts with provisional strings in (except for the void one added to all new dicts). We might in time be able to lift this restriction, but it is unlikely to be something anyone would want to do, so - let's not bother for now. */ + let's not bother for now. If we have a system-created void type, it might + have instantiated a new string. */ - if (ctf_dynhash_elements (fp->ctf_prov_strtab) != expected_prov_strings) + if ((fp->ctf_void_type == NULL + && ctf_dynhash_elements (fp->ctf_prov_strtab) != 0) + || (fp->ctf_void_type != NULL + && ctf_dynhash_elements (fp->ctf_prov_strtab) > 1)) { ctf_err_warn (fp, 0, EINVAL, _("ctf_import: child dict already has %zi strings, cannot import"), @@ -2715,6 +2716,12 @@ ctf_import_internal (ctf_dict_t *fp, ctf_dict_t *pfp, int unreffed) fp->ctf_parent_unreffed = unreffed; fp->ctf_parent = pfp; + /* BTF dicts don't have any parent strlen in the header, but we need to know + it to dereference strings. */ + + if (fp->ctf_opened_btf) + fp->ctf_header->cth_parent_strlen = pfp->ctf_str[CTF_STRTAB_0].cts_len; + /* If this is a dict that hasn't previously allowed string lookups, we can allow them now, and finish initialization. (This requires us to figure out whether the buffer contains pure BTF or not: we can do that by @@ -2723,9 +2730,8 @@ ctf_import_internal (ctf_dict_t *fp, ctf_dict_t *pfp, int unreffed) fp->ctf_flags |= LCTF_CHILD; fp->ctf_flags &= ~LCTF_NO_STR; - is_btf = CTH_MAGIC (fp->ctf_header) != CTFv4_MAGIC; if (no_strings && (err = init_static_types_names (fp, fp->ctf_header, - is_btf) < 0)) + fp->ctf_opened_btf) < 0)) { /* Undo everything other than cache flushing. */ |