Any gotchas using --relax

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

I am hoping that someone might be able to provide some insight in to problems I am encountering using the --relax linker directive

I have a project in my care that for historic reasons uses the 20070122 toolset to compile for the Atmega2560

I need to make space in this project to add a couple of new features and hoped to make use of the 3kB (approx) that I can see following trampolines
Unfortunately if I use the -Wl,--relax directive the code does not seem to link correctly:
- the space behind the trampolines is used as I would expect
- but the code does not work: function calls go awry and I am finding it difficult to see any pattern as to where or why
This makes it pretty difficult to debug what to try next: so I'm hopping there might be some suggestions here?

If I use WinAVR-20100110 (the most recent tool chain I have to hand) the code will link correctly IFF I use the --relax directive (otherwise it runs out of space)
- however with this version of the tool chain I find that the code generated is bigger than in the 20070122 case without the --relax directive
- hence I am returned to square one needing to find space to add the bits I require

Being able to recover the space I can see via --relax on the 20070122 would be the quickest win I could get here

Thanks in advance for any suggestions that might be offered
(I will investigate what happens under the recent version 3.4.1 of the toolchain)

All the best,
sd

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

Quote:

(the most recent tool chain I have to hand)

Then try Atmel's Toolchain 3.4.2 which contains compiler 4.7.2.

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

Thanks
- I'm currently working through the changes I need to do to see if Toolchain 3.4.2 gives any gains (renaming ISR vectors & repositioning "const" keywords mostly)
- I'll keep my fingers crossed
sd

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

Quote:
which contains compiler 4.7.2.

Isn't it the same as
Quote:
If I use WinAVR-20100110
?

Quote:
Being able to recover the space

any
const char[]

in ram?

No RSTDISBL, no fun!

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

Quote:

Isn't it the same as

WinAVR20100110 contains avr-gcc 4.3.3

The Atmel version contains 4.7.2 which has lots of "goodies" like __flash and is considerably "newer" by about 3 years. There are bug fixes, new features and in my experience the code generation is better.

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

Quote:
WinAVR20100110 contains avr-gcc 4.3.3

Oops, I have just noticed that I have WinAVR2010010 on hdd but my avr-gcc is 4.7.2 and from there I can see I had to upgrade avr-gcc in the meantime but I have no idea when :?:

No RSTDISBL, no fun!

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

I've spend the best part of the day getting the code to play nicely with the 4.7.2. compiler
- and I find that I am encountering pretty similar behaviour (but at least on a compiler from the correct decade!)

There is around 98% of the Chip flash used if I do not issue --relax and 94.8 if I do
- but the "relaxed" code fails; whereas the code works nicely without

So it is apparent that the linker is doing something based on the --relax but ending up with code that does not run correctly
- is it likely I have failed to specify something somewhere else which is causing this?

- the compiler options are:

avr-gcc -Os -Wundef -Wall -gdwarf-2 -mcall-prologues -fno-strict-aliasing -frename-registers -DCOMPILER_GCC -mmcu=atmega2560 -std=gnu99 -DARCH_AVR

- and those for the linker:

avr-gcc -mmcu=atmega2560 -gdwarf-2 -Wl,-T,C:\{buildpath}avr8_local.x -Wl,--relax -Wl,-defsym=__heap_end=0x80ffff,-Map,linker.map 

The linker scrip is there to configure external memory & looks like:

