leleliu008 / ndk-pkg-formula-repository-official-core

the formula repository for ndk-pkg
Apache License 2.0
13 stars 6 forks source link

Bash doesn't compile on arch linux. #2

Closed ghost closed 3 years ago

ghost commented 3 years ago
ld: error: duplicate symbol: strchrnul
>>> defined at strchrnul.c
>>>            strchrnul.o:(strchrnul) in archive ./lib/sh/libsh.a
>>> defined at static_function_dispatch.S:39 (bionic/libc/arch-arm64/static_function_dispatch.S:39)
>>>            static_function_dispatch.o:(.text+0x30) in archive /home/kubast2/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libc.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:582: bash] Error 1
make: Leaving directory '/tmp/tmp.yDkXKIKWcs/1625446615/arm64-v8a'
[✘] install bash/arm64-v8a failed! you can go to /tmp/tmp.yDkXKIKWcs to see see.

/tmp/tmp.yDkXKIKWcs test.tar.gz

leleliu008 commented 3 years ago

this is a issue since android-ndk r22 : https://github.com/android/ndk/issues/1409, please using android-ndk r21

ghost commented 3 years ago

I will take a look at that.

Between r21d and r22, the upstream Clang driver changed its default from -fcommon to -fno-common

Can you try adding -fcommon flag somewhere in the CFLAGS? If it really is about that, which I doubt.

But from I can tell the function from libsh appears in bionic libc for android 21(5.0).

leleliu008 commented 3 years ago

-fcommon added in CFLAGS, yet same error.

ghost commented 3 years ago

That's because the libc.a static bionic library, contains the same symbol strchrnul.

The way to respond to something like this can be:

1.Unpack the static library archive(it is made with ar) and contains .o files put in it blindly. Remove the offending .o file, and let libsh use said symbol, the static library(ar archive) modification needs to be local. And then we make sure it finds our new static libc first before one found in ndk. Because such change isn't done to a shared library and the change will be statically linked there are no side effects to this, bash expects the function not to be part of libc and so it staticslly links it is self against libsh I bet.

2.Remove the function from libsh, it is just a single file, but it would take a whole lot more time, there might be side effects if the bionic libc implementation has a different behavior.

leleliu008 commented 3 years ago

remove --enable-static-link, using shared library, don't use static library.

ghost commented 3 years ago

Yeah the armv7 build didn't went through for ndk22 and ndk21

ndk22 and 21 didn't find a couple of libc wrappers to setgrent getgrent endgrent; and it also has an undefined reference to mblen;

At least from my end how can I ignore builds of architectures which fail to compile?

I want to have it packaged up etc. primarily for armv8

leleliu008 commented 3 years ago
case $TARGET_OS_ARCH in
        armv7a)

            ;;
        aarch64)

            ;;
        i686)

            ;;
        x86_64)

            ;;
    esac
ghost commented 3 years ago
case $TARGET_OS_ARCH in
        armv7a)

            ;;
        aarch64)

            ;;
        i686)

            ;;
        x86_64)

            ;;
    esac

Fair I should have thought of that

ghost commented 3 years ago

Well the issue is closed for me, but you will probably want the armv7a running

leleliu008 commented 3 years ago

android-ndk r21 is highly recommended. because it is used in my Github Actions CI.

ghost commented 3 years ago

.c

        #include <sys/types.h>
        #include <grp.h>
        struct group* getgrent(void) {
                return NULL;
        }
        void setgrent(void) {
                return;
        }
        void endgrent(void) {
                return;
        }

.h

        struct group* getgrent(void);
        void setgrent(void);
        void endgrent(void);

mblen: https://github.com/awong-dev/ndk/blob/master/sources/android/support/src/musl-multibyte/mblen.c

ghost commented 3 years ago

it fails for me with ndk 21 as well actually idk what made it jump from aarch64 build to armv7 build, thought the arrch64 build went through

ghost commented 3 years ago
<kubast2>       Hey, how crucial is setgrent, getgrent and endgrent for bash? Say the target system doesn't have /etc/group, can I make a thin wrapper that will just return the error condition?
<kubast2>       I will just verify
<kubast2>       setgrent(3) getgrent(3) endgrent(3) is usually part of libc; but I have this specific embedded application with some alternative libc; which comes without those functions;
<earnestly>     Appears to use it directly for group name completions, and only there
leleliu008 commented 3 years ago

They are introduced in android-26.