This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH 2/6] libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 22 Oct 2015 00:19:57 +0200
- Subject: [PATCH 2/6] libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
libelf/ChangeLog | 17 +++++
libelf/Makefile.am | 5 +-
libelf/elf32_getchdr.c | 150 +++++++++++++++++++++++++++++++++++++++++++++
libelf/elf64_getchdr.c | 30 +++++++++
libelf/elf_end.c | 6 ++
libelf/elf_error.c | 8 ++-
libelf/gelf.h | 9 +++
libelf/gelf_getchdr.c | 69 +++++++++++++++++++++
libelf/libelf.h | 25 +++++++-
libelf/libelf.map | 7 +++
libelf/libelfP.h | 11 +++-
tests/ChangeLog | 14 +++++
tests/Makefile.am | 10 ++-
tests/elfgetchdr.c | 82 +++++++++++++++++++++++++
tests/msg_tst.c | 5 +-
tests/run-elfgetchdr.sh | 136 ++++++++++++++++++++++++++++++++++++++++
tests/testfile-zgabi32.bz2 | Bin 0 -> 767 bytes
tests/testfile-zgabi64.bz2 | Bin 0 -> 795 bytes
tests/testfile-zgnu32.bz2 | Bin 0 -> 780 bytes
tests/testfile-zgnu64.bz2 | Bin 0 -> 785 bytes
20 files changed, 574 insertions(+), 10 deletions(-)
create mode 100644 libelf/elf32_getchdr.c
create mode 100644 libelf/elf64_getchdr.c
create mode 100644 libelf/gelf_getchdr.c
create mode 100644 tests/elfgetchdr.c
create mode 100755 tests/run-elfgetchdr.sh
create mode 100755 tests/testfile-zgabi32.bz2
create mode 100755 tests/testfile-zgabi64.bz2
create mode 100755 tests/testfile-zgnu32.bz2
create mode 100755 tests/testfile-zgnu64.bz2
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 12dbe0a..932ac1a 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,22 @@
2015-10-14 Mark Wielaard <mjw@redhat.com>
+ * libelf.h (elf32_getchdr): New declaration.
+ (elf64_getchdr): Likewise.
+ * gelf.h (GElf_Chdr): New typedef.
+ (gelf_getchdr): New declaration.
+ * elf32_getchdr.c: New file.
+ * elf64_getchdr.c: New file.
+ * gelf_getchdr.c: New file.
+ * elf_end.c (elf_end): Free chdr.
+ * elf_error.c: Add ELF_E_NOT_COMPRESSED.
+ * libelf.h: Likewise.
+ * Makefile.am (libelf_a_SOURCES): Add elf32_getchdr.c,
+ elf64_getchdr.c and gelf_getchdr.c.
+ * libelf.map (ELFUTILS_1.7): New set. Add elf32_getchdr,
+ elf64_getchdr and gelf_getchdr.
+
+2015-10-14 Mark Wielaard <mjw@redhat.com>
+
* elf.h: Update from glibc. Add section compression constants and
structures.
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index 91a7d07..0a2586e 100644
--- a/libelf/Makefile.am
+++ b/libelf/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to create Makefile.in
##
-## Copyright (C) 1996-2010 Red Hat, Inc.
+## Copyright (C) 1996-2010, 2015 Red Hat, Inc.
## This file is part of elfutils.
##
## This file is free software; you can redistribute it and/or modify
@@ -88,7 +88,8 @@ libelf_a_SOURCES = elf_version.c elf_hash.c elf_error.c elf_fill.c \
elf32_offscn.c elf64_offscn.c gelf_offscn.c \
elf_getaroff.c \
elf_gnu_hash.c \
- elf_scnshndx.c
+ elf_scnshndx.c \
+ elf32_getchdr.c elf64_getchdr.c gelf_getchdr.c
libelf_pic_a_SOURCES =
am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os)
diff --git a/libelf/elf32_getchdr.c b/libelf/elf32_getchdr.c
new file mode 100644
index 0000000..f11843d
--- /dev/null
+++ b/libelf/elf32_getchdr.c
@@ -0,0 +1,150 @@
+/* Return section compression header.
+ Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <libelf.h>
+#include "libelfP.h"
+#include "common.h"
+
+#ifndef LIBELFBITS
+# define LIBELFBITS 32
+#endif
+
+
+ElfW2(LIBELFBITS,Chdr) *
+elfw2(LIBELFBITS,getchdr) (Elf_Scn *scn, int *type)
+{
+ /* Do we have the header already? */
+ ElfW2(LIBELFBITS,Chdr) *chdr = scn->chdr.ELFW(e,LIBELFBITS);
+ if (chdr != NULL)
+ {
+ *type = scn->chdr_type;
+ return chdr != (void *) -1 ? chdr : NULL;
+ }
+
+ ElfW2(LIBELFBITS,Shdr) *shdr;
+ shdr = elfw2(LIBELFBITS,getshdr) (scn);
+ if (shdr == NULL)
+ {
+ error:
+ *type = -1;
+ return NULL;
+ }
+
+ /* Allocated or no bits sections can never be compressed. */
+ if ((shdr->sh_flags & SHF_ALLOC) != 0
+ || shdr->sh_type == SHT_NULL || shdr->sh_type == SHT_NOBITS)
+ goto not_compressed;
+
+ Elf_Data *d;
+ d = elf_getdata (scn, NULL);
+ if (d == NULL)
+ goto error;
+
+ /* Deal with either a real Chdr or the old GNU zlib format. */
+ if (d->d_size >= sizeof (ElfW2(LIBELFBITS,Chdr))
+ && (shdr->sh_flags & SHF_COMPRESSED) != 0)
+ {
+ Elf *elf = scn->elf;
+ ElfW2(LIBELFBITS,Ehdr) *ehdr = elf->state.ELFW(elf,LIBELFBITS).ehdr;
+
+ if (ehdr->e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || ((uintptr_t) scn->rawdata_base
+ & (__alignof__ (ElfW2(LIBELFBITS,Chdr)) - 1)) == 0))
+ {
+ chdr = (ElfW2(LIBELFBITS,Chdr) *)scn->rawdata_base;
+ scn->chdr.ELFW(e,LIBELFBITS) = chdr;
+ }
+ else
+ {
+ scn->chdr.ELFW(e,LIBELFBITS)
+ = malloc (sizeof (ElfW2(LIBELFBITS,Chdr)));
+ chdr = scn->chdr.ELFW(e,LIBELFBITS);
+ if (chdr == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto error;
+ }
+ if (ehdr->e_ident[EI_DATA] == MY_ELFDATA)
+ memcpy (chdr, d->d_buf, sizeof (ElfW2(LIBELFBITS,Chdr)));
+ else
+ {
+ ElfW2(LIBELFBITS,Chdr) *bchdr = d->d_buf;
+ CONVERT_TO (chdr->ch_type, bchdr->ch_type);
+#if LIBELFBITS == 64
+ CONVERT_TO (chdr->ch_reserved, bchdr->ch_reserved);
+#endif
+ CONVERT_TO (chdr->ch_size, bchdr->ch_size);
+ CONVERT_TO (chdr->ch_type, bchdr->ch_type);
+ }
+ }
+ *type = scn->chdr_type = ELF_ZSCN_T_ELF;
+ return chdr;
+ }
+ else if (d->d_size >= 4 + 8
+ && memcmp (d->d_buf, "ZLIB", 4) == 0)
+ {
+ /* There is a 12-byte header of "ZLIB" followed by
+ an 8-byte big-endian size. There is only one type and
+ Alignment isn't preserved separately. */
+ uint64_t size;
+ memcpy (&size, d->d_buf + 4, sizeof size);
+ size = be64toh (size);
+
+ /* One more sanity check, size should be bigger than original
+ data size plus some overhead (4 chars ZLIB + 8 bytes size + 6
+ bytes zlib stream overhead + 5 bytes overhead max for one 16K
+ block) and should fit into a size_t. */
+ if (size + 4 + 8 + 6 + 5 < d->d_size || size > SIZE_MAX)
+ goto not_compressed;
+
+ scn->chdr.ELFW(e,LIBELFBITS) = malloc (sizeof (ElfW2(LIBELFBITS,Chdr)));
+ chdr = scn->chdr.ELFW(e,LIBELFBITS);
+ if (chdr == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto error;
+ }
+
+ *type = scn->chdr_type = ELF_ZSCN_T_GNU;
+ chdr->ch_type = ELFCOMPRESS_ZLIB;
+ chdr->ch_size = size;
+ chdr->ch_addralign = shdr->sh_addralign;
+ return chdr;
+ }
+
+not_compressed:
+ scn->chdr.ELFW(e,LIBELFBITS) = (void *) -1;
+ *type = scn->chdr_type = ELF_ZSCN_T_NONE;
+ __libelf_seterrno (ELF_E_NOT_COMPRESSED);
+ return NULL;
+}
diff --git a/libelf/elf64_getchdr.c b/libelf/elf64_getchdr.c
new file mode 100644
index 0000000..6588b79
--- /dev/null
+++ b/libelf/elf64_getchdr.c
@@ -0,0 +1,30 @@
+/* Return section compression header.
+ Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define LIBELFBITS 64
+#include "elf32_getchdr.c"
diff --git a/libelf/elf_end.c b/libelf/elf_end.c
index 7ea876c..3d5ed57 100644
--- a/libelf/elf_end.c
+++ b/libelf/elf_end.c
@@ -150,6 +150,12 @@ elf_end (Elf *elf)
/* It doesn't matter which pointer. */
free (scn->shdr.e32);
+ void *chdr = (elf->class == ELFCLASS32
+ ? (void *) scn->chdr.e32
+ : (void *) scn->chdr.e64);
+ if (chdr != (void *) -1 && chdr != scn->data_base)
+ free (chdr);
+
/* If the file has the same byte order and the
architecture doesn't require overly stringent
alignment the raw data buffer is the same as the
diff --git a/libelf/elf_error.c b/libelf/elf_error.c
index d6bdaab..9618da4 100644
--- a/libelf/elf_error.c
+++ b/libelf/elf_error.c
@@ -230,6 +230,11 @@ core files")
(ELF_E_NO_PHDR_IDX \
+ sizeof "file has no program header")
N_("invalid offset")
+ "\0"
+#define ELF_E_NOT_COMPRESSED_IDX \
+ (ELF_E_INVALID_OFFSET_IDX \
+ + sizeof "invalid offset")
+ N_("section does not contain compressed data")
};
@@ -277,7 +282,8 @@ static const uint_fast16_t msgidx[ELF_E_NUM] =
[ELF_E_GROUP_NOT_REL] = ELF_E_GROUP_NOT_REL_IDX,
[ELF_E_INVALID_PHDR] = ELF_E_INVALID_PHDR_IDX,
[ELF_E_NO_PHDR] = ELF_E_NO_PHDR_IDX,
- [ELF_E_INVALID_OFFSET] = ELF_E_INVALID_OFFSET_IDX
+ [ELF_E_INVALID_OFFSET] = ELF_E_INVALID_OFFSET_IDX,
+ [ELF_E_NOT_COMPRESSED] = ELF_E_NOT_COMPRESSED_IDX
};
#define nmsgidx ((int) (sizeof (msgidx) / sizeof (msgidx[0])))
diff --git a/libelf/gelf.h b/libelf/gelf.h
index e3f0740..cf9dc40 100644
--- a/libelf/gelf.h
+++ b/libelf/gelf.h
@@ -85,6 +85,8 @@ typedef Elf64_Rela GElf_Rela;
/* Program segment header. */
typedef Elf64_Phdr GElf_Phdr;
+typedef Elf64_Chdr GElf_Chdr;
+
/* Dynamic section entry. */
typedef Elf64_Dyn GElf_Dyn;
@@ -183,6 +185,13 @@ extern int gelf_update_phdr (Elf *__elf, int __ndx, GElf_Phdr *__src);
/* Create new program header with PHNUM entries. */
extern unsigned long int gelf_newphdr (Elf *__elf, size_t __phnum);
+/* Get compression header and compression type of section data, if
+ any. Returns NULL and sets __TYPE to -1 on failure. When the
+ section data isn't compressed __TYPE is set to ELF_ZSCN_T_NONE and
+ NULL is returned. Otherwise __DEST is returned and __TYPE is
+ set. */
+extern GElf_Chdr *gelf_getchdr (Elf_Scn *__scn, GElf_Chdr *__dst, int *__type);
+
/* Convert data structure from the representation in the file represented
by ELF to their memory representation. */
diff --git a/libelf/gelf_getchdr.c b/libelf/gelf_getchdr.c
new file mode 100644
index 0000000..239ac42
--- /dev/null
+++ b/libelf/gelf_getchdr.c
@@ -0,0 +1,69 @@
+/* Return section compression header.
+ Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libelfP.h"
+#include <gelf.h>
+#include <stddef.h>
+
+
+GElf_Chdr *
+gelf_getchdr (Elf_Scn *scn, GElf_Chdr *dest, int *type)
+{
+ if (scn == NULL)
+ return NULL;
+
+ if (dest == NULL || type == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ return NULL;
+ }
+
+ if (scn->elf->class == ELFCLASS32)
+ {
+ Elf32_Chdr *chdr = elf32_getchdr (scn, type);
+ if (chdr == NULL)
+ return NULL;
+ dest->ch_type = chdr->ch_type;
+ dest->ch_size = chdr->ch_size;
+ dest->ch_addralign = chdr->ch_addralign;
+ }
+ else
+ {
+ Elf64_Chdr *chdr = elf64_getchdr (scn, type);
+ if (chdr == NULL)
+ return NULL;
+ *dest = *chdr;
+ }
+
+ return dest;
+}
+INTDEF(gelf_getchdr)
diff --git a/libelf/libelf.h b/libelf/libelf.h
index 54f7c29..72a11c7 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -1,5 +1,5 @@
/* Interface for libelf.
- Copyright (C) 1998-2010 Red Hat, Inc.
+ Copyright (C) 1998-2010, 2015 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -128,6 +128,15 @@ typedef enum
ELF_K_NUM
} Elf_Kind;
+/* Different compression types a section can have. */
+
+typedef enum
+{
+ ELF_ZSCN_T_NONE, /* No compression. */
+ ELF_ZSCN_T_GNU, /* Old GNU style (Always uses ZLIB, no real Chdr). */
+ ELF_ZSCN_T_ELF, /* ELF style (with Chdr giving compression type). */
+ ELF_ZSCN_T_NUM /* Number of different compression types. */
+} Elf_ZScn_Type;
/* Archive member header. */
typedef struct
@@ -267,6 +276,20 @@ extern Elf32_Shdr *elf32_getshdr (Elf_Scn *__scn);
/* Similar for ELFCLASS64. */
extern Elf64_Shdr *elf64_getshdr (Elf_Scn *__scn);
+/* Returns compression header for a section if section data is
+ compressed. Returns the compression type (Elf_ZScn_Type) in
+ __TYPE. If the type is ELF_ZSCN_T_GNU then the returned
+ compression header is artificial (since the old GNU style
+ compressed section data didn't contain a real header). The ch_type
+ of such an artificial header is always ELFCOMPRESS_ZLIB and the
+ ch_addralign equals the sh_addralign of the Shdr of the section.
+ If an error occurs NULL is returned and __TYPE will be -1.
+ Allocated or no bits sections are never compressed. Requesting the
+ Chdr for a section that isn't compressed returns NULL and sets
+ __TYPE to ELF_ZSCN_T_NONE, elf_errno will be set to indicate the
+ section wasn't compressed. */
+extern Elf32_Chdr *elf32_getchdr (Elf_Scn *__scn, int *__type);
+extern Elf64_Chdr *elf64_getchdr (Elf_Scn *__scn, int *__type);
/* Set or clear flags for ELF file. */
extern unsigned int elf_flagelf (Elf *__elf, Elf_Cmd __cmd,
diff --git a/libelf/libelf.map b/libelf/libelf.map
index de6d912..8525294 100644
--- a/libelf/libelf.map
+++ b/libelf/libelf.map
@@ -138,3 +138,10 @@ ELFUTILS_1.6 {
global:
elf_getphdrnum;
} ELFUTILS_1.5;
+
+ELFUTILS_1.7 {
+ global:
+ elf32_getchdr;
+ elf64_getchdr;
+ gelf_getchdr;
+} ELFUTILS_1.6;
diff --git a/libelf/libelfP.h b/libelf/libelfP.h
index 993c655..3adbed7 100644
--- a/libelf/libelfP.h
+++ b/libelf/libelfP.h
@@ -1,5 +1,5 @@
/* Internal interfaces for libelf.
- Copyright (C) 1998-2010 Red Hat, Inc.
+ Copyright (C) 1998-2010, 2015 Red Hat, Inc.
This file is part of elfutils.
Contributed by Ulrich Drepper <drepper@redhat.com>, 1998.
@@ -138,6 +138,7 @@ enum
ELF_E_INVALID_PHDR,
ELF_E_NO_PHDR,
ELF_E_INVALID_OFFSET,
+ ELF_E_NOT_COMPRESSED,
/* Keep this as the last entry. */
ELF_E_NUM
};
@@ -208,6 +209,14 @@ struct Elf_Scn
Elf_Data_Scn rawdata; /* Uninterpreted data of the section. */
+ union
+ { /* 32/64bit Chdr used for section data. */
+ Elf32_Chdr *e32; /* NULL means not accessed yet. */
+ Elf64_Chdr *e64; /* Might point at data_base or is malloced. */
+ } chdr; /* -1 means not compressed. Check ch_type. */
+
+ int chdr_type; /* ELF_ZSCN_T_{NONE,GNU,ELF} chdr != NULL. */
+
int data_read; /* Nonzero if the section was created by the
user or if the data from the file/memory
is read. */
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 1913fbb..16f8144 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,17 @@
+2015-10-14 Mark Wielaard <mjw@redhat.com>
+
+ * msg_tst.c: Add ELF_E_NOT_COMPRESSED.
+ * run-elfgetchdr.sh: New test.
+ * testfile-zgnu32.bz2: New testfile.
+ * testfile-zgnu64.bz2: Likewise.
+ * testfile-zgabi32.bz2: Likewise.
+ * testfile-zgabi64.bz2: Likewise.
+ * Makefile.am (check_PROGRAMS): Add elfgetchdr.
+ (TESTS): Add run-elfgetchdr.sh.
+ (EXTRA_DIST): Add run-elfgetchdr.sh, testfile-zgnu32.bz2,
+ testfile-zgnu64.bz2, testfile-zgabi32.bz2 and testfile-zgabi64.bz2.
+ (elfgetchdr_LDADD): New variable.
+
2015-10-16 Mark Wielaard <mjw@redhat.com>
* Makefile.am (dwfl_proc_attach_LDFLAGS): Add AM_LDFLAGS.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e04707c..d252f1c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,7 +52,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
backtrace-data backtrace-dwarf debuglink debugaltlink \
buildid deleted deleted-lib.so aggregate_size vdsosyms \
getsrc_die strptr newdata elfstrtab dwfl-proc-attach \
- elfshphehdr elfstrmerge
+ elfshphehdr elfstrmerge elfgetchdr
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -120,7 +120,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \
run-linkmap-cut.sh run-aggregate-size.sh vdsosyms run-readelf-A.sh \
run-getsrc-die.sh run-strptr.sh newdata elfstrtab dwfl-proc-attach \
- elfshphehdr run-lfs-symbols.sh
+ elfshphehdr run-lfs-symbols.sh run-elfgetchdr.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -304,7 +304,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
testfile-x32-core.bz2 testfile-x32.bz2 \
backtrace.x32.core.bz2 backtrace.x32.exec.bz2 \
testfile-x32-s.bz2 testfile-x32-d.bz2 testfile-x32-debug.bz2 \
- run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2
+ run-lfs-symbols.sh lfs-symbols testfile-nolfs.bz2 \
+ testfile-zgnu32.bz2 testfile-zgnu64.bz2 \
+ testfile-zgabi32.bz2 testfile-zgabi64.bz2 \
+ run-elfgetchdr.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --error-exitcode=1 --run-libc-freeres=no'
@@ -453,6 +456,7 @@ dwfl_proc_attach_LDADD = $(libdw)
dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS)
elfshphehdr_LDADD =$(libelf)
elfstrmerge_LDADD = $(libebl) $(libelf)
+elfgetchdr_LDADD = $(libelf)
if GCOV
check: check-am coverage
diff --git a/tests/elfgetchdr.c b/tests/elfgetchdr.c
new file mode 100644
index 0000000..2bd58c0
--- /dev/null
+++ b/tests/elfgetchdr.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libelf.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ elf_version (EV_CURRENT);
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+
+ Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
+ if (elf == NULL)
+ {
+ printf ("%s not usable %s\n", argv[cnt], elf_errmsg (-1));
+ result = 1;
+ close (fd);
+ continue;
+ }
+
+ Elf_Scn *scn = NULL;
+ while ((scn = elf_nextscn (elf, scn)) != NULL)
+ {
+ int idx = elf_ndxscn (scn);;
+ GElf_Chdr chdr;
+ int chdr_type;
+ if (gelf_getchdr (scn, &chdr, &chdr_type) != NULL)
+ {
+ assert (chdr_type != ELF_ZSCN_T_NONE);
+ printf ("section %d: %s Compressed ch_type: %" PRId32
+ ", ch_size: %" PRIx64 ", ch_addralign: %" PRIx64 "\n",
+ idx, chdr_type == ELF_ZSCN_T_ELF ? "ELF" : "GNU",
+ chdr.ch_type, chdr.ch_size, chdr.ch_addralign);
+ }
+ else if (chdr_type != -1)
+ {
+ assert (chdr_type == ELF_ZSCN_T_NONE);
+ printf ("section %d: NOT Compressed %s\n", idx, elf_errmsg (-1));
+ }
+ else
+ printf ("section %d: gelf_getchdr error %s\n", idx,
+ elf_errmsg (-1));
+ }
+
+ elf_end (elf);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/msg_tst.c b/tests/msg_tst.c
index 10ff0f7..38f57f3 100644
--- a/tests/msg_tst.c
+++ b/tests/msg_tst.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
+/* Copyright (C) 2002, 2005, 2006, 2015 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -74,7 +74,8 @@ static struct
"program header only allowed in executables, shared objects, \
and core files" },
{ ELF_E_NO_PHDR, "file has no program header" },
- { ELF_E_INVALID_OFFSET, "invalid offset" }
+ { ELF_E_INVALID_OFFSET, "invalid offset" },
+ { ELF_E_NOT_COMPRESSED, "section does not contain compressed data" }
};
diff --git a/tests/run-elfgetchdr.sh b/tests/run-elfgetchdr.sh
new file mode 100755
index 0000000..3266ef1
--- /dev/null
+++ b/tests/run-elfgetchdr.sh
@@ -0,0 +1,136 @@
+#! /bin/sh
+# Copyright (C) 2015 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# = funcs.s =
+# .globl testfunc
+# testfunc:
+# nop
+# ret
+# .type testfunc, @function
+# .size testfunc, .-testfunc
+#
+# .globl testfunc2
+# testfunc2:
+# call testfunc
+# nop
+# nop
+# ret
+# .type testfunc2, @function
+# .size testfunc2, .-testfunc2
+#
+# .globl functest3
+# functest3:
+# jmp local
+# nop
+# nop
+# local:
+# call testfunc2
+# ret
+# .type functest3, @function
+# .size functest3, .-functest3
+
+# = start.s =
+# .global _start
+# _start:
+# call functest3
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# nop
+# ret
+# .type _start, @function
+# .size _start, .-_start
+
+# gas --compress-debug-sections=zlib-gnu -32 -g -o start.o start.s
+# gas --compress-debug-sections=zlib-gnu -32 -g -o funcs.o funcs.s
+# ld --compress-debug-sections=zlib-gnu -melf_i386 -g -o zgnu32 funcs.o start.o
+
+# gas --compress-debug-sections=zlib-gnu -64 -g -o start.o start.s
+# gas --compress-debug-sections=zlib-gnu -64 -g -o funcs.o funcs.s
+# ld --compress-debug-sections=zlib-gnu -g -o zgnu32 funcs.o start.o
+
+# gas --compress-debug-sections=zlib-gabi -32 -g -o start.o start.s
+# gas --compress-debug-sections=zlib-gabi -32 -g -o funcs.o funcs.s
+# ld --compress-debug-sections=zlib-gabi -melf_i386 -g -o zgabi32 funcs.o start.o
+
+# gas --compress-debug-sections=zlib-gabi -64 -g -o start.o start.s
+# gas --compress-debug-sections=zlib-gabi -64 -g -o funcs.o funcs.s
+# ld --compress-debug-sections=zlib-gabi -g -o zgabi64 funcs.o start.o
+
+testfiles testfile-zgnu64
+testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu64 <<\EOF
+section 1: NOT Compressed section does not contain compressed data
+section 2: GNU Compressed ch_type: 1, ch_size: 60, ch_addralign: 10
+section 3: GNU Compressed ch_type: 1, ch_size: aa, ch_addralign: 1
+section 4: NOT Compressed section does not contain compressed data
+section 5: GNU Compressed ch_type: 1, ch_size: 8d, ch_addralign: 1
+section 6: NOT Compressed section does not contain compressed data
+section 7: NOT Compressed section does not contain compressed data
+section 8: NOT Compressed section does not contain compressed data
+EOF
+
+testfiles testfile-zgabi64
+testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi64 <<\EOF
+section 1: NOT Compressed section does not contain compressed data
+section 2: ELF Compressed ch_type: 1, ch_size: 60, ch_addralign: 10
+section 3: ELF Compressed ch_type: 1, ch_size: aa, ch_addralign: 1
+section 4: NOT Compressed section does not contain compressed data
+section 5: ELF Compressed ch_type: 1, ch_size: 8d, ch_addralign: 1
+section 6: NOT Compressed section does not contain compressed data
+section 7: NOT Compressed section does not contain compressed data
+section 8: NOT Compressed section does not contain compressed data
+EOF
+
+testfiles testfile-zgnu32
+testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgnu32 <<\EOF
+section 1: NOT Compressed section does not contain compressed data
+section 2: GNU Compressed ch_type: 1, ch_size: 40, ch_addralign: 8
+section 3: GNU Compressed ch_type: 1, ch_size: 9a, ch_addralign: 1
+section 4: NOT Compressed section does not contain compressed data
+section 5: GNU Compressed ch_type: 1, ch_size: 85, ch_addralign: 1
+section 6: NOT Compressed section does not contain compressed data
+section 7: NOT Compressed section does not contain compressed data
+section 8: NOT Compressed section does not contain compressed data
+EOF
+
+testfiles testfile-zgabi32
+testrun_compare ${abs_top_builddir}/tests/elfgetchdr testfile-zgabi32 <<\EOF
+section 1: NOT Compressed section does not contain compressed data
+section 2: ELF Compressed ch_type: 1, ch_size: 40, ch_addralign: 8
+section 3: ELF Compressed ch_type: 1, ch_size: 9a, ch_addralign: 1
+section 4: NOT Compressed section does not contain compressed data
+section 5: ELF Compressed ch_type: 1, ch_size: 85, ch_addralign: 1
+section 6: NOT Compressed section does not contain compressed data
+section 7: NOT Compressed section does not contain compressed data
+section 8: NOT Compressed section does not contain compressed data
+EOF
+
+exit 0
diff --git a/tests/testfile-zgabi32.bz2 b/tests/testfile-zgabi32.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..6159dbcea3a74cc1851ac69e8d985d3224b9fe3f
GIT binary patch
literal 767
zcmV<b0s#F&T4*^jL0KkKSu?W*00050|NsB@{V8s7d~EmpWmW(8|9$6Wcs(<4h;aTe
z5FikJ=rF(nGl7hZHB3r+Owu%H(0Z8-83CXH=?sQ|Gy_0nXaS~%fEo=LjRQ?I$QqiO
zG>n98A(KNRO&S0V0iXZ?00000003wJ03g#N38PFP#4$9$5s{`LiGUL(011$2zyJ}G
z36lU!BLt?Rnx^#x^){o_)6`~w6DB5src6vs6B9#CFeVcqWYEBx01X%dG|0&#AtP84
z2+AmAh{6?1>!;MnfJ-$c%yXTxV0GETe=$D)H(|(ZxHGvVfDVf&lp`3&`J{fB4hRJ#
zWt^rf;I8rX36>`i)Po&r?#x3kkiZ1WdJ-Ix9E5<5n2RCQDJF^0I*4%o;GjSyDw&*_
zA~I$QWD(a)C#B4OOb;U!Oti;XaBDNa-_Nh;Je^sV<cA!Lp^g9*b)K|u`D=@WIvQBz1z
zAkO>aKl=ljr6^~I{$!3b(HjqI*Gs9!4c+G#sfu7zA_!>QO(I1T*)Tlqh&l#$so>MB
zCWR5x!t_(ch~r^F#F)p1Ps=N7Qa(%df0E!*#+xh1fZ;_y5z2Tm`4pejY68R&jtcJv
z3V?iGVu>UThy#KEi;~}vH-3v#;lEO0+Qinmn!XI-DS)>_#uZ!b?)k=KN1Kvl&XVYI
zcrgc=9`#e0c8<b=hGp_`qXG_iIprKyp3zEj%P3_qMNn3AQY42c3s8nOh;+G*P!6~Z
zgQlizUWiCE5I{S#jRt);*)d6>;=nhC5TnNp9^s-ig8^vf8KF3UK=8}C$W>&!h~a3E
zslbNN2H-Rw%9-l5xPv?4xTTF9RiOm5*k)nRy)0Lhz{-U-saEpkx{#Y~Y;-4gpp5&%
z4ZwoK3Kt1|JW`<Q1EVX5)iGC{vm(a)-XG?+AFJ$UNg&5IAYM_jM`Us(a)6+VhouHPnU(J
x5(a)fLs)tWGq0%19=(faJX>8_VVz=f!nIAj-AL5RFEq~iaJxgwk>NEz9JfB?<JRQUh^
literal 0
HcmV?d00001
diff --git a/tests/testfile-zgabi64.bz2 b/tests/testfile-zgabi64.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..3b44f089e98c7fe7f90969cbbefbca5d8a16c36a
GIT binary patch
literal 795
zcmV+$1LXWdT4*^jL0KkKSwf>T@&EzcfB*k~{cnC*dPo0UO(_58-}tj`bSHOEd`9o2
z7zTBCrZ&I=90EiYH87LZ{YIvkO$`HTG|<8g0BAG;qfImb292TyhCl(ML7)eudYWxd
zQ2-elX{II-iIIt;O)@etBLZLu(WXWwfr2zLFhe5~0x$qf2mr{_O))TxOpHw$X_1kE
z7!v?SjWRJb3=yG`f*BZ?5r6_<5}Kxv)bvbA;+PptG{`hygFrOXPe?Q#riM*4$kC%f
zWFDhKL7|`;001U};A;hb{Aj`zK81A|M7&D~BuA$);<a{EMD*FL{Y>Q~N{<g+k8OQZ
zwM3-f=@m84&3P)XEi3zrxOW!yfaJu41)ZzF!;(T(sghxvZFxn_U2S!C`A~)!Yb9TK
zby}KxL=GUCpF;@)2{KKjLr*{i!82(a)D9xg64CR(V}L2r?h)E$(n(a)g(9{>&=G)Md{J8
z;Tl>ZrExv>#+y8LL>HquUpxblMMMH(m5B3wQBQMeP8fyKxJC*L<@UL+!hNYts%H`e
z8Oe;q&DuqRXmVaKL{7+f(u)ro>C#Y8#4L-`+l1(>Mob23JD#b|A{keX4t+(dnu;wQ
z0lXh(xp7N=YL7Bh1j2Tl4M-^#=5v!qLySIdDC$62yrKfVcgQOM9)ti_2KC|Y#G?Kh
zp$WSE(n)3!hAlG@#$}5v<mK5tkFdj_$gCf(>RK7^7L&Co{7Ee9>&hKtzVPv^dU|Rf
zEZP*{u^K+Fh4gu(>vP_5Q2`5k)&yL(a)iTA+s87Zvd_=BSTNJ34N($qv%))V~UqZYz`
z1dRH~T&4PBgv|mrgy{0$uSCKL^5Ba6p$_V-y0SDcdJ~9d5u6diP)Boaop?xUIMW`4
z>SnHDu#pB$bk^XB2cG&$mgx-`3XB{crG5W8SpXn{+b?QDku3zT$LpIpD_A9_lN3(a)P
z85`aa?w`5Yi9<-p_IMk|gAt`rA03fx4Gb18K9E6zO&7`<AnDpHJP(a)hn4v9gQi02TZ
Z%-Q_&a*{Ly1>#@g?ntK!5(rdgen5r;U~B*Y
literal 0
HcmV?d00001
diff --git a/tests/testfile-zgnu32.bz2 b/tests/testfile-zgnu32.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..9d622cad1739554cbf744ed471936a5b470a1148
GIT binary patch
literal 780
zcmV+n1M~bsT4*^jL0KkKSrTWQ^8f*#fB*mY{V8v8d(a)c9vWp)4e|9$6Wcs(<4h;aTe
z5FikJ=rF(n7&(9jrb#_2eiC|*LYQqS>6F@@ri}nJ(<9Vrw15E9)bfX^p`+A#gCVDq
z4(a)u=brbdrVH8xQO69i<yOafq-ATR(4fC+#RrVzwnBSsN~(V!VJWCog4$RU$J(@Cai
zJs<|AYB4Yb!enXcVlsLFj0vUyOaKX^0GJvns$}&v(9p(a)FLqKRW(U8P4XaE2MAPoS-
zGz@?M27m#}asxKZGK?5R5Ji21Q5yEQp)t=CDGIUfz~cARS5HPYDIDn^z*Io^;ucCG
zHtw5j1JVN%5M<aEaQzS(kf4#HkdcQ~U5_4t5gwNWlu%JfBnd+C+JOL;D8wQZF?0(h
z0WOF(a)r3nv6KpG%Mlpc^!E8?J&1<>d*V&OQFa-<(wM2O-fvjV(_WuK~}L`}JT+6*v?
z(a)PvLx6jkqXsEz0tj@aqIVi|>*F}7JmQeNKp2q8)VtOh|gNf!B(%@PR61Pg#*GZ0}Q
zh?tN~AhiHqgPs-vA>?X*jD})!yxK9i7U!mx(?AX7^f8ha0Kr}l#gkYiY0&P?TsWqz
zgPku?abrnHwn9;J$q4Hcd1g7jrm|~MR^X|eXh=RcYH!v?t21DCzSShq&|M!(*$p0#
znI6VpOnc$iSR|^Dice_i$5>Moj2M!7vitt+OyG&}EO38S%?@!YnnO&6(ZVN{qyws|
zGzk|UeDRR8U@$Om5aE9mVfe=ZFw!V7PrIK9WkqBMYXv(a)w1-v=R!XW5n=U7tC0tu{D
z(a)51bza!6+ME|4m=1(a)H}vxWAo!+Znwvoc$Xaf;P37800QW!|ru3Jg58d#|dOd(a)igw6
z`IfS>^ZO3bs3pqHF+dyyj2?s!?G_Tazec-uIe9~Sndh~#cDxZWqrsIkBZnGB&e}OK
zHlE)MBE?jULAULAI+1SNVLi0$3x5~em;RCdo^-MyT)<$CHOCUDGHPo>2rNs#@pmLs
Kg$V&BdCxGFj#bD2
literal 0
HcmV?d00001
diff --git a/tests/testfile-zgnu64.bz2 b/tests/testfile-zgnu64.bz2
new file mode 100755
index 0000000000000000000000000000000000000000..1bc2c0906a4f2404d2df2b6e8aa6e096665ae2ba
GIT binary patch
literal 785
zcmV+s1Md7nT4*^jL0KkKSz)bY&;S9*|NsAg{cnDGdPCoQOgR7N-|)9?bS8IDd`9o2
z7zTBCrZ&I=8-Zrb6eJT(rlFdeWc3XXQ%w(1p`g$PjWjfApfU{r4Kf;Or>M{X05r+9
zG|B29WMVX6O&JCOG-;s084Ltq6C+GaOh$~1AkmP(CYS&d6A(2|Q$Y<iG}A*Nrhw2g
zG&BGjXwVG+0MGyc003wJ001OXMwHJ&hMOcFlhpLo&<&}kK+wnlHlP|BXwVt~pc)MT
z0000B9Rr$@2_y;e9?^JK(a)+lRwy39}0Bo#9AK4d}dW1Dv`6m~*9j{iwEDa>xjg)bd_
zUdu<RxT+JHCa@~!;F5(a)Abq0j5FLm)OzKZ8fD4Syd0abQaw>eg+DPevzr7;bpn;Th1
zsW1Y}X<fT%hAY9r!mzfjhsfs<VmnFZ1l$UmLhj?;3KKA-6pW3!*1S1d!A1`H07Sxz
zGqVT<cT8*Q&c3SOsU)*OS_<i-AMGDQb!i&Ep_5YyOC6&XhgqVY!Ub`ZIIt*>d&0Vk
zbEm&G2DtWbB8?LmmNPp(n>dMQD*7a#I6UVB8<{ZlAaTx&AJ>QmVwM^25)Mp{<kGvS
z#~|**b7PfIwnve1AXl%Dg2zG#bxUsQIZjDb;rdl9*FjW~kbo5frXVaujV=gNsA})C
zw9az0jD#@str2VCht9cq(<4YydvVe94Y3(a)ciZBcZ3;<{K6(a)lsM3apwOKcp1;-Y7&^
z*b*;$uOCz;{p<M*My=!U-Y#sp;UPyPa}q>`^kC)#xfr(3)Zb{d#KWOL89(a)ojL5W^u
z8jxfbHicM{3;_da7Nanl<N3(Jb0C?3PzC(a)gRP{DwgQ|X}>UO7*2zC>Aglp#qA*#rP
zr35q4TDw?1pr<H+d(Nkm{f1ld0t4t?il)m1ug$6Z2FaC)M2<gFUX=ng816Q2H(a)K*n
zR7a_46XY26m0)=3?c6jRn$ztB3`FV)L1KDIql=OU45bk<Fr~~RZ6P+snE2O-ngEH~
PKjQ94rwS4bHLRKdHyTwY
literal 0
HcmV?d00001
--
1.8.3.1