binutils-gdb/libctf/libctf.ver
Nick Alcock 6da9267482
libctf, include: add ctf_dict_set_flag: less enum dup checking by default
The recent change to detect duplicate enum values and return ECTF_DUPLICATE
when found turns out to perturb a great many callers.  In particular, the
pahole-created kernel BTF has the same problem we historically did, and
gleefully emits duplicated enum constants in profusion.  Handling the
resulting duplicate errors from BTF -> CTF converters reasonably is
unreasonably difficult (it amounts to forcing them to skip some types or
reimplement the deduplicator).

So let's step back a bit.  What we care about mostly is that the
deduplicator treat enums with conflicting enumeration constants as
conflicting types: programs that want to look up enumeration constant ->
value mappings using the new APIs to do so might well want the same checks
to apply to any ctf_add_* operations they carry out (and since they're
*using* the new APIs, added at the same time as this restriction was
imposed, there is likely to be no negative consequence of this).

So we want some way to allow processes that know about duplicate detection
to opt into it, while allowing everyone else to stay clear of it: but we
want ctf_link to get this behaviour even if its caller has opted out.

So add a new concept to the API: dict-wide CTF flags, set via
ctf_dict_set_flag, obtained via ctf_dict_get_flag.  They are not bitflags
but simple arbitrary integers and an on/off value, stored in an unspecified
manner (the one current flag, we translate into an LCTF_* flag value in the
internal ctf_dict ctf_flags word). If you pass in an invalid flag or value
you get a new ECTF_BADFLAG error, so the caller can easily tell whether
flags added in future are valid with a particular libctf or not.

We check this flag in ctf_add_enumerator, and set it around the link
(including on child per-CU dicts).  The newish enumerator-iteration test is
souped up to check the semantics of the flag as well.

The fact that the flag can be set and unset at any time has curious
consequences. You can unset the flag, insert a pile of duplicates, then set
it and expect the new duplicates to be detected, not only by
ctf_add_enumerator but also by ctf_lookup_enumerator.  This means we now
have to maintain the ctf_names and conflicting_enums enum-duplication
tracking as new enums are added, not purely as the dict is opened.
Move that code out of init_static_types_internal and into a new
ctf_track_enumerator function that addition can also call.

(None of this affects the file format or serialization machinery, which has
to be able to handle duplicate enumeration constants no matter what.)

include/
	* ctf-api.h (CTF_ERRORS) [ECTF_BADFLAG]: New.
	(ECTF_NERR): Update.
	(CTF_STRICT_NO_DUP_ENUMERATORS): New flag.
	(ctf_dict_set_flag): New function.
	(ctf_dict_get_flag): Likewise.

libctf/
	* ctf-impl.h (LCTF_STRICT_NO_DUP_ENUMERATORS): New flag.
	(ctf_track_enumerator): Declare.
	* ctf-dedup.c (ctf_dedup_emit_type): Set it.
	* ctf-link.c (ctf_create_per_cu): Likewise.
	(ctf_link_deduplicating_per_cu): Likewise.
	(ctf_link): Likewise.
	(ctf_link_write): Likewise.
	* ctf-subr.c (ctf_dict_set_flag): New function.
	(ctf_dict_get_flag): New function.
	* ctf-open.c (init_static_types_internal): Move enum tracking to...
	* ctf-create.c (ctf_track_enumerator): ... this new function.
	(ctf_add_enumerator): Call it.
	* libctf.ver: Add the new functions.
	* testsuite/libctf-lookup/enumerator-iteration.c: Test them.
2024-07-31 21:02:05 +01:00

210 lines
3.8 KiB
Plaintext

