-
Notifications
You must be signed in to change notification settings - Fork 628
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
Add Cosmopolitan Libc Platform #2598
Conversation
* Multi-OS x86_64 builds with the same binary. * Only interp modes supported. The only major change is posix.c/convert_errno() was rewritten to use a switch statement to accommodate errno values being non-const in the Cosmopolitan Libc (cosmocc allows switch statements with non-const case labels). Squashed commit of the following: commit 25222dc Author: Gavin Hayes <gavin@dylibso.com> Date: Fri Sep 22 13:05:11 2023 -0400 chore: add copyright headers commit f5cd374 Author: Gavin Hayes <gavin@dylibso.com> Date: Fri Sep 22 12:19:16 2023 -0400 chore: undo unintentional formatting, add cosmo test comment commit 248fe0a Author: Gavin Hayes <gavin@dylibso.com> Date: Wed Sep 20 13:43:40 2023 -0400 feat add testing with cosmopolitan, set CC=cosmocc and pass -j commit 6f5e471 Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Sep 14 16:47:28 2023 -0400 docs: add cosmo info to product mini README commit af95d87 Author: Gavin Hayes <gavin@dylibso.com> Date: Wed Sep 13 17:21:51 2023 -0400 fix: renable ipv6 multicast on supporting platforms, apply k&r commit eeac278 Author: Gavin Hayes <gavin@dylibso.com> Date: Wed Sep 13 16:53:12 2023 -0400 feat: add cosmopolitan platform commit a3de045 Author: Gavin Hayes <gavin@dylibso.com> Date: Wed Sep 13 14:34:14 2023 -0400 fix: renable convert_errno and make it cosmopolitan libc compatible commit 37113d0 Author: Gavin Hayes <gavin@dylibso.com> Date: Wed Sep 13 13:43:51 2023 -0400 renable CONFIG_HAS_POSIX_FALLOCATE and CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK on platforms that have it commit e8181bf Author: Gavin Hayes <gavin@dylibso.com> Date: Tue Sep 12 18:12:17 2023 -0400 remove some unneeded modifications for cosmo build commit f103efd Author: Gavin Hayes <gavin@dylibso.com> Date: Tue Sep 12 12:05:32 2023 -0400 chore: remove hermit commit 9453ed7 Author: Gavin Hayes <gavin@dylibso.com> Date: Tue Sep 12 11:27:46 2023 -0400 fix: wamr building with cosmo a359de7893c33bfbd99aa82d570f97c55bf2b935 commit b2ba69a Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 20:38:28 2023 -0400 fix: remove _start entrypoint to pass args commit a2d60e7 Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 18:25:55 2023 -0400 feat: add specifying ENTRYPOINT in hermit.json commit ab86abd Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 17:56:37 2023 -0400 chore: const json types commit 4ea65ac Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 17:48:00 2023 -0400 feat: add json parsing to hermit loader commit 9d1088d Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 16:46:51 2023 -0400 chore: rename hermit build script commit 4c3e01c Author: Gavin Hayes <gavin@dylibso.com> Date: Thu Jul 13 16:41:22 2023 -0400 feat: APW PoC
does this mean to build wamr this way: https://justine.lol/ape.html ? |
Yes, exactly! This allows building Actually Portable Executables that run on multiple x86_64 systems with the same binary. |
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds the Cosmopolitan Libc platform enabling compatibility with multiple x86_64 operating systems with the same binary. The platform is similar to the Linux platform, but for now only x86_64 with interpreter modes are supported. The only major change to the core is `posix.c/convert_errno()` was rewritten to use a switch statement. With Cosmopolitan errno values depend on the currently running operating system, and so they are non-constant and cannot be used in array designators. However, the `cosmocc` compiler allows non-constant case labels in switch statements, enabling the new version. And updated wamr-test-suites script to add `-j <platform>` option. The spec tests can be ran via `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t classic-interp` or `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t fast-interp`.
This patch adds the Cosmopolitan Libc platform enabling compatibility with multiple x86_64 operating systems with the same binary. The platform is similar to the Linux platform, but for now only x86_64 with interp modes are supported.
The only major change to the core is
posix.c/convert_errno()
was rewritten to use a switch statement. With Cosmopolitan errno values depend on the currently running operating system, and so they are non-constant and cannot be used in array designators. However, thecosmocc
compiler allows non-constant case labels in switch statements, enabling the new version.The spec tests can be ran via
CC=cosmocc ./test_wamr.sh -j cosmopolitan -t classic-interp
orCC=cosmocc ./test_wamr.sh -j cosmopolitan -t fast-interp
. However, they fail in the same way they do on the Linux platform on my machine. Tests with float64 NaN fail without this patch I am in the process of upstreaming into Cosmopolitan: jart/cosmopolitan#901 .tests/wamr-test-suites/test_wamr.sh
lines 669-671 (https://github.com/dylibso/wasm-micro-runtime/blob/339facc7bf80e4a68d81eb56d4ec358c6c257176/tests/wamr-test-suites/test_wamr.sh#L669-L671) contain a hack to enable the test suite to run even though the the platform is incorrectly detected as Linux by other scripts (Linux is the only platform supported to build Cosmopolitan). If this isn't acceptable, I am happy to remove it, but would appreciate some guidance on the best way to propagate the platform to the child scripts, it looks messy how it's handled for linux sgx.Edit: Updated test instructions after updating
-j
to specify platform in a3449ac.