public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>
To: <binutils@sourceware.org>
Cc: nick.alcock@oracle.com, amodra@gmail.com,
	"Torbjörn SVENSSON" <torbjorn.svensson@foss.st.com>,
	"Yvan ROUX" <yvan.roux@foss.st.com>
Subject: [PATCH v4] libctf: ctf_member_next needs to return (ssize_t)-1 on error
Date: Tue, 26 Sep 2023 19:28:49 +0200	[thread overview]
Message-ID: <20230926172848.1123514-1-torbjorn.svensson@foss.st.com> (raw)
In-Reply-To: <87wmwdt2bf.fsf@esperi.org.uk>

v1 -> v2:
Changed all functions with signed interger return type to return -1 based on
comment from Alan.

v2 -> v3:
Added ctf_set_errno_signed function to return a signed -1 value based on
comment from Nick.

v3 -> v4:
- Moved ctf_set_errno_signed function to ctf-inlines.h, renamed it to
ctf_set_int_errno and converted it to an inline function.
- Moved ctf_set_errno function to ctf-inlines.h, renamed it to
ctf_set_type_errno, changed return type to ctf_id_t and converted it to an
inline function.
- Updated the changelog entry in the commit message. Is this list really
required? I don't think it give much information in this patch and 'git log'
have mixed commits (some have the entry while others don't).


@Nick: Can you please try this is in your test bench and let me know if it's
ok for trunk?

---

The function ctf_member_next should return (ssize_t)-1 on
error. As the function ctf_set_errno returns (ctf_id_t)-1L and that is
then cast to "unsigned long" as it's the return type of the function,
it's not compatible and causes the value 0xffffffff to be returned on
64-bit Windows builds. As a result, the check for a negative value in
ctf_dedup_rhash_type will never be true and a resulting infinit loop is
created.

This was found testing an arm-none-eabi toolchain built with
x86_64-w64-mingw32. If the same source tree is built with
i686-w64-mingw32, everything appears to be working correctly.

libctf/
	PR libctf/30836
        * ctf-inlines.h (ctf_set_int_errno): New function.
        (ctf_set_type_errno) Likewise.
	(ctf_assert_internal): Call ctf_set_type_errno.
        * ctf-impl.h (ctf_set_errno): Removed function.
        * ctf-util.c (ctf_set_errno): Likewise.
        * ctf-create.c (ctf_add_enumerator): Call ctf_set_int_errno.
        (ctf_add_funcobjt_sym): Likewise.
        (ctf_add_member_encoded): Likewise.
        (ctf_add_member_offset): Likewise.
        (ctf_add_variable): Likewise.
        (ctf_grow_ptrtab): Likewise.
        (ctf_grow_vlen): Likewise.
        (ctf_rollback): Likewise.
        (ctf_set_array): Likewise.
        (ctf_update): Likewise.
	(ctf_add_generic): Call ctf_set_type_errno.
	(ctf_add_encoded): Likewise.
	(ctf_add_reftype): Likewise.
	(ctf_add_slice): Likewise.
	(ctf_add_array): Likewise.
	(ctf_add_function): Likewise.
	(ctf_add_struct_sized): Likewise.
	(ctf_add_union_sized): Likewise.
	(ctf_add_enum): Likewise.
	(ctf_add_enum_encoded): Likewise.
	(ctf_add_forward): Likewise.
	(ctf_add_unknown): Likewise.
	(ctf_add_typedef): Likewise.
	(ctf_add_type_internal): Likewise.
	(ctf_add_type): Likewise.
        * ctf-dedup.c (ctf_dedup_atoms_init): Call ctf_set_int_errno.
        (ctf_dedup_conflictify_unshared): Likewise.
        (ctf_dedup_detect_name_ambiguity): Likewise.
        (ctf_dedup_emit_struct_members): Likewise.
        (ctf_dedup_emit_type): Likewise.
        (ctf_dedup_hash_kind): Likewise.
        (ctf_dedup_init): Likewise.
        (ctf_dedup_mark_conflicting_hash): Likewise.
        (ctf_dedup_multiple_input_dicts): Likewise.
        (ctf_dedup_populate_mappings): Likewise.
        (ctf_dedup_record_origin): Likewise.
        (ctf_dedup_rwalk_output_mapping): Likewise.
        (ctf_dedup_walk_output_mapping): Likewise.
	(id_to_packed_id): Call ctf_set_type_errno.
	(intern): Likewise.
	(ctf_decorate_type_name): Likewise.
	(ctf_dedup_rhash_type): Likewise.
	(ctf_dedup_hash_type): Likewise.
	(ctf_dedup_maybe_synthesize_forward): Likewise.
	(ctf_dedup_id_to_target): Likewise.
	(ctf_dedup_emit): Likewise.
	(ctf_dedup_type_mapping): Likewise.
        * ctf-dump.c (ctf_dump_append): Call ctf_set_int_errno.
        (ctf_dump_header): Likewise.
        (ctf_dump_header_sectfield): Likewise.
        (ctf_dump_header_strfield): Likewise.
        (ctf_dump_label): Likewise.
        (ctf_dump_member): Likewise.
        (ctf_dump_str): Likewise.
        (ctf_dump_type): Likewise.
        (ctf_dump_var): Likewise.
	(ctf_dump_format_type): Call ctf_set_type_errno.
	(ctf_dump): Likewise.
        * ctf-labels.c (ctf_label_info): Call ctf_set_int_errno.
        (ctf_label_iter): Likewise.
	(ctf_label_topmost): Call ctf_set_type_errno.
	(ctf_label_info): Likewise.
        * ctf-link.c (ctf_link_add_ctf_internal): Call ctf_set_int_errno.
        (ctf_link_add_cu_mapping): Likewise.
        (ctf_link_add): Likewise.
        (ctf_link_deduplicating_one_symtypetab): Likewise.
        (ctf_link_deduplicating_per_cu): Likewise.
        (ctf_link_deduplicating_variables): Likewise.
        (ctf_link): Likewise.
        (ctf_link_one_variable): Likewise.
	(ctf_create_per_cu): Call ctf_set_type_errno.
	(ctf_link_deduplicating_open_inputs): Likewise.
	(ctf_link_deduplicating): Likewise.
	(ctf_accumulate_archive_names): Likewise.
	(ctf_link_write): Likewise.
        * ctf-lookup.c (ctf_func_args): Call ctf_set_int_errno.
        (ctf_func_info): Likewise.
        (grow_pptrtab): Likewise.
	(ctf_lookup_by_name_internal): Call ctf_set_type_errno.
	(ctf_lookup_by_id): Likewise.
	(ctf_lookup_variable): Likewise.
	(ctf_symidx_sort): Likewise.
	(ctf_lookup_symbol_name): Likewise.
	(ctf_lookup_symbol_idx): Likewise.
	(ctf_symbol_next): Likewise.
	(ctf_try_lookup_indexed): Likewise.
	(ctf_lookup_by_sym_or_name): Likewise.
	(ctf_func_args): Likewise.
        * ctf-open.c (ctf_cuname_set): Call ctf_set_int_errno.
        (ctf_import): Likewise.
        (ctf_parent_name_set): Likewise.
        (ctf_setmodel): Likewise.
	(ctf_setmodel): Call ctf_set_type_errno.
        * ctf-serialize.c (ctf_gzwrite): Call ctf_set_int_errno.
        (ctf_serialize): Likewise.
        (symtypetab_density): Likewise.
	(ctf_write_mem): Call ctf_set_type_errno.
	(ctf_write): Likewise.
        * ctf-string.c (ctf_str_move_pending): Call ctf_set_int_errno.
	(ctf_str_add_ref_internal): Call ctf_set_type_errno.
	(ctf_str_add_external): Likewise.
	* ctf-subr.c (ctf_errwarning_next): Call ctf_set_type_errno.
	(ctf_assert_fail_internal): Likewise.
        * ctf-types.c (ctf_array_info): Call ctf_set_int_errno.
        (ctf_func_type_info): Likewise.
        (ctf_member_count): Likewise.
        (ctf_member_info): Likewise.
        (ctf_member_next): Likewise.
        (ctf_type_align): Likewise.
        (ctf_type_encoding): Likewise.
        (ctf_type_rvisit): Likewise.
        (ctf_type_size): Likewise.
	(ctf_enum_next): Call ctf_set_type_errno.
	(ctf_type_next): Likewise.
	(ctf_variable_next): Likewise.
	(ctf_type_resolve): Likewise.
	(ctf_type_resolve_unsliced): Likewise.
	(ctf_type_aname): Likewise.
	(ctf_type_reference): Likewise.
	(ctf_type_pointer): Likewise.
	(ctf_enum_name): Likewise.
	(ctf_type_rvisit): Likewise.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
---
 libctf/ctf-create.c    | 148 ++++++++++++++++++++---------------------
 libctf/ctf-dedup.c     | 102 ++++++++++++++--------------
 libctf/ctf-dump.c      |  42 ++++++------
 libctf/ctf-impl.h      |   1 -
 libctf/ctf-inlines.h   |  17 +++++
 libctf/ctf-labels.c    |  10 +--
 libctf/ctf-link.c      |  96 +++++++++++++-------------
 libctf/ctf-lookup.c    |  60 ++++++++---------
 libctf/ctf-open.c      |  16 ++---
 libctf/ctf-serialize.c |  34 +++++-----
 libctf/ctf-string.c    |   8 +--
 libctf/ctf-subr.c      |  10 +--
 libctf/ctf-types.c     | 108 +++++++++++++++---------------
 libctf/ctf-util.c      |  10 ---
 14 files changed, 334 insertions(+), 328 deletions(-)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 6b342dc64a2..46a85e1342d 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -60,7 +60,7 @@ ctf_grow_ptrtab (ctf_dict_t *fp)
 
       if ((new_ptrtab = realloc (fp->ctf_ptrtab,
 				 new_ptrtab_len * sizeof (uint32_t))) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_int_errno (fp, ENOMEM));
 
       fp->ctf_ptrtab = new_ptrtab;
       memset (fp->ctf_ptrtab + fp->ctf_ptrtab_len, 0,
@@ -87,7 +87,7 @@ ctf_grow_vlen (ctf_dict_t *fp, ctf_dtdef_t *dtd, size_t vlen)
 				dtd->dtd_vlen_alloc * 2)) == NULL)
     {
       dtd->dtd_vlen = old;
-      return (ctf_set_errno (fp, ENOMEM));
+      return (ctf_set_int_errno (fp, ENOMEM));
     }
   memset (dtd->dtd_vlen + dtd->dtd_vlen_alloc, 0, dtd->dtd_vlen_alloc);
   dtd->dtd_vlen_alloc *= 2;
@@ -197,7 +197,7 @@ int
 ctf_update (ctf_dict_t *fp)
 {
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   fp->ctf_dtoldid = fp->ctf_typemax;
   return 0;
@@ -226,7 +226,7 @@ ctf_dtd_insert (ctf_dict_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
   if (ctf_dynhash_insert (fp->ctf_dthash, (void *) (uintptr_t) dtd->dtd_type,
 			  dtd) < 0)
     {
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_int_errno (fp, ENOMEM);
       return -1;
     }
 
@@ -239,7 +239,7 @@ ctf_dtd_insert (ctf_dict_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
 	{
 	  ctf_dynhash_remove (fp->ctf_dthash, (void *) (uintptr_t)
 			      dtd->dtd_type);
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_int_errno (fp, ENOMEM);
 	  return -1;
 	}
     }
@@ -330,7 +330,7 @@ ctf_dvd_insert (ctf_dict_t *fp, ctf_dvdef_t *dvd)
 {
   if (ctf_dynhash_insert (fp->ctf_dvhash, dvd->dvd_name, dvd) < 0)
     {
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_int_errno (fp, ENOMEM);
       return -1;
     }
   ctf_list_append (&fp->ctf_dvdefs, dvd);
@@ -391,10 +391,10 @@ ctf_rollback (ctf_dict_t *fp, ctf_snapshot_id_t id)
   ctf_dvdef_t *dvd, *nvd;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (fp->ctf_snapshot_lu >= id.snapshot_id)
-    return (ctf_set_errno (fp, ECTF_OVERROLLBACK));
+    return (ctf_set_int_errno (fp, ECTF_OVERROLLBACK));
 
   for (dtd = ctf_list_next (&fp->ctf_dtdefs); dtd != NULL; dtd = ntd)
     {
@@ -453,23 +453,23 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
   ctf_id_t type;
 
   if (flag != CTF_ADD_NONROOT && flag != CTF_ADD_ROOT)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_type_errno (fp, ECTF_RDONLY));
 
   if (LCTF_INDEX_TO_TYPE (fp, fp->ctf_typemax, 1) >= CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, ECTF_FULL));
+    return (ctf_set_type_errno (fp, ECTF_FULL));
 
   if (LCTF_INDEX_TO_TYPE (fp, fp->ctf_typemax, 1) == (CTF_MAX_PTYPE - 1))
-    return (ctf_set_errno (fp, ECTF_FULL));
+    return (ctf_set_type_errno (fp, ECTF_FULL));
 
   /* Make sure ptrtab always grows to be big enough for all types.  */
   if (ctf_grow_ptrtab (fp) < 0)
       return CTF_ERR;				/* errno is set for us. */
 
   if ((dtd = calloc (1, sizeof (ctf_dtdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_type_errno (fp, EAGAIN));
 
   dtd->dtd_vlen_alloc = vlen;
   if (vlen > 0)
@@ -499,7 +499,7 @@ ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
   return type;
 
  oom:
-  ctf_set_errno (fp, EAGAIN);
+  ctf_set_type_errno (fp, EAGAIN);
  err:
   free (dtd->dtd_vlen);
   free (dtd);
@@ -532,10 +532,10 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
   uint32_t encoding;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    return (ctf_set_type_errno (fp, ECTF_NONAME));
 
   if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT))
     return -1;					/* errno is set for us.  */
@@ -570,7 +570,7 @@ ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, uint32_t kind)
   int child = fp->ctf_flags & LCTF_CHILD;
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (ref != 0 && ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -613,13 +613,13 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref,
   ctf_dict_t *tmp = fp;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if ((ep->cte_bits > 255) || (ep->cte_offset > 255))
-    return (ctf_set_errno (fp, ECTF_SLICEOVERFLOW));
+    return (ctf_set_type_errno (fp, ECTF_SLICEOVERFLOW));
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (ref != 0 && ((tp = ctf_lookup_by_id (&tmp, ref)) == NULL))
     return CTF_ERR;		/* errno is set for us.  */
@@ -634,7 +634,7 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref,
   if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) &&
       (kind != CTF_K_ENUM)
       && (ref != 0))
-    return (ctf_set_errno (fp, ECTF_NOTINTFP));
+    return (ctf_set_type_errno (fp, ECTF_NOTINTFP));
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_SLICE,
 			       sizeof (ctf_slice_t), &dtd)) == CTF_ERR)
@@ -682,7 +682,7 @@ ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
   ctf_dict_t *tmp = fp;
 
   if (arp == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (arp->ctr_contents != 0
       && ctf_lookup_by_id (&tmp, arp->ctr_contents) == NULL)
@@ -697,7 +697,7 @@ ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
       ctf_err_warn (fp, 1, ECTF_INCOMPLETE,
 		    _("ctf_add_array: index type %lx is incomplete"),
 		    arp->ctr_contents);
-      return (ctf_set_errno (fp, ECTF_INCOMPLETE));
+      return (ctf_set_type_errno (fp, ECTF_INCOMPLETE));
     }
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY,
@@ -723,11 +723,11 @@ ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp)
   ctf_array_t *vlen;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (dtd == NULL
       || LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info) != CTF_K_ARRAY)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    return (ctf_set_int_errno (fp, ECTF_BADID));
 
   vlen = (ctf_array_t *) dtd->dtd_vlen;
   fp->ctf_flags |= LCTF_DIRTY;
@@ -751,11 +751,11 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
   size_t i;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_type_errno (fp, ECTF_RDONLY));
 
   if (ctc == NULL || (ctc->ctc_flags & ~CTF_FUNC_VARARG) != 0
       || (ctc->ctc_argc != 0 && argv == NULL))
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   vlen = ctc->ctc_argc;
   if (ctc->ctc_flags & CTF_FUNC_VARARG)
@@ -766,7 +766,7 @@ ctf_add_function (ctf_dict_t *fp, uint32_t flag,
     return CTF_ERR;				/* errno is set for us.  */
 
   if (vlen > CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, EOVERFLOW));
+    return (ctf_set_type_errno (fp, EOVERFLOW));
 
   /* 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
@@ -818,7 +818,7 @@ ctf_add_struct_sized (ctf_dict_t *fp, uint32_t flag, const char *name,
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_type_errno (fp, ENOMEM));
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -858,7 +858,7 @@ ctf_add_union_sized (ctf_dict_t *fp, uint32_t flag, const char *name,
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_type_errno (fp, ENOMEM));
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -897,7 +897,7 @@ ctf_add_enum (ctf_dict_t *fp, uint32_t flag, const char *name)
   if (dtd->dtd_vlen_alloc == 0)
     {
       if ((dtd->dtd_vlen = calloc (1, initial_vlen)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_type_errno (fp, ENOMEM));
       dtd->dtd_vlen_alloc = initial_vlen;
     }
 
@@ -925,7 +925,7 @@ ctf_add_enum_encoded (ctf_dict_t *fp, uint32_t flag, const char *name,
     {
       if ((ctf_type_kind (fp, type) != CTF_K_FORWARD) &&
 	  (ctf_type_kind_unsliced (fp, type) != CTF_K_ENUM))
-	return (ctf_set_errno (fp, ECTF_NOTINTFP));
+	return (ctf_set_type_errno (fp, ECTF_NOTINTFP));
     }
   else if ((type = ctf_add_enum (fp, flag, name)) == CTF_ERR)
     return CTF_ERR;		/* errno is set for us.  */
@@ -943,10 +943,10 @@ ctf_add_forward (ctf_dict_t *fp, uint32_t flag, const char *name,
   ctf_id_t type = 0;
 
   if (!ctf_forwardable_kind (kind))
-    return (ctf_set_errno (fp, ECTF_NOTSUE));
+    return (ctf_set_type_errno (fp, ECTF_NOTSUE));
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    return (ctf_set_type_errno (fp, ECTF_NONAME));
 
   /* If the type is already defined or exists as a forward tag, just
      return the ctf_id_t of the existing definition.  */
@@ -985,7 +985,7 @@ ctf_add_unknown (ctf_dict_t *fp, uint32_t flag, const char *name)
 			_("ctf_add_unknown: cannot add unknown type "
 			  "named %s: type of this name already defined"),
 			name ? name : _("(unnamed type)"));
-	  return (ctf_set_errno (fp, ECTF_CONFLICT));
+	  return (ctf_set_type_errno (fp, ECTF_CONFLICT));
 	}
     }
 
@@ -1007,10 +1007,10 @@ ctf_add_typedef (ctf_dict_t *fp, uint32_t flag, const char *name,
   ctf_dict_t *tmp = fp;
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   if (name == NULL || name[0] == '\0')
-    return (ctf_set_errno (fp, ECTF_NONAME));
+    return (ctf_set_type_errno (fp, ECTF_NONAME));
 
   if (ref != 0 && ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -1055,23 +1055,23 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
   uint32_t kind, vlen, root;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_int_errno (fp, EINVAL));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (dtd == NULL)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    return (ctf_set_int_errno (fp, ECTF_BADID));
 
   kind = LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info);
   root = LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info);
   vlen = LCTF_INFO_VLEN (fp, dtd->dtd_data.ctt_info);
 
   if (kind != CTF_K_ENUM)
-    return (ctf_set_errno (fp, ECTF_NOTENUM));
+    return (ctf_set_int_errno (fp, ECTF_NOTENUM));
 
   if (vlen == CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, ECTF_DTFULL));
+    return (ctf_set_int_errno (fp, ECTF_DTFULL));
 
   old_vlen = dtd->dtd_vlen;
   if (ctf_grow_vlen (fp, dtd, sizeof (ctf_enum_t) * (vlen + 1)) < 0)
@@ -1090,7 +1090,7 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
 
   for (i = 0; i < vlen; i++)
     if (strcmp (ctf_strptr (fp, en[i].cte_name), name) == 0)
-      return (ctf_set_errno (fp, ECTF_DUPLICATE));
+      return (ctf_set_int_errno (fp, ECTF_DUPLICATE));
 
   en[i].cte_name = ctf_str_add_pending (fp, name, &en[i].cte_name);
   en[i].cte_value = value;
@@ -1119,10 +1119,10 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   ctf_lmember_t *memb;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (dtd == NULL)
-    return (ctf_set_errno (fp, ECTF_BADID));
+    return (ctf_set_int_errno (fp, ECTF_BADID));
 
   if (name != NULL && name[0] == '\0')
     name = NULL;
@@ -1132,10 +1132,10 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   vlen = LCTF_INFO_VLEN (fp, dtd->dtd_data.ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
-    return (ctf_set_errno (fp, ECTF_NOTSOU));
+    return (ctf_set_int_errno (fp, ECTF_NOTSOU));
 
   if (vlen == CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, ECTF_DTFULL));
+    return (ctf_set_int_errno (fp, ECTF_DTFULL));
 
   old_vlen = dtd->dtd_vlen;
   if (ctf_grow_vlen (fp, dtd, sizeof (ctf_lmember_t) * (vlen + 1)) < 0)
@@ -1156,7 +1156,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
     {
       for (i = 0; i < vlen; i++)
 	if (strcmp (ctf_strptr (fp, memb[i].ctlm_name), name) == 0)
-	  return (ctf_set_errno (fp, ECTF_DUPLICATE));
+	  return (ctf_set_int_errno (fp, ECTF_DUPLICATE));
     }
 
   if ((msize = ctf_type_size (fp, type)) < 0 ||
@@ -1174,7 +1174,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
       msize = 0;
       malign = 0;
       if (ctf_errno (fp) == ECTF_NONREPRESENTABLE)
-	ctf_set_errno (fp, 0);
+	ctf_set_int_errno (fp, 0);
       else if (ctf_errno (fp) == ECTF_INCOMPLETE)
 	is_incomplete = 1;
       else
@@ -1212,7 +1212,7 @@ ctf_add_member_offset (ctf_dict_t *fp, ctf_id_t souid, const char *name,
 			      "incomplete type %lx to struct %lx without "
 			      "specifying explicit offset\n"),
 			    name ? name : _("(unnamed member)"), type, souid);
-	      return (ctf_set_errno (fp, ECTF_INCOMPLETE));
+	      return (ctf_set_int_errno (fp, ECTF_INCOMPLETE));
 	    }
 
 	  if (ctf_type_encoding (fp, ltype, &linfo) == 0)
@@ -1285,7 +1285,7 @@ ctf_add_member_encoded (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   int otype = type;
 
   if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) && (kind != CTF_K_ENUM))
-    return (ctf_set_errno (fp, ECTF_NOTINTFP));
+    return (ctf_set_int_errno (fp, ECTF_NOTINTFP));
 
   if ((type = ctf_add_slice (fp, CTF_ADD_NONROOT, otype, &encoding)) == CTF_ERR)
     return -1;			/* errno is set for us.  */
@@ -1307,10 +1307,10 @@ ctf_add_variable (ctf_dict_t *fp, const char *name, ctf_id_t ref)
   ctf_dict_t *tmp = fp;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (ctf_dvd_lookup (fp, name) != NULL)
-    return (ctf_set_errno (fp, ECTF_DUPLICATE));
+    return (ctf_set_int_errno (fp, ECTF_DUPLICATE));
 
   if (ctf_lookup_by_id (&tmp, ref) == NULL)
     return -1;			/* errno is set for us.  */
@@ -1321,12 +1321,12 @@ ctf_add_variable (ctf_dict_t *fp, const char *name, ctf_id_t ref)
     return -1;
 
   if ((dvd = malloc (sizeof (ctf_dvdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_int_errno (fp, EAGAIN));
 
   if (name != NULL && (dvd->dvd_name = strdup (name)) == NULL)
     {
       free (dvd);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_int_errno (fp, EAGAIN));
     }
   dvd->dvd_type = ref;
   dvd->dvd_snapshots = fp->ctf_snapshots;
@@ -1350,25 +1350,25 @@ ctf_add_funcobjt_sym (ctf_dict_t *fp, int is_function, const char *name, ctf_id_
   ctf_dynhash_t *h = is_function ? fp->ctf_funchash : fp->ctf_objthash;
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   if (ctf_dynhash_lookup (fp->ctf_objthash, name) != NULL ||
       ctf_dynhash_lookup (fp->ctf_funchash, name) != NULL)
-    return (ctf_set_errno (fp, ECTF_DUPLICATE));
+    return (ctf_set_int_errno (fp, ECTF_DUPLICATE));
 
   if (ctf_lookup_by_id (&tmp, id) == NULL)
     return -1;                                  /* errno is set for us.  */
 
   if (is_function && ctf_type_kind (fp, id) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    return (ctf_set_int_errno (fp, ECTF_NOTFUNC));
 
   if ((dupname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
 
   if (ctf_dynhash_insert (h, dupname, (void *) (uintptr_t) id) < 0)
     {
       free (dupname);
-      return (ctf_set_errno (fp, ENOMEM));
+      return (ctf_set_int_errno (fp, ENOMEM));
     }
   return 0;
 }
@@ -1575,14 +1575,14 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
   ctf_id_t orig_src_type = src_type;
 
   if (!(dst_fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (dst_fp, ECTF_RDONLY));
+    return (ctf_set_type_errno (dst_fp, ECTF_RDONLY));
 
   if ((src_tp = ctf_lookup_by_id (&src_fp, src_type)) == NULL)
-    return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+    return (ctf_set_type_errno (dst_fp, ctf_errno (src_fp)));
 
   if ((ctf_type_resolve (src_fp, src_type) == CTF_ERR)
       && (ctf_errno (src_fp) == ECTF_NONREPRESENTABLE))
-    return (ctf_set_errno (dst_fp, ECTF_NONREPRESENTABLE));
+    return (ctf_set_type_errno (dst_fp, ECTF_NONREPRESENTABLE));
 
   name = ctf_strptr (src_fp, src_tp->ctt_name);
   kind = LCTF_INFO_KIND (src_fp, src_tp->ctt_info);
@@ -1661,7 +1661,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 			_("ctf_add_type: conflict for type %s: "
 			  "kinds differ, new: %i; old (ID %lx): %i"),
 			name, kind, dst_type, dst_kind);
-	  return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	  return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 	}
     }
 
@@ -1672,7 +1672,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
   if (kind == CTF_K_INTEGER || kind == CTF_K_FLOAT || kind == CTF_K_SLICE)
     {
       if (ctf_type_encoding (src_fp, src_type, &src_en) != 0)
-	return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+	return (ctf_set_type_errno (dst_fp, ctf_errno (src_fp)));
 
       if (dst_type != CTF_ERR)
 	{
@@ -1702,7 +1702,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 		}
 	      else
 		  {
-		    return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		    return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 		  }
 	    }
 	  else
@@ -1740,7 +1740,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 
   if (ctf_dynhash_insert (proc_tracking_fp->ctf_add_processing,
 			  (void *) (uintptr_t) src_type, (void *) 1) < 0)
-    return ctf_set_errno (dst_fp, ENOMEM);
+    return ctf_set_type_errno (dst_fp, ENOMEM);
 
   switch (kind)
     {
@@ -1785,7 +1785,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 
     case CTF_K_ARRAY:
       if (ctf_array_info (src_fp, src_type, &src_ar) != 0)
-	return (ctf_set_errno (dst_fp, ctf_errno (src_fp)));
+	return (ctf_set_type_errno (dst_fp, ctf_errno (src_fp)));
 
       src_ar.ctr_contents =
 	ctf_add_type_internal (dst_fp, src_fp, src_ar.ctr_contents,
@@ -1812,7 +1812,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 			    src_ar.ctr_index, src_ar.ctr_nelems,
 			    dst_ar.ctr_contents, dst_ar.ctr_index,
 			    dst_ar.ctr_nelems);
-	      return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	      return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 	    }
 	}
       else
@@ -1859,7 +1859,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 				"size differs, old %li, new %li"), name,
 			      dst_type, (long) ctf_type_size (src_fp, src_type),
 			      (long) ctf_type_size (dst_fp, dst_type));
-		return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 	      }
 
 	    if (ctf_member_iter (src_fp, src_type, membcmp, &dst))
@@ -1867,7 +1867,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 		ctf_err_warn (dst_fp, 1, ECTF_CONFLICT,
 			      _("conflict for type %s against ID %lx: members "
 				"differ, see above"), name, dst_type);
-		return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+		return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 	      }
 
 	    break;
@@ -1925,7 +1925,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
 	      ctf_err_warn (dst_fp, 1, ECTF_CONFLICT,
 			    _("conflict for enum %s against ID %lx: members "
 			      "differ, see above"), name, dst_type);
-	      return (ctf_set_errno (dst_fp, ECTF_CONFLICT));
+	      return (ctf_set_type_errno (dst_fp, ECTF_CONFLICT));
 	    }
 	}
       else
@@ -1964,7 +1964,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
       break;
 
     default:
-      return (ctf_set_errno (dst_fp, ECTF_CORRUPT));
+      return (ctf_set_type_errno (dst_fp, ECTF_CORRUPT));
     }
 
   if (dst_type != CTF_ERR)
@@ -1985,7 +1985,7 @@ ctf_add_type (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type)
   /* We store the hash on the source, because it contains only source type IDs:
      but callers will invariably expect errors to appear on the dest.  */
   if (!src_fp->ctf_add_processing)
-    return (ctf_set_errno (dst_fp, ENOMEM));
+    return (ctf_set_type_errno (dst_fp, ENOMEM));
 
   id = ctf_add_type_internal (dst_fp, src_fp, src_type, src_fp);
   ctf_dynhash_empty (src_fp->ctf_add_processing);
