We are currently working on porting legacy code for embedded systems from x86_64 windows systems to the riscv64 architecture.
However, we are faced with the problem that the data type ‘long’ is no longer 32 bit wide.
A few decades ago, we assumed that the ‘long’ data type always remains 32 bit wide and we would like to keep it that way. This choice is known as data model LLP64 [1].
Is there an easy possibility to change the used data model from LP64 to LLP64 when using the clang target triple riscv64-unknown-?
We are OS-independent, because we have our own implementation of the standard libraries.
Our considerations included:
asking ourselves whether there is a hidden switch to select the data model. But we didn’t find any.
creating a new target triple, which uses the LLP64 data model when compiling for riscv64.
Seems like your best bet would be to search and replace “long” with some typedef across your whole codebase. If your code is independent of windows APIs you can just use int32_t everywhere, but if you need to interoperate with windows apis in some build mode, you might want to use a different typedef that expands to “long” on windows and int32_t otherwise.
The stdint.h typedefs may have any of them as their underlying type, so long as it’s the correct width. Although in practice I believe every common platform where sizeof(int) == 4 has made int32_t a typedef for int. For int64_t, there’s no such consistency, however. Some LP64 platforms (e.g. with sizeof(long) == sizeof(long long) == 8) have made int64_t a typedef for long long, while others have made it a typedef for long.