Dear all,
I'm posting my question here because I think I have a linker issue.
I had a 32 bit global variable that has been extended to 64 bits, the program now crashes after this changes for some ecu applications and DO NOT crush for other ECUs using the same source files and the same linker file.
the only change that I made is that extended 32 bit global variable.
unsigned long long var = 0;
here is a part of my linker
I'm using MPC5644A MCU.
MEMORY
{
/* Internal Flash RCW */
/* MPC5634 1.5M Internal Flash, but subtract one 128K block for use by BAM. */
flash_rcw : org = 0x00010000, len = 0x10
int_flash : org = 0x00010010, len = 0x06fff0
flash_cal : org = 0x00080000, len = 0x4000
/* MPC5566 128K Internal SRAM _BOOTLOADER_n*/
/* Börjar fysiskt vid 0x40000000 men första 4000 används för kalibrerdata */
/* int_sram : org = 0x40000000, len = 0x017800*/
int_sram : org = 0x40004010, len = 0x0135F0
}
/* MPC5566 4K of internal cache used for stack. */
/* Stack Address Parameters */
__STACK_SIZE = 0x200;
__SP_INIT = 0x40017800;
__SP_END = __SP_INIT - __STACK_SIZE;
and this is a part of my sections
NEXT_LOAD_ADDR = . ;
__DATA_ROMX = . ;
.backupram : AT (NEXT_LOAD_ADDR)
{
__BACKUPRAMSTART = . ;
*(.backupram)
} > int_sram
__BACKUPRAMEND = . ;
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.backupram );
.adapdata : AT (NEXT_LOAD_ADDR)
{
__ADAPSTART = . ;
*(.adapdata)
__ADAPEND = . ;
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.adapdata );
.PPC.EMB.sdata2 : AT (NEXT_LOAD_ADDR)
{
_SDA2_BASE_ = .;
__SDATA2_START__ = .;
*(.PPC.EMB.sdata2)
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.PPC.EMB.sdata2);
.sdata2 : AT (NEXT_LOAD_ADDR)
{
*(.sdata2)
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.sdata2);
.PPC.EMB.sbss2 : AT (NEXT_LOAD_ADDR)
{
*(.PPC.EMB.sbss2)
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.PPC.EMB.sbss2);
.sbss2 : AT (NEXT_LOAD_ADDR)
{
*(.sbss2)
__SBSS2_END__ = .;
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.sbss2);
.data : AT (NEXT_LOAD_ADDR)
{
__DATASTART = . ;
*(.data)
*(.data.*)
*(.gnu.linkonce.d*)
CONSTRUCTORS
} > int_sram
NEXT_LOAD_ADDR = NEXT_LOAD_ADDR + SIZEOF(.data);
I found out that this change affects the segments LOAD in my elfdump.txt file. I'm trying to getting familiar with the program headers and memory mapping. and I discovered that the program headers are now 6 instead of 5.
before my change I had these LOADs:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00010000 0x00010000 0x34920 0x34920 R E 0x10000
LOAD 0x054010 0x40004010 0x00044920 0x0144f 0x0144f RW 0x10000
LOAD 0x055460 0x40005460 0x00045d6f 0x0000c 0x0000c RW 0x10000
LOAD 0x060000 0x00080000 0x00080000 0x000b0 0x000b0 R 0x10000
LOAD 0x065470 0x40005470 0x40005470 0x00000 0x04c7c RW 0x10000
Section to Segment mapping:
Segment Sections...
00 .rcw .init .FlashProgram .FlashErase .FlashDriver .text .flash_data .rodata .isrvectbl .xcptn
01 .backupram .adapdata .data
02 .ctors
03 calconst
04 .bss
Then after that 64 bit variable change I have these segments and these LOADs:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x00010000 0x00010000 0x34920 0x34920 R E 0x10000
LOAD 0x054010 0x40004010 0x00044920 0x0003c 0x0003c RW 0x10000
LOAD 0x054050 0x40004050 0x0004495c 0x0141b 0x0141b RW 0x10000
LOAD 0x05546c 0x4000546c 0x00045d77 0x0000c 0x0000c RW 0x10000
LOAD 0x060000 0x00080000 0x00080000 0x000b0 0x000b0 R 0x10000
LOAD 0x065478 0x40005478 0x40005478 0x00000 0x04c7c RW 0x10000
Section to Segment mapping:
Segment Sections...
00 .rcw .init .FlashProgram .FlashErase .FlashDriver .text .flash_data .rodata .isrvectbl .xcptn
01 .backupram .adapdata
02 .data
03 .ctors
04 calconst
05 .bss
As you can see, the file size of the second load should has been increased by 8, should be 0x01456 and not 0x0003C.and the data must be in the second segment. if I'm not wrong.
I know that uninitialized global variable go to .bss segment, so I tried to uninitialize that variable (just for testing) and it worked fine.
my question:
why the program headers have been increased, and why the data segment split into two segments?
please feel free to correct me if I'm wrong.
any help is appreciated,
Thank you!
Islem,