⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1028.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 3 页
字号:
[alert7@redhat62 alert7]$ gcc -fomit-frame-pointer -o test test.c<br>
[alert7@redhat62 alert7]$ wc -c test<br>
11773 test<br>
[alert7@redhat62 alert7]$ gdb -q test<br>
(gdb) disass main<br>
Dump of assembler code for function main:<br>
0x80483e0 : call 0x80483d0<br>
0x80483e5 : xor %eax,%eax<br>
0x80483e7 : jmp 0x80483f0<br>
0x80483e9 : lea 0x0(%esi,1),%esi<br>
0x80483f0 : ret<br>
....<br>
End of assembler dump.<br>
(gdb) disass hi<br>
Dump of assembler code for function hi:<br>
0x80483d0 : push $0x8048450<br>
0x80483d5 : call 0x8048308<br>
0x80483da : add $0x4,%esp<br>
0x80483dd : ret<br>
0x80483de : mov %esi,%esi<br>
End of assembler dump.<br>
在main()和hi()中都去掉了以下指令<br>
push %ebp<br>
mov %esp,%ebp//这两条指令安装<br>
leave//这条指令恢复<br>
来看看部分的内存映象<br>
(内存高址)<br>
+--------+<br>
|bffffbc4| argv的地址(即argv[0]的地址)<br>
0xbffffb84 +--------+<br>
|00000001| argc的值<br>
0xbffffb80 +--------+<br>
|400309cb|main的返回地址<br>
0xbffffb7c +--------+<br>
|080483e5| hi()的返回地址<br>
0xbffffb78 +--------+<br>
|08048450| "hi"字符串的地址<br>
0xbffffb74 +--------+<br>
| ...... |<br>
(内存低址)<br>
没有保存上层执行环境的ebp.<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
-fomit-frame-pointer && -O2<br>
<br>
★ -fomit-frame-pointer && -O2<br>
-fomit-frame-pointer编译选项去掉了<br>
push %ebp<br>
mov %esp,%ebp//这两条指令安装<br>
leave//这条指令恢复<br>
-O2编译选项去掉了<br>
add $0x4,%esp<br>
两个加起来会不会这四条指令一起去掉,从而使stack不平衡呢?<br>
[alert7@redhat62 alert7]$ gcc -fomit-frame-pointer -O2 -o test test.c<br>
[alert7@redhat62 alert7]$ wc -c test<br>
11741 test<br>
[alert7@redhat62 alert7]$ gdb -q test<br>
(gdb) disass main<br>
Dump of assembler code for function main:<br>
0x80483d8 : call 0x80483c8<br>
0x80483dd : xor %eax,%eax<br>
0x80483df : ret<br>
End of assembler dump.<br>
(gdb) disass hi<br>
Dump of assembler code for function hi:<br>
0x80483c8 : push $0x8048430<br>
0x80483cd : call 0x8048308<br>
0x80483d2 : add $0x4,%esp<br>
0x80483d5 : ret<br>
0x80483d6 : mov %esi,%esi<br>
End of assembler dump.<br>
来看看部分的内存映象<br>
(内存高址)<br>
+--------+<br>
|bffffbc4| argv的地址(即argv[0]的地址)<br>
0xbffffb84 +--------+<br>
|00000001| argc的值<br>
0xbffffb80 +--------+<br>
|400309cb|main的返回地址<br>
0xbffffb7c +--------+<br>
|080483dd| hi()的返回地址<br>
0xbffffb78 +--------+<br>
|08048430| "hi"字符串的地址<br>
0xbffffb74 +--------+<br>
| ...... |<br>
(内存低址)<br>
此时就没有把add $0x4,%esp优化掉,如果优化掉的话,整个stack就<br>
会变的不平衡,从而会导致程序出错。<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
-fPIC 编译选项<br>
<br>
★ -fPIC 编译选项<br>
-fPIC If supported for the target machine, emit position-independent<br>
code, suitable for dynamic linking,even if branches need large<br>
displacements.<br>
产生位置无关代码(PIC),一般创建共享库时用到。<br>
在x86上,PIC的代码的符号引用都是通过ebx进行操作的。<br>
<br>
[alert7@redhat62 alert7]$ gcc -fPIC -o test test.c<br>
[alert7@redhat62 alert7]$ wc -c test<br>
11805 test<br>
[alert7@redhat62 alert7]$ gdb -q test<br>
(gdb) disass main<br>
Dump of assembler code for function main:<br>
0x80483f8 : push %ebp<br>
0x80483f9 : mov %esp,%ebp<br>
0x80483fb : push %ebx<br>
0x80483fc : call 0x8048401<br>
0x8048401 : pop %ebx//取得该指令的地址<br>
0x8048402 : add $0x1093,%ebx//此时ebx里面存放着是GOT表的地址<br>
0x8048408 : call 0x80483d0<br>
0x804840d : xor %eax,%eax<br>
0x804840f : jmp 0x8048411<br>
0x8048411 : mov 0xfffffffc(%ebp),%ebx<br>
0x8048414 : leave<br>
0x8048415 : ret<br>
...<br>
End of assembler dump.<br>
(gdb) disass hi<br>
Dump of assembler code for function hi:<br>
0x80483d0 : push %ebp<br>
0x80483d1 : mov %esp,%ebp<br>
0x80483d3 : push %ebx<br>
0x80483d4 : call 0x80483d9<br>
0x80483d9 : pop %ebx<br>
0x80483da : add $0x10bb,%ebx<br>
0x80483e0 : lea 0xffffefdc(%ebx),%edx<br>
0x80483e6 : mov %edx,%eax<br>
0x80483e8 : push %eax<br>
0x80483e9 : call 0x8048308<br>
0x80483ee : add $0x4,%esp<br>
0x80483f1 : mov 0xfffffffc(%ebp),%ebx<br>
0x80483f4 : leave<br>
0x80483f5 : ret<br>
0x80483f6 : mov %esi,%esi<br>
End of assembler dump.<br>
来看看部分的内存映象<br>
<br>
(内存高址)<br>
+--------+<br>
|bffffbc4| argv的地址(即argv[0]的地址)<br>
0xbffffb84 +--------+<br>
|00000001| argc的值<br>
0xbffffb80 +--------+<br>
|400309cb|main的返回地址<br>
0xbffffb7c +--------+ &lt;-- 调用main函数前的esp<br>
|bffffb98| 调用main函数前的ebp<br>
0xbffffb78 +--------+ &lt;-- main函数的ebp<br>
|401081ec| 保存的ebx<br>
0xbffffb74 +--------+<br>
|0804840d| (存放过call 0x8048401的下一条指令地址)<br>
0xbffffb70 +--------+<br>
|bffffb78| 调用hi()前的esp<br>
0xbffffb6c +--------+<br>
|08049494| GOT表地址<br>
0xbffffb68 +--------+<br>
|08048470|(存放过call 0x80483d9的下一条指令地址)<br>
0xbffffb64 +--------+<br>
| ...... |<br>
(内存低址)<br>
<br>
<br>
<br>
[目录]<br>
<br>
--------------------------------------------------------------------------------<br>
<br>
<br>
-static 编译选项<br>
<br>
★ -static 编译选项<br>
-static<br>
On systems that support dynamic linking, this prevents<br>
linking with the shared libraries. On other systems,<br>
this option has no effect.<br>
把一些函数都静态的编译到程序中,而无需动态链接了。<br>
[alert7@redhat62 alert7]$ gcc -o test -static test.c<br>
[alert7@redhat62 alert7]$ wc -c test<br>
962808 test<br>
[alert7@redhat62 alert7]$ gdb -q test<br>
(gdb) disass main<br>
Dump of assembler code for function main:<br>
0x80481b4 : push %ebp<br>
0x80481b5 : mov %esp,%ebp<br>
0x80481b7 : call 0x80481a0<br>
0x80481bc : xor %eax,%eax<br>
0x80481be : jmp 0x80481c0<br>
0x80481c0 : leave<br>
0x80481c1 : ret<br>
...<br>
End of assembler dump.<br>
(gdb) disass hi<br>
Dump of assembler code for function hi:<br>
0x80481a0 : push %ebp<br>
0x80481a1 : mov %esp,%ebp<br>
0x80481a3 : push $0x8071528<br>
0x80481a8 : call 0x804865c<br>
0x80481ad : add $0x4,%esp<br>
0x80481b0 : leave<br>
0x80481b1 : ret<br>
0x80481b2 : mov %esi,%esi<br>
End of assembler dump.<br>
[alert7@redhat62 alert7]$ ldd test<br>
not a dynamic executable<br>
-static出来的代码已经没有PLT了,GOT虽然有,已经全部为0了。<br>
<br>
<br>
<br>
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -