Remove .fini9/.fini0 from executable?

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

My main() never return/exit, it's declared as:

void main(void) __attribute__ ((OS_main)) __attribute__ ((noreturn));

which produce the smaller code, however I noticed that in the .lss it still does a call to main then a jmp to _exit that fallback to __stop_program which loops on itself.

How can I remove those .finiN sections? Do I have to modify the .x linker file? Can I do it with some __attribute__? I know it's only about 8 bytes but if it's possible, I'd like to know how :?

Any input from the pro?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Do I have to modify the .x linker file?

Yes.

    *(.fini9)  /* _exit() starts here.  */
    KEEP (*(.fini9))
    *(.fini8)
    KEEP (*(.fini8))
    *(.fini7)
    KEEP (*(.fini7))
    *(.fini6)  /* C++ destructors.  */
    KEEP (*(.fini6))
    *(.fini5)
    KEEP (*(.fini5))
    *(.fini4)
    KEEP (*(.fini4))
    *(.fini3)
    KEEP (*(.fini3))
    *(.fini2)
    KEEP (*(.fini2))
    *(.fini1)
    KEEP (*(.fini1))
    *(.fini0)  /* Infinite loop after program termination.  */
    KEEP (*(.fini0))

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Cliff! I removed this section from my avr5.x file and relinked, _exit and __stop_program dissapeared, I still have the "call main" and "jmp exit" I guess I will have to declare my main as init9

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I still have the "call main" and "jmp exit"

See the source of gcrt1.S here:

http://svn.savannah.nongnu.org/v...

Seems to me that the CALL is unavoidable:

	.section .init9,"ax",@progbits
#ifdef __AVR_ASM_ONLY__
	XJMP	main
#else	/* !__AVR_ASM_ONLY__ */
	XCALL	main
	XJMP	exit
#endif	/* __AVR_ASM_ONLY__ */

though you could ditch .init9 from the .x and then just make main() "naked" and in one of the later .init sections - maybe .init8?

I'm intrigued by this - which AVR is it that is so tight that 4/5 words of code matter? And if space is so tight why use C anyway? For one thing, if you aren't using all the vectors I'd ditch the entire vector table and then just hand assemble (in a .S) a cut-down thing like gcrt1.S maybe using the unused vectors for something like fixed data storage (or even a small routine?) and stopping at the last used vector so you aren't wasting space with vector jumps you don't need.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's an ATMEGA168, I still have about 400 bytes of flash to play with, I more wanted to know how it worked rather than save 4 or 5 bytes :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Build an "empty" program. I get the following:

Device: atmega168

Program:     138 bytes (0.8% Full)

Of those 138 bytes 100 of them are:

   4:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
   8:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
   c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  10:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  14:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  18:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  1c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  20:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  24:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  28:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  2c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  30:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  34:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  38:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  3c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  40:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  44:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  48:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  4c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  50:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  54:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  58:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  5c:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  60:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>
  64:	0c 94 3e 00 	jmp	0x7c	; 0x7c <__bad_interrupt>

That, IMAO, is where the real saving is to be made, far better than 4/5 words (8/10 bytes)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I'm intrigued by this - which AVR is it that is so tight that 4/5 words of code matter? And if space is so tight why use C anyway? For one thing, if you aren't using all the vectors I'd ditch the entire vector table and then just hand assemble (in a .S) a cut-down thing like gcrt1.S maybe using the unused vectors for something like fixed data storage (or even a small routine?) and stopping at the last used vector so you aren't wasting space with vector jumps you don't need.
Depending partly on their skill sets,
different people will have different ideas of low-hanging fruit.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skeeve wrote:
Depending partly on their skill sets,
different people will have different ideas of low-hanging fruit.
True. But that does not mean that what that person perceives as "low-hanging" fruit is the fruit he should be jumping for.

Simple example: Let's suppose the OP is working to remove just 5 more bytes to fit the program in to his AVR. On the other hand, he has some floating point code and spaced out including libm.a. Result: He's stepping over 2000 bytes (difference between the crappy generic FP library and the hand-crafted libm code) to save 5.

Even worse: He's passing a variable to _delay_ms(). By misusing the _delay_ms() function, he's picked up over 3000 bytes of crappy generic floating point library that he doesn't need for code that won't work as he expects.

Peter Viscarola wrote an opinion piece in "The NT Insider" (Open Systems Resources) that newbies often post questions that are the equivalent to "Why won't wings stay glued to my pig?" Instead of answering with, "Did you use superglue? Try using epoxy.", you might want to ask why he wants wings on a pig. If he answers, "my truck is broken down and I want to get to the next farm", it is now far more likely you'll be able to help him achieve what he wants.

