linker - In which cases is the C compiler allowed to ignore the calling conventions? -


for obvious reasons, c compiler has compile functions externally visible other shared libraries conform platform's calling conventions , other abi requirements. however, i've learned doesn't need functions can guaranteed never called external modules.

how , when can compiler determine whether holds true given function?

  • a static function visible other functions in same compilation unit, , therefore candidate such abi-breaking optimizations. function pointers static function still passed other modules. compiler try determine if function pointers passed anywhere in code?

  • the gcc compiler has some extensions allow symbols declared default, hidden or internal, , documentation mentions information can used perform kinds of optimizations not possible externally visible funcitons. happen if function pointer passed external code function annotated being internal?

what best way compiler perform optimizations possible, while still guaranteeing interoperability other libraries? should use compiler option define functions internal, , override attribute functions need externally visible?

the c standard requires in cases, 2 pointers same function compare equal.

the compiler can perform abi-breaking tricks if declare symbol external and pointer never passed external code.

does compiler try determine if function pointers passed anywhere in code?

yes, does, if wants perform optimization. compiler can trivially know functions have function pointer decay performed upon them, it's not big deal know if you've taken address of function. conservatively, compiler can assume function pointers passed external code, or might try more advanced.

what happen if function pointer passed external code function annotated being internal?

nothing of interest- must work.

internal/external visibility that- visibility. compiler can turn licence break abi in relatively few cases.

should use compiler option define functions internal, , override attribute functions need externally visible?

unless library composed of single translation unit, expect virtually functions need externally visible. there no meaningful difference in c between "external within library" , "external all". however, in theory, try this. doubt, however, you'd achieve speedup , lot of effort non-trivial codebase.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -