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

investigate using #pragma comment(lib, ...) #1931

Open
DanAlbert opened this issue Sep 14, 2023 · 0 comments
Open

investigate using #pragma comment(lib, ...) #1931

DanAlbert opened this issue Sep 14, 2023 · 0 comments

Comments

@DanAlbert
Copy link
Member

We just found a pretty big landmine with this feature. In the example we just encountered this on:

if (__builtin_available(android 29, *)) {
  ATrace_beginAsyncSection("ndk::asyncBeginEndSection", 0);
}

The code is right. It includes a check for __builtin_available to make sure the app is running on a new enough version of the OS before making the maybe-available API call.

The part that was wrong isn't visible here (and therefore isn't visible to the compiler, so it can't diagnose this): the build script forgot to link libandroid. The loader saw the weak symbol, couldn't find a definition for it, and set ATrace_beginAsyncSection to nullptr. __builtin_available returned true though, because the device we were running on was API 32, so the call segfaulted.

Could you add a #pragma comment(lib, "android") in the relevant headers so that including the header also ensures that you link against the library? That started out as a Windows thing, but Clang and LLD have supported it for ELF for a while now, and I believe e.g. Fuchsia uses it pretty extensively. I guess it'd still need to be guarded by an __ANDROID_API__ check for libraries which were introduced in later API levels, so it's not foolproof, but it's still something.

Originally posted by @smeenai in #837 (comment)

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

No branches or pull requests

1 participant