PROGMEM usage problem

i have some large enougth code, and unfortunatly can't post all it.
i will try to describe problem with small parts of it.

project have multiply source and header files.
all manually included in *ino file, so have only one translation unit for my code (+libryraes, core).

current platform: arduino_nano.

with progmem for tables off:
Binary sketch size: 23 528 bytes (used 77% of a 30 720 byte maximum) (0,15 secs)
Minimum Memory Usage: 1080 bytes (53% of a 2048 byte maximum)

with progmem for tables on:
Binary sketch size: 24 010 bytes (used 78% of a 30 720 byte maximum) (1,29 secs)
Minimum Memory Usage: 466 bytes (23% of a 2048 byte maximum)

Using for compilation Visual Studio + Visual Micro.
manu

have some interface:

class IBaseMemoryAllocator
{
public:
virtual void * AllocateMemory ( size_t nSize ) = 0;
virtual void FreeMemory ( void * pPtr ) = 0;
virtual void * ReAllocateMemory ( void * pPtr, size_t nNewSize ) = 0;
};

// CSimplestBaseAllocator - simple implementation, nothing special.

CSimplestBaseAllocator g_MemoryAllocator;

// source code have some quantity of constant data tables, such as:
const u8t SomeObj1::m_CustomData[] CODE_SEG =
{
0xXX, ..., 0xXX
}

// source code have some quantity of constant data tables, such as:
const u8t SomeObj2::m_CustomData[] CODE_SEG =
{
0xXX, ..., 0xXX
}

.... etc.

have some test code:

void setup()
{
// this sample geterates simple calls. no problems
{
void * pPtr = g_MemoryAllocator.AllocateMemory( 21 );
00000F0D 65.e1 LDI R22,0x15 Load immediate
00000F0E 70.e0 LDI R23,0x00 Load immediate
00000F0F 8a.e0 LDI R24,0x0A Load immediate
00000F10 91.e0 LDI R25,0x01 Load immediate
00000F11 0e.94.50.01 CALL 0x00000150 Call subroutine g_MemoryAllocator.FreeMemory( pPtr );
}

// this sample also geterates simple calls. no problems
{
void * pPtr = (&g_MemoryAllocator)->AllocateMemory( 11 );
(&g_MemoryAllocator)->FreeMemory( pPtr );
}

IBaseMemoryAllocator * pMemoryAllocator = &g_MemoryAllocator;

// this sample geterates simple ICall.
// when disabling probmem usage for data tables (define CODE_SEG as empty macro)
// i see correct calls.
// But when i enable progmem usage
// #define CODE_SEG PROGMEM
// this call going to some unpredicted (for me) location.
{
void * pPtr = pMemoryAllocator->AllocateMemory( 60 );
00000F23 e0.91.0a.01 LDS R30,0x010A Load direct from data space
00000F25 f0.91.0b.01 LDS R31,0x010B Load direct from data space
00000F27 01.90 LD R0,Z+ Load indirect and postincrement
00000F28 f0.81 LDD R31,Z+0 Load indirect with displacement
00000F29 e0.2d MOV R30,R0 Copy register
00000F2A 6c.e3 LDI R22,0x3C Load immediate
00000F2B 70.e0 LDI R23,0x00 Load immediate
00000F2C 8a.e0 LDI R24,0x0A Load immediate
00000F2D 91.e0 LDI R25,0x01 Load immediate
00000F2E 09.95 ICALL Indirect call to (Z)
pMemoryAllocator->FreeMemory( pPtr );
}

i found some information, that unaligned data can cause problems.
i'm aligned (x2 bytes) all tables that i found manually, but probles steel exist.
after aligning, ICall locatins changed, and goint to Pring metod on Serial.
before aligning it was jump to one of my data table.

Is this compiler bug? or i don't know something?

}

and i can't see any warnings, that i can think may cause this behavior.

Any help, any information ? (why this can happens)

looks like problem in such kind pointers storing in progmem:

#define SHCD_ENCODE_PTR( x ) ( ( size_t ) x ) & 0xff, ( ( ( size_t ) x ) >> 8 ) & 0xff,

// source code have some quantity of constant data tables, such as:
const u8t SomeObj3::m_CustomData[] CODE_SEG =
{
0xXX, ..., 0xXX,
SHCD_ENCODE_PTR( SomeFunc )
0xXX, ..., 0xXX,
SHCD_ENCODE_PTR( SomeDataPtr)
etc
}

it was used about 100 times, to encode pointers to (data or functions) in a byte array inside progmem and this will cause compiler to generate incorrect code.

same code without usage progmem generaged correct calls.

Is this compiler bug or i don't know something?

looks like problem not present, if modify tables from

  1. from ( u8t [] ) to ( u16t[] )

also all pointers have more strict typed.

ie :

const u16 SomeObj3::m_CustomData[] CODE_SEG =
{
0xXX, ..., 0xXX,
SHCD_ENCODE_PTR( SomeFunc, PFN_Ctor )
0xXX, ..., 0xXX,
SHCD_ENCODE_PTR( SomeDataPtr, const u16t * )
etc
}

But i steel wonder, is this compiler bug?