diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2019-10-21 11:27:43 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-06-26 15:56:39 +0100 |
commit | fe4c2d55634c700ba527ac4183e05c66e9f93c62 (patch) | |
tree | 67eeb7d1fa76d860f2d2473eddc9c7f4533cc6c9 /libctf/ctf-open.c | |
parent | 094e34f22146ad53eb93da22e480cab428bd23b5 (diff) | |
download | gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.zip gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.tar.gz gdb-fe4c2d55634c700ba527ac4183e05c66e9f93c62.tar.bz2 |
libctf: create: non-root-visible types should not appear in name tables
We were accidentally interning newly-added and newly-opened
non-root-visible types into name tables, and removing names from name
tables when such types were removed. This is very wrong: the whole
point of non-root-visible types is they do not go in name tables and
cannot be looked up by name. This bug made non-root-visible types
basically identical to root-visible types, right back to the earliest
days of libctf in the Solaris era.
libctf/
* ctf-open.c (init_types): Only intern root-visible types.
* ctf-create.c (ctf_dtd_insert): Likewise.
(ctf_dtd_delete): Only remove root-visible types.
(ctf_rollback): Likewise.
(ctf_add_generic): Adjust.
(ctf_add_struct_sized): Adjust comment.
(ctf_add_union_sized): Likewise.
(ctf_add_enum): Likewise.
* ctf-impl.h (ctf_dtd_insert): Adjust prototype.
Diffstat (limited to 'libctf/ctf-open.c')
-rw-r--r-- | libctf/ctf-open.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 6408146..4daa1e4 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -765,7 +765,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) for (id = 1, tp = tbuf; tp < tend; xp++, id++) { unsigned short kind = LCTF_INFO_KIND (fp, tp->ctt_info); - unsigned short flag = LCTF_INFO_ISROOT (fp, tp->ctt_info); + unsigned short isroot = LCTF_INFO_ISROOT (fp, tp->ctt_info); unsigned long vlen = LCTF_INFO_VLEN (fp, tp->ctt_info); ssize_t size, increment, vbytes; @@ -787,7 +787,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) if (((ctf_hash_lookup_type (fp->ctf_names.ctn_readonly, fp, name)) == 0) - || (flag & CTF_ADD_ROOT)) + || isroot) { err = ctf_hash_define_type (fp->ctf_names.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), @@ -804,6 +804,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) break; case CTF_K_FUNCTION: + if (!isroot) + break; + err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); @@ -812,6 +815,12 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) break; case CTF_K_STRUCT: + if (size >= CTF_LSTRUCT_THRESH) + nlstructs++; + + if (!isroot) + break; + err = ctf_hash_define_type (fp->ctf_structs.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); @@ -819,23 +828,27 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) if (err != 0) return err; - if (size >= CTF_LSTRUCT_THRESH) - nlstructs++; break; case CTF_K_UNION: + if (size >= CTF_LSTRUCT_THRESH) + nlunions++; + + if (!isroot) + break; + err = ctf_hash_define_type (fp->ctf_unions.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); if (err != 0) return err; - - if (size >= CTF_LSTRUCT_THRESH) - nlunions++; break; case CTF_K_ENUM: + if (!isroot) + break; + err = ctf_hash_define_type (fp->ctf_enums.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); @@ -845,6 +858,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) break; case CTF_K_TYPEDEF: + if (!isroot) + break; + err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); @@ -855,6 +871,10 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) case CTF_K_FORWARD: { ctf_names_t *np = ctf_name_table (fp, tp->ctt_type); + + if (!isroot) + break; + /* Only insert forward tags into the given hash if the type or tag name is not already present. */ if (ctf_hash_lookup_type (np->ctn_readonly, fp, name) == 0) @@ -881,6 +901,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) case CTF_K_VOLATILE: case CTF_K_CONST: case CTF_K_RESTRICT: + if (!isroot) + break; + err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, LCTF_INDEX_TO_TYPE (fp, id, child), tp->ctt_name); |