[PATCH v2 14/19] libctf: library version enforcement
Nick Alcock
nick.alcock@oracle.com
Fri May 17 22:10:00 GMT 2019
This old Solaris standard allows callers to specify that they are
expecting one particular API and/or CTF file format from the library.
It is basically vestigial and I would be amenable to dropping it.
Changes from v1:
- Correct erroneous license (GPLv2+ -> v3+) and reset copyright years.
- Adjust to ctf_free() prototype changes
- Migrate into ctf-subr.c, since ctf-lib.c is gone
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.
---
include/ctf-api.h | 1 +
libctf/ctf-impl.h | 1 +
libctf/ctf-subr.c | 27 +++++++++++++++++++++++++++
3 files changed, 29 insertions(+)
diff --git a/include/ctf-api.h b/include/ctf-api.h
index 049062ea80..81f790dafd 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -239,6 +239,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/ctf-impl.h b/libctf/ctf-impl.h
index 91c46d5d5a..a067e0f4d0 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -364,6 +364,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 3103e28a3f..09ec2951e5 100644
--- a/libctf/ctf-subr.c
+++ b/libctf/ctf-subr.c
@@ -27,6 +27,7 @@
#include <unistd.h>
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)
{
--
2.21.0.237.gd0cfaa883d
More information about the Binutils
mailing list