Regarding GOT table in PIC code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
This is regarding GOT in PIC code.

I have built a shared object library with simple hello function
printing the contents of a global variable (say p). When I use objdump
the code shows the function referencing the variable address from a
GOT table index. (see dump below).

The code is such that the offset of GOT from SP is already decided at
link time in the shared object file (0x1b1c, as I can see from
objdump).

This makes me ask -
1. Does the dynamic linker map the physical pages for .data segments
such that GOT is at a fixed offset from code in logical address space?
is this true?

2. Aren't the variables themselves at a fixed offset from GOT (since
GOT is part of data segment)? So, can't the code just access the data
relative to PC with a single indirection?


000004cc <hello>:
 4cc:	55                   	push   ebp
 4cd:	89 e5                	mov    ebp,esp
 4cf:	53                   	push   ebx
 4d0:	83 ec 14             	sub    esp,0x14
 4d3:	e8 ef ff ff ff       	call   4c7 <__i686.get_pc_thunk.bx>
 4d8:	81 c3 1c 1b 00 00    	add    ebx,0x1b1c
  <----------------------offset
 4de:	8b 83 f4 ff ff ff    	mov    eax,DWORD PTR [ebx-0xc]
 4e4:	8b 00                	mov    eax,DWORD PTR [eax]
 4e6:	89 c1                	mov    ecx,eax
 4e8:	8b 83 f8 ff ff ff    	mov    eax,DWORD PTR [ebx-0x8]
 4ee:	8b 10                	mov    edx,DWORD PTR [eax]
 4f0:	8d 83 90 e5 ff ff    	lea    eax,[ebx-0x1a70]
 4f6:	89 4c 24 08          	mov    DWORD PTR [esp+0x8],ecx
 4fa:	89 54 24 04          	mov    DWORD PTR [esp+0x4],edx
 4fe:	89 04 24             	mov    DWORD PTR [esp],eax
 501:	e8 d2 fe ff ff       	call   3d8 <printf@plt>
 506:	83 c4 14             	add    esp,0x14
 509:	5b                   	pop    ebx
 50a:	5d                   	pop    ebp
 50b:	c3                   	ret


Regards,
Chethan


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux