Skip to content

Arm feature detection on Apple platforms should use sysctlbyname #20188

Closed

Description

@davidben

As discussed in #14838, the SIGILL-based feature detection that OpenSSL uses on Arm is incorrect and causes problems. On Apple platforms, the API to use is sysctlbyname:
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics

OpenSSL broadly uses sysctlbyname, but still runs the probing mechanism on Apple platforms. It just happens to filter out the not-always-available features on this line:

# if defined(__aarch64__) && !defined(__APPLE__)

But then later PRs regressed this by not similarly guarding such features: #17916 and #15361. I ran into this because OpenSSL's regression here seems to interfere with debugging things on macOS with lldb, but the SIGILL mechanism is also not thread-safe.

But that limited __APPLE__ guard is also the wrong way to do this. Instead one should completely disable the SIGILL mechanism on platforms where a real API is available. Indeed, as it's not thread-safe, best not to have it at all and just use the correct APIs on all platforms, combined with the preprocessor defines from ACLE to handle always-available features since older Apple platforms didn't provide runtime detection for such features. (BoringSSL handles all its detection without SIGILL.)

Activity

  1. added
    issue: bug report
    on Feb 1, 2023
  2. added
    triaged: feature
    help wanted
    and removed
    issue: bug report
    on Feb 1, 2023
  3. paulidale commented on Feb 1, 2023

    @paulidale
    Contributor

    Is there any way to handle the big.LITTLE problems where features differ across cores and are wrongly attempted?

  4. davidben commented on Feb 1, 2023

    @davidben
    ContributorAuthor

    Yup, by removing the SIGILL probing as I've been suggesting. :-) BoringSSL does not have any SIGILL code and we've never run into any problems of that nature. The expectation is the OS APIs are supposed to smooth over differences across the cores.

  5. tom-cosgrove-arm commented on Feb 1, 2023

    @tom-cosgrove-arm
    Contributor

    I agree we shouldn't be doing the SIGILL probing on Apple Silicon. I've been working on a set of changes to tidy up armcap.c which include that. Note that in general operation these tests are benign as long as they pass, and as long as you're not in lldb (which has hit me too!).

  6. paulidale commented on Feb 1, 2023

    @paulidale
    Contributor

    Looking forward to the PR.

  7. added a commit that references this issue on Feb 16, 2023
    e86b694
  8. added a commit that references this issue on Mar 17, 2023
  9. h-vetinari commented on May 12, 2023

    @h-vetinari
    Contributor

    Could 52a3814 (or a minimal version of it) be backported to the 3.1 branch?

  10. t8m commented on May 12, 2023

    @t8m
    Member

    It is a feature/refactoring. If someone backports it OTC can consider approving it for merge to 3.1 (possibly 3.0 as well).

  11. added a commit that references this issue on May 12, 2023
    6f97322
  12. h-vetinari commented on May 13, 2023

    @h-vetinari
    Contributor

    It is a feature/refactoring. If someone backports it OTC can consider approving it for merge to 3.1 (possibly 3.0 as well).

    Well, some change related to this between 3.0.8 & 3.1.0 ended up breaking debugging of CPython on osx-arm, which is causing people to have to come up with work-arounds (see python/cpython#99079).

    That's why I said "or a minimal version of it" - it's a pity that the change is combined with a clean-up & refactoring, but it should be backported in some form. I'm glad @oraluben opened #20948 already, thanks!

    For context (from discussion in the linked issue but primarily here), CPython maintainers (I am not one of them) are so concerned by the volume of problems with OpenSSL 3 that people have been seriously considering delaying the move to OpenSSL 3 even beyond the EOL of 1.1.1, or changing away from OpenSSL entirely. I mention the perception of one big downstream dependency in case people happen to care about such things, as not backporting a fix would likely pile onto that displeasure.

  13. paulidale commented on May 14, 2023

    @paulidale
    Contributor

    Added a note in the PR with the OTC question.

  14. added a commit that references this issue on Aug 1, 2024
    52a3814
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedtriaged: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions