From patchwork Sat Jan 24 13:30:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 4792 Received: (qmail 17470 invoked by alias); 24 Jan 2015 13:31:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17448 invoked by uid 89); 24 Jan 2015 13:31:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sat, 24 Jan 2015 13:31:28 +0000 From: Mark Wielaard To: gdb-patches@sourceware.org Cc: Mark Wielaard Subject: [PATCH] GCC5 build error. unmap_overlay_command doesn't check section_is_overlay. Date: Sat, 24 Jan 2015 14:30:37 +0100 Message-Id: <1422106237-20723-1-git-send-email-mjw@redhat.com> MIME-Version: 1.0 X-Spam-Score: -2.9 (--) Building with gcc (GCC) 5.0.0 20150123 (experimental) gives the following error: In file included from /home/mark/src/binutils-gdb/gdb/symfile.c:32:0: /home/mark/src/binutils-gdb/gdb/symfile.c: In function ‘unmap_overlay_command’: /home/mark/src/binutils-gdb/gdb/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++) \ ^ /home/mark/src/binutils-gdb/gdb/symfile.c:3442:23: note: ‘sec’ was declared here struct obj_section *sec; ^ cc1: all warnings being treated as errors This comes from the following construct: /* First, find a section matching the user supplied argument. */ ALL_OBJSECTIONS (objfile, sec) if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args)) { if (!sec->ovly_mapped) error (_("Section %s is not mapped"), args); sec->ovly_mapped = 0; return; } error (_("No overlay section called %s"), args); ALL_OBJSECTIONS is defined in gdb/objfiles.h as two nested for statements that try to make sure that if one breaks from the second for loop the first for loop is also terminated. The definition is slightly hairy (you might want to read the comments in objfiles.h that explain it). for (osect = objfile->sections; osect < objfile->sections_end; osect++) \ if (osect->the_bfd_section == NULL) \ { \ /* Nothing. */ \ } \ else for ((objfile) = current_program_space->objfiles, \ (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \ (objfile) != NULL \ && (osect) == (objfile)->sections_end; \ ((osect) == (objfile)->sections_end \ ? ((objfile) = (objfile)->next, \ (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \ : 0)) \ ALL_OBJFILE_OSECTIONS (objfile, osect) This is the only ALL_OBJSECTIONS construct that gives this error. The only difference with the others is that they all contain an (indirect) call to section_is_overlay (sec). Adding that check here solves the error. Adding the check also a bit more correct in this case. A non-overlay section with the given name would otherwise give the error "is not mapped" (only overlay sections can be mapped), while the correct error would be the second "No overlay section". But I am not entirely sure why adding the check solves the issue. It might be because section_is_overlay does an explicit NULL pointer check. Without an explicit check for NULL the compiler might decide sec is only used in a < comparison or by dereferencing, both of which imply sec can never be NULL (because that would be undefined behavior). So one of the conditions in the for loops is always true and most of the code can be optimized away? The code relies on the fact that osect = objfile->sections; osect < objfile->sections_end; osect++; will eventually end with (osect) == (objfile)->sections_end. But I am not sure that the C language pointer rules really guarantee that. --- gdb/symfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index d55e361..5c80892 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3451,7 +3451,9 @@ unmap_overlay_command (char *args, int from_tty) /* First, find a section matching the user supplied argument. */ ALL_OBJSECTIONS (objfile, sec) - if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args)) + if (section_is_overlay (sec) + && !strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), + args)) { if (!sec->ovly_mapped) error (_("Section %s is not mapped"), args);