summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-04-24 10:17:13 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-05-28 17:07:46 +0100
commit72f3392127e1892cb203a98092b4ae32485365fe (patch)
tree9c851214b2dd4f6f1967c7be277b536684923085 /include
parent47d546f427d0d3bf9f503b5b118ae05b49d73d28 (diff)
downloadbinutils-gdb-72f3392127e1892cb203a98092b4ae32485365fe.tar.gz
libctf: opening
This fills in the other half of the opening/creation puzzle: opening of already-existing CTF files. Such files are always read-only: if you want to add to a CTF file opened with one of the opening functions in this file, use ctf_add_type(), in a later commit, to copy appropriate types into a newly ctf_create()d, writable container. The lowest-level opening functions are in here: ctf_bufopen(), which takes ctf_sect_t structures akin to ELF section headers, and ctf_simple_open(), which can be used if you don't have an entire ELF section header to work from. Both will malloc() new space for the buffers only if necessary, will mmap() directly from the file if requested, and will mprotect() it afterwards to prevent accidental corruption of the types. These functions are also used by ctf_update() when converting types in a writable container into read-only types that can be looked up using the lookup functions (in later commits). The files are always of the native endianness of the system that created them: at read time, the endianness of the header magic number is used to determine whether or not the file needs byte-swapping, and the entire thing is aggressively byte-swapped. The agggressive nature of this swapping avoids complicating the rest of the code with endianness conversions, while the native endianness introduces no byte-swapping overhead in the common case. (The endianness-independence code is also much newer than everything else in this file, and deserves closer scrutiny.) The accessors at the top of the file are there to transparently support older versions of the CTF file format, allowing translation from older formats that have different sizes for the structures in ctf.h: currently, these older formats are intermingled with the newer ones in ctf.h: they will probably migrate to a compatibility header in time, to ease readability. The ctf_set_base() function is split out for the same reason: when conversion code to a newer format is written, it would need to malloc() new storage for the entire ctf_file_t if a file format change causes it to grow, and for that we need ctf_set_base() to be a separate function. One pair of linked data structures supported by this file has no creation code in libctf yet: the data and function object sections read by init_symtab(). These will probably arrive soon, when the linker comes to need them. (init_symtab() has hardly been changed since 2009, but if any code in libctf has rotted over time, this will.) A few simple accessors are also present that can even be called on read-only containers because they don't actually modify them, since the relevant things are not stored in the container but merely change its operation: ctf_setmodel(), which lets you specify whether a container is LP64 or not (used to statically determine the sizes of a few types), ctf_import(), which is the only way to associate a parent container with a child container, and ctf_setspecific(), which lets the caller associate an arbitrary pointer with the CTF container for any use. If the user doesn't call these functions correctly, libctf will misbehave: this is particularly important for ctf_import(), since a container built against a given parent container will not be able to resolve types that depend on types in the parent unless it is ctf_import()ed with a parent container with the same set of types at the same IDs, or a superset. Possible future extensions (also noted in the ctf-hash.c file) include storing a count of things so that we don't need to do one pass over the CTF file counting everything, and computing a perfect hash at CTF creation time in some compact form, storing it in the CTF file, and using it to hash things so we don't need to do a second pass over the entire CTF file to set up the hashes used to go from names to type IDs. (There are multiple such hashes, one for each C type namespace: types, enums, structs, and unions.) libctf/ * ctf-open.c: New file. * swap.h: Likewise. include/ * ctf-api.h (ctf_file_close): New declaration. (ctf_getdatasect): Likewise. (ctf_parent_file): Likewise. (ctf_parent_name): Likewise. (ctf_parent_name_set): Likewise. (ctf_import): Likewise. (ctf_setmodel): Likewise. (ctf_getmodel): Likewise. (ctf_setspecific): Likewise. (ctf_getspecific): Likewise.
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog13
-rw-r--r--include/ctf-api.h13
2 files changed, 26 insertions, 0 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index f069a9dfd40..8b82efedf00 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,5 +1,18 @@
2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+ * ctf-api.h (ctf_file_close): New declaration.
+ (ctf_getdatasect): Likewise.
+ (ctf_parent_file): Likewise.
+ (ctf_parent_name): Likewise.
+ (ctf_parent_name_set): Likewise.
+ (ctf_import): Likewise.
+ (ctf_setmodel): Likewise.
+ (ctf_getmodel): Likewise.
+ (ctf_setspecific): Likewise.
+ (ctf_getspecific): Likewise.
+
+2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+
* ctf-api.h (zlib.h): New include.
(ctf_sect_t): New.
(ctf_sect_names_t): Likewise.
diff --git a/include/ctf-api.h b/include/ctf-api.h
index eb7f0d64c16..d9eff0bc284 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -198,10 +198,23 @@ enum
#define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */
#define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */
+extern ctf_sect_t ctf_getdatasect (const ctf_file_t *);
extern ctf_file_t *ctf_simple_open (const char *, size_t, const char *, size_t,
size_t, const char *, size_t, int *);
extern ctf_file_t *ctf_bufopen (const ctf_sect_t *, const ctf_sect_t *,
const ctf_sect_t *, int *);
+extern void ctf_file_close (ctf_file_t *);
+
+extern ctf_file_t *ctf_parent_file (ctf_file_t *);
+extern const char *ctf_parent_name (ctf_file_t *);
+extern void ctf_parent_name_set (ctf_file_t *, const char *);
+
+extern int ctf_import (ctf_file_t *, ctf_file_t *);
+extern int ctf_setmodel (ctf_file_t *, int);
+extern int ctf_getmodel (ctf_file_t *);
+
+extern void ctf_setspecific (ctf_file_t *, void *);
+extern void *ctf_getspecific (ctf_file_t *);
extern int ctf_errno (ctf_file_t *);
extern const char *ctf_errmsg (int);