diff --git a/libctf/ctf-dedup.c b/libctf/ctf-dedup.c
index 5fdddfd0b54..96d2ff29535 100644
--- a/libctf/ctf-dedup.c
+++ b/libctf/ctf-dedup.c
@@ -321,7 +321,7 @@ id_to_packed_id (ctf_dict_t *fp, int input_num, ctf_id_t type)
 
  oom:
   free (dynkey);
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_type_errno (fp, ENOMEM);
   return NULL;
 }
 
@@ -378,7 +378,7 @@ ctf_dedup_atoms_init (ctf_dict_t *fp)
       if ((fp->ctf_dedup_atoms_alloc
 	   = ctf_dynset_create (htab_hash_string, htab_eq_string,
 				free)) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	return ctf_set_int_errno (fp, ENOMEM);
     }
   fp->ctf_dedup_atoms = fp->ctf_dedup_atoms_alloc;
   return 0;
@@ -398,7 +398,7 @@ intern (ctf_dict_t *fp, char *atom)
     {
       if (ctf_dynset_insert (fp->ctf_dedup_atoms, atom) < 0)
 	{
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_type_errno (fp, ENOMEM);
 	  return NULL;
 	}
       foo = atom;
@@ -461,7 +461,7 @@ ctf_decorate_type_name (ctf_dict_t *fp, const char *name, int kind)
   return ret;
 
  oom:
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_type_errno (fp, ENOMEM);
   return NULL;
 }
 
@@ -543,7 +543,7 @@ ctf_dedup_record_origin (ctf_dict_t *fp, int input_num, const char *decorated,
 
   if (populate_origin)
     if (ctf_dynhash_cinsert (d->cd_struct_origin, decorated, origin) < 0)
-      return ctf_set_errno (fp, errno);
+      return ctf_set_int_errno (fp, errno);
   return 0;
 }
 
@@ -981,7 +981,7 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
 		input_num, gettext (whaterr), type, kind);
   return NULL;
  oom:
-  ctf_set_errno (fp, errno);
+  ctf_set_type_errno (fp, errno);
   ctf_err_warn (fp, 0, 0, _("%s (%i): %s: during type hashing for type %lx, "
 			    "kind %i"), ctf_link_input_name (input),
 		input_num, gettext (whaterr), type, kind);
@@ -1051,7 +1051,7 @@ ctf_dedup_hash_type (ctf_dict_t *fp, ctf_dict_t *input,
 
   if ((tp = ctf_lookup_by_id (&input, type)) == NULL)
     {
-      ctf_set_errno (fp, ctf_errno (input));
+      ctf_set_type_errno (fp, ctf_errno (input));
       ctf_err_warn (fp, 0, 0, _("%s (%i): lookup failure for type %lx: "
 				"flags %x"), ctf_link_input_name (input),
 		    input_num, type, flags);
@@ -1140,7 +1140,7 @@ ctf_dedup_hash_type (ctf_dict_t *fp, ctf_dict_t *input,
   return hval;
 
  oom:
-  ctf_set_errno (fp, errno);
+  ctf_set_type_errno (fp, errno);
  err:
   ctf_err_warn (fp, 0, 0, _("%s (%i): %s: during type hashing, "
 			    "type %lx, kind %i"),
@@ -1185,7 +1185,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
     }
   else
     if (ctf_dynhash_cinsert (d->cd_output_mapping_guard, id, hval) < 0)
-      return ctf_set_errno (fp, errno);
+      return ctf_set_int_errno (fp, errno);
 #endif
 
   /* Record the type in the output mapping: if this is the first time this type
@@ -1197,17 +1197,17 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 				      hval)) == NULL)
     {
       if (ctf_dynhash_cinsert (d->cd_output_first_gid, hval, id) < 0)
-	return ctf_set_errno (fp, errno);
+	return ctf_set_int_errno (fp, errno);
 
       if ((type_ids = ctf_dynset_create (htab_hash_pointer,
 					 htab_eq_pointer,
 					 NULL)) == NULL)
-	return ctf_set_errno (fp, errno);
+	return ctf_set_int_errno (fp, errno);
       if (ctf_dynhash_insert (d->cd_output_mapping, (void *) hval,
 			      type_ids) < 0)
 	{
 	  ctf_dynset_destroy (type_ids);
-	  return ctf_set_errno (fp, errno);
+	  return ctf_set_int_errno (fp, errno);
 	}
     }
 #ifdef ENABLE_LIBCTF_HASH_DEBUGGING
@@ -1248,7 +1248,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 	    }
 	}
       if (err != ECTF_NEXT_END)
-	return ctf_set_errno (fp, err);
+	return ctf_set_int_errno (fp, err);
     }
 #endif
 
@@ -1256,7 +1256,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
      don't waste time reinserting the same keys in that case.  */
   if (!ctf_dynset_exists (type_ids, id, NULL)
       && ctf_dynset_insert (type_ids, id) < 0)
-    return ctf_set_errno (fp, errno);
+    return ctf_set_int_errno (fp, errno);
 
   /* The rest only needs to happen for types with names.  */
   if (!decorated_name)
@@ -1273,12 +1273,12 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
       if ((name_counts = ctf_dynhash_create (ctf_hash_string,
 					     ctf_hash_eq_string,
 					     NULL, NULL)) == NULL)
-	  return ctf_set_errno (fp, errno);
+	  return ctf_set_int_errno (fp, errno);
       if (ctf_dynhash_cinsert (d->cd_name_counts, decorated_name,
 			       name_counts) < 0)
 	{
 	  ctf_dynhash_destroy (name_counts);
-	  return ctf_set_errno (fp, errno);
+	  return ctf_set_int_errno (fp, errno);
 	}
     }
 
@@ -1287,7 +1287,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
 
   if (ctf_dynhash_cinsert (name_counts, hval,
 			   (const void *) (uintptr_t) (count + 1)) < 0)
-    return ctf_set_errno (fp, errno);
+    return ctf_set_int_errno (fp, errno);
 
   return 0;
 }
@@ -1318,7 +1318,7 @@ ctf_dedup_mark_conflicting_hash (ctf_dict_t *fp, const char *hval)
   if (ctf_dynset_cinsert (d->cd_conflicting_types, hval) < 0)
     {
       ctf_dprintf ("Out of memory marking %s as conflicted\n", hval);
-      ctf_set_errno (fp, errno);
+      ctf_set_int_errno (fp, errno);
       return -1;
     }
 
@@ -1340,7 +1340,7 @@ ctf_dedup_mark_conflicting_hash (ctf_dict_t *fp, const char *hval)
 	}
     }
   if (err != ECTF_NEXT_END)
-    return ctf_set_errno (fp, err);
+    return ctf_set_int_errno (fp, err);
 
   return 0;
 }
@@ -1366,7 +1366,7 @@ ctf_dedup_hash_kind (ctf_dict_t *fp, ctf_dict_t **inputs, const char *hash)
   if (!type_ids)
     {
       ctf_dprintf ("Looked up type kind by nonexistent hash %s.\n", hash);
-      return ctf_set_errno (fp, ECTF_INTERNAL);
+      return ctf_set_int_errno (fp, ECTF_INTERNAL);
     }
   id = ctf_dynset_lookup_any (type_ids);
   if (!ctf_assert (fp, id))
@@ -1585,7 +1585,7 @@ ctf_dedup_detect_name_ambiguity (ctf_dict_t *fp, ctf_dict_t **inputs)
 
  iterr:
   ctf_err_warn (fp, 0, err, _("iteration failed: %s"), gettext (whaterr));
-  return ctf_set_errno (fp, err);
+  return ctf_set_int_errno (fp, err);
 
  assert_err:
   ctf_next_destroy (i);
@@ -1683,7 +1683,7 @@ ctf_dedup_init (ctf_dict_t *fp)
  oom:
   ctf_err_warn (fp, 0, ENOMEM, _("ctf_dedup_init: cannot initialize: "
 				 "out of memory"));
-  return ctf_set_errno (fp, ENOMEM);
+  return ctf_set_int_errno (fp, ENOMEM);
 }
 
 /* No ctf_dedup calls are allowed after this call other than starting a new
@@ -1784,7 +1784,7 @@ ctf_dedup_multiple_input_dicts (ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, err, _("iteration error "
 				      "propagating conflictedness"));
-      return ctf_set_errno (output, err);
+      return ctf_set_int_errno (output, err);
     }
 
   if (multiple)
@@ -1872,14 +1872,14 @@ ctf_dedup_conflictify_unshared (ctf_dict_t *output, ctf_dict_t **inputs)
   return 0;
 
  err_no:
-  ctf_set_errno (output, errno);
+  ctf_set_int_errno (output, errno);
  err:
   err = ctf_errno (output);
   ctf_next_destroy (i);
  iterr:
   ctf_dynset_destroy (to_mark);
   ctf_err_warn (output, 0, err, _("conflictifying unshared types"));
-  return ctf_set_errno (output, err);
+  return ctf_set_int_errno (output, err);
 }
 
 /* The core deduplicator.  Populate cd_output_mapping in the output ctf_dedup
@@ -1913,7 +1913,7 @@ ctf_dedup (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
       if (ctf_dynhash_insert (d->cd_input_nums, inputs[i],
 			      (void *) (uintptr_t) i) < 0)
 	{
-	  ctf_set_errno (output, errno);
+	  ctf_set_int_errno (output, errno);
 	  ctf_err_warn (output, 0, errno, _("ctf_dedup: cannot initialize: %s\n"),
 			ctf_errmsg (errno));
 	  goto err;
@@ -1950,7 +1950,7 @@ ctf_dedup (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
 	{
-	  ctf_set_errno (output, ctf_errno (inputs[i]));
+	  ctf_set_int_errno (output, ctf_errno (inputs[i]));
 	  ctf_err_warn (output, 0, 0, _("iteration failure "
 					"computing type hashes"));
 	  goto err;
@@ -2176,7 +2176,7 @@ ctf_dedup_rwalk_one_output_mapping (ctf_dict_t *output,
 		    type_id, depth, arg);
 
  err_msg:
-  ctf_set_errno (output, ctf_errno (fp));
+  ctf_set_int_errno (output, ctf_errno (fp));
   ctf_err_warn (output, 0, 0, _("%s in input file %s at type ID %lx"),
 		gettext (whaterr), ctf_link_input_name (fp), type);
  err:
@@ -2219,7 +2219,7 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, ECTF_INTERNAL,
 		    _("looked up type kind by nonexistent hash %s"), hval);
-      return ctf_set_errno (output, ECTF_INTERNAL);
+      return ctf_set_int_errno (output, ECTF_INTERNAL);
     }
 
   /* Have we seen this type before?  */
@@ -2237,7 +2237,7 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
 	{
 	  ctf_err_warn (output, 0, ENOMEM,
 			_("out of memory tracking already-visited types"));
-	  return ctf_set_errno (output, ENOMEM);
+	  return ctf_set_int_errno (output, ENOMEM);
 	}
     }
 
@@ -2274,7 +2274,7 @@ ctf_dedup_rwalk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
   if (err != ECTF_NEXT_END)
     {
       ctf_err_warn (output, 0, err, _("cannot walk conflicted type"));
-      return ctf_set_errno (output, err);
+      return ctf_set_int_errno (output, err);
     }
 
   return 0;
@@ -2376,7 +2376,7 @@ ctf_dedup_walk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
   if ((already_visited = ctf_dynset_create (htab_hash_string,
 					    htab_eq_string,
 					    NULL)) == NULL)
-    return ctf_set_errno (output, ENOMEM);
+    return ctf_set_int_errno (output, ENOMEM);
 
   sort_arg.inputs = inputs;
   sort_arg.ninputs = ninputs;
@@ -2400,7 +2400,7 @@ ctf_dedup_walk_output_mapping (ctf_dict_t *output, ctf_dict_t **inputs,
   if (err != ECTF_NEXT_END)
     {
       ctf_err_warn (output, 0, err, _("cannot recurse over output mapping"));
-      ctf_set_errno (output, err);
+      ctf_set_int_errno (output, err);
       goto err;
     }
   ctf_dynset_destroy (already_visited);
@@ -2452,7 +2452,7 @@ ctf_dedup_maybe_synthesize_forward (ctf_dict_t *output, ctf_dict_t *target,
       if ((emitted_forward = ctf_add_forward (target, CTF_ADD_ROOT, name,
 					      fwdkind)) == CTF_ERR)
 	{
-	  ctf_set_errno (output, ctf_errno (target));
+	  ctf_set_type_errno (output, ctf_errno (target));
 	  return CTF_ERR;
 	}
 
@@ -2460,7 +2460,7 @@ ctf_dedup_maybe_synthesize_forward (ctf_dict_t *output, ctf_dict_t *target,
 			       decorated, (void *) (uintptr_t)
 			       emitted_forward) < 0)
 	{
-	  ctf_set_errno (output, ENOMEM);
+	  ctf_set_type_errno (output, ENOMEM);
 	  return CTF_ERR;
 	}
     }
@@ -2550,7 +2550,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
     case 0: /* No forward needed.  */
       break;
     case -1:
-      ctf_set_errno (err_fp, ctf_errno (output));
+      ctf_set_type_errno (err_fp, ctf_errno (output));
       ctf_err_warn (err_fp, 0, 0, _("cannot add synthetic forward for type "
 				    "%i/%lx"), input_num, id);
       return -1;
@@ -2582,7 +2582,7 @@ ctf_dedup_id_to_target (ctf_dict_t *output, ctf_dict_t *target,
 	  ctf_err_warn (err_fp, 0, ctf_errno (output),
 			_("cannot add synthetic forward for type %i/%lx"),
 			input_num, id);
-	  return ctf_set_errno (err_fp, ctf_errno (output));
+	  return ctf_set_type_errno (err_fp, ctf_errno (output));
 	default:
 	  return emitted_forward;
 	}
@@ -2664,7 +2664,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 	      ctf_err_warn (output, 0, err,
 			    _("cannot create per-CU CTF archive for CU %s"),
 			    ctf_link_input_name (input));
-	      return ctf_set_errno (output, err);
+	      return ctf_set_int_errno (output, err);
 	    }
 
 	  ctf_import_unref (target, output);
@@ -2687,7 +2687,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
       ctf_err_warn (output, 0, ctf_errno (input),
 		    _("%s: lookup failure for type %lx"),
 		    ctf_link_input_name (real_input), type);
-      return ctf_set_errno (output, ctf_errno (input));
+      return ctf_set_int_errno (output, ctf_errno (input));
     }
 
   name = ctf_strraw (real_input, tp->ctt_name);
@@ -2765,7 +2765,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 			      ctf_link_input_name (input), input_num, name,
 			      type);
 		ctf_next_destroy (i);
-		return ctf_set_errno (output, ctf_errno (target));
+		return ctf_set_int_errno (output, ctf_errno (target));
 	      }
 	  }
 	if (ctf_errno (input) != ECTF_NEXT_END)
@@ -2860,7 +2860,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 
 	if ((args = calloc (fi.ctc_argc, sizeof (ctf_id_t))) == NULL)
 	  {
-	    ctf_set_errno (input, ENOMEM);
+	    ctf_set_int_errno (input, ENOMEM);
 	    goto err_input;
 	  }
 
