Building libctf on MinGW

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Building libctf on MinGW

Eli Zaretskii
Hi,

Back in November I built Binutils 2.33 with mingw.org's MinGW, and
bumped into 3 compilation problems, which I reported on Bugzilla:

  https://sourceware.org/bugzilla/show_bug.cgi?id=25155

There was no response to that report, and these days I've built a
pretest of GDB 9.1 and bumped into the same problem.

Could these minor issues in libctf please be resolved upstream?  If
you need some more information from me beyond what's in Bugzilla,
please tell.

TIA
Reply | Threaded
Open this post in threaded view
|

Fix various build issues when building on MinGW

Joel Brobecker
Hello,

Eli Zaretskii found that libctf does not build on MinGW, and sent
some patches on bugzilla:

    https://sourceware.org/bugzilla/show_bug.cgi?id=25155

He mentioned those patches in this mailing list
(https://sourceware.org/ml/binutils/2019-12/msg00277.html), but
since there has been no response, he's asked me to submit them
on his behalf. Here they are (except for the first one, which is
from me, and pretty obvious).

Note that these patches are holding the GDB 9 release, so a prompt
review would be appreciated.

 * [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4
 * [RFA 2/3] libctf: Add configure check for asprintf (for MinGW)
 * [RFA 3/3] libctf: compilation failure on MinGW due to missing errno

These patches were tested by rebuilding on GNU/Linux. I do not have
access to a Windows machine with the compiler using the version of
MinGW Eli uses, so Eli, could you double-check that everything still
works? In particular, I had to re-generate the configure and config.h.in
files.

OK to push to master?

Thank you,
--
Joel

Reply | Threaded
Open this post in threaded view
|

[RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Joel Brobecker
I noticed that if I run "autoreconf" with vanilla automake-1.15.1
and autoconf-2.69, I get some differences.

libctf/ChangeLog:

        * Makefile.in, aclocal.m4: Regenerate.

I think this one qualifies as obvious, but perhaps I'm missing
something...

OK to push to master?

Thank you!
--
Joel

---
 libctf/Makefile.in | 6 +++---
 libctf/aclocal.m4  | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libctf/Makefile.in b/libctf/Makefile.in
index d6e73cac732..cfcac9536f4 100644
--- a/libctf/Makefile.in
+++ b/libctf/Makefile.in
@@ -110,13 +110,13 @@ host_triplet = @host@
 @NEED_CTF_QSORT_R_TRUE@am__append_1 = ctf-qsort_r.c
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../bfd/acinclude.m4 \
+ $(top_srcdir)/../config/acx.m4 \
  $(top_srcdir)/../config/depstand.m4 \
  $(top_srcdir)/../config/lead-dot.m4 \
  $(top_srcdir)/../config/override.m4 \
  $(top_srcdir)/../config/warnings.m4 \
- $(top_srcdir)/../config/zlib.m4 \
- $(top_srcdir)/../bfd/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../config/zlib.m4 $(top_srcdir)/../libtool.m4 \
  $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
  $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
  $(top_srcdir)/configure.ac
diff --git a/libctf/aclocal.m4 b/libctf/aclocal.m4
index 04583b42f02..15d96cd63e3 100644
--- a/libctf/aclocal.m4
+++ b/libctf/aclocal.m4
@@ -1227,13 +1227,13 @@ AC_SUBST([am__tar])
 AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
+m4_include([../bfd/acinclude.m4])
 m4_include([../config/acx.m4])
 m4_include([../config/depstand.m4])
 m4_include([../config/lead-dot.m4])
 m4_include([../config/override.m4])
 m4_include([../config/warnings.m4])
 m4_include([../config/zlib.m4])
-m4_include([../bfd/acinclude.m4])
 m4_include([../libtool.m4])
 m4_include([../ltoptions.m4])
 m4_include([../ltsugar.m4])
--
2.17.1

Reply | Threaded
Open this post in threaded view
|

[RFA 2/3] libctf: Add configure check for asprintf (for MinGW)

Joel Brobecker
In reply to this post by Joel Brobecker
From: Eli Zaretskii <[hidden email]>

This commit fixes a compilation warning when compiling libctf
on MinGW:

    libctf/ctf-dump.c:118:8: warning: implicit declaration of function
    'asprintf'; did you mean 'vasprintf'? [-Wimplicit-function-declaration]

         if (asprintf (&bit, " %lx: [slice 0x%x:0x%x]",
             ^~~~~~~~
             vasprintf

MinGW doesn't provide that function, so we depend on the one provided
by libiberty. However, the declaration is guarded by HAVE_DECL_ASPRINTF,
which we do not have in libctf's config.h.

libctf/ChangeLog:

        PR binutils/25155:
        * configure.ac: Add AC_CHECK_DECLS([asprintf]).
        * configure, config.h.in: Regenerate.

OK to push to master?

Thanks,
--
Joel

---
 libctf/config.h.in  |  4 +++
 libctf/configure    | 62 +++++++++++++++++++++++++++++++++++++++++++--
 libctf/configure.ac |  2 ++
 3 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/libctf/config.h.in b/libctf/config.h.in
index 4c8be4ab78a..264cbc3e49d 100644
--- a/libctf/config.h.in
+++ b/libctf/config.h.in
@@ -9,6 +9,10 @@
 /* Define to 1 if you have the <byteswap.h> header file. */
 #undef HAVE_BYTESWAP_H
 
+/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
+   don't. */
+#undef HAVE_DECL_ASPRINTF
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
diff --git a/libctf/configure b/libctf/configure
index 66b583fbbe7..e5493b31691 100755
--- a/libctf/configure
+++ b/libctf/configure
@@ -1875,6 +1875,52 @@ $as_echo "$ac_res" >&6; }
   eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_func
+
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
@@ -11385,7 +11431,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11388 "configure"
+#line 11434 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11491,7 +11537,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11494 "configure"
+#line 11540 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12971,6 +13017,18 @@ fi
 done
 
 
+ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" "$ac_includes_default"
+if test "x$ac_cv_have_decl_asprintf" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_ASPRINTF $ac_have_decl
+_ACEOF
+
+
 
 
 
diff --git a/libctf/configure.ac b/libctf/configure.ac
index aa40e4e234b..9c71a270ce0 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -99,6 +99,8 @@ AC_C_BIGENDIAN
 AC_CHECK_HEADERS(byteswap.h endian.h)
 AC_CHECK_FUNCS(pread)
 
+AC_CHECK_DECLS([asprintf])
+
 dnl Check for qsort_r.  (Taken from gnulib.)
 AC_CHECK_FUNCS_ONCE([qsort_r])
 if test $ac_cv_func_qsort_r = yes; then
--
2.17.1

Reply | Threaded
Open this post in threaded view
|

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

Joel Brobecker
In reply to this post by Joel Brobecker
From: Eli Zaretskii <[hidden email]>

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.

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.
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
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.

Rather than second-guess what the CTF developers would prefer,
I'm starting by sending Eli's patch, to see what you guys think.

Thanks,
--
Joel

---
 libctf/ctf-create.c | 4 ++++
 libctf/ctf-subr.c   | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index fa40100c770..84aa4526a30 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -23,6 +23,10 @@
 #include <string.h>
 #include <zlib.h>
 
+#ifndef EOVERFLOW
+#define EOVERFLOW ERANGE
+#endif
+
 #ifndef roundup
 #define roundup(x, y)  ((((x) + ((y) - 1)) / (y)) * (y))
 #endif
diff --git a/libctf/ctf-subr.c b/libctf/ctf-subr.c
index 6bd7f10aeea..cc275c507c9 100644
--- a/libctf/ctf-subr.c
+++ b/libctf/ctf-subr.c
@@ -26,6 +26,10 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifndef ENOTSUP
+#define ENOTSUP ENOSYS
+#endif
+
 int _libctf_version = CTF_VERSION;      /* Library client version.  */
 int _libctf_debug = 0;      /* Debugging messages enabled.  */
 
--
2.17.1

Reply | Threaded
Open this post in threaded view
|

Re: [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Tom Tromey-2
In reply to this post by Joel Brobecker
>>>>> "Joel" == Joel Brobecker <[hidden email]> writes:

Joel> I noticed that if I run "autoreconf" with vanilla automake-1.15.1
Joel> and autoconf-2.69, I get some differences.

Joel> libctf/ChangeLog:

Joel>         * Makefile.in, aclocal.m4: Regenerate.

Joel> I think this one qualifies as obvious, but perhaps I'm missing
Joel> something...

Joel> OK to push to master?

This one looks obvious to me.

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Building libctf on MinGW

Nick Alcock
In reply to this post by Eli Zaretskii
On 17 Dec 2019, Eli Zaretskii stated:

> Hi,
>
> Back in November I built Binutils 2.33 with mingw.org's MinGW, and
> bumped into 3 compilation problems, which I reported on Bugzilla:
>
>   https://sourceware.org/bugzilla/show_bug.cgi?id=25155
>
> There was no response to that report, and these days I've built a
> pretest of GDB 9.1 and bumped into the same problem.

I'm sorry, I didn't notice this report because the component wasn't
"libctf": mea culpa. Clearly I need to be searching subjects as well :)

These should definitely be fixed, but to prevent the recurrence of
things like this I'd like to know how people compile on mingw. I've been
using the Cygwin->mingw cross-compilers, which show none of these
problems, so clearly a *proper* mingw compilation uses something
different. What is it? :)
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Nick Alcock
In reply to this post by Tom Tromey-2
On 2 Jan 2020, Tom Tromey said:

>>>>>> "Joel" == Joel Brobecker <[hidden email]> writes:
>
> Joel> I noticed that if I run "autoreconf" with vanilla automake-1.15.1
> Joel> and autoconf-2.69, I get some differences.
>
> Joel> libctf/ChangeLog:
>
> Joel>         * Makefile.in, aclocal.m4: Regenerate.
>
> Joel> I think this one qualifies as obvious, but perhaps I'm missing
> Joel> something...
>
> Joel> OK to push to master?
>
> This one looks obvious to me.

Agreed (this is also done by my most recent patches under review).

--
NULL && (void)
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 2/3] libctf: Add configure check for asprintf (for MinGW)

Nick Alcock
In reply to this post by Joel Brobecker
On 2 Jan 2020, Joel Brobecker told this:

> From: Eli Zaretskii <[hidden email]>
>
> This commit fixes a compilation warning when compiling libctf
> on MinGW:
>
>     libctf/ctf-dump.c:118:8: warning: implicit declaration of function
>     'asprintf'; did you mean 'vasprintf'? [-Wimplicit-function-declaration]
>
> if (asprintf (&bit, " %lx: [slice 0x%x:0x%x]",
>     ^~~~~~~~
>     vasprintf
>
> MinGW doesn't provide that function, so we depend on the one provided
> by libiberty. However, the declaration is guarded by HAVE_DECL_ASPRINTF,
> which we do not have in libctf's config.h.
>
> libctf/ChangeLog:
>
> PR binutils/25155:
> * configure.ac: Add AC_CHECK_DECLS([asprintf]).
> * configure, config.h.in: Regenerate.

Looks good.
Reply | Threaded
Open this post in threaded view
|

Re: Building libctf on MinGW

Eli Zaretskii
In reply to this post by Nick Alcock
> From: Nick Alcock <[hidden email]>
> Cc: Nick Alcock <[hidden email]>, [hidden email]
> Date: Fri, 03 Jan 2020 15:48:01 +0000
>
> > Back in November I built Binutils 2.33 with mingw.org's MinGW, and
> > bumped into 3 compilation problems, which I reported on Bugzilla:
> >
> >   https://sourceware.org/bugzilla/show_bug.cgi?id=25155
> >
> > There was no response to that report, and these days I've built a
> > pretest of GDB 9.1 and bumped into the same problem.
>
> I'm sorry, I didn't notice this report because the component wasn't
> "libctf": mea culpa.

Sorry, I guess I overlooked libctf in the "component" part.

> These should definitely be fixed, but to prevent the recurrence of
> things like this I'd like to know how people compile on mingw. I've been
> using the Cygwin->mingw cross-compilers, which show none of these
> problems, so clearly a *proper* mingw compilation uses something
> different. What is it? :)

I build Binutils (and GDB) natively on MS-Windows using the MSYS ports
of Bash and Make.  GCC and Binutils are as provided by MinGW for
native compilation and linking.

Thanks.
Reply | Threaded
Open this post in threaded view
|

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

Nick Alcock
In reply to this post by Joel Brobecker
On 2 Jan 2020, Joel Brobecker stated:

> From: Eli Zaretskii <[hidden email]>
>
> 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);
 
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Joel Brobecker
In reply to this post by Nick Alcock
> >>>>>> "Joel" == Joel Brobecker <[hidden email]> writes:
> >
> > Joel> I noticed that if I run "autoreconf" with vanilla automake-1.15.1
> > Joel> and autoconf-2.69, I get some differences.
> >
> > Joel> libctf/ChangeLog:
> >
> > Joel>         * Makefile.in, aclocal.m4: Regenerate.
> >
> > Joel> I think this one qualifies as obvious, but perhaps I'm missing
> > Joel> something...
> >
> > Joel> OK to push to master?
> >
> > This one looks obvious to me.
>
> Agreed (this is also done by my most recent patches under review).

Thank you both. I was going to apply the patch, but Alan's
copyright year update patch also took care of it, somehow.

    commit b3adc24a0713411ab38a21dc894dd40dbc5c8f4f
    Author: Alan Modra <[hidden email]>
    Date:   Wed Jan 1 18:27:01 2020 +1030
    Subject: Update year range in copyright notice of binutils files


--
Joel
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 2/3] libctf: Add configure check for asprintf (for MinGW)

Joel Brobecker
In reply to this post by Nick Alcock
> > libctf/ChangeLog:
> >
> > PR binutils/25155:
> > * configure.ac: Add AC_CHECK_DECLS([asprintf]).
> > * configure, config.h.in: Regenerate.
>
> Looks good.

Thanks, Nick. Pushed to master.

I will also push to gdb-9-branch but I'll email gdb-patches
about that.

--
Joel
Reply | Threaded
Open this post in threaded view
|

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

Joel Brobecker
In reply to this post by Nick Alcock
Hi Nick,

> 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):

