Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Static Initialization Order with icpc

Alexander_L_Intel
418 Views

Hi All,
Who have ever studied static objects initialization order (inter-module) with Intel compiler, could you pelase check and reply?

1. I understand that inter-module static initialization dependency is not defined by standard so strictly speaking Iwork with anincorrect program;
- I have to cope with it becauseI have no resources to fix my program (it will take man-years);
2. GNU initialization order looks to be clear and quite simple; we can influence it changing order of object files in the archive;
3. Intel compiler makes it in different ways in Release and Debug modes; Debug mode follows GNU algorithm;
4. I do not use -ipo, which certainly shall make initialization order a mess;
5. I use -O3

Any ideas guys, who has ever tried TO INFLUENCE INITIALIZATION ORDER with Intel?

0 Kudos
3 Replies
JenniferJ
Moderator
418 Views
We're compatible with GCC. But because this is not defined by standards, so the implementation details could be different.
Please detail the difference you see in debug/release build and I can check to see what we can do.

You can also file an issue report at our Premier Support "https://premier.intel.com/" as long as you have an eval license.

Jennifer
0 Kudos
TimP
Honored Contributor III
418 Views


2. GNU initialization order looks to be clear and quite simple; we can influence it changing order of object files in the archive;
3. Intel compiler makes it in different ways in Release and Debug modes; Debug mode follows GNU algorithm;
4. I do not use -ipo, which certainly shall make initialization order a mess;
5. I use -O3

I would have thought, by passing the objects to ar and ld in the same order as with g++, you might achieve the same sequence.
g++ -O3 implies -finline-functions, but g++ may not make the same substitutions as icpc. As your question seems indefinite to me, but implies that optimization has undesirable effects, you might also consider whether your icpc options are as close as possible to consistent with g++; for example -fp-model source if you don't set g++ -ffast-math.
0 Kudos
Judith_W_Intel
Employee
418 Views

If you're on Linux, can you just use the init_priority attribute? See details in the
Gnu documentation here:

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/C_002b_002b-Attributes.html
0 Kudos
Reply