Of course, there are always those who insist that, if they can just get the wings to stick, the pig will fly. Sometimes it's better to show them and let them deal with the annoyed pig! :twisted:

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just wanted to know how it worked :)
And believe me my program is very optimized, next step is to rewrite some part in assembler, and even doing this, I doubt I'll gain 10%.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stu_san wrote:
skeeve wrote:
Depending partly on their skill sets,
different people will have different ideas of low-hanging fruit.
True. But that does not mean that what that person perceives as "low-hanging" fruit is the fruit he should be jumping for.
Sometimes, as in this case it does.
If one needs five words, fifty isn't necessarily going to help more.
Go for the easiest five that work.
Quote:
Simple example: Let's suppose the OP is working to remove just 5 more bytes to fit the program in to his AVR. On the other hand, he has some floating point code and spaced out including libm.a. Result: He's stepping over 2000 bytes (difference between the crappy generic FP library and the hand-crafted libm code) to save 5.

Even worse: He's passing a variable to _delay_ms(). By misusing the _delay_ms() function, he's picked up over 3000 bytes of crappy generic floating point library that he doesn't need for code that won't work as he expects.

You forgot to add -O0.
Quote:
Peter Viscarola wrote an opinion piece in "The NT Insider" (Open Systems Resources) that newbies often post questions that are the equivalent to "Why won't wings stay glued to my pig?" Instead of answering with, "Did you use superglue? Try using epoxy.", you might want to ask why he wants wings on a pig. If he answers, "my truck is broken down and I want to get to the next farm", it is now far more likely you'll be able to help him achieve what he wants.
All too often such responses are more condescending than informative.
Quote:
Of course, there are always those who insist that, if they can just get the wings to stick, the pig will fly. Sometimes it's better to show them and let them deal with the annoyed pig!
Sometimes they want an annoyed flying pig,
but will settle for an annoyed gliding pig.

Getting back to the fruit analogy,
sometimes the poster has indeed figured out that that blackberry is really a bowling ball.
He would really like to know what's holding it up.

My suggestion for answering foolish requests:
If it's easy, answer the question as asked.
Add whatever additional information necessary to make him see the error of his ways.
If it's not easy and more information would make it easy,
ask for the information.
Add whatever information necessary to make him see the error of his ways.
If it's hard regardless, say so.
You might even say what makes it hard.
Add whatever additional information necessary to make him see the error of his ways.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stu_san wrote:
skeeve wrote:
Depending partly on their skill sets,
different people will have different ideas of low-hanging fruit.
True. But that does not mean that what that person perceives as "low-hanging" fruit is the fruit he should be jumping for.
Sometimes, as in this case it does.
If one needs five words, fifty isn't necessarily going to help more.
Go for the easiest five that work.
Quote:
Simple example: Let's suppose the OP is working to remove just 5 more bytes to fit the program in to his AVR. On the other hand, he has some floating point code and spaced out including libm.a. Result: He's stepping over 2000 bytes (difference between the crappy generic FP library and the hand-crafted libm code) to save 5.

Even worse: He's passing a variable to _delay_ms(). By misusing the _delay_ms() function, he's picked up over 3000 bytes of crappy generic floating point library that he doesn't need for code that won't work as he expects.

You forgot to add -O0.
Quote:
Peter Viscarola wrote an opinion piece in "The NT Insider" (Open Systems Resources) that newbies often post questions that are the equivalent to "Why won't wings stay glued to my pig?" Instead of answering with, "Did you use superglue? Try using epoxy.", you might want to ask why he wants wings on a pig. If he answers, "my truck is broken down and I want to get to the next farm", it is now far more likely you'll be able to help him achieve what he wants.
All too often such responses are more condescending than informative.
Quote:
Of course, there are always those who insist that, if they can just get the wings to stick, the pig will fly. Sometimes it's better to show them and let them deal with the annoyed pig!
Sometimes they want an annoyed flying pig,
but will settle for an annoyed gliding pig.

Getting back to the fruit analogy,
sometimes the poster has indeed figured out that that blackberry is really a bowling ball.
He would really like to know what's holding it up.

My suggestion for answering foolish requests:
If it's easy, answer the question as asked.
Add whatever additional information necessary to make him see the error of his ways.
If it's not easy and more information would make it easy,
ask for the information.
Add whatever information necessary to make him see the error of his ways.
If it's hard regardless, say so.
You might even say what makes it hard.
Add whatever additional information necessary to make him see the error of his ways.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not a newb!! I'm 39yo and started coding in Z80 assembly at 12yo, I have a master's degree in CS too.

Even if I already wrote Pascal->68000 compiler in Eiffel and also in C, I never checked how the low level gcc stuff was working, the gcrt1.S and all. I understand that the _exit() is to catch return of main() but it should be an option in avr-gcc because I doubt a lot of people return from their main()...

Want me to show you my optimization string and my delay function? :roll:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stu_san wrote:
skeeve wrote:
Depending partly on their skill sets,
different people will have different ideas of low-hanging fruit.
True. But that does not mean that what that person perceives as "low-hanging" fruit is the fruit he should be jumping for.
Sometimes, as in this case it does.
If one needs five words, fifty isn't necessarily going to help more.
Go for the easiest five that work.
Quote:
Simple example: Let's suppose the OP is working to remove just 5 more bytes to fit the program in to his AVR. On the other hand, he has some floating point code and spaced out including libm.a. Result: He's stepping over 2000 bytes (difference between the crappy generic FP library and the hand-crafted libm code) to save 5.

Even worse: He's passing a variable to _delay_ms(). By misusing the _delay_ms() function, he's picked up over 3000 bytes of crappy generic floating point library that he doesn't need for code that won't work as he expects.

You forgot to add -O0.
Quote:
Peter Viscarola wrote an opinion piece in "The NT Insider" (Open Systems Resources) that newbies often post questions that are the equivalent to "Why won't wings stay glued to my pig?" Instead of answering with, "Did you use superglue? Try using epoxy.", you might want to ask why he wants wings on a pig. If he answers, "my truck is broken down and I want to get to the next farm", it is now far more likely you'll be able to help him achieve what he wants.
All too often such responses are more condescending than informative.
Quote:
Of course, there are always those who insist that, if they can just get the wings to stick, the pig will fly. Sometimes it's better to show them and let them deal with the annoyed pig!
Sometimes they want an annoyed flying pig,
but will settle for an annoyed gliding pig.

Getting back to the fruit analogy,
sometimes the poster has indeed figured out that that blackberry is really a bowling ball.
He would really like to know what's holding it up.

My suggestion for answering foolish requests:
If it's easy, answer the question as asked.
Add whatever additional information necessary to make him see the error of his ways.
If it's not easy and more information would make it easy,
ask for the information.
Add whatever information necessary to make him see the error of his ways.
If it's hard regardless, say so.
You might even say what makes it hard.
Add whatever additional information necessary to make him see the error of his ways.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Magister wrote:
I'm not a newb!! I'm 39yo and started coding in Z80 assembly at 12yo, I have a master's degree in CS too.
Cool. I'm a 54 year-old who started programming in Basic on an HP TimeShareBasic system back in 1970 when the only access was a Teletype attached to a 110 baud acoustic coupler modem. I did not take a class in programming until 4 years after that start, yet had a job programming the first summer after I first learned. I built my own computer (as in soldered the boards) at 17. I paid my way through college by programming in Fortran, Cobol (*shudder*) and Assembly. I've worked on more that 30 different types of computers, from an ancient Univac SolidState-80 (vintage 1962), through DEC, UNIVAC ( 1107/8 ), HP, IBM, Apollo, CDC, Motorola, Intel, ARM, and Atmel. I've taught 3 semesters of Beginning Pascal. I've made my living programming in at least 6 different computer languages and assembly language on at least 4 different processors, one of them being the Atmel AVR. I was on the engineering team for the HP PA-RISC 8000 microprocessor (their first 64-bit micro, 4-instruction superscalar) in 1993-95. I've done production code for applications ranging from graphical design systems to embedded processors, from accounting systems to resource mapping, from servo systems to compilers.

Wanna compare scars? :evil:

And after all the above I realize that I'm far from the most experienced and brightest person on this forum. I have been wrong in the past and, being human, will be in the future. I learn far more from this forum than I ever give.

Magister, my comment was not directed at you, per se, but at Michael's comment about "low-hanging fruit". I agreed with Cliff that there were other ways to pick up 4-5 bytes. My point was that, according to your initial post, it appeared you were fighting for every last byte. Sometimes people wedge themselves down a rat hole when, if they looked up, they could find a much easier solution to their perceived problem.

I am sorry you took offense, that was not my intent. I admit I missed your comment about not needing the 4-5 bytes but instead wanting to know how things work - that is always an admirable goal.

Pax?

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hahaha no problem stu :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stu_san wrote:
Magister, my comment was not directed at you, per se, but at Michael's comment about "low-hanging fruit".
It was still uncalled-for.
Quote:
I agreed with Cliff that there were other ways to pick up 4-5 bytes.
To me, *the* other way Cliff suggested was as least as esoteric as removing a .fini .
Cliff might reasonably have thought otherwise.
It was a close enough case to be decided
by the skill set of the person doing it.
Sometimes, what one ought to do depends on what one can do.
Quote:
My point was that, according to your initial post, it appeared you were fighting for every last byte. Sometimes people wedge themselves down a rat hole when, if they looked up, they could find a much easier solution to their perceived problem.
Quote:
I am sorry you took offense, that was not my intent. I admit I missed your comment about not needing the 4-5 bytes but instead wanting to know how things work - that is always an admirable goal.

Pax?

Stu

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles