Resolving problems creating reproducible binaries using Sun Studio Compilers
By C Project Lead on Jul 24, 2006
Certain flags (-g, -xipo, -xcrossfile) invoke features of the Sun
Studio Compilers and tools that must make static data global. To avoid
namespace collisions, the data is globalized using a unique
globalization prefix. The drawback of using a unique globalization
prefix is that the resulting object files will be different every time
the source file is compiled, even though the sources and compilation
options are identical. So, if you compare the resulting object files
from two identical compilations they will differ.
If you are in an environment that requires the ability to reproduce
identical object files, this becomes a problem.
Both C and C++ have an undocumented flag (-xglobalstatic) that can be
passed to the compiler front-end which will force the use of a static
globalization prefix based on the source filepath, instead of the usual
algorithm that guarantees a unique prefix. To pass the flag to cc use
the -W0 option as follows:
To pass the flag to CC use the -Qoption ccfe option as follows:
CC -Qoption ccfe -xglobalstatic
The drawback to using the filepath to generate the globalization prefix
is the increased risk of a namespace collision at link time between
static data with the same name that has been globalized from two files
with the same filepaths. Though rare it does occur more often than
using a randomly generated prefix.
If you do run into namespace collisions, you might need to assign
the globalization prefix. For C this can be done with the
wizard option -W0,-xp<prefix>, for example:
For C++ this can be done with the wizard options
-Qoption ccfe -prefix -Qoption ccfe <prefix>, for example:
-Qoption ccfe -prefix -Qoption ccfe \\$XA0ZlkBtDTxEGkV.