diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2025-04-25 18:26:45 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2025-04-25 21:23:07 +0100 |
commit | 27d5d0ccc73858336cdca094b80cfefded3d1061 (patch) | |
tree | a7bf50c1e32e251a1fbc4af70186ba6929485637 | |
parent | 0a283f3d7a84286111eeed792e41856160a6937e (diff) | |
download | binutils-27d5d0ccc73858336cdca094b80cfefded3d1061.zip binutils-27d5d0ccc73858336cdca094b80cfefded3d1061.tar.gz binutils-27d5d0ccc73858336cdca094b80cfefded3d1061.tar.bz2 |
libctf: open-bfd: open BTF dicts
Teaching ctf_open and ctf_fdopen to open BTF dicts if passed is quite
simple: we just need to check the magic number and allow BTF dicts
into the lower-level ctf_simple_open machinery (which ultimately
calls ctf_bufopen).
-rw-r--r-- | libctf/ctf-open-bfd.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c index 7241de7..d121011 100644 --- a/libctf/ctf-open-bfd.c +++ b/libctf/ctf-open-bfd.c @@ -56,7 +56,8 @@ ctf_bfdopen (struct bfd *abfd, int *errp) libctf_init_debug(); - if ((ctf_asect = bfd_get_section_by_name (abfd, _CTF_SECTION)) == NULL) + if (((ctf_asect = bfd_get_section_by_name (abfd, _CTF_SECTION)) == NULL) + && ((ctf_asect = bfd_get_section_by_name (abfd, ".BTF")) == NULL)) { return (ctf_set_open_errno (errp, ECTF_NOCTFDATA)); } @@ -257,26 +258,32 @@ ctf_fdopen (int fd, const char *filename, const char *target, int *errp) struct stat st; ssize_t nbytes; - ctf_preamble_t ctfhdr; + ctf_preamble_v3_t *ctfhdr; + ctf_btf_preamble_t btfhdr; uint64_t arc_magic; - memset (&ctfhdr, 0, sizeof (ctfhdr)); + memset (&btfhdr, 0, sizeof (btfhdr)); libctf_init_debug(); if (fstat (fd, &st) == -1) return (ctf_set_open_errno (errp, errno)); - if ((nbytes = ctf_pread (fd, &ctfhdr, sizeof (ctfhdr), 0)) <= 0) + if ((nbytes = ctf_pread (fd, &btfhdr, sizeof (btfhdr) > sizeof (ctfhdr) + ? sizeof (btfhdr) : 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, in either endianness, attempt to interpret the file as raw - CTF. */ - - if ((size_t) nbytes >= sizeof (ctf_preamble_t) - && (ctfhdr.ctp_magic == CTF_MAGIC - || ctfhdr.ctp_magic == bswap_16 (CTF_MAGIC))) + ctfhdr = (ctf_preamble_v3_t *) &btfhdr; + + /* If we have read enough bytes to form a CTF or BTF header and the magic + string matches, in either endianness, attempt to interpret the file as raw + CTF/BTF. */ + + if (((size_t) nbytes >= sizeof (ctf_preamble_v3_t) + && (ctfhdr->ctp_magic == CTF_MAGIC + || ctfhdr->ctp_magic == bswap_16 (CTF_MAGIC))) + || ((size_t) nbytes >= sizeof (ctf_btf_preamble_t) + && (btfhdr.btf_magic == CTF_BTF_MAGIC + || btfhdr.btf_magic == bswap_16 (CTF_BTF_MAGIC)))) { ctf_dict_t *fp = NULL; void *data; |