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

Android: lld: error: undefined symbol: __emutls_get_address #5921

Closed
meme opened this issue Jul 25, 2020 · 7 comments
Closed

Android: lld: error: undefined symbol: __emutls_get_address #5921

meme opened this issue Jul 25, 2020 · 7 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@meme
Copy link
Contributor

meme commented Jul 25, 2020

Seems that Android support has regressed, testing with Android NDK r20, the following missing symbol error occurs (presumably there are more):

lld: error: undefined symbol: __emutls_get_address
>>> referenced by debug.zig:253 (/zig/lib/std/debug.zig:253)
>>>               ./sample.o:(std.debug.panicExtra)
>>> referenced by debug.zig:255 (/zig/lib/std/debug.zig:255)
>>>               ./sample.o:(std.debug.panicExtra)
>>> referenced by debug.zig:284 (/zig/lib/std/debug.zig:284)
>>>               ./sample.o:(std.debug.panicExtra)

Can reproduce as follows (995fd73):

zig build-exe -target aarch64-linux-android --libc aarch64-linux-android.txt sample.zig

aarch64-linux-android.txt:

include_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
sys_include_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
static_crt_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/
crt_dir=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21

msvc_lib_dir=
kernel32_lib_dir=

Can't assign myself to an issue, but I'm taking a look at this currently. Question for the team though: how can we prevent regressions like this in the future?

@meme
Copy link
Contributor Author

meme commented Jul 25, 2020

Since Zig implements its own compiler_rt does this functionality need to be added to Zig, or are we better off using LLVM's as a reference implementation: https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/builtins/emutls.c#L378 and implementing it ourselves?

I feel like we should be linking against the NDK's runtime... but we still need to support static targets, for Zig programs that link against libc, linking against libgcc as provided in NDK seems to solve this issue.

@FireFox317
Copy link
Contributor

@meme Yes, this should indeed be added to the compiler_rt of Zig. Basically the compiler_rt of Zig is ported from the LLVM implementation of the compiler_rt, but we have increased safety checks, because it is written in Zig. :)

@meme
Copy link
Contributor Author

meme commented Jul 26, 2020

OK, a few problems after reading into this implementation:

  1. It requires a GPA to expand the TLS table, there appears to be no allocator functionality in Zig's compiler_rt at this time~ perhaps someone who has worked on compiler_rt in the past can clarify
  2. Uses pthread to store a thread-local pointer to the TLS

This is going to be a pain to implement, and we're probably going to have to cut corners to do it. I think getting Android to be plug-and-play again when linking against libc (i.e.: don't use Zig's compiler_rt, use the NDK's) should be done first, then we can tackle the static Android binary situation.

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Aug 1, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Aug 1, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@meme meme closed this as completed Dec 14, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.8.0 Jan 12, 2021
@bayo-code
Copy link

Please how do we apply this fix? this undefined symbol still exists when trying to build for android

@desttinghim
Copy link
Contributor

I don't think this issue has been resolved yet. compiler_rt doesn't expose __emutls_get_address unless the platform is openbsd, so android binaries still do not export it. Getting this working means adding android as an os target, and then exporting the symbol.

@semarie
Copy link
Contributor

semarie commented Oct 12, 2022

isn't possible to simply match on target.abi == .android and export the symbol ?

@desttinghim
Copy link
Contributor

Yes, I think that would do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
Development

No branches or pull requests

6 participants