chipKIT® Development Platform

Inspired by Arduino™

Small data error when create large arrays on ChipKIT MAX32

Created Tue, 14 Jun 2016 01:12:11 +0000 by reverie001


Tue, 14 Jun 2016 01:12:11 +0000


I was trying to create three large arrays on chipKIT Max32 with Arduino C. They looks like below:

int A[128][64]; float B[128][64]; float C[128][64];

However, error message as " small-data section exceeds 64KB; lower small-data size limit (see option -G)" jumped out and I have to change the array size back to [64][64] as below to make the code work, as below:

int A[64][64]; float B[64][64]; float C[64][64];

I did try the compiler optimizations shown in this thread: [url][/url] But it did not work.

Really appreciate if anyone can give some suggestions on how to optimize the compiler to overcome this issue. I'm using mpide-0150-windows-20150820.

I also see the proposed solution in the other thread as below. I will give it a try later and see how thing goes. Thanks.

Re: Linking errors when compiling and linking for Max32 Postby EmbeddedMan » Wed Apr 20, 2016 4:55 pm

That is a pretty old version. I'd give Arduino IDE 1.6.7 a try, with chipKIT-core v1.1.0 installed within it. You can find direction here :

Maybe that will help resolve your linker issue - maybe not. But it's worth a shot.



Tue, 14 Jun 2016 10:54:23 +0000

This is actually a bug with the compiler (well, not the compiler itself, but the libraries in the compiler). It has already been identified and tackled and the next compiler release will fix it.

For now you can disable the "smalldata" section by editing the compilation commands (in platform.txt or platforms.txt depending on if you're using mpide or chipkit-core - I forget which is which, or compiler.txt if you're using UECIDE) and adding the flag (IIRC - it's been a while since I did this myself) "-mno-gopt" to both compiler and linker commands.

Another option is to find the file "ctype.h" which is in .../pic32mx/include/ctype.h in the compiler, wherever that is, and add to the start of it:

#ifndef __IMPORT
#undef __IMPORT
#define __IMPORT __attribute__((section(".data")))

which may cure the problem for you as well without having to find the right compiler commands to modify.


Tue, 14 Jun 2016 13:08:30 +0000

Man, Majenko, how do you ever remember all of this stuff. Thanks so much for helping everybody out with all of the interesting questions - like this one - I'm always impressed at how much technical information you seem to have instantly available at your fingertips to help people out.

Reverie001 - As soon as the new compiler is ready for release, we will do a new release of chipKIT-core. We just did a 1.2.0 release of the core, which did NOT include the new compiler with the fix Makenjo is talking about, because it isn't quite ready yet. But as soon as it is, we'll do a release and post about it.



Tue, 14 Jun 2016 13:09:32 +0000

Brian, it's called "The GMail Search Box" ;) That and never deleting old emails ;)


Tue, 14 Jun 2016 23:46:36 +0000

Hi Majenko, Thank you so much for you prompt reply, I really appreciate it. I think I understand what is happening now but I have some difficulty in fixing it. It will be great if I can have some hand by hand help from you. Following your instructions, what I have done is as below:

  1. I first tried the second option you give to modify "ctype.h". I found the file you mentioned at that location and added the code to the start of it. However, the same error persists.

  2. While keeping the modifications in ctype.h, I went to file "platforms.txt", I tried to understand where I should change by adding "-mno-gopt" after three commends: pic32.compiler.ldflags=-mno-gopt; pic32.compiler.upload.cmd=-mno-gopt; pic32.compiler.upload.flags=-mno-gopt. But it still did not work.

The version of my mpide is mipde-0150-windows-20150820. Now the file "platforms.txt" looks like this:



Before I go to dig deeper into the references, it will be great if you can help point out where exactly I should modify? Thank you very much!

EmbeddedMan - Thanks for letting me know that, will upgrade at the first place if it can fix the bug. Thanks.


Wed, 15 Jun 2016 10:45:21 +0000

You need to append it to:

pic32.compiler.c.flags pic32.compiler.cpp.flags pic32.compiler.ldflags


Wed, 15 Jun 2016 23:23:17 +0000

Dear Majenko:

I tried different ways to append "-mno-gopt" to the three commends you mentioned. For example, I tried as below:

pic32.compiler.c.flags=-mno-gopt pic32.compiler.cpp.flags=-mno-gopt pic32.compiler.ldflags=-mno-gopt

I also tried keeping the old commands and only added "-mno-gopt" to the end of the commands.

However, none of them works. The error message as "cc1plus.exe: error: unrecognized command line option "-mno-gopt" " appeared.

I would be really appreciate if you can help with this on how the code should be appended here.

Thanks a lot.


Wed, 15 Jun 2016 23:30:42 +0000

I just placed that chunk of C macros into my ctype.h file and it worked. Code that I know gives the error that you describe compiles with it in there.

I have attached my ctype.h file for you in case you didn't put the code in right.

The ctype.h file is the best way of fixing the problem.


Thu, 16 Jun 2016 00:01:23 +0000

Thanks Majenko for your patiently help!

I first went get a clean version of the mpide-0150, then I used your ctype file to replace the old one. However, small data error is still there...

Then I went to change the command in "platforms.txt" by changing commands to:

pic32.compiler.c.flags=-mno-gopt pic32.compiler.cpp.flags=-mno-gopt pic32.compiler.ldflags=-mno-gopt

The error message as "cc1plus.exe: error: unrecognized command line option "-mno-gopt" " appeared again.

It's strange that it works for you but not for me...Is it just because this mpide-0150 has some other bugs?

May I know your choice of the compiler so maybe I can switch to your setup to update my CHIPKIT MAX32?

Many thanks!


Thu, 16 Jun 2016 08:15:23 +0000

I always use UECIDE of course :)

Of course, we could be seeing completely different things. Your problem may be caused by something else that my problem, which is why my fix isn't working for you.

Any chance you could post your entire code so I can try it out?


Thu, 16 Jun 2016 18:50:18 +0000

Hi Majenko, thanks a lot.

I tried UECIDE (uecide-0.8.8alpha22-windows-full), the plugin manager does not work for me, I could not see anything to install or download. I guess it's because of the firewall system in the company.

Second, sorry that I could not directly share the code here, it's company's property. I did more tests by adding code block by block and wanted to see which cause the problem. Indeed, if I only claim a 128x64 array at the beginning with nothing else, your solution works and code complies with no error! This continued until I added in the 11th block of my code, which adds up to a few thousand lines of code in total, then the small-data error message appears:

C:/Users/humia/Downloads/mpide-0150/hardware/pic32/compiler/pic32-tools/bin/../lib/gcc/pic32mx/4.5.2/../../../../pic32mx/bin/ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)
sketch_jun16a.cpp.o: In function `pulse_the_latch()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:495:(.text._Z15pulse_the_latchv+0x8): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `column_safe_start()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:512:(.text._Z17column_safe_startv+0x20): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `row_safe_start()':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:592:(.text._Z14row_safe_startv+0x24): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_pulse_width(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:744:(.text._Z21setup_col_pulse_widthiii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:812:(.text._Z21setup_col_pulse_widthiii+0x170): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_sample_and_hold(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:821:(.text._Z25setup_col_sample_and_holdiii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:875:(.text._Z25setup_col_sample_and_holdiii+0x170): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_adc_convst(int, int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:883:(.text._Z20setup_col_adc_convstiii+0x44): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:936:(.text._Z20setup_col_adc_convstiii+0x168): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
sketch_jun16a.cpp.o: In function `setup_col_dac_span(int, int)':
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:946:(.text._Z18setup_col_dac_spanii+0x40): relocation truncated to fit: R_MIPS_GPREL16 against `NOT_BOARD_OE'
C:/Users/humia/AppData/Local/Temp/build926005512767424714.tmp/sketch_jun16a.cpp:999:(.text._Z18setup_col_dac_spanii+0x1e0): additional relocation overflows omitted from the output
collect2: ld returned 1 exit status

So I think you are right, it is due to something else. But does it simply means that my hardware could not handle the larger code if I want to put in more functions? Or is there anyway to overcome this issue? Actually in another thread: [url][/url], I see they are solving a very similar problem that I encountered here. However, the final solution is quite vague to understand how it was solved.

In the worst case, I will have to delete the additional functions to implement on the MCU, or I have to find better ways to code my things? Like using fewer variables? I really don't know.



Thu, 16 Jun 2016 23:04:44 +0000

You should see the same in alpha22 that you see in alpha21. They both use the same repsitory.

We have just (literally a few minutes ago) been handed a new version (prerelease beta) of the compiler with a number of bug fixes. I am at this moment in time building the UECIDE packages for it - it might cure your problem (or it might not). It should appear in the plugin manager in due course.


Mon, 20 Jun 2016 21:49:33 +0000

Thanks Majenko, I think I will build two versions of firmware to overcome the problem at this moment. One with more functions but support small arrays, one with fewer functions but support larger arrays.

And I will update the compiler as well later to see if that helps, thanks a lot for your help all this way!