-
Bug
-
Resolution: Fixed
-
Medium
-
Code Generation Tools
-
CODEGEN-10848
-
-
-
default
-
When using --abi=eabi, the compiler incorrectly places class variables that will be dynamically initiailized into the .const section instead of the .data section. This results in incorrect runtime initialization of the variables that were incorrectly placed in .const
More details:
----------------
The attached file has these lines ...
#include <stdint.h> class has_static_members final { public: static const float c_Pi = 3.14f; static const float c_2Pi; // init'd elsewhere static const float c_3Pi; // init'd elsewhere static const uint32_t c_beef = 0xDEADBEEF; static const uint32_t c_var; // init'd elsewhere }; class use_variables final { public: const float not_static_c_Pi; const float not_static_c_2Pi; const float not_static_c_3Pi; const uint32_t not_static_c_beef; const uint32_t not_static_c_var; }; // This instance of the class is put in the .const section, then a function // is auto-generated which writes to some of these members variables volatile static const use_variables instance = { has_static_members::c_Pi, // OK has_static_members::c_2Pi, // WRITTEN! has_static_members::c_3Pi, // WRITTEN! has_static_members::c_beef, // OK has_static_members::c_var // WRITTEN! };
Build it ...
% cl2000 --abi=eabi -o0 -s file.cpp
Inspect the resulting assembly file. These lines show that the instance of the class is in .const ...
.sect ".const" .align 2 .elfsym ||instance||,SYM_SIZE(10) ||instance||: .xfloat $strtod("0x1.91eb86p+1") ; instance.not_static_c_Pi @ 0 .xfloat $strtod("0x0p+0") ; instance.not_static_c_2Pi @ 32 .xfloat $strtod("0x0p+0") ; instance.not_static_c_3Pi @ 64 .bits 0xdeadbeef,32 ; instance.not_static_c_beef @ 96 .bits 0,32 ; instance.not_static_c_var @ 128
These lines are the beginning of an auto-generated function which writes to some members in instance ...
||__sti___8_file_cpp_b59a82a8||: ;*** 25 ----------------------- instance.not_static_c_2Pi = has_static_members::c_2Pi; ;*** 25 ----------------------- instance.not_static_c_3Pi = has_static_members::c_3Pi; ;*** 25 ----------------------- instance.not_static_c_var = has_static_members::c_var;
The function _sti__8_file_cpp_b59a82a8 is called by the startup code. Thus, by the time main starts, the mistaken writes to these members of instance have already occurred.