From: Jan Beulich Date: Fri, 15 Sep 2023 07:56:02 +0000 (+0200) Subject: x86: make code size vs CPU arch checking consistent X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1d07cfb4406ee1dd336dd63cd5af7e8534892be7;p=binutils-gdb.git x86: make code size vs CPU arch checking consistent While update_code_flag() checks for LM / i386, set_cpu_arch() so far didn't, allowing e.g. 64-bit code to be emitted after ".arch generic32". Oddly enough a few of our testcases actually exhibit bad behavior (and hence need minor adjustments). --- diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 1208e30abe8..72e5729ce1c 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -2928,6 +2928,24 @@ set_cpu_arch (int dummy ATTRIBUTE_UNUSED) { check_cpu_arch_compatible (string, cpu_arch[j].enable); + if (flag_code == CODE_64BIT && !cpu_arch[j].enable.bitfield.cpulm ) + { + as_bad (_("64bit mode not supported on `%s'."), + cpu_arch[j].name); + (void) restore_line_pointer (e); + ignore_rest_of_line (); + return; + } + + if (flag_code == CODE_32BIT && !cpu_arch[j].enable.bitfield.cpui386) + { + as_bad (_("32bit mode not supported on `%s'."), + cpu_arch[j].name); + (void) restore_line_pointer (e); + ignore_rest_of_line (); + return; + } + cpu_arch_name = cpu_arch[j].name; free (cpu_sub_arch_name); cpu_sub_arch_name = NULL; diff --git a/gas/testsuite/gas/i386/287.s b/gas/testsuite/gas/i386/287.s index 74ad160c270..b0deeb8381a 100644 --- a/gas/testsuite/gas/i386/287.s +++ b/gas/testsuite/gas/i386/287.s @@ -1,9 +1,9 @@ # Check 287-only instructions. .text + .code16 .arch i286 .arch .287 - .code16 _8087: fnsetpm frstpm diff --git a/gas/testsuite/gas/i386/8087.s b/gas/testsuite/gas/i386/8087.s index 9149eb23c70..5f1e2f387b4 100644 --- a/gas/testsuite/gas/i386/8087.s +++ b/gas/testsuite/gas/i386/8087.s @@ -1,9 +1,9 @@ # Check 8087-only instructions. .text + .code16 .arch i8086 .arch .8087 - .code16 _8087: fdisi feni diff --git a/gas/testsuite/gas/i386/att-regs.s b/gas/testsuite/gas/i386/att-regs.s index 10018240381..18509d1e9f6 100644 --- a/gas/testsuite/gas/i386/att-regs.s +++ b/gas/testsuite/gas/i386/att-regs.s @@ -1,8 +1,8 @@ .text .att_syntax noprefix - .arch i286 .code16 + .arch i286 mov eax, ax ; add al, (bx,si) mov rax, ax ; add al, (bx,si) mov axl, ax ; add al, (bx,si) diff --git a/gas/testsuite/gas/i386/intel-regs.s b/gas/testsuite/gas/i386/intel-regs.s index 44e369bb0f0..1f88881a195 100644 --- a/gas/testsuite/gas/i386/intel-regs.s +++ b/gas/testsuite/gas/i386/intel-regs.s @@ -3,8 +3,8 @@ mov eax, tmm1 - .arch i286 .code16 + .arch i286 mov ax, eax ; add [bx+si], al mov ax, rax ; add [bx+si], al mov ax, axl ; add [bx+si], al diff --git a/gas/testsuite/gas/i386/inval-16.l b/gas/testsuite/gas/i386/inval-16.l index bf5d4cde190..13443bddde2 100644 --- a/gas/testsuite/gas/i386/inval-16.l +++ b/gas/testsuite/gas/i386/inval-16.l @@ -10,7 +10,7 @@ GAS LISTING .* [ ]*1[ ]+\.text -[ ]*2[ ]+\.arch i186; \.code16 +[ ]*2[ ]+\.code16; \.arch i186 [ ]*3[ ]+vmovapd %xmm0,%xmm1 [ ]*4[ ]+vaddsd %xmm4, %xmm5, %xmm6\{%k7\} [ ]*5[ ]+vfrczpd %xmm7,%xmm7 diff --git a/gas/testsuite/gas/i386/inval-16.s b/gas/testsuite/gas/i386/inval-16.s index d3966daa913..611115bcdba 100644 --- a/gas/testsuite/gas/i386/inval-16.s +++ b/gas/testsuite/gas/i386/inval-16.s @@ -1,5 +1,5 @@ .text - .arch i186; .code16 + .code16; .arch i186 vmovapd %xmm0,%xmm1 vaddsd %xmm4, %xmm5, %xmm6{%k7} vfrczpd %xmm7,%xmm7 diff --git a/gas/testsuite/gas/i386/nops-5.s b/gas/testsuite/gas/i386/nops-5.s index 4536c981f47..a932a10d84f 100644 --- a/gas/testsuite/gas/i386/nops-5.s +++ b/gas/testsuite/gas/i386/nops-5.s @@ -1,4 +1,5 @@ .text + .code32 .arch i386 i386: movsbl %al,%esi