ITPub博客

首页 > 数据库 > Oracle > [20211013]阅读ldd源代码跟踪.txt

[20211013]阅读ldd源代码跟踪.txt

原创 Oracle 作者:lfree 时间:2021-10-13 15:52:05 0 删除 编辑

[20211013]阅读ldd源代码跟踪.txt

--//前几天才发现ldd是bash shell脚本,我看了一下源代码,感觉最后的执行有点怪,做一个记录.

$ file $(which ldd)
/usr/bin/ldd: Bourne shell script text executable

$ cp /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/lsnrctl .

$ bash -x ldd lsnrctl
Program=bash LineNo=8 :|bash -x ldd lsnrctl
Program=ldd LineNo=27 /usr/bin/ldd:|TEXTDOMAIN=libc
Program=ldd LineNo=28 /usr/bin/ldd:|TEXTDOMAINDIR=/usr/share/locale
Program=ldd LineNo=30 /usr/bin/ldd:|RTLDLIST='/lib/ld-linux.so.2 /lib64/ld-linux-x86-64.so.2'
Program=ldd LineNo=31 /usr/bin/ldd:|warn=
Program=ldd LineNo=32 /usr/bin/ldd:|bind_now=
Program=ldd LineNo=33 /usr/bin/ldd:|verbose=
Program=ldd LineNo=35 /usr/bin/ldd:|test 1 -gt 0
Program=ldd LineNo=36 /usr/bin/ldd:|case "$1" in
Program=ldd LineNo=92 /usr/bin/ldd:|break
Program=ldd LineNo=103 /usr/bin/ldd:|add_env='LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW='
Program=ldd LineNo=104 /usr/bin/ldd:|add_env='LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION=$verify_out'
Program=ldd LineNo=105 /usr/bin/ldd:|add_env='LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION=$verify_out LD_VERBOSE='
Program=ldd LineNo=106 /usr/bin/ldd:|test '' = yes
Program=ldd LineNo=114 /usr/bin/ldd:|set -o pipefail
Program=ldd LineNo=124 /usr/bin/ldd:|case $# in
Program=ldd LineNo=131 /usr/bin/ldd:|single_file=t
Program=ldd LineNo=138 /usr/bin/ldd:|result=0
Program=ldd LineNo=139 /usr/bin/ldd:|for file in '"$@"'
Program=ldd LineNo=141 /usr/bin/ldd:|test t = t
Program=ldd LineNo=142 /usr/bin/ldd:|case $file in
Program=ldd LineNo=145 /usr/bin/ldd:|file=./lsnrctl
Program=ldd LineNo=148 /usr/bin/ldd:|test '!' -e ./lsnrctl
Program=ldd LineNo=151 /usr/bin/ldd:|test '!' -f ./lsnrctl
Program=ldd LineNo=154 /usr/bin/ldd:|test -r ./lsnrctl
Program=ldd LineNo=155 /usr/bin/ldd:|test -x ./lsnrctl
Program=ldd LineNo=157 /usr/bin/ldd:|RTLD=
Program=ldd LineNo=158 /usr/bin/ldd:|ret=1
Program=ldd LineNo=159 /usr/bin/ldd:|for rtld in '${RTLDLIST}'
Program=ldd LineNo=160 /usr/bin/ldd:|test -x /lib/ld-linux.so.2
PProgram=ldd LineNo=161 /usr/bin/ldd:|/lib/ld-linux.so.2 --verify ./lsnrctl
Program=ldd LineNo=161 /usr/bin/ldd:|verify_out=
Program=ldd LineNo=162 /usr/bin/ldd:|ret=1
Program=ldd LineNo=163 /usr/bin/ldd:|case $ret in
Program=ldd LineNo=159 /usr/bin/ldd:|for rtld in '${RTLDLIST}'
Program=ldd LineNo=160 /usr/bin/ldd:|test -x /lib64/ld-linux-x86-64.so.2
PProgram=ldd LineNo=161 /usr/bin/ldd:|/lib64/ld-linux-x86-64.so.2 --verify ./lsnrctl
Program=ldd LineNo=161 /usr/bin/ldd:|verify_out=
Program=ldd LineNo=162 /usr/bin/ldd:|ret=0
Program=ldd LineNo=163 /usr/bin/ldd:|case $ret in
Program=ldd LineNo=164 /usr/bin/ldd:|RTLD=/lib64/ld-linux-x86-64.so.2
Program=ldd LineNo=164 /usr/bin/ldd:|break
Program=ldd LineNo=168 /usr/bin/ldd:|case $ret in
Program=ldd LineNo=177 /usr/bin/ldd:|try_trace /lib64/ld-linux-x86-64.so.2 ./lsnrctl
Program=ldd LineNo=116 /usr/bin/ldd:try_trace|eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= 'LD_LIBRARY_VERSION=$verify_out' LD_VERBOSE= '"$@"'
Program=ldd LineNo=116 /usr/bin/ldd:try_trace|cat
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_TRACE_LOADED_OBJECTS=1
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_WARN=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_BIND_NOW=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_LIBRARY_VERSION=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_VERBOSE=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|/lib64/ld-linux-x86-64.so.2 ./lsnrctl
        linux-vdso.so.1 =>  (0x00007ffffd5e0000)
        libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1 (0x00007fe81c758000)
        libnnz11.so => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libnnz11.so (0x00007fe81c38a000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003799800000)
        libm.so.6 => /lib64/libm.so.6 (0x00000032cac00000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x000000379a000000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x000000379c400000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003799000000)
        libaio.so.1 => /usr/lib64/libaio.so.1 (0x00007fe81c187000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003798c00000)
Program=ldd LineNo=190 /usr/bin/ldd:|exit 0


--//注意看最后几行
Program=ldd LineNo=116 /usr/bin/ldd:try_trace|eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= 'LD_LIBRARY_VERSION=$verify_out' LD_VERBOSE= '"$@"'
Program=ldd LineNo=116 /usr/bin/ldd:try_trace|cat
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_TRACE_LOADED_OBJECTS=1
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_WARN=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_BIND_NOW=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_LIBRARY_VERSION=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|LD_VERBOSE=
PProgram=ldd LineNo=116 /usr/bin/ldd:try_trace|/lib64/ld-linux-x86-64.so.2 ./lsnrctl

--//感觉执行的是内容是:
eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION= LD_VERBOSE= /lib64/ld-linux-x86-64.so.2 ./lsnrctl

--//如果仔细看可以发现开始检查参数,给一下参数LD开头的赋值,然后执行如下:
eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION= LD_VERBOSE= /lib64/ld-linux-x86-64.so.2 ./lsnrctl

--//手工执行如下:
$ eval LD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW= LD_LIBRARY_VERSION= LD_VERBOSE= /lib64/ld-linux-x86-64.so.2 ./lsnrctl
        linux-vdso.so.1 =>  (0x00007fff2097b000)
        libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1 (0x00007f88c2549000)
        libnnz11.so => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libnnz11.so (0x00007f88c217b000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003799800000)
        libm.so.6 => /lib64/libm.so.6 (0x00000032cac00000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x000000379a000000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x000000379c400000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003799000000)
        libaio.so.1 => /usr/lib64/libaio.so.1 (0x00007f88c1f78000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003798c00000)

--//如果单独执行如下,直接执行程序:
$ /lib64/ld-linux-x86-64.so.2 ./lsnrctl
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-OCT-2021 15:23:45
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL>

$ eval  /lib64/ld-linux-x86-64.so.2 ./lsnrctl
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-OCT-2021 15:24:48
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL>

--//只要设置LD_TRACE_LOADED_OBJECTS的环境变量就可以执行,不需要赋值.
$ eval LD_TRACE_LOADED_OBJECTS=  /lib64/ld-linux-x86-64.so.2 ./lsnrctl
        linux-vdso.so.1 =>  (0x00007fffb93c1000)
        libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1 (0x00007f427e229000)
        libnnz11.so => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libnnz11.so (0x00007f427de5b000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003799800000)
        libm.so.6 => /lib64/libm.so.6 (0x00000032cac00000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x000000379a000000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x000000379c400000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003799000000)
        libaio.so.1 => /usr/lib64/libaio.so.1 (0x00007f427dc58000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003798c00000)

$ export LD_TRACE_LOADED_OBJECTS=
$ /lib64/ld-linux-x86-64.so.2 ./lsnrctl
        linux-vdso.so.1 =>  (0x00007fff2829c000)
        libclntsh.so.11.1 => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libclntsh.so.11.1 (0x00007f360edb5000)
        libnnz11.so => /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libnnz11.so (0x00007f360e9e7000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000003799800000)
        libm.so.6 => /lib64/libm.so.6 (0x00000032cac00000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x000000379a000000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x000000379c400000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003799000000)
        libaio.so.1 => /usr/lib64/libaio.so.1 (0x00007f360e7e4000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003798c00000)

$ unset LD_TRACE_LOADED_OBJECTS
$ /lib64/ld-linux-x86-64.so.2 ./lsnrctl
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-OCT-2021 15:29:31
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL>

$ LD_TRACE_LOADED_OBJECTS=1
$ /lib64/ld-linux-x86-64.so.2 ./lsnrctl
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-OCT-2021 15:29:55
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL>


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2795768/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    3048
  • 访问量
    6781969