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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
1,783 Views
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.

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
964 Views
CrasyCat
Specialist III

Hello

 

Did you look at linker option -Cocc?

 

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

 

CrasyCat

 

View solution in original post

0 Kudos
Reply
4 Replies
964 Views
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 Kudos
Reply
965 Views
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 Kudos
Reply
964 Views
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 Kudos
Reply
964 Views
tomlogic
Contributor III

Additional info: HC08, CodeWarrior 5.9.0

0 Kudos
Reply