@@ -2912,7 +2912,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
 	/* Record the need to emit the members of this structure later.  */
 	if (ctf_dynhash_insert (d->cd_emission_struct_members, id, out_id) < 0)
 	  {
-	    ctf_set_errno (target, errno);
+	    ctf_set_int_errno (target, errno);
 	    goto err_target;
 	  }
 	break;
@@ -2921,7 +2921,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
       ctf_err_warn (output, 0, ECTF_CORRUPT, _("%s: unknown type kind for "
 					       "input type %lx"),
 		    ctf_link_input_name (input), type);
-      return ctf_set_errno (output, ECTF_CORRUPT);
+      return ctf_set_int_errno (output, ECTF_CORRUPT);
     }
 
   if (!emission_hashed
@@ -2931,7 +2931,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
     {
       ctf_err_warn (output, 0, ENOMEM, _("out of memory tracking deduplicated "
 					 "global type IDs"));
-	return ctf_set_errno (output, ENOMEM);
+	return ctf_set_int_errno (output, ENOMEM);
     }
 
   if (!emission_hashed && new_type != 0)
@@ -2944,21 +2944,21 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
  oom_hash:
   ctf_err_warn (output, 0, ENOMEM, _("out of memory creating emission-tracking "
 				     "hashes"));
-  return ctf_set_errno (output, ENOMEM);
+  return ctf_set_int_errno (output, ENOMEM);
 
  err_input:
   ctf_err_warn (output, 0, ctf_errno (input),
 		_("%s (%i): while emitting deduplicated %s, error getting "
 		  "input type %lx"), ctf_link_input_name (input),
 		input_num, errtype, type);
-  return ctf_set_errno (output, ctf_errno (input));
+  return ctf_set_int_errno (output, ctf_errno (input));
  err_target:
   ctf_err_warn (output, 0, ctf_errno (target),
 		_("%s (%i): while emitting deduplicated %s, error emitting "
 		  "target type from input type %lx"),
 		ctf_link_input_name (input), input_num,
 		errtype, type);
-  return ctf_set_errno (output, ctf_errno (target));
+  return ctf_set_int_errno (output, ctf_errno (target));
 }
 
 /* Traverse the cd_emission_struct_members and emit the members of all
@@ -3051,11 +3051,11 @@ ctf_dedup_emit_struct_members (ctf_dict_t *output, ctf_dict_t **inputs,
   ctf_err_warn (output, 0, ctf_errno (err_fp),
 		_("%s (%i): error emitting members for structure type %lx"),
 		ctf_link_input_name (input_fp), input_num, err_type);
-  return ctf_set_errno (output, ctf_errno (err_fp));
+  return ctf_set_int_errno (output, ctf_errno (err_fp));
  iterr:
   ctf_err_warn (output, 0, err, _("iteration failure emitting "
 				  "structure members"));
-  return ctf_set_errno (output, err);
+  return ctf_set_int_errno (output, err);
 }
 
 /* Emit deduplicated types into the outputs.  The shared type repository is
@@ -3101,7 +3101,7 @@ ctf_dedup_emit (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
     {
       ctf_err_warn (output, 0, ENOMEM,
 		    _("out of memory allocating link outputs array"));
-      ctf_set_errno (output, ENOMEM);
+      ctf_set_type_errno (output, ENOMEM);
       return NULL;
     }
   *noutputs = num_outputs;
@@ -3152,7 +3152,7 @@ ctf_dedup_type_mapping (ctf_dict_t *fp, ctf_dict_t *src_fp, ctf_id_t src_type)
     output = fp->ctf_parent;
   else
     {
-      ctf_set_errno (fp, ECTF_INTERNAL);
+      ctf_set_type_errno (fp, ECTF_INTERNAL);
       ctf_err_warn (fp, 0, ECTF_INTERNAL,
 		    _("dict %p passed to ctf_dedup_type_mapping is not a "
 		      "deduplicated output"), (void *) fp);
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 686951a9869..dfb2d671a95 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -56,7 +56,7 @@ ctf_dump_append (ctf_dump_state_t *state, char *str)
   ctf_dump_item_t *cdi;
 
   if ((cdi = malloc (sizeof (struct ctf_dump_item))) == NULL)
-    return (ctf_set_errno (state->cds_fp, ENOMEM));
+    return (ctf_set_int_errno (state->cds_fp, ENOMEM));
 
   cdi->cdi_item = str;
   ctf_list_append (&state->cds_items, cdi);
@@ -93,7 +93,7 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
   ctf_id_t new_id;
   char *str = NULL, *bit = NULL, *buf = NULL;
 
-  ctf_set_errno (fp, 0);
+  ctf_set_type_errno (fp, 0);
   new_id = id;
   do
     {
@@ -117,7 +117,7 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
 	{
 	  if (id == 0 || ctf_errno (fp) == ECTF_NONREPRESENTABLE)
 	    {
-	      ctf_set_errno (fp, ECTF_NONREPRESENTABLE);
+	      ctf_set_type_errno (fp, ECTF_NONREPRESENTABLE);
 	      str = str_append (str, " (type not represented in CTF)");
 	      return str;
 	    }
@@ -237,7 +237,7 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
   return str;
 
  oom:
-  ctf_set_errno (fp, errno);
+  ctf_set_type_errno (fp, errno);
  err:
   ctf_err_warn (fp, 1, 0, _("cannot format name dumping type 0x%lx"), id);
   free (buf);
@@ -261,7 +261,7 @@ ctf_dump_header_strfield (ctf_dict_t *fp, ctf_dump_state_t *state,
   return 0;
 
  err:
-  return (ctf_set_errno (fp, errno));
+  return (ctf_set_int_errno (fp, errno));
 }
 
 /* Dump one section-offset field from the file header into the cds_items.  */
@@ -281,7 +281,7 @@ ctf_dump_header_sectfield (ctf_dict_t *fp, ctf_dump_state_t *state,
   return 0;
 
  err:
-  return (ctf_set_errno (fp, errno));
+  return (ctf_set_int_errno (fp, errno));
 }
 
 /* Dump the file header into the cds_items.  */
@@ -398,7 +398,7 @@ ctf_dump_header (ctf_dict_t *fp, ctf_dump_state_t *state)
   return 0;
  err:
   free (flagstr);
-  return (ctf_set_errno (fp, errno));
+  return (ctf_set_int_errno (fp, errno));
 }
 
 /* Dump a single label into the cds_items.  */
@@ -412,7 +412,7 @@ ctf_dump_label (const char *name, const ctf_lblinfo_t *info,
   ctf_dump_state_t *state = arg;
 
   if (asprintf (&str, "%s -> ", name) < 0)
-    return (ctf_set_errno (state->cds_fp, errno));
+    return (ctf_set_int_errno (state->cds_fp, errno));
 
   if ((typestr = ctf_dump_format_type (state->cds_fp, info->ctb_type,
 				       CTF_ADD_ROOT | CTF_FT_REFS)) == NULL)
@@ -471,7 +471,7 @@ ctf_dump_objts (ctf_dict_t *fp, ctf_dump_state_t *state, int functions)
       continue;
 
     oom:
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_int_errno (fp, ENOMEM);
       ctf_next_destroy (i);
       return -1;
     }
@@ -487,7 +487,7 @@ ctf_dump_var (const char *name, ctf_id_t type, void *arg)
   ctf_dump_state_t *state = arg;
 
   if (asprintf (&str, "%s -> ", name) < 0)
-    return (ctf_set_errno (state->cds_fp, errno));
+    return (ctf_set_int_errno (state->cds_fp, errno));
 
   if ((typestr = ctf_dump_format_type (state->cds_fp, type,
 				       CTF_ADD_ROOT | CTF_FT_REFS)) == NULL)
@@ -540,7 +540,7 @@ ctf_dump_member (const char *name, ctf_id_t id, unsigned long offset,
  oom:
   free (typestr);
   free (bit);
-  return (ctf_set_errno (state->cdm_fp, errno));
+  return (ctf_set_int_errno (state->cdm_fp, errno));
 }
 
 /* Report the number of digits in the hexadecimal representation of a type
@@ -569,7 +569,7 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
 
   /* Indent neatly.  */
   if (asprintf (&indent, "    %*s", type_hex_digits (id), "") < 0)
-    return (ctf_set_errno (state->cds_fp, ENOMEM));
+    return (ctf_set_int_errno (state->cds_fp, ENOMEM));
 
   /* Dump the type itself.  */
   if ((str = ctf_dump_format_type (state->cds_fp, id,
@@ -654,7 +654,7 @@ ctf_dump_type (ctf_id_t id, int flag, void *arg)
  oom:
   free (indent);
   free (str);
-  return ctf_set_errno (state->cds_fp, ENOMEM);
+  return ctf_set_int_errno (state->cds_fp, ENOMEM);
 }
 
 /* Dump the string table into the cds_items.  */
@@ -671,7 +671,7 @@ ctf_dump_str (ctf_dict_t *fp, ctf_dump_state_t *state)
       if (asprintf (&str, "0x%lx: %s",
 		    (unsigned long) (s - fp->ctf_str[CTF_STRTAB_0].cts_strs),
 		    s) < 0)
-	return (ctf_set_errno (fp, errno));
+	return (ctf_set_int_errno (fp, errno));
       ctf_dump_append (state, str);
       s += strlen (s) + 1;
     }
@@ -707,7 +707,7 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
 
       if ((*statep = malloc (sizeof (struct ctf_dump_state))) == NULL)
 	{
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_type_errno (fp, ENOMEM);
 	  goto end;
 	}
       state = *statep;
@@ -726,7 +726,7 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
 	    {
 	      if (ctf_errno (fp) != ECTF_NOLABELDATA)
 		goto end;		/* errno is set for us.  */
-	      ctf_set_errno (fp, 0);
+	      ctf_set_type_errno (fp, 0);
 	    }
 	  break;
 	case CTF_SECT_OBJT:
@@ -749,7 +749,7 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
 	  ctf_dump_str (fp, state);
 	  break;
 	default:
-	  ctf_set_errno (fp, ECTF_DUMPSECTUNKNOWN);
+	  ctf_set_type_errno (fp, ECTF_DUMPSECTUNKNOWN);
 	  goto end;
 	}
     }
@@ -759,7 +759,7 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
 
       if (state->cds_sect != sect)
 	{
-	  ctf_set_errno (fp, ECTF_DUMPSECTCHANGED);
+	  ctf_set_type_errno (fp, ECTF_DUMPSECTCHANGED);
 	  goto end;
 	}
     }
@@ -813,18 +813,18 @@ ctf_dump (ctf_dict_t *fp, ctf_dump_state_t **statep, ctf_sect_names_t sect,
       str = strdup (state->cds_current->cdi_item);
       if (!str)
 	{
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_type_errno (fp, ENOMEM);
 	  return str;
 	}
     }
 
-  ctf_set_errno (fp, 0);
+  ctf_set_type_errno (fp, 0);
   return str;
 
  end:
   ctf_dump_free (state);
   free (state);
-  ctf_set_errno (fp, 0);
+  ctf_set_type_errno (fp, 0);
   *statep = NULL;
   return NULL;
 }
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index da687762c89..77d74ef0ea9 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -741,7 +741,6 @@ extern struct ctf_archive *ctf_arc_open_internal (const char *, int *);
 extern void ctf_arc_close_internal (struct ctf_archive *);
 extern const ctf_preamble_t *ctf_arc_bufpreamble (const ctf_sect_t *);
 extern void *ctf_set_open_errno (int *, int);
-extern unsigned long ctf_set_errno (ctf_dict_t *, int);
 extern void ctf_flip_header (ctf_header_t *);
 extern int ctf_flip (ctf_dict_t *, ctf_header_t *, unsigned char *, int);
 
diff --git a/libctf/ctf-inlines.h b/libctf/ctf-inlines.h
index 6bda68d68e6..fb6e884a0a7 100644
--- a/libctf/ctf-inlines.h
+++ b/libctf/ctf-inlines.h
@@ -90,6 +90,23 @@ ctf_assert_internal (ctf_dict_t *fp, const char *file, size_t line,
   return expr;
 }
 
+static inline int
+ctf_set_int_errno (ctf_dict_t *fp, int err)
+{
+  fp->ctf_errno = err;
+  /* Don't rely on CTF_ERR here as it will not properly sign extend on 64-bit
+     Windows ABI.  */
+  return -1;
+}
+
+static inline ctf_id_t
+ctf_set_type_errno (ctf_dict_t *fp, int err)
+{
+  fp->ctf_errno = err;
+  return CTF_ERR;
+}
+
+
 #ifdef	__cplusplus
 }
 #endif
diff --git a/libctf/ctf-labels.c b/libctf/ctf-labels.c
index 16b111b14df..125d392395e 100644
--- a/libctf/ctf-labels.c
+++ b/libctf/ctf-labels.c
@@ -48,12 +48,12 @@ ctf_label_topmost (ctf_dict_t *fp)
 
   if (num_labels == 0)
     {
-      (void) ctf_set_errno (fp, ECTF_NOLABELDATA);
+      (void) ctf_set_type_errno (fp, ECTF_NOLABELDATA);
       return NULL;
     }
 
   if ((s = ctf_strraw (fp, (ctlp + num_labels - 1)->ctl_label)) == NULL)
-    (void) ctf_set_errno (fp, ECTF_CORRUPT);
+    (void) ctf_set_type_errno (fp, ECTF_CORRUPT);
 
   return s;
 }
@@ -74,7 +74,7 @@ ctf_label_iter (ctf_dict_t *fp, ctf_label_f *func, void *arg)
     return -1;			/* errno is set for us.  */
 
   if (num_labels == 0)
-    return (ctf_set_errno (fp, ECTF_NOLABELDATA));
+    return (ctf_set_int_errno (fp, ECTF_NOLABELDATA));
 
   for (i = 0; i < num_labels; i++, ctlp++)
     {
@@ -84,7 +84,7 @@ ctf_label_iter (ctf_dict_t *fp, ctf_label_f *func, void *arg)
 	  ctf_err_warn (fp, 0, ECTF_CORRUPT,
 			"failed to decode label %u with type %u",
 			ctlp->ctl_label, ctlp->ctl_type);
-	  return (ctf_set_errno (fp, ECTF_CORRUPT));
+	  return (ctf_set_int_errno (fp, ECTF_CORRUPT));
 	}
 
       linfo.ctb_type = ctlp->ctl_type;
@@ -134,7 +134,7 @@ ctf_label_info (ctf_dict_t *fp, const char *lname, ctf_lblinfo_t *linfo)
     return rc;
 
   if (rc != 1)
