링커가 함수 및 변수를 제거하거나 외부 참조를 찾을 수 없음

기술노트 51348

아키텍처:

All

컴포넌트:

linker

업데이트:

2018-02-28 오전 2:54

Introduction

If functions and variables are not refered to in the main() call-tree or in any interrupt call-tree the linker will remove them by default.

You can prevent this and force the linker to keep a certain variable or function by using the __root extension keyword.

__root char myvariable;

__root void myfunction(void)
{
/* function code */
}

Other methods to keep the functions/variables are to use

  • IAR XLINK Linker -g option
  • IAR ILINK Linker --keep option
  • use the REQUIRE keyword in assembler

This behavior has the benefits:

  • Less use of RAM and ROM.
  • Reduced chance of "segment did not fit" errors.
  • Non-used "external" variables/functions are not searched for, which can lead to fewer errors.

The compiler also removes unused variables on absolute addresses.
This can lead to a problem when other modules refer to them.
It can be described with the below code.
Only the variable test1 will be kept in this compile unit.
test2, test3 and test4 are not kept since they are not accessed.
If you in some other C file use test2 as external, it will not be found by the linker.

__no_init int test1 @ 0x0004;
__no_init int test2 @ 0x0008;
__no_init int test3 @ 0x000C;
__no_init int test4 @ 0x0010;

void abc(void)
{
test1 = 1;
}

One important reason for doing like this is that the device specific .h files creates a very large number of variables which could create segment overlap errors if included in more than one module.

All product names are trademarks or registered trademarks of their respective owners.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.