GNU Binutils with patches for OS216
Revision | fe4c2d55634c700ba527ac4183e05c66e9f93c62 (tree) |
---|---|
Time | 2020-06-26 23:56:39 |
Author | Nick Alcock <nick.alcock@orac...> |
Commiter | Nick Alcock |
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.
@@ -1,3 +1,15 @@ | ||
1 | +2020-06-26 Nick Alcock <nick.alcock@oracle.com> | |
2 | + | |
3 | + * ctf-open.c (init_types): Only intern root-visible types. | |
4 | + * ctf-create.c (ctf_dtd_insert): Likewise. | |
5 | + (ctf_dtd_delete): Only remove root-visible types. | |
6 | + (ctf_rollback): Likewise. | |
7 | + (ctf_add_generic): Adjust. | |
8 | + (ctf_add_struct_sized): Adjust comment. | |
9 | + (ctf_add_union_sized): Likewise. | |
10 | + (ctf_add_enum): Likewise. | |
11 | + * ctf-impl.h (ctf_dtd_insert): Adjust prototype. | |
12 | + | |
1 | 13 | 2020-03-11 John Baldwin <jhb@FreeBSD.org> |
2 | 14 | |
3 | 15 | * swap.h (bswap_identity_64): Make static. |
@@ -597,13 +597,13 @@ ctf_name_table (ctf_file_t *fp, int kind) | ||
597 | 597 | } |
598 | 598 | |
599 | 599 | int |
600 | -ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int kind) | |
600 | +ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int flag, int kind) | |
601 | 601 | { |
602 | 602 | const char *name; |
603 | 603 | if (ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd) < 0) |
604 | 604 | return -1; |
605 | 605 | |
606 | - if (dtd->dtd_data.ctt_name | |
606 | + if (flag == CTF_ADD_ROOT && dtd->dtd_data.ctt_name | |
607 | 607 | && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) |
608 | 608 | { |
609 | 609 | if (ctf_dynhash_insert (ctf_name_table (fp, kind)->ctn_writable, |
@@ -646,7 +646,8 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd) | ||
646 | 646 | } |
647 | 647 | |
648 | 648 | if (dtd->dtd_data.ctt_name |
649 | - && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) | |
649 | + && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL | |
650 | + && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info)) | |
650 | 651 | { |
651 | 652 | ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable, |
652 | 653 | name); |
@@ -762,7 +763,8 @@ ctf_rollback (ctf_file_t *fp, ctf_snapshot_id_t id) | ||
762 | 763 | kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info); |
763 | 764 | |
764 | 765 | if (dtd->dtd_data.ctt_name |
765 | - && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL) | |
766 | + && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL | |
767 | + && LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info)) | |
766 | 768 | { |
767 | 769 | ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable, |
768 | 770 | name); |
@@ -831,7 +833,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind, | ||
831 | 833 | return (ctf_set_errno (fp, EAGAIN)); |
832 | 834 | } |
833 | 835 | |
834 | - if (ctf_dtd_insert (fp, dtd, kind) < 0) | |
836 | + if (ctf_dtd_insert (fp, dtd, flag, kind) < 0) | |
835 | 837 | { |
836 | 838 | free (dtd); |
837 | 839 | return CTF_ERR; /* errno is set for us. */ |
@@ -1094,8 +1096,7 @@ ctf_add_struct_sized (ctf_file_t *fp, uint32_t flag, const char *name, | ||
1094 | 1096 | ctf_dtdef_t *dtd; |
1095 | 1097 | ctf_id_t type = 0; |
1096 | 1098 | |
1097 | - /* Promote forwards to structs. */ | |
1098 | - | |
1099 | + /* Promote root-visible forwards to structs. */ | |
1099 | 1100 | if (name != NULL) |
1100 | 1101 | type = ctf_lookup_by_rawname (fp, CTF_K_STRUCT, name); |
1101 | 1102 |
@@ -1132,7 +1133,7 @@ ctf_add_union_sized (ctf_file_t *fp, uint32_t flag, const char *name, | ||
1132 | 1133 | ctf_dtdef_t *dtd; |
1133 | 1134 | ctf_id_t type = 0; |
1134 | 1135 | |
1135 | - /* Promote forwards to unions. */ | |
1136 | + /* Promote root-visible forwards to unions. */ | |
1136 | 1137 | if (name != NULL) |
1137 | 1138 | type = ctf_lookup_by_rawname (fp, CTF_K_UNION, name); |
1138 | 1139 |
@@ -1168,7 +1169,7 @@ ctf_add_enum (ctf_file_t *fp, uint32_t flag, const char *name) | ||
1168 | 1169 | ctf_dtdef_t *dtd; |
1169 | 1170 | ctf_id_t type = 0; |
1170 | 1171 | |
1171 | - /* Promote forwards to enums. */ | |
1172 | + /* Promote root-visible forwards to enums. */ | |
1172 | 1173 | if (name != NULL) |
1173 | 1174 | type = ctf_lookup_by_rawname (fp, CTF_K_ENUM, name); |
1174 | 1175 |
@@ -399,7 +399,7 @@ extern void ctf_list_prepend (ctf_list_t *, void *); | ||
399 | 399 | extern void ctf_list_delete (ctf_list_t *, void *); |
400 | 400 | extern int ctf_list_empty_p (ctf_list_t *lp); |
401 | 401 | |
402 | -extern int ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *, int); | |
402 | +extern int ctf_dtd_insert (ctf_file_t *, ctf_dtdef_t *, int flag, int kind); | |
403 | 403 | extern void ctf_dtd_delete (ctf_file_t *, ctf_dtdef_t *); |
404 | 404 | extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_file_t *, ctf_id_t); |
405 | 405 | extern ctf_dtdef_t *ctf_dynamic_type (const ctf_file_t *, ctf_id_t); |
@@ -765,7 +765,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
765 | 765 | for (id = 1, tp = tbuf; tp < tend; xp++, id++) |
766 | 766 | { |
767 | 767 | unsigned short kind = LCTF_INFO_KIND (fp, tp->ctt_info); |
768 | - unsigned short flag = LCTF_INFO_ISROOT (fp, tp->ctt_info); | |
768 | + unsigned short isroot = LCTF_INFO_ISROOT (fp, tp->ctt_info); | |
769 | 769 | unsigned long vlen = LCTF_INFO_VLEN (fp, tp->ctt_info); |
770 | 770 | ssize_t size, increment, vbytes; |
771 | 771 |
@@ -787,7 +787,7 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
787 | 787 | |
788 | 788 | if (((ctf_hash_lookup_type (fp->ctf_names.ctn_readonly, |
789 | 789 | fp, name)) == 0) |
790 | - || (flag & CTF_ADD_ROOT)) | |
790 | + || isroot) | |
791 | 791 | { |
792 | 792 | err = ctf_hash_define_type (fp->ctf_names.ctn_readonly, fp, |
793 | 793 | LCTF_INDEX_TO_TYPE (fp, id, child), |
@@ -804,6 +804,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
804 | 804 | break; |
805 | 805 | |
806 | 806 | case CTF_K_FUNCTION: |
807 | + if (!isroot) | |
808 | + break; | |
809 | + | |
807 | 810 | err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, |
808 | 811 | LCTF_INDEX_TO_TYPE (fp, id, child), |
809 | 812 | tp->ctt_name); |
@@ -812,6 +815,12 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
812 | 815 | break; |
813 | 816 | |
814 | 817 | case CTF_K_STRUCT: |
818 | + if (size >= CTF_LSTRUCT_THRESH) | |
819 | + nlstructs++; | |
820 | + | |
821 | + if (!isroot) | |
822 | + break; | |
823 | + | |
815 | 824 | err = ctf_hash_define_type (fp->ctf_structs.ctn_readonly, fp, |
816 | 825 | LCTF_INDEX_TO_TYPE (fp, id, child), |
817 | 826 | tp->ctt_name); |
@@ -819,23 +828,27 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
819 | 828 | if (err != 0) |
820 | 829 | return err; |
821 | 830 | |
822 | - if (size >= CTF_LSTRUCT_THRESH) | |
823 | - nlstructs++; | |
824 | 831 | break; |
825 | 832 | |
826 | 833 | case CTF_K_UNION: |
834 | + if (size >= CTF_LSTRUCT_THRESH) | |
835 | + nlunions++; | |
836 | + | |
837 | + if (!isroot) | |
838 | + break; | |
839 | + | |
827 | 840 | err = ctf_hash_define_type (fp->ctf_unions.ctn_readonly, fp, |
828 | 841 | LCTF_INDEX_TO_TYPE (fp, id, child), |
829 | 842 | tp->ctt_name); |
830 | 843 | |
831 | 844 | if (err != 0) |
832 | 845 | return err; |
833 | - | |
834 | - if (size >= CTF_LSTRUCT_THRESH) | |
835 | - nlunions++; | |
836 | 846 | break; |
837 | 847 | |
838 | 848 | case CTF_K_ENUM: |
849 | + if (!isroot) | |
850 | + break; | |
851 | + | |
839 | 852 | err = ctf_hash_define_type (fp->ctf_enums.ctn_readonly, fp, |
840 | 853 | LCTF_INDEX_TO_TYPE (fp, id, child), |
841 | 854 | tp->ctt_name); |
@@ -845,6 +858,9 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
845 | 858 | break; |
846 | 859 | |
847 | 860 | case CTF_K_TYPEDEF: |
861 | + if (!isroot) | |
862 | + break; | |
863 | + | |
848 | 864 | err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, |
849 | 865 | LCTF_INDEX_TO_TYPE (fp, id, child), |
850 | 866 | tp->ctt_name); |
@@ -855,6 +871,10 @@ init_types (ctf_file_t *fp, ctf_header_t *cth) | ||
855 | 871 | case CTF_K_FORWARD: |
856 | 872 | { |
857 | 873 | ctf_names_t *np = ctf_name_table (fp, tp->ctt_type); |
874 | + | |
875 | + if (!isroot) | |
876 | + break; | |
877 | + | |
858 | 878 | /* Only insert forward tags into the given hash if the type or tag |
859 | 879 | name is not already present. */ |
860 | 880 | 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) | ||
881 | 901 | case CTF_K_VOLATILE: |
882 | 902 | case CTF_K_CONST: |
883 | 903 | case CTF_K_RESTRICT: |
904 | + if (!isroot) | |
905 | + break; | |
906 | + | |
884 | 907 | err = ctf_hash_insert_type (fp->ctf_names.ctn_readonly, fp, |
885 | 908 | LCTF_INDEX_TO_TYPE (fp, id, child), |
886 | 909 | tp->ctt_name); |