Resolving problems creating reproducible binaries using Sun Studio Compilers



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:

cc -W0,-xglobalstatic

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:

-W0,-xp\\$XAqalkBBa5_D2Mo

For C++ this can be done with the wizard options
-Qoption ccfe -prefix -Qoption ccfe <prefix>, for example:

-Qoption ccfe -prefix -Qoption ccfe \\$XA0ZlkBtDTxEGkV.

Comments:

Douglas, Is there a way when just using -g to avoid the globalization completely with C and C++? I know this breaks the dbx fix&cont feature, but we can accept that. I realize that with -xipo or -xcrossfile you have to globalize the statics, but with -g it seems like we should have the option. Thanks. -kto

Posted by Kelly O'Hair on February 03, 2007 at 01:15 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Douglas is a principal software engineer working as the C compiler project lead and the Oracle Solaris Studio technical lead.

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  
       
Today