1

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 = . ;
}
4

2 回答 2

0

如何编写条件测试并使用链接器脚本使构建失败?

在我看来,您可以将失败简单地实现为链接后步骤。例如在你的Makefile

foo.exe: foo.o
    $(CC) -o foo.exe ...
    nm foo.exe | grep BINARY_TEST | \
    ... commands to verify that symbol value < 32K, or fail
于 2014-04-17T14:48:48.720 回答
0

这是执行此操作的一种方法:

CHECK_BOOTLOADER_SIZE = 1 / (. <= 32768);

如果当前位置超出限制,这将给出错误消息:

linker.ld:33 / by zero

不是最清晰的错误消息,但至少它包含行号,以便用户可以阅读评论。

于 2022-03-04T13:04:45.763 回答