diff options
author | Martin Liska <mliska@suse.cz> | 2020-10-05 18:03:08 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-10-06 16:07:02 +0200 |
commit | 190c04ba36d9c6c3dce41f12012aa97c6d7f22f5 (patch) | |
tree | 5ae616d53d3231f9a73afd4a03b0a1494cc0dc5d /libiberty | |
parent | a9a88a0a55e131172960fe56013965a7ab4eaf96 (diff) | |
download | gcc-190c04ba36d9c6c3dce41f12012aa97c6d7f22f5.zip gcc-190c04ba36d9c6c3dce41f12012aa97c6d7f22f5.tar.gz gcc-190c04ba36d9c6c3dce41f12012aa97c6d7f22f5.tar.bz2 |
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
...
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.
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/simple-object-elf.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c index 7c9d492..37e7334 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, |