Skip to content

HAVE_POLL_FINE is always false when cross-compiling with CMake #14714

Description

@Kartatz

I did this

I was having a weird issue when using the multi interface where the curl_multi_poll() call occasionally returns CURLM_UNRECOVERABLE_POLL.

The thing is, this issue was only reproducible in cross-compiled binaries. After a bit of investigation around Curl_poll(), I found that this is caused by the lack of the HAVE_POLL_FINE define in these builds.

Looking at CMake/OtherTests.cmake I see that there is indeed a check for HAVE_POLL_FINE inside a if (NOT CMAKE_CROSSCOMPILING) condition.

Removing the NOT CMAKE_CROSSCOMPILING check and replacing check_c_source_runs() with check_c_source_compiles() fixes this.

I expected the following

Properly detection of HAVE_POLL_FINE.

curl/libcurl version

libcurl/8.10.0-DEV BearSSL nghttp2/1.61.0

operating system

Linux rhel 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. bagder commented on Aug 29, 2024

    @bagder
    Member

    The check for this actually builds and runs code to verify poll() and that cannot be done for cross-compiles. Thus, it guesses.

    Maybe this should rather guess on it working, if not using Apple OS.

  2. vszakats commented on Aug 29, 2024

    @vszakats
    Member

    One option is to hard-wire known results for (cross-)compilation targets (like done for Apple).
    One other is to explicitly pass -DHAVE_POLL_FINE=ON/OFF to CMake override the default for specific builds.

  3. vszakats commented on Aug 29, 2024

    @vszakats
    Member

    In ./configure this detection is reserved for cross-builds as well.

  4. bagder commented on Aug 29, 2024

    @bagder
    Member

    Classically, you'd double-check the config.h file after configure has run so that it figured out things correctly. For cross-compiles especially, as it has more limited checks due to not being able to run code for checks.

    So cmake/configure needs to use a use a default for such checks. Probably going with the safe one.

  5. Kartatz commented on Aug 29, 2024

    @Kartatz
    Author

    Maybe this should rather guess on it working, if not using Apple OS.

    That seem a reasonable solution to me. I would say that there are more platforms with a working poll() than platforms with a broken one, but I think I should not speculate about this.

    Either way, I think it would be cool to have an entry about this behavior in the Known Bugs section; something like "poll() cannot be detected properly in some environments" sounds fine.

  6. bagder commented on Aug 29, 2024

    @bagder
    Member

    it would be cool to have an entry about this behavior in the Known Bugs section

    It's not really a bug, it's a known limitation. And this is not unique for curl, this is how cross-compiling works for just about everyone. There several more checks that cannot be done for cross-builds.

    Ideally we should have these documented, but it might be tricky.

  7. vszakats commented on Aug 29, 2024

    @vszakats
    Member

    Would it help to fall back to a non-runtime detection for cross-builds, like?:

    #if <UNIX> && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
    /* has native poll() */
    #endif
  8. bagder commented on Aug 29, 2024

    @bagder
    Member

    Yeah, that's probably a decent guess.

  9. added a commit that references this issue on Aug 29, 2024
    a780bd5
  10. vszakats commented on Aug 29, 2024

    @vszakats
    Member

    @Kartatz Does #14734 make poll() detected in your cross-build?

  11. Kartatz commented on Aug 30, 2024

    @Kartatz
    Author

    Does #14734 make poll() detected in your cross-build?

    Yes, it's correctly detected. Thanks!

  12. added a commit that references this issue on Aug 30, 2024
    04e3621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions