public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* about -fpic/-fPIC option for gcc
@ 2006-09-03  8:21 Lin George
  2006-09-05 15:23 ` Ian Lance Taylor
  2006-09-14 15:25 ` Marcelo Slomp
  0 siblings, 2 replies; 15+ messages in thread
From: Lin George @ 2006-09-03  8:21 UTC (permalink / raw)
  To: gcc-help

Hello everyone,


I am confused about the meaning and function of -fpic
and -fPIC option of gcc. I am more confused when after
reading the manual of gcc (for example, what means
PIC, GOT, constant addresses, etc.). Could anyone
explain to me what are their functions in easy to
understand words?

Here are the descriptions from gcc manual, which makes
me confused. :-)

--------------------
-fpic Generate position-independent code (PIC)
suitable for use in a shared library,
if supported for the target machine. Such code
accesses all constant addresses
through a global offset table (GOT). The dynamic
loader resolves the GOT
entries when the program starts (the dynamic loader is
not part of GCC; it
is part of the operating system). If the GOT size for
the linked executable
exceeds a machine-specific maximum size, you get an
error message from the
linker indicating that ‘-fpic’ does not work; in that
case, recompile with ‘-fPIC’
instead. (These maximums are 8k on the SPARC and 32k
on the m68k and
RS/6000. The 386 has no such limit.)
Position-independent code requires special support,
and therefore works only on
certain machines. For the 386, GCC supports PIC for
System V but not for the
Sun 386i. Code generated for the IBM RS/6000 is always
position-independent.

-fPIC If supported for the target machine, emit
position-independent code, suitable
for dynamic linking and avoiding any limit on the size
of the global offset table.
This option makes a difference on the m68k, PowerPC
and SPARC.
Chapter 3: GCC Command Options 193
Position-independent code requires special support,
and therefore works only
on certain machines.
--------------------


thanks in advance,
George

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-03  8:21 about -fpic/-fPIC option for gcc Lin George
@ 2006-09-05 15:23 ` Ian Lance Taylor
  2006-09-14  9:51   ` Lin George
  2006-09-14 15:25 ` Marcelo Slomp
  1 sibling, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-05 15:23 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> I am confused about the meaning and function of -fpic
> and -fPIC option of gcc. I am more confused when after
> reading the manual of gcc (for example, what means
> PIC, GOT, constant addresses, etc.). Could anyone
> explain to me what are their functions in easy to
> understand words?

If we could write it better, we would.

Very short and incomplete version which may suffice for your purposes:
the -fpic and -fPIC options are for generating code that will be put
into a shared library on an ELF system.  GNU/Linux is an example of an
ELF system.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-05 15:23 ` Ian Lance Taylor
@ 2006-09-14  9:51   ` Lin George
  2006-09-14 15:49     ` Ian Lance Taylor
  0 siblings, 1 reply; 15+ messages in thread
From: Lin George @ 2006-09-14  9:51 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thank you Ian!


Could you provide a little more information please? I
mean what is the different things generated by -fpic
and -fPIC in a shared library?


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > I am confused about the meaning and function of
> -fpic
> > and -fPIC option of gcc. I am more confused when
> after
> > reading the manual of gcc (for example, what means
> > PIC, GOT, constant addresses, etc.). Could anyone
> > explain to me what are their functions in easy to
> > understand words?
> 
> If we could write it better, we would.
> 
> Very short and incomplete version which may suffice
> for your purposes:
> the -fpic and -fPIC options are for generating code
> that will be put
> into a shared library on an ELF system.  GNU/Linux
> is an example of an
> ELF system.
> 
> Ian
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-03  8:21 about -fpic/-fPIC option for gcc Lin George
  2006-09-05 15:23 ` Ian Lance Taylor
@ 2006-09-14 15:25 ` Marcelo Slomp
  2006-09-17  8:53   ` Lin George
  1 sibling, 1 reply; 15+ messages in thread
From: Marcelo Slomp @ 2006-09-14 15:25 UTC (permalink / raw)
  To: gcc-help



Lin George wrote:
> 
> Hello everyone,
> 
> 
> I am confused about the meaning and function of -fpic
> and -fPIC option of gcc. I am more confused when after
> reading the manual of gcc (for example, what means
> PIC, GOT, constant addresses, etc.). Could anyone
> explain to me what are their functions in easy to
> understand words?
> 
> Here are the descriptions from gcc manual, which makes
> me confused. :-)
> 

While -fpic is platform-dependent, -fPIC works always, but generates much
more code than -fpic does.
In practice, using an non-technical language, -fPIC will generate a code
capable to see things beyond
the normal scope, so that system can map the (position independent) code in
any case.
The rule is: if you want a fast and small code, and the target is
pic-enabled, use -fpic.
Otherwise, avoid headhaches using -fPIC always.

Regards,
Marcelo Slomp
-- 
View this message in context: http://www.nabble.com/about--fpic--fPIC-option-for-gcc-tf2209766.html#a6308284
Sent from the gcc - Help forum at Nabble.com.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-14  9:51   ` Lin George
@ 2006-09-14 15:49     ` Ian Lance Taylor
  2006-09-17  8:55       ` Lin George
  0 siblings, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-14 15:49 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> Could you provide a little more information please? I
> mean what is the different things generated by -fpic
> and -fPIC in a shared library?

To make the code position independent and to permit the executable to
override symbols defined in the shared library, all global variables
are accessed via a table of addresses (the Global Offset Table, or
GOT) and all functions are called via a table of branches (the
Procedure Linkage Table, or PLT).  The dynamic linker initializes the
GOT and PLT at runtime.  The precise details depend on the platform.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-14 15:25 ` Marcelo Slomp
@ 2006-09-17  8:53   ` Lin George
  0 siblings, 0 replies; 15+ messages in thread
From: Lin George @ 2006-09-17  8:53 UTC (permalink / raw)
  To: Marcelo Slomp, gcc-help

Thank you Marcelo,


Your answer makes me clear about how to use them. I
have a further question, I am wondering what are the
differences (could you provide a little more
information) of the code generated by -fpic/-fPIC? Do
you mean there are any differences in some tables
which linker or something else will ues?


regards,
George

--- Marcelo Slomp <mslomp@linuxmail.org> wrote:

> 
> 
> Lin George wrote:
> > 
> > Hello everyone,
> > 
> > 
> > I am confused about the meaning and function of
> -fpic
> > and -fPIC option of gcc. I am more confused when
> after
> > reading the manual of gcc (for example, what means
> > PIC, GOT, constant addresses, etc.). Could anyone
> > explain to me what are their functions in easy to
> > understand words?
> > 
> > Here are the descriptions from gcc manual, which
> makes
> > me confused. :-)
> > 
> 
> While -fpic is platform-dependent, -fPIC works
> always, but generates much
> more code than -fpic does.
> In practice, using an non-technical language, -fPIC
> will generate a code
> capable to see things beyond
> the normal scope, so that system can map the
> (position independent) code in
> any case.
> The rule is: if you want a fast and small code, and
> the target is
> pic-enabled, use -fpic.
> Otherwise, avoid headhaches using -fPIC always.
> 
> Regards,
> Marcelo Slomp
> -- 
> View this message in context:
>
http://www.nabble.com/about--fpic--fPIC-option-for-gcc-tf2209766.html#a6308284
> Sent from the gcc - Help forum at Nabble.com.
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-14 15:49     ` Ian Lance Taylor
@ 2006-09-17  8:55       ` Lin George
  2006-09-17 16:07         ` Ian Lance Taylor
  0 siblings, 1 reply; 15+ messages in thread
From: Lin George @ 2006-09-17  8:55 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Hi Ian,


Do you mean -fpic and -fPIC will make GOT and PLT
different? If yes, what are the differences?


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > Could you provide a little more information
> please? I
> > mean what is the different things generated by
> -fpic
> > and -fPIC in a shared library?
> 
> To make the code position independent and to permit
> the executable to
> override symbols defined in the shared library, all
> global variables
> are accessed via a table of addresses (the Global
> Offset Table, or
> GOT) and all functions are called via a table of
> branches (the
> Procedure Linkage Table, or PLT).  The dynamic
> linker initializes the
> GOT and PLT at runtime.  The precise details depend
> on the platform.
> 
> Ian
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-17  8:55       ` Lin George
@ 2006-09-17 16:07         ` Ian Lance Taylor
  2006-09-18  8:47           ` Lin George
  0 siblings, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-17 16:07 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> Do you mean -fpic and -fPIC will make GOT and PLT
