I just discovered that some parts of the code I am working on incorrectly uses writeable static data where it could/should use constant data.
Short of doing a dumb search-and-replace for “static” -> “static const”, is there any way to preventing all ‘static’ data from being writeable, much like how constant string data can be made explicitly writeable?
I am using the GCC toolchain, development target is x86.
There’s probably writable static data in some of the libraries you use. (Such as the standard C and C++ libraries). Making that const would be bad.
It’s probably better to go through your code and change things manually.
You can use
nmto get a list of symbols in your.ofiles. In thenmoutput, the first column gives the type of symbol; the lettersB,C,D,GorSindicate writable data. The last column gives the (mangled) variable name. It’s possible to write a little script to parse thenmoutput and look for these.