public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: to reduce footprint
@ 2006-12-20 16:46 Lin George
  2006-12-21 15:30 ` John Love-Jensen
  0 siblings, 1 reply; 6+ messages in thread
From: Lin George @ 2006-12-20 16:46 UTC (permalink / raw)
  To: John Love-Jensen, MSX to GCC

Thanks John! I want to reduce the file size of my shared library. I think you are an expert in this field. I have read through your comments below and I am especially interested in the following points,

1. Use footprint techniques (such as inheritance, specialization and partial
specialization) to reduce the amount of code generated by templates.

Could you provide some references to them?

2. Avoid the convenience of multiple copies of weak linkage for stronger,
explicit linkage.  [Depending on what kind of footprint you are trying to
reduce.]

Could you provide some reference about weak linker and a strong (explicit linker)?

3. Make sure all your header files do not emit any code (e.g., no static
variables in header files).  Compile your header files to confirm that all
your header files are non-code-generating.

I can understand what you mean, but I do not know why if header files emit code, the footprint will be larger?

4. --gc-sections -ffunction-sections -fdata-sections

gcc manual does not contain much information about these parameters. Could you briefly introduce the functions of them?


thanks in advance,
George


----- Original Message ----
From: John Love-Jensen <eljay@adobe.com>
To: Lin George <george4academic@yahoo.com>; MSX to GCC <gcc-help@gcc.gnu.org>
Sent: Tuesday, December 19, 2006 9:18:32 PM
Subject: Re: to reduce footprint


Hi George,

> I am wondering how to reduce the footprint of a binary build (C/C++) program
> generated by gcc.

Memory footprint, or file footprint?

> 1. Any ideas of reduce the footprint of a debug version build?
> 2. Any ideas of reduce the footprint of a release version build?

Just some suggestions, by no means a comprehensive list...

If you have an object file with 100 routines in it, but you only use 1
routine out of the hundred, isolate that one routine and link just it (.o
file).  Then you won't get the unnecessary 99 fallow routines.

Use footprint techniques (such as inheritance, specialization and partial
specialization) to reduce the amount of code generated by templates.

Avoid the convenience of multiple copies of weak linkage for stronger,
explicit linkage.  [Depending on what kind of footprint you are trying to
reduce.]

Make sure all your header files do not emit any code (e.g., no static
variables in header files).  Compile your header files to confirm that all
your header files are non-code-generating.

Use code coverage tools to identify code that is not used.  Figure out why
it isn't used, and consider if it can be disposed.

Use enums instead of strings for references to resources.

If you have a value range of, say, 0 to 100, and you have a large array of
them, consider using a typedef unsigned char uint8_t; instead of an array of
int to hold them.

> I think some linker or compiler options may help, what are they? Any other
> ideas to reduce footprint?

Depending on your platform, you may be able to use these switches:
--gc-sections -ffunction-sections -fdata-sections

hHTH,
--Eljay

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

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

* Re: to reduce footprint
  2006-12-20 16:46 to reduce footprint Lin George
@ 2006-12-21 15:30 ` John Love-Jensen
  0 siblings, 0 replies; 6+ messages in thread
From: John Love-Jensen @ 2006-12-21 15:30 UTC (permalink / raw)
  To: Lin George, MSX to GCC

Hi George,

> Could you provide some references to them?

The C++ Programming Language (special edition) by Stroustrup

Chapter 13 in particular.

Other highly recommended references in general...

C++ FAQs by Cline, Lomow, Girou

Large-Scale C++ Software Design by Lakos

C++ Coding Standards by Sutter, Alexandrescu

Exceptional C++ by Sutter

More Exceptional C++ by Sutter

Exceptional C++ Style by Sutter

Debugging the Development Process by Maguire

Code Complete by McConnell

Writing Solid Code by Maguire

> Could you provide some reference about weak linker and a strong (explicit
linker)?

Know your linkage: weak, vague, strong, external, static.  (I probably
missed a few.)

Google turned up this URL:

http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Conc
epts/WeakLinking.html

> I can understand what you mean, but I do not know why if header files emit
code, the footprint will be larger?

If a header emits stuff, then every translation that includes that header
will emit that code.  If you have 1000 source files which include that
header, you will have 1000 copies of the stuff emitted by that header.

So, yes, the footprint will be larger.

> gcc manual does not contain much information about these parameters. Could you
briefly introduce the functions of them?

I'm not that familiar with them, myself.  They are not supported on the
platforms I use.

I can only refer you to the GCC manual.

HTH,
--Eljay

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

* Re: to reduce footprint
  2006-12-21 17:50 Lin George
@ 2006-12-21 19:13 ` John Love-Jensen
  0 siblings, 0 replies; 6+ messages in thread
From: John Love-Jensen @ 2006-12-21 19:13 UTC (permalink / raw)
  To: Lin George, MSX to GCC

Hi George,

> Thank fo your great reply John!

You're welcome.  :-)

> I have read the document for weak linking, and it seems that it is something
specific for MAC OS?

Quite a few different platforms support weak linking.

The document is Mac specific, but the weak linking concept is not.

Sincerely,
--Eljay


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

* Re: to reduce footprint
@ 2006-12-21 17:50 Lin George
  2006-12-21 19:13 ` John Love-Jensen
  0 siblings, 1 reply; 6+ messages in thread
From: Lin George @ 2006-12-21 17:50 UTC (permalink / raw)
  To: John Love-Jensen, MSX to GCC

Thank fo your great reply John! I have read the document for weak linking, and it seems that it is something specific for MAC OS?

BTW: I am working on Linux.


regards,
George

----- Original Message ----
From: John Love-Jensen <eljay@adobe.com>
To: Lin George <george4academic@yahoo.com>; MSX to GCC <gcc-help@gcc.gnu.org>
Sent: Thursday, December 21, 2006 11:30:06 PM
Subject: Re: to reduce footprint


Hi George,

> Could you provide some references to them?

The C++ Programming Language (special edition) by Stroustrup

Chapter 13 in particular.

Other highly recommended references in general...

C++ FAQs by Cline, Lomow, Girou

Large-Scale C++ Software Design by Lakos

C++ Coding Standards by Sutter, Alexandrescu

Exceptional C++ by Sutter

More Exceptional C++ by Sutter

Exceptional C++ Style by Sutter

Debugging the Development Process by Maguire

Code Complete by McConnell

Writing Solid Code by Maguire

> Could you provide some reference about weak linker and a strong (explicit
linker)?

Know your linkage: weak, vague, strong, external, static.  (I probably
missed a few.)

Google turned up this URL:

http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Conc
epts/WeakLinking.html

> I can understand what you mean, but I do not know why if header files emit
code, the footprint will be larger?

If a header emits stuff, then every translation that includes that header
will emit that code.  If you have 1000 source files which include that
header, you will have 1000 copies of the stuff emitted by that header.

So, yes, the footprint will be larger.

> gcc manual does not contain much information about these parameters. Could you
briefly introduce the functions of them?

I'm not that familiar with them, myself.  They are not supported on the
platforms I use.

I can only refer you to the GCC manual.

HTH,
--Eljay

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

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

* Re: to reduce footprint
  2006-12-19  2:41 Lin George
@ 2006-12-19 13:18 ` John Love-Jensen
  0 siblings, 0 replies; 6+ messages in thread
From: John Love-Jensen @ 2006-12-19 13:18 UTC (permalink / raw)
  To: Lin George, MSX to GCC

Hi George,

> I am wondering how to reduce the footprint of a binary build (C/C++) program
> generated by gcc.

Memory footprint, or file footprint?

> 1. Any ideas of reduce the footprint of a debug version build?
> 2. Any ideas of reduce the footprint of a release version build?

Just some suggestions, by no means a comprehensive list...

If you have an object file with 100 routines in it, but you only use 1
routine out of the hundred, isolate that one routine and link just it (.o
file).  Then you won't get the unnecessary 99 fallow routines.

Use footprint techniques (such as inheritance, specialization and partial
specialization) to reduce the amount of code generated by templates.

Avoid the convenience of multiple copies of weak linkage for stronger,
explicit linkage.  [Depending on what kind of footprint you are trying to
reduce.]

Make sure all your header files do not emit any code (e.g., no static
variables in header files).  Compile your header files to confirm that all
your header files are non-code-generating.

Use code coverage tools to identify code that is not used.  Figure out why
it isn't used, and consider if it can be disposed.

Use enums instead of strings for references to resources.

If you have a value range of, say, 0 to 100, and you have a large array of
them, consider using a typedef unsigned char uint8_t; instead of an array of
int to hold them.

> I think some linker or compiler options may help, what are they? Any other
> ideas to reduce footprint?

Depending on your platform, you may be able to use these switches:
--gc-sections -ffunction-sections -fdata-sections

HTH,
--Eljay

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

* to reduce footprint
@ 2006-12-19  2:41 Lin George
  2006-12-19 13:18 ` John Love-Jensen
  0 siblings, 1 reply; 6+ messages in thread
From: Lin George @ 2006-12-19  2:41 UTC (permalink / raw)
  To: gcc-help

Hello everyone,


I am wondering how to reduce the footprint of a binary build (C/C++) program generated by gcc.

1. Any ideas of reduce the footprint of a debug version build?
2. Any ideas of reduce the footprint of a release version build?

I think some linker or compiler options may help, what are they? Any other ideas to reduce footprint?


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] 6+ messages in thread

end of thread, other threads:[~2006-12-21 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-20 16:46 to reduce footprint Lin George
2006-12-21 15:30 ` John Love-Jensen
  -- strict thread matches above, loose matches on Subject: below --
2006-12-21 17:50 Lin George
2006-12-21 19:13 ` John Love-Jensen
2006-12-19  2:41 Lin George
2006-12-19 13:18 ` John Love-Jensen

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