diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-06-27 16:29:44 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-06-27 16:29:44 +0300 |
| commit | b942d430199d8060fbac42a2b37e2d7b1beac243 (patch) | |
| tree | e33d0ad707d69fe30ea6d0582aaef56b3f233645 | |
| parent | 6aefc5167a64e05580dcf1afc70efa496ed145ac (diff) | |
| download | copyjit-b942d430199d8060fbac42a2b37e2d7b1beac243.tar.gz copyjit-b942d430199d8060fbac42a2b37e2d7b1beac243.zip | |
add some info on supported arches
| -rw-r--r-- | Makefile | 29 | ||||
| -rw-r--r-- | README.md | 70 | ||||
| -rw-r--r-- | TODO | 4 | ||||
| -rw-r--r-- | lib/imm.h | 56 | ||||
| -rw-r--r-- | lib/source.mk | 2 |
5 files changed, 130 insertions, 31 deletions
@@ -1,6 +1,11 @@ DO != echo -n > deps.mk -DEBUGFLAGS != [ $(RELEASE) ] && echo "-flto=auto -O2 -DNODEBUG" || echo "-O0 -g -DDEBUG" +LLVM ?= 0 +RELEASE ?= 0 +DEBUGFLAGS != [ "$(RELEASE)" != "0" ] \ + && echo "-flto=auto -O2 -DNODEBUG" \ + || echo "-O0 -g -DDEBUG" + CFLAGS = -Wall -Wextra DEPFLAGS = -MT $@ -MMD -MP -MF $@.d LINTFLAGS = -fsyntax-only @@ -14,8 +19,15 @@ all: copyjit CROSS_COMPILE ?= # common programs -CC = gcc -OBJCOPY = objcopy +OBJCOPY != [ "$(LLVM)" != "0" ] \ + && echo llvm-objcopy \ + || echo $(CROSS_COMPILE)objcopy + +# weird, I thought clang accepted the same system target triplet as gcc? +# apparently it should be passed without a trailing dash, will have to fix +COMPILER != [ "$(LLVM)" != "0" ] \ + && echo clang --target="$(CROSS_COMPILE)" \ + || echo $(CROSS_COMPILE)gcc SOURCES := OP_SOURCES := @@ -24,10 +36,15 @@ IMM_SOURCES := include ops/source.mk include src/source.mk -COMPILE = $(CROSS_COMPILE)$(CC) $(DEBUGFLAGS)\ +# compile tools with these flags +# at the moment just prune.c, wonder if it should be rewritten in some +# scripting language? +HOST_COMPILE = $(CC) $(DEBUGFLAGS) $(CFLAGS) + +COMPILE = $(COMPILER) $(DEBUGFLAGS)\ $(CFLAGS) $(DEPFLAGS) $(COMPILEFLAGS) $(INCLUDEFLAGS) -OP_COMPILE := $(CROSS_COMPILE)$(CC) \ +OP_COMPILE := $(COMPILER) \ -Wall -Wextra -O2 \ -fno-schedule-insns -fno-schedule-insns2 \ -fpic -fpie \ @@ -35,7 +52,7 @@ OP_COMPILE := $(CROSS_COMPILE)$(CC) \ -ffreestanding \ -nostdlib -IMM_COMPILE := $(CROSS_COMPILE)$(CC) \ +IMM_COMPILE := $(COMPILER) \ -Wall -Wextra -O2 \ -fpic -fpie \ -T lib/imm.ld \ @@ -128,3 +128,73 @@ I suspect it would be reasonably easy to use two linker scripts, one for operati that shouldn't take immedates and one for operations that should, with the difference just being that one directly falls through and another jumps over some data appended to it at runime. + +## Arch status + +All GCC test cases were cross-compiled with Debian's prebuilt compiler packages +(`gcc-aarch64-linux-gnu` etc.) and run with qemu usermode emulation with +Debian's prebuilt `qemu-user` package. Similarly, LLVM test cases were compiled +with the same architecture string as the GCC tests. + +For instance, a GCC test case: +``` +make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv64 -j$(nproc) +qemu-riscv64 -L /usr/riscv64-linux-gnu ./copyjit +``` + +And an LLVM test case: +``` +make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv64 -j$(nproc) +qemu-riscv64 -L /usr/riscv64-linux-gnu ./copyjit +``` + +Some of the 'broken' architectures may end up working with some compiler flag +tweaks, similar to aarch64. + +The test setup is far from optimal and ideally I would set up some automatic CI +that would probably be easier to parse. Additionally, I haven't yet put that +much time into figuring out why each arch fails, but I added some of my thoughts +as to what the issue seems to be. + +GCC toolchain, tested with Debian's prebuilt GCC packages: +Linux: +OK: ++ `x86_64` ++ `i686` ++ `riscv64` ++ `aarch64` ++ `arm` + +Broken: ++ `mips64el` (possibly due to bug in instruction cache flushing? otherwise unsure) ++ `mips64` ++ `mipsel` ++ `mips` ++ `sparc64` (fails to generate continuation passing) ++ `sh4` (fails to generate continuation passing (I think?)) ++ `s390x` (doesn't crash, but seems to jump over some code or something?) ++ `m68k` (segfault, unclear why) ++ `powerpc64le` (fails to generate continuation passing) ++ `powerpc64` ++ `powerpc` + +Fails to compile: ++ `hppa64` (missing string.h?) ++ `hppa` ('undefined reference to `$$dyncall`) ++ `alpha` (`'internal compiler error: in extract_insn, at recog.cc:2791'`) + +Untestable (by me at least): ++ `arc` (compiles but doesn't have a qemu user emulator) + +LLVM toolchain: + +OK: ++ `x86_64` ++ `aarch64` ++ `riscv64` + +Broken: ++ `i686` (fails to generate continuation passing) ++ `arm` (unsure, possibly some branch issue) + +TODO: continue testing LLVM @@ -0,0 +1,4 @@ ++ Add in placeholders for immediate values ++ Remove GCC flags unknown to LLVM and vice versa ++ Fix warnings on 32bit systems ++ Figure out compiler flags/tweaks currently broken architectures would require @@ -1,43 +1,51 @@ #ifndef COPYJIT_IMM_H #define COPYJIT_IMM_H unsigned char gen_addia[] = { - 0x48, 0x03, 0x35, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0xbe, 0x95, + 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; -unsigned int gen_addia_len = 20; +unsigned int gen_addia_len = 28; unsigned char gen_addio[] = { - 0x4c, 0x03, 0x05, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0x3e, 0x97, + 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; -unsigned int gen_addio_len = 20; +unsigned int gen_addio_len = 28; unsigned char gen_addix[] = { - 0x48, 0x03, 0x15, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0x3e, 0x96, + 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; -unsigned int gen_addix_len = 20; +unsigned int gen_addix_len = 28; unsigned char gen_addiy[] = { - 0x48, 0x03, 0x0d, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0xbe, 0x96, + 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }; -unsigned int gen_addiy_len = 20; +unsigned int gen_addiy_len = 28; unsigned char gen_lia[] = { - 0x48, 0x8b, 0x35, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x25, 0x01, 0x8c, 0x61, 0x17, 0x03, + 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; -unsigned int gen_lia_len = 20; +unsigned int gen_lia_len = 26; unsigned char gen_lio[] = { - 0x4c, 0x8b, 0x05, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x17, 0x07, 0x00, 0x00, 0x13, 0x07, 0x27, 0x01, 0x18, 0x63, 0x17, 0x03, + 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; -unsigned int gen_lio_len = 20; +unsigned int gen_lio_len = 26; unsigned char gen_lix[] = { - 0x48, 0x8b, 0x15, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x17, 0x06, 0x00, 0x00, 0x13, 0x06, 0x26, 0x01, 0x10, 0x62, 0x17, 0x03, + 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; -unsigned int gen_lix_len = 20; +unsigned int gen_lix_len = 26; unsigned char gen_liy[] = { - 0x48, 0x8b, 0x0d, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00, - 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x97, 0x06, 0x00, 0x00, 0x93, 0x86, 0x26, 0x01, 0x94, 0x62, 0x17, 0x03, + 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; -unsigned int gen_liy_len = 20; +unsigned int gen_liy_len = 26; #endif /* COPYJIT_OPS_H */ diff --git a/lib/source.mk b/lib/source.mk index e1ba486..9403aff 100644 --- a/lib/source.mk +++ b/lib/source.mk @@ -1,6 +1,6 @@ # some glue to keep everything together lib/prune: lib/empty.bin - $(COMPILE) lib/prune.c -o lib/prune + $(HOST_COMPILE) lib/prune.c -o lib/prune lib/empty.c: ops/common.h lib/empty.bin: lib/empty |
