gdb: rename displaced_step_closure to displaced_step_copy_insn_closure
[binutils-gdb.git] / libctf / ctf-open-bfd.c
index 449347ee39a8836a471bfe88e00f8bf1082374b1..1a00cb674268e854ef21fb18bcafff32cee9223d 100644 (file)
@@ -97,15 +97,40 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
   ctf_sect_t *strsectp = NULL;
   const char *bfderrstr = NULL;
   char *strtab_alloc = NULL;
+  int symsect_endianness = -1;
 
 #ifdef HAVE_BFD_ELF
   ctf_sect_t symsect, strsect;
-  Elf_Internal_Shdr *symhdr = &elf_symtab_hdr (abfd);
+  Elf_Internal_Shdr *symhdr;
   size_t symcount;
   Elf_Internal_Sym *isymbuf;
   bfd_byte *symtab = NULL;
+  const char *symtab_name;
   const char *strtab = NULL;
+  const char *strtab_name;
   size_t strsize;
+  const ctf_preamble_t *preamble;
+
+  if (ctfsect->cts_data == NULL)
+    {
+      bfderrstr = N_("CTF section is NULL");
+      goto err;
+    }
+  preamble = ctf_arc_bufpreamble (ctfsect);
+
+  if (preamble->ctp_flags & CTF_F_DYNSTR)
+    {
+      symhdr = &elf_tdata (abfd)->dynsymtab_hdr;
+      strtab_name = ".dynstr";
+      symtab_name = ".dynsym";
+    }
+  else
+    {
+      symhdr = &elf_tdata (abfd)->symtab_hdr;
+      strtab_name = ".strtab";
+      symtab_name = ".symtab";
+    }
+
   /* TODO: handle SYMTAB_SHNDX.  */
 
   /* Get the symtab, and the strtab associated with it.  */
@@ -145,12 +170,12 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
            strtab = (const char *) strhdr->contents;
        }
     }
-  else         /* No symtab: just try getting .strtab by name.  */
+  else         /* No symtab: just try getting .strtab or .dynstr by name.  */
     {
       bfd_byte *str_bcontents;
       asection *str_asect;
 
-      if ((str_asect = bfd_get_section_by_name (abfd, ".strtab")) != NULL)
+      if ((str_asect = bfd_get_section_by_name (abfd, strtab_name)) != NULL)
        {
          if (bfd_malloc_and_get_section (abfd, str_asect, &str_bcontents))
            {
@@ -168,7 +193,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
         use it for anything but debugging.  */
 
       strsect.cts_data = strtab;
-      strsect.cts_name = ".strtab";
+      strsect.cts_name = strtab_name;
       strsect.cts_size = strsize;
       strsectp = &strsect;
     }
@@ -176,12 +201,14 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
   if (symtab)
     {
       assert (symhdr->sh_entsize == get_elf_backend_data (abfd)->s->sizeof_sym);
-      symsect.cts_name = ".symtab";
+      symsect.cts_name = symtab_name;
       symsect.cts_entsize = symhdr->sh_entsize;
       symsect.cts_size = symhdr->sh_size;
       symsect.cts_data = symtab;
       symsectp = &symsect;
     }
+
+  symsect_endianness = bfd_little_endian (abfd);
 #endif
 
   arci = ctf_arc_bufopen (ctfsect, symsectp, strsectp, errp);
@@ -191,6 +218,10 @@ ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
       arci->ctfi_free_symsect = 1;
       if (strtab_alloc)
        arci->ctfi_free_strsect = 1;
+
+      /* Get the endianness right.  */
+      if (symsect_endianness > -1)
+       ctf_arc_symsect_endianness (arci, symsect_endianness);
       return arci;
     }
 #ifdef HAVE_BFD_ELF