> different? If yes, what are the differences?

I quote the documentation about -fPIC:

    If supported for the target machine, emit position-independent
    code, suitable for dynamic linking and avoiding any limit on the
    size of the global offset table.  This option makes a difference
    on the m68k, PowerPC and SPARC.

The difference is that with -fPIC there is no limit on the size of the
GOT.  The precise details depend on the platform.

Ian

> --- Ian Lance Taylor <iant@google.com> wrote:
> 
> > Lin George <george4academic@yahoo.com> writes:
> > 
> > > Could you provide a little more information
> > please? I
> > > mean what is the different things generated by
> > -fpic
> > > and -fPIC in a shared library?
> > 
> > To make the code position independent and to permit
> > the executable to
> > override symbols defined in the shared library, all
> > global variables
> > are accessed via a table of addresses (the Global
> > Offset Table, or
> > GOT) and all functions are called via a table of
> > branches (the
> > Procedure Linkage Table, or PLT).  The dynamic
> > linker initializes the
> > GOT and PLT at runtime.  The precise details depend
> > on the platform.
> > 
> > Ian
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-17 16:07         ` Ian Lance Taylor
@ 2006-09-18  8:47           ` Lin George
  2006-09-18 14:22             ` Ian Lance Taylor
  0 siblings, 1 reply; 15+ messages in thread
From: Lin George @ 2006-09-18  8:47 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thank you Ian,


You have answered most of my question. What materials
are stored in GOT? Any documents describe it in a
simple/clear/brief way? :-)


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > Do you mean -fpic and -fPIC will make GOT and PLT
> > different? If yes, what are the differences?
> 
> I quote the documentation about -fPIC:
> 
>     If supported for the target machine, emit
> position-independent
>     code, suitable for dynamic linking and avoiding
> any limit on the
>     size of the global offset table.  This option
> makes a difference
>     on the m68k, PowerPC and SPARC.
> 
> The difference is that with -fPIC there is no limit
> on the size of the
> GOT.  The precise details depend on the platform.
> 
> Ian
> 
> > --- Ian Lance Taylor <iant@google.com> wrote:
> > 
> > > Lin George <george4academic@yahoo.com> writes:
> > > 
> > > > Could you provide a little more information
> > > please? I
> > > > mean what is the different things generated by
> > > -fpic
> > > > and -fPIC in a shared library?
> > > 
> > > To make the code position independent and to
> permit
> > > the executable to
> > > override symbols defined in the shared library,
> all
> > > global variables
> > > are accessed via a table of addresses (the
> Global
> > > Offset Table, or
> > > GOT) and all functions are called via a table of
> > > branches (the
> > > Procedure Linkage Table, or PLT).  The dynamic
> > > linker initializes the
> > > GOT and PLT at runtime.  The precise details
> depend
> > > on the platform.
> > > 
> > > Ian
> > > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> > http://mail.yahoo.com 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-18  8:47           ` Lin George
@ 2006-09-18 14:22             ` Ian Lance Taylor
  2006-09-19  5:00               ` Lin George
  0 siblings, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-18 14:22 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> What materials
> are stored in GOT?

There is some variation among platforms, but normally each entry in
the GOT is the addresses of a global variable.

> Any documents describe it in a
> simple/clear/brief way? :-)

The ELF processor-specific supplement for the processor you are using.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-18 14:22             ` Ian Lance Taylor
@ 2006-09-19  5:00               ` Lin George
  2006-09-19  5:44                 ` Ian Lance Taylor
  0 siblings, 1 reply; 15+ messages in thread
From: Lin George @ 2006-09-19  5:00 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thank you Ian,


I think if -fpic will generate less information than
-fPIC in GOT, we will be impacted by such information
when develop/debug?? For example, missing some symbol
names will make debugger fail to find
function/variable names.


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > What materials
> > are stored in GOT?
> 
> There is some variation among platforms, but
> normally each entry in
> the GOT is the addresses of a global variable.
> 
> > Any documents describe it in a
> > simple/clear/brief way? :-)
> 
> The ELF processor-specific supplement for the
> processor you are using.
> 
> Ian
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-19  5:00               ` Lin George
@ 2006-09-19  5:44                 ` Ian Lance Taylor
  2006-09-20 11:43                   ` Lin George
  0 siblings, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-19  5:44 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> I think if -fpic will generate less information than
