This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Renaming default compiler sections

Hello fellow engineers,

Is there a way to force compiler to override default sections (.text, .data, .bss, ...)?

I have read the compiler documentation (SPRU514G) but I did not find anything related to renaming sections. The toolchain does not have tool for manipulating sections in object files either. The only way seems to be passing sections definitions to the linker but this out of the question since it forces me to maintain specific section files to every output executable. Incremental linking could solve this issue but we are using CMake for our project and I think making CMake understand concept of incremental linking would take a lot of work. Also I don't like compiler pragmas (e.g. CODE_SECTION) as I would need to add one pragma for each variable or function in the library.

To clarify my problem consider following:

library foo:
    * foo.obj
    * foo1.obj
    * foo2.obj

library bar:
    * bar.obj
    * bar1.obj
    * bar2.obj

executable foobar:
    * library foo
    * library bar
    * linker_sections.cmd

executable foo:
    * library foo
    * linker_sections.cmd

executable bar:
    * library bar
    * linker_sections.cmd


In order to place sections from foo and bar libraries to memory segment "FOO" in the executable foobar, the linker_section.cmd file must have something like this:

SECTIONS {

    GROUP {
        .foo.bss: {
            -l"foo.lib" (.ebss, .bss, .econst, .const)
            -l"bar.lib" (.ebss, .bss, .econst, .const)
        }
    } load = FOO, PAGE = 1
}

SECTIONS {
    GROUP {
        .foo.text: {
            -l"foo.lib" (.text)
            -l"bar.lib" (.text)
        }
    } load = FOO, PAGE = 0
}

However, I cannot reuse this linker_sections.cmd file for executables foo since it links bar library to the executable. More elegant solution would be renaming sections in libraries to include prefix libfoo: and use following shared linker_sections.cmd:

SECTIONS {
    GROUP {
        .foo.bss: {
            *(libfoo:.bss)
            *(libbar:.bss)
        }
    } load = FOO, PAGE = 1
}

SECTIONS {
    GROUP {
        .foo.text: {
            *(libfoo:.text)
            *(libbar:.text)
        }
    } load = FOO, PAGE = 0
}

This linker_sections.cmd file could be shared with all executables. (The syntax might not be correct but should give you some idea what I am looking for).

Any advices? Thank you for at least reading this post! :)

  • Consider this idea ... Put #pragma SET_CODE_SECTION and #pragma SET_DATA_SECTION in the header file of your libraries.  All of the code and data from those libraries is then placed in sections you name.  Read about those pragmas in the C2000 compiler manual.  These pragmas are introduced in compiler version 6.1.x.

    Thanks and regards,

    -George

  • Hi George,

    Thank you for your reply. I tried using SET_CODE_SECTION and SET_DATA_SECTION pragmas but they seem to move functions/variable only targeted to .text and .data sections to new sections. I still not have means to rename .econst, .ebss, .cinit or .switch sections.
  • Another idea to consider ... The linker command file supports C-style preprocessing commands like #ifdef.  So you could have something like this ...

            .libraries.bss: {
                #ifdef FOO_LIB_USED
                -l"foo.lib" (.ebss, .bss, .econst, .const)
                #endif
           
                #ifdef BAR_LIB_USED
                -l"bar.lib" (.ebss, .bss, .econst, .const)
                #endif
            }

    The linker command line would -DFOO_LIB_USED or -DBAR_LIB_USED as needed.  Please read more about linker preprocessing in the section titled Linker Command File Preprocessing of the C2000 assembly tools manual.

    Thanks and regards,

    -George