Where has -mshort-calls compiler option gone?

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

I have a bootloader which when compiled with gcc4.6.x or 4.7.x (AS6.0/6.1) fits within the 2048 bytes available on an Mega168pa.  To get it to fit I enabled the -mshort-calls option under optimization.

 

With AS6.2 (gcc4.8.x) the option still exists in the GUI but when I try and build the project it gives me the error:

 

avr-gcc.exe(0,0): error: unrecognized command line option '-mshort-calls'

 

If I disable this option it builds but the code has grown by 10% to 2188 bytes and no longer fits in the bootloader section.

 

Does anyone know why the -mshort-calls command line option has been removed from gcc from 4.8 onwards?

 

Cheers

Simon

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

https://gcc.gnu.org/bugzilla/sho...

 

Try using relaxation as recommended in that bug report. Please come back with your findings.

 

> With AS6.2 (gcc4.8.x) the option still exists in the GUI

 

Complain in the AS6 subforum (if such still exists).

 

JW

 

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

JW,

 

Thanks for the reply.  Using those options makes no difference.  I still end up with 2188 bytes.

 

Using gcc 4.6.2 in the past took only 1954 bytes.  So much for progress.

 

Simon

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

Can you please try to compile the code with 4.6.2 but *without* -mshort-calls? Will that produce a different code?

 

I guess not and the difference is elsewhere.

 

If you don't mind, post the source, either here or through PM, so that we can discuss what could be done to reduce the binary.

 

JW

 

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

If I build it with gcc 4.6.2 without -mshort-calls it results in 2106 bytes.  So that option makes a substantial difference, although it doesn't explain all of it.

 

Happy to send the source if you think that will help.  I have already reclaimed the unused interrupt vectors for code etc, so there is little chance for more optimization.

 

Simon

 

 

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

> If I build it with gcc 4.6.2 without -mshort-calls it results in 2106 bytes.

 

Hummm. Relaxation should do the same thing - replace JMP/CALL by RJMP/RCALL wherever possible.

 

Can you please check the disassembly of the gcc-4.8 with-relax compiled binary, whether it still contains JMP/CALLs?

 

> Happy to send the source if you think that will help.

 

Why not give it a try.

 

JW

 

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

Might be getting somewhere.  Looking at the .lss file it has relaxed most of the jmp's to rjmp's, but all the calls are still calls.

 

Looks like a bug in the linker to me.

 

I'll zip up a copy of the AS6.0 version of the project and pm it to you.

 

Simon

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

In the PMd files, I run the makefile (after changing the hardcoded paths - whoever wrote the makefile generator was an idiot), removing -mshort-calls and adding -relax to the linking step, with

avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 4.8.1

GNU ld (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 2.23.2

(both from some of the standalone "toolchains" by Atmel, should match some of the AS6 packages, don't know if matches yours)

and without relax it ends at 0x408a while with relax it ends at 0x3fee and all calls being replaced by rcalls.

 

What is your compiler and linker/binutils version?

 

JW

 

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

Also, how did you specify relaxation?

 

If -mrelax, what if you try -Wl,-relax?

 

JW

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

One more thing - remove all object files before recompiling (make clean, but do it manually to be sure). Any change?

 

JW

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

-mshort-calls has been deprecated for GCC 4.7 and removed in GCC 4.8; cf. the caveats section of GCC 4.7 and GCC 4.8 release notes.

Rationale is that with -mrelax there is an better alternative and users trying to be too smart added -mshort-calls to applications where that option is not appropriate resulting in program crash, resulting in bug reports.

avrfreaks does not support Opera. Profile inactive.

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

Thanks for the suggestions JW.  I was putting the -relax option in the wrong place.  I had it under compiler options not linker options.  When I put -mrelax or -Wl, --relax in the 'Other Linker Flags' under miscellaneous it compiles to 2032 bytes which at least now fits.

 

It doesn't explain why the size has grown from 1954 bytes that gcc 4.6.2 produced.  When I have time I will go through and compare the .lss files from each.

 

Thanks

Simon

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

If it's Studio 6 you are talking about it already has a tick box for doing the relax thing "properly". It's not under compiler options and it's not under linker options but under "Common".

This is because it has to be passed to both compiler and linker.

See here:

 

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

> This is because it has to be passed to both compiler and linker.

 

Why would it be needed for the compiler?

 

JW

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

wek wrote:
> This is because it has to be passed to both compiler and linker.

Why would it be needed for the compiler?

For the actual relaxing, one or the other is sufficient.

 

The compiler option -mrelax simply passes --relax to the linker, for it is the linker which performs the relaxation.

 

If you want debug symbols to survive the relaxation the compiler needs to know, for it is the compiler which embeds the debug symbols.  You tell it with -mrelax.

 

You don't actually need both but if you compile and link in separate steps be sure you specify -mrelax in each step.  If you link without using the driver (avr-gcc) you'll need to specify --relax when you link directly with avr-ld.

 

Specifying -Wl,--relax on the driver command line will perform relaxation at the link stage, but the compiler won't embed relaxation-friendly debug symbols, so the .lss will show 'misalignment' between source code and object code.

 

See a previous discussion:
https://www.avrfreaks.net/forum/s...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Ah, I see.

 

I don't doubt what you say, but what is the reason? I mean, in what way are the debug symbols more linker/relax-friendly when using -mrelax, and how can they be linker/nonrelax-unfriendly (i.e. why couldn't the compiler emit the "relax-friendly debug symbols" all the time, without any switch)?

 

JW

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

I don't doubt what you say, but what is the reason? I mean, in what way are the debug symbols more linker/relax-friendly when using -mrelax, and how can they be linker/nonrelax-unfriendly (i.e. why couldn't the compiler emit the "relax-friendly debug symbols" all the time, without any switch)?

The debug symbols seem to refer to fix offsets in the binary data. If the binary data gets shorter because the CALL's become RCALL's and the JMP's become RJMP's the debug offsets are not updated to reflect this. So the more and more JMP/CALL's that are replaced the further and further away the source annotation gets from the actual code.

 

It basically makes it impossible to debug or even to generate a sensible .lss

 

I suppose if the debug stuff did not used fixed offsets but some other technique to say "these 4 bytes relate that line 47 in foo.c" it would be OK. But if it doesn't use a fixed offset to say which 4 bytes how could it do it in a "relax friendly" way?

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

I don't know the mechanism.  It would be interesting to dig deeper though.  For now I know that specifying -mrelax results in properly placed debug information.  Perhaps that debug info simply assumes that all jmp/call instructions will be relaxed.  If it turns out some can't perhaps you'll still see debug symbol offset at some point in the .lss.

 

I'll have to contrive a test, but not today ;)

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

I found the relevant changes - it's in the assembler, not the compiler:

https://sourceware.org/ml/binuti...

 

and in the "compiler driver" to pass -mrelax both to as and ld:

https://gcc.gnu.org/ml/gcc-patch...

 

I still don't understand what is the reason to retain the original behaviour in as.

 

JW

 

 

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

Interesting.  I wonder if this patch really made it into the latest Atmel toolchain (3.4.4), which was built 2014-04-25.  That's only two weeks after the sourceware.org posts.  I suspect Atmel aren't quite that on-the-ball... but 3.4.4 seems to perform well w.r.t. debug symbols and -mrelax.

 

wek wrote:
I still don't understand what is the reason to retain the original behaviour in as.
It has the potential to break existing code.

 

I expect the old behaviour will eventually become deprecated, then removed altogether, but I wouldn't hold my breath.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Sep 16, 2014 - 11:07 PM