> -fPIC in GOT, we will be impacted by such information
> when develop/debug?? For example, missing some symbol
> names will make debugger fail to find
> function/variable names.

Using -fpic will not affect the debugging information.

The difference between -fpic and -fPIC is that some large programs
will fail to link if you use -fpic.  All programs will link if you use
-fPIC.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-19  5:44                 ` Ian Lance Taylor
@ 2006-09-20 11:43                   ` Lin George
  2006-09-20 16:09                     ` Ian Lance Taylor
  0 siblings, 1 reply; 15+ messages in thread
From: Lin George @ 2006-09-20 11:43 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thank you Ian,


The last question, could you provide some reference
materials to read on this topic. My background is I
have used for C/C++ compiler/linker for years and I
know something about compiler/linker internals, but
not too much (for example, the differences which -fpic
and -fPIC will impact).


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > I think if -fpic will generate less information
> than
> > -fPIC in GOT, we will be impacted by such
> information
> > when develop/debug?? For example, missing some
> symbol
> > names will make debugger fail to find
> > function/variable names.
> 
> Using -fpic will not affect the debugging
> information.
> 
> The difference between -fpic and -fPIC is that some
> large programs
> will fail to link if you use -fpic.  All programs
> will link if you use
> -fPIC.
> 
> Ian
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-20 11:43                   ` Lin George
@ 2006-09-20 16:09                     ` Ian Lance Taylor
  2006-09-21  6:22                       ` Lin George
  0 siblings, 1 reply; 15+ messages in thread
From: Ian Lance Taylor @ 2006-09-20 16:09 UTC (permalink / raw)
  To: Lin George; +Cc: gcc-help

Lin George <george4academic@yahoo.com> writes:

> The last question, could you provide some reference
> materials to read on this topic. My background is I
> have used for C/C++ compiler/linker for years and I
> know something about compiler/linker internals, but
> not too much (for example, the differences which -fpic
> and -fPIC will impact).

As I believe I've mentioned a couple of times, you should look at the
ELF ABI documentation.  You can find some here:
    http://sco.com/developers/gabi/
Unfortunately some of the documentation, such as the full ELF ABI
documentation and the i386 processor supplement, is not available
online as far as I know.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: about -fpic/-fPIC option for gcc
  2006-09-20 16:09                     ` Ian Lance Taylor
@ 2006-09-21  6:22                       ` Lin George
  0 siblings, 0 replies; 15+ messages in thread
From: Lin George @ 2006-09-21  6:22 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thank you for your help all the way, Ian.


regards,
George

--- Ian Lance Taylor <iant@google.com> wrote:

> Lin George <george4academic@yahoo.com> writes:
> 
> > The last question, could you provide some
> reference
> > materials to read on this topic. My background is
> I
> > have used for C/C++ compiler/linker for years and
> I
> > know something about compiler/linker internals,
> but
> > not too much (for example, the differences which
> -fpic
> > and -fPIC will impact).
> 
> As I believe I've mentioned a couple of times, you
> should look at the
> ELF ABI documentation.  You can find some here:
>     http://sco.com/developers/gabi/
> Unfortunately some of the documentation, such as the
> full ELF ABI
> documentation and the i386 processor supplement, is
> not available
> online as far as I know.
> 
> Ian
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-09-21  6:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-03  8:21 about -fpic/-fPIC option for gcc Lin George
2006-09-05 15:23 ` Ian Lance Taylor
2006-09-14  9:51   ` Lin George
2006-09-14 15:49     ` Ian Lance Taylor
2006-09-17  8:55       ` Lin George
2006-09-17 16:07         ` Ian Lance Taylor
2006-09-18  8:47           ` Lin George
2006-09-18 14:22             ` Ian Lance Taylor
2006-09-19  5:00               ` Lin George
2006-09-19  5:44                 ` Ian Lance Taylor
2006-09-20 11:43                   ` Lin George
2006-09-20 16:09                     ` Ian Lance Taylor
2006-09-21  6:22                       ` Lin George
2006-09-14 15:25 ` Marcelo Slomp
2006-09-17  8:53   ` Lin George

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).