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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 21 02:18:30 PDT 2024


philnik777 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.

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


More information about the libcxx-commits mailing list