termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
34.68k stars 3.65k forks source link

libc.so has bad ELF magic: 2f2a2047 #2107

Closed Maxython closed 3 years ago

Maxython commented 3 years ago

Hi @xeffyr, @WMCB-Tech, @Yisus7u7 and others. You know about pacman-for-termux development. So I found a way to install packages, although it is installing but does not work. This is due to unworthy libraries. All necessary libraries were in the glibc package, although it was conflicting, but the conflict was due to header files. As a result, after installation, this error occurred.

CANNOT LINK EXECUTABLE "-bash": "/data/data/com.termux/files/usr/lib/libc.so" has bad ELF magic: 2f2a2047

[Process completed (code 1) - press Enter]

After that I decided to extract specific libraries from the package and after adding the libc.so file the same error is displayed.

Of course, I know how to fix this error, but I'm wondering why it happens.

ghost commented 3 years ago

but I'm wondering why it happens.

ABI difference between Android (Bionic) libc and GNU libc. Termux packages are built with Android NDK toolchain and cannot be executed with GNU libc, Musl, uClibc and others not compatible with Bionic.

Maxython commented 3 years ago

That is, need library analogues on the Android NDK tool?

ghost commented 3 years ago

No, this means if you are using Termux packages, the libc must be Bionic. I.e. from /system/lib. If unsupported libc.so will appear in library search path, you won't be able to execute any of Termux utility.

So if you want to use pacman with GNU libc, rm -rf $PREFIX and fill it with compatible binaries.

Maxython commented 3 years ago

OK thanks)

Yisus7u7 commented 3 years ago

@xeffyr

It's not for nothing, but if it's still fixed, I think some packages wouldn't work because they're echos to work in the standard routes (/bin /share /etc) or am I wrong?

Maxython commented 3 years ago

The installer has added termux-chroot activation. https://wiki.termux.com/wiki/Differences_from_Linux
Therefore, those packages should not actually break.

ghost commented 3 years ago

@Yisus7u7 https://wiki.termux.com/wiki/Differences_from_Linux states this regarding execution behavior:

Therefore, those packages should not actually break.

@Maxython termux-chroot only fixes FHS and some system calls. Nothing more. Bash linked with Bionic libc won't suddenly start work with GNU libc.

Yisus7u7 commented 3 years ago

Well if it's true, using termux-chroot can evade the problem

Maxython commented 3 years ago

@xeffyr I understand that termux-chroot fixes the FHS and that's what I mean.

@Yisus7u7, there are still packages that are not supported on termux. These packages will be written here.

Maxython commented 3 years ago

Another bug with the glibc package, but with a different library and for a different reason. Screenshot_20210603-082944_Termux And if you delete this file, then pacman stops working.

Maxython commented 3 years ago

I'm probably going to ask a dumb question, but I'm curious. Is it possible to link libraries (with GNU libc and with Bionic) if replace some commands with GNU libc (for example bash)?

It's just that some termux commands play an important role, for example the same termux-chroot.

ghost commented 3 years ago

@Maxython Everything that you need to do is to place GNU libc outside of library search path. $PREFIX/lib is reserved solely for Termux purpose and is hardcoded into each ELF executable (in both utilities and libraries).

So if you want to place GNU libc files to $PREFIX/lib, this will not work. Use proot to separate $PREFIX from the rest of FHS layout, i.e. don't use termux-chroot implementation packaged in Termux since you need there a custom directory bindings.

You can use https://github.com/termux/proot-distro/blob/master/proot-distro.sh as example of co-existing of $PREFIX and Linux distribution.

Maxython commented 3 years ago

Is it possible to make an analogue of glibc, but for termux?

ghost commented 3 years ago

GNU libc, even if will be compiled with Android NDK will have a different ABI (application binary interface) anyway, so you won't be able to execute Termux binaries with it. Is that not understandable that GNU libc and Bionic libc are different things on binary and source levels?

Compiler doesn't matter, unlike the information coded into ELF header of executable during compilation time. It is specific to used shared libraries. So if you compiled & linked program with GNU libc, it will not work with Bionic and other libc, unless this different libc has compatibility with GNU libc on binary level.


To accomplish what you are asking, here is what required (minimal):

I've did an experiment with porting Musl libc (it is smaller than GNU libc) - https://archive.org/details/termux-musl-repository-25.01.2019.tar, and it didn't finished successfully. Maintenance requires a lot more effort than current setup with Android NDK. It just not worth it, unless you have unlimited amount of free time and very good knowledge in GCC and libc internals to successfully troubleshoot them.

So if

Is it possible to make an analogue of glibc, but for termux?

is actually request for GNU libc package in Termux, then answer is: no, not possible.


I personally see no reason to have pacman with few GNU libc packages and packages from Termux repositories with termux-chroot use. Better to use proot-distro then or make termux-packages fork producing pacman packages.

Maxython commented 3 years ago

Ok, I understand you.

leap0x7b commented 3 years ago

If it's impossible, then how can nix-on-droid run both bionic and glibc binaries?

ghost commented 3 years ago

@leapofazzam123 Because glibc is not in a library search path of Bionic-linked programs. Glibc is stored in Nix store bind-mounted via proot. It works in same way as UserLAnd or other proot launchers.