Bug 1445370
| Summary: | Observed ordering change in static/global initializers with C++ from RHEL6 to RHEL7 | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Kevin <kevin.moran> | ||||
| Component: | gcc | Assignee: | Marek Polacek <mpolacek> | ||||
| Status: | CLOSED NOTABUG | QA Contact: | qe-baseos-tools-bugs | ||||
| Severity: | unspecified | Docs Contact: | |||||
| Priority: | unspecified | ||||||
| Version: | 7.3 | CC: | dkochuka, fweimer, jakub, kevin.moran, law, mnewsome, srandhaw | ||||
| Target Milestone: | rc | ||||||
| Target Release: | --- | ||||||
| Hardware: | Unspecified | ||||||
| OS: | Unspecified | ||||||
| Whiteboard: | |||||||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |||||
| Doc Text: | Story Points: | --- | |||||
| Clone Of: | Environment: | ||||||
| Last Closed: | 2017-11-28 19:11:15 UTC | Type: | Bug | ||||
| Regression: | --- | Mount Type: | --- | ||||
| Documentation: | --- | CRM: | |||||
| Verified Versions: | Category: | --- | |||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||
| Embargoed: | |||||||
| Bug Depends On: | |||||||
| Bug Blocks: | 1473718 | ||||||
| Attachments: |
|
||||||
Kevin, it seems that the email communication you attached to this ticket does not contain any details regarding the initializer ordering change you observed, and the reproducers (not attached to this bug) are concerned with the size change of debugging information. Note that the C++ language does not define a global initialization order between different files. Only within a single translation unit, global initialization is ordered according the the source file order. However, GNU C++ has an extension, init_priority, which allows you to influence the global initialization ordering: https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html The change was not mentioned in the Red Hat Enterprise Linux 7 release notes because the initialization order of different object files was already unspecified in Red Hat Enterprise Linux 6. The ISO C++ standard states that initialization of these objects is indeterminately sequenced. Depending on any particular ordering results in unspecified/undefined behavior.
Reordering of initialization was already possible in previous versions of Red Hat Enterprise Linux depending on compiler/linker options, ordering of files on the link line, and potentially other factors. It is unfortunate that the upgrade exposes a latent bug in your codebase, but this is the natural result of relying on unspecified behavior.
If you want to avoid the init_priority attribute and use a portable approach, you could replace the global variable xbfDG with a function like this:
xbfGlobalData &
xbfGlobalDataGet()
{
static xbfGlobalData gd;
return gd;
}
This way, the initialization will be performed as needed, upon the first reference to the object. Other global objects in your codebase may need similar treatment. (The GNU compiler implementation is thread-safe.)
Regarding the ability to run applications compiled on Red Hat Enterprise Linux 6 on Red Hat Enterprise Linux 7, Red Hat strongly recommends that application developers validate that any behavior they depend on is explicitly defined in formal API documentation and appropriate language standards to prevent introducing dependencies on unspecified implementation-specific semantics or introducing dependencies on bugs in a particular implementation.
|
Created attachment 1273940 [details] Email communication with Joe Mario and Compiler Group Description of problem: Observed ordering change in static/global initializers with C++ from RHEL6 to RHEL7 Version-Release number of selected component (if applicable): RHEL 6: gcc -E $STDCC xbfNotifier.C -o xbfNotifier-GCC4-4-7.i loyal.telcordia.com% echo $STDCC -g -m64 -fPIC -Wall -DNDEBUG -DBITS64 -D_REENTRANT -D_RWCONFIG=12d -DRW_MULTI_THREAD -D_THREAD_SAFE -DTELEXEL_MUTEX -DNOIPC -DPTHREADS -DPTHREAD_SAFE -D_TMPROTOTYPES -DXWF_USE_RW -D_REENTRANT -D_SYS_TIMES_INCLUDED -D_PROTOTYPES -Wno-deprecated -I. -I./C++ -I/usr/include/tirpc -I/export/force/envs_10_8_dev/dev/include -I/export/force/extern/10_8/include -I/export/force/extern/10_8/include/stubs -I/export/force/extern/10_8/include/sys -I/opt/vendor/rougewave_spc++/12.0.1 -I/usr/local/laure/10_8/include -I/opt/vendor/oracle/11204/xdk/include -I/usr/include/rpm RHEL 7: gcc -E $STDCC xbfNotifier.C -o xbfNotifier-GCC-4-8-5.i loyal.telcordia.com% echo $STDCC -g -m64 -fPIC -Wall -DNDEBUG -DBITS64 -D_REENTRANT -D_RWCONFIG=12d -DRW_MULTI_THREAD -D_THREAD_SAFE -DTELEXEL_MUTEX -DNOIPC -DPTHREADS -DPTHREAD_SAFE -D_TMPROTOTYPES -DXWF_USE_RW -D_REENTRANT -D_SYS_TIMES_INCLUDED -D_PROTOTYPES -Wno-deprecated -I. -I./C++ -I/usr/include/tirpc -I/export/force/envs_10_8_1_dev/dev/include -I/export/force/extern/10_8_1/include -I/export/force/extern/10_8_1/include/stubs -I/export/force/extern/10_8_1/include/sys -I/opt/vendor/rougewave_spc++/12.0.1 -I/usr/local/laure/10_8_1/include -I/opt/vendor/oracle/11204/xdk/include -I/usr/include/rpmSteps to Reproduce: 1. 2. 3. Actual results: change in behavior from RHEL6 linker version to RHEL7 linker version. Can Redhat provide documentation saying how the linker works differently in GCC 4.8 than the previous releases in terms of static and global initialization Expected results: Additional info: How reproducible: Can't in a small program. Hoping there's some type of debugging, trace that can show initialization ordering differences