Patchwork Work-around for a bug in GCC5.

login
register
mail settings
Submitter Alexander Klimov
Date Jan. 27, 2015, 6:14 p.m.
Message ID <TheMailAgent.7a67d083@6dc232f2>
Download mbox | patch
Permalink /patch/4829/
State New
Headers show

Comments

Alexander Klimov - Jan. 27, 2015, 6:14 p.m.
Compilation of (GDB) 7.9.50.20150127-cvs with (GCC) 5.0.0 20150127 
fails with

In file included from symfile.c:32:0:
symfile.c: In function 'unmap_overlay_command':
objfiles.h:628:3: error: 'sec' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
   ^
symfile.c:3442:23: note: 'sec' was declared here
   struct obj_section *sec;
                       ^
cc1: all warnings being treated as errors
make[2]: *** [symfile.o] Error 1
make[2]: Leaving directory `gdb/gdb'

While the bug was reported to GCC as
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64823>,
the attached patch simply initializes sec with NULL.
Mark Wielaard - Jan. 27, 2015, 9:31 p.m.
On Tue, Jan 27, 2015 at 08:14:39PM +0200, Alexander Klimov wrote:
> Compilation of (GDB) 7.9.50.20150127-cvs with (GCC) 5.0.0 20150127 
> fails with
> 
> In file included from symfile.c:32:0:
> symfile.c: In function 'unmap_overlay_command':
> objfiles.h:628:3: error: 'sec' may be used uninitialized in this 
> function [-Werror=maybe-uninitialized]
>    for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
>    ^
> symfile.c:3442:23: note: 'sec' was declared here
>    struct obj_section *sec;
>                        ^
> cc1: all warnings being treated as errors
> make[2]: *** [symfile.o] Error 1
> make[2]: Leaving directory `gdb/gdb'
> 
> While the bug was reported to GCC as
> <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64823>,
> the attached patch simply initializes sec with NULL.

Thanks for reducing it to something simpler! I was somewhat embarrassed
I couldn't find a simpler case that showed the issue. I had a different
fix, but I couldn't figure out why it was necessary:
https://sourceware.org/ml/gdb-patches/2015-01/msg00665.html

Your fix is simpler and it is more clear why it is a real workaround.
I think my fix is technically more correct since it makes the code
and error emmitted in this case more like the other commands (although
it isn't clear if that really matters, it is still an error case). But it
isn't immediately clear why it is a good workaround for this GCC5 issue.

What do others think? Could someone approve either of the fixes?
Getting a fix in to make GDB compile with GCC5 would be really welcome.

Thanks,

Mark

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c

index d55e361..86a758a 100644

--- a/gdb/symfile.c

+++ b/gdb/symfile.c

@@ -3439,7 +3439,7 @@  static void

 unmap_overlay_command (char *args, int from_tty)
 {
   struct objfile *objfile;
-  struct obj_section *sec;

+  struct obj_section *sec = NULL;

 
   if (!overlay_debugging)
     error (_("Overlay debugging not enabled.  "