intel - strcmp and strcmp_sse functions in libc -


i've seen in libc.so actual type of strcmp_sse call decided function strcmp itself.

here code:

      strcmp:  .text:000000000007b9f0                 cmp     cs:__cpu_features.kind, 0  .text:000000000007b9f7                 jnz     short loc_7b9fe  .text:000000000007b9f9                 call    __init_cpu_features  .text:000000000007b9fe  .text:000000000007b9fe loc_7b9fe:                              ; code xref: .text:000000000007b9f7j  .text:000000000007b9fe                 lea     rax, __strcmp_sse2_unaligned  .text:000000000007ba05                 test    cs:__cpu_features.cpuid._eax, 10h  .text:000000000007ba0f                 jnz     short locret_7ba2b  .text:000000000007ba11                 lea     rax, __strcmp_ssse3  .text:000000000007ba18                 test    cs:__cpu_features.cpuid._ecx, 200h  .text:000000000007ba22                 jnz     short locret_7ba2b  .text:000000000007ba24                 lea     rax, __strcmp_sse2  .text:000000000007ba2b  .text:000000000007ba2b locret_7ba2b:                           ; code xref: .text:000000000007ba0fj  .text:000000000007ba2b                                         ; .text:000000000007ba22j  .text:000000000007ba2b                 retn 

what not understand address of strcmp_sse function call placed in rax , never called. therefore wondering: going call *rax? when?

linux dynamic linker supports special symbol type called stt_gnu_ifunc. strcmp implemented ifunc. 'regular' symbols in dynamic library nothing more mapping name address. ifuncs bit more complex that: address isn't readily available, in order obtain linker must execute piece of code library itself. seeing example of such peice of code here. note in x86_64 abi function returns result in rax.

this technique typically used pick optimal implementation based on cpu features. please note selection logic runs once; first call strcmp fast.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -