Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make or Shell Variables In Linker Script

Is it possible for a linker script to access makefile/shell variables and make a decision based on the said variable?

For example, suppose I want to change the start of the RAM area below without using a different linker script, would it be possible to use a make variable to do this?

MEMORY
{
ifeq ($(SOME_VAR),0)
RAM (wx) : ORIGIN = 0x100000, LENGTH = 128K
else
RAM (wx) : ORIGIN = 0x200000, LENGTH = 128K
endif
}
like image 505
jkayca Avatar asked Jun 07 '12 18:06

jkayca


People also ask

How do you make a linker script?

You write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments or an assignment to a symbol. You may separate commands using semicolons. Whitespace is generally ignored.

What is in linker script?

The Linker Script is a text file made up of a series of Linker directives which tell the Linker where the available memory is and how it should be used. Thus, they reflect exactly the memory resources and memory map of the target microcontroller.

What is GCC linker script?

This script is written in the linker command language. The main purpose of the linker script is to describe how the sections in the input files should be mapped into the output file, and to control the memory layout of the output file. Most linker scripts do nothing more than this.

What is align in linker file?

Section alignment with the linkerThe linker permits ELF program headers and output sections to be aligned on a four-byte boundary regardless of the maximum alignment of the input sections. This enables armlink to minimize the amount of padding that it inserts into the image.


1 Answers

ld does not import any variables from the environment, so it cannot use them directly. The best way to do this is to create your own linker script with the environment variables you want to export, and have the original linker script include it as so:

makefile:

foo:
    echo SOMEVAR=$(SOMEVAR) > environment_linker_script
    ld ...

enviroment_linker_script:

SOMEVAR=xxx

master_linker_script:

include environment_linker_script

ifeq ($(SOME_VAR),0) ...
like image 81
John Avatar answered Nov 01 '22 02:11

John