From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 0E3733942001 for ; Mon, 5 Oct 2020 16:09:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0E3733942001 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CD00FB12A; Mon, 5 Oct 2020 16:09:22 +0000 (UTC) Subject: Re: [PATCH] lto: fix LTO debug sections copying. From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: gcc-patches@gcc.gnu.org References: <7924754a-8a5a-04ac-4e46-157376806f74@suse.cz> <0a28a10a-86d2-ec66-d782-1eabcbba20e6@suse.cz> Message-ID: <02134394-2562-e2d5-132a-60459ce0faa2@suse.cz> Date: Mon, 5 Oct 2020 18:09:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: <0a28a10a-86d2-ec66-d782-1eabcbba20e6@suse.cz> Content-Type: multipart/mixed; boundary="------------47051F733EBAD3D18D9D18F7" Content-Language: en-US X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Oct 2020 16:09:25 -0000 This is a multi-part message in MIME format. --------------47051F733EBAD3D18D9D18F7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi. The previous patch was not correct. This one should be. Ready for master? Thanks, Martin --------------47051F733EBAD3D18D9D18F7 Content-Type: text/x-patch; charset=UTF-8; name="0001-lto-fix-LTO-debug-sections-copying.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-lto-fix-LTO-debug-sections-copying.patch" >From a96f7ae39b5d56ce886edf1bfb9ca6475a857652 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 5 Oct 2020 18:03:08 +0200 Subject: [PATCH] lto: fix LTO debug sections copying. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit readelf -S prints: There are 81999 section headers, starting at offset 0x1f488060: Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 01404f 00 81998 0 0 [ 1] .group GROUP 0000000000000000 000040 000008 04 81995 105027 4 ... [81995] .symtab SYMTAB 0000000000000000 d5d9298 2db310 18 81997 105026 8 [81996] .symtab_shndx SYMTAB SECTION INDICES 0000000000000000 d8b45a8 079dd8 04 81995 0 4 [81997] .strtab STRTAB 0000000000000000 d92e380 80460c 00 0 0 1 ... Looking at the documentation: Table 7–15 ELF sh_link and sh_info Interpretation sh_type - sh_link SHT_SYMTAB - The section header index of the associated string table. SHT_SYMTAB_SHNDX - The section header index of the associated symbol table. As seen, sh_link of a SHT_SYMTAB always points to a .strtab and readelf confirms that. So we need to use reverse mapping taken from [81996] .symtab_shndx SYMTAB SECTION INDICES 0000000000000000 d8b45a8 079dd8 04 81995 0 4 where sh_link points to 81995. libiberty/ChangeLog: PR lto/97290 * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Use sh_link of a .symtab_shndx section. --- libiberty/simple-object-elf.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c index 7c9d492f6a4..37e73348cb7 100644 --- a/libiberty/simple-object-elf.c +++ b/libiberty/simple-object-elf.c @@ -1191,7 +1191,7 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj, unsigned int sh_link; sh_link = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, shdr, sh_link, Elf_Word); - symtab_indices_shndx[sh_link - 1] = i; + symtab_indices_shndx[sh_link - 1] = i - 1; /* Always discard the extended index sections, after copying it will not be needed. This way we don't need to update it and deal with the ordering constraints of @@ -1372,19 +1372,22 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj, { unsigned entsize = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, shdr, sh_entsize, Elf_Addr); - unsigned strtab = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, - shdr, sh_link, Elf_Word); size_t prevailing_name_idx = 0; unsigned char *ent; unsigned *shndx_table = NULL; /* Read the section index table if present. */ if (symtab_indices_shndx[i - 1] != 0) { - unsigned char *sidxhdr = shdrs + (strtab - 1) * shdr_size; + unsigned char *sidxhdr = shdrs + symtab_indices_shndx[i - 1] * shdr_size; off_t sidxoff = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, sidxhdr, sh_offset, Elf_Addr); size_t sidxsz = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, sidxhdr, sh_size, Elf_Addr); + unsigned int shndx_type + = ELF_FETCH_FIELD (type_functions, ei_class, Shdr, + sidxhdr, sh_type, Elf_Word); + if (shndx_type != SHT_SYMTAB_SHNDX) + return "Wrong section type of a SYMTAB SECTION INDICES section"; shndx_table = (unsigned *)XNEWVEC (char, sidxsz); simple_object_internal_read (sobj->descriptor, sobj->offset + sidxoff, -- 2.28.0 --------------47051F733EBAD3D18D9D18F7--