Bug 53228 - [4.6/4.7/4.8 Regression] target attributes in libcpp/lex.c cause illegal instructions to be used elsewhere
Summary: [4.6/4.7/4.8 Regression] target attributes in libcpp/lex.c cause illegal inst...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.1
: P3 major
Target Milestone: 4.5.4
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: wrong-code
: 48326 55816 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-05-04 08:33 UTC by Richard Biener
Modified: 2021-08-15 05:43 UTC (History)
2 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-05-04 00:00:00


Attachments
preprocessed source (35.42 KB, application/octet-stream)
2012-05-04 08:33 UTC, Richard Biener
Details
Proposed patch (1.01 KB, patch)
2012-05-04 11:37 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2012-05-04 08:33:04 UTC
When building libcpp/lex.c for -march=i586 and -mtune=generic on i586-linux-gnu
generic code contains cmov* instructions which will SIGILL on

finger@mtech:~> cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 8
model name      : AMD-K6(tm) 3D processor
stepping        : 12
microcode       : 0x8b
cpu MHz         : 428.811
cache size      : 64 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr cx8 pge mmx syscall 3dnow k6_mtrr up
bogomips        : 857.62
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

CPUs which are perfectly fine matching -march=i586.

When you remove all target attribute annotated code from lex.c these
instructions disappear.

Thus, a compiler built for i586 does not work.

The bug persists with GCC 4.6, 4.7 and 4.8.
Comment 1 Richard Biener 2012-05-04 08:33:53 UTC
Created attachment 27304 [details]
preprocessed source

Preprocessed lex.c from the 4.6 branch.
Comment 2 Andrew Pinski 2012-05-04 08:43:09 UTC
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49104 ?
Comment 3 Richard Biener 2012-05-04 08:57:44 UTC
The revision that supposedly fixed the issue is in reporters sources
(for reference: https://bugzilla.novell.com/show_bug.cgi?id=760210).

Note that I see cmov* instructions in _cpp_clean_line, _cpp_temp_token,
cpp_avoid_paste, cpp_output_line_to_string and more.  _Not_ only in the
SSE marked functions.
Comment 4 Uroš Bizjak 2012-05-04 11:37:48 UTC
Created attachment 27305 [details]
Proposed patch

Untested patch that changes TARGET_CMOVE test.
Comment 5 Richard Biener 2012-05-04 11:44:02 UTC
I can confirm the patch works though I don't trivially see how it fixes the
interaction with the option save/restore code ;)
Comment 6 Uroš Bizjak 2012-05-04 12:46:24 UTC
(In reply to comment #5)
> I can confirm the patch works though I don't trivially see how it fixes the
> interaction with the option save/restore code ;)

It doesn't "fix" anything in option processing code, the patch avoids changing ix86_arch_features behind option processing back.
Comment 7 uros 2012-05-04 16:42:32 UTC
Author: uros
Date: Fri May  4 16:42:23 2012
New Revision: 187168

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187168
Log:
	PR target/53228
	* config/i386/i386.h (X86_ARCH_CMOV): Rename from X86_ARCH_CMOVE.
	(TARGET_CMOV): Rename from TARGET_CMOVE.
	(TARGET_CMOVE): New define.
	* config/i386/i386.c (ix86_option_override_internal): Use TARGET_CMOV.
	Do not set TARGET_CMOVE here.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/i386.h
Comment 8 uros 2012-05-04 16:58:21 UTC
Author: uros
Date: Fri May  4 16:58:16 2012
New Revision: 187169

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187169
Log:
	Backport from mainline
	2012-05-04  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53228
	* config/i386/i386.h (X86_ARCH_CMOV): Rename from X86_ARCH_CMOVE.
	(TARGET_CMOV): Rename from TARGET_CMOVE.
	(TARGET_CMOVE): New define.
	* config/i386/i386.c (ix86_option_override_internal): Use TARGET_CMOV.
	Do not set TARGET_CMOVE here.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/i386.c
    branches/gcc-4_7-branch/gcc/config/i386/i386.h
Comment 9 uros 2012-05-04 17:49:00 UTC
Author: uros
Date: Fri May  4 17:48:56 2012
New Revision: 187171

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187171
Log:
	Backport from mainline
	2012-05-04  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53228
	* config/i386/i386.h (X86_ARCH_CMOV): Rename from X86_ARCH_CMOVE.
	(TARGET_CMOV): Rename from TARGET_CMOVE.
	(TARGET_CMOVE): New define.
	* config/i386/i386.c (ix86_option_override_internal): Use TARGET_CMOV.
	Do not set TARGET_CMOVE here.


Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/i386/i386.c
    branches/gcc-4_6-branch/gcc/config/i386/i386.h
Comment 10 uros 2012-05-04 18:43:16 UTC
Author: uros
Date: Fri May  4 18:43:10 2012
New Revision: 187172

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187172
Log:
	Backport from mainline
	2012-05-04  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53228
	* config/i386/i386.h (X86_ARCH_CMOV): Rename from X86_ARCH_CMOVE.
	(TARGET_CMOV): Rename from TARGET_CMOVE.
	(TARGET_CMOVE): New define.
	* config/i386/i386.c (override_options): Use TARGET_CMOV.
	Do not set TARGET_CMOVE here.


Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/config/i386/i386.c
    branches/gcc-4_5-branch/gcc/config/i386/i386.h
Comment 11 Uroš Bizjak 2012-05-04 18:45:58 UTC
Fixed everywhere.
Comment 12 Andrew Pinski 2021-08-15 05:42:43 UTC
*** Bug 55816 has been marked as a duplicate of this bug. ***
Comment 13 Andrew Pinski 2021-08-15 05:43:07 UTC
*** Bug 48326 has been marked as a duplicate of this bug. ***