On 14/02/18 11:41, Jakub Jelinek wrote:
Hi!

As mentioned in detail in the PR, PowerPC64 ELFv1 function symbols
point to function descriptors in .opd section rather than actual
code, and one needs to read the code address from the .opd section
in order to associate symbols with .text addresses.

Fixed thusly, bootstrapped/regtested on powerpc64-linux (-m32/-m64
testing) and powerpc64le-linux, ok for trunk?

2018-02-14  Jakub Jelinek  <ja...@redhat.com>

        PR other/82368
        * elf.c (EM_PPC64, EF_PPC64_ABI): Undefine and define.
        (struct elf_ppc64_opd_data): New type.
        (elf_initialize_syminfo): Add opd argument, handle symbols
        pointing into the PowerPC64 ELFv1 .opd section.
        (elf_add): Read .opd section on PowerPC64 ELFv1, pass pointer
        to structure with .opd data to elf_initialize_syminfo.

--- libbacktrace/elf.c.jj       2018-02-08 20:46:10.671242369 +0000
+++ libbacktrace/elf.c  2018-02-14 08:39:06.674088951 +0000
...
@@ -2857,6 +2889,23 @@ elf_add (struct backtrace_state *state,
              debuglink_crc = *(const uint32_t*)(debuglink_data + crc_offset);
            }
        }
+
+      /* Read the .opd section on PowerPC64 ELFv1.  */
+      if (ehdr.e_machine == EM_PPC64
+         && (ehdr.e_flags & EF_PPC64_ABI) < 2
+         && shdr->sh_type == SHT_PROGBITS

this broke baremetal arm targets (e.g. aarch64-none-elf with newlib)

...src/gcc/libbacktrace/elf.c: In function 'elf_add':
...src/gcc/libbacktrace/elf.c:2896:24: error: 'SHT_PROGBITS' undeclared (first 
use in this function)

    && shdr->sh_type == SHT_PROGBITS
                        ^~~~~~~~~~~~


+         && strcmp (name, ".opd") == 0)
+       {
+         if (!backtrace_get_view (state, descriptor, shdr->sh_offset,
+                                  shdr->sh_size, error_callback, data,
+                                  &opd_data.view))
+           goto fail;
+
+         opd = &opd_data;
+         opd->addr = shdr->sh_addr;
+         opd->data = (const char *) opd_data.view.data;
+         opd->size = shdr->sh_size;
+       }
      }
if (symtab_shndx == 0)

Reply via email to