This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH v2 00/19] libctf, and CTF support for objdump and readelf
On 28 May 2019, Christophe Lyon stated:
> On Tue, 28 May 2019 at 18:39, Jose E. Marchesi <jose.marchesi@oracle.com> wrote:
>>
>>
>> > Nick Alcock (19):
>> > include: new header ctf.h: file format description
>> > include: new header ctf-api.h
>> > libctf: lowest-level memory allocation and debug-dumping wrappers
>> > libctf: low-level list manipulation and helper utilities
>> > libctf: error handling
>> > libctf: hashing
>> > libctf: implementation definitions related to file creation
>> > libctf: creation functions
>> > libctf: opening
>> > libctf: ELF file opening via BFD
>> > libctf: core type lookup
>> > libctf: lookups by name and symbol
>> > libctf: type copying
>> > libctf: library version enforcement
>> > libctf: mmappable archives
>> > libctf: labels
>> > libctf: debug dumping
>> > libctf: build system
>> > binutils: CTF support for objdump and readelf
>>
>> Patch series approved (all of it) - please apply.
>>
>> Just pushed it in behalf of Nix, with the additions you suggested.
>> Thanks!
>
>
> One of the patches in the series broke the build for --target arm-pe:
> ../libctf/libctf.a(ctf-open-bfd.o): In function `ctf_bfdopen_ctfsect':
> /home/tcwg-buildslave/workspace/tcwg-binutils/bfd/--enable-64-bit-bfd=no/label/tcwg-x86_64-cam/target/arm-pe/build-arm-pe/libctf/../../libctf/ctf-open-bfd.c:136:
> undefined reference to `bfd_section_from_elf_index'
> /home/tcwg-buildslave/workspace/tcwg-binutils/bfd/--enable-64-bit-bfd=no/label/tcwg-x86_64-cam/target/arm-pe/build-arm-pe/libctf/../../libctf/ctf-open-bfd.c:145:
> undefined reference to `bfd_section_from_elf_index'
>
> Can you check & fix?
Very sorry about that. My non-ELF platform of choice was mingw, which I
now see pulls in the ELF bfd stuff! Ironically I had all the necessary
ifdefs in place for the non-ELF builds but was intentionally trimming
them out of the copy synced to binutils...
I am testing the fix below (on lots more targets, this time, so it might
be a few hours). I hope the build system fiddling is right. It was... a
bit counterintuitive, although all the changes made sense in hindsight.
I tested mingw, x86_64-pc-linux-gnu and arm-pe by hand and it seems to
work on all three.
commit e23cfedad4f85235337d485b5c51bdcda92565ef
Author: Nick Alcock <nick.alcock@oracle.com>
Date: Tue May 28 22:24:01 2019 +0100
Fix libctf build on non-ELF targets.
All machinery works as on ELF, except for automatic loading of ELF
string and symbol tables in the BFD-style open machinery.
* Makefile.def (dependencies): configure-libctf depends on all-bfd
and all its deps.
* Makefile.in: Regenerated.
libctf/
* configure.in: Check for bfd_section_from_elf_index.
* configure: Regenerate.
* config.h.in [HAVE_BFD_ELF]: Likewise.
* libctf/ctf_open_bfd (ctf_bfdopen_ctfsect): Use it.
abfd is potentially unused now.
diff --git a/ChangeLog b/ChangeLog
index f57f4fe2f9..cbfb2155c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+
+ * Makefile.def (dependencies): configure-libctf depends on all-bfd
+ and all its deps.
+ * Makefile.in: Regenerated.
+
2019-05-28 Nick Alcock <nick.alcock@oracle.com>
* MAINTAINERS: Add libctf.
diff --git a/Makefile.def b/Makefile.def
index 3aa03b45d3..e3a94f2c7d 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -522,6 +522,11 @@ dependencies = { module=all-fastjar; on=all-libiberty; };
dependencies = { module=all-libctf; on=all-libiberty; hard=true; };
dependencies = { module=all-libctf; on=all-bfd; };
dependencies = { module=all-libctf; on=all-zlib; };
+// So that checking for ELF support in BFD from libctf configure is possible.
+dependencies = { module=configure-libctf; on=all-bfd; };
+dependencies = { module=configure-libctf; on=all-intl; };
+dependencies = { module=configure-libctf; on=all-zlib; };
+dependencies = { module=configure-libctf; on=all-libiconv; };
// Warning, these are not well tested.
dependencies = { module=all-bison; on=all-intl; };
diff --git a/Makefile.in b/Makefile.in
index 68675f0479..e4b6051b1a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50930,6 +50930,34 @@ all-stage3-libctf: maybe-all-stage3-zlib
all-stage4-libctf: maybe-all-stage4-zlib
all-stageprofile-libctf: maybe-all-stageprofile-zlib
all-stagefeedback-libctf: maybe-all-stagefeedback-zlib
+configure-libctf: maybe-all-bfd
+configure-stage1-libctf: maybe-all-stage1-bfd
+configure-stage2-libctf: maybe-all-stage2-bfd
+configure-stage3-libctf: maybe-all-stage3-bfd
+configure-stage4-libctf: maybe-all-stage4-bfd
+configure-stageprofile-libctf: maybe-all-stageprofile-bfd
+configure-stagefeedback-libctf: maybe-all-stagefeedback-bfd
+configure-libctf: maybe-all-intl
+configure-stage1-libctf: maybe-all-stage1-intl
+configure-stage2-libctf: maybe-all-stage2-intl
+configure-stage3-libctf: maybe-all-stage3-intl
+configure-stage4-libctf: maybe-all-stage4-intl
+configure-stageprofile-libctf: maybe-all-stageprofile-intl
+configure-stagefeedback-libctf: maybe-all-stagefeedback-intl
+configure-libctf: maybe-all-zlib
+configure-stage1-libctf: maybe-all-stage1-zlib
+configure-stage2-libctf: maybe-all-stage2-zlib
+configure-stage3-libctf: maybe-all-stage3-zlib
+configure-stage4-libctf: maybe-all-stage4-zlib
+configure-stageprofile-libctf: maybe-all-stageprofile-zlib
+configure-stagefeedback-libctf: maybe-all-stagefeedback-zlib
+configure-libctf: maybe-all-libiconv
+configure-stage1-libctf: maybe-all-stage1-libiconv
+configure-stage2-libctf: maybe-all-stage2-libiconv
+configure-stage3-libctf: maybe-all-stage3-libiconv
+configure-stage4-libctf: maybe-all-stage4-libiconv
+configure-stageprofile-libctf: maybe-all-stageprofile-libiconv
+configure-stagefeedback-libctf: maybe-all-stagefeedback-libiconv
all-bison: maybe-all-build-texinfo
all-flex: maybe-all-build-bison
all-flex: maybe-all-m4
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index a4fd3b17ba..879aeed38f 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,3 +1,11 @@
+2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+
+ * configure.in: Check for bfd_section_from_elf_index.
+ * configure: Regenerate.
+ * config.h.in [HAVE_BFD_ELF]: Likewise.
+ * libctf/ctf_open_bfd (ctf_bfdopen_ctfsect): Use it.
+ abfd is potentially unused now.
+
2019-05-28 Nick Alcock <nick.alcock@oracle.com>
* Makefile.am: New.
diff --git a/libctf/config.h.in b/libctf/config.h.in
index 8d87b3d08a..829201033e 100644
--- a/libctf/config.h.in
+++ b/libctf/config.h.in
@@ -1,5 +1,8 @@
/* config.h.in. Generated from configure.ac by autoheader. */
+/* Whether libbfd was configured for an ELF target. */
+#undef HAVE_BFD_ELF
+
/* Define to 1 if you have the <byteswap.h> header file. */
#undef HAVE_BYTESWAP_H
diff --git a/libctf/configure b/libctf/configure
index 2213393673..1c0340125a 100755
--- a/libctf/configure
+++ b/libctf/configure
@@ -5974,6 +5974,114 @@ $as_echo "#define HAVE_MMAP 1" >>confdefs.h
fi
rm -f conftest.mmap conftest.txt
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
+$as_echo_n "checking for library containing dlopen... " >&6; }
+if ${ac_cv_search_dlopen+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' dl; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_dlopen=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_dlopen+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_dlopen+:} false; then :
+
+else
+ ac_cv_search_dlopen=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
+$as_echo "$ac_cv_search_dlopen" >&6; }
+ac_res=$ac_cv_search_dlopen
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
+# Similar to GDB_AC_CHECK_BFD.
+OLD_CFLAGS=$CFLAGS
+OLD_LDFLAGS=$LDFLAGS
+OLD_LIBS=$LIBS
+# Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
+# points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
+# always want our bfd.
+CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
+ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
+LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
+intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
+LIBS="-lbfd -liberty -lz $intl $LIBS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ELF support in BFD" >&5
+$as_echo_n "checking for ELF support in BFD... " >&6; }
+if ${ac_cv_libctf_bfd_elf+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <stdlib.h>
+ #include "bfd.h"
+ #include "elf-bfd.h"
+int
+main ()
+{
+(void) bfd_section_from_elf_index (NULL, 0);
+ return 0;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_libctf_bfd_elf=yes
+else
+ ac_cv_libctf_bfd_elf=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libctf_bfd_elf" >&5
+$as_echo "$ac_cv_libctf_bfd_elf" >&6; }
+CFLAGS=$OLD_CFLAGS
+LDFLAGS=$OLD_LDFLAGS
+LIBS=$OLD_LIBS
+
+if test $ac_cv_libctf_bfd_elf = yes; then
+
+$as_echo "#define HAVE_BFD_ELF 1" >>confdefs.h
+
+fi
+
for ac_header in byteswap.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "byteswap.h" "ac_cv_header_byteswap_h" "$ac_includes_default"
diff --git a/libctf/configure.ac b/libctf/configure.ac
index 2d0cf86bb7..2df10935c0 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -55,6 +55,37 @@ AM_MAINTAINER_MODE
ACX_PROG_CC_WARNING_OPTS([-Wall], [ac_libctf_warn_cflags])
AC_FUNC_MMAP
+AC_SEARCH_LIBS(dlopen, dl)
+
+# Similar to GDB_AC_CHECK_BFD.
+OLD_CFLAGS=$CFLAGS
+OLD_LDFLAGS=$LDFLAGS
+OLD_LIBS=$LIBS
+# Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
+# points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
+# always want our bfd.
+CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
+ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
+LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
+intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
+LIBS="-lbfd -liberty -lz $intl $LIBS"
+AC_CACHE_CHECK([for ELF support in BFD], ac_cv_libctf_bfd_elf,
+[AC_TRY_LINK([#include <stdlib.h>
+ #include "bfd.h"
+ #include "elf-bfd.h"],
+ [(void) bfd_section_from_elf_index (NULL, 0);
+ return 0;],
+ [ac_cv_libctf_bfd_elf=yes],
+ [ac_cv_libctf_bfd_elf=no])])
+CFLAGS=$OLD_CFLAGS
+LDFLAGS=$OLD_LDFLAGS
+LIBS=$OLD_LIBS
+
+if test $ac_cv_libctf_bfd_elf = yes; then
+ AC_DEFINE([HAVE_BFD_ELF], 1,
+ [Whether libbfd was configured for an ELF target.])
+fi
+
AC_CHECK_HEADERS(byteswap.h)
AC_CHECK_FUNCS(pread)
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
index d6d442ea42..5e34d12369 100644
--- a/libctf/ctf-open-bfd.c
+++ b/libctf/ctf-open-bfd.c
@@ -119,7 +119,8 @@ ctf_bfdopen (struct bfd *abfd, int *errp)
later. */
ctf_archive_t *
-ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
+ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+ const ctf_sect_t *ctfsect, int *errp)
{
struct ctf_archive *arc = NULL;
ctf_archive_t *arci;
@@ -129,6 +130,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
const char *bfderrstr = NULL;
int is_archive;
+#ifdef HAVE_BFD_ELF
asection *sym_asect;
ctf_sect_t symsect, strsect;
/* TODO: handle SYMTAB_SHNDX. */
@@ -178,6 +180,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
symsectp = &symsect;
}
}
+#endif
if (ctfsect->cts_size > sizeof (uint64_t) &&
((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC))
@@ -203,9 +206,11 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
if (arci)
return arci;
err_free_sym:
+#ifdef HAVE_BFD_ELF
free ((void *) symsect.cts_data);
err_free_str:
free ((void *) strsect.cts_data);
+#endif
err: _libctf_unused_;
if (bfderrstr)
{