首页 > 解决方案 > [IAR]如何打印一段结束地址的开头?

问题描述

1.我在 .icf 中为 myTest 创建了一个自定义部分

define symbol __ICFEDIT_region_TEST_start__ = (0x10080000);
define symbol __ICFEDIT_region_TEST_end__ = (0x100DFFFF);
define region TEST_region  = mem:[from __ICFEDIT_region_TEST_start__ to __ICFEDIT_region_TEST_end__];
place at start of TEST_region {section .test_cases_entries};

2.我在test.c中编写了一些测试代码

#pragma section = ".test_cases_entries"
void pfm_test_cases_init(void)
{
  struct pwb_altest_desc *start,*stop;
  start = __section_begin(".test_cases_entries");
  stop = __section_end(".test_cases_entries");
  printf("test section start = %x \n\r",start);
  printf("test section end = %x \n\r",stop);
}
  1. 结果响应
test section start = 0
test section end = 0
  1. 预期结果:0x10080000 部分的开始?0x100DFFFF 部分结束?

标签: attributesldsectionsiarsymbolicc++

解决方案


__section_begin(".section")__section_end(".section")如果该部分的任何部分.section都不包含在最终二进制文件中,则为0 。在您的情况下,您首先必须确保该部分.test_case_entries不为空,即项目中的某些模块将数据放在该部分中。然后你需要让链接器在最终的二进制文件中包含这些数据。这可以通过引用某个模块中的数据(__section_begin并且__section_end不计算在内)、将数据声明为__root--keep在链接器命令行上使用来完成。

下面包括一个适用于我的机器的测试程序。请注意,.icf 文件并不完整,因为其中大部分取决于您的目标系统。

测试.c:

#include <stdio.h>

// Make the compiler recognize .section as a section for __section_begin and
// __section_end.
#pragma section = ".section"

void main(void)
{
  // Find the start and end address of .section
  int *start = __section_begin(".section");
  int *stop = __section_end(".section");
  printf("section start = %x \n", start);
  printf("section end = %x \n", stop);
}

// Put data in .section and make the data root to ensure is is included.
// This can be in a different file.
#pragma location=".section"
__root int data[100];

test.icf 的一部分

define symbol TEST_start = (0x10080000);
define symbol TEST_end   = (0x100DFFFF);
define region TEST_region  = mem:[from TEST_start to TEST_end];
place at start of TEST_region {section .section};

推荐阅读