public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: yuucyf <yuucyf@163.com>, libc-help@sourceware.org
Subject: Re: A question regarding the optimization of string functions in glibc.
Date: Tue, 10 Oct 2023 11:49:05 -0300	[thread overview]
Message-ID: <91cf42cc-e0c1-4d70-8b33-de838d40b357@linaro.org> (raw)
In-Reply-To: <35e2d94d.e6e.18b0cf26dce.Coremail.yuucyf@163.com>



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

      reply	other threads:[~2023-10-10 14:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-08  1:41 yuucyf
2023-10-10 14:49 ` Adhemerval Zanella Netto [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=91cf42cc-e0c1-4d70-8b33-de838d40b357@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-help@sourceware.org \
    --cc=yuucyf@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).