Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » MSPGCC
  • » [Mspgcc-users] eliminate unused function [RSS Feed]

#1 Dec. 14, 2003 11:20:46

Matthias W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


How can I tell mcpgcc not to link unused functions into the target?

example:

func1()
{
}

func2()
{
}

main()
{
func1();
}

func2 should not appear in the elf-file, because it is never called.

I found some gcc options that would do that

-fvtable-gc
Emit special relocations for vtables and virtual function references so that
the linker can identify unused virtual functions and zero out vtable slots
that refer to them. This is most useful with -ffunction-sections' and
-Wl,--gc-sections', in order to also discard the functions themselves.
This optimization requires GNU as and GNU ld. Not all systems support this
option. -Wl,--gc-sections' is ignored without -static'.

But fvtable-gc is not available for mspgcc. Virtual functions and vtables
sound like c++ options; ok I dont need that, but elimination of
unsued function would be good.
Is there a way to achieve this (maybe creating a lib?).

Matthias

Offline

#2 Dec. 15, 2003 08:28:21

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


As simple as:
-ffunction-sections -Wl,--gc-sections -Wl,-uInterruptVectors

BUT...
use with care. If you miss third option to gcc, you lose all interrupt
functions and a startup code. Also, if you're playing with c++, all global
constructors/destructors will be eliminated.

~d



On Sunday 14 December 2003 14:20, Matthias Weingart wrote:
> How can I tell mcpgcc not to link unused functions into the target?
>
> example:
>
> func1()
> {
> }
>
> func2()
> {
> }
>
> main()
> {
> func1();
> }
>
> func2 should not appear in the elf-file, because it is never called.
>
> I found some gcc options that would do that
>
> -fvtable-gc
> Emit special relocations for vtables and virtual function references so
> that the linker can identify unused virtual functions and zero out vtable
> slots that refer to them. This is most useful with -ffunction-sections' and
> -Wl,--gc-sections', in order to also discard the functions themselves. This
> optimization requires GNU as and GNU ld. Not all systems support this
> option. -Wl,--gc-sections' is ignored without -static'.
>
> But fvtable-gc is not available for mspgcc. Virtual functions and vtables
> sound like c++ options; ok I dont need that, but elimination of
> unsued function would be good.
> Is there a way to achieve this (maybe creating a lib?).
>
> Matthias
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now!http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-us***@*ists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/mspgcc-users--
/*****************************************************************
("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
`6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
(_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
_..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
(il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
*****************************************************************/

Offline

#3 Dec. 15, 2003 08:58:31

Matthias W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


On Mon, Dec 15, 2003 at 11:26:14AM +0300, Dmitry wrote:
>
> As simple as:
> -ffunction-sections -Wl,--gc-sections -Wl,-uInterruptVectors

Thx ~d, I tried the first options, but as I wrote in a previous posting
there must be something wrong. The failure is in the elf-file.
The debugger cannot load it also.

>msp430-objdump -DSg main.elf > main.lst
main.elf: .stab: stab entry 0 is corrupt, strx = 0x464c457f, type = 1
main.elf: .stab: stab entry 2 is corrupt, strx = 0x1100, type = 52
main.elf: .stab: stab entry 4 is corrupt, strx = 0xb000e, type = 68
debug_record_line: no current unit
Last stabs entries before error:
n_type n_desc n_value string
2 105 00000001
NOMAP 32 00280000 OCUME~1/XHKJAMES/LOCALS~1/Temp/cc07sSok.s
SLINE 55 00000000


msp430-gcc main.c -mmcu=msp430x149 -g -O2 -ffunction-sections -Wl,--gc-sections
-o main.elf
msp430-objdump -DSg main.elf > main.lst
msp430-objcopy -O ihex main.elf main.hex

and this is main.c:

func1()
{
}

func2()
{
}

main()
{
func1();
}

Matthias

Offline

#4 Dec. 15, 2003 09:04:54

D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


Again, do not forget -Wl,-uInterruptVector !!!
I just tried:
msp430-gcc m.c -mmcu=msp430x149 -O2 -ffunction-sections
-Wl,--gc-sections

-Wl,-uInterruptVectors -o main.elf -g

And it works fine.
~d


On Monday 15 December 2003 11:58, Matthias Weingart wrote:
> On Mon, Dec 15, 2003 at 11:26:14AM +0300, Dmitry wrote:
> > As simple as:
> > -ffunction-sections -Wl,--gc-sections -Wl,-uInterruptVectors
>
> Thx ~d, I tried the first options, but as I wrote in a previous posting
> there must be something wrong. The failure is in the elf-file.
> The debugger cannot load it also.
>
> >msp430-objdump -DSg main.elf > main.lst
>
> main.elf: .stab: stab entry 0 is corrupt, strx = 0x464c457f, type = 1
> main.elf: .stab: stab entry 2 is corrupt, strx = 0x1100, type = 52
> main.elf: .stab: stab entry 4 is corrupt, strx = 0xb000e, type = 68
> debug_record_line: no current unit
> Last stabs entries before error:
> n_type n_desc n_value string
> 2 105 00000001
> NOMAP 32 00280000 OCUME~1/XHKJAMES/LOCALS~1/Temp/cc07sSok.s
> SLINE 55 00000000
>
>
> msp430-gcc main.c -mmcu=msp430x149 -g -O2 -ffunction-sections
> -Wl,--gc-sections -o main.elf msp430-objdump -DSg main.elf > main.lst
> msp430-objcopy -O ihex main.elf main.hex
>
> and this is main.c:
>
> func1()
> {
> }
>
> func2()
> {
> }
>
> main()
> {
> func1();
> }
>
> Matthias
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now!http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-us***@*ists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/mspgcc-users--
/*****************************************************************
("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
`6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
(_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
_..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
(il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
*****************************************************************/

Offline

#5 Dec. 15, 2003 09:32:57

Matthias W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


Oh sorry, I misunderstood you. I need to have the option -uInterruptVector!
Good to know, something for the docs.

M.

On Mon, Dec 15, 2003 at 12:02:56PM +0300, Dmitry wrote:
> Again, do not forget -Wl,-uInterruptVector !!!
> I just tried:
> msp430-gcc m.c -mmcu=msp430x149 -O2 -ffunction-sections
> -Wl,--gc-sections
>
> -Wl,-uInterruptVectors -o main.elf -g
>
> And it works fine.
> ~d
>
>
> On Monday 15 December 2003 11:58, Matthias Weingart wrote:
> > On Mon, Dec 15, 2003 at 11:26:14AM +0300, Dmitry wrote:
> > > As simple as:
> > > -ffunction-sections -Wl,--gc-sections -Wl,-uInterruptVectors
> >
> > Thx ~d, I tried the first options, but as I wrote in a previous posting
> > there must be something wrong. The failure is in the elf-file.
> > The debugger cannot load it also.
> >
> > >msp430-objdump -DSg main.elf > main.lst
> >
> > main.elf: .stab: stab entry 0 is corrupt, strx = 0x464c457f, type = 1
> > main.elf: .stab: stab entry 2 is corrupt, strx = 0x1100, type = 52
> > main.elf: .stab: stab entry 4 is corrupt, strx = 0xb000e, type = 68
> > debug_record_line: no current unit
> > Last stabs entries before error:
> > n_type n_desc n_value string
> > 2 105 00000001
> > NOMAP 32 00280000 OCUME~1/XHKJAMES/LOCALS~1/Temp/cc07sSok.s
> > SLINE 55 00000000
> >
> >
> > msp430-gcc main.c -mmcu=msp430x149 -g -O2 -ffunction-sections
> > -Wl,--gc-sections -o main.elf msp430-objdump -DSg main.elf > main.lst
> > msp430-objcopy -O ihex main.elf main.hex
> >
> > and this is main.c:
> >
> > func1()
> > {
> > }
> >
> > func2()
> > {
> > }
> >
> > main()
> > {
> > func1();
> > }
> >
> > Matthias
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: IBM Linux Tutorials.
> > Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> > Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> > Click now!http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click> > _______________________________________________
> > Mspgcc-users mailing list
> > Mspgcc-us***@*ists.sourceforge.net
> >https://lists.sourceforge.net/lists/listinfo/mspgcc-users>
> --
> /*****************************************************************
> ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ
> `6_ 6 ) `-. ( ).`-.__.`) State Polytechnical Univ.
> (_Y_.)' ._ ) `._ `. ``-..-' Radio-Physics Departament
> _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia
> (il),-'' (li),' ((!.-' +7 (812) 5403923, 5585314
> *****************************************************************/
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now!http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/mspgcc-usersMatthias

Offline

#6 Dec. 16, 2003 21:21:25

Hunter W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function


Is there a reason -ffunction-sections causes msp430-gcc to emit the
warning:

"cc1: warning: -ffunction-sections may affect debugging on some targets"

This warning doesn't show on the x86-linux and arm-elf target gcc's so
I figure it is port specific. The reason that I ask is that our project
uses -Werror and I'd like to use function sections on the msp without
removing -Werror (a safety check that we like).

- Hunter

--
Hunter Ware <hw***@*rivaris.com> ,,, I doubt,
Senior Software Engineer (o o) therefore I may be.
==============================oOO==(_)==OOo==============================
When I die, I want to go peacefully in my sleep like my Dad,
not in a screaming panic.... like his passengers.

Offline

#7 June 19, 2017 00:54:09

RobertIrren
Registered: 2017-06-18
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function

This post is being moderated

Offline

#8 June 19, 2017 16:22:42

ArthurGoame
Registered: 2017-06-19
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function

This post is being moderated

Offline

#9 June 20, 2017 02:29:55

HaroldHig
Registered: 2017-06-19
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function

This post is being moderated

Offline

#10 June 20, 2017 13:01:57

Antoniozooth
Registered: 2017-06-20
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

[Mspgcc-users] eliminate unused function

This post is being moderated

Offline

  • Root
  • » MSPGCC
  • » [Mspgcc-users] eliminate unused function [RSS Feed]

Board footer

Moderator control

Enjoy the 26th of September
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support