+2009-08-26 Roland McGrath <roland@redhat.com>
+
+ * configure.ac (zip_LIBS): Check for liblzma too.
+
2009-04-19 Roland McGrath <roland@redhat.com>
* configure.ac (eu_version): Round down here, not in version.h macros.
dwarf_attr_integrate to look up indirect inherited attributes.
libdwfl: Support Linux bzip2 kernel images for automatic decompression.
+ Support automatic decompression of files in XZ format.
Version 0.142:
dnl conditional and config.h USE_ZLIB/USE_BZLIB #define.
save_LIBS="$LIBS"
LIBS=
-eu_ZIPLIB(z,Z,z,gzdirect,gzip)
-eu_ZIPLIB(bz,BZ,bz2,BZ2_bzdopen,bzip2)
+eu_ZIPLIB(zlib,ZLIB,z,gzdirect,gzip)
+eu_ZIPLIB(bzlib,BZLIB,bz2,BZ2_bzdopen,bzip2)
+eu_ZIPLIB(lzma,LZMA,lzma,lzma_auto_decoder,[LZMA (xz)])
zip_LIBS="$LIBS"
LIBS="$save_LIBS"
AC_SUBST([zip_LIBS])
2009-08-26 Roland McGrath <roland@redhat.com>
+ * open.c [USE_LZMA]: Try __libdw_unlzma.
+ * libdwflP.h: Declare it.
+ (DWFL_ERRORS): Add DWFL_E_LZMA.
+ * gzip.c [LZMA]: Implement liblzma version for XZ file format.
+ * lzma.c: New file.
+ * Makefile.am [LZMA] (libdwfl_a_SOURCES): Add it.
+
* gzip.c (mapped_zImage): Limit scan to 32kb.
Make this unconditional, support bzip2 kernel images too.
(unzip): Use direct inflate method for non-mmap case too.
if BZLIB
libdwfl_a_SOURCES += bzip2.c
endif
+if LZMA
+libdwfl_a_SOURCES += lzma.c
+endif
if MUDFLAP
libdwfl = libdwfl.a $(libdw) $(libebl) $(libelf) $(libeu)
#include <unistd.h>
-#ifdef BZLIB
+#ifdef LZMA
+# define USE_INFLATE 1
+# include <lzma.h>
+# define unzip __libdw_unlzma
+# define DWFL_E_ZLIB DWFL_E_LZMA
+# define MAGIC "\xFD" "7zXZ\0"
+# define Z(what) LZMA_##what
+# define LZMA_ERRNO LZMA_PROG_ERROR
+# define z_stream lzma_stream
+# define inflateInit(z) lzma_auto_decoder (z, 1 << 30, 0)
+# define do_inflate(z) lzma_code (z, LZMA_RUN)
+# define inflateEnd(z) lzma_end (z)
+#elif defined BZLIB
# define USE_INFLATE 1
# include <bzlib.h>
# define unzip __libdw_bunzip2
# define BZ_ERRNO BZ_IO_ERROR
# define z_stream bz_stream
# define inflateInit(z) BZ2_bzDecompressInit (z, 0, 0)
-# define inflate(z, f) BZ2_bzDecompress (z)
+# define do_inflate(z) BZ2_bzDecompress (z)
# define inflateEnd(z) BZ2_bzDecompressEnd (z)
-# define gzFile BZFILE *
-# define gzdopen BZ2_bzdopen
-# define gzread BZ2_bzread
-# define gzclose BZ2_bzclose
-# define gzerror BZ2_bzerror
#else
# define USE_INFLATE 0
# define crc32 loser_crc32
}
inline void smaller_buffer (size_t end)
{
- buffer = realloc (buffer, end) ?: buffer;
+ buffer = realloc (buffer, end) ?: end == 0 ? NULL : buffer;
size = end;
}
z_stream z = { .next_in = mapped, .avail_in = mapped_size };
int result = inflateInit (&z);
if (result != Z (OK))
- return zlib_fail (result);
+ {
+ inflateEnd (&z);
+ return zlib_fail (result);
+ }
do
{
{
ssize_t n = pread_retry (fd, input_buffer, READ_SIZE, input_pos);
if (unlikely (n < 0))
- return zlib_fail (Z (IO_ERROR));
+ {
+ inflateEnd (&z);
+ return zlib_fail (Z (ERRNO));
+ }
z.next_in = input_buffer;
z.avail_in = n;
input_pos += n;
z.avail_out = size - pos;
}
}
- while ((result = inflate (&z, Z_SYNC_FLUSH)) == Z (OK));
+ while ((result = do_inflate (&z)) == Z (OK));
#ifdef BZLIB
uint64_t total_out = (((uint64_t) z.total_out_hi32 << 32)
DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)")) \
DWFL_ERROR (ZLIB, N_("gzip decompression failed")) \
DWFL_ERROR (BZLIB, N_("bzip2 decompression failed")) \
+ DWFL_ERROR (LZMA, N_("LZMA decompression failed")) \
DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine")) \
DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file")) \
DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type")) \
void *mapped, size_t mapped_size,
void **whole, size_t *whole_size)
internal_function;
-extern Dwfl_Error __libdw_bunzip2 (int fd, off64_t start_offset,
- void *mapped, size_t mapped_size,
- void **whole, size_t *whole_size)
+extern Dwfl_Error __libdw_bunzip2 (int fd, off64_t start_offset,
+ void *mapped, size_t mapped_size,
+ void **whole, size_t *whole_size)
+ internal_function;
+extern Dwfl_Error __libdw_unlzma (int fd, off64_t start_offset,
+ void *mapped, size_t mapped_size,
+ void **whole, size_t *whole_size)
internal_function;
/* Open Elf handle on *FDP. This handles decompression and checks
--- /dev/null
+/* liblzma is pretty close to zlib and bzlib. */
+
+#define LZMA
+#include "gzip.c"
# define __libdw_bunzip2(...) false
#endif
+#if !USE_LZMA
+# define __libdw_unlzma(...) false
+#endif
+
/* Always consumes *ELF, never consumes FD.
Replaces *ELF on success. */
static Dwfl_Error
void *buffer = NULL;
size_t size = 0;
-#if USE_ZLIB || USE_BZLIB
+#if USE_ZLIB || USE_BZLIB || USE_LZMA
const off64_t offset = (*elf)->start_offset;
void *const mapped = ((*elf)->map_address == NULL ? NULL
: (*elf)->map_address + (*elf)->start_offset);
error = __libdw_gunzip (fd, offset, mapped, mapped_size, &buffer, &size);
if (error == DWFL_E_BADELF)
error = __libdw_bunzip2 (fd, offset, mapped, mapped_size, &buffer, &size);
+ if (error == DWFL_E_BADELF)
+ error = __libdw_unlzma (fd, offset, mapped, mapped_size, &buffer, &size);
#endif
elf_end (*elf);
+2009-08-26 Roland McGrath <roland@redhat.com>
+
+ * zip.m4 (eu_ZIPLIB): Don't apply lib/LIB suffix to args.
+
2009-02-01 Roland McGrath <roland@redhat.com>
* zip.m4: Fix --with/--without argument handling.
dnl -*- Autoconf -*- test for either zlib or bzlib.
-dnl Defines --with-$1lib argument, $2LIB automake conditional,
-dnl and sets AC_DEFINE(USE_$2LIB) and LIBS.
+dnl Defines --with-$1 argument, $2 automake conditional,
+dnl and sets AC_DEFINE(USE_$2) and LIBS.
AC_DEFUN([eu_ZIPLIB], [dnl
-AC_ARG_WITH([[$1]lib],
-AC_HELP_STRING([--with-[$1]lib], [support g[$1]ip compression in libdwfl]),,
- [with_[$1]lib=default])
-if test $with_[$1]lib != no; then
- AC_SEARCH_LIBS([$4], [$3], [with_[$1]lib=yes],
- [test $with_[$1]lib = default ||
- AC_MSG_ERROR([missing -l[$3] for --with-[$1]lib])])
+AC_ARG_WITH([[$1]],
+AC_HELP_STRING([--with-[$1]], [support [$1] compression in libdwfl]),,
+ [with_[$1]=default])
+if test $with_[$1] != no; then
+ AC_SEARCH_LIBS([$4], [$3], [with_[$1]=yes],
+ [test $with_[$1] = default ||
+ AC_MSG_ERROR([missing -l[$3] for --with-[$1]])])
fi
-AM_CONDITIONAL([$2]LIB, test $with_[$1]lib = yes)
-if test $with_[$1]lib = yes; then
- AC_DEFINE(USE_[$2]LIB)
+AM_CONDITIONAL([$2], test $with_[$1] = yes)
+if test $with_[$1] = yes; then
+ AC_DEFINE(USE_[$2])
fi
-AH_TEMPLATE(USE_[$2]LIB, [Support $5 decompression via -l$3.])])
+AH_TEMPLATE(USE_[$2], [Support $5 decompression via -l$3.])])