GNU Binutils with patches for OS216
Revision | 0860f6373e0df2b8dcece04dd874f95c3f09e3df (tree) |
---|---|
Zeit | 2017-11-27 02:38:09 |
Autor | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
Check corrupted symbol table
bfd/
PR binutils/12639
* elfcode.h (elf_slurp_symbol_table): Check corrupted global
symbols.
binutils/
PR binutils/12639
* readelf.c (process_symbol_table): Detect corrupted symbol
table.
@@ -1173,6 +1173,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) | ||
1173 | 1173 | sym = symbase = NULL; |
1174 | 1174 | else |
1175 | 1175 | { |
1176 | + /* Start of global symbols */ | |
1177 | + Elf_Internal_Sym *start_global; | |
1178 | + | |
1176 | 1179 | isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0, |
1177 | 1180 | NULL, NULL, NULL); |
1178 | 1181 | if (isymbuf == NULL) |
@@ -1218,6 +1221,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) | ||
1218 | 1221 | if (xver != NULL) |
1219 | 1222 | ++xver; |
1220 | 1223 | isymend = isymbuf + symcount; |
1224 | + start_global = isymbuf; | |
1225 | + if (!elf_bad_symtab (abfd)) | |
1226 | + start_global += hdr->sh_info; | |
1221 | 1227 | for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++) |
1222 | 1228 | { |
1223 | 1229 | memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym)); |
@@ -1275,6 +1281,12 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) | ||
1275 | 1281 | if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) |
1276 | 1282 | sym->symbol.value -= sym->symbol.section->vma; |
1277 | 1283 | |
1284 | + if (isym < start_global | |
1285 | + && ELF_ST_BIND (isym->st_info) != STB_LOCAL) | |
1286 | + (*_bfd_error_handler) | |
1287 | + (_("%s: corrupted global symbol `%s' treated as local"), | |
1288 | + abfd->filename, sym->symbol.name); | |
1289 | + | |
1278 | 1290 | switch (ELF_ST_BIND (isym->st_info)) |
1279 | 1291 | { |
1280 | 1292 | case STB_LOCAL: |
@@ -11571,6 +11571,12 @@ process_symbol_table (Filedata * filedata) | ||
11571 | 11571 | && filedata->section_headers != NULL) |
11572 | 11572 | { |
11573 | 11573 | unsigned int i; |
11574 | + /* Irix 5 and 6 are broken. Object file symbol tables are not | |
11575 | + always sorted correctly such that local symbols precede global | |
11576 | + symbols, and the sh_info field in the symbol table is not | |
11577 | + always right. */ | |
11578 | + bfd_boolean check_corrupt_symtab | |
11579 | + = filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_IRIX; | |
11574 | 11580 | |
11575 | 11581 | for (i = 0, section = filedata->section_headers; |
11576 | 11582 | i < filedata->file_header.e_shnum; |
@@ -11640,7 +11646,12 @@ process_symbol_table (Filedata * filedata) | ||
11640 | 11646 | putchar (' '); |
11641 | 11647 | print_vma (psym->st_size, DEC_5); |
11642 | 11648 | printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); |
11643 | - printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
11649 | + if (check_corrupt_symtab | |
11650 | + && si < section->sh_info | |
11651 | + && ELF_ST_BIND (psym->st_info) != STB_LOCAL) | |
11652 | + printf (" %-6s", "<corrupt>"); | |
11653 | + else | |
11654 | + printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); | |
11644 | 11655 | if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) |
11645 | 11656 | printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); |
11646 | 11657 | else |