nfp->ctf_dtoldid = fp->ctf_dtnextid - 1;
nfp->ctf_snapshots = fp->ctf_snapshots + 1;
nfp->ctf_specific = fp->ctf_specific;
+ nfp->ctf_link_inputs = fp->ctf_link_inputs;
+ nfp->ctf_link_outputs = fp->ctf_link_outputs;
nfp->ctf_syn_ext_strtab = fp->ctf_syn_ext_strtab;
+ nfp->ctf_link_cu_mapping = fp->ctf_link_cu_mapping;
+ nfp->ctf_link_type_mapping = fp->ctf_link_type_mapping;
+ nfp->ctf_link_memb_name_changer = fp->ctf_link_memb_name_changer;
+ nfp->ctf_link_memb_name_changer_arg = fp->ctf_link_memb_name_changer_arg;
nfp->ctf_snapshot_lu = fp->ctf_snapshots;
nfp->ctf_str_atoms = fp->ctf_str_atoms;
fp->ctf_str_atoms = NULL;
memset (&fp->ctf_dtdefs, 0, sizeof (ctf_list_t));
+ fp->ctf_link_inputs = NULL;
+ fp->ctf_link_outputs = NULL;
fp->ctf_syn_ext_strtab = NULL;
+ fp->ctf_link_cu_mapping = NULL;
+ fp->ctf_link_type_mapping = NULL;
fp->ctf_dvhash = NULL;
memset (&fp->ctf_dvdefs, 0, sizeof (ctf_list_t));
ctf_id_t tmp;
const char *name;
- uint32_t kind, flag, vlen;
+ uint32_t kind, forward_kind, flag, vlen;
const ctf_type_t *src_tp, *dst_tp;
ctf_bundle_t src, dst;
ctf_funcinfo_t ctc;
ctf_hash_t *hp;
+ ctf_id_t orig_src_type = src_type;
if (!(dst_fp->ctf_flags & LCTF_RDWR))
return (ctf_set_errno (dst_fp, ECTF_RDONLY));
flag = LCTF_INFO_ISROOT (src_fp, src_tp->ctt_info);
vlen = LCTF_INFO_VLEN (src_fp, src_tp->ctt_info);
- switch (kind)
+ forward_kind = kind;
+ if (kind == CTF_K_FORWARD)
+ forward_kind = src_tp->ctt_type;
+
+ switch (forward_kind)
{
case CTF_K_STRUCT:
hp = dst_fp->ctf_structs;
/* If an identically named dst_type exists, fail with ECTF_CONFLICT
unless dst_type is a forward declaration and src_type is a struct,
- union, or enum (i.e. the definition of the previous forward decl). */
+ union, or enum (i.e. the definition of the previous forward decl).
- if (dst_type != CTF_ERR && dst_kind != kind
- && (dst_kind != CTF_K_FORWARD
- || (kind != CTF_K_ENUM && kind != CTF_K_STRUCT
- && kind != CTF_K_UNION)))
+ We also allow addition in the opposite order (addition of a forward when a
+ struct, union, or enum already exists), which is a NOP and returns the
+ already-present struct, union, or enum. */
+
+ if (dst_type != CTF_ERR && dst_kind != kind)
{
- ctf_dprintf ("Conflict for type %s: kinds differ, new: %i; "
- "old (ID %lx): %i\n", name, kind, dst_type, dst_kind);
- return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+ if (kind == CTF_K_FORWARD
+ && (dst_kind == CTF_K_ENUM || dst_kind == CTF_K_STRUCT
+ || dst_kind == CTF_K_UNION))
+ {
+ ctf_add_type_mapping (src_fp, src_type, dst_fp, dst_type);
+ return dst_type;
+ }
+
+ if (dst_kind != CTF_K_FORWARD
+ || (kind != CTF_K_ENUM && kind != CTF_K_STRUCT
+ && kind != CTF_K_UNION))
+ {
+ ctf_dprintf ("Conflict for type %s: kinds differ, new: %i; "
+ "old (ID %lx): %i\n", name, kind, dst_type, dst_kind);
+ return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+ }
}
/* We take special action for an integer, float, or slice since it is
if (memcmp (&src_en, &dst_en, sizeof (ctf_encoding_t)) == 0)
{
if (kind != CTF_K_SLICE)
- return dst_type;
+ {
+ ctf_add_type_mapping (src_fp, src_type, dst_fp, dst_type);
+ return dst_type;
+ }
}
else
{
int match; /* Do the encodings match? */
if (kind != CTF_K_INTEGER && kind != CTF_K_FLOAT && kind != CTF_K_SLICE)
- return dtd->dtd_type;
+ {
+ ctf_add_type_mapping (src_fp, src_type, dst_fp, dtd->dtd_type);
+ return dtd->dtd_type;
+ }
sroot = (flag & CTF_ADD_ROOT);
droot = (LCTF_INFO_ISROOT (dst_fp,
if (match && sroot == droot)
{
if (kind != CTF_K_SLICE)
- return dtd->dtd_type;
+ {
+ ctf_add_type_mapping (src_fp, src_type, dst_fp, dtd->dtd_type);
+ return dtd->dtd_type;
+ }
}
else if (!match && sroot && droot)
{
case CTF_K_FORWARD:
if (dst_type == CTF_ERR)
- {
- dst_type = ctf_add_forward (dst_fp, flag,
- name, CTF_K_STRUCT); /* Assume STRUCT. */
- }
+ dst_type = ctf_add_forward (dst_fp, flag, name, forward_kind);
break;
case CTF_K_TYPEDEF:
return (ctf_set_errno (dst_fp, ECTF_CORRUPT));
}
+ if (dst_type != CTF_ERR)
+ ctf_add_type_mapping (src_fp, orig_src_type, dst_fp, dst_type);
return dst_type;
}
{
ctf_dprintf ("zlib deflate err: %s\n", zError (rc));
err = ctf_set_errno (fp, ECTF_COMPRESS);
- ctf_free (buf);
goto ret;
}
return err;
}
+/* Optionally compress the specified CTF data stream and return it as a new
+ dynamically-allocated string. */
+unsigned char *
+ctf_write_mem (ctf_file_t *fp, size_t *size, size_t threshold)
+{
+ unsigned char *buf;
+ unsigned char *bp;
+ ctf_header_t *hp;
+ ssize_t header_len = sizeof (ctf_header_t);
+ ssize_t compress_len;
+ size_t max_compress_len = compressBound (fp->ctf_size);
+ int rc;
+
+ if (fp->ctf_size < threshold)
+ max_compress_len = fp->ctf_size;
+ if ((buf = malloc (max_compress_len
+ + sizeof (struct ctf_header))) == NULL)
+ {
+ ctf_set_errno (fp, ENOMEM);
+ return NULL;
+ }
+
+ hp = (ctf_header_t *) buf;
+ memcpy (hp, fp->ctf_header, header_len);
+ bp = buf + sizeof (struct ctf_header);
+ *size = sizeof (struct ctf_header);
+
+ compress_len = max_compress_len;
+
+ if (fp->ctf_size < threshold)
+ {
+ hp->cth_flags &= ~CTF_F_COMPRESS;
+ memcpy (bp, fp->ctf_buf, fp->ctf_size);
+ *size += fp->ctf_size;
+ }
+ else
+ {
+ hp->cth_flags |= CTF_F_COMPRESS;
+ if ((rc = compress (bp, (uLongf *) &compress_len,
+ fp->ctf_buf, fp->ctf_size)) != Z_OK)
+ {
+ ctf_dprintf ("zlib deflate err: %s\n", zError (rc));
+ ctf_set_errno (fp, ECTF_COMPRESS);
+ ctf_free (buf);
+ return NULL;
+ }
+ *size += compress_len;
+ }
+ return buf;
+}
+
/* Write the uncompressed CTF data stream to the specified file descriptor. */
int
ctf_write (ctf_file_t *fp, int fd)