diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2025-03-20 16:40:06 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2025-03-20 16:40:06 +0000 |
commit | c4bc0f74f9b623df0d62742af106d24f3c1af1fe (patch) | |
tree | 851e45a826a75b453f142a9906dc48b9144c38ec /libctf/ctf-open-bfd.c | |
parent | aba7ef898745fd09d03ad4ebedcd11f68abc5160 (diff) | |
download | binutils-c4bc0f74f9b623df0d62742af106d24f3c1af1fe.zip binutils-c4bc0f74f9b623df0d62742af106d24f3c1af1fe.tar.gz binutils-c4bc0f74f9b623df0d62742af106d24f3c1af1fe.tar.bz2 |
libctf: more compilation error fixes
Compiles now. Still doesn't work yet...
Diffstat (limited to 'libctf/ctf-open-bfd.c')
-rw-r--r-- | libctf/ctf-open-bfd.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c index 354efac..731303c 100644 --- a/libctf/ctf-open-bfd.c +++ b/libctf/ctf-open-bfd.c @@ -258,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; |