Skip to content

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

Closed

Description

@topjohnwu

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.

Activity

  1. enh-google commented on Dec 7, 2020

    @enh-google
    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

  2. enh-google commented on Dec 8, 2020

    @enh-google
    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.

  3. added a commit that references this issue on Mar 25, 2021
  4. added a commit that references this issue on Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions