[Bug other/46770] Replace .ctors/.dtors with .init_array/.fini_array on targets supporting them
ppluzhnikov at google dot com
gcc-bugzilla@gcc.gnu.org
Tue Apr 17 15:30:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
--- Comment #76 from Paul Pluzhnikov <ppluzhnikov at google dot com> 2012-04-17 15:18:56 UTC ---
(In reply to comment #75)
> Can you provide a testcase?
// foo.h
struct Foo {
Foo(Foo *other) : x(other->x) { }
Foo() : x(42) { }
int x;
private:
Foo(const Foo&);
};
extern Foo foo_global;
// foo.cc
#include "foo.h"
Foo foo_global;
// main.cc
#include <assert.h>
#include "foo.h"
Foo foo(&foo_global);
int main() { assert(foo.x == 42); }
Above, foo.cc simulates a library, and main depends on that library having been
initialized.
Using pre-init_array GCC, this works:
g++ main.cc foo.cc && a.out
and this doesn't:
g++ foo.cc main.cc && ./a.out
a.out: main.cc:6: int main(): Assertion `foo.x == 42' failed.
Using post-init_array GCC, the behavior is reversed: natural link order
(libraries after main) is broken.
> ARM EABI has been using .init_array from day
> one. How does it work for ARM EABI?
It doesn't. We have a *lot* of programs that don't run on ARM though, and they
are all broken by this change.
Note: we do understand that the example above depends on undefined behavior,
and we do intend to eventually fix our source. But it will take a lot of
effort.
More information about the Gcc-bugs
mailing list