From 08eb167b40d66da3b4a3a21351a8ed5b99fc3a83 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 24 Mar 2012 11:38:02 -0400 Subject: always build our libelf, as our libdwarf doesn't get along with the system libelf on linux --- Makefile.am | 13 ++++++++++++- configure.ac | 4 +++- libelf/_libelf.h | 1 + libelf/elf_errmsg.c | 4 ++++ libelf/elf_scn.c | 3 +++ libelf/elf_strptr.c | 2 +- libelf/elf_update.c | 2 +- libelf/libelf_convert.m4 | 18 +++++++----------- libelf/libelf_fsize.m4 | 9 ++------- libelf/libelf_msize.m4 | 10 ++++++---- 10 files changed, 40 insertions(+), 26 deletions(-) diff --git a/Makefile.am b/Makefile.am index 53dc0ca..be5afd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,18 @@ libpctf_la_SOURCES += \ libelf/libelf.c libelf/libelf_align.c libelf/libelf_allocate.c \ libelf/libelf_ar.c libelf/libelf_ar_util.c libelf/libelf_checksum.c \ libelf/libelf_data.c libelf/libelf_ehdr.c libelf/libelf_extended.c \ - libelf/libelf_phdr.c libelf/libelf_shdr.c libelf/libelf_xlate.c + libelf/libelf_phdr.c libelf/libelf_shdr.c libelf/libelf_xlate.c \ + libelf/libelf_fsize.c libelf/libelf_msize.c libelf/libelf_convert.c + +libelf/libelf_fsize.c: libelf/libelf_fsize.m4 + m4 libelf/libelf_fsize.m4 > libelf/libelf_fsize.c + +libelf/libelf_msize.c: libelf/libelf_msize.m4 + m4 libelf/libelf_msize.m4 > libelf/libelf_msize.c + +libelf/libelf_convert.c: libelf/libelf_convert.m4 + m4 libelf/libelf_convert.m4 > libelf/libelf_convert.c + endif ctfdump_SOURCES = dump/dump.c diff --git a/configure.ac b/configure.ac index 101b4f2..9f76c61 100644 --- a/configure.ac +++ b/configure.ac @@ -19,12 +19,14 @@ AC_CHECK_TYPE(uchar_t, unsigned char) AC_CHECK_FUNCS([ \ getexecname \ getprogname \ +strlcpy \ ]) AC_CHECK_LIB(z, uncompress) AC_CHECK_LIB(elf, gelf_getshdr, [],[ build_gelf=true ]) + build_gelf=true AM_CONDITIONAL([BUILD_ELF], [test "$build_gelf" = true]) AC_CHECK_LIB(dwarf, dwarf_elf_init, [], [ @@ -34,12 +36,12 @@ AM_CONDITIONAL([BUILD_DWARF], [test "$build_dwarf" = true]) AC_CHECK_LIB(pthread, pthread_create) +#gelf.h \ AC_CHECK_HEADERS([ \ ctype.h \ dwarf.h \ errno.h \ fcntl.h \ -gelf.h \ libdwarf.h \ libgen.h \ limits.h \ diff --git a/libelf/_libelf.h b/libelf/_libelf.h index 8367f2e..eb86f17 100644 --- a/libelf/_libelf.h +++ b/libelf/_libelf.h @@ -58,6 +58,7 @@ extern struct _libelf_globals _libelf; #define LIBELF_ELF_ERROR_MASK 0xFF #define LIBELF_OS_ERROR_SHIFT 8 +#define ROUNDUP2(V,N) (V) = ((((V) + (N) - 1)) & ~((N) - 1)) #define LIBELF_SET_ERROR(E, O) do { \ LIBELF_PRIVATE(error) = ((ELF_E_##E & LIBELF_ELF_ERROR_MASK)| \ diff --git a/libelf/elf_errmsg.c b/libelf/elf_errmsg.c index d6787b1..9fd96bb 100644 --- a/libelf/elf_errmsg.c +++ b/libelf/elf_errmsg.c @@ -69,6 +69,10 @@ elf_errmsg(int error) if (error < 0 || error >= ELF_E_NUM) return _libelf_errors[ELF_E_NUM]; if (oserr) { +#if !HAVE_STRLCPY +# define strlcpy strncpy +# define strlcat(dst, src, len) strcat(dst, src) +#endif strlcpy(LIBELF_PRIVATE(msg), _libelf_errors[error], sizeof(LIBELF_PRIVATE(msg))); strlcat(LIBELF_PRIVATE(msg), ": ", sizeof(LIBELF_PRIVATE(msg))); diff --git a/libelf/elf_scn.c b/libelf/elf_scn.c index 8a2cec0..75d9bf2 100644 --- a/libelf/elf_scn.c +++ b/libelf/elf_scn.c @@ -82,8 +82,11 @@ _libelf_load_scn(Elf *e, void *ehdr) i = 0; if (!STAILQ_EMPTY(&e->e_u.e_elf.e_scn)) { +#ifndef __linux__ + /* something in here expands to "struct" and breaks compilation */ assert(STAILQ_FIRST(&e->e_u.e_elf.e_scn) == STAILQ_LAST(&e->e_u.e_elf.e_scn, _Elf_Scn, s_next)); +#endif i = 1; src += fsz; diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c index e2ac7c6..586372f 100644 --- a/libelf/elf_strptr.c +++ b/libelf/elf_strptr.c @@ -100,7 +100,7 @@ elf_strptr(Elf *e, size_t scndx, size_t offset) LIBELF_SET_ERROR(DATA, 0); return (NULL); } - count = roundup2(count, alignment); + count = ROUNDUP2(count, alignment); } if (offset < count) { diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 284ff8d..9ae5a09 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -151,7 +151,7 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc) if ((uint64_t) d->d_off + d->d_size > scn_size) scn_size = d->d_off + d->d_size; } else { - scn_size = roundup2(scn_size, d->d_align); + scn_size = ROUNDUP2(scn_size, d->d_align); d->d_off = scn_size; scn_size += d->d_size; } diff --git a/libelf/libelf_convert.m4 b/libelf/libelf_convert.m4 index 3a8bb8d..4e6b833 100644 --- a/libelf/libelf_convert.m4 +++ b/libelf/libelf_convert.m4 @@ -24,6 +24,7 @@ * SUCH DAMAGE. */ +#if 0 #include __FBSDID("$FreeBSD: src/lib/libelf/libelf_convert.m4,v 1.4.2.3.2.1 2010/12/21 17:09:25 kensmith Exp $"); @@ -35,6 +36,7 @@ __FBSDID("$FreeBSD: src/lib/libelf/libelf_convert.m4,v 1.4.2.3.2.1 2010/12/21 17 #include #include #include +#endif #include "_libelf.h" @@ -197,8 +199,6 @@ __FBSDID("$FreeBSD: src/lib/libelf/libelf_convert.m4,v 1.4.2.3.2.1 2010/12/21 17 (P) = (P) + EI_NIDENT; \ } while (0) -#define ROUNDUP2(V,N) (V) = ((((V) + (N) - 1)) & ~((N) - 1)) - divert(-1) /* @@ -222,7 +222,7 @@ divert(-1) * treated as being potentially unaligned and no casting can be done. */ -include(SRCDIR`/elf_types.m4') +include(`libelf/elf_types.m4') /* * `IGNORE'_* flags turn off generation of template code. @@ -465,7 +465,7 @@ libelf_cvt$3_$1_tom(char *dst, size_t dsz, char *src, size_t count, */ define(`MAKE_TYPE_CONVERTER', - `#if __FreeBSD_version >= $3 /* $1 */ + `/* $1 */ ifdef(`BASE'_$1, `ifdef(`IGNORE_'$1,`', `MAKEPRIM_TO_F($1,$2,`',64) @@ -479,7 +479,7 @@ ifdef(`BASE'_$1, MAKE_TO_F($1,$2,64)dnl MAKE_TO_M($1,$2,32)dnl MAKE_TO_M($1,$2,64)')') -#endif /* $1 */ +/* $1 */ ') define(`MAKE_TYPE_CONVERTERS', @@ -507,7 +507,6 @@ libelf_cvt_BYTE_tox(char *dst, size_t dsz, char *src, size_t count, MAKE_TYPE_CONVERTERS(ELF_TYPE_LIST) -#if __FreeBSD_version >= 800062 /* * Sections of type ELF_T_GNUHASH start with a header containing 4 32-bit * words. Bloom filter data comes next, followed by hash buckets and the @@ -701,7 +700,6 @@ libelf_cvt64_GNUHASH_tof(char *dst, size_t dsz, char *src, size_t srcsz, return (1); } -#endif /* * Elf_Note structures comprise a fixed size header followed by variable @@ -847,11 +845,11 @@ define(`CONV', define(`CONVERTER_NAME', `ifdef(`IGNORE_'$1,`', - `#if __FreeBSD_version >= $3 + ` [ELF_T_$1] = { CONV($1,32,tof), CONV($1,32,tom), CONV($1,64,tof), CONV($1,64,tom) }, -#endif + ')') define(`CONVERTER_NAMES', @@ -875,14 +873,12 @@ CONVERTER_NAMES(ELF_TYPE_LIST) .tom64 = libelf_cvt_BYTE_tox }, -#if __FreeBSD_version >= 800062 [ELF_T_GNUHASH] = { .tof32 = libelf_cvt32_GNUHASH_tof, .tom32 = libelf_cvt32_GNUHASH_tom, .tof64 = libelf_cvt64_GNUHASH_tof, .tom64 = libelf_cvt64_GNUHASH_tom }, -#endif [ELF_T_NOTE] = { .tof32 = libelf_cvt_NOTE_tof, diff --git a/libelf/libelf_fsize.m4 b/libelf/libelf_fsize.m4 index fcfbfc2..1ab0d10 100644 --- a/libelf/libelf_fsize.m4 +++ b/libelf/libelf_fsize.m4 @@ -26,9 +26,6 @@ * $FreeBSD: src/lib/libelf/libelf_fsize.m4,v 1.2.10.2.2.1 2010/12/21 17:09:25 kensmith Exp $ */ -#include -#include - #include "_libelf.h" /* @@ -36,7 +33,7 @@ */ divert(-1) -include(SRCDIR`/elf_types.m4') +include(`libelf/elf_types.m4') /* * Translations from structure definitions to the size of their file @@ -118,9 +115,7 @@ DEFINE_ELF_FSIZES(ELF_TYPE_LIST) DEFINE_ELF_FSIZE(`IDENT',`') # `IDENT' is a pseudo type define(`FSIZE', - `#if __FreeBSD_version >= $3 - [ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 }, -#endif') + `[ELF_T_$1] = { .fsz32 = $1_SIZE32, .fsz64 = $1_SIZE64 },') define(`FSIZES', `ifelse($#,1,`', `FSIZE($1) diff --git a/libelf/libelf_msize.m4 b/libelf/libelf_msize.m4 index 7035843..c0272e9 100644 --- a/libelf/libelf_msize.m4 +++ b/libelf/libelf_msize.m4 @@ -24,6 +24,8 @@ * SUCH DAMAGE. */ +#include "_libelf.h" +#if 0 #include __FBSDID("$FreeBSD: src/lib/libelf/libelf_msize.m4,v 1.2.10.2.2.1 2010/12/21 17:09:25 kensmith Exp $"); @@ -35,8 +37,8 @@ __FBSDID("$FreeBSD: src/lib/libelf/libelf_msize.m4,v 1.2.10.2.2.1 2010/12/21 17: #include #include #include +#endif -#include "_libelf.h" /* WARNING: GENERATED FROM __file__. */ @@ -46,7 +48,7 @@ struct msize { }; divert(-1) -include(SRCDIR`/elf_types.m4') +include(`libelf/elf_types.m4') define(BYTE_SIZE, 1) define(GNUHASH_SIZE, 1) @@ -75,9 +77,9 @@ define(`DEFINE_ELF_MSIZES', DEFINE_ELF_MSIZES(ELF_TYPE_LIST) define(`MSIZE', - `#if __FreeBSD_version >= $3 + ` [ELF_T_$1] = { .msz32 = $1_SIZE32, .msz64 = $1_SIZE64 }, -#endif') +') define(`MSIZES', `ifelse($#,1,`', `MSIZE($1) -- cgit v1.2.3