Adding a condition to Linker Command File - linker

Can i write a condition in the .lcf ?
I want to check if the sum of certain sections is above a certain threshold. if yes i want the linker to show Error/Warning
I'm new to the .lcf and i don't know if this is possible or not.
Any Advice ?
Linker : WindRiver Linker 5.9.4

The following line if added to the .lcf will give a linker error if the value is above the threshold:
ASSERT( value < threshold, " The value is above the threshold ")

Related

Expression evaluation in linker script

In a GNU LD linker script, I have the following code
_. = ASSERT((__SEC1_FREE_END - __SEC2_VAR_START)>= 128,"Report error");
The above command does not report an error if __SEC2_VAR_START is greater than __SEC1_FREE_END,
i.e when the subtraction operation evaluates to be a negative number the linker does not report an error and exit as expected.
I scanned through several documentation files but could not find if any typecasting is done while evaluating the expressions in linker scripts.
How can we explain the behaviour exhibited here?

Using conditional logic with env variable in GCC Linker script

I have a build environment variable available, let's say for differentiating 2 hardware variants: HW_VER1
We are using linker script in build.
So, we want something like this. But, of course below gives error "invalid syntax in flags"
MEMORY
{
ifeq ($(HW_VER1),YES)
iram0_0_seg : org = 0x00080400, len = 0x21C00
else
iram0_0_seg : org = 0x00080400, len = 0xf1C00
endif
}
The requirement is not to use 2 linker scripts with the same exact contents, except the len value above, and let build system decide which one based on the env variable (the one with bigger len or smaller len based on the hw ver)

Is it possible to change the value of CONSTANT(MAXPAGESIZE) in a linker script

I am using ld with a custom link script (modified from the default script used by gcc) and I noticed that the default value for CONSTANT(MAXPAGESIZE) on ARM is 64KiB. I need this value to be 4KiB.
I am aware that I can change this value on the command line by invoking
ld -z max-page-size=0x1000 .....
However I'd like to know if there is a way to change the value of the symbolic constant MAXPAGESIZE in the script rather than on the command-line, in order to just give the script to co-workers and not having to change their Makefiles.
At the moment, my fall-back plan is to hardcode the value by replacing CONSTANT(MAXPAGESIZE) with 0x1000 inside the script.
here :
link-ldflags += -z max-page-size=4096

Error: L6218E: Undefined symbol main (referred from __rtentry2.o)

anyone can help me?? my board is LPC1768 and the sensor is BMP180
Rebuild target 'Target 1'
compiling BMP180.c...
compiling I2C.c...
assembling startup_LPC17xx.s...
compiling system_LPC17xx.c...
compiling GPIO_LPC17xx.c...
compiling PIN_LPC17xx.c...
linking...
.\Objects\asdsa.axf: Error: L6218E: Undefined symbol main (referred from __rtentry2.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
".\Objects\asdsa.axf" - 1 Error(s), 0 Warning(s).
Target not created.
I found the solution is easy, but before going deeper into the solution, keep in mind that C compilation unit (C Compiler and Assembler at least) compiles each pure C source file after resolving necessary pre-processor directives, and generates a relocatable object file as a result of compilation.
After the compilation unit does its job, there is another unit that is responsible for combining individually every source file that is compiled successfully into the relocatable form of one big object file for all. This unit is called Linker and the operation is called Linking
A very important feature in relocatable object file is that what is called variable, function will be noted as symbol so far. The linker has to solve the symbols, defining what is originally defined in an object file, reference what is being used in another to their original object file.
After this motivation, now we can call main() function as main() symbol.
I Found that the problem is because the source file that contains the main() function was not compiled. As a result, there is no a relocatable object file that contains the symbol corresponding to main() function. Hence, the compiler is complaining: you asked me to use (reference) a symbol you guaranteed to be found (defined) in another file but I found no such symbol!
The solution:
For Kiel IDE, to queue a source file for a compilation; you gotta shortlist it in the category "Source Group",by clicking right, either adding new files to group, or existing files to group. It will result in something like the following figure:
Now we have a main function, is turned (defined) to main symbol later, and found by the linker to reference it to whatever use it in any other relocatable object files.
I solved this problem with the following steps;
Delete your old project and create new project
Choose true library from Manage Run Time Environment like so:
Configure "Options for Target" segment. Define symbol USE_STDPERIPH_DRIVER and define project path like so:
Test your configuration. Please write the following code:
#include "stm32f10x.h" // Device header
int main() {
}
I had the same issue. The problem was that the function name in .c file had a different name with the one in the .h file, and I didn't know.
just add your c file (ex: 'main.c') to the source group (ex: 'source group 1') by expanding the target then right click on the source group, choose add existing files to group 'your source group', then choose the main.c file.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/14222.html
This should help.
Just create a dummy main() or main.c file. Linker can't find it in your pjt.
For solution only add this file C to driver folder and translate it,
Solved: This "Target Not Created" Issue was Resolved by the setting of Run Time Environment as shown in below(url) image.https://i.stack.imgur.com/kJ4IL.jpg ( consisting of CMSIS and Device supporting components in Run time environment)
{ compiling TransformFunctions.c...
linking...
Program Size: Code=768 RO-data=320 RW-data=4 ZI-data=612
FromELF: creating hex file...
".\Objects\LPC1768_B_T.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:07
}

avr-ld error: "gc-sections requires either an entry or an undefined symbol"

Using avr-gcc and attempting to reduce size of binary using -ffunction-sections and -fdata-sections when compiling and linking with --gc-sections. The .lds file contains nothing:
SECTIONS
{
}
This error occurs when partial linking many .o's into a .a, which will then be used later to complete the build.
I've read through some other posts that discuss these options, but nothing that clarifies the ENTRY() issue. Their doesn't seem to be a need for it at the partial stage before trying to reduce code size(pre-existing linker script clearly doesn't use it).
Documentation states : --gc-sectionts
"This option can be set when doing a partial link (enabled with option '-r'). In this case the root of symbols kept must be explicitly specified either by an '--entry' or `--undefined' option or by a ENTRY command in the linker script."
This is where I'm lost. Would greatly appreciate some more explanation of how to use --undefined, --entry, or ENTRY cmd in linker script to resolve this issue.
I had a similar issue and gave up. I ended up compiling with the -fwhole-program option enabled which significantly reduced the size of my bootloader.

Resources