-
Notifications
You must be signed in to change notification settings - Fork 5
Description
This is what I'm trying to do, and it almost works:
$ mkdir nettle-tkey
$ cd nettle-tkey
$ ~/hack/nettle/configure --host=riscv32-unknown-none CC='clang-15 --target=riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -nostdlib -fno-common -fno-builtin-printf -fno-builtin-putchar -mno-relax -O2 -Wall' --disable-shared --enable-mini-gmp --with-include-path=/home/nisse/hack/tkey/tkey-libs/include:/home/nisse/hack/tkey/include-hack
$ make libnettle.a
Not sure what's the intention, but I want to put tkey-libs/include on my include path, so that tkey-specific headers would be used as #include <tkey/foo.h> in application code.
I got this to work, with only a few header files added in the above include-hack directory. Details:
-
assert.h: Just include tkey/assert.h. I think this file should be moved one level up, from include/tkey/.
-
stdio.h: Dummy definition of FILE, stderr and fprintf:
typedef struct {} FILE;
#define stderr NULL
static inline int fprintf(FILE *f, const char *format, ...) { (void) f; (void) format; return -1; }
Not sure what would actually make sense for tkey-libs, but a fprintf function always returning -1 might be reasonable?
- stdlib.h: Include tkey/lib.h (for stddef.h and stdint.h, provided by clang). Dummy definitions of realloc (always return NULL), free (do nothing) and abort.
The abort function is an interesting case. Ideally, it should terminate application, with some way for firmware to tell the host that the app aborted. If that's not doable, maybe abort() should be an infinite loop, so it at least doesn't return.
- string.h: Include tkey/lib.h, for memset/memcpy. Define strcmp and memcmp.
In my hack string.h, I did strcmp and memcmp as static inline functions. I think it would make sense to add proper definitions of strcmp and memcmp to tkey-libs.
And that's all, with just those tweaks, it compiles successfully. Compiling the public-key things in nettle (the code which goes into libhogweed.a) will be more challenging, even with --enable-minigmp, since the bignum operations unfortunately depend on working malloc/realloc/free.