Duplicate string literals in final binary -- compiler optimization to "Reuse Strings"?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Duplicate string literals in final binary -- compiler optimization to "Reuse Strings"?

跳至解决方案
2,544 次查看
tomlogic
Contributor III

Browsing through the MAP file for my project, I saw that it contained multiple copies of some string literals (in my case "0123456789abcdef", used in multiple debug locations to dump byte arrays, and even the empty string "").  I searched quite a bit for a compiler option similar to the "Reuse Strings" option for the Coldfire compiler, but to no avail.

 

Is there some way to get the compiler to only link one copy of the string literal into the final binary?

 

I understand that I can create a constant char array, but that creates a dependency from these unrelated functions that I use on other platforms.  I'm surprised that a compiler for such a resource-constrained target wouldn't consolidate string literals as much as possible.

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,725 次查看
CrasyCat
Specialist III

Hello

 

Did you look at linker option -Cocc?

 

This one seems to be doing what  you are trying to achieve.

 

CrasyCat

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,725 次查看
bigmac
Specialist III

Hello,

 

I don't quite understand your dependency argument with respect to "unrelated functions".  I might assume a globally defined const char array, to be accessible to any function that required its use.

 

Regards,

Mac

 

0 项奖励
回复
1,726 次查看
CrasyCat
Specialist III

Hello

 

Did you look at linker option -Cocc?

 

This one seems to be doing what  you are trying to achieve.

 

CrasyCat

 

0 项奖励
回复
1,725 次查看
tomlogic
Contributor III

That's exactly what I needed.  I guess I overlooked that option when I was looking at the linker options.

 

Thanks!

0 项奖励
回复
1,725 次查看
tomlogic
Contributor III

Additional info: HC08, CodeWarrior 5.9.0

0 项奖励
回复