-    return (ctf_set_errno (fp, ECTF_NOLABEL));
+    return (ctf_set_int_errno (fp, ECTF_NOLABEL));
 
   return 0;
 }
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 9babec2aa37..8f6f77e547e 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -142,7 +142,7 @@ ctf_link_add_ctf_internal (ctf_dict_t *fp, ctf_archive_t *ctf,
  oom1:
   free (filename);
  oom:
-  return ctf_set_errno (fp, ENOMEM);
+  return ctf_set_int_errno (fp, ENOMEM);
 }
 
 /* Add a file, memory buffer, or unopened file (by name) to a link.
@@ -173,12 +173,12 @@ ctf_link_add (ctf_dict_t *fp, ctf_archive_t *ctf, const char *name,
 	      void *buf _libctf_unused_, size_t n _libctf_unused_)
 {
   if (buf)
-    return (ctf_set_errno (fp, ECTF_NOTYET));
+    return (ctf_set_int_errno (fp, ECTF_NOTYET));
 
   if (!((ctf && name && !buf)
 	|| (name && !buf && !ctf)
 	|| (buf && name && !ctf)))
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_int_errno (fp, EINVAL));
 
   /* We can only lazily open files if libctf.so is in use rather than
      libctf-nobfd.so.  This is a little tricky: in shared libraries, we can use
@@ -187,21 +187,21 @@ ctf_link_add (ctf_dict_t *fp, ctf_archive_t *ctf, const char *name,
 
 #if defined (PIC)
   if (!buf && !ctf && name && !ctf_open)
-    return (ctf_set_errno (fp, ECTF_NEEDSBFD));
+    return (ctf_set_int_errno (fp, ECTF_NEEDSBFD));
 #elif NOBFD
   if (!buf && !ctf && name)
-    return (ctf_set_errno (fp, ECTF_NEEDSBFD));
+    return (ctf_set_int_errno (fp, ECTF_NEEDSBFD));
 #endif
 
   if (fp->ctf_link_outputs)
-    return (ctf_set_errno (fp, ECTF_LINKADDEDLATE));
+    return (ctf_set_int_errno (fp, ECTF_LINKADDEDLATE));
   if (fp->ctf_link_inputs == NULL)
     fp->ctf_link_inputs = ctf_dynhash_create (ctf_hash_string,
 					      ctf_hash_eq_string, free,
 					      ctf_link_input_close);
 
   if (fp->ctf_link_inputs == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
 
   return ctf_link_add_ctf_internal (fp, ctf, NULL, name);
 }
@@ -243,7 +243,7 @@ ctf_link_lazy_open (ctf_dict_t *fp, ctf_link_input_t *input)
 #else
   ctf_err_warn (fp, 0, ECTF_NEEDSBFD, _("cannot open %s lazily"),
 		input->clin_filename);
-  ctf_set_errno (fp, ECTF_NEEDSBFD);
+  ctf_set_int_errno (fp, ECTF_NEEDSBFD);
   return -1;
 #endif
 
@@ -257,7 +257,7 @@ ctf_link_lazy_open (ctf_dict_t *fp, ctf_link_input_t *input)
 
       ctf_err_warn (fp, 0, err, _("opening CTF %s failed"),
 		    input->clin_filename);
-      ctf_set_errno (fp, err);
+      ctf_set_int_errno (fp, err);
       return -1;
     }
 
@@ -334,7 +334,7 @@ ctf_create_per_cu (ctf_dict_t *fp, ctf_dict_t *input, const char *cu_name)
 	{
 	  ctf_err_warn (fp, 0, err, _("cannot create per-CU CTF archive for "
 				      "input CU %s"), cu_name);
-	  ctf_set_errno (fp, err);
+	  ctf_set_type_errno (fp, err);
 	  return NULL;
 	}
 
@@ -357,7 +357,7 @@ ctf_create_per_cu (ctf_dict_t *fp, ctf_dict_t *input, const char *cu_name)
  oom:
   free (dynname);
   ctf_dict_close (cu_fp);
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_type_errno (fp, ENOMEM);
   return NULL;
 }
 
@@ -378,7 +378,7 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to)
 
   /* Mappings cannot be set up if per-CU output dicts already exist.  */
   if (fp->ctf_link_outputs && ctf_dynhash_elements (fp->ctf_link_outputs) != 0)
-      return (ctf_set_errno (fp, ECTF_LINKADDEDLATE));
+      return (ctf_set_int_errno (fp, ECTF_LINKADDEDLATE));
 
   if (fp->ctf_link_in_cu_mapping == NULL)
     fp->ctf_link_in_cu_mapping = ctf_dynhash_create (ctf_hash_string,
@@ -407,7 +407,7 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to)
 
   if ((err = ctf_dynhash_insert (fp->ctf_link_in_cu_mapping, f, t)) < 0)
     {
-      ctf_set_errno (fp, err);
+      ctf_set_int_errno (fp, err);
       goto oom_noerrno;
     }
 
@@ -426,7 +426,7 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to)
 				     t, one_out)) < 0)
 	{
 	  ctf_dynhash_destroy (one_out);
-	  ctf_set_errno (fp, err);
+	  ctf_set_int_errno (fp, err);
 	  goto oom_noerrno;
 	}
     }
@@ -438,14 +438,14 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char *from, const char *to)
 
   if (ctf_dynhash_insert (one_out, f, NULL) < 0)
     {
-      ctf_set_errno (fp, err);
+      ctf_set_int_errno (fp, err);
       goto oom_noerrno;
     }
 
   return 0;
 
  oom:
-  ctf_set_errno (fp, errno);
+  ctf_set_int_errno (fp, errno);
  oom_noerrno:
   free (f);
   free (t);
@@ -582,7 +582,7 @@ ctf_link_one_variable (ctf_dict_t *fp, ctf_dict_t *in_fp, const char *name,
 
   if (check_variable (name, per_cu_out_fp, dst_type, &dvd))
     if (ctf_add_variable (per_cu_out_fp, name, dst_type) < 0)
-      return (ctf_set_errno (fp, ctf_errno (per_cu_out_fp)));
+      return (ctf_set_int_errno (fp, ctf_errno (per_cu_out_fp)));
   return 0;
 }
 
@@ -680,7 +680,7 @@ ctf_link_deduplicating_count_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
     {
       ctf_err_warn (fp, 0, err, _("iteration error counting deduplicating "
 				  "CTF link inputs"));
-      ctf_set_errno (fp, err);
+      ctf_set_int_errno (fp, err);
       return -1;
     }
 
@@ -783,7 +783,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
 	  if (err != ECTF_NOMEMBNAM)
 	    {
 	      ctf_next_destroy (i);
-	      ctf_set_errno (fp, err);
+	      ctf_set_type_errno (fp, err);
 	      goto err;
 	    }
 	}
@@ -835,7 +835,7 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
   err = ENOMEM;
 
  iterr:
-  ctf_set_errno (fp, err);
+  ctf_set_type_errno (fp, err);
 
  err:
   free (dedup_inputs);
@@ -877,7 +877,7 @@ ctf_link_deduplicating_close_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
 	{
 	  ctf_err_warn (fp, 0, err, _("iteration error in deduplicating link "
 				      "input freeing"));
-	  ctf_set_errno (fp, err);
+	  ctf_set_int_errno (fp, err);
 	}
     }
   else
@@ -915,7 +915,7 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	return ctf_set_int_errno (fp, ctf_errno (inputs[i]));
 
       /* Next the symbols.  We integrate data symbols even though the compiler
 	 is currently doing the same, to allow the compiler to stop in
@@ -930,7 +930,7 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	return ctf_set_int_errno (fp, ctf_errno (inputs[i]));
 
       /* Finally the function symbols.  */
 
@@ -943,7 +943,7 @@ ctf_link_deduplicating_variables (ctf_dict_t *fp, ctf_dict_t **inputs,
 	    }
 	}
       if (ctf_errno (inputs[i]) != ECTF_NEXT_END)
-	return ctf_set_errno (fp, ctf_errno (inputs[i]));
+	return ctf_set_int_errno (fp, ctf_errno (inputs[i]));
     }
   return 0;
 }
@@ -1070,12 +1070,12 @@ ctf_link_deduplicating_one_symtypetab (ctf_dict_t *fp, ctf_dict_t *input,
 			_("symbol %s in input file %s found conflicting "
 			  "even when trying in per-CU dict."), name,
 			ctf_unnamed_cuname (input));
-	  return (ctf_set_errno (fp, ECTF_DUPLICATE));
+	  return (ctf_set_int_errno (fp, ECTF_DUPLICATE));
 	}
     }
   if (ctf_errno (input) != ECTF_NEXT_END)
     {
-      ctf_set_errno (fp, ctf_errno (input));
+      ctf_set_int_errno (fp, ctf_errno (input));
       ctf_err_warn (fp, 0, ctf_errno (input),
 		    functions ? _("iterating over function symbols") :
 		    _("iterating over data symbols"));
@@ -1147,7 +1147,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 	{
 	  ctf_err_warn (fp, 0, EFBIG, _("too many inputs in deduplicating "
 					"link: %li"), (long int) ninputs);
-	  ctf_set_errno (fp, EFBIG);
+	  ctf_set_int_errno (fp, EFBIG);
 	  goto err_open_inputs;
 	}
 
@@ -1172,7 +1172,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 	      ctf_err_warn (fp, 0, err, _("cannot open archive %s in "
 					  "CU-mapped CTF link"),
 			    only_input->clin_filename);
-	      ctf_set_errno (fp, err);
+	      ctf_set_int_errno (fp, err);
 	      goto err_open_inputs;
 	    }
 	  ctf_next_destroy (ai);
@@ -1218,7 +1218,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 	  ctf_err_warn (fp, 0, err, _("cannot create per-CU CTF archive "
 				      "for %s"),
 			out_name);
-	  ctf_set_errno (fp, err);
+	  ctf_set_int_errno (fp, err);
 	  goto err_inputs;
 	}
 
@@ -1233,7 +1233,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
 
       if (ctf_dedup (out, inputs, ninputs, parents, 1) < 0)
 	{
-	  ctf_set_errno (fp, ctf_errno (out));
+	  ctf_set_int_errno (fp, ctf_errno (out));
 	  ctf_err_warn (fp, 0, 0, _("CU-mapped deduplication failed for %s"),
 			out_name);
 	  goto err_inputs;
@@ -1242,7 +1242,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
       if ((outputs = ctf_dedup_emit (out, inputs, ninputs, parents,
 				     &noutputs, 1)) == NULL)
 	{
-	  ctf_set_errno (fp, ctf_errno (out));
+	  ctf_set_int_errno (fp, ctf_errno (out));
 	  ctf_err_warn (fp, 0, 0, _("CU-mapped deduplicating link type emission "
 				     "failed for %s"), out_name);
 	  goto err_inputs;
@@ -1258,7 +1258,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
       if (!(fp->ctf_link_flags & CTF_LINK_OMIT_VARIABLES_SECTION)
 	  && ctf_link_deduplicating_variables (out, inputs, ninputs, 1) < 0)
 	{
-	  ctf_set_errno (fp, ctf_errno (out));
+	  ctf_set_int_errno (fp, ctf_errno (out));
 	  ctf_err_warn (fp, 0, 0, _("CU-mapped deduplicating link variable "
 				    "emission failed for %s"), out_name);
 	  goto err_inputs_outputs;
@@ -1291,7 +1291,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
       if ((in_arc = ctf_new_archive_internal (0, 0, NULL, outputs[0], NULL,
 					      NULL, &err)) == NULL)
 	{
-	  ctf_set_errno (fp, err);
+	  ctf_set_int_errno (fp, err);
 	  goto err_outputs;
 	}
 
@@ -1330,7 +1330,7 @@ ctf_link_deduplicating_per_cu (ctf_dict_t *fp)
     {
       ctf_err_warn (fp, 0, err, _("iteration error in CU-mapped deduplicating "
 				  "link"));
-      return ctf_set_errno (fp, err);
+      return ctf_set_int_errno (fp, err);
     }
 
   return 0;
@@ -1355,7 +1355,7 @@ ctf_link_empty_outputs (ctf_dict_t *fp)
     {
       fp->ctf_flags &= ~LCTF_LINKING;
       ctf_err_warn (fp, 1, err, _("iteration error removing old outputs"));
-      ctf_set_errno (fp, err);
+      ctf_set_int_errno (fp, err);
       return -1;
     }
   return 0;
@@ -1433,7 +1433,7 @@ ctf_link_deduplicating (ctf_dict_t *fp)
       continue;
 
     oom_one_output:
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_type_errno (fp, ENOMEM);
       ctf_err_warn (fp, 0, 0, _("out of memory allocating link outputs"));
       free (dynname);
 
@@ -1465,7 +1465,7 @@ ctf_link_deduplicating (ctf_dict_t *fp)
     return;					/* errno is set for us.  */
 
   ninputs = 0;					/* Prevent double-close.  */
-  ctf_set_errno (fp, 0);
+  ctf_set_type_errno (fp, 0);
 
   /* Fall through.  */
 
@@ -1503,7 +1503,7 @@ ctf_link (ctf_dict_t *fp, int flags)
 					       ctf_dict_close);
 
   if (fp->ctf_link_outputs == NULL)
-    return ctf_set_errno (fp, ENOMEM);
+    return ctf_set_int_errno (fp, ENOMEM);
 
   fp->ctf_flags |= LCTF_LINKING;
   ctf_link_deduplicating (fp);
@@ -1536,7 +1536,7 @@ ctf_link (ctf_dict_t *fp, int flags)
 	{
 	  fp->ctf_flags &= ~LCTF_LINKING;
 	  ctf_err_warn (fp, 1, err, _("iteration error creating empty CUs"));
-	  ctf_set_errno (fp, err);
+	  ctf_set_int_errno (fp, err);
 	  return -1;
 	}
     }
@@ -1593,7 +1593,7 @@ ctf_link_add_strtab (ctf_dict_t *fp, ctf_link_strtab_string_f *add_string,
     }
 
   if (err)
-    ctf_set_errno (fp, err);
+    ctf_set_int_errno (fp, err);
 
   return -err;
 }
@@ -1635,7 +1635,7 @@ ctf_link_add_linker_symbol (ctf_dict_t *fp, ctf_link_sym_t *sym)
  oom:
   ctf_dynhash_destroy (fp->ctf_dynsyms);
   fp->ctf_dynsyms = NULL;
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_int_errno (fp, ENOMEM);
   return -ENOMEM;
 }
 
@@ -1658,7 +1658,7 @@ ctf_link_shuffle_syms (ctf_dict_t *fp)
 					    NULL, free);
       if (!fp->ctf_dynsyms)
 	{
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_int_errno (fp, ENOMEM);
 	  return -ENOMEM;
 	}
     }
@@ -1758,7 +1758,7 @@ ctf_link_shuffle_syms (ctf_dict_t *fp)
   free (fp->ctf_dynsymidx);
   fp->ctf_dynsymidx = NULL;
   fp->ctf_dynsymmax = 0;
-  ctf_set_errno (fp, err);
+  ctf_set_int_errno (fp, err);
   return -err;
 }
 
@@ -1785,14 +1785,14 @@ ctf_accumulate_archive_names (void *key, void *value, void *arg_)
   if ((names = realloc (arg->names, sizeof (char *) * ++(arg->i))) == NULL)
     {
       (arg->i)--;
-      ctf_set_errno (arg->fp, ENOMEM);
+      ctf_set_type_errno (arg->fp, ENOMEM);
       return;
     }
 
   if ((files = realloc (arg->files, sizeof (ctf_dict_t *) * arg->i)) == NULL)
     {
       (arg->i)--;
-      ctf_set_errno (arg->fp, ENOMEM);
+      ctf_set_type_errno (arg->fp, ENOMEM);
       return;
     }
 
@@ -1815,7 +1815,7 @@ ctf_accumulate_archive_names (void *key, void *value, void *arg_)
 				  sizeof (char *) * ++(arg->ndynames))) == NULL)
 	    {
 	      (arg->ndynames)--;
-	      ctf_set_errno (arg->fp, ENOMEM);
+	      ctf_set_type_errno (arg->fp, ENOMEM);
 	      return;
 	    }
 	    arg->dynames = dynames;
@@ -1986,7 +1986,7 @@ ctf_link_write (ctf_dict_t *fp, size_t *size, size_t threshold)
 			       threshold)) < 0)
     {
       errloc = "archive writing";
-      ctf_set_errno (fp, err);
+      ctf_set_type_errno (fp, err);
       goto err;
     }
 
@@ -2036,7 +2036,7 @@ ctf_link_write (ctf_dict_t *fp, size_t *size, size_t threshold)
   return buf;
 
  err_no:
-  ctf_set_errno (fp, errno);
+  ctf_set_type_errno (fp, errno);
 
   /* Turn off the is-linking flag on all the dicts in this link.  */
   for (i = 0; i < arg.i; i++)
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index c65849118cb..6ff9138de63 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -30,7 +30,7 @@ grow_pptrtab (ctf_dict_t *fp, size_t new_len)
 
   if ((new_pptrtab = realloc (fp->ctf_pptrtab, sizeof (uint32_t)
 			      * new_len)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
 
   fp->ctf_pptrtab = new_pptrtab;
 
@@ -143,7 +143,7 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
   ctf_id_t ntype, ptype;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_type_errno (fp, EINVAL));
 
   for (p = name, end = name + strlen (name); *p != '\0'; p = q)
     {
@@ -274,7 +274,7 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
 		  fp->ctf_tmp_typeslice = xstrndup (p, (size_t) (q - p));
 		  if (fp->ctf_tmp_typeslice == NULL)
 		    {
-		      ctf_set_errno (fp, ENOMEM);
+		      ctf_set_type_errno (fp, ENOMEM);
 		      return CTF_ERR;
 		    }
 		}
@@ -292,12 +292,12 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
     }
 
   if (*p != '\0' || type == 0)
-    return (ctf_set_errno (fp, ECTF_SYNTAX));
+    return (ctf_set_type_errno (fp, ECTF_SYNTAX));
 
   return type;
 
  notype:
-  ctf_set_errno (fp, ECTF_NOTYPE);
+  ctf_set_type_errno (fp, ECTF_NOTYPE);
   if (fp->ctf_parent != NULL)
     {
       /* Need to look up in the parent, from the child's perspective.
@@ -312,7 +312,7 @@ ctf_lookup_by_name_internal (ctf_dict_t *fp, ctf_dict_t *child,
       if ((ptype = ctf_lookup_by_name_internal (fp->ctf_parent, fp,
 						name)) != CTF_ERR)
 	return ptype;
-      return (ctf_set_errno (fp, ctf_errno (fp->ctf_parent)));
+      return (ctf_set_type_errno (fp, ctf_errno (fp->ctf_parent)));
     }
 
   return CTF_ERR;
@@ -336,7 +336,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
 
   if ((fp = ctf_get_dict (fp, type)) == NULL)
     {
-      (void) ctf_set_errno (*fpp, ECTF_NOPARENT);
+      (void) ctf_set_type_errno (*fpp, ECTF_NOPARENT);
       return NULL;
     }
 
@@ -351,7 +351,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
 	  *fpp = fp;
 	  return &dtd->dtd_data;
 	}
-      (void) ctf_set_errno (*fpp, ECTF_BADID);
+      (void) ctf_set_type_errno (*fpp, ECTF_BADID);
       return NULL;
     }
 
@@ -364,7 +364,7 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type)
       return (LCTF_INDEX_TO_TYPEPTR (fp, idx));
     }
 
-  (void) ctf_set_errno (*fpp, ECTF_BADID);
+  (void) ctf_set_type_errno (*fpp, ECTF_BADID);
   return NULL;
 }
 
@@ -407,10 +407,10 @@ ctf_lookup_variable (ctf_dict_t *fp, const char *name)
 
           if ((ptype = ctf_lookup_variable (fp->ctf_parent, name)) != CTF_ERR)
             return ptype;
-          return (ctf_set_errno (fp, ctf_errno (fp->ctf_parent)));
+          return (ctf_set_type_errno (fp, ctf_errno (fp->ctf_parent)));
         }
 
-      return (ctf_set_errno (fp, ECTF_NOTYPEDAT));
+      return (ctf_set_type_errno (fp, ECTF_NOTYPEDAT));
     }
 
   return ent->ctv_type;
@@ -447,7 +447,7 @@ ctf_symidx_sort (ctf_dict_t *fp, uint32_t *idx, size_t *nidx,
 
   if ((sorted = malloc (len)) == NULL)
     {
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_type_errno (fp, ENOMEM);
       return NULL;
     }
 
@@ -512,7 +512,7 @@ ctf_lookup_symbol_name (ctf_dict_t *fp, unsigned long symidx)
       }
       break;
     default:
-      ctf_set_errno (fp, ECTF_SYMTAB);
+      ctf_set_type_errno (fp, ECTF_SYMTAB);
       return _CTF_NULLSTR;
     }
 
@@ -526,12 +526,12 @@ ctf_lookup_symbol_name (ctf_dict_t *fp, unsigned long symidx)
       const char *ret;
       ret = ctf_lookup_symbol_name (fp->ctf_parent, symidx);
       if (ret == NULL)
-	ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
+	ctf_set_type_errno (fp, ctf_errno (fp->ctf_parent));
       return ret;
     }
   else
     {
-      ctf_set_errno (fp, err);
+      ctf_set_type_errno (fp, err);
       return _CTF_NULLSTR;
     }
 }
@@ -621,7 +621,7 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
 	  }
 	  break;
 	default:
-	  ctf_set_errno (fp, ECTF_SYMTAB);
+	  ctf_set_type_errno (fp, ECTF_SYMTAB);
 	  return (unsigned long) -1;
 	}
     }
@@ -639,16 +639,16 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname)
           != (unsigned long) -1)
         return psym;
 
-      ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
+      ctf_set_type_errno (fp, ctf_errno (fp->ctf_parent));
       return (unsigned long) -1;
     }
   else
     {
-      ctf_set_errno (fp, err);
+      ctf_set_type_errno (fp, err);
       return (unsigned long) -1;
     }
 oom:
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_type_errno (fp, ENOMEM);
   ctf_err_warn (fp, 0, ENOMEM, _("cannot allocate memory for symbol "
 				 "lookup hashtab"));
   return (unsigned long) -1;
@@ -673,7 +673,7 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	return ctf_set_type_errno (fp, ENOMEM);
 
       i->cu.ctn_fp = fp;
       i->ctn_iter_fun = (void (*) (void)) ctf_symbol_next;
@@ -682,10 +682,10 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
     }
 
   if ((void (*) (void)) ctf_symbol_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFUN));
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFP));
 
   /* We intentionally use raw access, not ctf_lookup_by_symbol, to avoid
      incurring additional sorting cost for unsorted symtypetabs coming from the
@@ -701,7 +701,7 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
       if (!dynh)
 	{
 	  ctf_next_destroy (i);
-	  return (ctf_set_errno (fp, ECTF_NEXT_END));
+	  return (ctf_set_type_errno (fp, ECTF_NEXT_END));
 	}
 
       err = ctf_dynhash_next (dynh, &i->ctn_next, &dyn_name, &dyn_value);
@@ -710,7 +710,7 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
 	{
 	  ctf_next_destroy (i);
 	  *it = NULL;
-	  return ctf_set_errno (fp, err);
+	  return ctf_set_type_errno (fp, err);
 	}
 
       *name = dyn_name;
@@ -786,7 +786,7 @@ ctf_symbol_next (ctf_dict_t *fp, ctf_next_t **it, const char **name,
  end:
   ctf_next_destroy (i);
   *it = NULL;
-  return (ctf_set_errno (fp, ECTF_NEXT_END));
+  return (ctf_set_type_errno (fp, ECTF_NEXT_END));
 }
 
 /* A bsearch function for function and object index names.  */
@@ -878,7 +878,7 @@ ctf_try_lookup_indexed (ctf_dict_t *fp, unsigned long symidx,
 
   /* Should be impossible, but be paranoid.  */
   if ((idx - sxlate) > (ptrdiff_t) nidx)
-    return (ctf_set_errno (fp, ECTF_CORRUPT));
+    return (ctf_set_type_errno (fp, ECTF_CORRUPT));
 
   ctf_dprintf ("Symbol %lx (%s) is of type %x\n", symidx, symname,
 	       symtypetab[*idx]);
@@ -1010,11 +1010,11 @@ ctf_lookup_by_sym_or_name (ctf_dict_t *fp, unsigned long symidx,
       ctf_id_t ret = ctf_lookup_by_sym_or_name (fp->ctf_parent, symidx,
 						symname);
       if (ret == CTF_ERR)
-	ctf_set_errno (fp, ctf_errno (fp->ctf_parent));
+	ctf_set_type_errno (fp, ctf_errno (fp->ctf_parent));
       return ret;
     }
   else
-    return (ctf_set_errno (fp, err));
+    return (ctf_set_type_errno (fp, err));
 }
 
 /* Given a symbol table index, return the type of the function or data object
@@ -1046,7 +1046,7 @@ ctf_func_info (ctf_dict_t *fp, unsigned long symidx, ctf_funcinfo_t *fip)
     return -1;					/* errno is set for us.  */
 
   if (ctf_type_kind (fp, type) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    return (ctf_set_int_errno (fp, ECTF_NOTFUNC));
 
   return ctf_func_type_info (fp, type, fip);
 }
@@ -1064,7 +1064,7 @@ ctf_func_args (ctf_dict_t *fp, unsigned long symidx, uint32_t argc,
     return -1;					/* errno is set for us.  */
 
   if (ctf_type_kind (fp, type) != CTF_K_FUNCTION)
-    return (ctf_set_errno (fp, ECTF_NOTFUNC));
+    return (ctf_set_int_errno (fp, ECTF_NOTFUNC));
 
   return ctf_func_type_args (fp, type, argc, argv);
 }
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 35f635b6559..fa020a10424 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -159,7 +159,7 @@ get_vbytes_common (ctf_dict_t *fp, unsigned short kind,
     case CTF_K_RESTRICT:
       return 0;
     default:
-      ctf_set_errno (fp, ECTF_CORRUPT);
+      ctf_set_int_errno (fp, ECTF_CORRUPT);
       ctf_err_warn (fp, 0, 0, _("detected invalid CTF kind: %x"), kind);
       return -1;
     }
@@ -1935,7 +1935,7 @@ ctf_parent_name_set (ctf_dict_t *fp, const char *name)
     free (fp->ctf_dynparname);
 
   if ((fp->ctf_dynparname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
   fp->ctf_parname = fp->ctf_dynparname;
   return 0;
 }
@@ -1956,7 +1956,7 @@ ctf_cuname_set (ctf_dict_t *fp, const char *name)
     free (fp->ctf_dyncuname);
 
   if ((fp->ctf_dyncuname = strdup (name)) == NULL)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
   fp->ctf_cuname = fp->ctf_dyncuname;
   return 0;
 }
@@ -1969,10 +1969,10 @@ int
 ctf_import (ctf_dict_t *fp, ctf_dict_t *pfp)
 {
   if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0))
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_int_errno (fp, EINVAL));
 
   if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel)
-    return (ctf_set_errno (fp, ECTF_DMODEL));
+    return (ctf_set_int_errno (fp, ECTF_DMODEL));
 
   if (fp->ctf_parent && !fp->ctf_parent_unreffed)
     ctf_dict_close (fp->ctf_parent);
@@ -2008,10 +2008,10 @@ int
 ctf_import_unref (ctf_dict_t *fp, ctf_dict_t *pfp)
 {
   if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0))
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_int_errno (fp, EINVAL));
 
   if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel)
-    return (ctf_set_errno (fp, ECTF_DMODEL));
+    return (ctf_set_int_errno (fp, ECTF_DMODEL));
 
   if (fp->ctf_parent && !fp->ctf_parent_unreffed)
     ctf_dict_close (fp->ctf_parent);
@@ -2052,7 +2052,7 @@ ctf_setmodel (ctf_dict_t *fp, int model)
 	}
     }
 
-  return (ctf_set_errno (fp, EINVAL));
+  return (ctf_set_int_errno (fp, EINVAL));
 }
 
 /* Return the data model constant for the CTF dict.  */
diff --git a/libctf/ctf-serialize.c b/libctf/ctf-serialize.c
index ba830a2b095..4f410ebbeab 100644
--- a/libctf/ctf-serialize.c
+++ b/libctf/ctf-serialize.c
@@ -123,7 +123,7 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 
       if ((linker_known = ctf_dynhash_create (ctf_hash_string, ctf_hash_eq_string,
 					      NULL, NULL)) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_int_errno (fp, ENOMEM));
 
       while ((err = ctf_dynhash_cnext (symfp->ctf_dynsyms, &i,
 				       &name, &ctf_sym)) == 0)
@@ -147,7 +147,7 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  if (ctf_dynhash_cinsert (linker_known, name, ctf_sym) < 0)
 	    {
 	      ctf_dynhash_destroy (linker_known);
-	      return (ctf_set_errno (fp, ENOMEM));
+	      return (ctf_set_int_errno (fp, ENOMEM));
 	    }
 	}
       if (err != ECTF_NEXT_END)
@@ -155,7 +155,7 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  ctf_err_warn (fp, 0, err, _("iterating over linker-known symbols during "
 				  "serialization"));
 	  ctf_dynhash_destroy (linker_known);
-	  return (ctf_set_errno (fp, err));
+	  return (ctf_set_int_errno (fp, err));
 	}
     }
 
@@ -219,7 +219,7 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
       ctf_err_warn (fp, 0, err, _("iterating over CTF symtypetab during "
 				  "serialization"));
       ctf_dynhash_destroy (linker_known);
-      return (ctf_set_errno (fp, err));
+      return (ctf_set_int_errno (fp, err));
     }
 
   if (!(flags & CTF_SYMTYPETAB_FORCE_INDEXED))
@@ -236,7 +236,7 @@ symtypetab_density (ctf_dict_t *fp, ctf_dict_t *symfp, ctf_dynhash_t *symhash,
 	  ctf_err_warn (fp, 0, err, _("iterating over linker-known symbols "
 				      "during CTF serialization"));
 	  ctf_dynhash_destroy (linker_known);
-	  return (ctf_set_errno (fp, err));
+	  return (ctf_set_int_errno (fp, err));
 	}
     }
 
