激動の2020年も気づけば残り3ヵ月、
転回
この問題をメンテナMLに報告してあれこれ議論しているうち、
straceは、
$ strace /sbin/installer/ls -l |& cat -n 1 execve("/sbin/installer/ls", ["/sbin/installer/ls", "-l"], 0x7ffcf614a268 /* 28 vars */) = 0 2 uname({sysname="Linux", nodename="2020_0822", ...}) = 0 3 brk(NULL) = 0x1b62000 4 brk(0x1b63200) = 0x1b63200 5 arch_prctl(ARCH_SET_FS, 0x1b628c0) = 0 ... 80 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 4 81 fstat(4, {st_mode=S_IFREG|0644, st_size=1686, ...}) = 0 82 lseek(4, 0, SEEK_SET) = 0 83 read(4, "root:x:0:0::/root:/bin/bash\nbin:"..., 4096) = 1686 84 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xe5} --- 85 +++ killed by SIGSEGV +++
この結果を見ると、
もう少し絞り込むために、
$ strace /sbin/installer/ls -l |& grep open | cat -n .... 9 openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3 10 open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 4 11 open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 4 12 open("/lib/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 4 13 open("/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 4 14 open("/lib64/ld-linux-x86-64.so.2", O_RDONLY|O_CLOEXEC) = 4 15 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 4
最初の方は今回の問題とは関係ないロケール回りの処理なので省略しました。
この結果を見ると、
この動作はどう見ても仕様のレベルだよなぁ…… と、
「あれれ、
$ cat -n configure | less .... 1436 --enable-stack-protector=[yes|no|all|strong] 1437 Use -fstack-protector[-all|-strong] to detect glibc 1438 buffer overflows 1439 --enable-static-nss build static NSS modules [default=no] 1440 --disable-force-install don't force installation of files from this package, 1441 even if they are older than the installed files ....
configureの説明は"build static NSS modules
$ cat -n INSTALL | less .... 149 '--enable-static-nss' 150 Compile static versions of the NSS (Name Service Switch) libraries. 151 This is not recommended because it defeats the purpose of NSS; a 152 program linked statically with the NSS libraries cannot be 153 dynamically reconfigured to use a different name database. 154 ....
どうやらこのオプションを指定しないとNSS回りのライブラリを静的リンク用にできないようです。ただし、
インターミッション
UNIXの世界では、
元々、
そこで考案されたのが"YP
"Yellow Pages"は英米の
YP/
NSSの特徴のひとつが、
たとえば、
そして,このmDNSサービスを利用するためのNSSプラグインがnss_
このプラグインの本体はlibnss_
Plamo Linuxではnsswitch.
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
この設定で、
なお、
glibc2では、
解決
まずconfigureオプションに"--enable-static-nss"を追加してglibc-2.
具体的なサイズを見てみると、
$ ls -lh default_nss/usr/lib/libc*.a -rw-r--r-- 1 kojima users 5.2M 8月 7日 08:06 default_nss/usr/lib/libc.a -rw-r--r-- 1 kojima users 23K 8月 7日 08:06 default_nss/usr/lib/libc_nonshared.a
一方、
$ ls -lh static_nss/usr/lib/libc*.a -rw-r--r-- 1 kojima users 5.4M 8月 16日 08:36 static_nss/usr/lib/libc.a -rw-r--r-- 1 kojima users 266K 8月 16日 08:36 static_nss/usr/lib/libc_nonshared.a
実際にどのような機能が増えたのかをlibc.
$ nm default_nss/usr/lib/libc.a |& grep nss_files | wc -l 8 $ nm static_nss/usr/lib/libc.a |& grep nss_files | wc -l 143
具体的に、
$ nm static_nss/usr/lib/libc.a |& grep nss_files | cat -n ... 59 nss_files_fopen.o: 60 0000000000000000 T __nss_files_fopen 61 U __nss_files_fopen 62 0000000000000310 T _nss_files_endprotoent 63 0000000000000520 T _nss_files_getprotobyname_r 64 00000000000006d0 T _nss_files_getprotobynumber_r 65 0000000000000370 T _nss_files_getprotoent_r 66 0000000000000000 T _nss_files_parse_protoent 67 0000000000000280 T _nss_files_setprotoent 68 U __nss_files_fopen 69 0000000000000360 T _nss_files_endservent 70 0000000000000570 T _nss_files_getservbyname_r .... 141 0000000000000000 T _nss_files_initgroups_dyn 142 U _nss_files_parse_grent 143 0000000000000000 T _nss_files_init
一方、
$ nm default_nss/usr/lib/libc.a |& grep nss_files | cat -n 1 0000000000000000 T _nss_files_parse_grent 2 0000000000000000 T _nss_files_parse_pwent 3 0000000000000000 T _nss_files_parse_spent 4 U _nss_files_parse_spent 5 0000000000000000 T _nss_files_parse_sgent 6 U _nss_files_parse_sgent 7 nss_files_fopen.o: 8 0000000000000000 T __nss_files_fopen
どうやらこのlibc.
$ nm static-build/src/ls | grep nss | cat -n 1 000000000053a2a0 V __nss_aliases_database 2 0000000000472d40 T __nss_configure_lookup ... 68 0000000000473890 T _nss_files_getprotobyname_r 69 0000000000473a40 T _nss_files_getprotobynumber_r 70 00000000004736e0 T _nss_files_getprotoent_r 71 0000000000476bf0 T _nss_files_getpwent_r 72 0000000000476da0 T _nss_files_getpwnam_r 73 0000000000476f30 T _nss_files_getpwuid_r ... 101 0000000000477fb0 T _nss_netgroup_parseline 102 0000000000472490 t nss_parse_service_list
static linkしたlsに組み込まれているシンボルは102あり、
念のため、
$ nm src/ls | grep nss | cat -n 1 000000000051d8e8 V __nss_aliases_database 2 0000000000479be0 T __nss_configure_lookup ... 19 000000000051d8a8 V __nss_passwd_database 20 000000000047a2c0 T __nss_passwd_lookup2 ... 24 000000000051d888 V __nss_services_database 25 000000000051d880 V __nss_shadow_database 26 0000000000479330 t nss_parse_service_list
この"--enable-static-nss"なglibc2環境で作ったstatic linkのlsは、
$ ls /lib/libc* /lib/libc-2.30.so* /lib/libcap.so.2@ /lib/libcrack.so.2@ /lib/libcrypt-2.30.so* /lib/libc.so.6@ /lib/libcap.so.2.27* /lib/libcrack.so.2.9.0* /lib/libcrypt.so.1@ $ strace ./ls -l |& grep openat | cat -n ... 5 openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 4 6 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 4 7 openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 4 8 openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3 ...
このように、
2回に渡って、
Linuxに代表されるOSSの世界ではたいていのソースコードは公開されているので、
筆者自身、