Skip to content
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

Re-introduce riscv64 support. #7

Merged
merged 35 commits into from Oct 7, 2021
Merged

Re-introduce riscv64 support. #7

merged 35 commits into from Oct 7, 2021

Conversation

sunfishcode
Copy link
Owner

No description provided.

@sunfishcode sunfishcode force-pushed the sunfishcode/riscv64 branch 2 times, most recently from c2f1b2b to 448c6fb Compare September 10, 2021 22:30
@sunfishcode
Copy link
Owner Author

The failure appears due to riscv64 using function-sections by default, which means that c-scape's trick for replacing libc functions doesn't work.

sunfishcode added a commit that referenced this pull request Sep 13, 2021
Redesign how mustang ensures its libraries are linked in, to be somewhat
more robust in the face of various kinds of optimizations. Use explicit symbols
to pull in individual modules. This also makes it easier to split more c-scape
functionality into separate modules.

 - Instead of having users declare `extern crate mustang`, have them invoke
   a macro, `mustang::can_compile_this!();`.

 - Don't declare c-scape functions as `pub`. Most code should use the
   `libc` crate declarations; `c-scape` uses `extern "C"` to intercept
   those at link time.

 - Put `extern "C"` functions in a named section; this overrides
   -ffunction-sections and puts all the functions in the same section,
   so that the linker doesn't DCE individual functions before they have a
   chance to intercept libc calls.

 - Similarly, add `#[inline(never)]` so that these functions aren't inlined,
   which can result in symbols being removed if an optimizer believes it
   has seen all of their uses.

This helps with #7, though is not the only thing needed.
@sunfishcode sunfishcode mentioned this pull request Sep 13, 2021
sunfishcode added a commit that referenced this pull request Sep 14, 2021
Redesign how mustang ensures its libraries are linked in, to be somewhat
more robust in the face of various kinds of optimizations. Use explicit symbols
to pull in individual modules. This also makes it easier to split more c-scape
functionality into separate modules.

 - Instead of having users declare `extern crate mustang`, have them invoke
   a macro, `mustang::can_compile_this!();`.

 - Don't declare c-scape functions as `pub`. Most code should use the
   `libc` crate declarations; `c-scape` uses `extern "C"` to intercept
   those at link time.

 - Put `extern "C"` functions in a named section; this overrides
   -ffunction-sections and puts all the functions in the same section,
   so that the linker doesn't DCE individual functions before they have a
   chance to intercept libc calls.

 - Similarly, add `#[inline(never)]` so that these functions aren't inlined,
   which can result in symbols being removed if an optimizer believes it
   has seen all of their uses.

This helps with #7, though is not the only thing needed.
@sunfishcode sunfishcode mentioned this pull request Sep 15, 2021
Factoring these out into separate files appears to be insufficient to
force them to all be linked in, replacing libc, so pull them all into
a single module.
The `unwind` crate appears to work well for this purpose, even on panics with
RUST_BACKTRACE=full.

This uses the `fde-phdr-dl` backend, which uses `dl_iterate_phdr`, so implement
`dl_iterate_phdr`.

Fixes #27.
Unwind doesn't support 32-bit x86 yet, so drop it for now.
It's used by `init_have_lse_atomics` in libgcc/compiler-rt.
This has a better chance of allowing a user to open the file reliably.
@sunfishcode sunfishcode force-pushed the sunfishcode/riscv64 branch 5 times, most recently from 4a01b82 to 80968f5 Compare October 6, 2021 01:23
On RISC-V, the thread pointer is offset by 0x800 from the base of the
TLS data, so introduce a `TLS_OFFSET` constant to make this adjustment.
32-bit ARM is not yet supported by `unwinding`, but everything else works.

Fixes #17.
Temporarily disable unwinding until the changes in gimli needed to
support unwinding on aarch64 and riscv64 are available in a release. This
allows us to avoid the `[patch.crates-io]` lines in Cargo.toml.
@sunfishcode sunfishcode merged commit b9abe21 into main Oct 7, 2021
@sunfishcode sunfishcode deleted the sunfishcode/riscv64 branch October 7, 2021 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant