我使用 linaro 和 codesourcery 工具链为 android 进行交叉编译,我发现即使在-static
这里提供问题似乎来自 glibc 动态链接libnss_* libraries
。
这是我的代码
#include <sys/types.h>
#include <pwd.h>
int main(){
struct passwd *pw = getpwnam("root");
return 0;
}
运行以下命令
arm-linux-gnueabihf-gcc -static pwnam_test.c -lc -o pwtest
在跟踪它之后得到以下输出
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)
我怎样才能静态链接所有动态所需的库,还是需要交叉编译 glibc?
好吧,我不赞成使用 NDK,因为我试图以某种方式交叉编译 nginx,但在访问 localhost:8080 时,nginx 没有响应