Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kartatz opened this issue Aug 28, 2024 · 10 comments
Closed

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

Kartatz opened this issue Aug 28, 2024 · 10 comments

Comments

@Kartatz
Copy link

Kartatz commented Aug 28, 2024

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

@bagder bagder added the cmake label Aug 29, 2024
@bagder
Copy link
Member

bagder commented Aug 29, 2024

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.

@vszakats
Copy link
Member

vszakats commented Aug 29, 2024

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.

@vszakats
Copy link
Member

vszakats commented Aug 29, 2024

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

@vszakats vszakats added the build label Aug 29, 2024
@bagder
Copy link
Member

bagder commented Aug 29, 2024

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.

@Kartatz
Copy link
Author

Kartatz commented Aug 29, 2024

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.

@bagder
Copy link
Member

bagder commented Aug 29, 2024

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.

@vszakats
Copy link
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

@bagder
Copy link
Member

bagder commented Aug 29, 2024

Yeah, that's probably a decent guess.

vszakats added a commit to vszakats/curl that referenced this issue Aug 29, 2024
Also:
- cmake: delete unnecessary `#include <sys/time.h>` from
  non-cross-build `poll()` detection snippet.
  Follow-up tp cc8b813 curl#14718

Fixes curl#14714
@vszakats
Copy link
Member

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

@Kartatz
Copy link
Author

Kartatz commented Aug 30, 2024

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

Yes, it's correctly detected. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants