Bug 63228 - -m16 doesn't work if gcc is compiled for x32
Summary: -m16 doesn't work if gcc is compiled for x32
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: 4.9.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-11 18:25 UTC by mikulas
Modified: 2014-09-11 22:29 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux-gnux32
Target: x86_64-linux-gnux32
Build: x86_64-linux-gnux32
Known to work:
Known to fail:
Last reconfirmed: 2014-09-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mikulas 2014-09-11 18:25:41 UTC
When gcc is configured and compiled for x32 mode (x86_64-linux-gnux32 triplet), the flag -m16 doesn't work. The bug was reproduced on gcc-4.9.1-13 from Debian Ports x32 distribution (https://wiki.debian.org/X32Port)

Attempting to compile or assemble anything with "gcc -m16 -march=i386" results in this error message:
error: CPU you selected does not support x86-64 instruction set
(this error causes linux kernel 3.16.2 compilation failure)

If you remove "-march=i386", the file is compiled, but it can't be assembled, because gcc generates incorrect assembler as if it was x86_64 target. For example, compiling a file test.c containing "int bla(void) { return 3; }" with "gcc -c -m16 test.c", results in these error messages:
/tmp/cc89iTZG.s: Assembler messages:
/tmp/cc89iTZG.s:9: Error: bad register name `%rbp'
/tmp/cc89iTZG.s:15: Error: bad register name `%rbp'

When gcc is configured for x86_64 mode (x86_64-unknown-linux-gnu), -m16 works correctly.
Comment 1 H.J. Lu 2014-09-11 19:53:15 UTC
A patch is posted at

https://gcc.gnu.org/ml/gcc-patches/2014-09/msg00987.html
Comment 2 hjl@gcc.gnu.org 2014-09-11 22:18:38 UTC
Author: hjl
Date: Thu Sep 11 22:18:06 2014
New Revision: 215194

URL: https://gcc.gnu.org/viewcvs?rev=215194&root=gcc&view=rev
Log:
Also turn off OPTION_MASK_ABI_X32 for -m16

	PR target/63228
	* config/i386/i386.c (ix86_option_override_internal): Also turn
	off OPTION_MASK_ABI_X32 for -m16.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
Comment 3 hjl@gcc.gnu.org 2014-09-11 22:28:48 UTC
Author: hjl
Date: Thu Sep 11 22:28:16 2014
New Revision: 215195

URL: https://gcc.gnu.org/viewcvs?rev=215195&root=gcc&view=rev
Log:
Also turn off OPTION_MASK_ABI_X32 for -m16

	Backport from mainline
	PR target/63228
	* config/i386/i386.c (ix86_option_override_internal): Also turn
	off OPTION_MASK_ABI_X32 for -m16.

Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/i386/i386.c
Comment 4 H.J. Lu 2014-09-11 22:29:18 UTC
Fixed.