From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 3D7F6385BF81 for ; Tue, 19 May 2020 14:50:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3D7F6385BF81 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.193] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id AA5C71EDD8; Tue, 19 May 2020 10:50:12 -0400 (EDT) Subject: Re: [PATCH] [PR 25678] gdb crashes with "internal-error: sect_index_text not initialized" when .text To: mlimber Cc: gdb-patches@sourceware.org References: <072e4b2b-4d71-b343-c8ef-0edbc6ab6804@simark.ca> <59eeb6ee-1ab2-e5aa-000a-2fb6d522b8d0@simark.ca> From: Simon Marchi Message-ID: Date: Tue, 19 May 2020 10:44:54 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 14:50:14 -0000 On 2020-05-19 10:36 a.m., mlimber wrote: > I have skimmed that code, but we're beyond my ken here. The things I observe in that code are: > > 1. This only acts on files with 1 or 2 segments. (It gets skipped for libtestcase.so as you say.) > > 2. If the segment info is 1 or 2, it sets two segment indices to refer to this one segment. Perhaps that's legit (I'm a naif when it comes to ELF details), but it struck me as odd. > > 3. Line 300, where this function is called, has this curious comment: > > /* This is where things get really weird... We MUST have valid > > indices for the various sect_index_* members or gdb will abort. > > So if for example, there is no ".text" section, we have to > > accomodate that. First, check for a file with the standard > > one or two segments. */ I reached the same conclusions. > >   > > So I'm curious, in your libicudata.so library, how many segments there are.  That > can be checked with: > >   $ readelf -l libicudata.so.52 | grep LOAD > > > I have two load segments: > > readelf -l libicudata.so > > Elf file type is DYN (Shared object file) > Entry point 0x2b6 > There are 6 program headers, starting at offset 64 > > Program Headers: >   Type           Offset             VirtAddr           PhysAddr >                  FileSiz            MemSiz              Flags  Align >   LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000 >                  0x000000000166a940 0x000000000166a940  R      200000 >   LOAD           0x000000000166af30 0x000000000186af30 0x000000000186af30 >                  0x00000000000000d0 0x00000000000000d0  RW     200000 >   DYNAMIC        0x000000000166af30 0x000000000186af30 0x000000000186af30 >                  0x00000000000000d0 0x00000000000000d0  RW     8 >   NOTE           0x0000000000000190 0x0000000000000190 0x0000000000000190 >                  0x0000000000000024 0x0000000000000024  R      4 >   GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000 >                  0x0000000000000000 0x0000000000000000  RW     10 >   GNU_RELRO      0x000000000166af30 0x000000000186af30 0x000000000186af30 >                  0x00000000000000d0 0x00000000000000d0  R      1 Are we inspecting the same library? In the libicudata.so.52 you've sent, there are three load segments: $ readelf -l libicudata.so.52.2 | grep LOAD LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x166a940 0x166a940 R 0x200000 LOAD 0x166af30 0x000000000186af30 0x000000000186af30 0x0000d0 0x0000d0 RW 0x200000 LOAD 0x166c000 0x000000000186b000 0x000000000186b000 0x000180 0x000180 RW 0x1000 I successfully reproduced the bug using your lib. Since there's no DWARF info, it fails in init_entry_point_info. With my lib, it fails earlier, when the DWARF info is read. Anyway, it's all variations of the same bug, some code assumes that sect_index_text is set to some valid value.< > I note that there is an entry point specified on the second line of output, which is curious to me since there is no code in this library. I noticed that too, shared libraries have entry points... that fields looks mandatory in the ELF header, so it can probably just be ignored. > > Perhaps if we forced an extra load segment in this .so, it would produce different results due to skipping the function cited above. >   > > If the libicudata.so.52 is really the problematic one, I'm a bit surprised that you > don't always see the problem when debugging a program that uses it. > > > I'm also not sure why it sometimes happens and sometimes doesn't. Could it be something with how or when it is loaded -- say, in a certain sequence or via a manual dlopen() instead of via dynamic linking info? The only reason I would see is that you might not be loading the libicudata.so you think you are loading. Simon