/* based on default linker script, for normal executables, but with external memory definitions*/
__xram_start_address = 0x2200 ;
OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
OUTPUT_ARCH(avr:6)
MEMORY
{
  text   (rx)   : ORIGIN = 0, LENGTH = 1024K
  data   (rw!x) : ORIGIN = 0x800200, LENGTH = 0xfe00
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
  fuse      (rw!x) : ORIGIN = 0x820000, LENGTH = 1K
  lock      (rw!x) : ORIGIN = 0x830000, LENGTH = 1K
  signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K
  user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = 1K
}
SECTIONS
{
  /* Read-only sections, merged into text segment: */
  .hash          : { *(.hash)		}
  .dynsym        : { *(.dynsym)		}
  .dynstr        : { *(.dynstr)		}
  .gnu.version   : { *(.gnu.version)	}
  .gnu.version_d   : { *(.gnu.version_d)	}
  .gnu.version_r   : { *(.gnu.version_r)	}
  .rel.init      : { *(.rel.init)		}
  .rela.init     : { *(.rela.init)	}
  .rel.text      :
    {
      *(.rel.text)
      *(.rel.text.*)
      *(.rel.gnu.linkonce.t*)
    }
  .rela.text     :
    {
      *(.rela.text)
      *(.rela.text.*)
      *(.rela.gnu.linkonce.t*)
    }
  .rel.fini      : { *(.rel.fini)		}
  .rela.fini     : { *(.rela.fini)	}
  .rel.rodata    :
    {
      *(.rel.rodata)
      *(.rel.rodata.*)
      *(.rel.gnu.linkonce.r*)
    }
  .rela.rodata   :
    {
      *(.rela.rodata)
      *(.rela.rodata.*)
      *(.rela.gnu.linkonce.r*)
    }
  .rel.data      :
    {
      *(.rel.data)
      *(.rel.data.*)
      *(.rel.gnu.linkonce.d*)
    }
  .rela.data     :
    {
      *(.rela.data)
      *(.rela.data.*)
      *(.rela.gnu.linkonce.d*)
    }
  .rel.ctors     : { *(.rel.ctors)	}
  .rela.ctors    : { *(.rela.ctors)	}
  .rel.dtors     : { *(.rel.dtors)	}
  .rela.dtors    : { *(.rela.dtors)	}
  .rel.got       : { *(.rel.got)		}
  .rela.got      : { *(.rela.got)		}
  .rel.bss       : { *(.rel.bss)		}
  .rela.bss      : { *(.rela.bss)		}
  .rel.plt       : { *(.rel.plt)		}
  .rela.plt      : { *(.rela.plt)		}
  /* Internal text space or external memory.  */
  .text :
  {
    *(.vectors)
    KEEP(*(.vectors))
    /* For data that needs to reside in the lower 64k of progmem.  */
    *(.progmem.gcc*)
    *(.progmem*)
    . = ALIGN(2);
     __trampolines_start = . ;
    /* The jump trampolines for the 16-bit limited relocs will reside here.  */
    *(.trampolines)
    *(.trampolines*)
     __trampolines_end = . ;
    /* For future tablejump instruction arrays for 3 byte pc devices.
       We don't relax jump/call instructions within these sections.  */
    *(.jumptables)
    *(.jumptables*)
    /* For code that needs to reside in the lower 128k progmem.  */
    *(.lowtext)
    *(.lowtext*)
     __ctors_start = . ;
     *(.ctors)
     __ctors_end = . ;
     __dtors_start = . ;
     *(.dtors)
     __dtors_end = . ;
    KEEP(SORT(*)(.ctors))
    KEEP(SORT(*)(.dtors))
    /* From this point on, we don't bother about wether the insns are
       below or above the 16 bits boundary.  */
    *(.init0)  /* Start here after reset.  */
    KEEP (*(.init0))
    *(.init1)
    KEEP (*(.init1))
    *(.init2)  /* Clear __zero_reg__, set up stack pointer.  */
    KEEP (*(.init2))
    *(.init3)
    KEEP (*(.init3))
    *(.init4)  /* Initialize data and BSS.  */
    KEEP (*(.init4))
    *(.init5)
    KEEP (*(.init5))
    *(.init6)  /* C++ constructors.  */
    KEEP (*(.init6))
    *(.init7)
    KEEP (*(.init7))
    *(.init8)
    KEEP (*(.init8))
    *(.init9)  /* Call main().  */
    KEEP (*(.init9))
    *(.text)
    . = ALIGN(2);
    *(.text.*)
    . = ALIGN(2);
    *(.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))
     _etext = . ;
  }  > text
  
  .data	  : AT (ADDR (.text) + SIZEOF (.text))
  {
     PROVIDE (__data_start = .) ;
    /* --gc-sections will delete empty .data. This leads to wrong start
       addresses for subsequent sections because -Tdata= from the command
       line will have no effect, see PR13697.  Thus, keep .data  */
    KEEP (*(.data))
    *(.data*)
    *(.rodata)  /* We need to include .rodata here if gcc is used */
    *(.rodata*) /* with -fdata-sections.  */
    *(.gnu.linkonce.d*)
    . = ALIGN(2);
     _edata = . ;
     PROVIDE (__data_end = .) ;
  }  > data
  
   __data_load_start = LOADADDR(.data);
   __data_load_end = __data_load_start + SIZEOF(.data);
   
  .bss  SIZEOF(.data) + ADDR(.data) :
  {
     PROVIDE (__bss_start = .) ;
    *(.bss)
   
    *(COMMON)
     PROVIDE (__bss_end = .) ;
  }  > data

  /* reset info structure -- not cleared at reset  */
  .resinfox  (0x800000 + __xram_start_address) :
	AT (0x800000 + __xram_start_address)
  {
     PROVIDE (__resinfox_start = .) ;
    *(.resinfox*)
     PROVIDE (__resinfox_end = .) ;
  }  > data
  
  /* power device info -- not cleared at reset */
  .powerx   SIZEOF(.resinfox) + ADDR(.resinfox) :
  {
     PROVIDE (__powerx_start = .) ;
    *(.powerx*)
     PROVIDE (__powerx_end = .) ;
  }  > data

  /* external RAM -- cleared at reset  */
  .bssx  SIZEOF(.powerx) + ADDR(.powerx) :
  {
     PROVIDE (__bssx_start = .) ;
    *(.bssx)
     PROVIDE (__bssx_end = .) ;
  }  > data
  
  /* Global external data not cleared at reset  */
  .noinitx  SIZEOF(.bssx) + ADDR(.bssx) :
  {
    PROVIDE (__noinitx_start = .) ;
    *(.noinitx)
     PROVIDE (__noinitx_end = .) ;
     _endx = . ;
     PROVIDE (__heap_start = .) ;
     PROVIDE (__heap_end = 0x80ffff) ;
   } > data
  
  
  /* Global data not cleared after reset.  */
  .noinit  SIZEOF(.bss) + ADDR(.bss) :
  {
     PROVIDE (__noinit_start = .) ;
    *(.noinit*)
     PROVIDE (__noinit_end = .) ;
     _end = . ;
  }  > data
  .eeprom  :
  {
    KEEP (*(.eeprom*))
     __eeprom_end = . ;
  }  > eeprom
  .fuse  :
  {
    KEEP(*(.fuse))
    KEEP(*(.lfuse))
    KEEP(*(.hfuse))
    KEEP(*(.efuse))
  }  > fuse
  .lock  :
  {
    KEEP(*(.lock*))
  }  > lock
  .signature  :
  {
    KEEP(*(.signature*))
  }  > signature
  .user_signatures  :
  {
    KEEP(*(.user_signatures*))
  }  > user_signatures
  /* Stabs debugging sections.  */
  .stab 0 : { *(.stab) }
  .stabstr 0 : { *(.stabstr) }
  .stab.excl 0 : { *(.stab.excl) }
  .stab.exclstr 0 : { *(.stab.exclstr) }
  .stab.index 0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment 0 : { *(.comment) }
  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */
  /* DWARF 1 */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  /* DWARF 3 */
  .debug_pubtypes 0 : { *(.debug_pubtypes) }
  .debug_ranges   0 : { *(.debug_ranges) }
  /* DWARF Extension.  */
  .debug_macro    0 : { *(.debug_macro) }
}

- if there are no quick wins wrt this directive I guess I'll start looking at what I can do to prune the code given the new tools in this version of the compiler

does using __flash result in the same code as using PROGMEM and its associated routines?
- I'll pick a small data table and see what happens

All the best,
sd

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

Does the whole .trampolines section in your application fit under the 64kW limit?

JW