Re: [PATCH] backends: add abi_cfi and register_info callbacks for RISC-V

2018-06-20 Thread Mark Wielaard
Hi Andreas,

On Mon, 2018-06-18 at 09:59 +0200, Andreas Schwab wrote:
> On Jun 15 2018, Mark Wielaard  wrote:
> 
> > How does the result of make check look now on a native riscv
> > system?
> 
> FAIL: run-native-test.sh
> 
> return_value_location is missing

Sadly DWARF doesn't describe how return values are passed back. So
you'll have to write that by hand for the abi. It normally isn't that
hard for scalar types, sometimes there is some trickery for floats or
small structs.

> FAIL: run-low_high_pc.sh
> 
> lowpc: 220, highpc: 220lx
> ../../elfutils/src/size.c: [c84] 'handle_elf' highpc <= lowpc
> 
> lowpc: 41c, highpc: 41clx
> ../../elfutils/src/strip.c: [1c00] 'update_section_size' highpc <=
> lowpc

That is odd. For which testfile is this? Is it for a native (self test)
file? If it is for an ET_REL object file it might be that we don't
handle all relocations correctly. If you could post the file somewhere,
that might be helpful to track down the issue.

> FAIL: run-backtrace-native.sh
> FAIL: run-backtrace-dwarf.sh
> FAIL: run-deleted.sh
> 
> set_initial_registers_tid is missing

If the target has ptrace support this probably wouldn't be too hard to
get going.

> FAIL: run-backtrace-native-core.sh
> 
> no corefile support

That would need a corenote backend implementation.

> SKIP: run-backtrace-data.sh
> 
> no unwinding support

That is expected. It really is an architecture specific (x86_64) test.

> > Could you provide a testcase for tests/run-allregs.sn and/or
> > tests/run-addrcfi.sh if possible so people can check things work on
> > other arches?
> > 
> > If this is enough to actually unwind could you look at providing an
> > tests/run-backtrace-core-riscv.sh testcase (the existing ones
> > should
> > explain how to generate the (static) executable and core file for
> > the
> > test, but if it is unclear please ask.
> 
> I will work on these.

Thanks. Without tests it is hard to know if an arch is really fully
functional and it risks bit-rotting.

I have added a ChangeLog entry for your patch and pushed it to master.

Cheers,

Mark


Re: [PATCH] libdw: aggregate_size check NULL result from get_type.

2018-06-20 Thread Mark Wielaard
On Mon, 2018-06-18 at 10:37 +0200, Mark Wielaard wrote:
> aggregate_size can be called recursively with the result of get_type.
> get_type can return NULL when dwarf_peel_type fails. Found by afl-
> fuzz.
> 
> dwarf_aggregate_size when called directly doesn't need a NULL check
> because it calls and checks the result of dwarf_peel_type directly.

Pushed to master.


Re: [PATCH v2] backends,bpf: add proper relocation support

2018-06-20 Thread Mark Wielaard
On Sat, 2018-06-16 at 13:02 -0700, Yonghong Song wrote:
> Due to libdw does not have proper BPF relocation support,
> the pahole cannot display filenames correctly for objects
> with default llvm options. So we have to invent
> a special option "llc -march=bpf -mattr=dwarfris" to
> prevent llvm from generating cross-section dwarf relocation
> records (https://reviews.llvm.org/rL326505).
> The pahole related discussion is in linux netdev
> mailing list (http://lists.openwall.net/netdev/2018/06/15/38, etc.)
> 
> We would like to add proper BPF relocation support
> to libdw so eventually we could retire the special llc bpf
> flag "-mattr=dwarfris".
> 
> The bpf relocations are defined in
> llvm_repo:include/llvm/BinaryFormat/ELFRelocs/BPF.def:
>   ELF_RELOC(R_BPF_NONE,0)
>   ELF_RELOC(R_BPF_64_64,   1)
>   ELF_RELOC(R_BPF_64_32,  10)
> 
> Removed the relocation type R_BPF_MAP_FD whoes name does not
> confirm to llvm definition and replaced it with R_BPF_64_64.
> The BPF object is just a relocatible object, not an executable or
> a shared library, so assign ELF type to REL only in bpf_reloc.def.
> 
> Signed-off-by: Yonghong Song 
> ---
>  backends/ChangeLog  |   7 +
>  backends/Makefile.am|   2 +-
>  backends/bpf_init.c |   1 +
>  backends/bpf_reloc.def  |   3 +-
>  backends/bpf_symbol.c   |  54
> 
>  libelf/elf.h|   3 +-
>  tests/ChangeLog |   9 ++
>  tests/Makefile.am   |   5 +++-
>  tests/run-reloc-bpf.sh  |  33 ++
>  tests/testfile-bpf-reloc.expect.bz2 | Bin 0 -> 300 bytes
>  tests/testfile-bpf-reloc.o.bz2  | Bin 0 -> 933 bytes
>  11 files changed, 113 insertions(+), 4 deletions(-)
>  create mode 100644 backends/bpf_symbol.c
>  create mode 100755 tests/run-reloc-bpf.sh
>  create mode 100644 tests/testfile-bpf-reloc.expect.bz2
>  create mode 100644 tests/testfile-bpf-reloc.o.bz2
> 
> Note:
>  I didn't add the Changelog to libelf/elf.h as I anticipate the
>  change will come from sync'ing with glibc.
>  If this patch version looks good, I can send another revision
>  once the libelf/elf.h is synced.

The patch looks perfect. And the new testcase is good. I used the
testfile to quickly test eu-readelf --debug-dump also got the
relocations right, and it did of course.

Just waiting for the glibc elf.h update/sync and then I'll push this to
master.

Thanks,

Mark


Re: [PATCH] libdw: dwarf_peel_type break long chains/cycles.

2018-06-20 Thread Mark Wielaard
On Mon, 2018-06-18 at 10:42 +0200, Mark Wielaard wrote:
> Limit the number of chained modifiers to 64 (that is 8 chains for all
> 8 modifiers, most of which cannot be chained). This prevents loops in
> the DWARF DIE DW_AT_type references.

Pushed to master.


Re: [PATCH] libdw: Break dwarf_aggregate_size recursion because of type cycles.

2018-06-20 Thread Mark Wielaard
On Mon, 2018-06-18 at 12:44 +0200, Mark Wielaard wrote:
> Found by afl-fuzz. An array type (indirectly) referring to itself in the
> DIE tree could blow up the stack when dwarf_aggregate_size was called.
> Limit the recursion depth to MAX_DEPTH (256) entries.

Pushed to master.


Re: [PATCH] backends: add abi_cfi and register_info callbacks for RISC-V

2018-06-20 Thread Andreas Schwab
On Jun 20 2018, Mark Wielaard  wrote:

>> FAIL: run-low_high_pc.sh
>> 
>> lowpc: 220, highpc: 220lx
>> ../../elfutils/src/size.c: [c84] 'handle_elf' highpc <= lowpc
>> 
>> lowpc: 41c, highpc: 41clx
>> ../../elfutils/src/strip.c: [1c00] 'update_section_size' highpc <=
>> lowpc
>
> That is odd. For which testfile is this? Is it for a native (self test)
> file?

Yes, the object files for these 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."


Re: [PATCH] backends: add abi_cfi and register_info callbacks for RISC-V

2018-06-20 Thread Mark Wielaard
On Wed, 2018-06-20 at 14:38 +0200, Andreas Schwab wrote:
> On Jun 20 2018, Mark Wielaard  wrote:
> 
> > > FAIL: run-low_high_pc.sh
> > > 
> > > lowpc: 220, highpc: 220lx
> > > ../../elfutils/src/size.c: [c84] 'handle_elf' highpc <= lowpc
> > > 
> > > lowpc: 41c, highpc: 41clx
> > > ../../elfutils/src/strip.c: [1c00] 'update_section_size' highpc
> > > <=
> > > lowpc
> > 
> > That is odd. For which testfile is this? Is it for a native (self
> > test)
> > file?
> 
> Yes, the object files for these sources.

If you could post them somewhere we can see what is wrong.

Thanks,

Mark


[Bug general/23320] New: Incorrect usage of sizeof

2018-06-20 Thread serban at us dot ibm.com
https://sourceware.org/bugzilla/show_bug.cgi?id=23320

Bug ID: 23320
   Summary: Incorrect usage of sizeof
   Product: elfutils
   Version: unspecified
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: general
  Assignee: unassigned at sourceware dot org
  Reporter: serban at us dot ibm.com
CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

The following diff show the incorrect usages of the sizeof routine:
--> git diff src/ar.c src/nm.c src/readelf.c
diff --git a/src/ar.c b/src/ar.c
index bfb324c..58c8b11 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -919,7 +919,7 @@ do_oper_delete (const char *arfname, char **argv, int argc,
long int instance)
 {
   bool *found = alloca (sizeof (bool) * argc);
-  memset (found, '\0', sizeof (found));
+  memset (found, '\0', sizeof (bool) * argc);

   /* List of the files we keep.  */
   struct armem *to_copy = NULL;
diff --git a/src/nm.c b/src/nm.c
index f78861e..6c86298 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -752,7 +752,7 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char
*fullname,
   if (unlikely (name == NULL))
{
  name = alloca (sizeof "[invalid sh_name 0x12345678]");
- snprintf (name, sizeof name, "[invalid sh_name %#" PRIx32 "]",
+ snprintf (name, sizeof "[invalid sh_name 0x12345678]", "[invalid
sh_name %#" PRIx32 "]",
gelf_getshdr (scn, &shdr_mem)->sh_name);
}
   scnnames[elf_ndxscn (scn)] = name;
diff --git a/src/readelf.c b/src/readelf.c
index 4032bd4..69b2abb 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4787,7 +4787,7 @@ register_info (Ebl *ebl, unsigned int regno, const
Ebl_Register_Location *loc,
 bits ?: &ignore, type ?: &ignore);
   if (n <= 0)
 {
-  snprintf (name, sizeof name, "reg%u", loc->regno);
+  snprintf (name, REGNAMESZ, "reg%u", loc->regno);
   if (bits != NULL)
*bits = loc->bits;
   if (type != NULL)

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

[Bug general/23320] Incorrect usage of sizeof

2018-06-20 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=23320

Mark Wielaard  changed:

   What|Removed |Added

 CC||mark at klomp dot org

--- Comment #1 from Mark Wielaard  ---
Thanks, but I believe you are using an old version of elfutils.
In the current code these bugs have already been fixed by:

commit 1a4d0668d18bf1090c5c08cdb5cb3ba2b8eb5410
Author: David Abdurachmanov 
Date:   Sun Jan 13 16:44:21 2013 +0100

ar.c (do_oper_delete): Fix num passed to memset.

Signed-off-by: David Abdurachmanov 

commit 57bd66cabf6e6b9ecf622cdbf350804897a8df58
Author: Roland McGrath 
Date:   Tue Dec 11 09:42:07 2012 -0800

nm: Fix size passed to snprintf for invalid sh_name case.

Signed-off-by: Roland McGrath 

commit 8d1e297a883c35eae53914a1739fdf0bfb590a6e
Author: Marek Polacek 
Date:   Tue Oct 4 05:11:42 2011 -0400

readelf.c: Assume the right size of an array

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

Re: [PATCH] backends: add abi_cfi and register_info callbacks for RISC-V

2018-06-20 Thread Mark Wielaard
On Wed, 2018-06-20 at 15:55 +0200, Andreas Schwab wrote:
> It's probably because there are more than just simple relocations on
> debug sections, more than reloc_simple_type can handle.

aha, ok, but it looks like RISCV_(ADD|SUB)(8|16|32|64) should not be
too hard to handle. The other ones (RISCV_SETX) might be a little
harder. They are not used much though and only against .debug_frame. So
if you get RISC_ADD/SUB going that probably handles most uses. Maybe
backend reloc_simple_type hook needs to be changed a bit to handle
them. But that shouldn't really be a problem, all callers are internal
(libdwfl/relocate.c and strip.c).

Cheers,

Mark


[Bug general/23320] Incorrect usage of sizeof

2018-06-20 Thread serban at us dot ibm.com
https://sourceware.org/bugzilla/show_bug.cgi?id=23320

--- Comment #2 from serban at us dot ibm.com ---
Darn, yes, I cloned from another fork, don't know how.  I re-cloned from
upstream and it build w/no problems now.

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

[Bug general/23320] Incorrect usage of sizeof

2018-06-20 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=23320

Mark Wielaard  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #3 from Mark Wielaard  ---
No worries, the issues were real. Just already solved.

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