Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316962

Summary: need a simple linker command file escape
Product: [Technology] RTSC Reporter: Dave Russo <d-russo>
Component: TargetsAssignee: Sasha Slijepcevic <sascha>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P1 CC: mtakatz
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: target:3.21
Attachments:
Description Flags
thread describing problem and "heavy" solution none

Description Dave Russo CLA 2010-06-15 15:39:36 EDT
Created attachment 171983 [details]
thread describing problem and "heavy" solution

The attached newsgroup post contains a use-case that deserves a better, "lighter weight", solution.
Comment 1 Dave Russo CLA 2010-08-25 14:30:14 EDT
One possibility is to add the following configs to xdc.cfg.Program
    /* regexp of section names to exclude from generation */
    config String excludeSects = null; 

    /* exclude compiler sections from linker command file generation */
    config Bool excludeTargetSects = false;

This would allow the user to take _complete_ control of the sections specified with their own linker command file.

Suppose, for example, you want explicit control of the .text and .const sections.  Within the program's config script, you'd add:
    Program.excludeSects = "\.text|\.const";

Then you would add your own linker command file to the link step with the following content (for example):
    SECTIONS {
        .text:load > FLASH START(_text_load) SIZE(_text_size)
        .text:run  > SRAM  START(_text_run)

        .const: LOAD = FLASHA, PAGE 1, RUN = DSRAM, PAGE 1, LOAD_START(__C_LoadStart) RUN_START(__ConstRunStart), SIZE(__ConstSize)
    }
Comment 2 Dave Russo CLA 2010-08-30 21:05:29 EDT
Initial fix added to 3.21 stream.  Note target linker templates need updating for this to work.

Added two config new config params to xdc.cfg.Program:
    sectionsExclude: a regexp string naming sections to exclude during generation
    sectionsTemplate: a template that is expanded inside SECTIONS

sectionsExclude allows users to take control of specific sections (or all sections if they specify ".*").

sectionsTemplate provides a means to easily specify the contents that should replace the sections excluded above.  The template can be a file whose contents are literally copied _or_ it may contain expressions that leverage the Program object.  For example, to add start/size symbols to all sections one can specify the following template:
    %var sectMap = $args[0];
    %for (var sn in sectMap) {
    %    var sym = sn.replace(/\./g, '_');
       `sn`: START(`sym`_start) SIZE(`sym`_size)
    %}
Comment 3 Sasha Slijepcevic CLA 2010-11-01 17:55:44 EDT
Using 3.21.00.22, I verified that sectionsTemplate and sectionsExclude are implemented and work as expected. The only change I would make is in the documentation for sectionsTemplate. The part that says:
"This is useful especially when excluding specific sections via sectionsExclude or when taking full control of the linker command file via linkTemplate is unnecessary."
leaves an impression that a user can use sectionsExclude and sectionsTemplate at the same time. However, if sectionsTemplate is specified, the whole generated content of the SECTIONS directive is removed, so the specified template must allocate all compiler sections, not only the ones removed by sectionsExclude.
If the intent of the change was what the documentation hints to, then the functionality should be implemented differently.
Comment 4 Dave Russo CLA 2010-11-01 18:33:48 EDT
Actually you can use sectionsExclude with this parameter since the original content is computed and passed to the template as an argument which can be used to generate the new content.

Added the following clarification: 
     "The original
     *  "`SECTIONS`" content is computed and passed as an argument to this
     *  template, which makes it relatively simple to perform small changes to
     *  the "`SECTIONS`" content without having to explicitly handle every
     *  section required by the compiler toolchain."
Comment 5 Dave Russo CLA 2011-06-20 14:03:09 EDT
Shipped in XDCtools 3.21.
Comment 6 Dave Russo CLA 2011-06-20 14:05:11 EDT
Shipped in XDCtools 3.21