Skip to content
Snippets Groups Projects
Commit cdf2915c authored by Matt Turner's avatar Matt Turner Committed by Kamil Konieczny
Browse files

lib: Inline igt_x86_features() into ifunc resolvers

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. Since this function is only called
       from a few places it does not significantly increase binary size
       to inline it.

Linux distros (at least Fedora since v23, Gentoo/Hardened, soon standard
Gentoo) use `-Wl,-z now` to improve security. By binding upfront, the
loader can mark the GOT as read-only for a security enhancement. See
https://wiki.gentoo.org/wiki/Hardened/Toolchain for more details.

[Fixed whitespaces (Kamil)]
Bug: https://bugs.gentoo.org/788625
Bug: https://bugs.gentoo.org/925348


Reviewed-by: default avatarZbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: default avatarMatt Turner <mattst88@gmail.com>
parent 2d695183
No related branches found
No related tags found
Loading
Checking pipeline status
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment