On 10/6/20 10:00 AM, Richard Biener wrote:
On Tue, Oct 6, 2020 at 9:01 AM Martin Liška <mli...@suse.cz> wrote:
On 10/5/20 6:34 PM, Ian Lance Taylor wrote:
On Mon, Oct 5, 2020 at 9:09 AM Martin Liška <mli...@suse.cz> wrote:
The previous patch was not correct. This one should be.
Ready for master?
I don't understand why this code uses symtab_indices_shndx at all.
There should only be one SHT_SYMTAB_SHNDX section. There shouldn't be
any need for the symtab_indices_shndx vector.
Well, the question is if we can have multiple .symtab sections in one ELF
file? Theoretically yes, so we should also handle SHT_SYMTAB_SHNDX sections.
Note that the original usage of the SHT_SYMTAB_SHNDX section was motivated
by PR81968 which is about Solaris ld.
It wasn't my code but I suppose this way the implementation was
"easiest". There
should be exactly one symtab / shndx section. Rainer authored this support.
If we expect at maximum one SHT_SYMTAB_SHNDX section section, then I'm
suggesting
an updated version of the patch. It's what Ian offered.
Thoughts?
Martin
But in any case this patch looks OK.
I also think the patch looks OK. Rainer?
Richard.
Waiting for a feedback from Richi.
Thanks,
Martin
Thanks.
Ian
>From bb259b4dc2a79ef45d449896d05855122ecc2ef9 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Mon, 5 Oct 2020 18:03:08 +0200
Subject: [PATCH] lto: fix LTO debug sections copying.
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
...
Expect only at maximum one .symtab_shndx section.
libiberty/ChangeLog:
PR lto/97290
* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
Expect only one .symtab_shndx section.
---
libiberty/simple-object-elf.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 7c9d492f6a4..6dc5c60a842 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1109,7 +1109,7 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
unsigned new_i;
unsigned *sh_map;
unsigned first_shndx = 0;
- unsigned int *symtab_indices_shndx;
+ unsigned int symtab_shndx = 0;
shdr_size = (ei_class == ELFCLASS32
? sizeof (Elf32_External_Shdr)
@@ -1151,9 +1151,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
pfnret = XNEWVEC (int, shnum);
pfnname = XNEWVEC (const char *, shnum);
- /* Map of symtab to index section. */
- symtab_indices_shndx = XCNEWVEC (unsigned int, shnum - 1);
-
/* First perform the callbacks to know which sections to preserve and
what name to use for those. */
for (i = 1; i < shnum; ++i)
@@ -1188,10 +1185,9 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
shdr, sh_type, Elf_Word);
if (sh_type == SHT_SYMTAB_SHNDX)
{
- 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;
+ if (symtab_shndx != 0)
+ return "Multiple SYMTAB SECTION INDICES sections";
+ symtab_shndx = 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
@@ -1323,7 +1319,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
*err = 0;
XDELETEVEC (names);
XDELETEVEC (shdrs);
- XDELETEVEC (symtab_indices_shndx);
return "ELF section name out of range";
}
@@ -1341,7 +1336,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
{
XDELETEVEC (names);
XDELETEVEC (shdrs);
- XDELETEVEC (symtab_indices_shndx);
return errmsg;
}
@@ -1362,7 +1356,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
XDELETEVEC (buf);
XDELETEVEC (names);
XDELETEVEC (shdrs);
- XDELETEVEC (symtab_indices_shndx);
return errmsg;
}
@@ -1372,19 +1365,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)
+ if (symtab_shndx != 0)
{
- unsigned char *sidxhdr = shdrs + (strtab - 1) * shdr_size;
+ unsigned char *sidxhdr = shdrs + symtab_shndx * 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,
@@ -1543,7 +1539,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
{
XDELETEVEC (names);
XDELETEVEC (shdrs);
- XDELETEVEC (symtab_indices_shndx);
return errmsg;
}
@@ -1585,7 +1580,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
XDELETEVEC (shdrs);
XDELETEVEC (pfnret);
XDELETEVEC (pfnname);
- XDELETEVEC (symtab_indices_shndx);
XDELETEVEC (sh_map);
return NULL;
--
2.28.0