The change in crtend.asm causes the wrong init oder.
Created attachment 6025 [details] A testcase # make /usr/gcc-3.4/bin/gcc -O -g -c -o bar.o bar.c /usr/gcc-3.4/bin/gcc -static bar.o -o bar ./bar preinit array 0 preinit array 1 preinit array 2 init array 0 init array 1 init array 2 init fini array 2 fini array 1 fini array 0 fini The right one should be [hjl@gnu-4 init]$ make CC=gcc gcc -O -g -c -o bar.o bar.c /tmp/ccyDlcv7.s: Assembler messages: /tmp/ccyDlcv7.s:184: Warning: ignoring incorrect section type for .preinit_array/tmp/ccyDlcv7.s:292: Warning: ignoring incorrect section type for .init_array /tmp/ccyDlcv7.s:400: Warning: ignoring incorrect section type for .fini_array gcc -static bar.o -o bar ./bar preinit array 0 preinit array 1 preinit array 2 init init array 0 init array 1 init array 2 fini array 2 fini array 1 fini array 0 fini
The last change to crtend.asm was over a year ago why was this not found way before the release?
Created attachment 6026 [details] A patch This patch should work for both 3.4 and 3.5.
H.J., can you please post your patches to gcc-patches and put URL into gcc-patches archive into the PRs instead of just attaching them to PRs and not mentioning them on gcc-patches at all?
The bug was introduced by http://gcc.gnu.org/ml/gcc-cvs/2003-05/msg00274.html
Created attachment 6080 [details] An updated patch __do_jv_register_classes should be place before __do_global_ctors_aux to preserve the init order the same as gcc 3.3.
A testcase is posted at http://gcc.gnu.org/ml/gcc-patches/2004-04/msg00788.html
Subject: Re: [3.4/3.5 Regression] The wrong init order pinskia at gcc dot gnu dot org wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-01 20:05 ------- > The last change to crtend.asm was over a year ago why was this not found way before the release? This only fails if an application or library uses init_array/fini_array. GCC still uses ctors/dtors sections instead of the preferred and standardized init_array/fini_array sections. So the only way that you can trigger this problem is if someone explicitly uses attribute section init_array, or if you link with code compiled by another compiler. I suspect the latter method is how HJ found the problem, e.g. he may have noticed the problem after trying to link icc compiled code with gcc compiled code.
Subject: Bug 14813 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: hjl@gcc.gnu.org 2004-04-21 23:19:09 Modified files: gcc : ChangeLog gcc/config/ia64: crtbegin.asm crtend.asm Log message: 2004-04-21 H.J. Lu <hongjiu.lu@intel.com> PR target/14813 Backport from mainline: * config/ia64/crtend.asm: Move pointer to __do_global_ctors_aux in .init_array section to ... * config/ia64/crtbegin.asm: Here. * config/ia64/crtend.asm: Mark __do_global_ctors_aux global and hidden if HAVE_INITFINI_ARRAY is defined. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.405&r2=2.2326.2.406 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/crtbegin.asm.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.16&r2=1.16.16.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/ia64/crtend.asm.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.12&r2=1.12.16.1
Fixed for 3.4.1.