[Bug general/21011] "may be used uninitialized" error with -Werror=maybe-uninitialized

2017-04-19 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=21011

--- Comment #10 from Mark Wielaard  ---
That is a pretty involved way to configure elfutils. You do add various
-Wno-error=unused-but-set-variable -Wno-error=unused-result options. Why not
just add -Wno-error=maybe-uninitialized in that case?

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

[PATCH] libelf: Initialize n to zero in elf_getarsym.

2017-04-19 Thread Mark Wielaard
When building with gcc -Os it seems we can inline read_number_entries
but if that function fails then n will not be initialized. GCC seems not
to realize that in that case n won't be used at all. Explicitly initialize
n to zero to prevent a spurious error: 'n' may be used uninitialized in
this function [-Werror=maybe-uninitialized] in that case.

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

Signed-off-by: Mark Wielaard 
---
 libelf/ChangeLog  | 4 
 libelf/elf_getarsym.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 23a4fb9..d425e50 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-19  Mark Wielaard  
+
+   * elf_getarsym.c (elf_getarsym): Initialize n to zero.
+
 2017-03-27  Mark Wielaard  
 
* elf32_updatefile.c (updatemmap): Always update last_positition.
diff --git a/libelf/elf_getarsym.c b/libelf/elf_getarsym.c
index d5f0ba4..1f031fc 100644
--- a/libelf/elf_getarsym.c
+++ b/libelf/elf_getarsym.c
@@ -167,7 +167,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
 
   /* We have an archive.  The first word in there is the number of
 entries in the table.  */
-  uint64_t n;
+  uint64_t n = 0;
   size_t off = elf->start_offset + SARMAG + sizeof (struct ar_hdr);
   if (read_number_entries (&n, elf, &off, index64_p) < 0)
{
-- 
1.8.3.1



[Bug general/21011] "may be used uninitialized" error with -Werror=maybe-uninitialized

2017-04-19 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=21011

--- Comment #11 from Mark Wielaard  ---
So the flag that seem to trigger it is -Os (but only on 32bit systems?).
Proposed the following:

commit 7114c513fbebcca8b76796b7f64b57447ba383e1
Author: Mark Wielaard 
Date:   Wed Apr 19 17:07:46 2017 +0200

libelf: Initialize n to zero in elf_getarsym.

When building with gcc -Os it seems we can inline read_number_entries
but if that function fails then n will not be initialized. GCC seems not
to realize that in that case n won't be used at all. Explicitly initialize
n to zero to prevent a spurious error: 'n' may be used uninitialized in
this function [-Werror=maybe-uninitialized] in that case.

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

Signed-off-by: Mark Wielaard 

https://sourceware.org/ml/elfutils-devel/2017-q2/msg00042.html

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

Re: frame unwinding patches

2017-04-19 Thread Mark Wielaard
On Tue, 2017-04-11 at 12:16 +0200, Ulf Hermann wrote:
> > I do agree with Jan that frame pointer unwinding is notoriously
> > untrustworthy. Even with some sanity checks it is hard to know whether
> > you are doing a correct unwind. gdb gets away with it through pretty
> > advanced frame sniffers, which take a lot of low-level compiler
> > generation knowledge to get correct (and even then...). You only restore
> > the pc, stack and frame pointer registers (maybe incorrectly). So
> > afterwards, even if you got valid CFI data you might be stuck.
> 
> Yes, especially with mixed stack traces, where part of the stack has
> CFI and part of it doesn't, we quickly run into guesswork. I've
> regenerated the binaries as suggested, with the result being that
> raise() from libc actually has CFI, but doesn't set a frame pointer.
> So, the frame pointer unwinder can find raise() in the link register,
> but it sets up the FP register with the wrong value. Then raise() is
> unwound using CFI, which mixes up the registers some more. At that
> point we're lost. I don't see an easy way out of this.

That might just mean that the testcase is slightly unrealistic.
Getting a reliable backtrace through signal handlers when not having
full CFI is probably not something we can expect to work. That doesn't
mean having a frame pointer based fallback is a bad thing. We probably
should find a more realistic testcase. And maybe in the future add an
interface to allow people to unwind through "pure CFI" or mixed mode
with frame markers that tell the caller whether the registers can be
trusted or not.

> I will keep a version of the frame unwinding for perfparser as it's
> still better than not unwinding at all, but I do understand that it's
> not really suitable for mainline elfutils.

Really I do think it would be nice to have. I certainly didn't mean it
isn't suitable for mainline. We just should be realistic about the
expectations. IMHO if at all possible we should get this upstream so you
don't have to carry extra patches.

Cheers,

Mark


[Bug general/21011] "may be used uninitialized" error with -Werror=maybe-uninitialized

2017-04-19 Thread luizluca at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21011

--- Comment #12 from Luiz Angelo Daros de Luca  ---
Great! Thanks!

How about libcpu/i386_disasm.c case?

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

Re: dwfl_attach_state alternative taking Ebl?

2017-04-19 Thread Mark Wielaard
On Tue, 2017-04-11 at 14:27 +0200, Ulf Hermann wrote:
> The code would be cleaner if we could attach_state before starting to 
> parse. And there might be pathological cases where no valid elf file can 
> ever be found but we can still unwind by frame pointer.

Another reason to try and get the frame pointer based unwinder
upstream :)

Cheers,

Mark


[Bug general/21011] "may be used uninitialized" error with -Werror=maybe-uninitialized

2017-04-19 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=21011

--- Comment #13 from Mark Wielaard  ---
(In reply to Luiz Angelo Daros de Luca from comment #12)
> Great! Thanks!
> 
> How about libcpu/i386_disasm.c case?

Don't use -DNDEBUG. assert is a noreturn function. The asserts in the code are
deliberately there. If they fail something is seriously wrong.

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

[Bug general/21011] "may be used uninitialized" error with -Werror=maybe-uninitialized

2017-04-19 Thread luizluca at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=21011

--- Comment #14 from Luiz Angelo Daros de Luca  ---
I do not set -DNDEBUG. All compiler flags are similar in this case. Maybe a gcc
bug?

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