[PATCH] libdwfl: Don't crash on out of memory when frame unwinding.
by Mark Wielaard
new_unwound didn't check whether malloc was successful. Check that we
could allocate memory before use and return DWFL_E_NOMEM otherwise.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdwfl/ChangeLog | 6 ++++++
libdwfl/frame_unwind.c | 23 ++++++++++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index cc8eec7..903c0cc 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * frame_unwind.c (new_unwound): Check and return unwound.
+ (handle_cfi): Check new_unwound was able to allocate new memory
+ before use. Return DWFL_E_NOMEM otherwise.
+
2016-02-11 Mark Wielaard <mjw(a)redhat.com>
* relocate.c (relocate_section): Check result of all gelf_get* calls.
diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c
index 0e470b9..a885446 100644
--- a/libdwfl/frame_unwind.c
+++ b/libdwfl/frame_unwind.c
@@ -1,5 +1,5 @@
/* Get previous frame state for an existing frame state.
- Copyright (C) 2013, 2014 Red Hat, Inc.
+ Copyright (C) 2013, 2014, 2016 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -511,7 +511,7 @@ expr_eval (Dwfl_Frame *state, Dwarf_Frame *frame, const Dwarf_Op *ops,
#undef pop
}
-static void
+static Dwfl_Frame *
new_unwound (Dwfl_Frame *state)
{
assert (state->unwound == NULL);
@@ -522,6 +522,8 @@ new_unwound (Dwfl_Frame *state)
assert (nregs > 0);
Dwfl_Frame *unwound;
unwound = malloc (sizeof (*unwound) + sizeof (*unwound->regs) * nregs);
+ if (unlikely (unwound == NULL))
+ return NULL;
state->unwound = unwound;
unwound->thread = thread;
unwound->unwound = NULL;
@@ -529,6 +531,7 @@ new_unwound (Dwfl_Frame *state)
unwound->initial_frame = false;
unwound->pc_state = DWFL_FRAME_STATE_ERROR;
memset (unwound->regs_set, 0, sizeof (unwound->regs_set));
+ return unwound;
}
/* The logic is to call __libdwfl_seterrno for any CFI bytecode interpretation
@@ -545,8 +548,14 @@ handle_cfi (Dwfl_Frame *state, Dwarf_Addr pc, Dwarf_CFI *cfi, Dwarf_Addr bias)
__libdwfl_seterrno (DWFL_E_LIBDW);
return;
}
- new_unwound (state);
- Dwfl_Frame *unwound = state->unwound;
+
+ Dwfl_Frame *unwound = new_unwound (state);
+ if (unwound == NULL)
+ {
+ __libdwfl_seterrno (DWFL_E_NOMEM);
+ return;
+ }
+
unwound->signal_frame = frame->fde->cie->signal_frame;
Dwfl_Thread *thread = state->thread;
Dwfl_Process *process = thread->process;
@@ -730,7 +739,11 @@ __libdwfl_frame_unwind (Dwfl_Frame *state)
Dwfl_Thread *thread = state->thread;
Dwfl_Process *process = thread->process;
Ebl *ebl = process->ebl;
- new_unwound (state);
+ if (new_unwound (state) == NULL)
+ {
+ __libdwfl_seterrno (DWFL_E_NOMEM);
+ return;
+ }
state->unwound->pc_state = DWFL_FRAME_STATE_PC_UNDEFINED;
// &Dwfl_Frame.signal_frame cannot be passed as it is a bitfield.
bool signal_frame = false;
--
2.5.0
8 years
[PATCH] libdw: Fix bad free on invalid data in dwarf_getsrclines.c.
by Mark Wielaard
If the last dir name wasn't zero terminated we goto invalid_data
and might free the wrong data because we believe ndirlist is valid.
Don't update ndirlist until we are sure we will use all dirs.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdw/ChangeLog | 5 +++++
libdw/dwarf_getsrclines.c | 6 ++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index fc80e8d..36c332a 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * dwarf_getsrclines.c (read_srclines): Calculate ndirs first, then
+ assign to ndirlist.
+
2015-12-18 Mark Wielaard <mjw(a)redhat.com>
* libdwP.h (struct Dwarf): Remove sectiondata_gzip_mask.
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index dd1b3c1..d02c38d 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -1,5 +1,5 @@
/* Return line number information of CU.
- Copyright (C) 2004-2010, 2013, 2014, 2015 Red Hat, Inc.
+ Copyright (C) 2004-2010, 2013, 2014, 2015, 2016 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper(a)redhat.com>, 2004.
@@ -288,14 +288,16 @@ read_srclines (Dwarf *dbg,
/* First count the entries. */
const unsigned char *dirp = linep;
+ unsigned int ndirs = 0;
while (*dirp != 0)
{
uint8_t *endp = memchr (dirp, '\0', lineendp - dirp);
if (endp == NULL)
goto invalid_data;
- ++ndirlist;
+ ++ndirs;
dirp = endp + 1;
}
+ ndirlist += ndirs;
/* Arrange the list in array form. */
if (ndirlist >= MAX_STACK_DIRS)
--
2.5.0
8 years
[PATCH] config: Check for and use gcc -Wnull-dereference.
by Mark Wielaard
-Wnull-dereference is new in GCC6
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
ChangeLog | 4 ++++
config/ChangeLog | 5 +++++
config/eu.am | 7 +++++++
configure.ac | 10 ++++++++++
4 files changed, 26 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index d206a8e..0a8166b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-02-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * configure.ac: Add check for whether gcc accepts -Wnull-dereference.
+
2016-02-98 Mark Wielaard <mjw(a)redhat.com>
* configure.ac: Add checks for sane -Wlogical-op and whether gcc
diff --git a/config/ChangeLog b/config/ChangeLog
index 8523cb3..494778a 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-13 Mark Wielaard <mjw(a)redhat.com>
+
+ * eu.am: Check HAVE_NULL_DEREFERENCE_WARNING.
+ (AM_CFLAGS): Add NULL_DEREFERENCE_WARNING.
+
2016-02-09 Mark Wielaard <mjw(a)redhat.com>
* eu.am: Check SANE_LOGICAL_OP_WARNING and
diff --git a/config/eu.am b/config/eu.am
index c4e9279..4998771 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -55,9 +55,16 @@ else
DUPLICATED_COND_WARNING=
endif
+if HAVE_NULL_DEREFERENCE_WARNING
+NULL_DEREFERENCE_WARNING=-Wnull-dereference
+else
+NULL_DEREFERENCE_WARNING=
+endif
+
AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
-Wold-style-definition -Wstrict-prototypes \
$(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
+ $(NULL_DEREFERENCE_WARNING) \
$(if $($(*F)_no_Werror),,-Werror) \
$(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
$(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
diff --git a/configure.ac b/configure.ac
index d447db7..df58b5b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -313,6 +313,16 @@ CFLAGS="$old_CFLAGS"])
AM_CONDITIONAL(HAVE_DUPLICATED_COND_WARNING,
[test "x$ac_cv_duplicated_cond" != "xno"])
+# -Wnull-dereference was added by GCC6
+AC_CACHE_CHECK([whether gcc accepts -Wnull-dereference], ac_cv_null_dereference, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wnull-dereference"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+ ac_cv_null_dereference=yes, ac_cv_null_dereference=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_NULL_DEREFERENCE_WARNING,
+ [test "x$ac_cv_null_dereference" != "xno"])
+
dnl Check if we have argp available from our libc
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
--
2.5.0
8 years
[PATCH] Fix GCC6 -Wnull-dereference warnings.
by Mark Wielaard
asm_begin.c: In function ‘asm_begin’:
asm_begin.c:62:7: error: potential null pointer dereference [-Werror=null-dereference]
__fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We set result to NULL just before this call in case of error.
Fixed by only calling __fsetlocking when result is not NULL.
strip.c: In function ‘handle_elf.constprop’:
strip.c:1270:31: error: null pointer dereference [-Werror=null-dereference]
elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
~~~~~~~~~~~^~~
src/strip.c:597:37: note: in definition of macro ‘elf_assert’
#define elf_assert(test) do { if (!(test)) goto illformed; } while (0)
^~~~
That is the wrong check, we want to check shndxdata, not versiondata here.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libasm/ChangeLog | 5 +++++
libasm/asm_begin.c | 4 ++--
src/ChangeLog | 4 ++++
src/strip.c | 6 ++++--
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index beb6211..a8ac2c7 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-12 Mark Wielaard <mjw(a)redhat.com>
+
+ * asm_begin.c (prepare_text_output): Only call __fsetlocking when
+ result isn't NULL.
+
2015-10-05 Josh Stone <jistone(a)redhat.com>
* Makefile.am (libasm.so): Add AM_V_CCLD and AM_V_at silencers.
diff --git a/libasm/asm_begin.c b/libasm/asm_begin.c
index ff4d94c..dc83cd8 100644
--- a/libasm/asm_begin.c
+++ b/libasm/asm_begin.c
@@ -58,8 +58,8 @@ prepare_text_output (AsmCtx_t *result)
free (result);
result = NULL;
}
-
- __fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
+ else
+ __fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
}
return result;
diff --git a/src/ChangeLog b/src/ChangeLog
index 71709e4..369b12c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2016-02-12 Mark Wielaard <mjw(a)redhat.com>
+
+ * strip.c (handle_elf): Correct elf_assert shndxdata check.
+
2016-02-09 Mark Wielaard <mjw(a)redhat.com>
* readelf.c (read_encoded): Move up.
diff --git a/src/strip.c b/src/strip.c
index 06d7cfd..a604244 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1267,8 +1267,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
NULL);
- elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
- >= shdr_info[cnt].data->d_size / elsize);
+ elf_assert (shndxdata != NULL
+ && shndxdata->d_buf != NULL
+ && ((shndxdata->d_size / sizeof (Elf32_Word))
+ >= shdr_info[cnt].data->d_size / elsize));
}
if (shdr_info[cnt].version_idx != 0)
--
2.5.0
8 years
[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, 1 month
[PATCH] libdwfl: Check result of gelf_get* calls in relocate.c
by Mark Wielaard
For corrupted ELF files gelf_get calls might fail in which case it
is better to immediately return an error instead of using the NULL
result and crashing.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdwfl/ChangeLog | 6 ++++++
libdwfl/relocate.c | 26 ++++++++++++++++++++------
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index e92372a..cc8eec7 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,11 @@
2016-02-11 Mark Wielaard <mjw(a)redhat.com>
+ * relocate.c (relocate_section): Check result of all gelf_get* calls.
+ (__libdwfl_relocate): Likewise.
+ (__libdwfl_relocate_section): Likewise.
+
+2016-02-11 Mark Wielaard <mjw(a)redhat.com>
+
* relocate.c (relocate_section): Check result of gelf_update_* calls.
2016-01-08 Mark Wielaard <mjw(a)redhat.com>
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 920ead2..a44126e 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -671,6 +671,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
{
GElf_Rel rel_mem;
GElf_Rel *r = gelf_getrel (reldata, relidx, &rel_mem);
+ if (unlikely (r == NULL))
+ return DWFL_E_LIBELF;
if (r->r_info != 0 || r->r_offset != 0)
{
if (next != relidx)
@@ -684,6 +686,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
{
GElf_Rela rela_mem;
GElf_Rela *r = gelf_getrela (reldata, relidx, &rela_mem);
+ if (unlikely (r == NULL))
+ return DWFL_E_LIBELF;
if (r->r_info != 0 || r->r_offset != 0 || r->r_addend != 0)
{
if (next != relidx)
@@ -729,6 +733,8 @@ __libdwfl_relocate (Dwfl_Module *mod, Elf *debugfile, bool debug)
{
GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+ if (unlikely (shdr == NULL))
+ return DWFL_E_LIBELF;
if ((shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA)
&& shdr->sh_size != 0)
@@ -762,10 +768,18 @@ __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated,
if (elf_getshdrstrndx (relocated, &shstrndx) < 0)
return DWFL_E_LIBELF;
- return (__libdwfl_module_getebl (mod)
- ?: relocate_section (mod, relocated,
- gelf_getehdr (relocated, &ehdr_mem), shstrndx,
- &reloc_symtab,
- relocscn, gelf_getshdr (relocscn, &shdr_mem),
- tscn, false, partial));
+ Dwfl_Error result = __libdwfl_module_getebl (mod);
+ if (unlikely (result != DWFL_E_NOERROR))
+ return result;
+
+ GElf_Ehdr *ehdr = gelf_getehdr (relocated, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return DWFL_E_LIBELF;
+
+ GElf_Shdr *shdr = gelf_getshdr (relocscn, &shdr_mem);
+ if (unlikely (shdr == NULL))
+ return DWFL_E_LIBELF;
+
+ return relocate_section (mod, relocated, ehdr, shstrndx, &reloc_symtab,
+ relocscn, shdr, tscn, false, partial);
}
--
1.8.3.1
8 years, 1 month
[PATCH] libdwfl: Check result of gelf_update_* calls in relocate_section.
by Mark Wielaard
For corrupted ELF files the gelf_update calls might fail in which case it
is better to immediately return an error message instead of (silently)
continuing.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdwfl/ChangeLog | 4 ++++
libdwfl/relocate.c | 18 ++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 94c58d9..e92372a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+2016-02-11 Mark Wielaard <mjw(a)redhat.com>
+
+ * relocate.c (relocate_section): Check result of gelf_update_* calls.
+
2016-01-08 Mark Wielaard <mjw(a)redhat.com>
* libdwfl_a_SOURCES: Unconditionally add gzip.c.
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index fc88df3..920ead2 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -1,5 +1,5 @@
/* Relocate debug information.
- Copyright (C) 2005-2011, 2014 Red Hat, Inc.
+ Copyright (C) 2005-2011, 2014, 2016 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -605,7 +605,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
case DWFL_E_NOERROR:
/* We applied the relocation. Elide it. */
memset (&rel_mem, 0, sizeof rel_mem);
- gelf_update_rel (reldata, relidx, &rel_mem);
+ if (unlikely (gelf_update_rel (reldata, relidx, &rel_mem) == 0))
+ return DWFL_E_LIBELF;
++complete;
break;
case DWFL_E_BADRELTYPE:
@@ -635,7 +636,9 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
case DWFL_E_NOERROR:
/* We applied the relocation. Elide it. */
memset (&rela_mem, 0, sizeof rela_mem);
- gelf_update_rela (reldata, relidx, &rela_mem);
+ if (unlikely (gelf_update_rela (reldata, relidx,
+ &rela_mem) == 0))
+ return DWFL_E_LIBELF;
++complete;
break;
case DWFL_E_BADRELTYPE:
@@ -671,7 +674,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
if (r->r_info != 0 || r->r_offset != 0)
{
if (next != relidx)
- gelf_update_rel (reldata, next, r);
+ if (unlikely (gelf_update_rel (reldata, next, r) == 0))
+ return DWFL_E_LIBELF;
++next;
}
}
@@ -683,7 +687,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
if (r->r_info != 0 || r->r_offset != 0 || r->r_addend != 0)
{
if (next != relidx)
- gelf_update_rela (reldata, next, r);
+ if (unlikely (gelf_update_rela (reldata, next, r) == 0))
+ return DWFL_E_LIBELF;
++next;
}
}
@@ -691,7 +696,8 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr,
}
shdr->sh_size = reldata->d_size = nrels * sh_entsize;
- gelf_update_shdr (scn, shdr);
+ if (unlikely (gelf_update_shdr (scn, shdr) == 0))
+ return DWFL_E_LIBELF;
}
return result;
--
1.8.3.1
8 years, 1 month
[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, 1 month
[PATCH] Add NT_ARM_SYSTEM_CALL aarch64 syscall regset.
by Mark Wielaard
Linux kernel 3.18 added the NT_ARM_SYSTEM_CALL regset for aarch64.
Recognize and print this new core item.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
backends/ChangeLog | 7 +++++++
backends/aarch64_corenote.c | 11 ++++++++++-
libebl/eblcorenotetypename.c | 1 +
libelf/ChangeLog | 4 ++++
libelf/elf.h | 1 +
5 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/backends/ChangeLog b/backends/ChangeLog
index cc0dd6f..578f6b1 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,10 @@
+2016-02-12 Mark Wielaard <mjw(a)redhat.com>
+
+ * aarch64_corenote.c (aarch64_syscall_items): New Ebl_Core_Item[].
+ (EXTRA_NOTES): Add NT_ARM_SYSTEM_CALL.
+ * eblcorenotetypename.c (ebl_core_note_type_name):
+ Add ARM_SYSTEM_CALL.
+
2015-12-28 Mark Wielaard <mjw(a)redhat.com>
* i386_reloc.def: Add GOT32X.
diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
index 9b42485..905a4b8 100644
--- a/backends/aarch64_corenote.c
+++ b/backends/aarch64_corenote.c
@@ -99,6 +99,14 @@ static const Ebl_Core_Item aarch64_tls_items[] =
}
};
+static const Ebl_Core_Item aarch64_syscall_items [] =
+ {
+ {
+ .name = "syscall", .type = ELF_T_WORD, .format = 'x',
+ .offset = 0, .group = "register"
+ }
+ };
+
#define AARCH64_HWBP_REG(KIND, N) \
{ \
.name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', \
@@ -158,6 +166,7 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
aarch64_fpregset_regs, aarch64_fpregset_items) \
EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items) \
EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items) \
- EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)
+ EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items) \
+ EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items)
#include "linux-core-note.c"
diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
index 826f9a1..fa81dbe 100644
--- a/libebl/eblcorenotetypename.c
+++ b/libebl/eblcorenotetypename.c
@@ -90,6 +90,7 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf, size_t len)
KNOWNSTYPE (ARM_TLS);
KNOWNSTYPE (ARM_HW_BREAK);
KNOWNSTYPE (ARM_HW_WATCH);
+ KNOWNSTYPE (ARM_SYSTEM_CALL);
KNOWNSTYPE (SIGINFO);
KNOWNSTYPE (FILE);
#undef KNOWNSTYPE
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 41eaa00..fbff2d0 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2016-02-12 Mark Wielaard <mjw(a)redhat.com>
+
+ * elf.h: Update from glibc. Add NT_ARM_SYSTEM_CALL.
+
2016-02-04 Mark Wielaard <mjw(a)redhat.com>
* elf_getdata.c (__libelf_set_rawdata_wrlock): Don't adjust align
diff --git a/libelf/elf.h b/libelf/elf.h
index 1a7000b..ce96bd5 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -667,6 +667,7 @@ typedef struct
#define NT_ARM_TLS 0x401 /* ARM TLS register */
#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
+#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
/* Legal values for the note segment descriptor types for object files. */
--
1.8.3.1
8 years, 1 month
[PATCH] libebl: Don't assume ELF notes are "GNU" when unknown, recognize "Go" notes.
by Mark Wielaard
We used to assume any unknown ELF note provider name was "GNU" and didn't
recognize any of the "Go" provider types. We now check the provider name
explictly in ebl_object_note_type_name and recognize the following Go
note names: PKGLIST, ABIHASH, DEPS and BUILDID. But there is no attempt
yet in ebl_object_note to decode the description of these notes.
https://bugzilla.redhat.com/show_bug.cgi?id=1295951
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libebl/ChangeLog | 6 ++++++
libebl/eblobjnotetypename.c | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index aa3d686..26a4f94 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-12 Mark Wielaard <mjw(a)redhat.com>
+
+ * eblobjnotetypename.c (ebl_object_note_type_name): Check name is
+ "Go" and use new goknowntypes then. Otherwise check name is not
+ "GNU" and return "unknown".
+
2016-01-09 Mark Wielaard <mjw(a)redhat.com>
* eblobjnote.c (ebl_object_note): Add brackets around if statement
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 8e2e329..db040d2 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -1,5 +1,5 @@
/* Return note type name.
- Copyright (C) 2002, 2007, 2009, 2011 Red Hat, Inc.
+ Copyright (C) 2002, 2007, 2009, 2011, 2016 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <drepper(a)redhat.com>, 2002.
@@ -51,6 +51,39 @@ ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
return buf;
}
+#define ELF_NOTE_GOPKGLIST 1
+#define ELF_NOTE_GOABIHASH 2
+#define ELF_NOTE_GODEPS 3
+#define ELF_NOTE_GOBUILDID 4
+
+ static const char *goknowntypes[] =
+ {
+#define KNOWNSTYPE(name) [ELF_NOTE_GO##name] = #name
+ KNOWNSTYPE (PKGLIST),
+ KNOWNSTYPE (ABIHASH),
+ KNOWNSTYPE (DEPS),
+ KNOWNSTYPE (BUILDID),
+#undef KNOWNSTYPE
+ };
+
+ if (strcmp (name, "Go") == 0)
+ {
+ if (type < sizeof (goknowntypes) / sizeof (goknowntypes[0])
+ && goknowntypes[type] != NULL)
+ return goknowntypes[type];
+ else
+ {
+ snprintf (buf, len, "%s: %" PRIu32, gettext ("<unknown>"), type);
+ return buf;
+ }
+ }
+
+ if (strcmp (name, "GNU") != 0)
+ {
+ snprintf (buf, len, "%s: %" PRIu32, gettext ("<unknown>"), type);
+ return buf;
+ }
+
static const char *knowntypes[] =
{
#define KNOWNSTYPE(name) [NT_##name] = #name
--
1.8.3.1
8 years, 1 month