免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3106 | 回复: 5
打印 上一主题 下一主题

请教程序连接执行的过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-25 23:29 |只看该作者 |倒序浏览
--------------a.c-------------

#include <unistd.h>
#include <string.h>

void a (char *s)
{

    write(1,s ,strlen(s));

}





--------------m.c-------------

extern void a (char *);

int main(char ac, char **av)
{

    static char string[]="hello world!\n";
    a(string);

}



arm-linux-gcc a.c m.c -o a.out

a.o的返汇编代码:
-----------------------a.objdump------------------


a.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <a>:
   0:        e1a0c00d         mov        ip, sp
   4:        e92dd800         stmdb        sp!, {fp, ip, lr, pc}

   8:        e24cb004         sub        fp, ip, #4        ; 0x4  
   c:        e24dd004         sub        sp, sp, #4        ; 0x4
  10:        e50b0010         str        r0, [fp, #-16]
  14:        e51b0010         ldr        r0, [fp, #-16]   //传入函数a的是一个字符串指针,这个指针放在r0中,先要把r0压栈
  18:        ebfffffe         bl        18 <a+0x18>      //调用strlen
  1c:        e1a03000         mov        r3, r0           //strlen的返回值放在r3中
  20:        e3a00001         mov        r0, #1        ; 0x1         // write的第一个参数1放在r0中
  24:        e51b1010         ldr        r1, [fp, #-16]   //字符串的地址放在r1中
  28:        e1a02003         mov        r2, r3           //字符串的长度放在r2中
  2c:        ebfffffe         bl        2c <a+0x2c>      //调用write函数

  30:        e89da808         ldmia        sp, {r3, fp, sp, pc}
Disassembly of section .comment:

00000000 <.comment>:
   0:        43434700         cmpmi        r3, #0        ; 0x0
   4:        4728203a         undefined
   8:        2029554e         eorcs        r5, r9, lr, asr #10
   c:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  10:        Address 0x10 is out of bounds.


m.o的返汇编代码:
--------------------m.objdump--------------------


m.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <main>:
   0:        e1a0c00d         mov        ip, sp
   4:        e92dd800         stmdb        sp!, {fp, ip, lr, pc}
   8:        e24cb004         sub        fp, ip, #4        ; 0x4

   c:        e24dd008         sub        sp, sp, #8        ; 0x8

  10:        e1a03000         mov        r3, r0  //char ac 放在r0中
  14:        e50b1014         str        r1, [fp, #-20] //char **av 放在r1中

  18:        e54b300d         strb        r3, [fp, #-13]
1c:        e59f000c         ldr        r0, [pc, #12]        ; 30 <.text+0x30>   //这里main调用函数a(char * )  ,传入r0的应该是字符串的地址,可这句话就是不懂!
  20:        ebfffffe         bl        20 <main+0x20>
  24:        e1a00003         mov        r0, r3
  28:        e24bd00c         sub        sp, fp, #12        ; 0xc
  2c:        e89da800         ldmia        sp, {fp, sp, pc}
  30:        00000000         andeq        r0, r0, r0
Disassembly of section .data:

00000000 <string.0>:
   0:        6c6c6568         cfstr64vs        mvdx6, [ip], #-416
   4:        6f77206f         swivs        0x0077206f
   8:        21646c72         cmncs        r4, r2, ror ip
   c:        0000000a         andeq        r0, r0, sl
Disassembly of section .comment:

00000000 <.comment>:
   0:        43434700         cmpmi        r3, #0        ; 0x0
   4:        4728203a         undefined
   8:        2029554e         eorcs        r5, r9, lr, asr #10
   c:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  10:        Address 0x10 is out of bounds.






  18:        e54b300d         strb        r3, [fp, #-13]
  1c:        e59f000c         ldr        r0, [pc, #12]        ; 30 <.text+0x30>
  20:        ebfffffe         bl        20 <main+0x20>
  24:        e1a00003         mov        r0, r3
  28:        e24bd00c         sub        sp, fp, #12        ; 0xc
  2c:        e89da800         ldmia        sp, {fp, sp, pc}
  30:        00000000         andeq        r0, r0, r0
Disassembly of section .data:

00000000 <string.0>:
   0:        6c6c6568         cfstr64vs        mvdx6, [ip], #-416
   4:        6f77206f         swivs        0x0077206f
   8:        21646c72         cmncs        r4, r2, ror ip
   c:        0000000a         andeq        r0, r0, sl
Disassembly of section .comment:

00000000 <.comment>:
   0:        43434700         cmpmi        r3, #0        ; 0x0
   4:        4728203a         undefined
   8:        2029554e         eorcs        r5, r9, lr, asr #10
   c:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  10:        Address 0x10 is out of bounds.

[ 本帖最后由 rocky1972 于 2008-6-25 23:34 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-06-25 23:31 |只看该作者
-------------------------a.out.objdump---------------------


a.out:     file format elf32-littlearm

Disassembly of section .interp://        This section holds the path name of a program interpreter.


000080f4 <.interp>:
    80f4:        62696c2f         rsbvs        r6, r9, #12032        ; 0x2f00
    80f8:        2d646c2f         stccsl        12, cr6, [r4, #-188]!
    80fc:        756e696c         strvcb        r6, [lr, #-2412]!
    8100:        6f732e78         swivs        0x00732e78
    8104:        Address 0x8104 is out of bounds.

Disassembly of section .note.ABI-tag:

00008108 <.note.ABI-tag>:
    8108:        00000004         andeq        r0, r0, r4
    810c:        00000010         andeq        r0, r0, r0, lsl r0
    8110:        00000001         andeq        r0, r0, r1
    8114:        00554e47         subeqs        r4, r5, r7, asr #28
    8118:        00000000         andeq        r0, r0, r0
    811c:        00000002         andeq        r0, r0, r2
    8120:        00000004         andeq        r0, r0, r4
    8124:        00000003         andeq        r0, r0, r3
Disassembly of section .hash:

The .hash section with type SHT_HASH holds a symbol hash table.

00008128 <.hash>:
    8128:        00000003         andeq        r0, r0, r3
    812c:        00000008         andeq        r0, r0, r8
    8130:        00000007         andeq        r0, r0, r7
    8134:        00000004         andeq        r0, r0, r4
    8138:        00000005         andeq        r0, r0, r5
        ...
    814c:        00000003         andeq        r0, r0, r3
    8150:        00000002         andeq        r0, r0, r2
    8154:        00000001         andeq        r0, r0, r1
    8158:        00000006         andeq        r0, r0, r6
Disassembly of section .dynsym:


        This section holds the dynamic linking symbol table, as "Symbol Table''
        describes. See Chapter 2 for more information.




0000815c <.dynsym>:
        ...
    816c:        00000034         andeq        r0, r0, r4, lsr r0
    8170:        000082d0         ldreqd        r8, [r0], -r0
    8174:        00000074         andeq        r0, r0, r4, ror r0
    8178:        00000012         andeq        r0, r0, r2, lsl r0
    817c:        0000002e         andeq        r0, r0, lr, lsr #32
    8180:        000082dc         ldreqd        r8, [r0], -ip
    8184:        000001fc         streqd        r0, [r0], -ip
    8188:        00000012         andeq        r0, r0, r2, lsl r0
    818c:        0000005b         andeq        r0, r0, fp, asr r0
    8190:        000082e8         andeq        r8, r0, r8, ror #5
    8194:        00000060         andeq        r0, r0, r0, rrx
    8198:        00000012         andeq        r0, r0, r2, lsl r0
    819c:        00000049         andeq        r0, r0, r9, asr #32
    81a0:        000082f4         streqd        r8, [r0], -r4
    81a4:        00000124         andeq        r0, r0, r4, lsr #2
    81a8:        00000012         andeq        r0, r0, r2, lsl r0
    81ac:        0000003a         andeq        r0, r0, sl, lsr r0
    81b0:        00008548         andeq        r8, r0, r8, asr #10
    81b4:        00000004         andeq        r0, r0, r4
    81b8:        000e0011         andeq        r0, lr, r1, lsl r0
    81bc:        00000001         andeq        r0, r0, r1
        ...
    81c8:        00000020         andeq        r0, r0, r0, lsr #32
    81cc:        00000015         andeq        r0, r0, r5, lsl r0
        ...
    81d8:        00000020         andeq        r0, r0, r0, lsr #32
Disassembly of section .dynstr:


        This section holds strings needed for dynamic linking, most commonly the
        strings that represent the names associated with symbol table entries. See
        Chapter 2 for more information.



000081dc <.dynstr>:
    81dc:        764a5f00         strvcb        r5, [sl], -r0, lsl #30
    81e0:        6765525f         undefined
    81e4:        65747369         ldrvsb        r7, [r4, #-873]!
    81e8:        616c4372         cmnvs        ip, r2, ror r3
    81ec:        73657373         cmnvc        r5, #-872415231        ; 0xcc000001
    81f0:        675f5f00         ldrvsb        r5, [pc, -r0, lsl #30]
    81f4:        5f6e6f6d         swipl        0x006e6f6d
    81f8:        72617473         rsbvc        r7, r1, #1929379840        ; 0x73000000
    81fc:        005f5f74         subeqs        r5, pc, r4, ror pc
    8200:        6362696c         cmnvs        r2, #1769472        ; 0x1b0000
    8204:        2e6f732e         cdpcs        3, 6, cr7, cr15, cr14, {1}
    8208:        62610036         rsbvs        r0, r1, #54        ; 0x36
    820c:        0074726f         rsbeqs        r7, r4, pc, ror #4
    8210:        74697277         strvcbt        r7, [r9], #-631
    8214:        495f0065         ldmmidb        pc, {r0, r2, r5, r6}^
    8218:        74735f4f         ldrvcbt        r5, [r3], #-3919
    821c:        5f6e6964         swipl        0x006e6964
    8220:        64657375         strvsbt        r7, [r5], #-885
    8224:        6c5f5f00         mrrcvs        15, 0, r5, pc, cr0
    8228:        5f636269         swipl        0x00636269
    822c:        72617473         rsbvc        r7, r1, #1929379840        ; 0x73000000
    8230:        616d5f74         cmnvs        sp, r4, ror pc
    8234:        73006e69         tstvc        r0, #1680        ; 0x690
    8238:        656c7274         strvsb        r7, [ip, #-628]!
    823c:        4c47006e         mcrrmi        0, 6, r0, r7, cr14
    8240:        5f434249         swipl        0x00434249
    8244:        00302e32         eoreqs        r2, r0, r2, lsr lr
Disassembly of section .gnu.version:

00008248 <.gnu.version>:
    8248:        00020000         andeq        r0, r2, r0
    824c:        00020002         andeq        r0, r2, r2
    8250:        00010002         andeq        r0, r1, r2
    8254:        00000000         andeq        r0, r0, r0
Disassembly of section .gnu.version_r:

00008258 <.gnu.version_r>:
    8258:        00010001         andeq        r0, r1, r1
    825c:        00000024         andeq        r0, r0, r4, lsr #32
    8260:        00000010         andeq        r0, r0, r0, lsl r0
    8264:        00000000         andeq        r0, r0, r0
    8268:        0d696910         stceql        9, cr6, [r9, #-64]!
    826c:        00020000         andeq        r0, r2, r0
    8270:        00000062         andeq        r0, r0, r2, rrx
    8274:        00000000         andeq        r0, r0, r0
Disassembly of section .rel.dyn:

00008278 <.rel.dyn>:
    8278:        00010668         andeq        r0, r1, r8, ror #12
    827c:        00000715         andeq        r0, r0, r5, lsl r7
Disassembly of section .rel.plt:

00008280 <.rel.plt>:
    8280:        00010654         andeq        r0, r1, r4, asr r6
    8284:        00000116         andeq        r0, r0, r6, lsl r1
    8288:        00010658         andeq        r0, r1, r8, asr r6
    828c:        00000216         andeq        r0, r0, r6, lsl r2
    8290:        0001065c         andeq        r0, r1, ip, asr r6
    8294:        00000316         andeq        r0, r0, r6, lsl r3
    8298:        00010660         andeq        r0, r1, r0, ror #12
    829c:        00000416         andeq        r0, r0, r6, lsl r4
    82a0:        00010664         andeq        r0, r1, r4, ror #12
    82a4:        00000616         andeq        r0, r0, r6, lsl r6
Disassembly of section .init:

      This section holds executable instructions that contribute to the process
      initialization code. When a program starts to run, the system executes the
      code in this section before calling the main program entry point (called
      main for C programs).


000082a8 <_init>:
    82a8:        e52de004         str        lr, [sp, #-4]!
    82ac:        eb000024         bl        8344 <call_gmon_start>
    82b0:        eb000046         bl        83d0 <frame_dummy>
    82b4:        eb000090         bl        84fc <__do_global_ctors_aux>
    82b8:        e49df004         ldr        pc, [sp], #4
Disassembly of section .plt:

The .got and .plt sections with type SHT_PROGBITS hold two separate tables: the global
offset table and the procedure linkage table. Programs use the global offset table for
position-independent code.




000082bc <.plt>:
    82bc:        e52de004         str        lr, [sp, #-4]!
    82c0:        e59fe004         ldr        lr, [pc, #4]        ; 82cc <.plt+0x10>
    82c4:        e08fe00e         add        lr, pc, lr
    82c8:        e5bef008         ldr        pc, [lr, #8]!
    82cc:        0000837c         andeq        r8, r0, ip, ror r3
    82d0:        e28fc600         add        ip, pc, #0        ; 0x0
    82d4:        e28cca08         add        ip, ip, #32768        ; 0x8000
    82d8:        e5bcf37c         ldr        pc, [ip, #892]!
    82dc:        e28fc600         add        ip, pc, #0        ; 0x0
    82e0:        e28cca08         add        ip, ip, #32768        ; 0x8000
    82e4:        e5bcf374         ldr        pc, [ip, #884]!
    82e8:        e28fc600         add        ip, pc, #0        ; 0x0
    82ec:        e28cca08         add        ip, ip, #32768        ; 0x8000
    82f0:        e5bcf36c         ldr        pc, [ip, #876]!
    82f4:        e28fc600         add        ip, pc, #0        ; 0x0
    82f8:        e28cca08         add        ip, ip, #32768        ; 0x8000
    82fc:        e5bcf364         ldr        pc, [ip, #868]!
    8300:        e28fc600         add        ip, pc, #0        ; 0x0
    8304:        e28cca08         add        ip, ip, #32768        ; 0x8000
    8308:        e5bcf35c         ldr        pc, [ip, #860]!
Disassembly of section .text:

0000830c <_start>:
    830c:        e59fc024         ldr        ip, [pc, #36]        ; 8338 <_start+0x2c>
    8310:        e3a0b000         mov        fp, #0        ; 0x0
    8314:        e49d1004         ldr        r1, [sp], #4
    8318:        e1a0200d         mov        r2, sp
    831c:        e52d2004         str        r2, [sp, #-4]!
    8320:        e52d0004         str        r0, [sp, #-4]!
    8324:        e59f0010         ldr        r0, [pc, #16]        ; 833c <_start+0x30>
    8328:        e59f3010         ldr        r3, [pc, #16]        ; 8340 <_start+0x34>
    832c:        e52dc004         str        ip, [sp, #-4]!
    8330:        ebffffef         bl        82f4 <.text-0x18>
    8334:        ebffffe8         bl        82dc <.text-0x30>
    8338:        000084b4         streqh        r8, [r0], -r4
    833c:        00008434         andeq        r8, r0, r4, lsr r4
    8340:        00008468         andeq        r8, r0, r8, ror #8

00008344 <call_gmon_start>:
    8344:        e92d4400         stmdb        sp!, {sl, lr}
    8348:        e59fa01c         ldr        sl, [pc, #28]        ; 836c <.text+0x60>
    834c:        e08fa00a         add        sl, pc, sl
    8350:        e59f3018         ldr        r3, [pc, #24]        ; 8370 <.text+0x64>
    8354:        e79a3003         ldr        r3, [sl, r3]
    8358:        e3530000         cmp        r3, #0        ; 0x0
    835c:        08bd8400         ldmeqia        sp!, {sl, pc}
    8360:        e1a0e00f         mov        lr, pc
    8364:        e1a0f003         mov        pc, r3
    8368:        e8bd8400         ldmia        sp!, {sl, pc}
    836c:        000082f4         streqd        r8, [r0], -r4
    8370:        00000020         andeq        r0, r0, r0, lsr #32

00008374 <__do_global_dtors_aux>:
    8374:        e92d4030         stmdb        sp!, {r4, r5, lr}

    8378:        e59f5040         ldr        r5, [pc, #64]        ; 83c0 <.text+0xb4>
    837c:        e5d53000         ldrb        r3, [r5]
    8380:        e3530000         cmp        r3, #0        ; 0x0
    8384:        18bd8030         ldmneia        sp!, {r4, r5, pc}
    8388:        e59f4034         ldr        r4, [pc, #52]        ; 83c4 <.text+0xb8>
    838c:        ea000004         b        83a4 <__do_global_dtors_aux+0x30>
    8390:        e5943000         ldr        r3, [r4]
    8394:        e2833004         add        r3, r3, #4        ; 0x4
    8398:        e5843000         str        r3, [r4]
    839c:        e1a0e00f         mov        lr, pc
    83a0:        e1a0f002         mov        pc, r2
    83a4:        e5943000         ldr        r3, [r4]
    83a8:        e5932000         ldr        r2, [r3]
    83ac:        e3520000         cmp        r2, #0        ; 0x0
    83b0:        1afffff6         bne        8390 <__do_global_dtors_aux+0x1c>
    83b4:        e3a03001         mov        r3, #1        ; 0x1
    83b8:        e5c53000         strb        r3, [r5]
    83bc:        e8bd8030         ldmia        sp!, {r4, r5, pc}
    83c0:        0001066c         andeq        r0, r1, ip, ror #12
    83c4:        00010554         andeq        r0, r1, r4, asr r5

000083c8 <call___do_global_dtors_aux>:
    83c8:        e52de004         str        lr, [sp, #-4]!
    83cc:        e49df004         ldr        pc, [sp], #4

000083d0 <frame_dummy>:
    83d0:        e59f0018         ldr        r0, [pc, #24]        ; 83f0 <.text+0xe4>
    83d4:        e5903000         ldr        r3, [r0]
    83d8:        e3530000         cmp        r3, #0        ; 0x0
    83dc:        01a0f00e         moveq        pc, lr
    83e0:        e59f300c         ldr        r3, [pc, #12]        ; 83f4 <.text+0xe8>
    83e4:        e3530000         cmp        r3, #0        ; 0x0
    83e8:        01a0f00e         moveq        pc, lr
    83ec:        eaffffc3         b        8300 <.text-0xc>
    83f0:        00010644         andeq        r0, r1, r4, asr #12
    83f4:        00000000         andeq        r0, r0, r0

000083f8 <call_frame_dummy>:
    83f8:        e52de004         str        lr, [sp, #-4]!
    83fc:        e49df004         ldr        pc, [sp], #4

00008400 <a>:
    8400:        e1a0c00d         mov        ip, sp
    8404:        e92dd800         stmdb        sp!, {fp, ip, lr, pc}
    8408:        e24cb004         sub        fp, ip, #4        ; 0x4
    840c:        e24dd004         sub        sp, sp, #4        ; 0x4
    8410:        e50b0010         str        r0, [fp, #-16]
    8414:        e51b0010         ldr        r0, [fp, #-16]
    8418:        ebffffb2         bl        82e8 <.text-0x24>
    841c:        e1a03000         mov        r3, r0
    8420:        e3a00001         mov        r0, #1        ; 0x1
    8424:        e51b1010         ldr        r1, [fp, #-16]
    8428:        e1a02003         mov        r2, r3
    842c:        ebffffa7         bl        82d0 <.text-0x3c>
    8430:        e89da808         ldmia        sp, {r3, fp, sp, pc}

00008434 <main>:
    8434:        e1a0c00d         mov        ip, sp
    8438:        e92dd800         stmdb        sp!, {fp, ip, lr, pc}
    843c:        e24cb004         sub        fp, ip, #4        ; 0x4
    8440:        e24dd008         sub        sp, sp, #8        ; 0x8
    8444:        e1a03000         mov        r3, r0
    8448:        e50b1014         str        r1, [fp, #-20]
    844c:        e54b300d         strb        r3, [fp, #-13]
    8450:        e59f000c         ldr        r0, [pc, #12]        ; 8464 <.text+0x158>
    8454:        ebffffe9         bl        8400 <a> //8400这个地址是00008400 <a>:,这个很容易看懂,就是main调用a的时候pc会调到8400这个位置执行
    8458:        e1a00003         mov        r0, r3
    845c:        e24bd00c         sub        sp, fp, #12        ; 0xc
    8460:        e89da800         ldmia        sp, {fp, sp, pc}
    8464:        00010558         andeq        r0, r1, r8, asr r5

00008468 <__libc_csu_init>:
    8468:        e92d4070         stmdb        sp!, {r4, r5, r6, lr}
    846c:        ebffff8d         bl        82a8 <_init>
    8470:        e3a04000         mov        r4, #0        ; 0x0
    8474:        e59f3030         ldr        r3, [pc, #48]        ; 84ac <.text+0x1a0>
    8478:        e59f2030         ldr        r2, [pc, #48]        ; 84b0 <.text+0x1a4>
    847c:        e0623003         rsb        r3, r2, r3
    8480:        e1540143         cmp        r4, r3, asr #2
    8484:        28bd8070         ldmcsia        sp!, {r4, r5, r6, pc}
    8488:        e1a06002         mov        r6, r2
    848c:        e59f3018         ldr        r3, [pc, #24]        ; 84ac <.text+0x1a0>
    8490:        e0625003         rsb        r5, r2, r3
    8494:        e1a0e00f         mov        lr, pc
    8498:        e796f104         ldr        pc, [r6, r4, lsl #2]
    849c:        e2844001         add        r4, r4, #1        ; 0x1
    84a0:        e1540145         cmp        r4, r5, asr #2
    84a4:        3afffffa         bcc        8494 <__libc_csu_init+0x2c>
    84a8:        e8bd8070         ldmia        sp!, {r4, r5, r6, pc}
    84ac:        0001054c         andeq        r0, r1, ip, asr #10
    84b0:        0001054c         andeq        r0, r1, ip, asr #10

000084b4 <__libc_csu_fini>:
    84b4:        e92d4030         stmdb        sp!, {r4, r5, lr}
    84b8:        e59f2034         ldr        r2, [pc, #52]        ; 84f4 <.text+0x1e8>
    84bc:        e59f3034         ldr        r3, [pc, #52]        ; 84f8 <.text+0x1ec>
    84c0:        e0634002         rsb        r4, r3, r2
    84c4:        e1a04144         mov        r4, r4, asr #2
    84c8:        e2444001         sub        r4, r4, #1        ; 0x1
    84cc:        e3740001         cmn        r4, #1        ; 0x1
    84d0:        0a000005         beq        84ec <__libc_csu_fini+0x38>
    84d4:        e1a05003         mov        r5, r3
    84d8:        e1a0e00f         mov        lr, pc
    84dc:        e795f104         ldr        pc, [r5, r4, lsl #2]
    84e0:        e2444001         sub        r4, r4, #1        ; 0x1
    84e4:        e3740001         cmn        r4, #1        ; 0x1
    84e8:        1afffffa         bne        84d8 <__libc_csu_fini+0x24>
    84ec:        eb000012         bl        853c <_fini>
    84f0:        e8bd8030         ldmia        sp!, {r4, r5, pc}
    84f4:        0001054c         andeq        r0, r1, ip, asr #10
    84f8:        0001054c         andeq        r0, r1, ip, asr #10

000084fc <__do_global_ctors_aux>:
    84fc:        e92d4010         stmdb        sp!, {r4, lr}
    8500:        e59f3028         ldr        r3, [pc, #40]        ; 8530 <.text+0x224>
    8504:        e2434004         sub        r4, r3, #4        ; 0x4
    8508:        e5132004         ldr        r2, [r3, #-4]
    850c:        e3720001         cmn        r2, #1        ; 0x1
    8510:        08bd8010         ldmeqia        sp!, {r4, pc}
    8514:        e1a03002         mov        r3, r2
    8518:        e1a0e00f         mov        lr, pc
    851c:        e1a0f003         mov        pc, r3
    8520:        e5343004         ldr        r3, [r4, #-4]!
    8524:        e3730001         cmn        r3, #1        ; 0x1
    8528:        1afffffa         bne        8518 <__do_global_ctors_aux+0x1c>
    852c:        e8bd8010         ldmia        sp!, {r4, pc}
    8530:        00010638         andeq        r0, r1, r8, lsr r6

00008534 <call___do_global_ctors_aux>:
    8534:        e52de004         str        lr, [sp, #-4]!
    8538:        e49df004         ldr        pc, [sp], #4

Disassembly of section .fini:

      This section holds executable instructions that contribute to the process
      termination code. When a program exits normally, the system executes the
      code in this section.


0000853c <_fini>:
    853c:        e52de004         str        lr, [sp, #-4]!
    8540:        ebffff8b         bl        8374 <__do_global_dtors_aux>
    8544:        e49df004         ldr        pc, [sp], #4
Disassembly of section .rodata:

00008548 <_IO_stdin_used>:
    8548:        00020001         andeq        r0, r2, r1
Disassembly of section .data:

0001054c <__data_start>:
   1054c:        00000000         andeq        r0, r0, r0

00010550 <__dso_handle>:
   10550:        00000000         andeq        r0, r0, r0

00010554 <p.0>:
   10554:        00010640         andeq        r0, r1, r0, asr #12

00010558 <string.0>:
   10558:        6c6c6568         cfstr64vs        mvdx6, [ip], #-416
   1055c:        6f77206f         swivs        0x0077206f
   10560:        21646c72         cmncs        r4, r2, ror ip
   10564:        0000000a         andeq        r0, r0, sl
Disassembly of section .eh_frame:

00010568 <__FRAME_END__>:
   10568:        00000000         andeq        r0, r0, r0
Disassembly of section .dynamic:

0001056c <_DYNAMIC>:
   1056c:        00000001         andeq        r0, r0, r1
   10570:        00000024         andeq        r0, r0, r4, lsr #32
   10574:        0000000c         andeq        r0, r0, ip
   10578:        000082a8         andeq        r8, r0, r8, lsr #5
   1057c:        0000000d         andeq        r0, r0, sp
   10580:        0000853c         andeq        r8, r0, ip, lsr r5
   10584:        00000004         andeq        r0, r0, r4
   10588:        00008128         andeq        r8, r0, r8, lsr #2
   1058c:        00000005         andeq        r0, r0, r5
   10590:        000081dc         ldreqd        r8, [r0], -ip
   10594:        00000006         andeq        r0, r0, r6
   10598:        0000815c         andeq        r8, r0, ip, asr r1
   1059c:        0000000a         andeq        r0, r0, sl
   105a0:        0000006c         andeq        r0, r0, ip, rrx
   105a4:        0000000b         andeq        r0, r0, fp
   105a8:        00000010         andeq        r0, r0, r0, lsl r0
   105ac:        00000015         andeq        r0, r0, r5, lsl r0
   105b0:        00000000         andeq        r0, r0, r0
   105b4:        00000003         andeq        r0, r0, r3
   105b8:        00010648         andeq        r0, r1, r8, asr #12
   105bc:        00000002         andeq        r0, r0, r2
   105c0:        00000028         andeq        r0, r0, r8, lsr #32
   105c4:        00000014         andeq        r0, r0, r4, lsl r0
   105c8:        00000011         andeq        r0, r0, r1, lsl r0
   105cc:        00000017         andeq        r0, r0, r7, lsl r0
   105d0:        00008280         andeq        r8, r0, r0, lsl #5
   105d4:        00000011         andeq        r0, r0, r1, lsl r0
   105d8:        00008278         andeq        r8, r0, r8, ror r2
   105dc:        00000012         andeq        r0, r0, r2, lsl r0
   105e0:        00000008         andeq        r0, r0, r8
   105e4:        00000013         andeq        r0, r0, r3, lsl r0
   105e8:        00000008         andeq        r0, r0, r8
   105ec:        6ffffffe         swivs        0x00fffffe
   105f0:        00008258         andeq        r8, r0, r8, asr r2
   105f4:        6fffffff         swivs        0x00ffffff
   105f8:        00000001         andeq        r0, r0, r1
   105fc:        6ffffff0         swivs        0x00fffff0
   10600:        00008248         andeq        r8, r0, r8, asr #4
        ...
Disassembly of section .ctors:

00010634 <__CTOR_LIST__>:
   10634:        ffffffff         swinv        0x00ffffff

00010638 <__CTOR_END__>:
   10638:        00000000         andeq        r0, r0, r0
Disassembly of section .dtors:

0001063c <__DTOR_LIST__>:
   1063c:        ffffffff         swinv        0x00ffffff

00010640 <__DTOR_END__>:
   10640:        00000000         andeq        r0, r0, r0
Disassembly of section .jcr:

00010644 <__JCR_END__>:
   10644:        00000000         andeq        r0, r0, r0


Disassembly of section .got:


The .got and .plt sections with type SHT_PROGBITS hold two separate tables: the global
offset table and the procedure linkage table. Programs use the global offset table for
position-independent code.



00010648 <_GLOBAL_OFFSET_TABLE_>:
   10648:        0001056c         andeq        r0, r1, ip, ror #10
        ...
   10654:        000082bc         streqh        r8, [r0], -ip
   10658:        000082bc         streqh        r8, [r0], -ip
   1065c:        000082bc         streqh        r8, [r0], -ip
   10660:        000082bc         streqh        r8, [r0], -ip
   10664:        000082bc         streqh        r8, [r0], -ip
   10668:        00000000         andeq        r0, r0, r0
Disassembly of section .bss:

0001066c <completed.1>:
   1066c:        00000000         andeq        r0, r0, r0
Disassembly of section .comment:

00000000 <.comment>:
   0:        43434700         cmpmi        r3, #0        ; 0x0
   4:        4728203a         undefined
   8:        2029554e         eorcs        r5, r9, lr, asr #10
   c:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  10:        47000031         smladxmi        r0, r1, r0, r0
  14:        203a4343         eorcss        r4, sl, r3, asr #6
  18:        554e4728         strplb        r4, [lr, #-1832]
  1c:        2e332029         cdpcs        0, 3, cr2, cr3, cr9, {1}
  20:        00312e34         eoreqs        r2, r1, r4, lsr lr
  24:        43434700         cmpmi        r3, #0        ; 0x0
  28:        4728203a         undefined
  2c:        2029554e         eorcs        r5, r9, lr, asr #10
  30:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  34:        47000031         smladxmi        r0, r1, r0, r0
  38:        203a4343         eorcss        r4, sl, r3, asr #6
  3c:        554e4728         strplb        r4, [lr, #-1832]
  40:        2e332029         cdpcs        0, 3, cr2, cr3, cr9, {1}
  44:        00312e34         eoreqs        r2, r1, r4, lsr lr
  48:        43434700         cmpmi        r3, #0        ; 0x0
  4c:        4728203a         undefined
  50:        2029554e         eorcs        r5, r9, lr, asr #10
  54:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  58:        47000031         smladxmi        r0, r1, r0, r0
  5c:        203a4343         eorcss        r4, sl, r3, asr #6
  60:        554e4728         strplb        r4, [lr, #-1832]
  64:        2e332029         cdpcs        0, 3, cr2, cr3, cr9, {1}
  68:        00312e34         eoreqs        r2, r1, r4, lsr lr
  6c:        43434700         cmpmi        r3, #0        ; 0x0
  70:        4728203a         undefined
  74:        2029554e         eorcs        r5, r9, lr, asr #10
  78:        2e342e33         mrccs        14, 1, r2, cr4, cr3, {1}
  7c:        47000031         smladxmi        r0, r1, r0, r0
  80:        203a4343         eorcss        r4, sl, r3, asr #6
  84:        554e4728         strplb        r4, [lr, #-1832]
  88:        2e332029         cdpcs        0, 3, cr2, cr3, cr9, {1}
  8c:        00312e34         eoreqs        r2, r1, r4, lsr lr

[ 本帖最后由 rocky1972 于 2008-6-25 23:39 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-06-25 23:32 |只看该作者
啥意思?

论坛徽章:
0
4 [报告]
发表于 2008-06-25 23:32 |只看该作者
用gcc编译后用strace 查看a.out执行过程的细节:
root@rocky1972-laptop:~/work/c_src# gcc a.c m.c
root@rocky1972-laptop:~/work/c_src# strace ./a.out
execve("./a.out", ["./a.out"], [/* 37 vars */]) = 0
brk(0)                                  = 0x804a000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fd7000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=59049, ...}) = 0
mmap2(NULL, 59049, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fc8000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260e\1"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1364388, ...}) = 0
mmap2(NULL, 1369712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7e79000
mmap2(0xb7fc2000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x149) = 0xb7fc2000
mmap2(0xb7fc5000, 9840, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7fc5000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7e78000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7e786b0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xb7fc2000, 4096, PROT_READ)   = 0
munmap(0xb7fc8000, 59049)               = 0
write(1, "hello world!\n", 13hello world!
)          = 13
exit_group(13)                          = ?
Process 6416 detached
root@rocky1972-laptop:~/work/c_src#

论坛徽章:
0
5 [报告]
发表于 2008-06-25 23:41 |只看该作者
原帖由 mik 于 2008-6-25 23:32 发表
啥意思?



小弟不懂程序是怎么编译、连接、执行的,看了elf、连接器和加载器的文档后不是很懂,想从实际代码的角度去理解,把用strace得到的结果和返汇编代码结合起来;
还有elf格式和纯二进制bin文件的转换原理。


请教一个各位大牛们,有没有好的入手方法和资料来理解这些东西。

[ 本帖最后由 rocky1972 于 2008-6-25 23:47 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2008-06-26 11:03 |只看该作者
虚心求教,顶一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP