c - Absolute Jumps Within Shared Object Code Unix -



c - Absolute Jumps Within Shared Object Code Unix -

i have question regarding handling , interpretation of shared libraries.

suppose, build shared object foo.c using command:

gcc -shared -fpic -o libfoo.so foo.c

where foo.c consists of:

#include <stdlib.h> #include <stdio.h> int main(void) { int i; printf("this silly test\n"); if(i) goto ret; printf("hello world\n"); ret: homecoming 0; }

now, let's @ objdump output, of foo's main:

0000000005ec <main>: 5ec: 55 force %rbp 5ed: 48 89 e5 mov %rsp,%rbp 5f0: 48 83 ec 10 sub $0x10,%rsp 5f4: 48 8d 3d 6b 00 00 00 lea 0x6b(%rip),%rdi # 666 <_fini+0xe> 5fb: e8 00 ff ff ff callq 500 <puts@plt> 600: 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 604: 75 0e jne 614 <main+0x28> 606: 48 8d 3d 65 00 00 00 lea 0x65(%rip),%rdi # 672 <_fini+0x1a> 60d: e8 ee fe ff ff callq 500 <puts@plt> 612: eb 01 jmp 615 <main+0x29> 614: 90 nop 615: b8 00 00 00 00 mov $0x0,%eax 61a: c9 leaveq 61b: c3 retq 61c: 90 nop 61d: 90 nop 61e: 90 nop 61f: 90 nop

i can see calls puts beingness redirected plt, expected. however, don't understand instructions @ 604 , 612. not relative ip, nor phone call plt. utilize absolute address, based on symbol main.

how shared library perchance used simultaneously betwen several processes? (and should) loaded @ different virtual addresses, point each process should share implementation stored in ram. how can different processes main loaded @ different virtual addresses share instructions @ 604 , 612?

they're not absolute jumps, they're pc relative jumps. in fact direct jump , phone call instructions pc-relative on x86 -- there no absolute direct jumps (so if want absolute jump, has indirect).

the reason callq instruction utilize plt because target symbol might in different shared object, relative branch won't work (the other shared object might loaded @ address, independently of shared object). plt little piece of code within shared object, single (indirect) absolute jump each remote symbol. when shared objects dynamically loaded, absolute address set appropriately, when code runs, callq instruction pc-relative branch (call) plt consists of single indirect jump puts routine.

c unix linker dynamic-linking

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -