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

Revamp linking. #12

Merged
merged 2 commits into from Sep 14, 2021
Merged

Revamp linking. #12

merged 2 commits into from Sep 14, 2021

Conversation

sunfishcode
Copy link
Owner

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.

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.
unsafe impl Sync for SendSyncVoidStar {}

/// An ABI-conforming `__dso_handle`.
#[cfg(target_vendor = "mustang")]
#[link_section = ".mustang.data"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use .text.mustang for functions and .data.mustang for statics?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good idea. We're currently using __mustang as our C-symbol namespace prefix, so I think this comes out as .text.__mustang.

@sunfishcode sunfishcode merged commit fa357be into main Sep 14, 2021
@sunfishcode sunfishcode deleted the sunfishcode/revamp-linking branch September 14, 2021 13:54
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

2 participants