Quantcast

msp430-elf-g++ optimizing out main()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

msp430-elf-g++ optimizing out main()

Wylder Keane-2
I've been using the new msp430-elf-g++ released on 2014-09-03 to build and
debug, and while attempting to reduce the binary size I've added the
following arguments for the compilation and linking phases (except
gc-sections is linker only).

-fdata-sections -ffunction-section -nodefaultlibs --gc-sections

While greatly reducing the code space, it also seems to think main() isn't
a root and optimizes it away... needless to say this isn't very good.

As far as I can tell it is the combination of these compiler flags that
product the result, and I can reproduce it with the blink example by adding
those flags and changing the compiler to msp430-elf-g++.

If I remove either the --gc-sections, or the -nodefaultlibs flags, it then
complains that the .text section is over by 90Kb... so basically I need to
stip away all stdc++ implicit references to make the code fit, and unused
code in my codebase.

Does anyone have an idea as to how I can tell the compiler to not link in
the stdc++ library that seems to bloat the .text section?

-Wylder

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

DJ Delorie

main() is not a root with gcc, start() is (defined by your linker
script), and is usually provided by crt0.o - except you told it not to
with -nodefaultlibs.

The flag you really want is -minrt, which tells gcc to encode extra
information in each object that helps the linker reduce the amount of
runtime needed to only the routines that will actually do something
useful (and, most likely, remove C++ constructors/destructors at the
same time).

If even with that flag the code still doesn't fit, add
-Wl,-Map,somemap.txt and see *what* functions are getting included,
and why.  It may turn out to be something silly.

Also, if main() returns a value, the runtime may include extra
processing to happen at exit() time, which is kinda pointless on an
MCU.  main() should end in a while(1); so it doesn't return.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

Wylder Keane-2
Interesting that main() is not considered a root with gcc. The crt0.S start
code which references main is in the binary that is generated event with
the nodefaultlibs call. The minrt flag and it doesn't seem to make a
difference.

The map file is telling me a few small functions are being linked in
(memset, memcpy) and I assume that since the standard library wasn't built
with -ffunction-sections or -fdata-sections that it then links the entire
library.

Also, seeing a lot of exception handling code from libstdc++ as well
despite specifying -fno-exceptions, -fno-rtti, and -fno-enforce-eh-specs.
Is this also a side effect of the library not being build with those
sections flags? If so, why isn't the library built like that for cases like
this where you want to have only a few small functions?

I'm going to remove all references to the official memset, memcpy, etc. and
see if that fixes the issue.

-Wylder

On Tue, Sep 23, 2014 at 4:04 PM, DJ Delorie <[hidden email]> wrote:

>
> main() is not a root with gcc, start() is (defined by your linker
> script), and is usually provided by crt0.o - except you told it not to
> with -nodefaultlibs.
>
> The flag you really want is -minrt, which tells gcc to encode extra
> information in each object that helps the linker reduce the amount of
> runtime needed to only the routines that will actually do something
> useful (and, most likely, remove C++ constructors/destructors at the
> same time).
>
> If even with that flag the code still doesn't fit, add
> -Wl,-Map,somemap.txt and see *what* functions are getting included,
> and why.  It may turn out to be something silly.
>
> Also, if main() returns a value, the runtime may include extra
> processing to happen at exit() time, which is kinda pointless on an
> MCU.  main() should end in a while(1); so it doesn't return.
>

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

DJ Delorie

> The map file is telling me a few small functions are being linked in
> (memset, memcpy) and I assume that since the standard library wasn't built
> with -ffunction-sections or -fdata-sections that it then links the entire
> library.

-ffunction-sections affects multiple functions in the same object.  It
has no effect on separate objects.  Functions like memcpy() and
memset() are in separate source files in the library, so will be
linked in or not depending only on whether or not they're actually
needed.

> Is this also a side effect of the library not being build with those
> sections flags? If so, why isn't the library built like that for
> cases like this where you want to have only a few small functions?

One could argue that the library should be built with whatever flags
the user specifies.  This quickly turns into thousands, if not
millions, of permutations of builds, and is not practical.  The only
way to solve this is to build the whole library as part of your
project, so you can choose the flags you want.

Also, the -ffunction-section and -fdata-section flags are mostly
useless for the standard libraries *anyway*, as, as I mentioned
already, they're already broken into one function per section.

The -minrt option is designed to work mostly with the startup code, by
selectively linking in parts of (what is normally) crt0.s based on a
more "global" knowledge of features used by the program.  If you use a
C++ function that uses exceptions, the exception startup gets linked
in.  Without -minrt, the exception startup gets linked in even if
nothing uses exceptions.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

Grant Edwards-6
In reply to this post by Wylder Keane-2
On 2014-09-23, Wylder Keane <[hidden email]> wrote:
> I've been using the new msp430-elf-g++ released on 2014-09-03 to build and
> debug, and while attempting to reduce the binary size I've added the
> following arguments for the compilation and linking phases (except
> gc-sections is linker only).
>
> -fdata-sections -ffunction-section -nodefaultlibs --gc-sections
>
> While greatly reducing the code space, it also seems to think main() isn't
> a root and optimizes it away... needless to say this isn't very good.

A would guess that the -nodefaultlibs option is preventing the
inclusion of the standard startup code, which is what normally calls
main().  That unresolved reference to main is what would normally
cause the linker to pull in main.

You can probably work around it by passing -u main to the linker, but
unless there is startup code calling main it won't really matter
whether it's linked in or not.

--
Grant Edwards               grant.b.edwards        Yow! Should I do my BOBBIE
                                  at               VINTON medley?
                              gmail.com            


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

Grant Edwards-6
In reply to this post by Wylder Keane-2
On 2014-09-23, Wylder Keane <[hidden email]> wrote:

> Interesting that main() is not considered a root with gcc. The crt0.S start
> code which references main is in the binary that is generated event with
> the nodefaultlibs call.

So you end up with an uresolved reference to main when using
--gc-sections et al?

--
Grant Edwards               grant.b.edwards        Yow! Your CHEEKS sit like
                                  at               twin NECTARINES above
                              gmail.com            a MOUTH that knows no
                                                   BOUNDS --


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: msp430-elf-g++ optimizing out main()

Wylder Keane-2
Looking at the disassembly again, the reference to main is not there, it
seems to strip it out. If you look at the crt0.S file it has a reference to
it though so I'm slightly confused by why it is removed. From what I
understood the -nodefaultlibs flag only removed default libraries, not
startup code, whereas -nostdlib removed both.

I tried the minrt flag with no luck, exception code is still linked in. Is
it possible the -fno-exceptions flag isn't making it through? It also seems
like i'm getting some cio calls and malloc despite not calling those
functions anywhere...

Also, I've encountered the (known) issue where -ffunction-sections breaks
debugging symbols, is there any change of this being fixed in the future or
is it too obscure?

On Wed, Sep 24, 2014 at 7:27 AM, Grant Edwards <[hidden email]>
wrote:

> On 2014-09-23, Wylder Keane <[hidden email]> wrote:
>
> > Interesting that main() is not considered a root with gcc. The crt0.S
> start
> > code which references main is in the binary that is generated event with
> > the nodefaultlibs call.
>
> So you end up with an uresolved reference to main when using
> --gc-sections et al?
>
> --
> Grant Edwards               grant.b.edwards        Yow! Your CHEEKS sit
> like
>                                   at               twin NECTARINES above
>                               gmail.com            a MOUTH that knows no
>                                                    BOUNDS --
>
>
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> Mspgcc-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Loading...