Bug 35661 - __attribute__((cold)) generates wrong code
Summary: __attribute__((cold)) generates wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-21 20:14 UTC by Zuxy
Modified: 2008-05-11 21:09 UTC (History)
2 users (show)

See Also:
Host: i686-pc-mingw32
Target: i686-pc-mingw32
Build: i686-pc-mingw32
Known to work:
Known to fail:
Last reconfirmed: 2008-04-07 02:00:23


Attachments
Sample C file that gets compiled incorrectly (176 bytes, text/plain)
2008-03-21 20:18 UTC, Zuxy
Details
Proposed patch against 4.3.0, marking .text.unlikely as executable. (337 bytes, patch)
2008-04-07 06:00 UTC, Zuxy
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zuxy 2008-03-21 20:14:41 UTC
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.
Comment 1 Zuxy 2008-03-21 20:18:37 UTC
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.
Comment 2 Zuxy 2008-03-21 20:23:24 UTC
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...

Comment 3 Zuxy 2008-04-07 06:00:16 UTC
Created attachment 15437 [details]
Proposed patch against 4.3.0, marking .text.unlikely as executable.
Comment 4 Zuxy 2008-04-13 12:18:22 UTC
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.
Comment 5 dannysmith@gcc.gnu.org 2008-04-14 23:48:23 UTC
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

Comment 6 dannysmith@gcc.gnu.org 2008-05-11 21:04:14 UTC
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

Comment 7 Danny Smith 2008-05-11 21:09:44 UTC
Fixed on 4_3 branch