Link Error: Illegal 16-bit small data area relative reference to symbol

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link Error: Illegal 16-bit small data area relative reference to symbol

Jump to solution
5,119 Views
jimfell
Contributor III

Does anyone know what this linker error means and/or how to resolve it?

 

'Building target: USB_CDC_Test_App.elf'

'Executing target #4 USB_CDC_Test_App.elf'

'Invoking: ColdFire Linker'

"C:/Program Files/Freescale/CW MCU v10.2/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf" @@"USB_CDC_Test_App.args" -o "USB_CDC_Test_App.elf"   -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/Queue_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/USB_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/Debug_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/SArray_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/Serial_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/Text_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/Timer_MCF51JM.lib" -l"C:/Users/jim.fell/Source/Embedded/Libs/Target/Debug/valloc_MCF51JM.lib"

C:/Program Files/Freescale/CW MCU v10.2/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf|Linker|Error

>Illegal 16-bit small data area relative reference to symbol '_g_Mem'                                                                                          

>from address 0x000030BA in section '.text' of file 'USB_MCF51JM.lib

>usb_dci_c.o    '.

>This type of reference has a range from 4294934528 to 32767 bytes.

>from address 0x00003202 in section '.text' of file 'USB_MCF51JM.lib

>usb_dci_c.o    '.

 

 

I am using CodeWarrior for MCU v10 with the ColdFire V1 architecture.  My application project is a simple bareboard project, which references multiple compiled libraries.  All of the libraries build without issue.  One of the libraries references a CDC library built using the Freescale USB stack v4.0.2.  Changes I made to the stack were very minimal:

 

  1. Linker output was changed to generate a library, rather than an application:
    • Project menu > Properties > C/C++ Build > Settings > Tool Settings tab > ColdFire Linker > Output > Output Type > Static Library
    • Project menu > Properties > C/C++ Build > Settings > Build Artifact tab > Artifact Extension > lib
  2. These files were excluded from the build:
    • user_config.h
    • virtual_com.h
    • main.c
    • RealTimerCounter.c
    • virtual_com.c

 

Functionality found in virtual_com.c was moved to one of the new libraries for abstraction purposes.  I know where g_Mem is declared, but I'm confused as to why it's giving me this link error when I try to build my application with the USB driver in referenced libraries.  Any help or insight into the linker error would be appreciated.  Thanks.

Labels (1)
0 Kudos
1 Solution
3,947 Views
BlackNight
NXP Employee
NXP Employee

Have you seen any linker/compiler warnings? That might be good indicators what is going wrong.

I have g_Mem[] non-static as I'm using it from another source file.

That location pragma in the source is used so I can use it in the linker file:

. = ALIGN(512);
__BDT_BASE = .;
*(.usb_bdt)
__BDT_END = .;



Erich

View solution in original post

0 Kudos
10 Replies
3,947 Views
BlackNight
NXP Employee
NXP Employee

Hello,

this means that the distance to the symbol/variable does fit any more into a 16bit offset. You need to change the 'memory' model of the compiler. Go into the project settings > ColdFire Compiler > Processor and select e.g. 'Far (32bit)' data model:

data model.png

I hope this helps,

Erich

0 Kudos
3,947 Views
jimfell
Contributor III

Hi Erich.  Thanks for the tip, but my project settings were already configured for the Far (32 bit) Data Model.  I tried changing the Code Model from Near Relative (pc16) to Far (32 bit), but it yielded the same results.  All of my projects (library and application) are using the same ColdFire Compiler Processor settings:

capture.jpg

Any other ideas? :smileyhappy:

0 Kudos
3,947 Views
BlackNight
NXP Employee
NXP Employee

Hmm, it looks like it is still using 16bit reference from usb_dci_c.o:

>Illegal 16-bit small data area relative reference to symbol '_g_Mem'                                                                                          

>from address 0x000030BA in section '.text' of file 'USB_MCF51JM.lib

>usb_dci_c.o    '.

>This type of reference has a range from 4294934528 to 32767 bytes.

>from address 0x00003202 in section '.text' of file 'USB_MCF51JM.lib

>usb_dci_c.o    '.

That might depend as well how g_Mem is referenced, Maybe your header file declaring g_Mem is using somehow a short segment?

As for my project (see USB CDC goes medical | MCU on Eclipse) I have it like this:


#pragma define_section usb_bdt ".usb_bdt" RW

__declspec (usb_bdt) uint_8 g_Mem[BYTES_1024];


Erich

0 Kudos
3,947 Views
jimfell
Contributor III

The stack I'm using has g_Mem declared as static:

#pragma define_section usb_bdt ".usb_bdt" RW

__declspec (usb_bdt) static uint_8 g_Mem[BYTES_1024];

When I comment out the program line and declspec, as such...

//#pragma define_section usb_bdt ".usb_bdt" RW

/* __declspec (usb_bdt) */ static uint_8 g_Mem[BYTES_1024];

...everything seems to build okay.  Would you happen to know if this is a valid workaround?  Was g_Mem defined as within that special section for a reason?  Thanks.

0 Kudos
3,948 Views
BlackNight
NXP Employee
NXP Employee

Have you seen any linker/compiler warnings? That might be good indicators what is going wrong.

I have g_Mem[] non-static as I'm using it from another source file.

That location pragma in the source is used so I can use it in the linker file:

. = ALIGN(512);
__BDT_BASE = .;
*(.usb_bdt)
__BDT_END = .;



Erich

0 Kudos
3,408 Views
marcelifirlej1
Contributor I

Hi Erich,

The solution is killing the Processor Expert generated FLASH.lcf file only.

For MCF52223 only a warning comes as doing it differently:

_g_Mem(.usb_bdt) in file usb_dci_cfv2_c.obj is referenced but has not been written. Check your linker command file. 

marcelifirlej1_0-1644620498527.png

 

However, in MCF51JM there is an error. 

Can I see step by step solution?

Regards,

Marceli

0 Kudos
3,397 Views
marcelifirlej1
Contributor I

Problem solved in component Help file and by disable PE build linker.

https://mcuoneclipse.com/2012/03/10/usb-or-not-cdc-with-processor-expert/

0 Kudos
3,947 Views
jimfell
Contributor III

Thanks.  I copied the .usb_bdt section from the linker file in the USB stack to the linker file in my application project, and it seems to be correctly building now.


0 Kudos
3,947 Views
jimfell
Contributor III

Hi Erich.  Can you please elaborate?  I don't understand how that is helpful.  Thanks. :smileyhappy:

0 Kudos
3,947 Views
BlackNight
NXP Employee
NXP Employee

Sorry for not being clear: I just wanted to show how I'm using it in the linker file.

Erich

0 Kudos