Merry Christmas Phil, If the standard libraries are linked statically with a Linux C program, why the whole library is not linked with our program? I saw the final object code, it is not big, it probably shows that the definition of some functions have been added to my program. When i link some other libraries the whole functions of that library are added completely but for the standard library only a few functions are added?!! How? My prog1.c is a simple printf: ------------------------------------------ main(){ printf("kkkkkkkk\n"); } ------------------------------------------ objdump -d ./prog1 ./prog1: file format elf32-i386 Disassembly of section .init: 08048290 <_init>: 8048290: 55 push %ebp 8048291: 89 e5 mov %esp,%ebp 8048293: 53 push %ebx 8048294: 83 ec 04 sub $0x4,%esp 8048297: e8 00 00 00 00 call 804829c <_init+0xc> 804829c: 5b pop %ebx 804829d: 81 c3 68 13 00 00 add $0x1368,%ebx 80482a3: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx 80482a9: 85 d2 test %edx,%edx 80482ab: 74 05 je 80482b2 <_init+0x22> 80482ad: e8 1e 00 00 00 call 80482d0 <__gmon_start__@plt> 80482b2: e8 d9 00 00 00 call 8048390 <frame_dummy> 80482b7: e8 84 01 00 00 call 8048440 <__do_global_ctors_aux> 80482bc: 58 pop %eax 80482bd: 5b pop %ebx 80482be: c9 leave 80482bf: c3 ret Disassembly of section .plt: 080482c0 <__gmon_start__@plt-0x10>: 80482c0: ff 35 08 96 04 08 pushl 0x8049608 80482c6: ff 25 0c 96 04 08 jmp *0x804960c 80482cc: 00 00 add %al,(%eax) ... 080482d0 <__gmon_start__@plt>: 80482d0: ff 25 10 96 04 08 jmp *0x8049610 80482d6: 68 00 00 00 00 push $0x0 80482db: e9 e0 ff ff ff jmp 80482c0 <_init+0x30> 080482e0 <__libc_start_main@plt>: 80482e0: ff 25 14 96 04 08 jmp *0x8049614 80482e6: 68 08 00 00 00 push $0x8 80482eb: e9 d0 ff ff ff jmp 80482c0 <_init+0x30> 080482f0 <puts@plt>: 80482f0: ff 25 18 96 04 08 jmp *0x8049618 80482f6: 68 10 00 00 00 push $0x10 80482fb: e9 c0 ff ff ff jmp 80482c0 <_init+0x30> Disassembly of section .text: 08048300 <_start>: 8048300: 31 ed xor %ebp,%ebp 8048302: 5e pop %esi 8048303: 89 e1 mov %esp,%ecx 8048305: 83 e4 f0 and $0xfffffff0,%esp 8048308: 50 push %eax 8048309: 54 push %esp 804830a: 52 push %edx 804830b: 68 d0 83 04 08 push $0x80483d0 8048310: 68 e0 83 04 08 push $0x80483e0 8048315: 51 push %ecx 8048316: 56 push %esi 8048317: 68 b4 83 04 08 push $0x80483b4 804831c: e8 bf ff ff ff call 80482e0 <__libc_start_main@plt> 8048321: f4 hlt 8048322: 90 nop 8048323: 90 nop 8048324: 90 nop 8048325: 90 nop 8048326: 90 nop 8048327: 90 nop 8048328: 90 nop 8048329: 90 nop 804832a: 90 nop 804832b: 90 nop 804832c: 90 nop 804832d: 90 nop 804832e: 90 nop 804832f: 90 nop 08048330 <__do_global_dtors_aux>: 8048330: 55 push %ebp 8048331: 89 e5 mov %esp,%ebp 8048333: 53 push %ebx 8048334: 8d 64 24 fc lea -0x4(%esp),%esp 8048338: 80 3d 20 96 04 08 00 cmpb $0x0,0x8049620 804833f: 75 3e jne 804837f <__do_global_dtors_aux+0x4f> 8048341: bb 30 95 04 08 mov $0x8049530,%ebx 8048346: a1 24 96 04 08 mov 0x8049624,%eax 804834b: 81 eb 2c 95 04 08 sub $0x804952c,%ebx 8048351: c1 fb 02 sar $0x2,%ebx 8048354: 83 eb 01 sub $0x1,%ebx 8048357: 39 d8 cmp %ebx,%eax 8048359: 73 1d jae 8048378 <__do_global_dtors_aux+0x48> 804835b: 90 nop 804835c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 8048360: 83 c0 01 add $0x1,%eax 8048363: a3 24 96 04 08 mov %eax,0x8049624 8048368: ff 14 85 2c 95 04 08 call *0x804952c(,%eax,4) 804836f: a1 24 96 04 08 mov 0x8049624,%eax 8048374: 39 d8 cmp %ebx,%eax 8048376: 72 e8 jb 8048360 <__do_global_dtors_aux+0x30> 8048378: c6 05 20 96 04 08 01 movb $0x1,0x8049620 804837f: 8d 64 24 04 lea 0x4(%esp),%esp 8048383: 5b pop %ebx 8048384: 5d pop %ebp 8048385: c3 ret 8048386: 8d 76 00 lea 0x0(%esi),%esi 8048389: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 08048390 <frame_dummy>: 8048390: 55 push %ebp 8048391: 89 e5 mov %esp,%ebp 8048393: 8d 64 24 e8 lea -0x18(%esp),%esp 8048397: a1 34 95 04 08 mov 0x8049534,%eax 804839c: 85 c0 test %eax,%eax 804839e: 74 12 je 80483b2 <frame_dummy+0x22> 80483a0: b8 00 00 00 00 mov $0x0,%eax 80483a5: 85 c0 test %eax,%eax 80483a7: 74 09 je 80483b2 <frame_dummy+0x22> 80483a9: c7 04 24 34 95 04 08 movl $0x8049534,(%esp) 80483b0: ff d0 call *%eax 80483b2: c9 leave 80483b3: c3 ret 080483b4 <main>: 80483b4: 55 push %ebp 80483b5: 89 e5 mov %esp,%ebp 80483b7: 83 e4 f0 and $0xfffffff0,%esp 80483ba: 83 ec 10 sub $0x10,%esp 80483bd: c7 04 24 94 84 04 08 movl $0x8048494,(%esp) 80483c4: e8 27 ff ff ff call 80482f0 <puts@plt> 80483c9: c9 leave 80483ca: c3 ret 80483cb: 90 nop 80483cc: 90 nop 80483cd: 90 nop 80483ce: 90 nop 80483cf: 90 nop 080483d0 <__libc_csu_fini>: 80483d0: 55 push %ebp 80483d1: 89 e5 mov %esp,%ebp 80483d3: 5d pop %ebp 80483d4: c3 ret 80483d5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 80483d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 080483e0 <__libc_csu_init>: 80483e0: 55 push %ebp 80483e1: 89 e5 mov %esp,%ebp 80483e3: 57 push %edi 80483e4: 56 push %esi 80483e5: 53 push %ebx 80483e6: e8 4f 00 00 00 call 804843a <__i686.get_pc_thunk.bx> 80483eb: 81 c3 19 12 00 00 add $0x1219,%ebx 80483f1: 83 ec 1c sub $0x1c,%esp 80483f4: e8 97 fe ff ff call 8048290 <_init> 80483f9: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi 80483ff: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax 8048405: 29 c7 sub %eax,%edi 8048407: c1 ff 02 sar $0x2,%edi 804840a: 85 ff test %edi,%edi 804840c: 74 24 je 8048432 <__libc_csu_init+0x52> 804840e: 31 f6 xor %esi,%esi 8048410: 8b 45 10 mov 0x10(%ebp),%eax 8048413: 89 44 24 08 mov %eax,0x8(%esp) 8048417: 8b 45 0c mov 0xc(%ebp),%eax 804841a: 89 44 24 04 mov %eax,0x4(%esp) 804841e: 8b 45 08 mov 0x8(%ebp),%eax 8048421: 89 04 24 mov %eax,(%esp) 8048424: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4) 804842b: 83 c6 01 add $0x1,%esi 804842e: 39 fe cmp %edi,%esi 8048430: 72 de jb 8048410 <__libc_csu_init+0x30> 8048432: 83 c4 1c add $0x1c,%esp 8048435: 5b pop %ebx 8048436: 5e pop %esi 8048437: 5f pop %edi 8048438: 5d pop %ebp 8048439: c3 ret 0804843a <__i686.get_pc_thunk.bx>: 804843a: 8b 1c 24 mov (%esp),%ebx 804843d: c3 ret 804843e: 90 nop 804843f: 90 nop 08048440 <__do_global_ctors_aux>: 8048440: 55 push %ebp 8048441: 89 e5 mov %esp,%ebp 8048443: 53 push %ebx 8048444: 8d 64 24 fc lea -0x4(%esp),%esp 8048448: a1 24 95 04 08 mov 0x8049524,%eax 804844d: 83 f8 ff cmp $0xffffffff,%eax 8048450: 74 12 je 8048464 <__do_global_ctors_aux+0x24> 8048452: bb 24 95 04 08 mov $0x8049524,%ebx 8048457: 90 nop 8048458: 8d 5b fc lea -0x4(%ebx),%ebx 804845b: ff d0 call *%eax 804845d: 8b 03 mov (%ebx),%eax 804845f: 83 f8 ff cmp $0xffffffff,%eax 8048462: 75 f4 jne 8048458 <__do_global_ctors_aux+0x18> 8048464: 8d 64 24 04 lea 0x4(%esp),%esp 8048468: 5b pop %ebx 8048469: 5d pop %ebp 804846a: c3 ret 804846b: 90 nop Disassembly of section .fini: 0804846c <_fini>: 804846c: 55 push %ebp 804846d: 89 e5 mov %esp,%ebp 804846f: 53 push %ebx 8048470: 83 ec 04 sub $0x4,%esp 8048473: e8 00 00 00 00 call 8048478 <_fini+0xc> 8048478: 5b pop %ebx 8048479: 81 c3 8c 11 00 00 add $0x118c,%ebx 804847f: e8 ac fe ff ff call 8048330 <__do_global_dtors_aux> 8048484: 59 pop %ecx 8048485: 5b pop %ebx 8048486: c9 leave 8048487: c3 ret ------------------------------------------ On Sat, Dec 25, 2010 at 2:11 PM, Philip Herron <redbrain@xxxxxxxxxxx> wrote: > On 25 December 2010 09:59, ali hagigat <hagigatali@xxxxxxxxx> wrote: >> When we use some functions like printf in Linux C programs, libc.a is >> linked with our program. Is it linked dynamically or statically? >> Regards >> > > You could probably google that but its static i am fairly sure you > could always do gcc -v to see whats going on and try -nostdinc i think > the option is to not do the standard includes. > > Hope this help! Now back to Christmas ;) > > --Phil >