public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* A question regarding the optimization of string functions in glibc.
@ 2023-10-08  1:41 yuucyf
  2023-10-10 14:49 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 2+ messages in thread
From: yuucyf @ 2023-10-08  1:41 UTC (permalink / raw)
  To: libc-help

[-- Attachment #1: Type: text/plain, Size: 1263 bytes --]

Dear all,

I have some questions to ask.
In the glibc source code, there are various string optimization functions for different PowerPC architectures in the sysdeps/powerpc/powerpc64/multiarch directory, such as xxx_power7, xxx_power8, xxx_power9, and so on. When building glibc, I've noticed that these source files generate .o files, and all of them are eventually merged into libc.a. My question is, if I use the strcpy function in my user code, which version of strcpy is actually linked? GCC supports specifying the CPU type using -mcpu, but how does the linker choose which version of strcpy to link? Can you please explain in detail the process of determining which function is linked?
I'm currently writing a test case on a Power8 platform that uses the strcpy string function. However, when I disassemble it after linking, I found that it's not using strcpy-power8.S. Since it's not using the optimized string function for the Power8 platform, I'm curious why there are assembly implementations of optimized string functions for multiple platforms like PowerPC, ARM, MIPS, and others. How does it determine which platform-specific optimized string function to use on a particular platform? Could someone kindly provide a detailed explanation? Thank you!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A question regarding the optimization of string functions in glibc.
  2023-10-08  1:41 A question regarding the optimization of string functions in glibc yuucyf
@ 2023-10-10 14:49 ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-10-10 14:49 UTC (permalink / raw)
  To: yuucyf, libc-help



On 07/10/23 22:41, yuucyf via Libc-help wrote:
> Dear all,
> 
> I have some questions to ask.
> In the glibc source code, there are various string optimization functions for different PowerPC architectures in the sysdeps/powerpc/powerpc64/multiarch directory, such as xxx_power7, xxx_power8, xxx_power9, and so on. When building glibc, I've noticed that these source files generate .o files, and all of them are eventually merged into libc.a. My question is, if I use the strcpy function in my user code, which version of strcpy is actually linked? GCC supports specifying the CPU type using -mcpu, but how does the linker choose which version of strcpy to link? Can you please explain in detail the process of determining which function is linked?
> I'm currently writing a test case on a Power8 platform that uses the strcpy string function. However, when I disassemble it after linking, I found that it's not using strcpy-power8.S. Since it's not using the optimized string function for the Power8 platform, I'm curious why there are assembly implementations of optimized string functions for multiple platforms like PowerPC, ARM, MIPS, and others. How does it determine which platform-specific optimized string function to use on a particular platform? Could someone kindly provide a detailed explanation? Thank you!

The powerpc64 multiarch uses the IFUNC GNU extension [1], and each port
might not provided the ifunc support for an specific symbol for static
linking.

The IFUNC is basically a way to select an implementation from a set at
runtime, based on a provided callback.  For powerpc the selection is
done through AT_HWCAP/AT_HWCAP2 fields from auxv (provided by the kernel).

For strcpy specifically, powerpc64 only provides the ifunc variant for
the shared library.  The libc.a will use the one provided by 
sysdeps/powerpc/powerpc64/multiarch/strcpy-ppc64.c which used the
generic string/strcpy.c.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-10 14:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-08  1:41 A question regarding the optimization of string functions in glibc yuucyf
2023-10-10 14:49 ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).