aboutsummaryrefslogtreecommitdiff
path: root/fesvr
diff options
context:
space:
mode:
authorMarcus Comstedt <marcus@mc.pp.se>2020-10-10 13:03:43 +0200
committerGitHub <noreply@github.com>2020-10-10 04:03:43 -0700
commite4419aa79a3c999e85610616d6e85847b08f7e19 (patch)
tree8e56eaa401bd2bf119a68a37f0c8b8d7fe75d1da /fesvr
parent72e5cabe6e3efa1658ad424403cd166aa8a008d2 (diff)
downloadspike-e4419aa79a3c999e85610616d6e85847b08f7e19.zip
spike-e4419aa79a3c999e85610616d6e85847b08f7e19.tar.gz
spike-e4419aa79a3c999e85610616d6e85847b08f7e19.tar.bz2
Fix new ELF checks on big endian hosts (#567)
The new macros IS_ELF_... introduced in 80b5b2f5 were not endian safe.
Diffstat (limited to 'fesvr')
-rw-r--r--fesvr/elf.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/fesvr/elf.h b/fesvr/elf.h
index a213832..7b38bf1 100644
--- a/fesvr/elf.h
+++ b/fesvr/elf.h
@@ -14,14 +14,16 @@
((hdr).e_ident[0] == 0x7f && (hdr).e_ident[1] == 'E' && \
(hdr).e_ident[2] == 'L' && (hdr).e_ident[3] == 'F')
+#define ELF_SWAP(hdr, val) (IS_ELFLE(hdr)? from_le((val)) : from_be((val)))
+
#define IS_ELF32(hdr) (IS_ELF(hdr) && (hdr).e_ident[4] == 1)
#define IS_ELF64(hdr) (IS_ELF(hdr) && (hdr).e_ident[4] == 2)
#define IS_ELFLE(hdr) (IS_ELF(hdr) && (hdr).e_ident[5] == 1)
#define IS_ELFBE(hdr) (IS_ELF(hdr) && (hdr).e_ident[5] == 2)
-#define IS_ELF_EXEC(hdr) (IS_ELF(hdr) && (hdr).e_type == ET_EXEC)
-#define IS_ELF_RISCV(hdr) (IS_ELF(hdr) && (hdr).e_machine == EM_RISCV)
-#define IS_ELF_EM_NONE(hdr) (IS_ELF(hdr) && (hdr).e_machine == EM_NONE)
-#define IS_ELF_VCURRENT(hdr) (IS_ELF(hdr) && (hdr).e_version == EV_CURRENT)
+#define IS_ELF_EXEC(hdr) (IS_ELF(hdr) && ELF_SWAP((hdr), (hdr).e_type) == ET_EXEC)
+#define IS_ELF_RISCV(hdr) (IS_ELF(hdr) && ELF_SWAP((hdr), (hdr).e_machine) == EM_RISCV)
+#define IS_ELF_EM_NONE(hdr) (IS_ELF(hdr) && ELF_SWAP((hdr), (hdr).e_machine) == EM_NONE)
+#define IS_ELF_VCURRENT(hdr) (IS_ELF(hdr) && ELF_SWAP((hdr), (hdr).e_version) == EV_CURRENT)
#define PT_LOAD 1