> gcc optimize for size is -Os. For dead code elimination you would also
> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
>
> I use this to compile (defines and includes removed):
> C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin\arm-none-eabi-gcc.exe -x
> c -fpack-struct=1 -c -gdwarf-3 -mcpu=cortex-m3 -mthumb -mfix-cortex-m3-ldrd
> -Os -fshort-enums -ffunction-sections -fdata-sections -fconserve-stack -fverbose-asm
> -fno-common -fno-merge-constants -fno-defer-pop -Wall -Wformat -Wimplicit -Wreturn-type
> -Wunused -Wuninitialized -Wunknown-pragmas -Wno-switch -Wno-strict-aliasing
> -Wtype-limits
Wformat, Wimplicit, Wreturn-type, Wunused, Wuninitialized, Wunknown-pragmas
are already turned on by Wall.
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wall-256
I'm not sure why you would disable Wswitch, can you explain?
I don't think you should disable the strict-aliasing warnings, you should
instead disable the strict-aliasing feature, with -fno-strict-aliasing.
Regards.
Reply by Paul●July 2, 20122012-07-02
In article <jsl3er$8jf$1@reader1.panix.com>, invalid@invalid.invalid
says...
>
> On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> > In article <jskko0$spl$1@reader1.panix.com>, invalid@invalid.invalid
> > says...
> >>
> >> On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> >> > In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
> >> > says...
> >> >>
> >> >> > Is that with -O2, or whatever the "optimize for size" switch is?
> >> >>
> >> >> gcc optimize for size is -Os. For dead code elimination you would also
> >> >> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
> >> >>
> >> > I have to use -gc for badly written 3rd party supposed libraries that
> >> > are not libraries but a bad collection of project modules forced into
> >> > library architecture.
> >>
> >> The sections/gc options are addictive. Once you get used to them, it
> >> becomes pretty painful to have to live without them. They make
> >> re-using code way easier, and they also make it a lot easier to
> >> enable disable features at link time.
> >
> > A real pain to prove what actually is used or not used when audited
> > for various bodies.
>
> How so? The linker listing shows exactly what's in the executable.
Yes and no, if you have a linker listing some bodies over the years I
have had folks want be sure what has been removed has no side effects
because linker has removed some parts and left references to removed
items. I know silly but I get this sort of thing from time to time
with various tools and bodies.
> > A real pain when someone else picks up the project and has to wade
> > through a large module within a 'library' to check for no side
> > effects. To ensure the compiler is really not missing something it
> > should not.
> >
> > Never rely on compiler tricks for correct code reduction of unused
> > code, it may change under your feet or between versions and platforms
> > or targets.
>
> Yet it's OK to rely on linker tricks for correct code reduction of
> unused code when using libraries? ;)
a) if you know the 3rd party library has been wriiten that way.
b) if the compiler vendor and 3rd party library co-operate properly
in one case it was specific version of compiler for that family
and manufacturer's library.
c) They all document and dont let you guess this is the way this library
is supposed to be used.
In one case I was working on one of the smallest members of a family and
simple code compile would not fit into device, with a few calls to
library. Why because nowhere in the documentation or the default builds
on compiler for that processor specifically stated should use -gc
option.
I believe the 3rd party library code has only really been tested for
builds and on largest device in family.
> I don't understand why you call it "compiler tricks". It's very
> straight forward, and it's the exact same thing that happens with
> libraries except it also works with non-global objects.
First of all anyone can write BAD libraries in the 90's I saw a PC based
library for then employer that always loaded the WHOLE library, no
matter if you only used one or all functions.
> > What is wrong with writing libraries correctly?
>
> The main thing I found "wrong" was that with the library approach
> everything has to be in a single, global name space whether it needs
> to be visible outside the module or not. In my experience, that
> produces designs that are hard to understand and maintain. You can
> end up with unintentional interactions between modules because every
> module has to expose internal names.
Yes and no, for some complex RAM based libraries for image processing
cryptography, maths functions etc you end up with some library 'globals'
whatever you do because you need them.
For board/processor support libraries you will always have some globals
even if they are actually constants just for regiosters, bit/bus width
etc.
One processor library gets around most of its globals, by ensuring all
functions have a parameterof the base address of the I/O unit you want
to address. Making it less encapsulated and less portable across the
same family or similar families. Why the hell is unit 0,1,2... passed.
Especially as you go up famioly trees these days with lots of
peripherals and RAM you could well have loadable binary tasks or code
segments that could be loaded on any processor, so common encapsulation
helps you, especially if the processor has the library in its ROM.
> With the sections/gc approach, a "module" can have a well-defined set
> of globally visible names and can still have it's own private name
> space. And, here's the important part, "private" things within that
> name space can be "optional" and won't be included in the executable
> if they are not used.
>
> I never figured out how to do that with libraries.
I have not had problems with module libraries. Lots of people do as in
my 90's example above.
However what I am finding in lazy DESIGN, so the library gets structured
relying on compiler to do all the real work, so the library gets poorly
structured, and becomes less portable.
Ends up with being scared of modules and we are getting back to one big
file with all the code in.
--
Paul Carpenter | paul@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate
Reply by Grant Edwards●June 29, 20122012-06-29
On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> In article <jskko0$spl$1@reader1.panix.com>, invalid@invalid.invalid
> says...
>>
>> On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
>> > In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
>> > says...
>> >>
>> >> > Is that with -O2, or whatever the "optimize for size" switch is?
>> >>
>> >> gcc optimize for size is -Os. For dead code elimination you would also
>> >> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
>> >>
>> > I have to use -gc for badly written 3rd party supposed libraries that
>> > are not libraries but a bad collection of project modules forced into
>> > library architecture.
>>
>> The sections/gc options are addictive. Once you get used to them, it
>> becomes pretty painful to have to live without them. They make
>> re-using code way easier, and they also make it a lot easier to
>> enable disable features at link time.
>
> A real pain to prove what actually is used or not used when audited
> for various bodies.
How so? The linker listing shows exactly what's in the executable.
> A real pain when someone else picks up the project and has to wade
> through a large module within a 'library' to check for no side
> effects. To ensure the compiler is really not missing something it
> should not.
>
> Never rely on compiler tricks for correct code reduction of unused
> code, it may change under your feet or between versions and platforms
> or targets.
Yet it's OK to rely on linker tricks for correct code reduction of
unused code when using libraries? ;)
I don't understand why you call it "compiler tricks". It's very
straight forward, and it's the exact same thing that happens with
libraries except it also works with non-global objects.
> What is wrong with writing libraries correctly?
The main thing I found "wrong" was that with the library approach
everything has to be in a single, global name space whether it needs
to be visible outside the module or not. In my experience, that
produces designs that are hard to understand and maintain. You can
end up with unintentional interactions between modules because every
module has to expose internal names.
With the sections/gc approach, a "module" can have a well-defined set
of globally visible names and can still have it's own private name
space. And, here's the important part, "private" things within that
name space can be "optional" and won't be included in the executable
if they are not used.
I never figured out how to do that with libraries.
--
Grant Edwards grant.b.edwards Yow! My NOSE is NUMB!
at
gmail.com
Reply by Paul●June 29, 20122012-06-29
In article <jskko0$spl$1@reader1.panix.com>, invalid@invalid.invalid
says...
>
> On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> > In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
> > says...
> >>
> >> > Is that with -O2, or whatever the "optimize for size" switch is?
> >>
> >> gcc optimize for size is -Os. For dead code elimination you would also
> >> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
> >>
> > I have to use -gc for badly written 3rd party supposed libraries that
> > are not libraries but a bad collection of project modules forced into
> > library architecture.
>
> The sections/gc options are addictive. Once you get used to them, it
> becomes pretty painful to have to live without them. They make
> re-using code way easier, and they also make it a lot easier to
> enable disable features at link time.
A real pain to prove what actually is used or not used when audited
for various bodies.
A real pain when someone else picks up the project and has to wade
through a large module within a 'library' to check for no side effects.
To ensure the compiler is really not missing something it should not.
Never rely on compiler tricks for correct code reduction of unused
code, it may change under your feet or between versions and platforms
or targets.
What is wrong with writing libraries correctly?
--
Paul Carpenter | paul@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate
Reply by Tim Wescott●June 29, 20122012-06-29
On Fri, 29 Jun 2012 10:41:03 +0300, Tauno Voipio wrote:
> On 29.6.12 6:12 , Tim Wescott wrote:
>> On Thu, 28 Jun 2012 09:11:56 +0200, Leo Havmøller wrote:
>>
>>>> I wonder how much is the compiler and how much is the library.
>>>
>>> It's the compiler and linker. Newlib would make the code size explode.
>>
>> Is that with -O2, or whatever the "optimize for size" switch is?
>>
>>
> Compiling the library with -Os makes small wonders here.
Oh man! I want to go try that now -- in my copious spare time, which
seems to be whatever time I spend having insomnia, these days.
--
My liberal friends think I'm a conservative kook.
My conservative friends think I'm a liberal kook.
Why am I not happy that they have found common ground?
Tim Wescott, Communications, Control, Circuits & Software
http://www.wescottdesign.com
Reply by Rob Gaddi●June 29, 20122012-06-29
On Fri, 29 Jun 2012 16:22:24 +0000 (UTC)
Grant Edwards <invalid@invalid.invalid> wrote:
> On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> > In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
> > says...
> >>
> >> > Is that with -O2, or whatever the "optimize for size" switch is?
> >>
> >> gcc optimize for size is -Os. For dead code elimination you would also
> >> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
> >>
> > I have to use -gc for badly written 3rd party supposed libraries that
> > are not libraries but a bad collection of project modules forced into
> > library architecture.
>
> The sections/gc options are addictive. Once you get used to them, it
> becomes pretty painful to have to live without them. They make
> re-using code way easier, and they also make it a lot easier to
> enable disable features at link time.
>
Agreed. They're part of my standard compiler option set; the ones that
just get carried from project to project. I can't see why you wouldn't
use them across the board, especially for an architecture like ARM with
function-local constant pooling.
--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.
Reply by Grant Edwards●June 29, 20122012-06-29
On 2012-06-29, Paul <paul@pcserviceselectronics.co.uk> wrote:
> In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
> says...
>>
>> > Is that with -O2, or whatever the "optimize for size" switch is?
>>
>> gcc optimize for size is -Os. For dead code elimination you would also
>> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
>>
> I have to use -gc for badly written 3rd party supposed libraries that
> are not libraries but a bad collection of project modules forced into
> library architecture.
The sections/gc options are addictive. Once you get used to them, it
becomes pretty painful to have to live without them. They make
re-using code way easier, and they also make it a lot easier to
enable disable features at link time.
--
Grant Edwards grant.b.edwards Yow! I'm young ... I'm
at HEALTHY ... I can HIKE
gmail.com THRU CAPT GROGAN'S LUMBAR
REGIONS!
Reply by Ignacio G.T.●June 29, 20122012-06-29
In article <4FED8CDE.4969F187@bytecraft.com>, walter@bytecraft.com
says...
>
> Tim Wescott wrote:
>
> > On Thu, 28 Jun 2012 05:33:59 +0200, Leo Havm�?ller wrote:
> >
> > >> Don't know about arm-cc, but it is definitely true for gcc vs IAR. IAR
> > >> has a free download (limited to 32 kbytes codesize), so you could just
> > >> try both.
> > >> So, which do you feel is better?
> > >
> > > IAR produces 10-20% smaller code than gcc (Sourcey CodeBench Lite). We
> > > use both.
> >
> > I wonder how much is the compiler and how much is the library. Newlib
> > has some amazing fluff-bombs that you can set off quite unexpectedly
> > (just one example: pow, in the math library, is huge).
>
> I think Tim is correct look carefully for other sources of differences when
> 10%-20% size difference is seen. I have written a code generator for the
> Cortex M3 and I would be surprised if the best to worst code generators
> would make at most a few percent difference in generated code.
>
> It would be interesting to get a measure of the compiler differences to
> compile the same code including libraries on both compilers. This
> may or may not be easy.
>
> w..
When comparing IAR for M32C with Renesas HEW for (Renesas) M32C, I saw a
size difference within that range too (being IAR the winner). The reason
I was told for that --by a Renesas worker-- was that IAR made their
libraries in asm, and Renesas made them in C. Go figure.
--
Saludos.
Ignacio G.T.
Reply by Walter Banks●June 29, 20122012-06-29
Tim Wescott wrote:
> On Thu, 28 Jun 2012 05:33:59 +0200, Leo Havmøller wrote:
>
> >> Don't know about arm-cc, but it is definitely true for gcc vs IAR. IAR
> >> has a free download (limited to 32 kbytes codesize), so you could just
> >> try both.
> >> So, which do you feel is better?
> >
> > IAR produces 10-20% smaller code than gcc (Sourcey CodeBench Lite). We
> > use both.
>
> I wonder how much is the compiler and how much is the library. Newlib
> has some amazing fluff-bombs that you can set off quite unexpectedly
> (just one example: pow, in the math library, is huge).
I think Tim is correct look carefully for other sources of differences when
10%-20% size difference is seen. I have written a code generator for the
Cortex M3 and I would be surprised if the best to worst code generators
would make at most a few percent difference in generated code.
It would be interesting to get a measure of the compiler differences to
compile the same code including libraries on both compilers. This
may or may not be easy.
w..
Reply by Paul●June 29, 20122012-06-29
In article <jsjqcq$lms$1@speranza.aioe.org>, rtxleh@nospam.nospam
says...
>
> > Is that with -O2, or whatever the "optimize for size" switch is?
>
> gcc optimize for size is -Os. For dead code elimination you would also
> use -ffunction-sections and -fdata-sections, and link with -gc-sections.
>
I have to use -gc for badly written 3rd party supposed libraries that
are not libraries but a bad collection of project modules forced into
library architecture.
Examples being board suppprt libraries that include every type of
peripheral support that the processor family has not what your
processor has.
--
Paul Carpenter | paul@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate