[PATCH] readelf: DW_CFA_set_loc operand is an address
by Ben Gamari
Previously this was incorrectly assumed to be an ULEB128. Hilarity
ensued.
This appears to be the case in both DWARF 3, DWARF 4, and LSB 5.
---
src/readelf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 5f6e4ed..7c3237f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4971,7 +4971,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
case DW_CFA_set_loc:
if ((uint64_t) (endp - readp) < 1)
goto invalid;
- get_uleb128 (op1, readp, endp);
+ op1 = read_addr_unaligned_inc (ptr_size, dbg, readp);
op1 += vma_base;
printf (" set_loc %" PRIu64 "\n", op1 * code_align);
break;
--
2.6.2
8 years, 1 month
[PATCH] eblopenback: Warn when unable to find ebl backend
by Ben Gamari
This could have easily saved me three hours.
---
libebl/eblopenbackend.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index b301400..662842d 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -376,7 +376,8 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
result->dlhandle = NULL;
result->elf = elf;
result->name = machines[cnt].prefix;
- fill_defaults (result);
+ fill_defaults (result);
+ fprintf(stderr, "ebl_openbackend: Failed to find backend DSO to handle machine.\n");
return result;
}
--
2.6.2
8 years, 1 month
[PATCH] Add new i386 and x86_64 relocation types.
by Mark Wielaard
Update elf.h from glibc and recognize R_386_GOT32X, R_X86_64_GOTPCRELX
and R_x86_64_REX_GOTPCRELX as non-dynamic relocations.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
backends/ChangeLog | 5 +++++
backends/i386_reloc.def | 1 +
backends/x86_64_reloc.def | 2 ++
libelf/ChangeLog | 4 ++++
libelf/elf.h | 23 ++++++++++++++++++-----
5 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 4b604fd..cc0dd6f 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2015-12-28 Mark Wielaard <mjw(a)redhat.com>
+
+ * i386_reloc.def: Add GOT32X.
+ * x86_64_reloc.def: Add GOTPCRELX and REX_GOTPCRELX.
+
2015-12-08 Jose E. Marchesi <jose.marchesi(a)oracle.com>
* sparc_init.c (sparc_init): Hook sparc_set_initial_registers_tid.
diff --git a/backends/i386_reloc.def b/backends/i386_reloc.def
index de3575d..a6a03f3 100644
--- a/backends/i386_reloc.def
+++ b/backends/i386_reloc.def
@@ -68,3 +68,4 @@ RELOC_TYPE (TLS_GOTDESC, REL)
RELOC_TYPE (TLS_DESC_CALL, REL)
RELOC_TYPE (TLS_DESC, EXEC)
RELOC_TYPE (IRELATIVE, EXEC|DYN)
+RELOC_TYPE (GOT32X, REL)
diff --git a/backends/x86_64_reloc.def b/backends/x86_64_reloc.def
index ad84efa..07a7c3d 100644
--- a/backends/x86_64_reloc.def
+++ b/backends/x86_64_reloc.def
@@ -61,3 +61,5 @@ RELOC_TYPE (GOTPC32_TLSDESC, REL)
RELOC_TYPE (TLSDESC_CALL, REL)
RELOC_TYPE (TLSDESC, REL|EXEC|DYN)
RELOC_TYPE (IRELATIVE, EXEC|DYN)
+RELOC_TYPE (GOTPCRELX, REL)
+RELOC_TYPE (REX_GOTPCRELX, REL)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index aabf6f6..9536ced 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2016-01-28 Mark Wielaard <mjw(a)redhat.com>
+
+ * elf.h: Update from glibc. Add new i386 and x86_64 relocations.
+
2016-01-13 Mark Wielaard <mjw(a)redhat.com>
* libelf.h: Check SHF_COMPRESSED is defined. If not define it and the
diff --git a/libelf/elf.h b/libelf/elf.h
index 12feb91..1a7000b 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -1,5 +1,5 @@
/* This file defines standard ELF types, structures, and macros.
- Copyright (C) 1995-2015 Free Software Foundation, Inc.
+ Copyright (C) 1995-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -1269,8 +1269,10 @@ typedef struct
argument, returning the TLS
offset for the symbol. */
#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */
+#define R_386_GOT32X 43 /* Load from 32 bit GOT entry,
+ relaxable. */
/* Keep this the last entry. */
-#define R_386_NUM 43
+#define R_386_NUM 44
/* SUN SPARC specific definitions. */
@@ -1727,7 +1729,11 @@ typedef struct
PLT is writable. For a non-writable PLT, this is omitted or has a zero
value. */
#define DT_MIPS_RWPLT 0x70000034
-#define DT_MIPS_NUM 0x35
+/* An alternative description of the classic MIPS RLD_MAP that is usable
+ in a PIE as it stores a relative offset from the address of the tag
+ rather than an absolute address. */
+#define DT_MIPS_RLD_MAP_REL 0x70000035
+#define DT_MIPS_NUM 0x36
/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
@@ -3140,8 +3146,15 @@ enum
#define R_X86_64_TLSDESC 36 /* TLS descriptor. */
#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */
#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */
-
-#define R_X86_64_NUM 39
+ /* 39 Reserved was R_X86_64_PC32_BND */
+ /* 40 Reserved was R_X86_64_PLT32_BND */
+#define R_X86_64_GOTPCRELX 41 /* Load from 32 bit signed pc relative
+ offset to GOT entry without REX
+ prefix, relaxable. */
+#define R_X86_64_REX_GOTPCRELX 42 /* Load from 32 bit signed pc relative
+ offset to GOT entry with REX prefix,
+ relaxable. */
+#define R_X86_64_NUM 43
/* AM33 relocations. */
--
1.8.3.1
8 years, 2 months
[PATCH] readelf: Show set_loc argument as hexadecimal
by Ben Gamari
---
src/readelf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/readelf.c b/src/readelf.c
index 7c3237f..446c591 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4973,7 +4973,7 @@ print_cfa_program (const unsigned char *readp, const unsigned char *const endp,
goto invalid;
op1 = read_addr_unaligned_inc (ptr_size, dbg, readp);
op1 += vma_base;
- printf (" set_loc %" PRIu64 "\n", op1 * code_align);
+ printf (" set_loc %" PRIx64 "\n", op1 * code_align);
break;
case DW_CFA_advance_loc1:
if ((uint64_t) (endp - readp) < 1)
--
2.6.2
8 years, 2 months
[PATCH] Move nested functions in elf_compress.c and elf_strptr.c.
by Chih-Hung Hsieh
* elf_compress.c (__libelf_compress): do_deflate_cleanup
* elf_strptr.c (elf_strptr): get_zdata
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libelf/ChangeLog | 7 +++++++
libelf/elf_compress.c | 25 +++++++++++++++----------
libelf/elf_strptr.c | 33 +++++++++++++++++----------------
3 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index aabf6f6..afe6a6a 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-22 Chih-Hung Hsieh <chh(a)google.com>
+
+ * elf_compress.c (__libelf_compress): Move nested function
+ 'do_deflate_cleanup' to file scope to compile with clang.
+ * elf_strptr.c (elf_strptr): Move nested function 'get_zdata'
+ to file scope to compile with clang.
+
2016-01-13 Mark Wielaard <mjw(a)redhat.com>
* libelf.h: Check SHF_COMPRESSED is defined. If not define it and the
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index ec5b717..4c7c35e 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -45,6 +45,21 @@
# define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
+/* Cleanup and return result. Don't leak memory. */
+static void *
+do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
+ int ei_data, Elf_Data *cdatap)
+{
+ deflateEnd (z);
+ free (out_buf);
+ if (ei_data != MY_ELFDATA)
+ free (cdatap->d_buf);
+ return result;
+}
+
+#define deflate_cleanup(result) \
+ do_deflate_cleanup(result, &z, out_buf, ei_data, &cdata)
+
/* Given a section, uses the (in-memory) Elf_Data to extract the
original data size (including the given header size) and data
alignment. Returns a buffer that has at least hsize bytes (for the
@@ -109,16 +124,6 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
Elf_Data cdata;
cdata.d_buf = NULL;
- /* Cleanup and return result. Don't leak memory. */
- void *deflate_cleanup (void *result)
- {
- deflateEnd (&z);
- free (out_buf);
- if (ei_data != MY_ELFDATA)
- free (cdata.d_buf);
- return result;
- }
-
/* Loop over data buffers. */
int flush = Z_NO_FLUSH;
do
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index e3b5876..ea21045 100644
--- a/libelf/elf_strptr.c
+++ b/libelf/elf_strptr.c
@@ -37,6 +37,21 @@
#include "libelfP.h"
+static void *
+get_zdata (Elf_Scn *strscn)
+{
+ size_t zsize, zalign;
+ void *zdata = __libelf_decompress_elf (strscn, &zsize, &zalign);
+ if (zdata == NULL)
+ return NULL;
+
+ strscn->zdata_base = zdata;
+ strscn->zdata_size = zsize;
+ strscn->zdata_align = zalign;
+
+ return zdata;
+}
+
char *
elf_strptr (Elf *elf, size_t idx, size_t offset)
{
@@ -83,20 +98,6 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
}
}
- void *get_zdata (void)
- {
- size_t zsize, zalign;
- void *zdata = __libelf_decompress_elf (strscn, &zsize, &zalign);
- if (zdata == NULL)
- return NULL;
-
- strscn->zdata_base = zdata;
- strscn->zdata_size = zsize;
- strscn->zdata_align = zalign;
-
- return zdata;
- }
-
size_t sh_size = 0;
if (elf->class == ELFCLASS32)
{
@@ -112,7 +113,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
sh_size = shdr->sh_size;
else
{
- if (strscn->zdata_base == NULL && get_zdata () == NULL)
+ if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
goto out;
sh_size = strscn->zdata_size;
}
@@ -138,7 +139,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
sh_size = shdr->sh_size;
else
{
- if (strscn->zdata_base == NULL && get_zdata () == NULL)
+ if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
goto out;
sh_size = strscn->zdata_size;
}
--
2.7.0.rc3.207.g0ac5344
8 years, 2 months
Some Debian elfutils issues
by Mark Wielaard
Hi Kurt,
Thanks for the Debian builds of elfutils-0.165. Sorry for the breakage,
wrt old glibc elf.h system header. But happy to see the simple fix seems
to work.
I looked at the latest build logs:
https://buildd.debian.org/status/package.php?p=elfutils
For the hppa failure we need some hppa hacker to explain whether or not
this is a real issue or not:
elflint /<<PKGBUILDDIR>>/tests/elfstrmerge
section [24] '.plt' is both executable and writable
FAIL run-strip-strmerge.sh (exit status: 1)
Normaly elflint is correct, this would be a bad thing.
The hurd test build issue should be easy to fix with the attached patch.
For the kFreeBSD variants you could start with the second patch to
elflint to at least recognize ELFOSABI_FREEBSD. Although I suspect there
might be more issues. But maybe we are lucky and it really is just like
normal GNU/Linux ELF files since you are using the normal GNU toolchain.
The other issue on kFreeBSD is that we try to run a test that uses the
linux specific dwfl_linux_proc_attach. We should just skip that on none
GNU/Linux platforms like the third attached patch does.
The mips failures are a bit harder to fix since elflint really doesn't
like some of the mips specific issues. We really should import the Debian
mips backend, I am sorry I haven't found time to do all the needed
research.
If you could try the attached patches on a new Debian build that would
be appreciated.
Thanks,
Mark
8 years, 3 months
[PATCH] configure: clarify zlib error message
by Mike Frysinger
Also drop the spurious quotes.
Signed-off-by: Mike Frysinger <vapier(a)gentoo.org>
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 67062ce..9a3301f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -244,7 +244,7 @@ dnl zlib is mandatory.
save_LIBS="$LIBS"
LIBS=
eu_ZIPLIB(zlib,ZLIB,z,gzdirect,gzip)
-AS_IF([test "x$with_zlib" = xno], [AC_MSG_ERROR("zlib not found")])
+AS_IF([test "x$with_zlib" = xno], [AC_MSG_ERROR([zlib not found but is required])])
LIBS="$save_LIBS"
dnl Test for bzlib and xz/lzma, gives BZLIB/LZMALIB .am
--
2.6.2
8 years, 3 months
[PATCH] gitignore: update
by Mike Frysinger
Signed-off-by: Mike Frysinger <vapier(a)gentoo.org>
---
.gitignore | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.gitignore b/.gitignore
index a944762..75043fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,8 @@ Makefile.in
/config/config.sub
/config/depcomp
/config/install-sh
+/config/libdw.pc
+/config/libelf.pc
/config/missing
/config/test-driver
/config/ylwrap
@@ -55,6 +57,7 @@ Makefile.in
/src/addr2line
/src/ar
/src/elfcmp
+/src/elfcompress
/src/elflint
/src/findtextrel
/src/ld
--
2.6.2
8 years, 3 months
[PATCH] libelf: Add ELF compression types and defines to libelf.h for older glibc.
by Mark Wielaard
Older glibc elf.h might not define the new ELF compression defines and
types. If not just define them in libelf.h directly to make the libelf
headers work on older glibc systems.
Also include a testcase to check the libelf headers build against the
system elf.h.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810885
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libelf/ChangeLog | 5 +++++
libelf/libelf.h | 28 ++++++++++++++++++++++++++++
tests/ChangeLog | 8 ++++++++
tests/Makefile.am | 9 +++++++--
tests/system-elf-libelf-test.c | 37 +++++++++++++++++++++++++++++++++++++
5 files changed, 85 insertions(+), 2 deletions(-)
create mode 100644 tests/system-elf-libelf-test.c
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 3a1fe91..aabf6f6 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * libelf.h: Check SHF_COMPRESSED is defined. If not define it and the
+ associated ELF compression types/defines.
+
2015-11-26 Mark Wielaard <mjw(a)redhat.com>
* elf_compress.c (__libelf_decompress_elf): New function, extracted
diff --git a/libelf/libelf.h b/libelf/libelf.h
index 364e776..c0d6389 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -35,6 +35,34 @@
/* Get the ELF types. */
#include <elf.h>
+#ifndef SHF_COMPRESSED
+ /* Older glibc elf.h might not yet define the ELF compression types. */
+ #define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
+
+ /* Section compression header. Used when SHF_COMPRESSED is set. */
+
+ typedef struct
+ {
+ Elf32_Word ch_type; /* Compression format. */
+ Elf32_Word ch_size; /* Uncompressed data size. */
+ Elf32_Word ch_addralign; /* Uncompressed data alignment. */
+ } Elf32_Chdr;
+
+ typedef struct
+ {
+ Elf64_Word ch_type; /* Compression format. */
+ Elf64_Word ch_reserved;
+ Elf64_Xword ch_size; /* Uncompressed data size. */
+ Elf64_Xword ch_addralign; /* Uncompressed data alignment. */
+ } Elf64_Chdr;
+
+ /* Legal values for ch_type (compression algorithm). */
+ #define ELFCOMPRESS_ZLIB 1 /* ZLIB/DEFLATE algorithm. */
+ #define ELFCOMPRESS_LOOS 0x60000000 /* Start of OS-specific. */
+ #define ELFCOMPRESS_HIOS 0x6fffffff /* End of OS-specific. */
+ #define ELFCOMPRESS_LOPROC 0x70000000 /* Start of processor-specific. */
+ #define ELFCOMPRESS_HIPROC 0x7fffffff /* End of processor-specific. */
+#endif
/* Known translation types. */
typedef enum
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 366aea9..234ae56 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2016-01-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * system-elf-libelf-test.c: New test.
+ * Makefile.am (TESTS): Add system-elf-libelf-test, if !STANDALONE.
+ (check_PROGRAMS): Likewise.
+ (system_elf_libelf_test_CPPFLAGS): New variable.
+ (system_elf_libelf_test_LDADD): Likewise.
+
2016-01-08 Mark Wielaard <mjw(a)redhat.com>
* elfputzdata.c (main): Fix parentheses in strncmp test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d09a6d7..f54017e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -136,8 +136,8 @@ export ELFUTILS_DISABLE_DEMANGLE = 1
endif
if !STANDALONE
-check_PROGRAMS += msg_tst md5-sha1-test
-TESTS += msg_tst md5-sha1-test
+check_PROGRAMS += msg_tst md5-sha1-test system-elf-libelf-test
+TESTS += msg_tst md5-sha1-test system-elf-libelf-test
endif
if LZMA
@@ -473,6 +473,11 @@ elfgetzdata_LDADD = $(libelf)
elfputzdata_LDADD = $(libelf)
zstrptr_LDADD = $(libelf)
+# We want to test the libelf headers against the system elf.h header.
+# Don't include any -I CPPFLAGS.
+system_elf_libelf_test_CPPFLAGS =
+system_elf_libelf_test_LDADD = $(libelf)
+
if GCOV
check: check-am coverage
.PHONY: coverage
diff --git a/tests/system-elf-libelf-test.c b/tests/system-elf-libelf-test.c
new file mode 100644
index 0000000..1c5ac3e
--- /dev/null
+++ b/tests/system-elf-libelf-test.c
@@ -0,0 +1,37 @@
+/* Explicit test compiling with system elf.h header plus libelf headers.
+
+ Copyright (C) 2016 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/>. */
+
+#include <elf.h>
+#include <stddef.h>
+#include "../libelf/libelf.h"
+#include "../libelf/gelf.h"
+
+int
+main (void)
+{
+ /* Trivial test, this is really a compile test anyway. */
+ if (elf_version (EV_CURRENT) == EV_NONE)
+ return -1;
+
+ /* This will obviously fail, so ignore the return value. It is just
+ to check that GElf_Chdr and gelf_getchdr are available. */
+ GElf_Chdr chdr;
+ gelf_getchdr (NULL, &chdr);
+
+ return 0;
+}
--
1.8.3.1
8 years, 3 months
elfutils 0.165 code coverage
by Lukas Berk
Hey,
I've been running code coverage for elfutils for the past few releases
(configure'd with --enable-gcov), and have updated the results for 0.165:
https://fedorapeople.org/~lberk/elfutils-coverage/
../../tests/coverage.sh
lib 83.37% covered unused files: 2
libasm 68.28% covered unused files: 9
libdw 78.30% covered unused files: 10
libdwfl 71.05% covered unused files: 4
libebl 49.58% covered unused files: 0
libelf 75.16% covered unused files: 19
backends 0.00% covered unused files: 88
src 66.01% covered unused files: 13
Overall test coverage has increased this past realease, which is
notable, mainly due to the number of lines added to libelf since 0.164.
For comparison/historical sake, I've kept the past runs of the code
coverage on my fedorapeople page (back to 0.158) appended with the
version number, ie;
https://fedorapeople.org/~lberk/elfutils-coverage.0.164/
Cheers,
Lukas
8 years, 3 months