Bug 19766 - All machines should pass dl_hwcap to ifunc resolvers.
Summary: All machines should pass dl_hwcap to ifunc resolvers.
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-04 16:00 UTC by Carlos O'Donell
Modified: 2016-09-05 15:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2016-03-04 16:00:47 UTC
Presently AArch64, ARM, s390x, s390, ppc32, ppc64, sparc32, and sparc64 all support passing dl_hwcap to the resolver function. This allows the resolver to do something interesting based on the hardware capabilities.

On i386, and x86_64 we do not pass dl_hwcap to the resolver functions and therefore have no save way to access this information.

We should immediately bring i386 and x86_64 up to parity with the other architectures and once this is done we should follow up by adding a symbol dependency to all ifunc attribute functions compiled by gcc, such that new binaries that need this feature are assured they run under an environment that provides the dl_hwcap and not just garbage in the incoming argument register.

Without this feature i386 and x86_64 ifunc's don't have much use.
Comment 1 Jakub Jelinek 2016-03-04 16:47:41 UTC
Why?  On i386/x86_64 it can (and usually does) just use the cpuid instruction to query the same information.
Comment 2 Carlos O'Donell 2016-03-04 17:16:22 UTC
(In reply to Jakub Jelinek from comment #1)
> Why?  On i386/x86_64 it can (and usually does) just use the cpuid
> instruction to query the same information.

It's faster than cpuid and doesn't serialize the instruction stream. If you really need cpuid then you're free to call it and process the information yourself, but AT_HWCAP (merged with AT_HWCAP2 on 64-bit platforms) contains useful information the ifunc resolver might need.
Comment 3 Carlos O'Donell 2016-03-04 18:17:33 UTC
(In reply to Carlos O'Donell from comment #2)
> (In reply to Jakub Jelinek from comment #1)
> > Why?  On i386/x86_64 it can (and usually does) just use the cpuid
> > instruction to query the same information.
> 
> It's faster than cpuid and doesn't serialize the instruction stream. If you
> really need cpuid then you're free to call it and process the information
> yourself, but AT_HWCAP (merged with AT_HWCAP2 on 64-bit platforms) contains
> useful information the ifunc resolver might need.

So one problem is that AT_HWCAP can't tell you about XSAVE/OSXSAVE which is required to enable AVX512 variants. So you're probably right that most people for modern hardware detection will have to rely on cpuid. Which is problematic. 

I wonder if we can just document the safe functions to use in the IFUNC and that would be enough, for example __builtin_cpu_init, __buildin_cpu_is, and __builtin_cpu_supports should be safe because gcc already uses them in multiversioning on x86?
Comment 4 Carlos O'Donell 2016-03-04 18:18:35 UTC
Either way, from a documentation perspective it's easier when the arches are the same, so adding dl_hwcap to the calling convention, and then documenting safe functions, should make this easier.