-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2: Define __ocaml_freestanding__, fix the endian.h mess #74
Conversation
This change allows for portable C code to determine if it is being built in an ocaml-freestanding environment by checking if the preprocessor macro __ocaml_freestanding__ is defined. In order to be able to do this reliably and in the presence of existing "#if...#elif...#endif" chains we need to undefine existing preprocessor macros identifying the host toolchain, including but not limited to, __FreeBSD__, __OpenBSD__ and __linux__. For a full list, see nolibc/include/_freestanding/overrides.h. _freestanding/overrides.h is now included automatically for each C source file built by adding "-include _freestanding/overrides.h" to both downstream pkg-config/dune CFLAGS and the Makefile-internal FREESTANDING_CFLAGS.
I have tested this manually on Debian 10 with GCC, including inspecting the Regarding your comments in #73:
Agreed. This V2 does that via
We may as well provide an
... I see no harm in that. The remaining question for me is that from your comments on #73 it's no longer obvious to me if we need the If you look at What do you think? |
This looks fine to me, I tested it on a FreeBSD 12.1 system.
I don't think we need it. The undefine of the host platform is sufficient to avoid issues in the common path, and there's no need to support "broken" EDIT: I pushed 8c06c0f to your branch that removes the After this is merged, I only have two more questions (out of scope for this PR I suspect, but since we're cleaning up headers, I though I'd raise them here):
|
This change provides a full <endian.h> in nolibc, defining BYTE_ORDER, LITTLE_ENDIAN, BIG_ENDIAN and the beXXtoh(), htobeXX(), htoleXX() and leXXtoh() interfaces as macros. [1] Further, <endian.h> is now arch-independent and uses the compiler built-in preprocessor macro __BYTE_ORDER__ to determine byte order. [2] This macro is available in all versions of GCC and clang that are recent enough for us to care about. [1] As proposed for / in the process of being included into / the newest POSIX standards: https://www.austingroupbugs.net/view.php?id=162 [2] https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
Provide a <sys/param.h> in nolibc, and define BYTE_ORDER, LITTLE_ENDIAN and BIG_ENDIAN in it (if not already defined via inclusion of endian.h or related elsewhere). This change is provided for the benefit of autoconf-based build systems such as the OCaml runtime and libgmp (gmp-freestanding). Autoconf-based build systems commonly use the AC_C_BIGENDIAN test, which looks for a definition of BYTE_ORDER in various UNIXy places [1], falling back to gradually more horrible heuristics if one is not found. While these heuristics work "by accident" until now, this solution is cleaner and ensures that a compile-only test is used by autoconf, which will work in the future presence of a cross compiler. [1] See lib/autoconf/c.m4 in the GNU autoconf source.
Thanks
Ok. I rebased the existing commits, removing the
No idea. I'm sure there was some reason for why it got done that way. It's ~300kB of headers and "stuff", if you're fine with just installing all of it, then let's do it.
Yeah, this doesn't work because the openlibm public headers want to include the private headers, and do so without using |
@mato great, let's defer that openlibm to a later point in time (don't fix issues that are not present). I looked into the history of the caml-header list, and it came with the initial commit. I feel more comfortable to install all of them (they are in EDIT:
that sounds good to me as well, I didn't want to force-push to your branch. |
All green, good to merge! |
This is a re-work of #73, containing the following changes:
83fc2b43226548)3c251fe5055052)__ocaml_freestanding__
, add overrides.h (239263b)See individual commits for details.
/cc mirage/hacl#30 mirage/mirage-crypto#54 Solo5/solo5#453 @hannesm