From e604410d3eafc77e1b9a7fbb0580a23e528f0037 Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Fri, 2 Aug 2019 19:45:15 +0200 Subject: riscv: tools: Fix prelink-riscv to work on big endian hosts All ELF fields whose values are inspected by the code are converted to CPU byteorder first. Values which are copied verbatim (relocation fixups) are not swapped to CPU byteorder and back as it is not needed. Signed-off-by: Marcus Comstedt Cc: Rick Chen Reviewed-by: Rick Chen --- tools/prelink-riscv.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tools/prelink-riscv.c') diff --git a/tools/prelink-riscv.c b/tools/prelink-riscv.c index 52eb78e9d0..a900a1497a 100644 --- a/tools/prelink-riscv.c +++ b/tools/prelink-riscv.c @@ -8,10 +8,6 @@ * without fixup. Both RV32 and RV64 are supported. */ -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ -#error "Only little-endian host is supported" -#endif - #include #include #include @@ -25,6 +21,7 @@ #include #include #include +#include #ifndef EM_RISCV #define EM_RISCV 243 -- cgit From 4539926a9c47638951f29f550f3a640e4c223032 Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Fri, 2 Aug 2019 19:45:16 +0200 Subject: riscv: tools: Add big endian target support to prelink-riscv Signed-off-by: Marcus Comstedt Cc: Rick Chen Reviewed-by: Rick Chen --- tools/prelink-riscv.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tools/prelink-riscv.c') diff --git a/tools/prelink-riscv.c b/tools/prelink-riscv.c index a900a1497a..b0467949eb 100644 --- a/tools/prelink-riscv.c +++ b/tools/prelink-riscv.c @@ -47,12 +47,28 @@ const char *argv0; exit(EXIT_FAILURE); \ } while (0) +#define PRELINK_BYTEORDER le #define PRELINK_INC_BITS 32 #include "prelink-riscv.inc" +#undef PRELINK_BYTEORDER #undef PRELINK_INC_BITS +#define PRELINK_BYTEORDER le #define PRELINK_INC_BITS 64 #include "prelink-riscv.inc" +#undef PRELINK_BYTEORDER +#undef PRELINK_INC_BITS + +#define PRELINK_BYTEORDER be +#define PRELINK_INC_BITS 32 +#include "prelink-riscv.inc" +#undef PRELINK_BYTEORDER +#undef PRELINK_INC_BITS + +#define PRELINK_BYTEORDER be +#define PRELINK_INC_BITS 64 +#include "prelink-riscv.inc" +#undef PRELINK_BYTEORDER #undef PRELINK_INC_BITS int main(int argc, const char *const *argv) @@ -88,11 +104,19 @@ int main(int argc, const char *const *argv) die("Invalid ELF file %s", argv[1]); bool is64 = e_ident[EI_CLASS] == ELFCLASS64; - - if (is64) - prelink64(data); - else - prelink32(data); + bool isbe = e_ident[EI_DATA] == ELFDATA2MSB; + + if (is64) { + if (isbe) + prelink_be64(data); + else + prelink_le64(data); + } else { + if (isbe) + prelink_be32(data); + else + prelink_le32(data); + } return 0; } -- cgit