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.

Dormant Linker Subsection

Hi,

     I was wondering if it's possible to declare custom linker sections and turn them on/off as needed. So basically if I decide not to enforce the custom sections, the .obj's that are set to reside there are instead going to the default .text section.

Best Regards,

Johnny

  • Hi Johnny,
    Moved this thread over Compiler forum for faster response. Please specify the compiler version used for this. Thank you...

  • Chia-Ning Wang said:
     I was wondering if it's possible to declare custom linker sections and turn them on/off as needed.

    Yes.  Here is how I would do it.  

    First, compile with the option --gen_func_subsections.  This causes every function to be placed in input sections with names like .text:name_of_function.  Consult your compiler manual for the precise details.  In your linker command file, you can make use of the preprocessing feature to do something like ...

    SECTIONS
    {
        #ifdef SPECIAL_LINK
        special_section 
        {
            .text:one_function
            .text_two_function
            /* and so on */
        } > SPECIAL_MEMORY_RANGE
        #endif
    
        .text > RAM
        /* other sections here */
    }
    

    If the preprocessor symbol SPECIAL_LINK is defined, then those functions are collected into the output section special_section and allocated to the SPECIAL_MEMORY_RANGE.  If SPECIAL_LINK is not defined, those those functions become part of the .text output section, and are allocated to RAM.

    Thanks and regards,

    -George