# A Stable Modular ABI for Rust

**URL:** <https://internals.rust-lang.org/t/a-stable-modular-abi-for-rust/12347>\
**Category:** compiler\
**Created:** [May 14, 2020, 6:14pm UTC](https://internals.rust-lang.org/t/a-stable-modular-abi-for-rust/12347 "2020-05-14T18:14:49Z")\
**Posts on this page:** 1\
**Showing post:** 69

<div class="post-metadata">

**Author:** ![ckaran](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@ckaran](https://internals.rust-lang.org/u/ckaran)\
**Post date:** [June 7, 2020, 4:10pm UTC](https://internals.rust-lang.org/t/a-stable-modular-abi-for-rust/12347/69 "2020-06-07T16:10:42Z")

</div>

> [@robinm](#):
>
> Note: if for some reason, a library libA must have some of its public function consumed using the ABI B, and the rest using the ABI C, it is always possible to split it in 3: libA\_core would contains all the functionalities, but shouldn't be consumed directly, libB would be a thin wrapper over the part of libA\_core that would be consumed with the calling convention B (and depends on libA\_core), while libC would be a thin wrapper over the part of libA\_core that would be consumed with the calling convention C (and likewise would depends on libA\_core).

Two (possibly dumb) questions:

- How do you write glue code? It looks like libA\_core is unable to call to libB or libC, so if libB tries to pass through to libC, it can't be done.
- Would this prevent the compiler from doing things intelligently? Under the earlier suggestions, the code (including the representation annotations) are available to the compiler from the start (they are likely to be in the same crate, if not in the same module), whereas this proposal sounds like the compiler will only be able to do linkage-level optimization tricks. If the compiler has full information and access right from the start (with the source code), it may be able to choose a layout in memory that is in the intersection of both ABIs1, making the translation a zero-cost abstraction.

1The example I'm thinking about involves byte alignment of certain types. Some ABIs require alignment along some byte boundary, whereas others will permit misalignment. If the compiler is aware that some pair of objects are going to be interrelated in some manner, it may choose to align everything along the byte boundary that both ABIs find acceptable.

---

_[View the full topic](https://internals.rust-lang.org/t/a-stable-modular-abi-for-rust/12347)._
