#1 2008-10-29 14:30:42
ASUS WL-500gP的library是否支援fstat64函式追蹤
寫了一支程式fstat64.c來測試系統是否支援fstat64函式
#include
#include
#include
int main(void)
{
struct stat buf;
fstat64 ("/tmp", &buf);
return 0;
}
利用Cross-Comoiler編譯:
# mipsel-linuc-gcc -o fstat64 fstat64.c
查看它需要什麼shared library
# mipsel-linux-objdump -p fstat64
fstat64: file format elf32-tradlittlemips
Program Header:
PHDR off 0x00000034 vaddr 0x00400034 paddr 0x00400034 align 2**2
filesz 0x000000c0 memsz 0x000000c0 flags r-x
INTERP off 0x000000f4 vaddr 0x004000f4 paddr 0x004000f4 align 2**0
filesz 0x00000014 memsz 0x00000014 flags r--
0x70000000 off 0x00000108 vaddr 0x00400108 paddr 0x00400108 align 2**2
filesz 0x00000018 memsz 0x00000018 flags r--
LOAD off 0x00000000 vaddr 0x00400000 paddr 0x00400000 align 2**12
filesz 0x000008f4 memsz 0x000008f4 flags r-x
LOAD off 0x00001000 vaddr 0x10000000 paddr 0x10000000 align 2**12
filesz 0x0000009c memsz 0x000000c0 flags rw-
DYNAMIC off 0x00000120 vaddr 0x00400120 paddr 0x00400120 align 2**2
filesz 0x000003e0 memsz 0x000003e0 flags rwx
Dynamic Section:
NEEDED libgcc_s.so.1
NEEDED libc.so.0
INIT 0x40054c
FINI 0x400870
HASH 0x400218
STRTAB 0x400408
SYMTAB 0x4002b8
STRSZ 0xf8
SYMENT 0x10
0x70000016 0x10000050
DEBUG 0x0
PLTGOT 0x10000060
REL 0x0
RELSZ 0x0
RELENT 0x8
0x70000001 0x1
0x70000005 0x2
0x70000006 0x400000
0x7000000a 0x7
0x70000011 0x15
0x70000012 0x1a
0x70000013 0xd
VERNEED 0x40052c
VERNEEDNUM 0x1
VERSYM 0x400500
Version References:
required from libgcc_s.so.1:
0x0b792650 0x00 02 GCC_3.0
private flags = 50001007: [abi=O32] [mips32] [not 32bitmode]
得知它需要:
NEEDED libgcc_s.so.1
NEEDED libc.so.0
並且查看它實際上呼叫是什麼函式:
# mipsel-linux-objdump -T fstat64
fstat64: file format elf32-tradlittlemips
DYNAMIC SYMBOL TABLE:
10000020 g D .data 00000000 Base _fdata
10008050 g d *ABS* 00000000 _gp_disp
00000001 g d *ABS* 00000000 Base _DYNAMIC_LINKING
00400120 g DO *ABS* 00000000 Base _DYNAMIC
10008050 g D *ABS* 00000000 Base _gp
004005e0 g D .text 00000000 Base _ftext
10000050 g DO .rld_map 00000000 Base __RLD_MAP
1000009c g D *ABS* 00000000 Base __bss_start
1000009c g D *ABS* 00000000 Base _edata
10000060 g DO *ABS* 00000000 Base _GLOBAL_OFFSET_TABLE_
100000c0 g D *ABS* 00000000 Base _end
1000009c g D *ABS* 00000000 Base _fbss
00000000 w D *UND* 00000000 _Jv_RegisterClasses
00000000 w DF *UND* 0000001c GCC_3.0 __register_frame_info
00400870 g DF .fini 0000001c Base _fini
00400770 g DF .text 00000064 Base main
00400850 DF *UND* 00000244 __uClibc_main
00000000 w DF *UND* 0000001c GCC_3.0 __deregister_frame_info
0040054c g DF .init 0000001c Base _init
00400840 DF *UND* 00000094 fstat64
telnet到ASUS WL-500gP的平台上,到/jffs/opt/lib的目錄中下,查看
/jffs/opt/lib # ls -al libc.so.0
lrwxrwxrwx 1 root root 19 Oct 23 08:55 libc.so.0 -> libuClibc-0.9.28.so
於是將libuClibc-0.9.28.so,利用ftp的方式將它上傳到Host Platform。
# mipsel-linux-objdump -D libuClibc-0.9.28.so > dump
# vim dump
確實查得到fstat64函式的section:
00052090 :
52090: 3c1c0006 lui gp,0x6
52094: 279c4710 addiu gp,gp,18192
52098: 0399e021 addu gp,gp,t9
5209c: 27bdff70 addiu sp,sp,-144
520a0: afbf0088 sw ra,136(sp)
520a4: afb10084 sw s1,132(sp)
520a8: afb00080 sw s0,128(sp)
520ac: afbc0010 sw gp,16(sp)
520b0: 27a60018 addiu a2,sp,24
520b4: 00a08821 move s1,a1
520b8: 00c02821 move a1,a2
520bc: 24021077 li v0,4215
520c0: 0000000c syscall
520c4: 8f9981f8 lw t9,-32264(gp)
520c8: 10e00007 beqz a3,520e8
520cc: 00408021 move s0,v0
520d0: 0320f809 jalr t9
520d4: 00000000 nop
520d8: 8fbc0010 lw gp,16(sp)
520dc: 2403ffff li v1,-1
520e0: 1000000a b 5210c
520e4: ac500000 sw s0,0(v0)
520e8: 8f998558 lw t9,-31400(gp)
520ec: 00401821 move v1,v0
520f0: 00c02021 move a0,a2
520f4: 14400005 bnez v0,5210c
520f8: 02202821 move a1,s1
520fc: 0320f809 jalr t9
52100: 00000000 nop
52104: 8fbc0010 lw gp,16(sp)
52108: 00001821 move v1,zero
5210c: 8fbf0088 lw ra,136(sp)
52110: 8fb10084 lw s1,132(sp)
52114: 8fb00080 lw s0,128(sp)
52118: 00601021 move v0,v1
5211c: 03e00008 jr ra
52120: 27bd0090 addiu sp,sp,144
...
將fstat64放到ASUS WL-500gP上去執行,執行前先設置環境
mount -o bind /jffs/opt /opt
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/jffs/opt/bin
export LD_LIBRARY_PATH=/lib:/usr/lib:/jffs/opt/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
執行:
~ # ./fstat64
./fstat64: can't resolve symbol 'fstat64'
實在為清楚為什麼,在library查得到fstat64的symbol及section,但卻會產生can't resolve symbol的問題。
還是在trace的過程有什麼沒注意的。
離線
#2 2008-10-29 16:22:47
Re: ASUS WL-500gP的library是否支援fstat64函式追蹤
我知道了~
我在設定LD_LIBRARY_PATH中:
export LD_LIBRARY_PATH=/lib:/usr/lib:/jffs/opt/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
在/lib的目錄中有libc.so.0,在執行fstat64程式時,會先到/lib搜尋,恰好有《libc.so.0》,但我猜測這個程式庫沒有fstat64(之所以用猜測的,因為我用objdump印不出來任何的symbol),所以就會告知找不到fstat64 symbol。我重新調換一下:
export LD_LIBRARY_PATH=/jffs/opt/lib:/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
問題解決了!
離線
#3 2008-10-29 16:47:01
Re: ASUS WL-500gP的library是否支援fstat64函式追蹤
調換了LD_LIBRARY_PATH之後,
執行wget會發生Segmentation fault,怪怪~ 一冷一熱
~ # wget http://xxx.yyy.zzz/filename
Connecting to xxx.yyy.zzz[xxx.yyy.zzz]:80
Segmentation fault
這該怎麼trace呢?
離線
#8 2008-10-30 14:41:37
Re: ASUS WL-500gP的library是否支援fstat64函式追蹤
DD-WRT v24 std (c) 2008 NewMedia-NET GmbH
Release: 10/22/08 (SVN revision: 10564)
WL-500gx login: root
Password:
==========================================================
____ ___ __ ______ _____ ____ _ _
| _ \| _ \ \ \ / / _ \_ _| __ _|___ \| || |
|| | || ||____\ \ /\ / /| |_) || | \ \ / / __) | || |_
||_| ||_||_____\ V V / | _ < | | \ V / / __/|__ _|
|___/|___/ \_/\_/ |_| \_\|_| \_/ |_____| |_|
DD-WRT v24
http://www.dd-wrt.com
==========================================================
BusyBox v1.12.1 (2008-10-22 15:25:40 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
root@WL-500gx:~# sh
BusyBox v1.12.1 (2008-10-22 15:25:40 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
root@WL-500gx:~#
現在可以胡搞了.
DD-WRT v24 std (c) 2008 NewMedia-NET GmbH
Release: 10/22/08 (SVN revision: 10564)
WL-500gx login: root
Password:
==========================================================
____ ___ __ ______ _____ ____ _ _
| _ \| _ \ \ \ / / _ \_ _| __ _|___ \| || |
|| | || ||____\ \ /\ / /| |_) || | \ \ / / __) | || |_
||_| ||_||_____\ V V / | _ < | | \ V / / __/|__ _|
|___/|___/ \_/\_/ |_| \_\|_| \_/ |_____| |_|
DD-WRT v24
http://www.dd-wrt.com
==========================================================
BusyBox v1.12.1 (2008-10-22 15:25:40 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
root@WL-500gx:~# cat > /tmp/test.sh
#!/bin/sh
ls -al
root@WL-500gx:~# chmod +x /tmp/test.sh
root@WL-500gx:~# /tmp/test.sh
drwxr-xr-x 16 root root 153 Oct 22 13:28 .
drwxr-xr-x 16 root root 153 Oct 22 13:28 ..
drwxr-xr-x 2 root root 498 Oct 22 13:28 bin
drwxr-xr-x 1 root root 0 Jan 1 1970 dev
drwxr-xr-x 5 root root 380 Oct 22 13:28 etc
drwxr-xr-x 7 root root 1024 Oct 15 23:03 jffs
drwxr-xr-x 3 root root 242 Oct 22 13:28 lib
drwxr-xr-x 2 root root 3 Oct 22 13:28 mmc
drwxr-xr-x 2 root root 3 Oct 22 13:28 mnt
drwxr-xr-x 19 root root 4096 Oct 29 05:29 opt
dr-xr-xr-x 49 root root 0 Jan 1 2000 proc
drwxr-xr-x 2 root root 973 Oct 22 13:28 sbin
drwxr-xr-x 2 root root 3 Oct 22 13:28 sys
drwxrwxrwx 1 root root 0 Jan 1 2000 tmp
drwxr-xr-x 7 root root 76 Oct 22 13:28 usr
lrwxrwxrwx 1 root root 7 Oct 22 13:28 var -> tmp/var
drwxr-xr-x 7 root root 112 Oct 22 13:28 www
root@WL-500gx:~#
這是簡單的script, 提供您觀念上的參考.
離線
#9 2008-10-30 15:07:30
Re: ASUS WL-500gP的library是否支援fstat64函式追蹤
哈哈~ 這個sh不錯用的樣子。
但我比較想了解為什麼
export LD_LIBRARY_PATH=/lib:/usr/lib:/jffs/opt/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
改成這一行
export LD_LIBRARY_PATH=/jffs/opt/lib:/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
執行wget會發生Segmentation fault說!
離線
#10 2008-10-30 15:58:35
Re: ASUS WL-500gP的library是否支援fstat64函式追蹤
DD-WRT v24 std (c) 2008 NewMedia-NET GmbH
Release: 10/22/08 (SVN revision: 10564)
WL-500gx login: root
Password:
==========================================================
____ ___ __ ______ _____ ____ _ _
| _ \| _ \ \ \ / / _ \_ _| __ _|___ \| || |
|| | || ||____\ \ /\ / /| |_) || | \ \ / / __) | || |_
||_| ||_||_____\ V V / | _ < | | \ V / / __/|__ _|
|___/|___/ \_/\_/ |_| \_\|_| \_/ |_____| |_|
DD-WRT v24
http://www.dd-wrt.com
==========================================================
BusyBox v1.12.1 (2008-10-22 15:25:40 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
root@WL-500gx:~# echo $LD_LIBRARY_PATH
/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
root@WL-500gx:~# cd /tmp
root@WL-500gx:/tmp# wget http://downloads.openwrt.org/whiterussian/packages/ipkg_0.99.149-2_mipsel.ipk
Connecting to downloads.openwrt.org (195.56.146.238:80)
root@WL-500gx:/tmp# rm ipkg_0.99.149-2_mipsel.ipk
root@WL-500gx:/tmp# export LD_LIBRARY_PATH=/opt/lib:/jffs/opt/lib:/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/
usr/local/lib
root@WL-500gx:/tmp# wget http://downloads.openwrt.org/whiterussian/packages/ipkg_0.99.149-2_mipsel.ipk
Connecting to downloads.openwrt.org (195.56.146.238:80)
Segmentation fault
root@WL-500gx:/tmp# cat > test.sh
#!/bin/sh
export LD_LIBRARY_PATH=/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
$1 $2
root@WL-500gx:/tmp# chmod +x test.sh
root@WL-500gx:/tmp# ./test.sh wget http://downloads.openwrt.org/whiterussian/packages/ipkg_0.99.149-2_mipsel.i
pk
Connecting to downloads.openwrt.org (195.56.146.238:80)
root@WL-500gx:/tmp# ls -al
drwxrwxrwx 1 root root 0 Jan 1 2000 .
drwxr-xr-x 16 root root 153 Oct 22 13:28 ..
-rw------- 1 root root 1925 Oct 30 13:36 .ipt
-rwx------ 1 root root 99 Oct 30 13:36 .rc_firewall
-rwx------ 1 root root 34 Jan 1 1970 .rc_startup
-rw-r--r-- 1 root root 20 Oct 30 13:36 .rule
-rw------- 1 root root 9 Oct 30 13:36 .wanuptime
drwx------ 1 root root 0 Jan 1 1970 cron.d
-rw-r--r-- 1 root root 0 Jan 1 1970 crontab
drwx------ 1 root root 0 Jan 1 1970 ddns
-rw-r--r-- 1 root root 211 Jan 1 1970 dnsmasq.conf
-rw-r--r-- 1 root root 63 Oct 30 13:38 dnsmasq.leases
drwx------ 1 root root 0 Jan 1 1970 etc
-rw-r--r-- 1 root root 41 Jan 1 1970 hosts
-rw------- 1 root root 205 Oct 30 13:36 igmpproxy.conf
-rw-r--r-- 1 root root 62784 Oct 30 15:57 ipkg_0.99.149-2_mipsel.ipk
-rw-r--r-- 1 root root 82 Jan 1 1970 loginprompt
srwxr-xr-x 1 root root 0 Jan 1 1970 php-fcgi.sock-0
drwxr-xr-x 1 root root 0 Jan 1 1970 ppp
-rw-r--r-- 1 root root 23 Jan 1 1970 resolv.conf
-rw-r--r-- 1 root root 75 Jan 1 1970 resolv.dnsmasq
drwx------ 1 root root 0 Jan 1 1970 root
-rwxr-xr-x 1 root root 97 Oct 30 15:55 test.sh
drwxr-xr-x 1 root root 0 Jan 1 2000 var
drwxr-xr-x 1 root root 0 Jan 1 1970 vsftpd
drwxr-xr-x 1 root root 0 Jan 1 2000 www
若無法理解, 請參閱鳥哥, Study Area相關資料
離線
相關討論主題
主題 | 回覆 | 點閱 | 最後發表 |
---|---|---|---|
ASUS RT-N66U刷Shibby 140 MultiWAN後設定為無線AP 作者 lcjh20516
|
0 | 2353 | 2022-08-26 12:56:28 作者 lcjh20516 |
|
159 | 383137 | 2022-08-14 06:06:27 作者 lcjh20516 |
|
21 | 83348 | 2022-08-14 05:54:54 作者 lcjh20516 |
置頂 |
132 | 372835 | 2022-06-07 10:13:50 作者 dennys |
|
45 | 139701 | 2022-05-06 14:32:17 作者 max7441 |