public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] lto: fix LTO debug sections copying.
@ 2020-10-05 15:20 Martin Liška
  2020-10-05 15:22 ` Martin Liška
  0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2020-10-05 15:20 UTC (permalink / raw)
  To: gcc-patches

As seen in the PR, we get to situation where we have a big number
of symbols (~125K) and thus we reach .symtab_shndx section usage.
For .symtab we get the following sh_link:

(gdb) p strtab
$1 = 81997

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
...

Apparently the index is starting from 1 and as we skip first section

│   1118          /* Read the section headers.  We skip section 0, which is not a
│   1119             useful section.  */

thus we need to subtract 2.

I run lto.exp and it's fine.
Ready for master?
Thanks,
Martin

libiberty/ChangeLog:

	PR lto/97290
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Fix off-by-one error.
---
  libiberty/simple-object-elf.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 7c9d492f6a4..ce3e809e1e0 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1380,11 +1380,16 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
  	  /* 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 + (strtab - 2) * 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-10-07  6:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05 15:20 [PATCH] lto: fix LTO debug sections copying Martin Liška
2020-10-05 15:22 ` Martin Liška
2020-10-05 16:09   ` Martin Liška
2020-10-05 16:34     ` Ian Lance Taylor
2020-10-06  7:01       ` Martin Liška
2020-10-06  8:00         ` Richard Biener
2020-10-06 10:20           ` Martin Liška
2020-10-06 14:23             ` Jakub Jelinek
2020-10-06 17:34             ` Ian Lance Taylor
2020-10-07  6:56               ` Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).