Skip to contentSkip to conversation

target-i386: Fix compilation with --enable-debug

PATCH Blue Swirl 2 participants 3 messages Jul 3, 2012 – Jul 5, 2012 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOZVR5Yt4eDU8cZ+UoCTA3Y9_M4k++z1z2MVsTc1uRROGyZGHA@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

Blue Swirl

author
#3 lore raw
Quoted 28 lines · Stefan Weil

Am 30.06.2012 14:16, schrieb Dunrong Huang:

Quoted 8 lines

2012/6/30 Stefan Weil <[email protected]>:

Quoted 4 lines

commit c4baa0503d9623f1ce891f525ccd140c598bc29a improved SSE table type safety which now raises compiler errors when latest QEMU was configured with --enable-debug.

The error occurs when building with --enable-werror, which is default option, not --enable-debug.

The default configuration (configure called without any options) compiles perfectly (no warnings, no errors) on x86_64 or i386 hosts.

I only see warnings or errors when QEMU was configured with --enable-debug-tcg. Option --enable-debug includes --enable-debug-tcg, so it triggers the same warnings or errors.

Stefan H., I suggest running some of the buildbots (for example default_x86_64_debian_6_0 and default_i386_debian_6_0) with --enable-debug. That option provides better code checks for TCG related code, and it also results in much shorter build times because compiler optimizations are disabled. gcc won't detect some kinds of errors which it only detects when it optimizes the code - that's why using --enable-debug for all buildbots would not be reasonable.

Quoted 3 lines

Blue, are you planning to apply my patch as it is, or would you prefer an implementation using if / else blocks instead of arrays of function pointers?

I looked briefly at how the tables could be converted switch() cases, but it looks like there would be a need for some refactoring if we don't want to just duplicate the common code.

Your patch could still be used as the first step regardless.

Quoted 5 lines

Regards,

Stefan W.

Reviewed-by
#4 lore raw
In reply to a message not in the archive
Quoted 41 lines · Stefan Weil

commit c4baa0503d9623f1ce891f525ccd140c598bc29a improved SSE table type safety which now raises compiler errors when latest QEMU was configured with --enable-debug.

Fix this by splitting the SSE tables even further to separate helper functions with different signatures.

Instead of crashing by calling address 0, the code now jumps to label illegal_op.

---
 target-i386/translate.c |   59 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 25 deletions(-)
target-i386/translate.c +10 -5
index a902f4a..a00a6a1 100644
@@ -2947,25 +2947,34 @@ static const SSEFunc_0_pp sse_op_table2[3 * 8][2] = {
     [16 + 7] = { NULL, gen_helper_pslldq_xmm },
 };
 
-static const SSEFunc_0_pi sse_op_table3a[4] = {
+static const SSEFunc_0_pi sse_op_table3ai[] = {
     gen_helper_cvtsi2ss,
-    gen_helper_cvtsi2sd,
-    X86_64_ONLY(gen_helper_cvtsq2ss),
-    X86_64_ONLY(gen_helper_cvtsq2sd),
+    gen_helper_cvtsi2sd
 };
 
-static const SSEFunc_i_p sse_op_table3b[4 * 2] = {
+#ifdef TARGET_X86_64
+static const SSEFunc_0_pl sse_op_table3aq[] = {
+    gen_helper_cvtsq2ss,
+    gen_helper_cvtsq2sd
+};
+#endif
+
+static const SSEFunc_i_p sse_op_table3bi[] = {

target-i386/translate.c static const SSEFunc_0_pp sse_op_table2[3 * 8][2] = { · line 2966

Quoted 10 lines
target-i386/translate.c +1 -6
     gen_helper_cvttss2si,
     gen_helper_cvttsd2si,
-    X86_64_ONLY(gen_helper_cvttss2sq),
-    X86_64_ONLY(gen_helper_cvttsd2sq),
-
     gen_helper_cvtss2si,
-    gen_helper_cvtsd2si,
-    X86_64_ONLY(gen_helper_cvtss2sq),
-    X86_64_ONLY(gen_helper_cvtsd2sq),
+    gen_helper_cvtsd2si

As Andreas says, leaving in the trailing comma makes for nicer patches.

target-i386/translate.c static const SSEFunc_0_pp sse_op_table2[3 * 8][2] = { · line 2976

Quoted 10 lines
target-i386/translate.c +8 -0
 };
 
+#ifdef TARGET_X86_64
+static const SSEFunc_l_p sse_op_table3bq[] = {
+    gen_helper_cvttss2sq,
+    gen_helper_cvttsd2sq,
+    gen_helper_cvtss2sq,
+    gen_helper_cvtsd2sq
+};
+#endif

This patch removes all the uses of X86_64_ONLY macro so we could remove its definition too.

Quoted 16 lines
target-i386/translate.c +1 -4
+
 static const SSEFunc_0_pp sse_op_table4[8][4] = {
     SSE_FOP(cmpeq),
     SSE_FOP(cmplt),
@@ -3097,10 +3106,6 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
 {
     int b1, op1_offset, op2_offset, is_xmm, val, ot;
     int modrm, mod, rm, reg, reg_addr, offset_addr;
-    SSEFunc_i_p sse_fn_i_p;
-    SSEFunc_l_p sse_fn_l_p;
-    SSEFunc_0_pi sse_fn_pi;
-    SSEFunc_0_pl sse_fn_pl;
     SSEFunc_0_pp sse_fn_pp;
     SSEFunc_0_ppi sse_fn_ppi;
     SSEFunc_0_ppt sse_fn_ppt;

target-i386/translate.c static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r) · line 3571

Quoted 6 lines
target-i386/translate.c +1 -2
@@ -3563,14 +3568,16 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
             op1_offset = offsetof(CPUX86State,xmm_regs[reg]);
             tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset);
             if (ot == OT_LONG) {
-                sse_fn_pi = sse_op_table3a[(s->dflag == 2) * 2 +
-                                           ((b >> 8) - 2)];
+                SSEFunc_0_pi sse_fn_pi = sse_op_table3ai[(b >> 8) - 2];

We could optionally do a later cleanup patch moving from "(b >> 8) - 2" to "(b >> 8) & 1" which I think is more obviously not overrunning the array.

Quoted 15 lines
target-i386/translate.c +5 -2
                 tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
                 sse_fn_pi(cpu_ptr0, cpu_tmp2_i32);
             } else {
-                sse_fn_pl = sse_op_table3a[(s->dflag == 2) * 2 +
-                                           ((b >> 8) - 2)];
+#ifdef TARGET_X86_64
+                SSEFunc_0_pl sse_fn_pl = sse_op_table3aq[(b >> 8) - 2];
                 sse_fn_pl(cpu_ptr0, cpu_T[0]);
+#else
+                goto illegal_op;
+#endif
             }
             break;
         case 0x02c: /* cvttps2pi */

target-i386/translate.c static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r) · line 3635

Quoted 8 lines
target-i386/translate.c +2 -3
@@ -3624,16 +3631,18 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
             }
             tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset);
             if (ot == OT_LONG) {
-                sse_fn_i_p = sse_op_table3b[(s->dflag == 2) * 2 +
-                                            ((b >> 8) - 2) +
-                                            (b & 1) * 4];
+                SSEFunc_i_p sse_fn_i_p =
+                    sse_op_table3bi[(b >> 8) - 2 + (b & 1) * 2];

((b >> 7) & 2) | (b & 1) plus rearranging the table to match would IMHO be cleaner in the long run.

Quoted 17 lines
target-i386/translate.c +6 -4
                 sse_fn_i_p(cpu_tmp2_i32, cpu_ptr0);
                 tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
             } else {
-                sse_fn_l_p = sse_op_table3b[(s->dflag == 2) * 2 +
-                                            ((b >> 8) - 2) +
-                                            (b & 1) * 4];
+#ifdef TARGET_X86_64
+                SSEFunc_l_p sse_fn_l_p =
+                    sse_op_table3bq[(b >> 8) - 2 + (b & 1) * 2];
                 sse_fn_l_p(cpu_T[0], cpu_ptr0);
+#else
+                goto illegal_op;
+#endif
             }
             gen_op_mov_reg_T0(ot, reg);
             break;
--
Quoted 1 line

1.7.10

However that is all nitpicking. I think we should apply this as is since it fixes a build breakage; we can clean up later if we want.

-- PMM

author Applied
#5 lore raw
In reply to a message not in the archive

Thanks, applied.

Quoted 125 lines · Stefan Weil

commit c4baa0503d9623f1ce891f525ccd140c598bc29a improved SSE table type safety which now raises compiler errors when latest QEMU was configured with --enable-debug.

Fix this by splitting the SSE tables even further to separate helper functions with different signatures.

Instead of crashing by calling address 0, the code now jumps to label illegal_op.

---
 target-i386/translate.c |   59 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 25 deletions(-)
target-i386/translate.c +34 -26
index a902f4a..a00a6a1 100644
@@ -2947,25 +2947,34 @@ static const SSEFunc_0_pp sse_op_table2[3 * 8][2] = {
     [16 + 7] = { NULL, gen_helper_pslldq_xmm },
 };
 
-static const SSEFunc_0_pi sse_op_table3a[4] = {
+static const SSEFunc_0_pi sse_op_table3ai[] = {
     gen_helper_cvtsi2ss,
-    gen_helper_cvtsi2sd,
-    X86_64_ONLY(gen_helper_cvtsq2ss),
-    X86_64_ONLY(gen_helper_cvtsq2sd),
+    gen_helper_cvtsi2sd
 };
 
-static const SSEFunc_i_p sse_op_table3b[4 * 2] = {
+#ifdef TARGET_X86_64
+static const SSEFunc_0_pl sse_op_table3aq[] = {
+    gen_helper_cvtsq2ss,
+    gen_helper_cvtsq2sd
+};
+#endif
+
+static const SSEFunc_i_p sse_op_table3bi[] = {
     gen_helper_cvttss2si,
     gen_helper_cvttsd2si,
-    X86_64_ONLY(gen_helper_cvttss2sq),
-    X86_64_ONLY(gen_helper_cvttsd2sq),
-
     gen_helper_cvtss2si,
-    gen_helper_cvtsd2si,
-    X86_64_ONLY(gen_helper_cvtss2sq),
-    X86_64_ONLY(gen_helper_cvtsd2sq),
+    gen_helper_cvtsd2si
 };
 
+#ifdef TARGET_X86_64
+static const SSEFunc_l_p sse_op_table3bq[] = {
+    gen_helper_cvttss2sq,
+    gen_helper_cvttsd2sq,
+    gen_helper_cvtss2sq,
+    gen_helper_cvtsd2sq
+};
+#endif
+
 static const SSEFunc_0_pp sse_op_table4[8][4] = {
     SSE_FOP(cmpeq),
     SSE_FOP(cmplt),
@@ -3097,10 +3106,6 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
 {
     int b1, op1_offset, op2_offset, is_xmm, val, ot;
     int modrm, mod, rm, reg, reg_addr, offset_addr;
-    SSEFunc_i_p sse_fn_i_p;
-    SSEFunc_l_p sse_fn_l_p;
-    SSEFunc_0_pi sse_fn_pi;
-    SSEFunc_0_pl sse_fn_pl;
     SSEFunc_0_pp sse_fn_pp;
     SSEFunc_0_ppi sse_fn_ppi;
     SSEFunc_0_ppt sse_fn_ppt;
@@ -3563,14 +3568,16 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
             op1_offset = offsetof(CPUX86State,xmm_regs[reg]);
             tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset);
             if (ot == OT_LONG) {
-                sse_fn_pi = sse_op_table3a[(s->dflag == 2) * 2 +
-                                           ((b >> 8) - 2)];
+                SSEFunc_0_pi sse_fn_pi = sse_op_table3ai[(b >> 8) - 2];
                 tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
                 sse_fn_pi(cpu_ptr0, cpu_tmp2_i32);
             } else {
-                sse_fn_pl = sse_op_table3a[(s->dflag == 2) * 2 +
-                                           ((b >> 8) - 2)];
+#ifdef TARGET_X86_64
+                SSEFunc_0_pl sse_fn_pl = sse_op_table3aq[(b >> 8) - 2];
                 sse_fn_pl(cpu_ptr0, cpu_T[0]);
+#else
+                goto illegal_op;
+#endif
             }
             break;
         case 0x02c: /* cvttps2pi */
@@ -3624,16 +3631,18 @@ static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r)
             }
             tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset);
             if (ot == OT_LONG) {
-                sse_fn_i_p = sse_op_table3b[(s->dflag == 2) * 2 +
-                                            ((b >> 8) - 2) +
-                                            (b & 1) * 4];
+                SSEFunc_i_p sse_fn_i_p =
+                    sse_op_table3bi[(b >> 8) - 2 + (b & 1) * 2];
                 sse_fn_i_p(cpu_tmp2_i32, cpu_ptr0);
                 tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
             } else {
-                sse_fn_l_p = sse_op_table3b[(s->dflag == 2) * 2 +
-                                            ((b >> 8) - 2) +
-                                            (b & 1) * 4];
+#ifdef TARGET_X86_64
+                SSEFunc_l_p sse_fn_l_p =
+                    sse_op_table3bq[(b >> 8) - 2 + (b & 1) * 2];
                 sse_fn_l_p(cpu_T[0], cpu_ptr0);
+#else
+                goto illegal_op;
+#endif
             }
             gen_op_mov_reg_T0(ot, reg);
             break;
--

1.7.10