x86: drop a few dead macros
[deliverable/binutils-gdb.git] / libctf / ctf-open-bfd.c
index d6d442ea42580b0510d59608447eddd7ed59a8d0..bb2d7e64de21b9c1aa8f69e75bf7159b5c8824d9 100644 (file)
@@ -26,6 +26,8 @@
 #include <fcntl.h>
 #include <elf.h>
 #include <bfd.h>
+#include "swap.h"
+#include "ctf-endian.h"
 
 #include "elf-bfd.h"
 
@@ -97,10 +99,7 @@ ctf_bfdopen (struct bfd *abfd, int *errp)
     }
 
   ctfsect.cts_name = _CTF_SECTION;
-  ctfsect.cts_type = SHT_PROGBITS;
-  ctfsect.cts_flags = 0;
   ctfsect.cts_entsize = 1;
-  ctfsect.cts_offset = 0;
   ctfsect.cts_size = bfd_section_size (abfd, ctf_asect);
   ctfsect.cts_data = contents;
 
@@ -119,7 +118,8 @@ ctf_bfdopen (struct bfd *abfd, int *errp)
    later.  */
 
 ctf_archive_t *
-ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
+ctf_bfdopen_ctfsect (struct bfd *abfd _libctf_unused_,
+                    const ctf_sect_t *ctfsect, int *errp)
 {
   struct ctf_archive *arc = NULL;
   ctf_archive_t *arci;
@@ -129,6 +129,7 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
   const char *bfderrstr = NULL;
   int is_archive;
 
+#ifdef HAVE_BFD_ELF
   asection *sym_asect;
   ctf_sect_t symsect, strsect;
   /* TODO: handle SYMTAB_SHNDX.  */
@@ -156,10 +157,8 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
            }
          strsect.cts_data = contents;
          strsect.cts_name = (char *) strsect.cts_data + strhdr->sh_name;
-         strsect.cts_type = strhdr->sh_type;
-         strsect.cts_flags = strhdr->sh_flags;
+         strsect.cts_size = bfd_section_size (abfd, str_asect);
          strsect.cts_entsize = strhdr->sh_size;
-         strsect.cts_offset = strhdr->sh_offset;
          strsectp = &strsect;
 
          if (!bfd_malloc_and_get_section (abfd, sym_asect, &contents))
@@ -170,14 +169,13 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
            }
 
          symsect.cts_name = (char *) strsect.cts_data + symhdr->sh_name;
-         symsect.cts_type = symhdr->sh_type;
-         symsect.cts_flags = symhdr->sh_flags;
          symsect.cts_entsize = symhdr->sh_size;
+         symsect.cts_size = bfd_section_size (abfd, sym_asect);
          symsect.cts_data = contents;
-         symsect.cts_offset = symhdr->sh_offset;
          symsectp = &symsect;
        }
     }
+#endif
 
   if (ctfsect->cts_size > sizeof (uint64_t) &&
       ((*(uint64_t *) ctfsect->cts_data) == CTFA_MAGIC))
@@ -203,9 +201,11 @@ ctf_bfdopen_ctfsect (struct bfd *abfd, const ctf_sect_t *ctfsect, int *errp)
   if (arci)
     return arci;
  err_free_sym:
+#ifdef HAVE_BFD_ELF
   free ((void *) symsect.cts_data);
 err_free_str:
   free ((void *) strsect.cts_data);
+#endif
 err: _libctf_unused_;
   if (bfderrstr)
     {
@@ -245,24 +245,27 @@ ctf_fdopen (int fd, const char *filename, const char *target, int *errp)
   if ((nbytes = ctf_pread (fd, &ctfhdr, sizeof (ctfhdr), 0)) <= 0)
     return (ctf_set_open_errno (errp, nbytes < 0 ? errno : ECTF_FMT));
 
-  /* If we have read enough bytes to form a CTF header and the magic
-     string matches, attempt to interpret the file as raw CTF.  */
+  /* If we have read enough bytes to form a CTF header and the magic string
+     matches, in either endianness, attempt to interpret the file as raw
+     CTF.  */
 
-  if ((size_t) nbytes >= sizeof (ctf_preamble_t) &&
-      ctfhdr.ctp_magic == CTF_MAGIC)
+  if ((size_t) nbytes >= sizeof (ctf_preamble_t)
+      && (ctfhdr.ctp_magic == CTF_MAGIC
+         || ctfhdr.ctp_magic == bswap_16 (CTF_MAGIC)))
     {
       ctf_file_t *fp = NULL;
       void *data;
 
-      if (ctfhdr.ctp_version > CTF_VERSION)
-       return (ctf_set_open_errno (errp, ECTF_CTFVERS));
-
       if ((data = ctf_mmap (st.st_size, 0, fd)) == NULL)
        return (ctf_set_open_errno (errp, errno));
 
       if ((fp = ctf_simple_open (data, (size_t) st.st_size, NULL, 0, 0,
                                 NULL, 0, errp)) == NULL)
-       ctf_munmap (data, (size_t) st.st_size);
+       {
+         ctf_munmap (data, (size_t) st.st_size);
+         return NULL;                  /* errno is set for us.  */
+       }
+
       fp->ctf_data_mmapped = data;
       fp->ctf_data_mmapped_len = (size_t) st.st_size;
 
@@ -272,7 +275,7 @@ ctf_fdopen (int fd, const char *filename, const char *target, int *errp)
   if ((nbytes = ctf_pread (fd, &arc_magic, sizeof (arc_magic), 0)) <= 0)
     return (ctf_set_open_errno (errp, nbytes < 0 ? errno : ECTF_FMT));
 
-  if ((size_t) nbytes >= sizeof (uint64_t) && arc_magic == CTFA_MAGIC)
+  if ((size_t) nbytes >= sizeof (uint64_t) && le64toh (arc_magic) == CTFA_MAGIC)
     {
       struct ctf_archive *arc;
 
This page took 0.028626 seconds and 4 git commands to generate.