Dynamic calling conventions also won't work with dynamic linking
Re:The Rust Calling Convention We Deserve
by kevincox on Saturday April 20, 2024 @04:42PM
(#40100853)
Even when dynamic linking a lot of calls will be internal to each library. So you can either:
1. Use a stable calling convention for external interfaces.
2. Use a stable calling convention for everything, but generate trampolines for external calls.
Swift is actually pretty cool here. It basically does 2. But you can also specify which dependencies are "pinned" so that even if they are dynamically linked they can't be updated without a recompile. Then you can use the unstable calling convention when calling those dependencies.
It would be interesting to see calling convention optimizations based on function body. I think that would be safe for static functions in C, as long as their address is not taken.