Forum Discussion
Altera_Forum
Honored Contributor
15 years agoproblem with code size"need help"
hello,
I have a problem with code size.. I am running an application to view a 24bit color picture on a 480x272 touch screen, I used a 8 Mbyte SDRAM on DE1 board cycloneII and a scatter gather DMA, the only memory in my system is the SDRAM. so the reset vector is at 0x00 and the exception vector is at 0x20(and i tried others like 0x2000) the problem is that when I include a small picture size like 100x50 pixels every thing is ok, but when I try to include a larger size like 200x100 or full picture 480x272 this message appears: mallocr.c:2150: warning: unable to reach (null) (at 0x0023814c) from the global pointer (at 0x0022addc) because the offset (54128) is out of the allowed range, -32678 to 32767. collect2: ld returned 1 exit status make: *** error 1 what is the problem? I have a 8 MByte sdram and the size 480x272 only needs 0.5MByte??? can you help me please??15 Replies
- Altera_Forum
Honored Contributor
The linker must be putting your program sections together in an incorrect order.
The 'small data' section is used for small data items (be default less than 8 bytes) so that they can be accessed using a signed 16bit offset from the 'global pointer' (gp) register instead of having to load the 32bit address for each access. So it looks as though the linker has put a large data item into the 'small data' section making the section larger than 64k. If do a working link (small image array) and then look at the symbol table and linker map output file (you'll need to persuade the IDE to pass -Map file to ld) you should be able to work out why. - Altera_Forum
Honored Contributor
That's not a matter of size. It seems the pointer used to reference the picture data bases on the current program counter, thus the code. How do you "include" the picture into you application?
- Altera_Forum
Honored Contributor
--- Quote Start --- That's not a matter of size. It seems the pointer used to reference the picture data bases on the current program counter, thus the code. How do you "include" the picture into you application? --- Quote End --- I included it like that:# include "picture.h" and inside it: int pic_h = 60; int pic_w = 120; unsigned int pic[60][120]= {................}; and the calling like that : draw_array( (unsigned int *)pic, pic_w, pic_h, pic_viewer.display, ((WIDTH-pic_w)/2), ((HEIGHT-pic_h)/2), SPLASH_BG_MASK); - Altera_Forum
Honored Contributor
--- Quote Start --- The linker must be putting your program sections together in an incorrect order. The 'small data' section is used for small data items (be default less than 8 bytes) so that they can be accessed using a signed 16bit offset from the 'global pointer' (gp) register instead of having to load the 32bit address for each access. So it looks as though the linker has put a large data item into the 'small data' section making the section larger than 64k. If do a working link (small image array) and then look at the symbol table and linker map output file (you'll need to persuade the IDE to pass -Map file to ld) you should be able to work out why. --- Quote End --- I will try this but how to persuade the IDE to pass MAP file to id?? - Altera_Forum
Honored Contributor
Is the variable definition
unsigned int pic[60][120] = { }; made inside of a function, i.e. main()? - Altera_Forum
Honored Contributor
--- Quote Start --- Is the variable definition unsigned int pic[60][120] = { }; made inside of a function, i.e. main()? --- Quote End --- no the data of int pic[60][120] is initialized in the picture.h I noticed that when the size of pic exceeds some value the error happens below this value the picture comes out on the LCD without errors???? - Altera_Forum
Honored Contributor
Maybe I should have been more precise. Is the variable pic[][] a global module variable or a local function variable?
- Altera_Forum
Honored Contributor
The output of 'objdump -h foo.o' and 'objdump -n foo.o' will show which sections the various pieces of data are assigned to.
Your pic[] should end up in .data, pic_h and pic_w in .sdata. If they are correct there, then maybe something is stopping the linker merging all the .sdata sections together. Which version of gcc are you using? - Altera_Forum
Honored Contributor
--- Quote Start --- Maybe I should have been more precise. Is the variable pic[][] a global module variable or a local function variable? --- Quote End --- I included the file pic.h inthe beginning of the main.c and the pic.h is like that: int pic_h = 40; int pic_w = 100; unsigned int pic[40][100]={ {16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215,16777215}, {16777215,.................... so I think it is a global variable.. - Altera_Forum
Honored Contributor
--- Quote Start --- The output of 'objdump -h foo.o' and 'objdump -n foo.o' will show which sections the various pieces of data are assigned to. Your pic[] should end up in .data, pic_h and pic_w in .sdata. If they are correct there, then maybe something is stopping the linker merging all the .sdata sections together. Which version of gcc are you using? --- Quote End --- I am using version 10.0