Skip to content

Commit cf6ab3d

Browse files
committed
Changes from last revision:
* make it explicit that runtime library support is not a requirement * accessing __aarch64_cpu_features outside FMV resolver is not well defined * allow __init_cpu_features_resolver to be called from constructors * encourage placing __aarch64_cpu_features in RELRO when IFUNC is supported
1 parent 7230f46 commit cf6ab3d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

sysvabi64/sysvabi64.rst

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,16 +1598,19 @@ Function Multi-versioning
15981598
Function Multi-versioning (FMV) is an Arm C Language Extension that
15991599
lets the compiler generate multiple function versions and auto-dispatch
16001600
between them. Each of the function versions is specialized for a set
1601-
of architecture extensions. The most suitable version is selected at
1602-
load time. This requires runtime information about the CPU features
1601+
of architecture extensions. The most suitable version is selected
1602+
dynamically. This requires runtime information about the CPU features
16031603
available on the host. FMV is supported on GNU/Linux, Android, and
16041604
many of the BSD operating systems.
16051605

16061606
On System V platforms Function Multi-versioning is implemented using
16071607
GNU Indirect Functions (IFUNC). The compiler generated IFUNC resolver
1608-
uses a global variable ``__aarch64_cpu_features`` that contains a
1609-
description of the detected CPU features to select the best function
1610-
version:
1608+
may rely on a runtime library for selecting the most suitable function
1609+
version, but it is not a requirement.
1610+
1611+
If a runtime library is used, it must ensure that a global variable
1612+
``__aarch64_cpu_features`` containing a description of the detected
1613+
CPU features is populated before the application code reaches main.
16111614

16121615
.. code-block:: c
16131616
@@ -1716,11 +1719,22 @@ The variable may contain the following fields:
17161719
A special value ``FEAT_INIT = (1U << 63);`` is used to signify
17171720
initialization completion.
17181721

1722+
Implementing FMV using ``__aarch64_cpu_features`` is not required.
1723+
Accessing ``__aarch64_cpu_features`` from outside a FMV resolver
1724+
function is not well defined.
1725+
17191726
Initialization of the ``__aarch64_cpu_features`` is performed by
1720-
the runtime. Each FMV resolver function will call the
1721-
``__init_cpu_features_resolver`` function that must be provided
1722-
by the runtime environment. This runtime function must ensure
1723-
that ``__aarch64_cpu_features`` is populated.
1727+
the runtime library. Each FMV resolver function will call the
1728+
``__init_cpu_features_resolver`` function at load time. This runtime
1729+
function must ensure that ``__aarch64_cpu_features`` is populated.
1730+
1731+
Systems without support for IFUNC may call the
1732+
``__init_cpu_features_resolver`` function from an
1733+
``__attribute__((constructor))`` function provided by the runtime.
1734+
1735+
Systems with support for IFUNC should place the global variable
1736+
``__aarch64_cpu_features`` in Relocation Read Only (RELRO) segment
1737+
to prevent it from being modified after the FMV resolvers have run.
17241738

17251739
The ``__init_cpu_features_resolver`` function has the following
17261740
prototype:

0 commit comments

Comments
 (0)