佐须之男的博客

技术需要沉淀,成长需要痛苦,成功需要坚持,敬仰需要奉献

替换智龙系统自带的库,解决域名解析失败问题

前言:
    不知道网友是否注意到,龙芯智龙开发板的库是存在一些问题的。会导致ping这一类程序执行失败,不能解析域名。下面是执行后返回信息:

[root@Loongson-gz:/lib]#ping forgotfun.org
ping: bad address 'forgotfun.org'

初步判断是缺少libnss库的问题,因为我网络配置都是正确的。为了确定是否是库导致的问题,使用strace运行了下ping程序,下面是执行后返回的信息:
[root@Loongson-gz:/lib]#./strace ping forgotfun.org
execve("/bin/ping", ["ping", "forgotfun.org"], [/* 9 vars */]) = 0
uname({sysname="Linux", nodename="Loongson-gz", ...}) = 0
brk(NULL)                               = 0xc15000
brk(0xc15ccc)                           = 0xc15ccc
set_thread_area(0xc1c470)               = 0
brk(0xc36ccc)                           = 0xc36ccc
brk(0xc37000)                           = 0xc37000
getuid()                                = 0
getpid()                                = 69
socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=69, groups=00000000}, [12]) = 0
time(NULL)                              = 1707022296
sendto(3, "\24\0\0\0\26\0\1\3\330\27\277e\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3,
 {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, 
msg_iov(1)=[{"<\0\0\0\24\0\2\0\330\27\277eE\0\0\0\2\30\200\0\2\0\0\0\10\0\1\0\300\250\1\7"...,
 4096}], msg_controllen=0, msg_flags=0}0
recvmsg(3, 
{msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, 
msg_iov(1)=[{"\24\0\0\0\3\0\2\0\330\27\277eE\0\0\0\0\0\0\0", 4096}], 
msg_controllen=0, msg_flags=0}, 0) = 20
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open("/etc/nsswitch.conf", O_RDONLY)    = -1 ENOENT (No such file or directory)
brk(0xc36000)                           = 0xc36000
open("/etc/resolv.conf", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0777, st_size=23, ...}) = 0
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b5ad000
read(3, "nameserver 192.168.1.1\n", 4096) = 23
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x2b5ad000, 65536)               = 0
uname({sysname="Linux", nodename="Loongson-gz", ...}) = 0
open("/lib/libnss_dns.so.2", O_RDONLY)  = -1 ENOENT (No such file or directory)
stat64("/lib", {st_mode=S_IFDIR|0755, st_size=2048, ...}) = 0
open("/usr/lib/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib", 0x7fa7dc90)          = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/lib/libnss_dns.so.2", O_RDONLY)  = -1 ENOENT (No such file or directory)
open("/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "ping: bad address 'forgotfun.org"..., 34ping: bad address 'forgotfun.org'
) = 34
exit_group(1)                           = ?
    提示找不到libnss_dns和libnss_files库。系统并没有自带strace,需要自己编译,但还是希望官方把这些常用的开发工具给集成到系统里。教程:    虽然说总体思路是很简单的,但是在解决的过程中还是绕了很多弯路的。下面和大家分享下,我遇到的问题和解决的思路。    遇到库问题缺失,我第一个反应是从交叉编译工具链中提取lib库文件,但是测试后发现程序执行的时候会报浮点错误,下面是错误信息的内容:
