x86: make code size vs CPU arch checking consistent
authorJan Beulich <jbeulich@suse.com>
Fri, 15 Sep 2023 07:56:02 +0000 (09:56 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 15 Sep 2023 07:56:02 +0000 (09:56 +0200)
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).

gas/config/tc-i386.c
gas/testsuite/gas/i386/287.s
gas/testsuite/gas/i386/8087.s
gas/testsuite/gas/i386/att-regs.s
gas/testsuite/gas/i386/intel-regs.s
gas/testsuite/gas/i386/inval-16.l
gas/testsuite/gas/i386/inval-16.s
gas/testsuite/gas/i386/nops-5.s

index 1208e30abe8889d7fa223569a2a37cc67b6fea69..72e5729ce1cc18f04d64ee24f4be53f21233f4b0 100644 (file)
@@ -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;
index 74ad160c27080be463fb11426bf152cc91edf330..b0deeb8381a220a409f1d7848b3feb55b7582565 100644 (file)
@@ -1,9 +1,9 @@
 # Check 287-only instructions.
 
        .text
+       .code16
        .arch i286
        .arch .287
-       .code16
 _8087:
        fnsetpm
        frstpm
index 9149eb23c70ea1b69b026b5bf07711b05a4beeb2..5f1e2f387b42cbee16ea5f7be1a05fe42bb70b6f 100644 (file)
@@ -1,9 +1,9 @@
 # Check 8087-only instructions.
 
        .text
+       .code16
        .arch i8086
        .arch .8087
-       .code16
 _8087:
        fdisi
        feni
index 1001824038171b1048a9ee91317b8487b1e682c6..18509d1e9f6c7f37c3b1eb3f5e56784acb726ab2 100644 (file)
@@ -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)
index 44e369bb0f04c3321d3c2d6e5bc7c0c2c999aaa4..1f88881a1959b538abfbf8e5d566c5cff6fa3582 100644 (file)
@@ -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
index bf5d4cde1900d27a15a0b8a0b9ecd99168c443d6..13443bddde2f70d2064e3696164993c219cbee49 100644 (file)
@@ -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
index d3966daa91332253f7ae6851e20ab429f2cc71c3..611115bcdbadc1812b06c8cb38a2e8b4d4e1a8e4 100644 (file)
@@ -1,5 +1,5 @@
        .text
-       .arch i186; .code16
+       .code16; .arch i186
        vmovapd %xmm0,%xmm1
        vaddsd  %xmm4, %xmm5, %xmm6{%k7}
        vfrczpd %xmm7,%xmm7
index 4536c981f47eec3f3631b86320914336ce735b28..a932a10d84f4792cf708f50a7b428c7810b5493f 100644 (file)
@@ -1,4 +1,5 @@
        .text
+       .code32
        .arch i386
 i386:
        movsbl %al,%esi