forked from Imagelibrary/binutils-gdb
libctf: open, types: ctf_import for BTF
ctf_import needs a bunch of fixes to work with pure BTF dicts -- and, for that matter, importing newly-created parent dicts that have never been written out, which may have a bunch of nonprovisional types (if types were added to it before any imports were done) or may not (if at least one ctf_import into it was done before any types were added). So we adjust things so that the values that are checked against are the nonprovisional-types values: the header revisions actually changed the name of cth_parent_typemax to cth_parent_ntypes to make this clearer, so catch up with that. In the parent, we have to use ctf_idmax, not ctf_typemax. One thing we must prohibit is that you cannot add a bunch of types to a child and then import a parent into it: the type IDs will all be wrong and the string offsets more so. This was partly prohibited: prohibit it entirely (excepting only that the not-actually-written-out void type we might add to new BTF dicts does not influence this check). Since BTF children don't have a cth_parent_ntypes or a cth_parent_strlen, we cannot check this stuff, but just set them and hope.
This commit is contained in:
@@ -40,7 +40,7 @@ ctf_type_isparent (const ctf_dict_t *fp, ctf_id_t id)
|
||||
have been added. Simple range check. */
|
||||
|
||||
if (!fp->ctf_parent)
|
||||
return (fp->ctf_header->cth_parent_typemax >= id);
|
||||
return (fp->ctf_header->cth_parent_ntypes >= id);
|
||||
|
||||
/* Types in the parent's idmax range (which encompasses its stypes range) are
|
||||
in the parent. */
|
||||
@@ -76,16 +76,16 @@ ctf_type_to_index_internal (const ctf_dict_t *fp, ctf_id_t type)
|
||||
{
|
||||
uint32_t idx = type;
|
||||
|
||||
assert (((fp->ctf_flags & LCTF_CHILD) && (type > fp->ctf_header->cth_parent_typemax)) ||
|
||||
assert (((fp->ctf_flags & LCTF_CHILD) && (type > fp->ctf_header->cth_parent_ntypes)) ||
|
||||
(!(fp->ctf_flags & LCTF_CHILD)));
|
||||
|
||||
if (fp->ctf_flags & LCTF_CHILD)
|
||||
{
|
||||
/* Non-dynamic type in parent: no index permitted. */
|
||||
|
||||
assert (type > fp->ctf_header->cth_parent_typemax);
|
||||
assert (type > fp->ctf_header->cth_parent_ntypes);
|
||||
|
||||
idx -= fp->ctf_header->cth_parent_typemax;
|
||||
idx -= fp->ctf_header->cth_parent_ntypes;
|
||||
}
|
||||
|
||||
if (idx <= fp->ctf_stypes)
|
||||
@@ -130,7 +130,7 @@ ctf_id_t
|
||||
ctf_index_to_type (const ctf_dict_t *fp, uint32_t idx)
|
||||
{
|
||||
if (fp->ctf_flags & LCTF_CHILD)
|
||||
return idx + fp->ctf_header->cth_parent_typemax;
|
||||
return idx + fp->ctf_header->cth_parent_ntypes;
|
||||
|
||||
if (idx <= (fp->ctf_typemax - fp->ctf_nprovtypes))
|
||||
return idx;
|
||||
|
||||
Reference in New Issue
Block a user