* Regarding GOT table in PIC code
@ 2012-01-09 10:47 Chethan Palakshamurthy
2012-01-09 11:17 ` Andrew Haley
0 siblings, 1 reply; 5+ messages in thread
From: Chethan Palakshamurthy @ 2012-01-09 10:47 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Regarding GOT table in PIC code
2012-01-09 10:47 Regarding GOT table in PIC code Chethan Palakshamurthy
@ 2012-01-09 11:17 ` Andrew Haley
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2012-01-09 11:17 UTC (permalink / raw)
To: gcc-help
On 01/09/2012 10:06 AM, Chethan Palakshamurthy wrote:
> 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?
Yes, it has to do this or it wouldn't be possible to find the GOT.
> 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?
No, because there may be more than one declaration of X: X may be
declared in more than one shared object file. So, it may be
necessary to fix up references to X to point outside a shared
object, even though it contains a definition of X.
Andrew.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Regarding GOT table in PIC code
2012-01-10 17:43 ` Ian Lance Taylor
@ 2012-01-11 8:18 ` Chethan Palakshamurthy
0 siblings, 0 replies; 5+ messages in thread
From: Chethan Palakshamurthy @ 2012-01-11 8:18 UTC (permalink / raw)
To: gcc-help
Thanks Ian, Andrew.
- chethan
On Tue, Jan 10, 2012 at 10:31 PM, Ian Lance Taylor <iant@google.com> wrote:
>
> Chethan Palakshamurthy <pchethan@gmail.com> writes:
>
> >>> 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?
> >>
> >>Yes, it has to do this or it wouldn't be possible to find the GOT.
> >
> > So, this method of paging is what makes it possible to share code
> > pages across processes? Several sources online(/books) mention that
> > PIC is the one which make code sharing across processes possible.
>
> I would not say that it's the method of paging that makes that
> possible. That is merely a detail in how the GOT is implemented.
>
> The GOT makes sharing possible because it separates the final address of
> the variable from the code. Thus the code can be shared even though the
> address of the variable will be different in different processes.
>
> Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Regarding GOT table in PIC code
2012-01-10 17:36 Chethan Palakshamurthy
@ 2012-01-10 17:43 ` Ian Lance Taylor
2012-01-11 8:18 ` Chethan Palakshamurthy
0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2012-01-10 17:43 UTC (permalink / raw)
To: Chethan Palakshamurthy; +Cc: gcc-help
Chethan Palakshamurthy <pchethan@gmail.com> writes:
>>> 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?
>>
>>Yes, it has to do this or it wouldn't be possible to find the GOT.
>
> So, this method of paging is what makes it possible to share code
> pages across processes? Several sources online(/books) mention that
> PIC is the one which make code sharing across processes possible.
I would not say that it's the method of paging that makes that
possible. That is merely a detail in how the GOT is implemented.
The GOT makes sharing possible because it separates the final address of
the variable from the code. Thus the code can be shared even though the
address of the variable will be different in different processes.
Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Regarding GOT table in PIC code
@ 2012-01-10 17:36 Chethan Palakshamurthy
2012-01-10 17:43 ` Ian Lance Taylor
0 siblings, 1 reply; 5+ messages in thread
From: Chethan Palakshamurthy @ 2012-01-10 17:36 UTC (permalink / raw)
To: gcc-help
>> 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?
>
>Yes, it has to do this or it wouldn't be possible to find the GOT.
So, this method of paging is what makes it possible to share code
pages across processes? Several sources online(/books) mention that
PIC is the one which make code sharing across processes possible.
- Chethan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-11 6:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-09 10:47 Regarding GOT table in PIC code Chethan Palakshamurthy
2012-01-09 11:17 ` Andrew Haley
2012-01-10 17:36 Chethan Palakshamurthy
2012-01-10 17:43 ` Ian Lance Taylor
2012-01-11 8:18 ` Chethan Palakshamurthy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).