0
votes

How to fail the build based on the conditional values of linker variables defined in linker script?

I am compiling C code using GCC. I defined a linker variable BINARY_TEST. If Value of BINARY_TEST > 32KB, then i want to Fail the build. How to write a conditional test and fail the build using linker script? Please suggest any script.

SECTIONS
{
  . = 0x0000 ;

  .text : 
  { 
    *(.text)
    *(.rdata)                             

  }

  .data :
  {
    *(*.data)
    *(*.bss)       
  }

  BINARY_TEST = . ;

  /*Want something like below */   
  if (BINARY_TEST > 32KB) 
     Throw Error and stop
  /* ******* */ 

  END = . ;
}
1

1 Answers

0
votes

How to write a conditional test and fail the build using linker script?

It seems to me that you could trivially implement the failure as a post-link step. E.g. in your Makefile:

foo.exe: foo.o
    $(CC) -o foo.exe ...
    nm foo.exe | grep BINARY_TEST | \
    ... commands to verify that symbol value < 32K, or fail