/* Copyright (C) 2019-2024 Free Software Foundation, Inc.
This file is part of libctf.
libctf is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not see
<http://www.gnu.org/licenses/>. */
LIBCTF_1.0 {
global:
/* In libctf and libctf-nobfd. */
ctf_bufopen;
ctf_simple_open;
ctf_create;
ctf_close;
ctf_ref;
ctf_file_close;
ctf_cuname;
ctf_cuname_set;
ctf_parent_file;
ctf_parent_name;
ctf_parent_name_set;
ctf_type_isparent;
ctf_type_ischild;
ctf_import;
ctf_setmodel;
ctf_getmodel;
ctf_setspecific;
ctf_getspecific;
ctf_errno;
ctf_errmsg;
ctf_version;
ctf_func_info;
ctf_func_args;
ctf_func_type_info;
ctf_func_type_args;
ctf_lookup_by_name;
ctf_lookup_by_symbol;
ctf_lookup_variable;
ctf_type_resolve;
ctf_type_lname;
ctf_type_name;
ctf_type_name_raw;
ctf_type_aname;
ctf_type_aname_raw;
ctf_type_size;
ctf_type_align;
ctf_type_kind;
ctf_type_kind_forwarded;
ctf_type_reference;
ctf_type_pointer;
ctf_type_encoding;
ctf_type_visit;
ctf_type_cmp;
ctf_type_compat;
ctf_member_info;
ctf_member_next;
ctf_array_info;
ctf_member_count;
ctf_enum_name;
ctf_enum_value;
ctf_label_topmost;
ctf_label_info;
ctf_member_iter;
ctf_enum_iter;
ctf_enum_next;
ctf_type_iter;
ctf_type_next;
ctf_type_iter_all;
ctf_label_iter;
ctf_variable_iter;
ctf_variable_next;
ctf_next_create;
ctf_next_destroy;
ctf_next_copy;
ctf_add_array;
ctf_add_const;
ctf_add_enum;
ctf_add_enum_encoded;
ctf_add_float;
ctf_add_forward;
ctf_add_function;
ctf_add_integer;
ctf_add_pointer;
ctf_add_type;
ctf_add_typedef;
ctf_add_restrict;
ctf_add_slice;
ctf_add_struct;
ctf_add_union;
ctf_add_struct_sized;
ctf_add_union_sized;
ctf_add_volatile;
ctf_add_enumerator;
ctf_add_member;
ctf_add_member_offset;
ctf_add_member_encoded;
ctf_add_variable;
ctf_set_array;
ctf_update;
ctf_discard;
ctf_snapshot;
ctf_rollback;
ctf_write;
ctf_write_mem;
ctf_gzwrite;
ctf_compress_write;
ctf_getdatasect;
ctf_arc_write;
ctf_arc_write_fd;
ctf_arc_bufopen;
ctf_arc_close;
ctf_arc_open_by_name;
ctf_arc_open_by_name_sections;
ctf_archive_count;
ctf_archive_iter;
ctf_archive_next;
ctf_archive_raw_iter;
ctf_get_arc;
ctf_dump;
ctf_setdebug;
ctf_getdebug;
ctf_errwarning_next;
ctf_link_add_ctf;
ctf_link_add_cu_mapping;
ctf_link_set_memb_name_changer;
ctf_link_set_variable_filter;
ctf_link;
ctf_link_add_strtab;
ctf_link_shuffle_syms;
ctf_link_write;
ctf_fdopen; /* libctf only. */
ctf_open; /* libctf only. */
ctf_arc_open; /* libctf only. */
ctf_bfdopen; /* libctf only. */
ctf_bfdopen_ctfsect; /* libctf only. */
local:
*;
};
LIBCTF_1.1 {
global:
ctf_dict_open;
ctf_dict_open_sections;
ctf_dict_close;
ctf_parent_dict;
ctf_symbol_next;
ctf_add_objt_sym;
ctf_add_func_sym;
ctf_link_add_linker_symbol;
ctf_arc_lookup_symbol;
ctf_arc_flush_caches;
ctf_getsymsect;
ctf_getstrsect;
ctf_symsect_endianness;
ctf_arc_symsect_endianness;
} LIBCTF_1.0;
LIBCTF_1.2 {
global:
ctf_lookup_by_symbol_name;
ctf_arc_lookup_symbol_name;
ctf_add_unknown;
} LIBCTF_1.1;
LIBCTF_1.3 {
global:
ctf_lookup_enumerator;
ctf_lookup_enumerator_next;
ctf_arc_lookup_enumerator_next;
ctf_dict_set_flag;
ctf_dict_get_flag;
} LIBCTF_1.2;