public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -fPIC changes sizeof class
@ 2009-08-07 17:03 Alan M. Carroll
  2009-08-10  9:06 ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: Alan M. Carroll @ 2009-08-07 17:03 UTC (permalink / raw)
  To: gcc-help

I have chased down a crash in my code to -fPIC changing the size of a class. My overall project uses some static libraries which are compiled without -fPIC and some dynamic libraries that use -fPIC. The effect is that if I use a template class in a static library and a dynamic library that links to the static library, I have to compile the static library with -fPIC as well. According to the documentation[1] this flag shouldn't have any effect at all because I am building for 64 bit Intel.

My question is, is this expected behavior? Or should I try to get a smaller example that demonstrates the problem?

gcc 4.3.3, x86-64, Fedora Core 10. The class and its members both have a lot of inherited zero-size classes.

[1] http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Code-Gen-Options.html#Code-Gen-Options

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

* Re: -fPIC changes sizeof class
  2009-08-07 17:03 -fPIC changes sizeof class Alan M. Carroll
@ 2009-08-10  9:06 ` Andrew Haley
  2009-08-10 13:47   ` Alan M. Carroll
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Haley @ 2009-08-10  9:06 UTC (permalink / raw)
  To: Alan M. Carroll; +Cc: gcc-help

Alan M. Carroll wrote:

> I have chased down a crash in my code to -fPIC changing the
> size of a class.

That seems odd.

> My overall project uses some static libraries which are
> compiled without -fPIC and some dynamic libraries that use
> -fPIC. The effect is that if I use a template class in a static
> library and a dynamic library that links to the static library,
> I have to compile the static library with -fPIC as well.

Well, yes.  generally speaking, all code in a DSO should be
PIC, and that includes code pulled in from libraries.

> According to the documentation[1] this flag shouldn't have any
> effect at all because I am building for 64 bit Intel.

I can't find that reference.  Can you please quote the section to
which you are referring?

> My question is, is this expected behavior? Or should I try to
> get a smaller example that demonstrates the problem?

I can't see why the size of a class should change.  However, it's
not a good idea to mix PIC and non-PIC in a DSO.

Andrew.

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

* Re: -fPIC changes sizeof class
  2009-08-10  9:06 ` Andrew Haley
@ 2009-08-10 13:47   ` Alan M. Carroll
  2009-08-10 15:40     ` Andrew Haley
  0 siblings, 1 reply; 4+ messages in thread
From: Alan M. Carroll @ 2009-08-10 13:47 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

At 04:05 AM 8/10/2009, Andrew Haley wrote:
>> According to the documentation[1] this flag shouldn't have any
>> effect at all because I am building for 64 bit Intel.
>
>I can't find that reference.  Can you please quote the section to
>which you are referring?

http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Code-Gen-Options.html#Code-Gen-Options

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

Position-independent code requires special support, and therefore works only on certain machines. 

When this flag is set, the macros __pic__ and __PIC__ are defined to 2. 

>I can't see why the size of a class should change. 

Is the behavior sufficiently anomalous that it would be worth generating a smaller example?

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

* Re: -fPIC changes sizeof class
  2009-08-10 13:47   ` Alan M. Carroll
@ 2009-08-10 15:40     ` Andrew Haley
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2009-08-10 15:40 UTC (permalink / raw)
  To: Alan M. Carroll; +Cc: gcc-help

Alan M. Carroll wrote:
> At 04:05 AM 8/10/2009, Andrew Haley wrote:
>>> According to the documentation[1] this flag shouldn't have any
>>> effect at all because I am building for 64 bit Intel.
>> I can't find that reference.  Can you please quote the section to
>> which you are referring?
>
> http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Code-Gen-Options.html#Code-Gen-Options
>
> -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.

It means that -fpic and ifPIC are different on 68k, ppc, and sparc.

PIC of some form, whether -fpic or -fPIC, is needed for DSOs on all
targets.

> Position-independent code requires special support, and therefore works only on certain machines.
>
> When this flag is set, the macros __pic__ and __PIC__ are defined to 2.
>
>> I can't see why the size of a class should change.
>
> Is the behavior sufficiently anomalous that it would be worth generating a smaller example?
>

Yes.

Andrew.

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

end of thread, other threads:[~2009-08-10 15:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-07 17:03 -fPIC changes sizeof class Alan M. Carroll
2009-08-10  9:06 ` Andrew Haley
2009-08-10 13:47   ` Alan M. Carroll
2009-08-10 15:40     ` Andrew Haley

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