# How can I provide my own \`compiler\_builtins\` implementation while using \`-Zbuild-std\`?

**URL:** <https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423>\
**Category:** compiler\
**Created:** [April 4, 2022, 8:53pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423 "2022-04-04T20:53:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acciente717](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/acciente717/32/8431_2.png) [@Acciente717](https://internals.rust-lang.org/u/Acciente717)\
**Post date:** [April 4, 2022, 8:53pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/1 "2022-04-04T20:53:54Z")

</div>

I am compiling my code with `-Zbuild-std=core,alloc`.

`cargo` automatically pulls `compiler_builtins v0.1.70`. I would like to replace `compiler_builtins` with my customized version, but I couldn't find a way to do that.

Is it possible to provide my own `compiler_builtins` implementation?

More background: I am compiling Rust code with segmented stack on ARM MCUs. Some `__aeabi_*` functions defined in `compiler_builtins` are written in inline assembly. I must patch these functions so that they respect segmented stack.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [April 5, 2022, 4:41am UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/2 "2022-04-05T04:41:47Z")

</div>

AFAIK `-Zbuild-std` currently doesn't support overriding any sources. You could try xargo instead.

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [April 9, 2022, 2:48pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/3 "2022-04-09T14:48:53Z")

</div>

However, note that xargo is basically unmaintained. I keep it just barely working for what Miri needs, but don't have time for anything beyond that.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [April 9, 2022, 9:38pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/4 "2022-04-09T21:38:41Z")

</div>

(I'm curious: what would Miri need from -Zbuild-std like functionality that isn't currently there to move off of xargo?)

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [April 9, 2022, 11:35pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/5 "2022-04-09T23:35:12Z")

</div>

(We need to build a _sysroot_, not just a library suited for a single workspace. The biggest technical hurdle I am aware of is that a sysroot contains _both_ `panic_abort` and `panic_unwind`, to support crates that use either panic strategy. This currently requires passing very specific flags when building these 2 crates, which is only possible via a `RUSTC` wrapper that [adjusts the flags](https://github.com/rust-lang/miri/blob/a4a667b3ce1d2dbdcbbf45b2854a42aa8af88b24/cargo-miri/bin.rs#L839-L844) between cargo and rustc.)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [July 8, 2022, 11:36pm UTC](https://internals.rust-lang.org/t/how-can-i-provide-my-own-compiler-builtins-implementation-while-using-zbuild-std/16423/6 "2022-07-08T23:36:14Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
