]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
libctf: create, types: functions, linkage, arg names (API ADVICE)
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 09:55:41 +0000 (10:55 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:43 +0000 (18:07 +0100)
commit39cdb3e395c27b3c337a9f6aa56ec3cad7dccbd5
treeaedb4f5b22a7b1aa336ed31b918065166e8530b8
parenta632f3ed33636101e0cef0485abe52255841b5c7
libctf: create, types: functions, linkage, arg names (API ADVICE)

Functions change in CTFv4 by growing argument names as well as argument
types; the representation changes into a two-element array of (type, string
offset) rather than a simple array of arg types.  Functions also gain an
explicit linkage in a different type kind (CTF_K_FUNC_LINKAGE, which
corresponds to BTF_KIND_FUNC).

New API:

 typedef struct ctf_funcinfo {
 /* ... */
-  uint32_t ctc_argc; /* Number of typed arguments to function.  */
+  size_t ctc_argc; /* Number of typed arguments to function.  */
};

int ctf_func_arg_names (ctf_dict_t *, unsigned long, uint32_t, const char **);
int ctf_func_type_arg_names (ctf_dict_t *, ctf_id_t, uint32_t,
      const char **names);
+extern int ctf_type_linkage (ctf_dict_t *, ctf_id_t);
-extern ctf_id_t ctf_add_function (ctf_dict_t *, uint32_t,
-   const ctf_funcinfo_t *, const ctf_id_t *);
+extern ctf_id_t ctf_add_function (ctf_dict_t *, uint32_t,
+   const ctf_funcinfo_t *, const ctf_id_t *,
+   const char **arg_names);
+extern ctf_id_t ctf_add_function_linkage (ctf_dict_t *, uint32_t,
+   ctf_id_t, const char *, int linkage);

Adding this is fairly straightforward; the only annoying part is the way the
callers need to allocate space for the arg name and type arrays.  Maybe we
should rethink these into something like ctf_type_aname(), allocating
space for the caller so the caller doesn't need to?  It would certainly
make all the callers in libctf much less complex...

While we're at it, adjust ctf_type_reference, ctf_type_align, and
ctf_type_size for the new internal API changes (they also all have
special-case code for functions).
include/ctf-api.h
libctf/ctf-create.c
libctf/ctf-decl.c
libctf/ctf-lookup.c
libctf/ctf-types.c
libctf/libctf.ver