歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 如何獲取Linux-gate.so.1動態庫

如何獲取Linux-gate.so.1動態庫

日期:2017/3/1 10:38:02   编辑:Linux編程

前面“Linux應用程序Helloworld入門”已經提到在Linux下每個可執行文件都依賴於幾個最為基本的動態庫,其中一個就是linux-gate.so.1。

從上面ldd給出的結果可以看出,這個linux-gate.so.1動態庫有一些異樣,libc.so.6的實際動態庫路徑在/lib/tls/i686/cmov/libc.so.6,而ld-linux.so.2是在/lib/ld-linux.so.2。那麼不禁要問一個問題linux-gate.so.1這個動態庫的路徑是什麼,是文件系統中那個文件呢?其實這個文件是內核映射上去的,並非存在實際的動態庫文件,對於這個具體問題我們後續再做詳細分析,這裡僅僅做如何獲取linux-gate.so.1動態庫的方法。

通常情況下,比如在SUSE10, suse11系統上,linux-gate.so.1被映射到ffffe000-fffff000這個高端內存段裡面。此時將這段內存導出到文件比較簡單,可以使用下面腳本,幫助各位導出:

  1. VDSO_FILE_NAME=linux-gate.dso
  2. cat /proc/self/maps|grep "vdso"
  3. VDSO_ADDR=`cat /proc/self/maps|grep "vdso" |awk -F '-' '{print $1 }'`
  4. echo "Current VDSO address is 0x$VDSO_ADDR"
  5. VDSO_BLOCK=`echo |awk '{print substr("'${VDSO_ADDR}'",1,5)}'`
  6. ((SKIP_BLOCKS=16#$VDSO_BLOCK))
  7. echo "We have $SKIP_BLOCKS blocks before VDSO library"
  8. echo "Ready to generate $VDSO_FILE_NAME from block $SKIP_BLOCKS"
  9. dd if=/proc/self/mem of=$VDSO_FILE_NAME bs=4096 skip=$SKIP_BLOCKS count=1
  10. echo "Generate $VDSO_FILE_NAME Done"

在suse系統上執行的結果:

  1. ~> ./cat_linux_gate_so.sh
  2. ffffe000-fffff000 ---p 00000000 00:00 0 [vdso]
  3. Current VDSO address is 0xffffe000
  4. We have 1048574 blocks before VDSO library
  5. Ready to generate linux-gate.dso from block 1048574
  6. 1+0 records in
  7. 1+0 records out
  8. 4096 bytes (4.1 kB) copied, 4.2e-05 seconds, 97.5 MB/s
  9. Generate linux-gate.dso Done
  10. ~> file -b linux-gate.dso
  11. ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), stripped
  12. ~> objdump -T linux-gate.dso
  13. linux-gate.dso: 文件格式 elf32-i386
  14. DYNAMIC SYMBOL TABLE:
  15. ffffe400 l d .text 00000000 .text
  16. ffffe478 l d .eh_frame_hdr 00000000 .eh_frame_hdr
  17. ffffe49c l d .eh_frame 00000000 .eh_frame
  18. ffffe620 l d .useless 00000000 .useless
  19. ffffe400 g DF .text 00000014 LINUX_2.5 __kernel_vsyscall
  20. 00000000 g DO *ABS* 00000000 LINUX_2.5 LINUX_2.5
  21. ffffe440 g DF .text 00000007 LINUX_2.5 __kernel_rt_sigreturn
  22. ffffe420 g DF .text 00000008 LINUX_2.5 __kernel_sigreturn

在Ubuntu 上情況比較復雜,在此也耽誤了不少時間,因為ubuntu映射到的內存地址是不固定的,每個進程映射的位置都是不同的。

多次執行:

cat /proc/self/maps|grep "vdso"

b7f47000-b7f48000 r-xp b7f47000 00:00 0 [vdso]

b7f5f000-b7f60000 r-xp b7f5f000 00:00 0 [vdso]

b7f54000-b7f55000 r-xp b7f54000 00:00 0 [vdso]

Copyright © Linux教程網 All Rights Reserved