-->
Page 1 of 1

[C++] Using std::string

PostPosted: Tue Aug 11, 2015 5:31 am
by Grim Reaper
Hi! I was trying to use std::string but it gave me a bunch of linker errors (undefined reference to _sbrk_r, _fstat_r, _read_r, _lseek_r, _write_r, _close_r, _open_r). I made prototypes for those functions and after that linker doesn't complain any more but there is another problem. I've got "section `.text' will not fit in region `iram1_0_seg'".

The code that i'm using is from here: https://github.com/CHERTS/esp8266-devki ... r_main.cpp
I just added one std::string variable.

Memory map before adding std::string variable:

Code: Select all------------------------------------------------------------------------------
Section info:

build/app.out:     file format elf32-xtensa-le

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000540  3ffe8000  3ffe8000  000000e0  2**4
                  CONTENTS, ALLOC, LOAD, DATA
  1 .rodata       000004e8  3ffe8540  3ffe8540  00000620  2**4
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00009200  3ffe8a28  3ffe8a28  00000b08  2**4
                  ALLOC
  3 .text         00006522  40100000  40100000  00000b08  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .irom0.text   00029898  40240000  40240000  00007030  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
------------------------------------------------------------------------------


Memory map after adding std::string variable
Code: Select all------------------------------------------------------------------------------
Section info:

build/app.out:     file format elf32-xtensa-le

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000d88  3ffe8000  3ffe8000  000000e0  2**4
                  CONTENTS, ALLOC, LOAD, DATA
  1 .rodata       00004e78  3ffe8d90  3ffe8d90  00000e70  2**4
                  CONTENTS, ALLOC, LOAD, DATA
 39 .bss          00009be8  3ffede10  3ffede10  00005ef0  2**4
                  ALLOC
 40 .text         00013666  40100000  40100000  00005ef0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 41 .irom0.text   00029898  40240000  40240000  00019560  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
------------------------------------------------------------------------------

(i resized iram section in .ld script to see how much space it takes, without this it doesn't compile)

Is there any possibility of using std::string?

Re: [C++] Using std::string

PostPosted: Thu Aug 27, 2015 4:45 pm
by kolban
I haven't tried to use std::string .... however ... you are doing the right levels of debug. To my way of thinking, you have 512K of flash into which you can place code. It is my understanding that ".text" section gets loaded straight away into RAM and you only have about 40-80K of RAM. Looking at your objdump, I see your ".text" section to be too large. I had this problem too and what I did was "move" the ".text" section to ".irom0.text". I was able to do that by running:

Code: Select allobjcopy --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal <myfile.o>


against each of the object files before linking. Now ... I am NOT saying this will work for you ... but it was a principle that worked for me ...

Neil