Is this possible? When I export my own implementation I receive no linker errors, but the implementation from compiler_rt is always in the final binary.
Edit - A few observations:
Debug build uses overridden implementation
Release builds use compiler_rt implementation
LTO=false builds always use overridden implementation
It is possible to change compiler-rt. Its source is distributed in the folder lib/compiler-rt of all zig downloads and you can change it. Your next build will detect the change in sources and rebuild compiler-rt library.
For certain targets, libraries like microzig may make use of specialized hardware to significantly improve the speedup of some primitives that are emulated in compiler-rt by default.
For example, the RP2040 provides single-cycle I/O access to a divider circuit that completes in 8 clock cycles. However, compiler-rt has no knowledge of specific SOC and specialized hardware. So whenever an integer division is required the compiler injects calls to the generic, slow compiler-rt version.
Pass -fno-compiler-rt to the compiler to make sure Zig’s implementation is not included. Equivalently, set .bundle_compiler_rt = false on a std.Build.Step.Compile.
That flag works as expected. Ideally I shouldn’t have to re-implement the entire compiler-rt just to override a few functions. My understanding is that weak linkage of compiler-rt should allow me to override specific symbols.
Huh, you’re right, my bad – I didn’t know we exported crt symbols with weak linkage. Indeed, if the override fails, it might be an LTO bug or something. If you have a repro, feel free to open a bug on the Zig issue tracker, and we can create an upstream issue if necessary.