From a5259595e7a6faac0240d257f7e9cfa599557d2e Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 4 Oct 2017 09:54:52 +1030 Subject: [PATCH] PowerPC64 ELFv2 symbols not needed in get_synthetic_symtab * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't sort or classify symbols for ELFv2. --- bfd/ChangeLog | 5 ++ bfd/elf64-ppc.c | 141 +++++++++++++++++++++++++----------------------- 2 files changed, 80 insertions(+), 66 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ce948c8222e..cffa777b42c 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2017-10-04 Alan Modra + + * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Don't sort or + classify symbols for ELFv2. + 2017-10-04 Pavel I. Kryukov PR 22245 diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 63c89840d28..53ea30e43bf 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -3270,77 +3270,86 @@ ppc64_elf_get_synthetic_symtab (bfd *abfd, return 0; } - symcount = static_count; - if (!relocatable) - symcount += dyn_count; - if (symcount == 0) - return 0; - - syms = bfd_malloc ((symcount + 1) * sizeof (*syms)); - if (syms == NULL) - return -1; - - if (!relocatable && static_count != 0 && dyn_count != 0) + syms = NULL; + codesecsym = 0; + codesecsymend = 0; + secsymend = 0; + opdsymend = 0; + symcount = 0; + if (opd != NULL) { - /* Use both symbol tables. */ - memcpy (syms, static_syms, static_count * sizeof (*syms)); - memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms)); - } - else if (!relocatable && static_count == 0) - memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms)); - else - memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms)); - - synthetic_relocatable = relocatable; - synthetic_opd = opd; - qsort (syms, symcount, sizeof (*syms), compare_symbols); - - if (!relocatable && symcount > 1) - { - long j; - /* Trim duplicate syms, since we may have merged the normal and - dynamic symbols. Actually, we only care about syms that have - different values, so trim any with the same value. */ - for (i = 1, j = 1; i < symcount; ++i) - if (syms[i - 1]->value + syms[i - 1]->section->vma - != syms[i]->value + syms[i]->section->vma) - syms[j++] = syms[i]; - symcount = j; - } - - i = 0; - /* Note that here and in compare_symbols we can't compare opd and - sym->section directly. With separate debug info files, the - symbols will be extracted from the debug file while abfd passed - to this function is the real binary. */ - if (opd != NULL && strcmp (syms[i]->section->name, ".opd") == 0) - ++i; - codesecsym = i; - - for (; i < symcount; ++i) - if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) - != (SEC_CODE | SEC_ALLOC)) - || (syms[i]->flags & BSF_SECTION_SYM) == 0) - break; - codesecsymend = i; + symcount = static_count; + if (!relocatable) + symcount += dyn_count; + if (symcount == 0) + return 0; - for (; i < symcount; ++i) - if ((syms[i]->flags & BSF_SECTION_SYM) == 0) - break; - secsymend = i; + syms = bfd_malloc ((symcount + 1) * sizeof (*syms)); + if (syms == NULL) + return -1; - if (opd != NULL) - for (; i < symcount; ++i) - if (strcmp (syms[i]->section->name, ".opd") != 0) - break; - opdsymend = i; + if (!relocatable && static_count != 0 && dyn_count != 0) + { + /* Use both symbol tables. */ + memcpy (syms, static_syms, static_count * sizeof (*syms)); + memcpy (syms + static_count, dyn_syms, + (dyn_count + 1) * sizeof (*syms)); + } + else if (!relocatable && static_count == 0) + memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms)); + else + memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms)); + + synthetic_relocatable = relocatable; + synthetic_opd = opd; + qsort (syms, symcount, sizeof (*syms), compare_symbols); + + if (!relocatable && symcount > 1) + { + long j; + /* Trim duplicate syms, since we may have merged the normal and + dynamic symbols. Actually, we only care about syms that have + different values, so trim any with the same value. */ + for (i = 1, j = 1; i < symcount; ++i) + if (syms[i - 1]->value + syms[i - 1]->section->vma + != syms[i]->value + syms[i]->section->vma) + syms[j++] = syms[i]; + symcount = j; + } + + i = 0; + /* Note that here and in compare_symbols we can't compare opd and + sym->section directly. With separate debug info files, the + symbols will be extracted from the debug file while abfd passed + to this function is the real binary. */ + if (opd != NULL && strcmp (syms[i]->section->name, ".opd") == 0) + ++i; + codesecsym = i; + + for (; i < symcount; ++i) + if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC + | SEC_THREAD_LOCAL)) + != (SEC_CODE | SEC_ALLOC)) + || (syms[i]->flags & BSF_SECTION_SYM) == 0) + break; + codesecsymend = i; - for (; i < symcount; ++i) - if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) - != (SEC_CODE | SEC_ALLOC)) - break; - symcount = i; + for (; i < symcount; ++i) + if ((syms[i]->flags & BSF_SECTION_SYM) == 0) + break; + secsymend = i; + + for (; i < symcount; ++i) + if (strcmp (syms[i]->section->name, ".opd") != 0) + break; + opdsymend = i; + for (; i < symcount; ++i) + if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL)) + != (SEC_CODE | SEC_ALLOC)) + break; + symcount = i; + } count = 0; if (relocatable) -- 2.30.2