[root@Loongson-gz:/tmp]#ping forgotfun.org
ping: ../sysdeps/unix/sysv/linux/ia64/getpagesize.c:35: __getpagesize: Assertion `_rtld_global_ro._dl_pagesize != 0' failed.
Floating point exception
 
   百思不得其解后,只能重新换思路。到网 
上下载buildroot,重新编译交叉工具链,编译时选择的是2.21的glibc库,比板子上的2.7稍高。我再次测试后发现这次出现的错误还是和上
面的一样,所以索性把板子的整个lib目录给替换了,当然可预见的是这次肯定还是失败了。下面是错误信息的内容:
[root@Loongson-gz:/lib]#./strace ping forgotfun.org
execve("/bin/ping", ["ping", "forgotfun.org"], [/* 9 vars */]) = 0
uname({sysname="Linux", nodename="Loongson-gz", ...}) = 0
brk(NULL)                               = 0x6f2000
brk(0x6f2ccc)                           = 0x6f2ccc
set_thread_area(0x6f9470)               = 0
brk(0x713ccc)                           = 0x713ccc
brk(0x714000)                           = 0x714000
getuid()                                = 0
getpid()                                = 114
socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=114, groups=00000000}, [12]) = 0
time(NULL)                              = 1707025006
sendto(3, "\24\0\0\0\26\0\1\3n\"\277e\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3,
 {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, 
msg_iov(1)=[{"<\0\0\0\24\0\2\0n\"\277er\0\0\0\2\30\200\0\2\0\0\0\10\0\1\0\300\250\1\7"...,
 4096}], msg_controllen=0, msg_flags=0}, 0)0
recvmsg(3, 
{msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, 
msg_iov(1)=[{"\24\0\0\0\3\0\2\0n\"\277er\0\0\0\0\0\0\0", 4096}], 
msg_controllen=0, msg_flags=0}, 0) = 20
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
socket(PF_LOCAL, SOCK_STREAM, 0)        = 3
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3)                                = 0
open("/etc/nsswitch.conf", O_RDONLY)    = -1 ENOENT (No such file or directory)
brk(0x713000)                           = 0x713000
open("/etc/resolv.conf", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0777, st_size=23, ...}) = 0
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b15e000
read(3, "nameserver 192.168.1.1\n", 4096) = 23
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x2b15e000, 65536)               = 0
uname({sysname="Linux", nodename="Loongson-gz", ...}) = 0
open("/lib/libnss_dns.so.2", O_RDONLY)  = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\0\f\0\0004\0\0\0"..., 512) = 512
lseek(3, 564, SEEK_SET)                 = 564
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0 \0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=22416, ...}) = 0
mmap(NULL, 86224, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b15e000
mprotect(0x2b163000, 61440, PROT_NONE)  = 0
mmap(0x2b172000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0x2b172000
close(3)                                = 0
open("/lib/libresolv.so.2", O_RDONLY)   = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0@%\0\0004\0\0\0"..., 512) = 512
lseek(3, 556, SEEK_SET)                 = 556
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0 \0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=83644, ...}) = 0
mmap(NULL, 153856, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b174000
mprotect(0x2b187000, 61440, PROT_NONE)  = 0
mmap(0x2b196000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12000) = 0x2b196000
mmap(0x2b198000, 6400, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2b198000
close(3)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0$\237\1\0004\0\0\0"..., 512) = 512
lseek(3, 700, SEEK_SET)                 = 700
read(3, "\4\0\0\0\20\0\0\0\1\0\0\0GNU\0\0\0\0\0\2\0\0\0\6\0\0\0 \0\0\0", 32) = 32
fstat64(3, {st_mode=S_IFREG|0755, st_size=1606224, ...}) = 0
mmap(NULL, 1584960, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b19a000
mprotect(0x2b305000, 65536, PROT_NONE)  = 0
mmap(0x2b315000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16b000) = 0x2b315000
mmap(0x2b31b000, 8000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2b31b000
close(3)                                = 0
open("/lib/ld.so.1", O_RDONLY)          = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\10\0\1\0\0\0\220\f\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=154296, ...}) = 0
mmap(NULL, 212212, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2b31d000
mprotect(0x2b340000, 61440, PROT_NONE)  = 0
mmap(0x2b34f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x2b34f000
close(3)                                = 0
mprotect(0x2b34f000, 4096, PROT_READ)   = 0
mprotect(0x2b315000, 12288, PROT_READ)  = 0
mprotect(0x2b196000, 4096, PROT_READ)   = 0
mprotect(0x2b172000, 4096, PROT_READ)   = 0
mmap(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b351000
open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0777, st_size=23, ...}) = 0
mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b451000
read(3, "nameserver 192.168.1.1\n", 4096) = 23
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x2b451000, 65536)               = 0
uname({sysname="Linux", nodename="Loongson-gz", ...}) = 0
gettimeofday({1707025006, 488888}, NULL) = 0
socket(PF_INET, SOCK_DGRAM|0x80 /* SOCK_??? */, IPPROTO_IP) = 3
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x6f1fe0} ---
+++ killed by SIGSEGV +++
Segmentation fault

    出现段错误,感觉是libc.so的问题,采用机器自带的libc.so后测试成功。下面是执行后的信息:

[root@Loongson-gz:/]#ping forgotfun.org
PING forgotfun.org (103.6.84.125): 56 data bytes
64 bytes from 103.6.84.125: seq=0 ttl=52 time=150.472 ms
^C
--- forgotfun.org ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 150.472/150.472/150.472 ms


    终于告一段落了,教程中使用的strace和lib目录的库文件我已经整理并上传,你只需下载解压到lib目录。不需要上述那么麻烦的操作,本文只起一个抛砖引玉的作用,不过还是希望智龙的开发组做好测试工作,减少用户的挫败感和麻烦。

   文章中的库文件下载地址:http://git.oschina.net/LuMingFen ... master/loongson_lib


版权所有: http://forgotfun.org/2016/03/%E6%9B%BF%E6%8D%A2%E6%99%BA%E9%BE%99%E7%B3%BB%E7%BB%9F%E8%87%AA%E5%B8%A6%E7%9A%84%E5%BA%93%EF%BC%8C%E8%A7%A3%E5%86%B3%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90%E5%A4%B1%E8%B4%A5%E9%97%AE%E9%A2%98.html 作者: 佐须之男 未经允许请勿转载

© 2016 佐须之男版权所有 | 联系方式 forgotfun@qq.com | 业务合作 181-1435-4589 (陆工)