I need to use _ExtInt on the BPF target. Simply switching it on seems to work fine.
I'm a not sure if anything else is needed. Please let me know if there is anything I can improve.
seanyoung on Dec 11 2020, 3:57 AM.Authored by
Add tests cases for _ExtInt on BPF. This makes the _ExtInt testing equivalent to the testing on every platform except x86-64.
The use-case is to use _ExtInt on BPF when targeting Solana BPF smart contracts. I am writing a solidity to BPF compiler which includes a standard library written in C. Solidity has types of 256 bits.
We could enable ExtIntType in bpf backend. But we need some kernel changes related to BTF to accommodate the new types.
#define BTF_INT_BITS(VAL) ((VAL) & 0x000000ff)
which means the maximum permitted number of bits for int type is 255.
Here, we try to define an int type 256 which will not fit in the BTF. Currently llvm can encode 256 in BTF as the last 4 bytes are available and llvm did not do strict checking.
#define BTF_INT_BITS(VAL) ((VAL) & 0x0000ffff)
But I do not think we need that big range, maybe
#define BTF_INT_BITS(VAL) ((VAL) & 0x000003ff)
which encode up to 512 bit integer (for power-of-2)? Do you have an use case for even bigger number of int?
Anyway, in parallel to this llvm patch, you need to have kernel change to accept such ext int's, the following are main changes in kernel: