Can we use Preprocessor or (Something like that) in Linker scripts?

Author
ravic
think_do_repeat
  • Total Posts : 120
  • Reward points : 0
  • Joined: 2016/02/04 03:02:20
  • Location: Bangalore, KA, India
  • Status: offline
2017/10/12 05:42:01 (permalink)
0

Can we use Preprocessor or (Something like that) in Linker scripts?

Hi,
         I am working with PIC32MZ2048EFH064, MPLABx 4.00, Harmony V2.01, XC32 V1.44.
 
I am trying to do like:
  • I have to write certain data to EEPROM or Either in Boot Flash Area.
  • If the #define USE_DATA_STORAGE is EEPROM then I need not to secure some memory portion in linker script for the data. I am storing that data to EEPROM then.
  • But if my #define is USE_DATA STORAGE is BOOT_FLASH then I have to secure Boot flash memory's last page for this data, so that my compiler won't write anything on it. And I can use this area as my storage.
 
I have options like,
  1. I can write two scripts (One with secured area and other with not) and one will be selected when the preprocessor is BOOT_FLASH my first linker will be selected and other will be excluded.
  2. I can write preprocessor directive in linker script also. This I really don't know whether linker script do support preprocessors
  3. I really don't have any idea about how to implement the above options. Or If you have better option, always welcome.
 

Always carry latest and best tools, whether it is WAR or PROGRAMMING
#1

2 Replies Related Threads

    Jim Nickerson
    User 452 _
    • Total Posts : 4111
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Can we use Preprocessor or (Something like that) in Linker scripts? 2017/10/12 07:31:41 (permalink)
    4.67 (3)
    from the release notes ( I use this, it works ):

    New Features in MPLAB® XC32 v1.34

  • New Part Support -- Support for several new PIC32MZ, PIC32MX, and PIC32MM MCUs was added for this release. See Devices Supported for a full list of devices.
  • Linker-Script Preprocessing -- A linker script is now passed to the C preprocessor before actual linking begins. This feature provides an opportunity to substitute macro definitions and to include conditional blocks of code. The C preprocessor is well-known by programmers and documentation for the preprocessor is widely available.
    Linker preprocessor options are listed in the sections below. When linking via the xc32-gcc driver, pass these options to the linker via the -Wl option (e.g. -Wl,-DMYMACRO=1).
  • -D<macro>[=value]
    Define a macro (with optional value) to the preprocessor. Macros can be used to substitute literal values into a script, such as for the origin or length of memory regions. They can also be used to select conditional blocks of code using directives such as #ifdef, #endif.
  • --no-cpp
    Do not preprocess linker scripts. Linker script preprocessing is enabled by default. This option can be used to disable preprocessing. Take care when selecting this option. If a linker script requires preprocessing (such as for conditional blocks of text), using this option will cause a processing error.
  • --save-gld
    Save preprocessed linker scripts. By default the result of preprocessing is a temporary file. This option can be used to save the preprocessed linker script. A filename is automatically generated based on the linker-script filename (e.g. p32MZ2048ECH100.ld.00) and located in your current working directory.

  • #2
    ravic
    think_do_repeat
    • Total Posts : 120
    • Reward points : 0
    • Joined: 2016/02/04 03:02:20
    • Location: Bangalore, KA, India
    • Status: offline
    Re: Can we use Preprocessor or (Something like that) in Linker scripts? 2017/10/13 01:45:02 (permalink)
    0
    Hi Jim, thanks for response. But I am really don't understand 'these' linker related things you are saying about. I mean I never worked with it before, So can you please give me an example or little simpler step by step process to do this?

    Always carry latest and best tools, whether it is WAR or PROGRAMMING
    #3
    Jump to:
    © 2017 APG vNext Commercial Version 4.5