[Bug tools/23787] eu-size: Bad handling of ar files inside are files

2020-06-06 Thread shockfilm.in at gmail dot com via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=23787

Vahid  changed:

   What|Removed |Added

 CC||shockfilm.in at gmail dot com

--- Comment #29 from Vahid  ---
i think is very best.

http://moshaveranetehran2.blog.ir/

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: location list

2020-06-06 Thread Mark Wielaard
Hi Sasha,

On Sat, 2020-06-06 at 00:30 +, Sasha Da Rocha Pinheiro wrote:
> As you can see the following variables have distinct locations:
>  [81]  variable abbrev: 5
>name (string) "a"
>decl_file(data1) sasha.c (1)
>decl_line(data1) 12
>type (ref4) [cd]
>location (sec_offset) location list
> [ 0]
>  [9f]variable abbrev: 5
>  name (string) "g"
>  decl_file(data1) sasha.c (1)
>  decl_line(data1) 15
>  type (ref4) [cd]
>  location (sec_offset) location list
> [4a]
> [bd]  variable abbrev: 5
>name (string) "z"
>decl_file(data1) sasha.c (1)
>decl_line(data1) 16
>type (ref4) [cd]
>location (sec_offset) location list
> [6e]
> 
> But when I use the code I sent before to list the three variables, I
> always get:
> 
> [main01.cpp:73] - Variable and location found (a), size(1).
> [main01.cpp:78] - interval: (0x0,0x5) 
> [main01.cpp:78] - interval: (0x5,0xa) 
> [main01.cpp:78] - interval: (0x16,0x24) 
> [main01.cpp:73] - Variable and location found (g), size(1).
> [main01.cpp:78] - interval: (0x0,0x5) 
> [main01.cpp:78] - interval: (0x5,0xa) 
> [main01.cpp:78] - interval: (0x16,0x24) 
> [main01.cpp:73] - Variable and location found (z), size(1).
> [main01.cpp:78] - interval: (0x0,0x5) 
> [main01.cpp:78] - interval: (0x5,0xa) 
> [main01.cpp:78] - interval: (0x16,0x24) 
> 
> 
> No matter the locationAttribute the code always get the first
> location descriptors in .debug_loc: 
>  
> DWARF section [ 7] '.debug_loc' at offset 0x1c6:
> 
>  CU [ b] base: .text+00 
>  [ 0] range 0, 5
>   .text+00 ..
>   .text+0x0004 
>[ 0] lit0
>[ 1] stack_value
>   range 5, a
>   .text+0x0005 ..
>   .text+0x0009 
>[ 0] reg1
>   range 16, 24
>   .text+0x0016 ..
>   .text+0x0023 
>[ 0] reg1
>  [4a] range 0, 5
>   .text+00 ..
>   .text+0x0004 
>[ 0] lit0
>[ 1] stack_value
>  [6e] range 5, a
>   .text+0x0005 ..
>   .text+0x0009 
>[ 0] lit0
>[ 1] stack_value
>   range a, e
>   .text+0x000a ..
>   .text+0x000d 
>[ 0] const4u 65537
>[ 5] breg0 0
>[ 7] minus
>[ 8] stack_value

I think I see what is happening. The fact that  is at
.text+00 suggests that this is actually an ET_REL file
(not linked object file). The libdw dwarf_xxx calls don't do
relocations. But eu-readelf does. So while eu-readelf shows some
offsets as their relocated values, your program just using dwarf_xxx
calls does not. Specifically the DW_AT_location list attributes will
all point to zero. Which explains why every location list seems to be
the same.

We don't have a public function to just apply all relocations to an
object file, but opening the file through dwfl_begin () will do it.

Something like the attached.

Hope that helps,

Mark
/* Print all locations in the whole DIE tree of a single file using
   dwfl to handle ET_REL files (which need the .debug sections to be
   relocated) and to automatically get separate debuginfo.

   gcc -Wall -Wextra -g -O2 -o dwfl_dwarf dwfl_dwarf.c -ldw
*/

/* We want the sane basename function. */
#define _GNU_SOURCE
#include 
#include 
#include 
#include 

#include 
#include 
#include 

void
handle_die (Dwarf_Die *die)
{
  do
{
  Dwarf_Attribute attr;
  if ((dwarf_attr (die, DW_AT_location, &attr) != NULL))
	{
	  printf ("[%" PRIx64 "]", dwarf_dieoffset (die));
	  ptrdiff_t off = 0;
	  Dwarf_Addr base, start, end;
	  do
	{
	  Dwarf_Op *expr;
	  size_t exprlen;
	  off = dwarf_getlocations(&attr, off, &base, &start, &end,
   &expr, &exprlen);
	  if (off > 0)
		printf ("(%" PRIx64 ",%" PRIx64 ")[%zd] ",
			start, end, exprlen);
	}
	  while (off > 0);
	  printf ("\n");
	}

  Dwarf_Die child;
  if (dwarf_child (die, &child) == 0)
	handle_die (&child);
}
  while (dwarf_siblingof (die, die) == 0);
}

static const Dwfl_Callbacks dwfl_callbacks =
  {
.find_debuginfo = dwfl_standard_find_debuginfo,
.section_address = dwfl_offline_section_address,
.find_elf = dwfl_build_id_find_elf,
  };