@@ -709,7 +709,7 @@ ctf_emit_symtypetab_sects (ctf_dict_t *fp, emit_symtypetab_state_t *s,
   return 0;
 
  oom:
-  ctf_set_errno (fp, EAGAIN);
+  ctf_set_int_errno (fp, EAGAIN);
   goto err;
 symerr:
   ctf_err_warn (fp, 0, err, _("error serializing symtypetabs"));
@@ -970,7 +970,7 @@ ctf_serialize (ctf_dict_t *fp)
   memset (&symstate, 0, sizeof (emit_symtypetab_state_t));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
-    return (ctf_set_errno (fp, ECTF_RDONLY));
+    return (ctf_set_int_errno (fp, ECTF_RDONLY));
 
   /* Update required?  */
   if (!(fp->ctf_flags & LCTF_DIRTY))
@@ -1026,7 +1026,7 @@ ctf_serialize (ctf_dict_t *fp)
   buf_size = sizeof (ctf_header_t) + hdr.cth_stroff + hdr.cth_strlen;
 
   if ((buf = malloc (buf_size)) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_int_errno (fp, EAGAIN));
 
   memcpy (buf, &hdr, sizeof (ctf_header_t));
   t = (unsigned char *) buf + sizeof (ctf_header_t) + hdr.cth_objtoff;
@@ -1106,7 +1106,7 @@ ctf_serialize (ctf_dict_t *fp)
 				       1, &err)) == NULL)
     {
       free (buf);
-      return (ctf_set_errno (fp, err));
+      return (ctf_set_int_errno (fp, err));
     }
 
   (void) ctf_setmodel (nfp, ctf_getmodel (fp));
@@ -1221,7 +1221,7 @@ ctf_serialize (ctf_dict_t *fp)
 
 oom:
   free (buf);
-  return (ctf_set_errno (fp, EAGAIN));
+  return (ctf_set_int_errno (fp, EAGAIN));
 err:
   free (buf);
   return -1;					/* errno is set for us.  */
@@ -1248,7 +1248,7 @@ ctf_gzwrite (ctf_dict_t *fp, gzFile fd)
   while (resid != 0)
     {
       if ((len = gzwrite (fd, buf, resid)) <= 0)
-	return (ctf_set_errno (fp, errno));
+	return (ctf_set_int_errno (fp, errno));
       resid -= len;
       buf += len;
     }
@@ -1258,7 +1258,7 @@ ctf_gzwrite (ctf_dict_t *fp, gzFile fd)
   while (resid != 0)
     {
       if ((len = gzwrite (fd, buf, resid)) <= 0)
-	return (ctf_set_errno (fp, errno));
+	return (ctf_set_int_errno (fp, errno));
       resid -= len;
       buf += len;
     }
@@ -1294,7 +1294,7 @@ ctf_write_mem (ctf_dict_t *fp, size_t *size, size_t threshold)
   if ((buf = malloc (compress_len
 		     + sizeof (struct ctf_header))) == NULL)
     {
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_type_errno (fp, ENOMEM);
       ctf_err_warn (fp, 0, 0, _("ctf_write_mem: cannot allocate %li bytes"),
 		    (unsigned long) (compress_len + sizeof (struct ctf_header)));
       return NULL;
@@ -1317,7 +1317,7 @@ ctf_write_mem (ctf_dict_t *fp, size_t *size, size_t threshold)
     {
       if ((flipped = malloc (fp->ctf_size)) == NULL)
 	{
-	  ctf_set_errno (fp, ENOMEM);
+	  ctf_set_type_errno (fp, ENOMEM);
 	  ctf_err_warn (fp, 0, 0, _("ctf_write_mem: cannot allocate %li bytes"),
 			(unsigned long) (fp->ctf_size + sizeof (struct ctf_header)));
 	  return NULL;
@@ -1343,7 +1343,7 @@ ctf_write_mem (ctf_dict_t *fp, size_t *size, size_t threshold)
       if ((rc = compress (bp, (uLongf *) &compress_len,
 			  src, fp->ctf_size)) != Z_OK)
 	{
-	  ctf_set_errno (fp, ECTF_COMPRESS);
+	  ctf_set_type_errno (fp, ECTF_COMPRESS);
 	  ctf_err_warn (fp, 0, 0, _("zlib deflate err: %s"), zError (rc));
 	  free (buf);
 	  return NULL;
@@ -1378,7 +1378,7 @@ ctf_compress_write (ctf_dict_t *fp, int fd)
     {
       if ((len = write (fd, bp, buf_len)) < 0)
 	{
-	  err = ctf_set_errno (fp, errno);
+	  err = ctf_set_int_errno (fp, errno);
 	  ctf_err_warn (fp, 0, 0, _("ctf_compress_write: error writing"));
 	  goto ret;
 	}
@@ -1412,7 +1412,7 @@ ctf_write (ctf_dict_t *fp, int fd)
     {
       if ((len = write (fd, bp, buf_len)) < 0)
 	{
-	  err = ctf_set_errno (fp, errno);
+	  err = ctf_set_int_errno (fp, errno);
 	  ctf_err_warn (fp, 0, 0, _("ctf_compress_write: error writing"));
 	  goto ret;
 	}
diff --git a/libctf/ctf-string.c b/libctf/ctf-string.c
index 911e94700f1..06de3fb4732 100644
--- a/libctf/ctf-string.c
+++ b/libctf/ctf-string.c
@@ -229,7 +229,7 @@ ctf_str_add_ref_internal (ctf_dict_t *fp, const char *str,
   free (atom);
   free (aref);
   free (newstr);
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_type_errno (fp, ENOMEM);
   return NULL;
 }
 
@@ -298,7 +298,7 @@ ctf_str_move_pending (ctf_dict_t *fp, uint32_t *new_ref, ptrdiff_t bytes)
     return 0;
 
   if (ctf_dynset_insert (fp->ctf_str_pending_ref, (void *) new_ref) < 0)
-    return (ctf_set_errno (fp, ENOMEM));
+    return (ctf_set_int_errno (fp, ENOMEM));
 
   ctf_dynset_remove (fp->ctf_str_pending_ref,
 		     (void *) ((signed char *) new_ref - bytes));
@@ -327,7 +327,7 @@ ctf_str_add_external (ctf_dict_t *fp, const char *str, uint32_t offset)
 						 NULL, NULL);
   if (!fp->ctf_syn_ext_strtab)
     {
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_int_errno (fp, ENOMEM);
       return 0;
     }
 
@@ -338,7 +338,7 @@ ctf_str_add_external (ctf_dict_t *fp, const char *str, uint32_t offset)
     {
       /* No need to bother freeing the syn_ext_strtab: it will get freed at
 	 ctf_str_write_strtab time if unreferenced.  */
-      ctf_set_errno (fp, ENOMEM);
+      ctf_set_int_errno (fp, ENOMEM);
       return 0;
     }
 
diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c
index f4118328a83..55c2ed3bf6d 100644
--- a/libctf/ctf-subr.c
+++ b/libctf/ctf-subr.c
@@ -288,7 +288,7 @@ ctf_errwarning_next (ctf_dict_t *fp, ctf_next_t **it, int *is_warning,
 	  if (errp)
 	    *errp = ENOMEM;
 	  else if (fp)
-	    ctf_set_errno (fp, ENOMEM);
+	    ctf_set_type_errno (fp, ENOMEM);
 	  return NULL;
 	}
 
@@ -302,7 +302,7 @@ ctf_errwarning_next (ctf_dict_t *fp, ctf_next_t **it, int *is_warning,
       if (errp)
 	*errp = ECTF_NEXT_WRONGFUN;
       else if (fp)
-	ctf_set_errno (fp, ECTF_NEXT_WRONGFUN);
+	ctf_set_type_errno (fp, ECTF_NEXT_WRONGFUN);
       return NULL;
     }
 
@@ -311,7 +311,7 @@ ctf_errwarning_next (ctf_dict_t *fp, ctf_next_t **it, int *is_warning,
       if (errp)
 	*errp = ECTF_NEXT_WRONGFP;
       else if (fp)
-	ctf_set_errno (fp, ECTF_NEXT_WRONGFP);
+	ctf_set_type_errno (fp, ECTF_NEXT_WRONGFP);
       return NULL;
     }
 
@@ -324,7 +324,7 @@ ctf_errwarning_next (ctf_dict_t *fp, ctf_next_t **it, int *is_warning,
       if (errp)
 	*errp = ECTF_NEXT_END;
       else if (fp)
-	ctf_set_errno (fp, ECTF_NEXT_END);
+	ctf_set_type_errno (fp, ECTF_NEXT_END);
       return NULL;
     }
 
@@ -342,5 +342,5 @@ ctf_assert_fail_internal (ctf_dict_t *fp, const char *file, size_t line,
 {
   ctf_err_warn (fp, 0, ECTF_INTERNAL, _("%s: %lu: libctf assertion failed: %s"),
 		file, (long unsigned int) line, exprstr);
-  ctf_set_errno (fp, ECTF_INTERNAL);
+  ctf_set_type_errno (fp, ECTF_INTERNAL);
 }
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index c20ff825d9a..85f6a7c529f 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -119,7 +119,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 	return -1;			/* errno is set for us.  */
 
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (ofp, ENOMEM);
+	return ctf_set_int_errno (ofp, ENOMEM);
       i->cu.ctn_fp = ofp;
       i->ctn_tp = tp;
 
@@ -129,7 +129,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
       if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
 	{
 	  ctf_next_destroy (i);
-	  return (ctf_set_errno (ofp, ECTF_NOTSOU));
+	  return (ctf_set_int_errno (ofp, ECTF_NOTSOU));
 	}
 
       if ((dtd = ctf_dynamic_type (fp, type)) != NULL)
@@ -150,14 +150,14 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
     }
 
   if ((void (*) (void)) ctf_member_next != i->ctn_iter_fun)
-    return (ctf_set_errno (ofp, ECTF_NEXT_WRONGFUN));
+    return (ctf_set_int_errno (ofp, ECTF_NEXT_WRONGFUN));
 
   if (ofp != i->cu.ctn_fp)
-    return (ctf_set_errno (ofp, ECTF_NEXT_WRONGFP));
+    return (ctf_set_int_errno (ofp, ECTF_NEXT_WRONGFP));
 
   /* Resolve to the native dict of this type.  */
   if ((fp = ctf_get_dict (ofp, type)) == NULL)
-    return (ctf_set_errno (ofp, ECTF_NOPARENT));
+    return (ctf_set_int_errno (ofp, ECTF_NOPARENT));
 
   max_vlen = LCTF_INFO_VLEN (fp, i->ctn_tp->ctt_info);
 
@@ -177,7 +177,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 
       if (ctf_struct_member (fp, &memb, i->ctn_tp, i->u.ctn_vlen, i->ctn_size,
 			     i->ctn_n) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+        return (ctf_set_int_errno (ofp, ctf_errno (fp)));
 
       membname = ctf_strptr (fp, memb.ctlm_name);
 
@@ -216,12 +216,12 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 	  ctf_next_destroy (i);
 	  *it = NULL;
 	  i->ctn_type = 0;
-	  ctf_set_errno (ofp, ctf_errno (fp));
+	  ctf_set_int_errno (ofp, ctf_errno (fp));
 	  return ret;
 	}
 
       if (!ctf_assert (fp, (i->ctn_next == NULL)))
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+        return (ctf_set_int_errno (ofp, ctf_errno (fp)));
 
       i->ctn_type = 0;
       /* This sub-struct has ended: on to the next real member.  */
@@ -233,7 +233,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
  end_iter:
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (ofp, ECTF_NEXT_END);
+  return ctf_set_int_errno (ofp, ECTF_NEXT_END);
 }
 
 /* Iterate over the members of an ENUM.  We pass the string name and associated
@@ -287,7 +287,7 @@ ctf_enum_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 
       if ((i = ctf_next_create ()) == NULL)
 	{
-	  ctf_set_errno (ofp, ENOMEM);
+	  ctf_set_type_errno (ofp, ENOMEM);
 	  return NULL;
 	}
       i->cu.ctn_fp = ofp;
@@ -299,7 +299,7 @@ ctf_enum_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
       if (kind != CTF_K_ENUM)
 	{
 	  ctf_next_destroy (i);
-	  ctf_set_errno (ofp, ECTF_NOTENUM);
+	  ctf_set_type_errno (ofp, ECTF_NOTENUM);
 	  return NULL;
 	}
 
@@ -318,20 +318,20 @@ ctf_enum_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
 
   if ((void (*) (void)) ctf_enum_next != i->ctn_iter_fun)
     {
-      ctf_set_errno (ofp, ECTF_NEXT_WRONGFUN);
+      ctf_set_type_errno (ofp, ECTF_NEXT_WRONGFUN);
       return NULL;
     }
 
   if (ofp != i->cu.ctn_fp)
     {
-      ctf_set_errno (ofp, ECTF_NEXT_WRONGFP);
+      ctf_set_type_errno (ofp, ECTF_NEXT_WRONGFP);
       return NULL;
     }
 
   /* Resolve to the native dict of this type.  */
   if ((fp = ctf_get_dict (ofp, type)) == NULL)
     {
-      ctf_set_errno (ofp, ECTF_NOPARENT);
+      ctf_set_type_errno (ofp, ECTF_NOPARENT);
       return NULL;
     }
 
@@ -349,7 +349,7 @@ ctf_enum_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
  end_iter:
   ctf_next_destroy (i);
   *it = NULL;
-  ctf_set_errno (ofp, ECTF_NEXT_END);
+  ctf_set_type_errno (ofp, ECTF_NEXT_END);
   return NULL;
 }
 
@@ -426,7 +426,7 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	return ctf_set_type_errno (fp, ENOMEM);
 
       i->cu.ctn_fp = fp;
       i->ctn_type = 1;
@@ -435,10 +435,10 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
     }
 
   if ((void (*) (void)) ctf_type_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFUN));
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFP));
 
   while (i->ctn_type <= fp->ctf_typemax)
     {
@@ -456,7 +456,7 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
     }
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (fp, ECTF_NEXT_END);
+  return ctf_set_type_errno (fp, ECTF_NEXT_END);
 }
 
 /* Iterate over every variable in the given CTF dict, in arbitrary order.
@@ -494,12 +494,12 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
   ctf_next_t *i = *it;
 
   if ((fp->ctf_flags & LCTF_CHILD) && (fp->ctf_parent == NULL))
-    return (ctf_set_errno (fp, ECTF_NOPARENT));
+    return (ctf_set_type_errno (fp, ECTF_NOPARENT));
 
   if (!i)
     {
       if ((i = ctf_next_create ()) == NULL)
-	return ctf_set_errno (fp, ENOMEM);
+	return ctf_set_type_errno (fp, ENOMEM);
 
       i->cu.ctn_fp = fp;
       i->ctn_iter_fun = (void (*) (void)) ctf_variable_next;
@@ -509,10 +509,10 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
     }
 
   if ((void (*) (void)) ctf_variable_next != i->ctn_iter_fun)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFUN));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFUN));
 
   if (fp != i->cu.ctn_fp)
-    return (ctf_set_errno (fp, ECTF_NEXT_WRONGFP));
+    return (ctf_set_type_errno (fp, ECTF_NEXT_WRONGFP));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
     {
@@ -538,7 +538,7 @@ ctf_variable_next (ctf_dict_t *fp, ctf_next_t **it, const char **name)
  end_iter:
   ctf_next_destroy (i);
   *it = NULL;
-  return ctf_set_errno (fp, ECTF_NEXT_END);
+  return ctf_set_type_errno (fp, ECTF_NEXT_END);
 }
 
 /* Follow a given type through the graph for TYPEDEF, VOLATILE, CONST, and
@@ -560,7 +560,7 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type)
   const ctf_type_t *tp;
 
   if (type == 0)
-    return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+    return (ctf_set_type_errno (ofp, ECTF_NONREPRESENTABLE));
 
   while ((tp = ctf_lookup_by_id (&fp, type)) != NULL)
     {
@@ -575,18 +575,18 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type)
 	    {
 	      ctf_err_warn (ofp, 0, ECTF_CORRUPT, _("type %lx cycle detected"),
 			    otype);
-	      return (ctf_set_errno (ofp, ECTF_CORRUPT));
+	      return (ctf_set_type_errno (ofp, ECTF_CORRUPT));
 	    }
 	  prev = type;
 	  type = tp->ctt_type;
 	  break;
 	case CTF_K_UNKNOWN:
-	  return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+	  return (ctf_set_type_errno (ofp, ECTF_NONREPRESENTABLE));
 	default:
 	  return type;
 	}
       if (type == 0)
-	return (ctf_set_errno (ofp, ECTF_NONREPRESENTABLE));
+	return (ctf_set_type_errno (ofp, ECTF_NONREPRESENTABLE));
     }
 
   return CTF_ERR;		/* errno is set for us.  */
