3 ms·
C allows for any function to be called via a function pointer, and functions can be in different translation units, so the compiler can't simply assume that a f
by messe 3y ago
C allows for any function to be called via a function pointer, and functions can be in different translation units, so the compiler can't simply assume that a function will never be called indirectly and has to pessimistically insert endbr64 in order to maintain a reasonable ABI.
And no, as I understand it, this is only for branch/calls not returns.
- Joker_vD 3y agoWell, if the function is marked "static", the compiler can actually check whether the function's address is taken in the current compilation unit or not and omit/emit ENDBR64 accordingly (passing pointers to static functions to code in another compilation units is legal, and should still work).
- messe 3y agoGood catch. Yeah, as long as the functions address is never taken the compiler has a lot of leeway with static functions; it can even avoid emitting code for them entirely if it can prove they're never called or if it's able to compute their results at compile-time.
- josephg 3y agoYep. Or inline them at every call site if that makes sense to do based on the optimization level and flags.
- MobiusHorizons 3y agoIs this theoretically something lto could remove?
- tedunangst 3y agoIf you disable dlopen and ld_preload.
- codedokode 3y agoDlopen() "sees" only functions marked as exported (with macro like DLLEXPORT on Windows), not every function or am I wrong? Is C that bad?
- tedunangst 3y agoOn openbsd at least, every global symbol is exported unless you use an explicit symbol list. It's unusual for executables.