How to run app linked with glibc.so on android

0

compiler is gcc-linaro-5.5.0-2017.10-i686_arm-linux-gnueabihf.tar.xz, app run on armv7 android4.4 device

My C code is test.c,

#include"stdio.h"
int main(void)
{
        printf("starting...\n");
        return 0;
}

If i compile it use command:

arm-linux-gnueabihf-gcc -o test_s test.c -g -Wl,-rpath=.:./lib -Wl,-rpath=.:./lib -Wl,-q -Wl,-dynamic-linker=ld-2.21.so -static

it can work well:

root@test:/data/mine # chmod 555 test_s
root@test:/data/mine # ./test_s
starting

But, if i compile it use command:

 arm-linux-gnueabihf-gcc -o test_d test.c -g -Wl,-rpath=.:./lib -Wl,-rpath=.:./lib -Wl,-q -Wl,-dynamic-linker=ld-2.21.so

it gives me the error:

root@test:/data/mine # chmod 555 test_d
root@test:/data/mine # ls -l test_d
-rwxrwxrwx root     root        12316 2018-04-19 13:37 test_d
root@test:/data/mine # ./test_d
/system/bin/sh: ./test_d: Permission denied

I have copied the required dynamic libs to the path /data/mine/lib

How should I deal with this problem?

update

before run command mount -o remount,exec /data the command mount return:

/dev/block/platform/comip-mmc.1/by-name/userdata /data ext4 rw,seclabel,nosuid,nodev,noatime,noauto_da_alloc,data=ordered 0 0

after run mount -o remount,exec /data the mount return:

/dev/block/platform/comip-mmc.1/by-name/userdata /data ext4 rw,seclabel,relatime,noauto_da_alloc,data=ordered 0 0

I run strace ./test_d again,it give me same result EACCES. I think "EACCES The filesystem is mounted noexec" is not the root reason, because the test_s is in the same directory, and run correctly

I try to compile with command: arm-linux-gnueabihf-gcc -o test_d_ndl test.c -g -Wl,-rpath=.:./lib

arm-linux-gnueabihf-readelf -d test_d_ndl
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x0000000f (RPATH)                      Library rpath: [.:./lib]

I copy the libc.so.6 to path /data/mine and run commond

root@test:/data/mine # ls -l
-rw-rw-rw- root     root       774660 2018-04-20 13:32 ld-2.21.so
drwxrwxr-x root     root              2018-04-17 14:43 lib
-rw-rw-rw- root     root      9180280 2018-04-20 16:50 libc.so.6
-rwxrwxrwx root     root        13808 2018-04-18 16:56 test
-rwxrwxrwx root     root        12316 2018-04-20 13:31 test_d
-r-xr-xr-x root     root        10520 2018-04-20 16:46 test_d_ndl
-rwxrwxrwx root     root         3348 2018-04-20 09:47 test_ld
-rwxrwxrwx root     root      3672356 2018-04-19 09:58 test_s

root@test:/data/mine # strace  ./test_d_ndl
execve("./test_d_ndl", ["./test_d_ndl"], [/* 25 vars */]) = -1 ENOENT (No such file or directory)
write(2, "strace: exec", 12strace: exec)            = 12
write(2, ": ", 2: )                       = 2
write(2, "No such file or directory", 25No such file or directory) = 25
write(2, "\n", 1
)                       = 1
exit_group(1)                           = ?

test_d_ndl give the error reason ENOENT, what can i do next?

update

use following command works well

arm-linux-gnueabihf-gcc test.c -o test_r_dl -Wl,-rpath=/data/mine/libc/lib -Wl,-dynamic-linker=/data/mine/libc/lib/ld-2.21.so

gcc
glibc
asked on Stack Overflow Apr 19, 2018 by Ricky • edited Apr 20, 2018 by Ricky

1 Answer

0

if i compile it use command: ... -Wl,-dynamic-linker=ld-2.21.so ...

Using relative path for --dynamic-linker is ill-advised: your app will run IFF there is a ./ld-2.21.so in your current working directory.

I have copied the required dynamic libs to the path /data/mine/lib

Since you are not in /data/mine/lib when you are starting the binary, and assuming you didn't also copy ld-2.21.so into /data/mine, your dynamic linker will not be found.

However, usually this is reported with ENOENT rather than EPERM, so I am not sure that is your real problem. Running strace ./test_d may provide additional clues.

Update:

root@test:/data/mine # strace ./test_d execve("./test_d", ["./test_d"], [/* 25 vars */]) = -1 EACCES (Permission denied) ...

The execve man page says:

EACCES The filesystem is mounted noexec.

which sounds like it may be the immediate cause of your error.

(Once you mount -o remount,exec /data/mine, it will likely start failing with ENOENT instead.)

answered on Stack Overflow Apr 20, 2018 by Employed Russian • edited Apr 20, 2018 by Employed Russian

User contributions licensed under CC BY-SA 3.0