[libcxx-commits] [libcxx] [libcxx] Option to disable overridden function detection (PR #108734)

Petr Hosek via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 29 08:03:51 PDT 2024


petrhosek wrote:

> > > More general thought: Could we implement this mechanism through aliases instead: https://godbolt.org/z/E5oKj9hfe? I think that might make `__is_function_overriden` a bit more lean and avoid having to put the functions into a separate section. That probably also doesn't work everywhere, but that doesn't seem like a huge problem to me.
> > 
> > 
> > I looked into it and try to implement this approach in libc++, but then realized that this approach has a serious downside in that both the original function and the one that overrides it would be kept in the binary even though the original is only used for the address comparison. This may not be a big deal on other systems but it's a concern for baremetal uses where every byte matters and don't want to ship any dead code.
> > With the existing implementation, that is also the case, but if you use a custom linker script you can manually discard it although that would effectively disable `__is_function_overriden` same as this change does but is more involved. Using that approach would likely result in embedded developers cargo culting the same snippet into every linker script which I think is undesirable.
> > Therefore, I'd would like to merge this change as is. I can try to finish and upload the implementation based on aliases for ELF as a follow up PR, but for baremetal we always want to disable this regardless of the implementation.
> 
> How would that result in dead code being shipped? If you properly override all the overloads the compiler can discard the libc++ versions and if you don't provide any yourself the checks can be constant-folded assuming you're using LTO.

LTO isn't generally usable on baremetal because it's incompatible with certain linker scripts constructs; this is something the community has been trying to [address for some time](https://llvm.org/devmtg/2022-11/slides/QuickTalk11-Link-TimeAttributesforLTO.pdf) but there still isn't a working solution.

https://github.com/llvm/llvm-project/pull/108734


More information about the libcxx-commits mailing list