Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gcc: Memory region for anonymous string

I used GCC and need to define big array of text, like

const char* myArray[1000] = {"red", "blue", "green", "yellow", ...};

I have a array of pointers and big heap of text like "red\0blue\0green\0..." somewere in memory. I want to change memory region for that text. I used __attribute__((section(...))) GCC directive, but they change only allocation of pointers. How can i change allocation of big text chunk? Thanks for answers.

P.S. Sorry for bad English.

like image 782
anonimouse Avatar asked Feb 12 '26 20:02

anonimouse


1 Answers

You can use -fdata-sections with gcc. That will create a unique section for each global variable in the object-file.

Then you can create a LdScript-file which will tell the linker (ld) to put the sections into the desired memory region.

Anonymous strings are in the .rodata-section of the object-file. An LdScript-example snippet:

.memregion1.rodata :
{ 
    Startup.c.obj(.rodata.str1.8)
}

will put the str1.8 from Startup.c into the memregion1.

like image 156
Patrick B. Avatar answered Feb 15 '26 10:02

Patrick B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!