I think it makes sense. In fact, it looks very good :-).

Will you let me know when it's pushed to master? We'll want to
cherry-pick the change on gdb-9-branch as well...

Thanks for the reviews and patch!

> 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.  */
[snip snip snip for brievity]

--
Joel
Reply | Threaded
Open this post in threaded view
|

Re: Building libctf on MinGW

Joel Brobecker
In reply to this post by Nick Alcock
> These should definitely be fixed, but to prevent the recurrence of
> things like this I'd like to know how people compile on mingw. I've been
> using the Cygwin->mingw cross-compilers, which show none of these
> problems, so clearly a *proper* mingw compilation uses something
> different. What is it? :)

To make things complicated, my understanding is that one has to know
that there are two MinGW projects:
  - one hosted at mingw.org, which I think is the original project,
    and does not look very active anymore;
  - one hosted at mingw-w64.org, which seems more active and more
    complete; I believe this is the version most users are now using.

Your cross compiler is probably using the same mingw package as
I am, which explains why both of us can't see the error that Eli
is seeing.

--
Joel
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Alan Modra-3
In reply to this post by Joel Brobecker
On Sun, Jan 05, 2020 at 09:43:30AM +0400, Joel Brobecker wrote:
> Thank you both. I was going to apply the patch, but Alan's
> copyright year update patch also took care of it, somehow.
>
>     commit b3adc24a0713411ab38a21dc894dd40dbc5c8f4f
>     Author: Alan Modra <[hidden email]>
>     Date:   Wed Jan 1 18:27:01 2020 +1030
>     Subject: Update year range in copyright notice of binutils files

