[PATCH i-g-t] lib: Inline igt_x86_features() into ifunc resolvers

Matt Turner mattst88 at gmail.com
Thu Mar 21 03:09:11 UTC 2024


On Wed, Mar 13, 2024 at 5:09 AM Zbigniew Kempczyński
<zbigniew.kempczynski at intel.com> wrote:
>
> On Mon, Mar 04, 2024 at 05:16:40PM -0500, Matt Turner wrote:
> > Quoting https://sourceware.org/glibc/wiki/GNU_IFUNC
> >
> > > When LD_BIND_NOW=1 or -Wl,z,now is in effect symbols must be
> > > immediately resolved at startup. In cases where an external function
> > > call depends needs to be made that may fail if such a call has not
> > > been initialized yet (PLT-based relocation which is processed later).
> > > For example calling strlen in an IFUNC resolver built with -Wl,z,now
> > > may lead to a segfault because the PLT is not yet resolved.
> >
> > We cannot rely on function calls through the PLT in ifunc resolvers as
> > the PLT may not have been initialized yet.
> >
> > In practice, this causes crashes when igt is linked with -Wl,-z,now or
> > when linked with the mold linker.
> >
> > To avoid this problem, we do two things:
> >     1. move igt_x86_features() to igt_x86.h so its definition is
> >        available to compilation units that call the function.
> >     2. mark the ifunc resolvers with __attribute__((flatten)) to ensure
> >        igt_x86_features() is inlined.
> >
> > Bug: https://bugs.gentoo.org/788625
> > Bug: https://bugs.gentoo.org/925348
> > Signed-off-by: Matt Turner <mattst88 at gmail.com>
>
> Hi.
>
> I started review of your code, but this this touches some linking intrisics
> I'm not familiar with yet so I need more time to explore this. I hope
> this is not a problem for you.

Do you have any questions I can answer? I tried my best to explain the
how and the why of the change in the commit message.


More information about the igt-dev mailing list