[RFA 3/3] libctf: compilation failure on MinGW due to missing errno values

Nick Alcock nick.alcock@oracle.com
Fri Jan 3 16:38:00 GMT 2020


On 2 Jan 2020, Joel Brobecker stated:

> From: Eli Zaretskii <eliz@gnu.org>
>
> This commit fixes a compilation failure in a couple of libctf files
> due to the use of EOVERFLOW and ENOTSUP, which are not defined
> when compiling on MinGW.

Hah. I knew using E* rather than defining libctf-specific error codes
for everything might bite us eventually. It's something else that makes
sense on a one-OS project that ceases to make sense when it becomes a
multi-OS project that spans operating systems with different sets of
errno values.

> libctf/ChangeLog:
>
> 	PR binutils/25155:
> 	* ctf-create.c (EOVERFLOW): If not defined by system header,
> 	redirect to ERANGE as a poor man's substitute.
> 	* ctf-subr.c (ENOTSUP): If not defined, use ENOSYS instead.
>
> This one is how Eli implemented it. I think this implementation
> has a weakness in the following sense: If other units in libctf
> start using those constants, we'll get the same error again.

Agreed. So I think we should do something that fixes this for good, at
the cost of an API break that I just checked won't affect any existing
users: see below.

> Also, I'm wondering whether their use is documented as part of
> the official libtcf API or not -- users might be writing code
> that tests for these, and if the system doesn't support them,
> how would they know what errno code to use in its place. This

Agreed. It should be documented, but is not, simply because the spec so
far only documents the *file format*: documenting the API (including
error codes) will happen, but debugging the deduplicating linker and
submitting the existing spec should come first. I'll probably write a
libctf spec in parallel with writing the missing testsuite.

It is most unlikely that any existing users are conditionalizing on
these rather than simply ctf_errmsg()ing them and printing them out,
since both of these are reporting conditions there really isn't any way
to recover from. I can see no sign that any existing users are using
these error codes, so I think we can simply migrate away from them.

> argues for a having that information in one of libctf's header
> files. I think it would be nice to have those in ctf-decls.h,
> but I think we'll need to include <errno.h> in ctf-decls.h if
> we decide to define those macros there.

I think what makes most sense is to migrate away from using E* constants
except for where we reflect the E* return of some underlying call
(ENOMEM/EAGAIN from malloc, say). libctf itself should only explicitly
set ECTF_* errors it also defines, in the range below ECTF_BASE. While
this is technically an API change, no users to date are affected. Here
and there this might require extra work for users responding to the
errors: e.g. they'd now need to check for ECTF_NOMEM || ENOMEM. However,
given that they'd already have to do this for ENOMEM versus EAGAIN I
don't consider this much of a problem. :)

Something like this (atop my latest patch series, will write a
changelog if people think this makes sense):

diff --git a/include/ctf-api.h b/include/ctf-api.h
index fb494b2021..c85abe1f6d 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -204,7 +204,10 @@ enum
    ECTF_DUMPSECTCHANGED,	/* Section changed in middle of dump.  */
    ECTF_NOTYET,			/* Feature not yet implemented.  */
    ECTF_INTERNAL,		/* Internal error in link.  */
