Flash tables - order of variables of gcc 4.3.4 vs 4.6.2

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

Dear all,

In my code, I have a table of variables as follows:

#include "version.h"
#include 

#define VERSION_TABLE __attribute__ ((section (".version_table")))

//-------------------------------------------------------------------------------------------------
// Linking Instructions
//-------------------------------------------------------------------------------------------------
// This table needs to be placed the bootloader revision at the very bottom of flash.
// Currently the size of the table is 8 bytes. It therefore needs to be placed at the following
// sections in flash:
//
// Application Images:
// ATxmega32A4  = 0x007FF8 (End of flash = 0x008000 Bytes)
// ATxmega128A1 = 0x01FFF8 (End of flash = 0x020000 Bytes)
//
// Bootloader Images:
//
// ATxmega32A4  = 0x008FF8 (End of bootloader flash = 0x009000 Bytes)
// ATxmega128A1 = 0x021ff8 (End of bootloader flash = 0x022000 Bytes)

//-------------------------------------------------------------------------------------------------
// Version Table
//-------------------------------------------------------------------------------------------------

const uint8_t  g_buildPlatform              VERSION_TABLE = BUILD_PLATFORM;
const uint8_t  g_padding                    VERSION_TABLE = 0;
const uint8_t  g_buildVersionType           VERSION_TABLE = BUILD_VERSION_TYPE;
const uint8_t  g_padding1                   VERSION_TABLE = 0;
const uint32_t g_svnRevision                VERSION_TABLE = BUILD_VERSION;

Examining the HEX file, there is a difference between 4.6.2 (Atmel AVR_8_bit_GNU_Toolchain_3.4.0_663 - Linux 64-bit) and Bingo's 4.3.4 toolchain (30 April 2010 - Linux 64-bit).

(Note for this build:)
* Build version = 62603 (0xF48B)
* Build type = 2
* Platform = 9

In 4.6.2, the relevant hex is as follows:

:08FFF8008BF400000002000977

In 4.3.4, the relevant hex is as follows

:08FFF800090002008BF4000077

So clearly, the order of the variables located in flash has been reversed.

Whilst there is an easy workaround (add more linker bits), is there a reason why this is the case, and is there a way I can specify the order of how the variables are to appear?

-- Damien

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

Put them in a struct?

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

C is allowed to reorder variable placement as much as it wants.
Putting them in a struct is the easy solution.

unsigned in clock_low, clock_high;   //could be in any order in memory.

struct { unsigned int low;
 unsigned int high;} clock;  // puts low and high in proper little-endian order.