Re: [PATCH] libdw: Fix crashing on illegal/zero Dwarf_Die.

2018-05-15 Thread Mark Wielaard
On Fri, 2018-05-11 at 12:49 +0200, Mark Wielaard wrote:
> In some cases we create an illegal Dwarf_Die by clearing all fields.
> The idea is that dwarf_tag () on such a Dwarf_Die will return
> DW_TAG_invalid, to indicate that the Dwarf_Die is unusable (and other
> functions will also return errors).  But when "reconstructing" the
> Dwarf_Die addr we might use the cu before realizing the Dwarf_Die is
> invalid.  Fix this with an explicit NULL check and add a testcase.

Pushed to master.


Re: [PATCH] readelf: Add DWARF5 .debug_line support.

2018-05-15 Thread Mark Wielaard
On Fri, 2018-05-11 at 14:28 +0200, Mark Wielaard wrote:
> This only changes the parsing of the directory and file name tables.
> It does this by sharing the printing of (non-CU based) from data from
> the .debug_macro code. Adding support for printing strx[1234] form
> data
> by sharing the code that detects the correct str_offsets_base in
> libdw.
> 
> The header format is also cleaned up a bit so that it better lines
> out.
> Testcases adjusted and new ones added.

Pushed to master.


Re: [PATCH] readelf, libdw: Handle DWARF5 .debug_macro.

2018-05-15 Thread Mark Wielaard
On Fri, 2018-05-11 at 15:38 +0200, Mark Wielaard wrote:
> Almost identical to GNU .debug_macro extension. Just accept and use
> DW_AT_macros where we accept or use DW_AT_GNU_macros. And be a little
> stricter in which FORMs we accept (this could have caused problems
> with the GNU variant too). Deals with DW_FORM_strx[1234], but not yet
> with imported macros through DW_MACRO_import_sup.

Pushed to master.


[COMMITTED] readelf: Fix 32bit compile issues.

2018-05-15 Thread Mark Wielaard
The buildbot flagged a couple of issues on debian-i686.
Fixes pushed to master.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog |  6 ++
 src/readelf.c | 10 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 4e6887e..419fa20 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-15  Mark Wielaard  
+
+   * readelf.c (print_form_data): Cast comparisons against offset_len to
+   ptrdiff_t.
+   (print_debug_line_section): Print uint64_t as PRIu64.
+
 2018-05-11  Mark Wielaard  
 
* readelf.c (print_debug_macro_section): Use libdw_valid_user_form.
diff --git a/src/readelf.c b/src/readelf.c
index c1d89d3..854d31c 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6906,7 +6906,7 @@ print_form_data (Dwarf *dbg, int form, const unsigned 
char *readp,
 case DW_FORM_strp:
 case DW_FORM_line_strp:
 case DW_FORM_strp_sup:
-  if (readendp - readp < offset_len)
+  if (readendp - readp < (ptrdiff_t) offset_len)
goto invalid_data;
   if (offset_len == 8)
val = read_8ubyte_unaligned_inc (dbg, readp);
@@ -6930,7 +6930,7 @@ print_form_data (Dwarf *dbg, int form, const unsigned 
char *readp,
   break;
 
 case DW_FORM_sec_offset:
-  if (readendp - readp < offset_len)
+  if (readendp - readp < (ptrdiff_t) offset_len)
goto invalid_data;
   if (offset_len == 8)
val = read_8ubyte_unaligned_inc (dbg, readp);
@@ -6952,7 +6952,7 @@ print_form_data (Dwarf *dbg, int form, const unsigned 
char *readp,
{
  readp = data->d_buf + str_offsets_base + val;
  readendp = data->d_buf + data->d_size;
- if (readendp - readp < offset_len)
+ if (readendp - readp < (ptrdiff_t) offset_len)
str = "???";
  else
{
@@ -7248,7 +7248,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, 
GElf_Ehdr *ehdr,
 
  for (uint64_t i = 0; i < directories_count; i++)
{
- printf (" %-5lu ", i);
+ printf (" %-5" PRIu64 " ", i);
  for (int j = 0; j < directory_entry_format_count; j++)
{
  linep = print_form_data (dbg, enc[j].form,
@@ -7324,7 +7324,7 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, 
GElf_Ehdr *ehdr,
 
  for (uint64_t i = 0; i < file_name_count; i++)
{
- printf (" %-5lu ", i);
+ printf (" %-5" PRIu64 " ", i);
  for (int j = 0; j < file_name_format_count; j++)
{
  linep = print_form_data (dbg, enc[j].form,
-- 
1.8.3.1



[PATCH] libdw, readelf: Handle .debug_*.dwo section name variants.

2018-05-15 Thread Mark Wielaard
The .debug_*.dwo section names are handled just like their none .dwo
variants.  The section contents is the same as sections without the .dwo
name, but they are only found in split-dwarf files.  This patch allows
opening and inspecting split-dwarf files.  It doesn't yet connect the
split-dwarf with their skeleton (or the other way around).  It also
doesn't yet handle any special split-dwarf attributes or tags.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog |  5 +
 libdw/dwarf_begin_elf.c | 31 +--
 src/ChangeLog   |  4 
 src/readelf.c   | 32 +---
 4 files changed, 51 insertions(+), 21 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index e66a1ec..42777b5 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-12  Mark Wielaard  
+
+   * dwarf_begin_elf.c (check_section): Also recognize .dwo section
+   name variants.
+
 2018-05-11  Mark Wielaard  
 
* dwarf_formudata.c (dwarf_formudata): Handle DW_AT_macros as macptr.
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 8bdcea2..61de752 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -1,7 +1,6 @@
 /* Create descriptor from ELF descriptor for processing file.
-   Copyright (C) 2002-2011, 2014, 2015, 2018 Red Hat, Inc.
+   Copyright (C) 2002-2011, 2014, 2015, 2017, 2018 Red Hat, Inc.
This file is part of elfutils.
-   Written by Ulrich Drepper , 2002.
 
This file is free software; you can redistribute it and/or modify
it under the terms of either
@@ -116,14 +115,26 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn 
*scn, bool inscngrp)
   size_t cnt;
   bool gnu_compressed = false;
   for (cnt = 0; cnt < ndwarf_scnnames; ++cnt)
-if (strcmp (scnname, dwarf_scnnames[cnt]) == 0)
-  break;
-else if (scnname[0] == '.' && scnname[1] == 'z'
-&& strcmp (&scnname[2], &dwarf_scnnames[cnt][1]) == 0)
-  {
-gnu_compressed = true;
-break;
-  }
+{
+  size_t dbglen = strlen (dwarf_scnnames[cnt]);
+  size_t scnlen = strlen (scnname);
+  if (strncmp (scnname, dwarf_scnnames[cnt], dbglen) == 0
+ && (dbglen == scnlen
+ || (scnlen == dbglen + 4
+ && strstr (scnname, ".dwo") == scnname + dbglen)))
+   break;
+  else if (scnname[0] == '.' && scnname[1] == 'z'
+  && (strncmp (&scnname[2], &dwarf_scnnames[cnt][1],
+   dbglen - 1) == 0
+  && (scnlen == dbglen + 1
+  || (scnlen == dbglen + 5
+  && strstr (scnname,
+ ".dwo") == scnname + dbglen + 1
+   {
+ gnu_compressed = true;
+ break;
+   }
+}
 
   if (cnt >= ndwarf_scnnames)
 /* Not a debug section; ignore it. */
diff --git a/src/ChangeLog b/src/ChangeLog
index 419fa20..9b5ef79 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-12  Mark Wielaard  
+
+   * readelf.c (print_debug): Also recognize .dwo section name variants.
+
 2018-05-15  Mark Wielaard  
 
* readelf.c (print_form_data): Cast comparisons against offset_len to
diff --git a/src/readelf.c b/src/readelf.c
index 854d31c..f34dd36 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -9127,17 +9127,27 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr 
*ehdr)
 
  int n;
  for (n = 0; n < ndebug_sections; ++n)
-   if (strcmp (name, debug_sections[n].name) == 0
-   || (name[0] == '.' && name[1] == 'z'
-   && debug_sections[n].name[1] == 'd'
-   && strcmp (&name[2], &debug_sections[n].name[1]) == 0)
-   )
- {
-   if ((print_debug_sections | implicit_debug_sections)
-   & debug_sections[n].bitmask)
- debug_sections[n].fp (dwflmod, ebl, ehdr, scn, shdr, dbg);
-   break;
- }
+   {
+ size_t dbglen = strlen (debug_sections[n].name);
+ size_t scnlen = strlen (name);
+ if ((strncmp (name, debug_sections[n].name, dbglen) == 0
+  && (dbglen == scnlen
+  || (scnlen == dbglen + 4
+  && strstr (name, ".dwo") == name + dbglen)))
+ || (name[0] == '.' && name[1] == 'z'
+ && debug_sections[n].name[1] == 'd'
+ && strncmp (&name[2], &debug_sections[n].name[1],
+ dbglen - 1) == 0
+ && (scnlen == dbglen + 1
+ || (scnlen == dbglen + 5
+ && strstr (name, ".dwo") == name + dbglen + 1
+   {
+ if ((print_debug_sections | implicit_debug_sections)
+ & debug_sections[n].bitmask)
+   debug_sections[n].fp (dwflmod, ebl, ehd

[PATCH] libdw: Add GNU DebugFission attributes, tags, forms and operands.

2018-05-15 Thread Mark Wielaard
Most are handled just like their DWARF5 counterparts.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog   | 20 
 libdw/dwarf.h | 16 
 libdw/dwarf_formaddr.c|  4 +++-
 libdw/dwarf_formstring.c  |  3 ++-
 libdw/dwarf_formudata.c   |  2 ++
 libdw/dwarf_getlocation.c |  2 ++
 libdw/libdw_form.c|  2 ++
 src/ChangeLog |  9 +
 src/readelf.c | 20 ++--
 9 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 42777b5..e41e5c8 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,23 @@
+2018-05-14  Mark Wielaard  
+
+   * dwarf.h: Add GNU Debug Fission extensions. DW_AT_GNU_dwo_name,
+   DW_AT_GNU_dwo_id, DW_AT_GNU_ranges_base, DW_AT_GNU_addr_base,
+   DW_AT_GNU_pubnames, DW_AT_GNU_pubtypes. DW_FORM_GNU_addr_index,
+   DW_FORM_GNU_str_index. DW_OP_GNU_addr_index, DW_OP_GNU_const_index.
+   * dwarf_formaddr.c (dwarf_formaddr): Handle DW_FORM_GNU_addr_index
+   as DW_FORM_addrx.
+   (__libdw_cu_addr_base): Check for both DW_AT_GNU_addr_base and
+   DW_AT_addr_base.
+   * dwarf_formstring.c (dwarf_formstring): Handle DW_FORM_GNU_str_index
+   as DW_FORM_strx.
+   * dwarf_formudata.c (dwarf_formudata): Recognize DW_AT_GNU_addr_base
+   as addrptr. Recognize DW_AT_GNU_ranges_base as rangelistptr.
+   * dwarf_getlocation.c (__libdw_intern_expression): Handle
+   DW_OP_GNU_addr_index as DW_OP_addrx and DW_OP_GNU_const_index as
+   DW_OP_constx.
+   * libdw_form.c (__libdw_form_val_compute_len): Handle
+   DW_FORM_GNU_addr_index and DW_FORM_GNU_str_index taking an uleb128.
+
 2018-05-12  Mark Wielaard  
 
* dwarf_begin_elf.c (check_section): Also recognize .dwo section
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index fc9801b..c438399 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -343,6 +343,13 @@ enum
 DW_AT_GNU_entry_view = 0x2138,
 DW_AT_GNU_macros = 0x2119,
 DW_AT_GNU_deleted = 0x211a,
+/* GNU Debug Fission extensions.  */
+DW_AT_GNU_dwo_name = 0x2130,
+DW_AT_GNU_dwo_id = 0x2131,
+DW_AT_GNU_ranges_base = 0x2132,
+DW_AT_GNU_addr_base = 0x2133,
+DW_AT_GNU_pubnames = 0x2134,
+DW_AT_GNU_pubtypes = 0x2135,
 
 DW_AT_hi_user = 0x3fff
   };
@@ -404,6 +411,10 @@ enum
 DW_FORM_addrx3 = 0x2b,
 DW_FORM_addrx4 = 0x2c,
 
+/* GNU Debug Fission extensions.  */
+DW_FORM_GNU_addr_index = 0x1f01,
+DW_FORM_GNU_str_index = 0x1f02,
+
 DW_FORM_GNU_ref_alt = 0x1f20, /* offset in alternate .debuginfo.  */
 DW_FORM_GNU_strp_alt = 0x1f21 /* offset in alternate .debug_str. */
   };
@@ -590,6 +601,11 @@ enum
 DW_OP_GNU_convert = 0xf7,
 DW_OP_GNU_reinterpret = 0xf9,
 DW_OP_GNU_parameter_ref = 0xfa,
+
+/* GNU Debug Fission extensions.  */
+DW_OP_GNU_addr_index = 0xfb,
+DW_OP_GNU_const_index = 0xfc,
+
 DW_OP_GNU_variable_value = 0xfd,
 
 DW_OP_lo_user = 0xe0,  /* Implementation-defined range start.  */
diff --git a/libdw/dwarf_formaddr.c b/libdw/dwarf_formaddr.c
index 25e6970..c917dea 100644
--- a/libdw/dwarf_formaddr.c
+++ b/libdw/dwarf_formaddr.c
@@ -56,6 +56,7 @@ dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr 
*return_addr)
 
   /* All others encode an index into the .debug_addr section where
 the address can be found.  */
+  case DW_FORM_GNU_addr_index:
   case DW_FORM_addrx:
if (datap >= endp)
  {
@@ -142,7 +143,8 @@ Dwarf_Off __libdw_cu_addr_base (Dwarf_CU *cu)
 {
   Dwarf_Die cu_die = CUDIE(cu);
   Dwarf_Attribute attr;
-  if (dwarf_attr (&cu_die, DW_AT_addr_base, &attr) != NULL)
+  if (dwarf_attr (&cu_die, DW_AT_GNU_addr_base, &attr) != NULL
+ || dwarf_attr (&cu_die, DW_AT_addr_base, &attr) != NULL)
{
  Dwarf_Word off;
  if (dwarf_formudata (&attr, &off) == 0)
diff --git a/libdw/dwarf_formstring.c b/libdw/dwarf_formstring.c
index 251784d..c3e892a 100644
--- a/libdw/dwarf_formstring.c
+++ b/libdw/dwarf_formstring.c
@@ -1,5 +1,5 @@
 /* Return string associated with given attribute.
-   Copyright (C) 2003-2010, 2013, 2018 Red Hat, Inc.
+   Copyright (C) 2003-2010, 2013, 2017, 2018 Red Hat, Inc.
This file is part of elfutils.
 
This file is free software; you can redistribute it and/or modify
@@ -94,6 +94,7 @@ dwarf_formstring (Dwarf_Attribute *attrp)
   switch (attrp->form)
{
case DW_FORM_strx:
+   case DW_FORM_GNU_str_index:
  if (datap >= endp)
{
invalid:
diff --git a/libdw/dwarf_formudata.c b/libdw/dwarf_formudata.c
index 62352ee..19d34f8 100644
--- a/libdw/dwarf_formudata.c
+++ b/libdw/dwarf_formudata.c
@@ -168,6 +168,7 @@ dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word 
*return_uval)
 
case DW_AT_ranges:
case DW_AT_start_scope:
+   case DW_AT_GNU_ranges_base:
  /* rangelistptr */
  

[PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv

2018-05-15 Thread Andreas Schwab
Signed-off-by: Andreas Schwab 
---
 backends/ChangeLog  |  5 +
 backends/riscv_init.c   |  1 +
 backends/riscv_symbol.c | 32 
 3 files changed, 38 insertions(+)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 63bb7e444e..0dde0ff3f5 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-15  Andreas Schwab  
+
+   * riscv_init.c (riscv_init): Hook check_special_symbol.
+   * riscv_symbol.c (riscv_check_special_symbol): New function.
+
 2018-04-19  Andreas Schwab  
 
* Makefile.am (modules): Add riscv.
diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index 0203eac8b8..4234cded2b 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -52,6 +52,7 @@ riscv_init (Elf *elf __attribute__ ((unused)),
   riscv_init_reloc (eh);
   HOOK (eh, register_info);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, check_special_symbol);
   HOOK (eh, machine_flag_check);
 
   return MODVERSION;
diff --git a/backends/riscv_symbol.c b/backends/riscv_symbol.c
index 628e0572ae..dce8e3586b 100644
--- a/backends/riscv_symbol.c
+++ b/backends/riscv_symbol.c
@@ -60,3 +60,35 @@ riscv_machine_flag_check (GElf_Word flags)
   return ((flags &~ (EF_RISCV_RVC
 | EF_RISCV_FLOAT_ABI)) == 0);
 }
+
+/* Check whether given symbol's st_value and st_size are OK despite failing
+   normal checks.  */
+bool
+riscv_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr, const GElf_Sym *sym,
+   const char *name, const GElf_Shdr *destshdr)
+{
+  if (name == NULL)
+return false;
+
+  const char *sname = elf_strptr (elf, ehdr->e_shstrndx, destshdr->sh_name);
+  if (sname == NULL)
+return false;
+
+  /* _GLOBAL_OFFSET_TABLE_ points to the start of the .got section, but it
+ is preceded by the .got.plt section in the output .got section.  */
+  if (strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0)
+return (strcmp (sname, ".got") == 0
+   && sym->st_value >= destshdr->sh_addr
+   && sym->st_value < destshdr->sh_addr + destshdr->sh_size);
+
+  /* __global_pointer$ points to the .sdata section with an offset of
+ 0x800.  It might however fall in the .got section, in which case we
+ cannot check the offset.  The size always should be zero.  */
+  if (strcmp (name, "__global_pointer$") == 0)
+return (((strcmp (sname, ".sdata") == 0
+ && sym->st_value == destshdr->sh_addr + 0x800)
+|| strcmp (sname, ".got") == 0)
+   && sym->st_size == 0);
+
+  return false;
+}
-- 
2.17.0


-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] libdw: Recognize GNU DebugFission split units.

2018-05-15 Thread Mark Wielaard
The split dwarf dwo unit id and type are not in the CU header itself, but
can be found in the CU DIE DW_AT_GNU_dwo attributes. Use this to set the
correct unit_type and id for GNU DebugFission split units. Also show this
information in eu-readelf when printing units.

Signed-off-by: Mark Wielaard 
---
 libdw/ChangeLog  |  9 +
 libdw/libdwP.h   | 15 ++-
 libdw/libdw_findcu.c | 23 ---
 src/ChangeLog|  5 +
 src/readelf.c|  3 ++-
 5 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index e41e5c8..385f52c 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,12 @@
+2018-05-15  Mark Wielaard  
+
+   * libdwP.h (__libdw_first_die_from_cu_start): Adjust commented out
+   asserts.
+   * libdw_findcu.c (__libdw_intern_next_unit): For version 4 DWARF if
+   the cudie has a DW_AT_GNU_dwi_id set the unit_id8 and unit_type to
+   DW_UT_skeleton or DW_UT_split_compile based on whether the cudie has
+   child DIEs and a DW_AT_GNU_dwo_name attribute.
+
 2018-05-14  Mark Wielaard  
 
* dwarf.h: Add GNU Debug Fission extensions. DW_AT_GNU_dwo_name,
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index da0383f..25a5ad3 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -360,15 +360,12 @@ __libdw_first_die_from_cu_start (Dwarf_Off cu_start,
 /*
   assert (offset_size == 4 || offset_size == 8);
   assert (version >= 2 && version <= 5);
-  assert (version >= 5 || (unit_type == DW_UT_compile
-  || unit_type == DW_UT_partial
-  || unit_type == DW_UT_type));
-  assert (version != 5 || (unit_type == DW_UT_compile
-  || unit_type == DW_UT_partial
-  || unit_type == DW_UT_skeleton
-  || unit_type == DW_UT_split_compile
-  || unit_type == DW_UT_type
-  || unit_type == DW_UT_split_type));
+  assert (unit_type == DW_UT_compile
+ || unit_type == DW_UT_partial
+ || unit_type == DW_UT_skeleton
+ || unit_type == DW_UT_split_compile
+ || unit_type == DW_UT_type
+ || unit_type == DW_UT_split_type);
 */
 
   Dwarf_Off off = cu_start;
diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
index 3899c08..0a65c97 100644
--- a/libdw/libdw_findcu.c
+++ b/libdw/libdw_findcu.c
@@ -123,7 +123,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
   newp->startp = data->d_buf + newp->start;
   newp->endp = data->d_buf + newp->end;
 
-  /* v4 debug type units have version == 4 and unit_type == 1.  */
+  /* v4 debug type units have version == 4 and unit_type == DW_UT_type.  */
   if (debug_types)
 newp->unit_type = DW_UT_type;
   else if (version < 5)
@@ -133,9 +133,26 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
 
   /* But set it correctly from the actual CUDIE tag.  */
   Dwarf_Die cudie = CUDIE (newp);
-  int tag = dwarf_tag (&cudie);
+  int tag = INTUSE(dwarf_tag) (&cudie);
   if (tag == DW_TAG_compile_unit)
-   newp->unit_type = DW_UT_compile;
+   {
+ Dwarf_Attribute dwo_id;
+ if (INTUSE(dwarf_attr) (&cudie, DW_AT_GNU_dwo_id, &dwo_id) != NULL)
+   {
+ Dwarf_Word id8;
+ if (INTUSE(dwarf_formudata) (&dwo_id, &id8) == 0)
+   {
+ if (INTUSE(dwarf_haschildren) (&cudie) == 0
+ && INTUSE(dwarf_hasattr) (&cudie,
+   DW_AT_GNU_dwo_name) == 1)
+   newp->unit_type = DW_UT_skeleton;
+ else
+   newp->unit_type = DW_UT_split_compile;
+
+ newp->unit_id8 = id8;
+   }
+   }
+   }
   else if (tag == DW_TAG_partial_unit)
newp->unit_type = DW_UT_partial;
   else if (tag == DW_TAG_type_unit)
diff --git a/src/ChangeLog b/src/ChangeLog
index 778d053..5a74e83 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-05-15  Mark Wielaard  
+
+   * readelf.c (print_debug_units): Print unit type and id for any
+   unit type that has it even when version < 5.
+
 2018-05-14  Mark Wielaard  
 
* readelf.c (print_ops): Handle DW_OP_GNU_addr_index and
diff --git a/src/readelf.c b/src/readelf.c
index 6d503c7..bb03d2c 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6577,7 +6577,8 @@ print_debug_units (Dwfl_Module *dwflmod,
   ", Offset size: %" PRIu8 "\n"),
  (uint64_t) offset, version, abbroffset, addrsize, offsize);
 
- if (version >= 5)
+ if (version >= 5 || (unit_type != DW_UT_compile
+  && unit_type != DW_UT_partial))
{
  printf (gettext (" Unit type: %s (%" PRIu8 ")"),
   dwarf_unit_name (unit_type), unit_type);
-- 
1.8.3.1



Re: [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv

2018-05-15 Thread Mark Wielaard
On Tue, 2018-05-15 at 13:47 +0200, Andreas Schwab wrote:
> +
> + * riscv_init.c (riscv_init): Hook check_special_symbol.
> + * riscv_symbol.c (riscv_check_special_symbol): New function.

Looks good. Pushed.

I assume this solves some of the self-tests in make check on riscv.

Is there an ELF abi document for riscv that describes these special
symbols?

Thanks,

Mark


Re: [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ and __global_pointer$ on riscv

2018-05-15 Thread Andreas Schwab
On Mai 15 2018, Mark Wielaard  wrote:

> Is there an ELF abi document for riscv that describes these special
> symbols?

There is
,
but it doesn't mention the symbols.  I have extracted that out of the
binutils sources.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


[PATCH] elflint: fix typo in error diagnostics

2018-05-15 Thread Dmitry V. Levin
diff --git a/src/ChangeLog b/src/ChangeLog
index 419fa20..8a664da 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-15  Dmitry V. Levin  
+
+   * elflint.c (check_elf_header): Fix typo in error diagnostics.
+
 2018-05-15  Mark Wielaard  
 
* readelf.c (print_form_data): Cast comparisons against offset_len to
diff --git a/src/elflint.c b/src/elflint.c
index fb40fe7..0a26d97 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -376,9 +376,9 @@ check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size)
   EI_OSABI,
   ebl_osabi_name (ebl, ehdr->e_ident[EI_OSABI], buf, sizeof (buf)));
 
-  /* No ABI versions other than zero supported either.  */
+  /* No ABI versions other than zero are supported either.  */
   if (ehdr->e_ident[EI_ABIVERSION] != 0)
-ERROR (gettext ("unsupport ABI version e_ident[%d] == %d\n"),
+ERROR (gettext ("unsupported ABI version e_ident[%d] == %d\n"),
   EI_ABIVERSION, ehdr->e_ident[EI_ABIVERSION]);
 
   for (cnt = EI_PAD; cnt < EI_NIDENT; ++cnt)
-- 
ldv


Re: [PATCH] elflint: fix typo in error diagnostics

2018-05-15 Thread Mark Wielaard
Hi Dmitry,

On Tue, May 15, 2018 at 06:34:57PM +0300, Dmitry V. Levin wrote:
> +2018-05-15  Dmitry V. Levin  
> +
> + * elflint.c (check_elf_header): Fix typo in error diagnostics.

Thanks for spotting this. Looks good. But all contributions
need an explicit Signed-off-by line. Could you take a look
at the CONTRIBUTING file and add one if you agree with the
Developer's Certificate of Origin:
https://sourceware.org/git/?p=elfutils.git;a=blob;f=CONTRIBUTING;hb=HEAD

Thanks,

Mark


[PATCH v2] elflint: fix typo in error diagnostics

2018-05-15 Thread Dmitry V. Levin
Signed-off-by: Dmitry V. Levin 
---
 src/ChangeLog | 4 
 src/elflint.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 419fa20..8a664da 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2018-05-15  Dmitry V. Levin  
+
+   * elflint.c (check_elf_header): Fix typo in error diagnostics.
+
 2018-05-15  Mark Wielaard  
 
* readelf.c (print_form_data): Cast comparisons against offset_len to
diff --git a/src/elflint.c b/src/elflint.c
index fb40fe7..0a26d97 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -376,9 +376,9 @@ check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size)
   EI_OSABI,
   ebl_osabi_name (ebl, ehdr->e_ident[EI_OSABI], buf, sizeof (buf)));
 
-  /* No ABI versions other than zero supported either.  */
+  /* No ABI versions other than zero are supported either.  */
   if (ehdr->e_ident[EI_ABIVERSION] != 0)
-ERROR (gettext ("unsupport ABI version e_ident[%d] == %d\n"),
+ERROR (gettext ("unsupported ABI version e_ident[%d] == %d\n"),
   EI_ABIVERSION, ehdr->e_ident[EI_ABIVERSION]);
 
   for (cnt = EI_PAD; cnt < EI_NIDENT; ++cnt)
-- 
ldv


Re: [PATCH v2] elflint: fix typo in error diagnostics

2018-05-15 Thread Mark Wielaard
On Tue, May 15, 2018 at 11:18:43PM +0300, Dmitry V. Levin wrote:
> Signed-off-by: Dmitry V. Levin 

Great. Pushed.

Thanks,

Mark