-   ECTF_NONREPRESENTABLE	/* Type not representable in CTF.  */
+   ECTF_NONREPRESENTABLE,	/* Type not representable in CTF.  */
+   ECTF_INVAL,			/* Invalid argument to CTF function.  */
+   ECTF_NOMEM,			/* Out of memory in libctf.  */
+   ECTF_ARGOVERFLOW		/* Limit on number of function arguments reached.  */
   };
 
 /* The CTF data model is inferred to be the caller's data model or the data
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index b875075f50..6af8bd2f64 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -52,7 +52,7 @@ ctf_grow_ptrtab (ctf_file_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_errno (fp, errno));
 
       fp->ctf_ptrtab = new_ptrtab;
       memset (fp->ctf_ptrtab + fp->ctf_ptrtab_len, 0,
@@ -83,7 +83,7 @@ ctf_create (int *errp)
 			       NULL, NULL);
   if (dthash == NULL)
     {
-      ctf_set_open_errno (errp, EAGAIN);
+      ctf_set_open_errno (errp, ECTF_NOMEM);
       goto err;
     }
 
@@ -91,7 +91,7 @@ ctf_create (int *errp)
 			       NULL, NULL);
   if (dvhash == NULL)
     {
-      ctf_set_open_errno (errp, EAGAIN);
+      ctf_set_open_errno (errp, ECTF_NOMEM);
       goto err_dt;
     }
 
@@ -105,7 +105,7 @@ ctf_create (int *errp)
 			      NULL, NULL);
   if (!structs || !unions || !enums || !names)
     {
-      ctf_set_open_errno (errp, EAGAIN);
+      ctf_set_open_errno (errp, ECTF_NOMEM);
       goto err_dv;
     }
 
@@ -352,7 +352,7 @@ ctf_serialize (ctf_file_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_errno (fp, errno));
 
   memcpy (buf, &hdr, sizeof (ctf_header_t));
   t = (unsigned char *) buf + sizeof (ctf_header_t) + hdr.cth_varoff;
@@ -481,7 +481,7 @@ ctf_serialize (ctf_file_t *fp)
   if (strtab.cts_strs == NULL)
     {
       free (buf);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, ECTF_NOMEM));
     }
 
   /* Now the string table is constructed, we can sort the buffer of
@@ -494,7 +494,7 @@ ctf_serialize (ctf_file_t *fp)
     {
       free (buf);
       free (strtab.cts_strs);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, errno));
     }
   buf = newbuf;
   memcpy (buf + buf_size, strtab.cts_strs, strtab.cts_len);
@@ -809,7 +809,7 @@ ctf_add_generic (ctf_file_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_errno (fp, ECTF_INVAL));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
     return (ctf_set_errno (fp, ECTF_RDONLY));
@@ -825,7 +825,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind,
       return CTF_ERR;		/* errno is set for us. */
 
   if ((dtd = malloc (sizeof (ctf_dtdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_errno (fp, errno));
 
   type = ++fp->ctf_typemax;
   type = LCTF_INDEX_TO_TYPE (fp, type, (fp->ctf_flags & LCTF_CHILD));
@@ -837,7 +837,7 @@ ctf_add_generic (ctf_file_t *fp, uint32_t flag, const char *name, int kind,
   if (dtd->dtd_data.ctt_name == 0 && name != NULL && name[0] != '\0')
     {
       free (dtd);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, ECTF_NOMEM));
     }
 
   if (ctf_dtd_insert (fp, dtd, flag, kind) < 0)
@@ -876,7 +876,7 @@ ctf_add_encoded (ctf_file_t *fp, uint32_t flag,
   ctf_id_t type;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if ((type = ctf_add_generic (fp, flag, name, kind, &dtd)) == CTF_ERR)
     return CTF_ERR;		/* errno is set for us.  */
@@ -898,7 +898,7 @@ ctf_add_reftype (ctf_file_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_errno (fp, ECTF_INVAL));
 
   if (ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -949,13 +949,13 @@ ctf_add_slice (ctf_file_t *fp, uint32_t flag, ctf_id_t ref,
   ctf_file_t *tmp = fp;
 
   if (ep == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if ((ep->cte_bits > 255) || (ep->cte_offset > 255))
     return (ctf_set_errno (fp, ECTF_SLICEOVERFLOW));
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if ((tp = ctf_lookup_by_id (&tmp, ref)) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -1006,7 +1006,7 @@ ctf_add_array (ctf_file_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
   ctf_file_t *tmp = fp;
 
   if (arp == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (ctf_lookup_by_id (&tmp, arp->ctr_contents) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -1056,7 +1056,7 @@ ctf_add_function (ctf_file_t *fp, uint32_t flag,
 
   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_errno (fp, ECTF_INVAL));
 
   vlen = ctc->ctc_argc;
   if (ctc->ctc_flags & CTF_FUNC_VARARG)
@@ -1073,10 +1073,10 @@ ctf_add_function (ctf_file_t *fp, uint32_t flag,
     }
 
   if (vlen > CTF_MAX_VLEN)
-    return (ctf_set_errno (fp, EOVERFLOW));
+    return (ctf_set_errno (fp, ECTF_ARGOVERFLOW));
 
   if (vlen != 0 && (vdat = malloc (sizeof (ctf_id_t) * vlen)) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_errno (fp, errno));
 
   if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_FUNCTION,
 			       &dtd)) == CTF_ERR)
@@ -1257,7 +1257,7 @@ ctf_add_typedef (ctf_file_t *fp, uint32_t flag, const char *name,
   ctf_file_t *tmp = fp;
 
   if (ref == CTF_ERR || ref > CTF_MAX_TYPE)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (ctf_lookup_by_id (&tmp, ref) == NULL)
     return CTF_ERR;		/* errno is set for us.  */
@@ -1301,7 +1301,7 @@ ctf_add_enumerator (ctf_file_t *fp, ctf_id_t enid, const char *name,
   char *s;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (!(fp->ctf_flags & LCTF_RDWR))
     return (ctf_set_errno (fp, ECTF_RDONLY));
@@ -1327,12 +1327,12 @@ ctf_add_enumerator (ctf_file_t *fp, ctf_id_t enid, const char *name,
     }
 
   if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_errno (fp, errno));
 
   if ((s = strdup (name)) == NULL)
     {
       free (dmd);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, errno));
     }
 
   dmd->dmd_name = s;
@@ -1390,12 +1390,12 @@ ctf_add_member_offset (ctf_file_t *fp, ctf_id_t souid, const char *name,
     return -1;			/* errno is set for us.  */
 
   if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
-    return (ctf_set_errno (fp, EAGAIN));
+    return (ctf_set_errno (fp, errno));
 
   if (name != NULL && (s = strdup (name)) == NULL)
     {
       free (dmd);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, errno));
     }
 
   dmd->dmd_name = s;
@@ -1512,12 +1512,12 @@ ctf_add_variable (ctf_file_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_errno (fp, errno));
 
   if (name != NULL && (dvd->dvd_name = strdup (name)) == NULL)
     {
       free (dvd);
-      return (ctf_set_errno (fp, EAGAIN));
+      return (ctf_set_errno (fp, errno));
     }
   dvd->dvd_type = ref;
   dvd->dvd_snapshots = fp->ctf_snapshots;
@@ -1593,12 +1593,12 @@ membadd (const char *name, ctf_id_t type, unsigned long offset, void *arg)
   char *s = NULL;
 
   if ((dmd = malloc (sizeof (ctf_dmdef_t))) == NULL)
-    return (ctf_set_errno (ctb->ctb_file, EAGAIN));
+    return (ctf_set_errno (ctb->ctb_file, errno));
 
   if (name != NULL && (s = strdup (name)) == NULL)
     {
       free (dmd);
-      return (ctf_set_errno (ctb->ctb_file, EAGAIN));
+      return (ctf_set_errno (ctb->ctb_file, errno));
     }
 
   /* For now, dmd_type is copied as the src_fp's type; it is reset to an
@@ -1804,7 +1804,7 @@ ctf_add_type_internal (ctf_file_t *dst_fp, ctf_file_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_errno (dst_fp, ECTF_NOMEM);
 
   switch (kind)
     {
@@ -2070,7 +2070,7 @@ ctf_add_type (ctf_file_t *dst_fp, ctf_file_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_errno (dst_fp, ECTF_NOMEM));
 
   id = ctf_add_type_internal (dst_fp, src_fp, src_type, src_fp);
   ctf_dynhash_empty (src_fp->ctf_add_processing);
@@ -2191,7 +2191,7 @@ ctf_write_mem (ctf_file_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_errno (fp, errno);
       return NULL;
     }
 
diff --git a/libctf/ctf-dump.c b/libctf/ctf-dump.c
index 88e81a574f..161ae4a485 100644
--- a/libctf/ctf-dump.c
+++ b/libctf/ctf-dump.c
@@ -55,7 +55,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_errno (state->cds_fp, errno));
 
   cdi->cdi_item = str;
   ctf_list_append (&state->cds_items, cdi);
@@ -419,7 +419,7 @@ ctf_dump_funcs (ctf_file_t *fp, ctf_dump_state_t *state)
 	    continue;
 	  }
       if ((args = calloc (fi.ctc_argc, sizeof (ctf_id_t))) == NULL)
-	return (ctf_set_errno (fp, ENOMEM));
+	return (ctf_set_errno (fp, errno));
 
       /* Return type.  */
       if ((str = ctf_type_aname (state->cds_fp, type)) == NULL)
@@ -672,7 +672,7 @@ ctf_dump (ctf_file_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_errno (fp, errno);
 	  goto end;
 	}
       state = *statep;
@@ -778,7 +778,7 @@ ctf_dump (ctf_file_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_errno (fp, errno);
 	  return str;
 	}
     }
diff --git a/libctf/ctf-error.c b/libctf/ctf-error.c
index c0adb4bb51..ba28c893a0 100644
--- a/libctf/ctf-error.c
+++ b/libctf/ctf-error.c
@@ -71,7 +71,10 @@ static const char *const _ctf_errlist[] = {
   "Section changed in middle of dump",		     /* ECTF_DUMPSECTCHANGED */
   "Feature not yet implemented",		     /* ECTF_NOTYET */
   "Internal error in link",			     /* ECTF_INTERNAL */
-  "Type not representable in CTF"		     /* ECTF_NONREPRESENTABLE */
+  "Type not representable in CTF",		     /* ECTF_NONREPRESENTABLE */
+  "Invalid argument to CTF function",		     /* ECTF_INVAL */
+  "Out of memory in libctf",			     /* ECTF_NOMEM */
+  "Limit on number of function arguments reached"    /* ECTF_ARGOVERFLOW */
 };
 
 static const int _ctf_nerr = sizeof (_ctf_errlist) / sizeof (_ctf_errlist[0]);
diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index 2f05522d01..4bb2e63bbe 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -172,7 +172,7 @@ ctf_link_add_ctf (ctf_file_t *fp, ctf_archive_t *ctf, const char *name)
   free (fp->ctf_link_inputs);
   fp->ctf_link_inputs = NULL;
   free (dupname);
-  return (ctf_set_errno (fp, ENOMEM));
+  return (ctf_set_errno (fp, ECTF_NOMEM));
 }
 
 /* Return a per-CU output CTF dictionary suitable for the given CU, creating and
@@ -228,7 +228,7 @@ ctf_create_per_cu (ctf_file_t *fp, const char *filename, const char *cuname)
  oom:
   free (dynname);
   ctf_file_close (cu_fp);
-  ctf_set_errno (fp, ENOMEM);
+  ctf_set_errno (fp, ECTF_NOMEM);
   return NULL;
 }
 
@@ -254,7 +254,7 @@ ctf_link_add_cu_mapping (ctf_file_t *fp, const char *from, const char *to)
 						  ctf_hash_eq_string, free,
 						  free);
   if (fp->ctf_link_cu_mapping == NULL)
-    return ctf_set_errno (fp, ENOMEM);
+    return ctf_set_errno (fp, ECTF_NOMEM);
 
   if (fp->ctf_link_outputs == NULL)
     fp->ctf_link_outputs = ctf_dynhash_create (ctf_hash_string,
@@ -262,7 +262,7 @@ ctf_link_add_cu_mapping (ctf_file_t *fp, const char *from, const char *to)
 					       ctf_file_close_thunk);
 
   if (fp->ctf_link_outputs == NULL)
-    return ctf_set_errno (fp, ENOMEM);
+    return ctf_set_errno (fp, ECTF_NOMEM);
 
   f = strdup (from);
   t = strdup (to);
@@ -518,7 +518,7 @@ ctf_link_one_input_archive_member (ctf_file_t *in_fp, const char *name, void *ar
     }
 
   if (!arg->arcname)
-    return ctf_set_errno (in_fp, ENOMEM);
+    return ctf_set_errno (in_fp, ECTF_NOMEM);
 
   arg->cu_name = name;
   if (strncmp (arg->cu_name, ".ctf.", strlen (".ctf.")) == 0)
@@ -613,7 +613,7 @@ ctf_link (ctf_file_t *fp, int share_mode)
 					       ctf_file_close_thunk);
 
   if (fp->ctf_link_outputs == NULL)
-    return ctf_set_errno (fp, ENOMEM);
+    return ctf_set_errno (fp, ECTF_NOMEM);
 
   ctf_dynhash_iter (fp->ctf_link_inputs, ctf_link_one_input_archive,
 		    &arg);
@@ -640,7 +640,7 @@ ctf_link_intern_extern_string (void *key _libctf_unused_, void *value,
 
   fp->ctf_flags |= LCTF_DIRTY;
   if (!ctf_str_add_external (fp, arg->str, arg->offset))
-    arg->err = ENOMEM;
+    arg->err = ECTF_NOMEM;
 }
 
 /* Repeatedly call ADD_STRING to acquire strings from the external string table,
@@ -663,7 +663,7 @@ ctf_link_add_strtab (ctf_file_t *fp, ctf_link_strtab_string_f *add_string,
 
       fp->ctf_flags |= LCTF_DIRTY;
       if (!ctf_str_add_external (fp, str, offset))
-	err = ENOMEM;
+	err = ECTF_NOMEM;
 
       ctf_dynhash_iter (fp->ctf_link_outputs, ctf_link_intern_extern_string,
 			&iter_arg);
@@ -706,14 +706,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_errno (arg->fp, errno);
       return;
     }
 
   if ((files = realloc (arg->files, sizeof (ctf_file_t *) * arg->i)) == NULL)
     {
       (arg->i)--;
-      ctf_set_errno (arg->fp, ENOMEM);
+      ctf_set_errno (arg->fp, errno);
       return;
     }
 
@@ -736,7 +736,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_errno (arg->fp, errno);
 	      return;
 	    }
 	    arg->dynames = dynames;
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index 6f180d68c2..9f7b0210f8 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -79,7 +79,7 @@ ctf_lookup_by_name (ctf_file_t *fp, const char *name)
   ctf_id_t ntype, ptype;
 
   if (name == NULL)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   for (p = name, end = name + strlen (name); *p != '\0'; p = q)
     {
@@ -156,7 +156,7 @@ ctf_lookup_by_name (ctf_file_t *fp, const char *name)
 		  fp->ctf_tmp_typeslice = xstrndup (p, (size_t) (q - p));
 		  if (fp->ctf_tmp_typeslice == NULL)
 		    {
-		      (void) ctf_set_errno (fp, ENOMEM);
+		      (void) ctf_set_errno (fp, ECTF_NOMEM);
 		      return CTF_ERR;
 		    }
 		}
@@ -249,7 +249,7 @@ ctf_lookup_symbol_name (ctf_file_t *fp, unsigned long symidx)
 
   if (symidx >= fp->ctf_nsyms)
     {
-      ctf_set_errno (fp, EINVAL);
+      ctf_set_errno (fp, ECTF_INVAL);
       return _CTF_NULLSTR;
     }
 
@@ -280,7 +280,7 @@ ctf_lookup_by_symbol (ctf_file_t *fp, unsigned long symidx)
     return (ctf_set_errno (fp, ECTF_NOSYMTAB));
 
   if (symidx >= fp->ctf_nsyms)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (sp->cts_entsize == sizeof (Elf32_Sym))
     {
@@ -364,7 +364,7 @@ ctf_func_info (ctf_file_t *fp, unsigned long symidx, ctf_funcinfo_t *fip)
     return (ctf_set_errno (fp, ECTF_NOSYMTAB));
 
   if (symidx >= fp->ctf_nsyms)
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (sp->cts_entsize == sizeof (Elf32_Sym))
     {
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 076a3cc708..c830f2fbdd 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -721,17 +721,17 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
   if ((fp->ctf_structs.ctn_readonly
        = ctf_hash_create (pop[CTF_K_STRUCT], ctf_hash_string,
 			  ctf_hash_eq_string)) == NULL)
-    return ENOMEM;
+    return ECTF_NOMEM;
 
   if ((fp->ctf_unions.ctn_readonly
        = ctf_hash_create (pop[CTF_K_UNION], ctf_hash_string,
 			  ctf_hash_eq_string)) == NULL)
-    return ENOMEM;
+    return ECTF_NOMEM;
 
   if ((fp->ctf_enums.ctn_readonly
        = ctf_hash_create (pop[CTF_K_ENUM], ctf_hash_string,
 			  ctf_hash_eq_string)) == NULL)
-    return ENOMEM;
+    return ECTF_NOMEM;
 
   if ((fp->ctf_names.ctn_readonly
        = ctf_hash_create (pop[CTF_K_INTEGER] +
@@ -744,14 +744,14 @@ init_types (ctf_file_t *fp, ctf_header_t *cth)
 			  pop[CTF_K_RESTRICT],
 			  ctf_hash_string,
 			  ctf_hash_eq_string)) == NULL)
-    return ENOMEM;
+    return ECTF_NOMEM;
 
   fp->ctf_txlate = malloc (sizeof (uint32_t) * (fp->ctf_typemax + 1));
   fp->ctf_ptrtab_len = fp->ctf_typemax + 1;
   fp->ctf_ptrtab = malloc (sizeof (uint32_t) * fp->ctf_ptrtab_len);
 
   if (fp->ctf_txlate == NULL || fp->ctf_ptrtab == NULL)
-    return ENOMEM;		/* Memory allocation failed.  */
+    return errno;		/* Memory allocation failed.  */
 
   xp = fp->ctf_txlate;
   *xp++ = 0;			/* Type id 0 is used as a sentinel value.  */
@@ -1332,7 +1332,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
 
   if ((ctfsect == NULL) || ((symsect != NULL) &&
 			    ((strsect == NULL) && syn_strtab == NULL)))
-    return (ctf_set_open_errno (errp, EINVAL));
+    return (ctf_set_open_errno (errp, ECTF_INVAL));
 
   if (symsect != NULL && symsect->cts_entsize != sizeof (Elf32_Sym) &&
       symsect->cts_entsize != sizeof (Elf64_Sym))
@@ -1394,7 +1394,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
     return (ctf_set_open_errno (errp, ECTF_NOCTFBUF));
 
   if ((fp = malloc (sizeof (ctf_file_t))) == NULL)
-    return (ctf_set_open_errno (errp, ENOMEM));
+    return (ctf_set_open_errno (errp, errno));
 
   memset (fp, 0, sizeof (ctf_file_t));
 
@@ -1404,7 +1404,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   if ((fp->ctf_header = malloc (sizeof (struct ctf_header))) == NULL)
     {
       free (fp);
-      return (ctf_set_open_errno (errp, ENOMEM));
+      return (ctf_set_open_errno (errp, errno));
     }
   hp = fp->ctf_header;
   memcpy (hp, ctfsect->cts_data, hdrsz);
@@ -1531,19 +1531,19 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
   if (fp->ctf_data.cts_name != NULL)
     if ((fp->ctf_data.cts_name = strdup (fp->ctf_data.cts_name)) == NULL)
       {
-	err = ENOMEM;
+	err = errno;
 	goto bad;
       }
   if (fp->ctf_symtab.cts_name != NULL)
     if ((fp->ctf_symtab.cts_name = strdup (fp->ctf_symtab.cts_name)) == NULL)
       {
-	err = ENOMEM;
+	err = errno;
 	goto bad;
       }
   if (fp->ctf_strtab.cts_name != NULL)
     if ((fp->ctf_strtab.cts_name = strdup (fp->ctf_strtab.cts_name)) == NULL)
       {
-	err = ENOMEM;
+	err = errno;
 	goto bad;
       }
 
@@ -1597,7 +1597,7 @@ ctf_bufopen_internal (const ctf_sect_t *ctfsect, const ctf_sect_t *symsect,
 
       if (fp->ctf_sxlate == NULL)
 	{
-	  err = ENOMEM;
+	  err = errno;
 	  goto bad;
 	}
 
@@ -1761,7 +1761,7 @@ ctf_parent_name_set (ctf_file_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_errno (fp, errno));
   fp->ctf_parname = fp->ctf_dynparname;
   return 0;
 }
@@ -1782,7 +1782,7 @@ ctf_cuname_set (ctf_file_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_errno (fp, errno));
   fp->ctf_cuname = fp->ctf_dyncuname;
   return 0;
 }
@@ -1794,7 +1794,7 @@ int
 ctf_import (ctf_file_t *fp, ctf_file_t *pfp)
 {
   if (fp == NULL || fp == pfp || (pfp != NULL && pfp->ctf_refcnt == 0))
-    return (ctf_set_errno (fp, EINVAL));
+    return (ctf_set_errno (fp, ECTF_INVAL));
 
   if (pfp != NULL && pfp->ctf_dmodel != fp->ctf_dmodel)
     return (ctf_set_errno (fp, ECTF_DMODEL));
@@ -1837,7 +1837,7 @@ ctf_setmodel (ctf_file_t *fp, int model)
 	}
     }
 
-  return (ctf_set_errno (fp, EINVAL));
+  return (ctf_set_errno (fp, ECTF_INVAL));
 }
 
 /* Return the data model constant for the CTF container.  */
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index b0139e82bd..0425de135d 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -423,7 +423,7 @@ ctf_type_aname (ctf_file_t *fp, ctf_id_t type)
     }
 
   if (cd.cd_enomem)
-    (void) ctf_set_errno (fp, ENOMEM);
+    (void) ctf_set_errno (fp, ECTF_NOMEM);
 
   buf = ctf_decl_buf (&cd);
 



More information about the Binutils mailing list