On MinGW32, GCC 4.3.0 marks the .text.unlikely section as "w"(writable) instead of "x"(executable), which makes the assembler to pad the section with zeros instead of NOPs. Runtime behavior is almost always incorrect and in many cases an application will crash.
Created attachment 15356 [details] Sample C file that gets compiled incorrectly Compile with "gcc -march=pentium-m -mtune=generic -O3 -fomit-frame-pointer -c" will give an object. Run "objdump -D" over the object and you'll see several "add %al,(%eax)" that should be NOP instead.
Subject: Re: __attribute__((cold)) generates wrong code 21 Mar 2008 20:17:53 -0000, pinskia at gcc dot gnu dot org <gcc-bugzilla@gcc.gnu.org>: > > > -- > > pinskia at gcc dot gnu dot org changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Severity|major |normal Sorry. I just revert it back. I didn't know it's intentionally changed by someone else...
Created attachment 15437 [details] Proposed patch against 4.3.0, marking .text.unlikely as executable.
The MinGW port has no idea of the unlikely text section ever since r80564, so it's likely that the fix should be applied to any release branch pulled after r80564; although before 4.3.0 the bug only affects profile feedback.
Subject: Bug 35661 Author: dannysmith Date: Mon Apr 14 23:47:39 2008 New Revision: 134296 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134296 Log: 2008-04-16 Zuxy Meng <zuxy.meng@gmail.com> PR target/35661 * config/i386/winnt.c (i386_pe_section_type_flags): Mark ".text.unlikely" section as executable. Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/winnt.c
Subject: Bug 35661 Author: dannysmith Date: Sun May 11 21:03:27 2008 New Revision: 135188 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135188 Log: Backport from mainline: 2008-04-15 Zuxy Meng <zuxy.meng@gmail.com> PR target/35661 * config/i386/winnt.c (i386_pe_section_type_flags): Mark ".text.unlikely" section as executable. Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/config/i386/winnt.c
Fixed on 4_3 branch