| Summary: | C++ global constructors are running out of order | ||
|---|---|---|---|
| Product: | [Build System, Metadata & Runtime] OE-Core | Reporter: | Mark Hatle <mark.hatle> |
| Component: | devtools / tool chain | Assignee: | Nitin Kamble <nitin.a.kamble> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | critical | ||
| Priority: | High | CC: | meta.mr.watcher, meta.watcher, qing.he, sgw |
| Version: | 1.0 | ||
| Target Milestone: | 1.0 PointRelease | ||
| Hardware: | Other | ||
| OS: | arm | ||
| Whiteboard: | |||
| OS type for building Yocto: | --- | Type of Regression: | --- |
| Verified: | Documentation change: | --- | |
| Bug Depends on: | |||
| Bug Blocks: | 827 | ||
|
Description
Mark Hatle
2011-03-29 09:41:52 UTC
The reason that ArchCompatSet is constructed before IdString is that it's invoked by another const constructor in some other file.
The exact spot is at zypp/Repository.cc:32, following is the run path
that actually initializes it:
const Repository Repository::noRepository;
-> zypp::Repository::Repository();
-> zypp::RepoInfo::RepoInfo();
-> zypp::RepoInfo::Impl::Impl();
-> zypp::repo::RepoVariablesUrlReplacer::RepoVariablesUrlReplacer();
-> zypp::repo::RepoVariablesStringReplacer::RepoVariablesStringReplacer();
The definition of the final node on the chain is at
zypp/repo/RepoVariables.cc:26
---
RepoVariablesStringReplacer::RepoVariablesStringReplacer()
{
sysarch = Arch_empty;
basearch = Arch_empty;
}
--
Where Arch_empty is defined in zypp/Arch.cc:
--
const Arch Arch_empty ( IdString::Empty );
--
At this point, the initialization order of zypp::Repository::noRepository
and zypp::Arch_empty is undefined (which is also referred to as the
"static initialization order fiasco"), since they belong to different
compilation units (read, .cc file).
On x86, we are fortunate that Arch_empty is init'ed before noRepository, but
on arm the order is reversed. When the constructor of
RepoVariablesStringReplacer
runs, Arch_empty is not constructed yet, and it immediately leads to
undefined behavior. On g++ 4.5.0, this will result in default
constructor of Arch, i.e. Arch::Arch() being called, and then
ArchCompatSet::instance(), which leads to the pre-mature construction of
the compatibility table. That's why zypper on arm fails.
(In reply to comment #1) > The reason that ArchCompatSet is constructed before IdString is that it's > invoked by another const constructor in some other file. i.e. this bug is not related to toolchain or arm, but fully inside libzypp. The initialization order of two global variables in two .cc file doesn't have a fixed order, the compiler and linker is not possible to determine the right order. So this "out of order" is caused by the ill-written constructors, the behavior of g++ is ok. It's suggested that the bug change to zypper bug and have the priority lowered. |