public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to reduce GOT entries in -fpic programs (to avoid -fPIC use)
@ 1999-10-21  3:58 Eric Dumazet
  1999-10-31 23:35 ` Eric Dumazet
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 1999-10-21  3:58 UTC (permalink / raw)
  To: gcc

Hi

I had to use -fPIC instead of -fpic to compile a shared library on sparc
(solaris 7)

I'm concerned about the overhead of -fPIC, using 3 instructions instead
of one for -fpic for address calculations.
Since my biggest library has 2300 entries in GOT, which is very close of
the 2048 limit for -fpic, I was thinking of a trick to reduce GOT
entries, without modifications to source code.

A very easy way to reduce GOT entries is to put const strings into a big
one.

This code :

1)
printf("First") ;
printf("Second") ;

could be replaced by this equivalent one : (if compiled without
-fwriteable-strings , delete 'const' keyword otherwise)

2)
static const char strings[] = "First\0Second\0" ;
printf(strings) ;
printf(strings+6) ;

Or even better (for better performance of string functions, an alignment
of strings is required)
3)
static const char strings[] = "First\0\0\0Second\0" ;
printf(strings) ;
printf(strings+8) ;

In the 2) and 3) cases, the compiler use only one GOT entry, instead of
2 for the 1) case


So the idea is to group together strings, in char arrays of no more than
X bytes, X depending of the CPU used, so that the compiler use only one
instruction to compute pic addresses. (X=4095 for sparc for example)

If a file contains N strings, it could use only one GOT entry instead of
N !

Of course, such a trick can be handled by a 'string compressor program',
acting as a preprocessor before C compilation.

But it would be nice if it could be integrated in gcc.
gcc has already an elimination of common strings, it would be great if
this feature could be added..
I could contribute to this if I receive positive feedbacks...
I think that debuggers could be fooled by this kind of hack, I have no
idea of the work involved.

Comments please ?


Eric Dumazet

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

* How to reduce GOT entries in -fpic programs (to avoid -fPIC use)
  1999-10-21  3:58 How to reduce GOT entries in -fpic programs (to avoid -fPIC use) Eric Dumazet
@ 1999-10-31 23:35 ` Eric Dumazet
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 1999-10-31 23:35 UTC (permalink / raw)
  To: gcc

Hi

I had to use -fPIC instead of -fpic to compile a shared library on sparc
(solaris 7)

I'm concerned about the overhead of -fPIC, using 3 instructions instead
of one for -fpic for address calculations.
Since my biggest library has 2300 entries in GOT, which is very close of
the 2048 limit for -fpic, I was thinking of a trick to reduce GOT
entries, without modifications to source code.

A very easy way to reduce GOT entries is to put const strings into a big
one.

This code :

1)
printf("First") ;
printf("Second") ;

could be replaced by this equivalent one : (if compiled without
-fwriteable-strings , delete 'const' keyword otherwise)

2)
static const char strings[] = "First\0Second\0" ;
printf(strings) ;
printf(strings+6) ;

Or even better (for better performance of string functions, an alignment
of strings is required)
3)
static const char strings[] = "First\0\0\0Second\0" ;
printf(strings) ;
printf(strings+8) ;

In the 2) and 3) cases, the compiler use only one GOT entry, instead of
2 for the 1) case


So the idea is to group together strings, in char arrays of no more than
X bytes, X depending of the CPU used, so that the compiler use only one
instruction to compute pic addresses. (X=4095 for sparc for example)

If a file contains N strings, it could use only one GOT entry instead of
N !

Of course, such a trick can be handled by a 'string compressor program',
acting as a preprocessor before C compilation.

But it would be nice if it could be integrated in gcc.
gcc has already an elimination of common strings, it would be great if
this feature could be added..
I could contribute to this if I receive positive feedbacks...
I think that debuggers could be fooled by this kind of hack, I have no
idea of the work involved.

Comments please ?


Eric Dumazet

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

end of thread, other threads:[~1999-10-31 23:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-21  3:58 How to reduce GOT entries in -fpic programs (to avoid -fPIC use) Eric Dumazet
1999-10-31 23:35 ` Eric Dumazet

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