This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Multiple symbols at the same location



On 25/08/2018 18:51, Derrick McKee wrote:
> Hi,
> 
> I am a PhD. student, and in my research I noticed that there are
> several versions of memmove and memcpy that are included in statically
> compiled binaries.  I understand that this is done for optimization
> purposes (and if that is not the case, let me know!).  However, some
> versions of memmove and memcpy are located in different places in
> .text, while others have their symbols located at the same location in
> .text.  For example, __memcpy_avx512_unaligned and
> __memmove_avx512_unaligned have the same address, however
> __memcpy_ssse3 and __memmove_ssse3 are placed at different addresses.
> I assume that this is also done for optimization purposes.
> 
> Can someone give me an explanation as to why it makes sense to
> separate one group of memory copying functions into two symbols, while
> for others the same code is used?  Thanks!

These are ifunc [1] variants selected at runtime depending of the some
criteria.  For x86_64, it builds an intern data structure with current
CPU features obtained from cpuid (sysdeps/x86/cpu-features.c) and then
each selection can use these flags to select the best suitable variation.
(check sysdeps/x86_64/multiarch/memcpy.c for instance).

Now, it is possible to implement memcpy with memmove, although it might
not be as optimized as possible. It is what memmove/memcpy for AVX512
does:

* sysdeps/x86_64/multiarch/memmove-avx512-unaligned-erms.S

 11 # include "memmove-vec-unaligned-erms.S"

* sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S

564 strong_alias (MEMMOVE_SYMBOL (__memmove, unaligned),                                     
565               MEMCPY_SYMBOL (__memcpy, unaligned))

[1] https://sourceware.org/glibc/wiki/GNU_IFUNC


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]