@@ -1598,16 +1598,19 @@ Function Multi-versioning
15981598Function Multi-versioning (FMV) is an Arm C Language Extension that
15991599lets the compiler generate multiple function versions and auto-dispatch
16001600between 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
16031603available on the host. FMV is supported on GNU/Linux, Android, and
16041604many of the BSD operating systems.
16051605
16061606On System V platforms Function Multi-versioning is implemented using
16071607GNU 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:
17161719A special value ``FEAT_INIT = (1U << 63); `` is used to signify
17171720initialization 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+
17191726Initialization 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
17251739The ``__init_cpu_features_resolver `` function has the following
17261740prototype:
0 commit comments