Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

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: gccAssignee: Marek Polacek <mpolacek>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.3CC: 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:
Description Flags
Email communication with Joe Mario and Compiler Group none

Description Kevin 2017-04-25 14:30:10 UTC
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

Comment 2 Florian Weimer 2017-06-26 10:14:54 UTC
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

Comment 11 Jeff Law 2017-11-28 19:11:15 UTC
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.