summaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2021-03-18 12:37:52 +0000
committerNick Alcock <nick.alcock@oracle.com>2021-03-18 12:40:40 +0000
commit81982d20fac4ae6981097a2d609093e8698fd179 (patch)
tree62ce36d903e94cac575d47cd5dc2aa172f59f5f5 /libctf
parent534444b1ee161f342d303fd6549310963ce233c9 (diff)
downloadbinutils-gdb-81982d20fac4ae6981097a2d609093e8698fd179.tar.gz
libctf: eliminate dtd_u, part 3: functions
One more member vanishes from the dtd_u, leaving only the member for struct/union/enum members. There's not much to do here, since as of commit afd78bd6f0a30ba5 we use the same representation (type sizes, etc) in the dtu_argv as we will use in the final vlen, with one exception: the vlen has alignment padding, and the dtu_argv did not. Simplify things by adding suitable padding in both cases. libctf/ChangeLog 2021-03-18 Nick Alcock <nick.alcock@oracle.com> * ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_argv>: Remove. * ctf-create.c (ctf_dtd_delete): No longer free it. (ctf_add_function): Use the dtd_vlen, not dtu_argv. Properly align. * ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen. * ctf-types.c (ctf_func_type_info): Just use the vlen. (ctf_func_type_args): Likewise.
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ChangeLog9
-rw-r--r--libctf/ctf-create.c33
-rw-r--r--libctf/ctf-impl.h1
-rw-r--r--libctf/ctf-serialize.c16
-rw-r--r--libctf/ctf-types.c4
5 files changed, 28 insertions, 35 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 25a32d2a658..3eff44c146a 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,14 @@
2021-03-18 Nick Alcock <nick.alcock@oracle.com>
+ * ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_argv>: Remove.
+ * ctf-create.c (ctf_dtd_delete): No longer free it.
+ (ctf_add_function): Use the dtd_vlen, not dtu_argv. Properly align.
+ * ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen.
+ * ctf-types.c (ctf_func_type_info): Just use the vlen.
+ (ctf_func_type_args): Likewise.
+
+2021-03-18 Nick Alcock <nick.alcock@oracle.com>
+
* ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_arr>: Remove.
* ctf-create.c (ctf_add_array): Use the dtd_vlen, not dtu_arr.
(ctf_set_array): Likewise.
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index bc46cfa6ca8..6acc2428cd7 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -242,9 +242,6 @@ ctf_dtd_delete (ctf_dict_t *fp, ctf_dtdef_t *dtd)
free (dmd);
}
break;
- case CTF_K_FUNCTION:
- free (dtd->dtd_u.dtu_argv);
- break;
case CTF_K_FORWARD:
name_kind = dtd->dtd_data.ctt_type;
break;
@@ -703,8 +700,9 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
ctf_dtdef_t *dtd;
ctf_id_t type;
uint32_t vlen;
- uint32_t *vdat = NULL;
+ uint32_t *vdat;
ctf_dict_t *tmp = fp;
+ size_t initial_vlen;
size_t i;
if (!(fp->ctf_flags & LCTF_RDWR))
@@ -720,38 +718,35 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
if (ctc->ctc_return != 0
&& ctf_lookup_by_id (&tmp, ctc->ctc_return) == NULL)
- return CTF_ERR; /* errno is set for us. */
+ return CTF_ERR; /* errno is set for us. */
if (vlen > CTF_MAX_VLEN)
return (ctf_set_errno (fp, EOVERFLOW));
- if (vlen != 0 && (vdat = malloc (sizeof (ctf_id_t) * vlen)) == NULL)
- return (ctf_set_errno (fp, EAGAIN));
+ /* One word extra allocated for padding for 4-byte alignment if need be.
+ Not reflected in vlen: we don't want to copy anything into it, and
+ it's in addition to (e.g.) the trailing 0 indicating varargs. */
+
+ initial_vlen = (sizeof (uint32_t) * (vlen + (vlen & 1)));
+ if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_FUNCTION,
+ initial_vlen, &dtd)) == CTF_ERR)
+ return CTF_ERR; /* errno is set for us. */
+
+ vdat = (uint32_t *) dtd->dtd_vlen;
for (i = 0; i < ctc->ctc_argc; i++)
{
tmp = fp;
if (argv[i] != 0 && ctf_lookup_by_id (&tmp, argv[i]) == NULL)
- {
- free (vdat);
- return CTF_ERR; /* errno is set for us. */
- }
+ return CTF_ERR; /* errno is set for us. */
vdat[i] = (uint32_t) argv[i];
}
- if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_FUNCTION,
- 0, &dtd)) == CTF_ERR)
- {
- free (vdat);
- return CTF_ERR; /* errno is set for us. */
- }
-
dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_FUNCTION, flag, vlen);
dtd->dtd_data.ctt_type = (uint32_t) ctc->ctc_return;
if (ctc->ctc_flags & CTF_FUNC_VARARG)
vdat[vlen - 1] = 0; /* Add trailing zero to indicate varargs. */
- dtd->dtd_u.dtu_argv = vdat;
return type;
}
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index c1ce50bc3b9..7a4e418ce2d 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -196,7 +196,6 @@ typedef struct ctf_dtdef
union
{
ctf_list_t dtu_members; /* struct, union, or enum */
- uint32_t *dtu_argv; /* function */
} dtd_u;
} ctf_dtdef_t;
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index d8e78f361f4..460ae1a510e 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -892,19 +892,9 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr)
break;
case CTF_K_FUNCTION:
- {
- uint32_t *argv = (uint32_t *) (uintptr_t) t;
- uint32_t argc;
-
- for (argc = 0; argc < vlen; argc++)
- *argv++ = dtd->dtd_u.dtu_argv[argc];
-
- if (vlen & 1)
- *argv++ = 0; /* Pad to 4-byte boundary. */
-
- t = (unsigned char *) argv;
- break;
- }
+ memcpy (t, dtd->dtd_vlen, sizeof (uint32_t) * (vlen + (vlen & 1)));
+ t += sizeof (uint32_t) * (vlen + (vlen & 1));
+ break;
case CTF_K_STRUCT:
case CTF_K_UNION:
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index 8c983d5542f..1e1ce8ee529 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -1678,7 +1678,7 @@ ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip)
if ((dtd = ctf_dynamic_type (fp, type)) == NULL)
args = (uint32_t *) ((uintptr_t) tp + increment);
else
- args = dtd->dtd_u.dtu_argv;
+ args = (uint32_t *) dtd->dtd_vlen;
if (fip->ctc_argc != 0 && args[fip->ctc_argc - 1] == 0)
{
@@ -1715,7 +1715,7 @@ ctf_func_type_args (ctf_dict_t *fp, ctf_id_t type, uint32_t argc, ctf_id_t *argv
if ((dtd = ctf_dynamic_type (fp, type)) == NULL)
args = (uint32_t *) ((uintptr_t) tp + increment);
else
- args = dtd->dtd_u.dtu_argv;
+ args = (uint32_t *) dtd->dtd_vlen;
for (argc = MIN (argc, f.ctc_argc); argc != 0; argc--)
*argv++ = *args++;