Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linker 如何基于链接器脚本中定义的链接器变量的条件值使构建失败?_Linker_Linker Errors_Linker Scripts - Fatal编程技术网

Linker 如何基于链接器脚本中定义的链接器变量的条件值使构建失败?

Linker 如何基于链接器脚本中定义的链接器变量的条件值使构建失败?,linker,linker-errors,linker-scripts,Linker,Linker Errors,Linker Scripts,如何基于链接器脚本中定义的链接器变量的条件值使构建失败 我正在使用GCC编译C代码。我定义了一个链接器变量BINARY_TEST。如果BINARY_TEST的值>32KB,那么我希望构建失败。如何使用链接器脚本编写条件测试并使生成失败? 请建议任何脚本 SECTIONS { . = 0x0000 ; .text : { *(.text) *(.rdata) } .data : {

如何基于链接器脚本中定义的链接器变量的条件值使构建失败

我正在使用GCC编译C代码。我定义了一个链接器变量BINARY_TEST。如果BINARY_TEST的值>32KB,那么我希望构建失败。如何使用链接器脚本编写条件测试并使生成失败? 请建议任何脚本

SECTIONS
{
  . = 0x0000 ;

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

  }

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

  BINARY_TEST = . ;

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

  END = . ;
}
如何使用链接器脚本编写条件测试并使生成失败

在我看来,您可以将失败简单地实现为一个链接后步骤。例如,在您的
生成文件中

foo.exe: foo.o
    $(CC) -o foo.exe ...
    nm foo.exe | grep BINARY_TEST | \
    ... commands to verify that symbol value < 32K, or fail
foo.exe:foo.o
$(CC)-o foo.exe。。。
nm foo.exe | grep BINARY|u TEST |\
... 验证符号值<32K或失败的命令

谢谢@Employed俄语。但我正在寻找链接器脚本方法。@RajivKumarSrivastav为什么要寻找链接器脚本方法?