I was cross compiling for android using linaro and codesourcery toolchains i found even after providing -static
here problem seems to come from glibc dynamically link libnss_* libraries
.
Here is my code
#include <sys/types.h>
#include <pwd.h>
int main(){
struct passwd *pw = getpwnam("root");
return 0;
}
run following command
arm-linux-gnueabihf-gcc -static pwnam_test.c -lc -o pwtest
after stracing it a got following output
11455 uname(0xf6ffeb70) = 0
11455 brk(NULL) = 0x0006d000
11455 brk(0x0006dd00) = 0x0006dd00
11455 brk(0x0008ed00) = 0x0008ed00
11455 brk(0x0008f000) = 0x0008f000
11455 socket(1,526337,0,0,445504,319244) = 3
11455 connect(3,0xf6ffea30,110) = -1 errno=2 (No such file or directory)
11455 close(3) = 0
11455 socket(1,526337,0,1,445504,0) = 3
11455 connect(3,0xf6ffeb50,110) = -1 errno=2 (No such file or directory)
11455 close(3) = 0
11455 open("/etc/nsswitch.conf",O_RDONLY|O_CLOEXEC) = 3
11455 fcntl64(3,F_GETFD) = 1
11455 fstat64(3,0xf6ffeb78) = 0
11455 mmap2(NULL,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0xf67fe000
11455 read(3,0xf67fe000,4096) = 513
11455 read(3,0xf67fe000,4096) = 0
11455 close(3) = 0
11455 munmap(0xf67fe000,4096) = 0
11455 open("/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3
11455 fstat64(3,0xf6ffe450) = 0
11455 mmap2(NULL,88624,PROT_READ,MAP_PRIVATE,3,0) = 0xf67e9000
11455 close(3) = 0
11455 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
11455 open("/lib/arm-linux-gnueabihf/libnss_compat.so.2",O_RDONLY|O_CLOEXEC) = -1 errno=2 (No such file or directory)
11455 stat64("/lib/arm-linux-gnueabihf",0xf6ffe488) = -1 errno=2 (No such file or directory)
11455 open("/usr/lib/arm-linux-gnueabihf/libnss_compat.so.2",O_RDONLY|O_CLOEXEC) = -1 errno=2 (No such file or directory)
11455 stat64("/usr/lib/arm-linux-gnueabihf",0xf6ffe488) = -1 errno=2 (No such file or directory)
11455 open("/lib/libnss_compat.so.2",O_RDONLY|O_CLOEXEC) = -1 errno=2 (No such file or directory)
11455 stat64("/lib",0xf6ffe488) = 0
11455 open("/usr/lib/libnss_compat.so.2",O_RDONLY|O_CLOEXEC) = -1 errno=2 (No such file or directory)
11455 stat64("/usr/lib",0xf6ffe488) = 0
11455 munmap(0xf67e9000,88624) = 0
11455 exit_group(0)
how can i able to statically link all dynamic required library or do i need to cross compile glibc ?
Well, i am not in the favor of using NDK because i am trying to cross compile nginx somehow it execute but on accessing localhost:8080 nginx doesn't responds