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