@@ -612,7 +612,7 @@ ctf_type_resolve_unsliced (ctf_dict_t *fp, ctf_id_t type)
       ctf_id_t ret;
 
       if ((ret = ctf_type_reference (fp, type)) == CTF_ERR)
-	return (ctf_set_errno (ofp, ctf_errno (fp)));
+	return (ctf_set_type_errno (ofp, ctf_errno (fp)));
       return ret;
     }
   return type;
@@ -675,7 +675,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
   if (cd.cd_err != 0)
     {
       ctf_decl_fini (&cd);
-      ctf_set_errno (fp, cd.cd_err);
+      ctf_set_type_errno (fp, cd.cd_err);
       return NULL;
     }
 
@@ -720,7 +720,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
 
 	      if (name[0] == '\0')
 		{
-		  ctf_set_errno (fp, ECTF_CORRUPT);
+		  ctf_set_type_errno (fp, ECTF_CORRUPT);
 		  ctf_decl_fini (&cd);
 		  return NULL;
 		}
@@ -744,7 +744,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
 
 		if ((argv = calloc (fi.ctc_argc, sizeof (ctf_id_t *))) == NULL)
 		  {
-		    ctf_set_errno (rfp, errno);
+		    ctf_set_type_errno (rfp, errno);
 		    goto err;
 		  }
 
@@ -775,7 +775,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
 		break;
 
 	      err:
-		ctf_set_errno (fp, ctf_errno (rfp));
+		ctf_set_type_errno (fp, ctf_errno (rfp));
 		free (argv);
 		ctf_decl_fini (&cd);
 		return NULL;
@@ -804,7 +804,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
 		    ctf_decl_sprintf (&cd, "enum %s", name);
 		    break;
 		  default:
-		    ctf_set_errno (fp, ECTF_CORRUPT);
+		    ctf_set_type_errno (fp, ECTF_CORRUPT);
 		    ctf_decl_fini (&cd);
 		    return NULL;
 		  }
@@ -836,7 +836,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
     }
 
   if (cd.cd_enomem)
-    (void) ctf_set_errno (fp, ENOMEM);
+    (void) ctf_set_type_errno (fp, ENOMEM);
 
   buf = ctf_decl_buf (&cd);
 
@@ -861,7 +861,7 @@ ctf_type_lname (ctf_dict_t *fp, ctf_id_t type, char *buf, size_t len)
   free (str);
 
   if (slen >= len)
-    (void) ctf_set_errno (fp, ECTF_NAMELEN);
+    (void) ctf_set_int_errno (fp, ECTF_NAMELEN);
 
   return slen;
 }
@@ -956,7 +956,7 @@ ctf_type_size (ctf_dict_t *fp, ctf_id_t type)
 
     case CTF_K_FORWARD:
       /* Forwards do not have a meaningful size.  */
-      return (ctf_set_errno (ofp, ECTF_INCOMPLETE));
+      return (ctf_set_int_errno (ofp, ECTF_INCOMPLETE));
 
     default: /* including slices of enums, etc */
       return (ctf_get_ctt_size (fp, tp, NULL, NULL));
@@ -1039,7 +1039,7 @@ ctf_type_align (ctf_dict_t *fp, ctf_id_t type)
 
     case CTF_K_FORWARD:
       /* Forwards do not have a meaningful alignment.  */
-      return (ctf_set_errno (ofp, ECTF_INCOMPLETE));
+      return (ctf_set_int_errno (ofp, ECTF_INCOMPLETE));
 
     default:  /* including slices of enums, etc */
       return (ctf_get_ctt_size (fp, tp, NULL, NULL));
@@ -1139,7 +1139,7 @@ ctf_type_reference (ctf_dict_t *fp, ctf_id_t type)
 	return sp->cts_type;
       }
     default:
-      return (ctf_set_errno (ofp, ECTF_NOTREF));
+      return (ctf_set_type_errno (ofp, ECTF_NOTREF));
     }
 }
 
@@ -1164,15 +1164,15 @@ ctf_type_pointer (ctf_dict_t *fp, ctf_id_t type)
     return (LCTF_INDEX_TO_TYPE (fp, ntype, (fp->ctf_flags & LCTF_CHILD)));
 
   if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
-    return (ctf_set_errno (ofp, ECTF_NOTYPE));
+    return (ctf_set_type_errno (ofp, ECTF_NOTYPE));
 
   if (ctf_lookup_by_id (&fp, type) == NULL)
-    return (ctf_set_errno (ofp, ECTF_NOTYPE));
+    return (ctf_set_type_errno (ofp, ECTF_NOTYPE));
 
   if ((ntype = fp->ctf_ptrtab[LCTF_TYPE_TO_INDEX (fp, type)]) != 0)
     return (LCTF_INDEX_TO_TYPE (fp, ntype, (fp->ctf_flags & LCTF_CHILD)));
 
-  return (ctf_set_errno (ofp, ECTF_NOTYPE));
+  return (ctf_set_type_errno (ofp, ECTF_NOTYPE));
 }
 
 /* Return the encoding for the specified INTEGER, FLOAT, or ENUM.  */
@@ -1235,7 +1235,7 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep)
 	break;
       }
     default:
-      return (ctf_set_errno (ofp, ECTF_NOTINTFP));
+      return (ctf_set_int_errno (ofp, ECTF_NOTINTFP));
     }
 
   return 0;
@@ -1370,7 +1370,7 @@ ctf_member_count (ctf_dict_t *fp, ctf_id_t type)
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION && kind != CTF_K_ENUM)
-    return (ctf_set_errno (ofp, ECTF_NOTSUE));
+    return (ctf_set_int_errno (ofp, ECTF_NOTSUE));
 
   return LCTF_INFO_VLEN (fp, tp->ctt_info);
 }
@@ -1398,7 +1398,7 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_STRUCT && kind != CTF_K_UNION)
-    return (ctf_set_errno (ofp, ECTF_NOTSOU));
+    return (ctf_set_int_errno (ofp, ECTF_NOTSOU));
 
   n = LCTF_INFO_VLEN (fp, tp->ctt_info);
   if ((dtd = ctf_dynamic_type (fp, type)) != NULL)
@@ -1418,7 +1418,7 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
       const char *membname;
 
       if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+        return (ctf_set_int_errno (ofp, ctf_errno (fp)));
 
       membname = ctf_strptr (fp, memb.ctlm_name);
 
@@ -1439,7 +1439,7 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
 	}
     }
 
-  return (ctf_set_errno (ofp, ECTF_NOMEMBNAM));
+  return (ctf_set_int_errno (ofp, ECTF_NOMEMBNAM));
 }
 
 /* Return the array type, index, and size information for the specified ARRAY.  */
@@ -1457,7 +1457,7 @@ ctf_array_info (ctf_dict_t *fp, ctf_id_t type, ctf_arinfo_t *arp)
     return -1;			/* errno is set for us.  */
 
   if (LCTF_INFO_KIND (fp, tp->ctt_info) != CTF_K_ARRAY)
-    return (ctf_set_errno (ofp, ECTF_NOTARRAY));
+    return (ctf_set_int_errno (ofp, ECTF_NOTARRAY));
 
   if ((dtd = ctf_dynamic_type (ofp, type)) != NULL)
     ap = (const ctf_array_t *) dtd->dtd_vlen;
@@ -1494,7 +1494,7 @@ ctf_enum_name (ctf_dict_t *fp, ctf_id_t type, int value)
 
   if (LCTF_INFO_KIND (fp, tp->ctt_info) != CTF_K_ENUM)
     {
-      ctf_set_errno (ofp, ECTF_NOTENUM);
+      ctf_set_type_errno (ofp, ECTF_NOTENUM);
       return NULL;
     }
 
@@ -1511,7 +1511,7 @@ ctf_enum_name (ctf_dict_t *fp, ctf_id_t type, int value)
 	return (ctf_strptr (fp, ep->cte_name));
     }
 
-  ctf_set_errno (ofp, ECTF_NOENUMNAM);
+  ctf_set_type_errno (ofp, ECTF_NOENUMNAM);
   return NULL;
 }
 
@@ -1536,7 +1536,7 @@ ctf_enum_value (ctf_dict_t *fp, ctf_id_t type, const char *name, int *valp)
 
   if (LCTF_INFO_KIND (fp, tp->ctt_info) != CTF_K_ENUM)
     {
-      (void) ctf_set_errno (ofp, ECTF_NOTENUM);
+      (void) ctf_set_int_errno (ofp, ECTF_NOTENUM);
       return -1;
     }
 
@@ -1557,7 +1557,7 @@ ctf_enum_value (ctf_dict_t *fp, ctf_id_t type, const char *name, int *valp)
 	}
     }
 
-  ctf_set_errno (ofp, ECTF_NOENUMNAM);
+  ctf_set_int_errno (ofp, ECTF_NOENUMNAM);
   return -1;
 }
 
@@ -1584,7 +1584,7 @@ ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip)
   kind = LCTF_INFO_KIND (fp, tp->ctt_info);
 
   if (kind != CTF_K_FUNCTION)
-    return (ctf_set_errno (ofp, ECTF_NOTFUNC));
+    return (ctf_set_int_errno (ofp, ECTF_NOTFUNC));
 
   fip->ctc_return = tp->ctt_type;
   fip->ctc_flags = 0;
@@ -1697,7 +1697,7 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
       ctf_lmember_t memb;
 
       if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0)
-        return (ctf_set_errno (ofp, ctf_errno (fp)));
+        return (ctf_set_int_errno (ofp, ctf_errno (fp)));
 
       if ((rc = ctf_type_rvisit (fp, memb.ctlm_type,
 				 func, arg, ctf_strptr (fp, memb.ctlm_name),
diff --git a/libctf/ctf-util.c b/libctf/ctf-util.c
index 9f83ab9ab0b..e0d412df390 100644
--- a/libctf/ctf-util.c
+++ b/libctf/ctf-util.c
@@ -255,16 +255,6 @@ ctf_set_open_errno (int *errp, int error)
   return NULL;
 }
 
-/* Store the specified error code into the CTF dict, and then return CTF_ERR /
-   -1 for the benefit of the caller. */
-
-unsigned long
-ctf_set_errno (ctf_dict_t *fp, int err)
-{
-  fp->ctf_errno = err;
-  return CTF_ERR;
-}
-
 /* Create a ctf_next_t.  */
 
 ctf_next_t *
-- 
2.25.1


  reply	other threads:[~2023-09-26 17:39 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 11:32 [PATCH] " Torbjörn SVENSSON
2023-08-25  2:22 ` Alan Modra
2023-08-25 16:53   ` [PATCH v2] " Torbjörn SVENSSON
2023-08-30  8:34     ` Torbjorn SVENSSON
2023-08-30  9:39       ` Alan Modra
2023-09-07 12:10         ` Nick Alcock
2023-09-08 12:58           ` Torbjorn SVENSSON
2023-09-12 14:23             ` Nick Alcock
2023-09-12 18:44               ` Torbjorn SVENSSON
2023-09-13  9:57               ` [PATCH v3] " Torbjörn SVENSSON
2023-09-13 18:37                 ` Nick Alcock
2023-09-13 20:20                   ` Torbjorn SVENSSON
2023-09-20 17:44                     ` Torbjorn SVENSSON
2023-09-26 14:51                     ` Nick Alcock
2023-09-26 17:28                       ` Torbjörn SVENSSON [this message]
2023-09-26 17:49                       ` Torbjorn SVENSSON
2023-09-28 16:41                         ` Nick Alcock
2023-09-29 12:11                           ` Torbjorn SVENSSON
2023-10-02 10:57                             ` Nick Alcock
2023-10-03 12:59                               ` Torbjorn SVENSSON
2023-10-03 20:53                                 ` Nick Alcock
2023-10-05  8:39                                   ` [PATCH v5] libctf: Sanitize error types for PR 30836 Torbjörn SVENSSON
2023-10-09 10:27                                     ` Nick Alcock
2023-10-09 14:44                                       ` [PATCH v6] " Torbjörn SVENSSON
2023-10-09 15:11                                         ` [PATCH v7] " Torbjörn SVENSSON
2023-10-11 11:14                                           ` Nick Alcock
2023-10-13 14:01                                           ` [PATCH] libctf: check for problems with error returns Nick Alcock
2023-10-13 18:31                                             ` Torbjorn SVENSSON
2023-10-15 19:18                                               ` Nick Alcock
2023-10-16 12:51                                                 ` [PATCH v8] libctf: Sanitize error types for PR 30836 Torbjörn SVENSSON
2023-10-17 15:15                                                   ` Nick Alcock
2023-10-17 15:35                                                     ` Torbjorn SVENSSON
2023-10-17 18:54                                                       ` [PATCH] libctf: Return CTF_ERR in ctf_type_resolve_unsliced " Torbjörn SVENSSON
2023-10-17 19:40                                                         ` Nick Alcock
2023-10-18  7:40                                                           ` Torbjorn SVENSSON
2023-10-20 17:01                                                             ` Nick Alcock
2023-10-16 13:02                                                 ` [PATCH] libctf: check for problems with error returns Torbjorn SVENSSON
2023-10-17 14:45                                                   ` Nick Alcock
2024-01-30 12:46                                             ` Andreas Schwab
2024-01-30 14:22                                               ` Nick Alcock
2024-01-30 14:27                                                 ` Andreas Schwab
2024-03-09  2:44                                                   ` Sam James
2024-03-11 15:14                                                     ` Nick Alcock
2024-03-12  6:52                                                       ` Sam James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230926172848.1123514-1-torbjorn.svensson@foss.st.com \
    --to=torbjorn.svensson@foss.st.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=nick.alcock@oracle.com \
    --cc=yvan.roux@foss.st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).