How to force linker to link unused const global variables?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to force linker to link unused const global variables?

ソリューションへジャンプ
5,587件の閲覧回数
wangyanjun
Contributor II
Thanks !
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
2,675件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
list them in a ENTRIES Var0 Var1 END block in the prm file. Check the linker manual.

元の投稿で解決策を見る

0 件の賞賛
返信
6 返答(返信)
2,674件の閲覧回数
wangyanjun
Contributor II
Is there any more simpler method? I have a lot of calibrated data to be treated as that. This method is too tedious. Thanks!
0 件の賞賛
返信
2,675件の閲覧回数
Lundin
Senior Contributor IV
The suggested method is good, because you won't have to alter the source code.

The alternative is less appealing:

/* unused variables: */
#pragam CONST_SEG GLOBAL_CONST
const int x = 123;
const int y = 456;
...
#pragma CONST_SEG DEFAULT


int main()
{
list_unused variables();
}


#pragma MESSAGE DISABLE C4002 /* result not used */
void list_unused variables()
{
(void) x;
(void) y;
...
}
#pragma MESSAGE DEFAULT C4002
0 件の賞賛
返信
2,675件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
That actually wont even help as the compiler has no reason to use x/y in list_unused variables, they are not volatile. So this version would need a few volatile's too, and would cause unnecessary code to be generated so its not the right thing to do anyway.

I would still propose to list the variables to be used. As alternative, the manual also specifies how to use ENTRIES with elf object file names and not just with individual objects. Details: In the linker manual part of
Help\PDF\Build_Tools_Utilities.pdf.

Daniel
0 件の賞賛
返信
2,675件の閲覧回数
Lundin
Senior Contributor IV
It does help.

(void) x;

translates to

0004 fc0000 LDD x

On the HCS12 compiler.
0 件の賞賛
返信
2,675件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Well, I would not rely on that optimization are not taking place.
For me, default options (say no options), CW For HC12 V4.6:

Code:
Function: list_unused_variables   18:  (void) x;   19:  (void) y;   20:  }  0000 3d           [5]     RTS  

Anyway, its not the right thing to do.

Daniel

0 件の賞賛
返信
2,676件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
list them in a ENTRIES Var0 Var1 END block in the prm file. Check the linker manual.
0 件の賞賛
返信