From: Nick Alcock Date: Wed, 24 Apr 2019 10:26:42 +0000 (+0100) Subject: libctf: library version enforcement X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6c33b742ce19cc2fd226d84f2991572239199a62;p=binutils-gdb.git libctf: library version enforcement This old Solaris standard allows callers to specify that they are expecting one particular API and/or CTF file format from the library. libctf/ * ctf-impl.h (_libctf_version): New declaration. * ctf-subr.c (_libctf_version): Define it. (ctf_version): New. include/ * ctf-api.h (ctf_version): New. --- diff --git a/include/ChangeLog b/include/ChangeLog index 4be07a55319..56922add8a8 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2019-05-28 Nick Alcock + + * ctf-api.h (ctf_version): New. + 2019-05-28 Nick Alcock * ctf-api.h (ctf_func_info): New. diff --git a/include/ctf-api.h b/include/ctf-api.h index 045d8af1905..6ab754a1840 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -269,6 +269,7 @@ extern void *ctf_getspecific (ctf_file_t *); extern int ctf_errno (ctf_file_t *); extern const char *ctf_errmsg (int); +extern int ctf_version (int); extern int ctf_func_info (ctf_file_t *, unsigned long, ctf_funcinfo_t *); extern int ctf_func_args (ctf_file_t *, unsigned long, uint32_t, ctf_id_t *); diff --git a/libctf/ChangeLog b/libctf/ChangeLog index c0c98d2f43f..a6eb11ee309 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,9 @@ +2019-05-28 Nick Alcock + + * ctf-impl.h (_libctf_version): New declaration. + * ctf-subr.c (_libctf_version): Define it. + (ctf_version): New. + 2019-05-28 Nick Alcock * ctf-create.c (enumcmp): New. diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index ff185049f91..363b62de7db 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -375,6 +375,7 @@ extern const char *ctf_lookup_symbol_name (ctf_file_t *fp, unsigned long symidx) extern const char _CTF_SECTION[]; /* name of CTF ELF section */ extern const char _CTF_NULLSTR[]; /* empty string */ +extern int _libctf_version; /* library client version */ extern int _libctf_debug; /* debugging messages enabled */ #ifdef __cplusplus diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c index 3103e28a3f3..09ec2951e54 100644 --- a/libctf/ctf-subr.c +++ b/libctf/ctf-subr.c @@ -27,6 +27,7 @@ #include static size_t _PAGESIZE _libctf_unused_; +int _libctf_version = CTF_VERSION; /* Library client version. */ int _libctf_debug = 0; /* Debugging messages enabled. */ _libctf_malloc_ void * @@ -190,6 +191,32 @@ ctf_strerror (int err) return (const char *) (strerror (err)); } +/* Set the CTF library client version to the specified version. If version is + zero, we just return the default library version number. */ +int +ctf_version (int version) +{ + if (version < 0) + { + errno = EINVAL; + return -1; + } + + if (version > 0) + { + /* Dynamic version switching is not presently supported. */ + if (version != CTF_VERSION) + { + errno = ENOTSUP; + return -1; + } + ctf_dprintf ("ctf_version: client using version %d\n", version); + _libctf_version = version; + } + + return _libctf_version; +} + void libctf_init_debug (void) {