0

I want to put some functions in a specific section named ".xip.text", but the read only data cannot put in that section.

The following is my test code:

#include <stdio.h>

void foo(void) __attribute__((section (".xip.text")));

void foo(void)
{
    printf("hello world\n");
}

In the linker script file:

MEMORY
{
  RAM (rwx)  : ORIGIN = 0x00010000, LENGTH = 448K
  FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 1024K
}

SECTIONS
{
    .xip :
    {
        *(.xip.text .xip.text.*)
        *(.xip.rodata .xip.rodata.*)
    } > FLASH

    .text :
    {
        *(.text*)
    } > RAM
}

After linking, the function text is placed in ".xip" section, but the string "hello world\n" is not put in the same section. How to solve it?

I can put the whole file in the ".xip" section to solve this problem. But I have many files, and I only want to put some functions to ".xip" section, not the whole file.

In the map file, text of foo() is placed in the right section, but string "hello world\n" (.rodata.str1.1) is placed in another seciton.

 *(.xip.text .xip.text.*)
 .xip.text      0x1002f7b0        0xc ../foo.o
                0x1002f7b0                foo
 *fill*         0x1002f7bc        0x4 


 .rodata.str1.1
                0x00025515        0xc ../foo.o
 *fill*         0x00025521        0x3 

After disassemble,

1002f7b0 <foo>:

void foo(void) __attribute__((section (".xip.text")));

void foo(void)
{
    printf("hello world\n");
1002f7b0:   4801        ldr r0, [pc, #4]    ; (1002f7b8 <foo+0x8>)
1002f7b2:   f000 b95d   b.w 1002fa70 <__puts_veneer>
1002f7b6:   bf00        nop
1002f7b8:   00025515    .word   0x00025515
1002f7bc:   00000000    .word   0x00000000

gcc version: gcc-arm-none-eabi-7-2017-q4-major, gcc version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (GNU Tools for Arm Embedded Processors 7-2017-q4-major)

Ivan
  • 191
  • 5

1 Answers1

1

function text is placed in ".xip" section, but the string "hello world\n" is not put in the same section.

The read-only data is not .text, so it shouldn't be put into the same section.

If you want to control which section the read-only data goes, you need to do that yourself. Something like this should work:

__attribute__((section(".xip.rodata")))
const char my_xip_data[] = "hello, world\n";

void foo(void)
{
  printf(my_xip_data);
}
Employed Russian
  • 199,314
  • 34
  • 295
  • 362