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

[BUG] libz.a for armeabi-v7a is missing symbols #1391

Closed
topjohnwu opened this issue Dec 6, 2020 · 3 comments
Closed

[BUG] libz.a for armeabi-v7a is missing symbols #1391

topjohnwu opened this issue Dec 6, 2020 · 3 comments
Assignees
Labels

Comments

@topjohnwu
Copy link

Using NDK r22-beta1 (22.0.6917172-beta1) on macOS with ndk-build to build static binaries.
When statically linking libz.a in 32 bit ARM code, the linker will complain with the following error:

ld: error: undefined symbol: arm_cpu_enable_crc32
>>> referenced by deflate.c:0 (external/zlib/deflate.c:0)
>>>               deflate.o:(deflateInit2_) in archive /Volumes/Developer/android/sdk/ndk/magisk/toolchains/llvm/prebuilt/darwin-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21/libz.a

ld: error: undefined symbol: x86_cpu_enable_simd
>>> referenced by deflate.c:0 (external/zlib/deflate.c:0)
>>>               deflate.o:(deflateInit2_) in archive /Volumes/Developer/android/sdk/ndk/magisk/toolchains/llvm/prebuilt/darwin-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21/libz.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Using readelf to print out symbols of all libz.a for arm 32, it seems all libz.a archives are missing cpu_features.o, causing the following symbols to be undefined:

int arm_cpu_enable_crc32;
int arm_cpu_enable_pmull;
int x86_cpu_enable_sse2;
int x86_cpu_enable_ssse3;
int x86_cpu_enable_simd;

This issue does not happen on any other arch.

@enh-google
Copy link
Collaborator

hmm. i wrote this in the Android.bp:

    // This file doesn't build for non-neon, so it can't be in the main srcs.
    "cpu_features.c",

i've just done an upstream update anyway so i'll have a look and see if that's actually/still true. (things might get a bit interesting if non-neon is just not supported, but we can always hack in some stubs.)

works for me locally, but iirc i need to let treehugger actually do an NDK build to hit the non-neon case anyway: https://android-review.googlesource.com/c/platform/external/zlib/+/1519998

@enh-google
Copy link
Collaborator

okay, the obvious "let's just build it" failed:

external/zlib/cpu_features.c:56:13: error: function '_cpu_check_features' has internal linkage but is not defined [-Werror,-Wundefined-internal]
static void _cpu_check_features(void);
            ^
external/zlib/cpu_features.c:70:42: note: used here
    pthread_once(&cpu_check_inited_once, _cpu_check_features);
                                         ^
1 error generated.

...but playing with the CPU_NO_SIMD #define seems to work. i've uploaded a new patchset to the same CL.

@hhb
Copy link
Collaborator

hhb commented Jan 29, 2021

@hhb hhb closed this as completed Jan 29, 2021
grendello added a commit to grendello/xamarin-android that referenced this issue Mar 25, 2021
Context: https://github.com/android/ndk/wiki/Changelog-r22#r22b
Context: android/ndk#1427

Upstream changes:

  * [Issue 1377][0]: Fix Clang backend crash in register scavenging.
  * [Issue 1388][1]: Fixed LLVM's incorrect conversion to list files for long command lines on Windows.
  * [Issue 1391][2]: Fixed missing symbols from libz.a.
  * [Issue 1427][3]: Fixed Clang auto-detection for CMake 3.19 and older for Windows.

Fix for issue 1427 above allows us to remove the older Android cmake
toolchain file we've been using to work around the bug on Windows
platforms.

[0]: android/ndk#1377
[1]: android/ndk#1388
[2]: android/ndk#1391
[3]: android/ndk#1427
jonpryor pushed a commit to dotnet/android that referenced this issue Mar 26, 2021
Context: https://github.com/android/ndk/wiki/Changelog-r22#r22b
Context: android/ndk#1427

Upstream changes:

  * [Issue 1377][0]: Fix Clang backend crash in register scavenging.
  * [Issue 1388][1]: Fixed LLVM's incorrect conversion to list files
    for long command lines on Windows.
  * [Issue 1391][2]: Fixed missing symbols from `libz.a`.
  * [Issue 1427][3]: Fixed Clang auto-detection for CMake 3.19 and
    older for Windows.

The fix for issue 1427 above allows us to remove the older Android
cmake toolchain file we've been using (accc846) to work around the
bug on Windows platforms.

[0]: android/ndk#1377
[1]: android/ndk#1388
[2]: android/ndk#1391
[3]: android/ndk#1427
chenyt9 pushed a commit to MotorolaMobilityLLC/external-zlib that referenced this issue May 9, 2023
Bug: android/ndk#1391
Test: treehugger
Test: ./build/soong/scripts/build-ndk-prebuilts.sh
Change-Id: I4e2f7836883cbad8cb533561e73cd7afcaf75ec4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants