From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42977 invoked by alias); 25 Feb 2019 20:17:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 38853 invoked by uid 89); 25 Feb 2019 20:17:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=BAYES_00,GIT_PATCH_1,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1911, H*Ad:D*google.com, familiar, H*r:sk:mail-pf X-HELO: mail-pf1-f202.google.com Received: from mail-pf1-f202.google.com (HELO mail-pf1-f202.google.com) (209.85.210.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Feb 2019 20:17:34 +0000 Received: by mail-pf1-f202.google.com with SMTP id a72so8575899pfj.19 for ; Mon, 25 Feb 2019 12:17:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=doKB+aGhA4D6uRh6cEKLAj5x4wclUHCuiqS3vMV1nUQ=; b=qbk6GS7ZjWkAFclVGVyrHrGCy2JEZo1Xevez8NnNeT58o2cr7hMz2vUV1DmzzprMYy gW4/GmJifsk01K00nwj/PwuJP2GIQm7A5r+rAHrIU491gl0V8JO1yF6Cgg645E9N+gdL Rfonwoih7LrKLeVi2Vdxbv31TjPcAqggqtYg6nxeAQ8IyCWafSLcwCIe0PaRhRxMgzoi VVMm6Td+UfrPZ08cjZvJt1nBYWlaLsoKYCBCwwfomiPS8AseJHOpe9Y+NJ6tqeuWw5OV 04pffZtn1PFKFXS7nPdT4A5InyZ9AxfnVU1y2HdvBamkSmv43+qz7MvXLprNUdj4ei8r HTqg== Date: Mon, 25 Feb 2019 20:17:00 -0000 In-Reply-To: <439bf4f6859a539472a2e51a028b9503@polymtl.ca> Message-Id: <20190225201715.144927-1-rupprecht@google.com> Mime-Version: 1.0 References: <439bf4f6859a539472a2e51a028b9503@polymtl.ca> Subject: Re: [PATCH] [dwarf2read] Fix crash when loading dwp files: calculate num_sections based on actual section indices, not just the number of sections. From: "Jordan Rupprecht via gdb-patches" Reply-To: Jordan Rupprecht To: gdb-patches@sourceware.org Cc: echristo@gmail.com, dblaikie@gmail.com, dje@google.com Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2019-02/txt/msg00417.txt.bz2 On Sat, Feb 23, 2019 at 8:01 PM Simon Marchi wrote: > > On 2019-02-22 19:53, Jordan Rupprecht via gdb-patches wrote: > > When loading dwp files, we create an array of elf sections indexed by > > the section index in the dwp file. The size of this array is > > calculated by section_count + 1 (the +1 handling the null section). > > However, when loading the bfd file, strtab/symtab sections are not > > added to the list, nor do they increment section_count, so > > section_count is actually smaller than the number of sections. > > Just wondering, is this the expected behavior of BFD, to not make the > strtab section count as a section (as far as bfd_count_sections is > concerned)? If so, why? I'm not very familiar with bfd, so I don't know if it's expected. It seems that bfd->sections contains "interesting" sections (e.g. progbits), and treats sections like strtab/symtab as a kind of metadata section that get stored differently. The method I'm stepping through is bfd_section_from_shdr here: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=f16acaa08d8e24af9af069efcdcb244b2c19c734;hb=HEAD#l1994. Running that method over a normal .dwp file, all the .debug_* methods get added to sections, but .strtab/.symtab/.shstrtab don't. So it *seems* like that's expected behavior, but I can't say for sure that it is. > > Otherwise can we just elf_numsections instead of bfd_count_sections? > Since we index the array by ELF section index, using the number of ELF > sections seems appropriate, it should always match. We wouldn't need > the +1 then. Don't know how I didn't see that. Now I don't need get_largest_section_index() anymore. Thanks! All your comments are basically not relevant any more :)