Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By kolban
#33326 Eldon,
Many thanks for the response. Unfortunately I have to compile large amounts of "neutral" C code that already exists that I can't modify. This means that I can't go through the original source and "escape" or otherwise process existing strings.

What I find is that when I compile a C source file to generate an object file, String constants are placed in their own linker section which appears to be called ".rodata.str1.1". What I was hoping for (and again, I don't know if it is even a possibility) is to use a linker flag or configuration file such that when the object files are being link-edited together, then static strings would be "moved" to flash.
User avatar
By jcmvbkbc
#33328
kolban wrote:What I find is that when I compile a C source file to generate an object file, String constants are placed in their own linker section which appears to be called ".rodata.str1.1". What I was hoping for (and again, I don't know if it is even a possibility) is to use a linker flag or configuration file such that when the object files are being link-edited together, then static strings would be "moved" to flash.

Putting string literals to FLASH can be achieved by moving .rodata.str1.1 input section in the ld script to the output section that goes to iram1_0_seg.
But putting strings to FLASH is only a half of the problem, once you put them there you'd need to access them, and you can't do it with instructions that access bytes in data memory. This issue outlines possible solutions to this.
User avatar
By dkinzer
#33552
kolban wrote:This means that I can't go through the original source and "escape" or otherwise process existing strings.
If true, you're stuck with having the string data where the compiler puts it.

You can arrange for any constant data (numeric, string, structures) to be in Flash by tagging it __attribute__((section(".irom.text"))). There is a shorthand for this defined in c_types.h, ICACHE_RO_DATA. The only problem is that the the Flash-based data must be read out using a helper routine that performs the reads in multiples of 4 bytes at addresses that are 32-bit aligned. Consequently, even though you might get the strings into Flash using some linker script magic you would probably get an exception when trying to read it out.
User avatar
By eriksl
#38778 I don't understand the problem. Any read-only data is already put in flash (and not in iram). I don't even think you can read data from iram, it's called iram for a reason ;) Try it out, make a whole bunch of large strings and watch which segment grow...

I have about 120 kb of strings, do you think it would fit in iram ;) And no, special treatment. Maybe the default load script that comes with opensdk has a fix that I copied, I don't know, you might want to have a look there.