int main (int argc, char **argv)
{
  if (argc == 2)
{
  const char *file = argv[1];

[Bug general/25838] eu-readelf crashes due to a general protection fault

2020-06-06 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=25838

--- Comment #4 from Mark Wielaard  ---
Sorry, I cannot replicate even when building elfutils with CC=afl-gcc, with or
without AFL_HARDEN=1. Could you provide more information on how exactly you
configure, build and run.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[PATCH] nm: Explicitly print weak 'V' or 'T' and common 'C' symbols.

2020-06-06 Thread Mark Wielaard
Mimic binutils nm for bsd and posix formats which uses 'V' for weak
symbols, 'C' for common symbols and 'T' for weak functions. Also fix
some formatting issues. Don't print undefined addresses as zeros, but
make sure there is enough padding instead. Just print UNIQUE for
GNU_UNIQUE to make it fit 6 chars, like other binding names in sysv
format.

https://sourceware.org/bugzilla/show_bug.cgi?id=25227

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog|  10 +++
 src/nm.c |  59 ++
 tests/ChangeLog  |   9 +++
 tests/Makefile.am|   3 +-
 tests/run-nm-syms.sh | 166 +++
 tests/testfilesyms32.bz2 | Bin 0 -> 771 bytes
 tests/testfilesyms64.bz2 | Bin 0 -> 652 bytes
 7 files changed, 232 insertions(+), 15 deletions(-)
 create mode 100755 tests/run-nm-syms.sh
 create mode 100644 tests/testfilesyms32.bz2
 create mode 100644 tests/testfilesyms64.bz2

diff --git a/src/ChangeLog b/src/ChangeLog
index c8e6b4e8..4684d332 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,13 @@
+2020-06-06  Mark Wielaard  
+
+   * nm.c (show_symbols_sysv): Skip no name and STT_FILE symbols.
+   When not printing address and size pad strings. Strip "GNU_"
+   prefix from binding name.
+   (class_type_char): Use 'V' for weak symbols, 'C' for common
+   symbols and 'T' for weak functions.
+   (show_symbols_posix): Skip STT_FILE symbols. Don't print value and
+   size when undefined.
+
 2020-06-04  Mark Wielaard  
 
* elflint.c (check_program_header): Remove PT_GNU_PROPERTY define.
diff --git a/src/nm.c b/src/nm.c
index f6ca3b0a..8302a98c 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -797,6 +797,16 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char 
*fullname,
   const char *symstr = sym_name (ebl->elf, strndx, syms[cnt].sym.st_name,
 symstrbuf, sizeof symstrbuf);
 
+  /* Printing entries with a zero-length name makes the output
+not very well parseable.  Since these entries don't carry
+much information we leave them out.  */
+  if (symstr[0] == '\0')
+   continue;
+
+  /* We do not print the entries for files.  */
+  if (GELF_ST_TYPE (syms[cnt].sym.st_info) == STT_FILE)
+   continue;
+
 #ifdef USE_DEMANGLE
   /* Demangle if necessary.  Require GNU v3 ABI by the "_Z" prefix.  */
   if (demangle && symstr[0] == '_' && symstr[1] == 'Z')
@@ -825,7 +835,10 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char 
*fullname,
 
   /* Covert the address.  */
   if (syms[cnt].sym.st_shndx == SHN_UNDEF)
-   addressbuf[0] = sizebuf[0] = '\0';
+   {
+ sprintf (addressbuf, "%*c", digits, ' ');
+ sprintf (sizebuf, "%*c", digits, ' ');
+   }
   else
{
  snprintf (addressbuf, sizeof (addressbuf),
@@ -841,11 +854,14 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char 
*fullname,
}
 
   /* Print the actual string.  */
+  const char *bind;
+  bind = ebl_symbol_binding_name (ebl,
+ GELF_ST_BIND (syms[cnt].sym.st_info),
+ symbindbuf, sizeof (symbindbuf));
+  if (bind != NULL && strncmp (bind, "GNU_", strlen ("GNU_")) == 0)
+   bind += strlen ("GNU_");
   printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n",
- longest_name, symstr, addressbuf,
- ebl_symbol_binding_name (ebl,
-  GELF_ST_BIND (syms[cnt].sym.st_info),
-  symbindbuf, sizeof (symbindbuf)),
+ longest_name, symstr, addressbuf, bind,
  ebl_symbol_type_name (ebl, GELF_ST_TYPE (syms[cnt].sym.st_info),
symtypebuf, sizeof (symtypebuf)),
  sizebuf, longest_where, syms[cnt].where,
@@ -884,6 +900,10 @@ class_type_char (Elf *elf, const GElf_Ehdr *ehdr, GElf_Sym 
*sym)
   if (ehdr->e_ident[EI_OSABI] == ELFOSABI_LINUX
  && GELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
result = 'u';
+  else if (GELF_ST_BIND (sym->st_info) == STB_WEAK)
+   result = 'V';
+  else if (sym->st_shndx == SHN_COMMON)
+   result = 'C';
   else
{
  GElf_Shdr shdr_mem;
@@ -898,6 +918,11 @@ class_type_char (Elf *elf, const GElf_Ehdr *ehdr, GElf_Sym 
*sym)
}
}
 }
+  else if (result == 'T')
+{
+  if (GELF_ST_BIND (sym->st_info) == STB_WEAK)
+   result = 'W';
+}
 
   return local_p ? tolower (result) : result;
 }
@@ -1063,6 +1088,10 @@ show_symbols_posix (Elf *elf, const GElf_Ehdr *ehdr, 
GElf_Word strndx,
   if (symstr[0] == '\0')
continue;
 
+  /* We do not print the entries for files.  */
+  if (GELF_ST_TYPE (syms[cnt].sym.st_info) == STT_FILE)
+   continue;
+
 #ifdef USE_DEMANGLE
   /* Demangle if necessary.  Require GNU v3 ABI by the "_Z" prefix.  */
   if (demangle && s

[Bug general/25227] "eu-nm --extern" skips first symbol

2020-06-06 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=25227

--- Comment #10 from Mark Wielaard  ---
Proposed patch:
https://sourceware.org/pipermail/elfutils-devel/2020q2/002713.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.