Yes, I try to avoid applying the copyright update to generated files,
but instead regen them.  That tidies anything like the libctf files
you noticed.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [RFA 1/3] libctf: Regenerate Makefile.in and acinclude.m4

Joel Brobecker
> > Thank you both. I was going to apply the patch, but Alan's
> > copyright year update patch also took care of it, somehow.
> >
> >     commit b3adc24a0713411ab38a21dc894dd40dbc5c8f4f
> >     Author: Alan Modra <[hidden email]>
> >     Date:   Wed Jan 1 18:27:01 2020 +1030
> >     Subject: Update year range in copyright notice of binutils files
>
> Yes, I try to avoid applying the copyright update to generated files,
> but instead regen them.  That tidies anything like the libctf files
> you noticed.

Thanks for that, Alan.

(you are a better man than I am ;-) )

--
Joel
Reply | Threaded
Open this post in threaded view
|

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

Nick Alcock
In reply to this post by Joel Brobecker
On 5 Jan 2020, Joel Brobecker said:

>> 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):
>
> I think it makes sense. In fact, it looks very good :-).
>
> Will you let me know when it's pushed to master? We'll want to
> cherry-pick the change on gdb-9-branch as well...

Will do. It'll probably be Friday at the earliest because I want to
properly test it (including on mingw) which means I have to be near my
Windows machine again.

Sorry for the delay...
Reply | Threaded
Open this post in threaded view
|

Re: Building libctf on MinGW

Nick Alcock
In reply to this post by Eli Zaretskii
On 3 Jan 2020, Eli Zaretskii told this:

> I build Binutils (and GDB) natively on MS-Windows using the MSYS ports
> of Bash and Make.  GCC and Binutils are as provided by MinGW for
> native compilation and linking.

Thanks for the clues: I'll add this to my increasingly enormous
portability test matrix.