From: Jan Beulich Date: Thu, 30 Nov 2017 10:46:26 +0000 (+0100) Subject: x86/Intel: issue diagnostics for redundant segment override prefixes X-Git-Tag: gdb-8.1-release~334 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd4e0347596acf79642625f4faad9e37c8fa0f0e;p=external%2Fbinutils.git x86/Intel: issue diagnostics for redundant segment override prefixes While we shouldn't outright reject such (as was wrongly done by commit 4d36230d59 ("x86: Update segment register check in Intel syntax"), as MASM accepts them even silently, issue (by default) a warning for such questionable constructs. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index 1b6401f..a46f8de 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,15 @@ +2017-11-29 Jan Beulich + + PR gas/21874 + * config/tc-i386-intel.c (i386_intel_simplify): Chain together + multiple segment override expressions. + (i386_intel_operand): Issue diagnostic for redundant segment + overrides. + * testsuite/gas/i386/intelok.e: New. + * testsuite/gas/i386/intelok.d: Reference intelok.e. + * testsuite/gas/i386/inval-seg.s: Add redundant override checks. + * testsuite/gas/i386/inval-seg.l: Adjust expectations. + 2017-11-29 Jim Wilson Palmer Dabbelt diff --git a/gas/config/tc-i386-intel.c b/gas/config/tc-i386-intel.c index 74aae24..99d215e 100644 --- a/gas/config/tc-i386-intel.c +++ b/gas/config/tc-i386-intel.c @@ -413,7 +413,19 @@ static int i386_intel_simplify (expressionS *e) intel_state.index)) return 0; if (!intel_state.in_offset) - intel_state.seg = e->X_add_symbol; + { + if (!intel_state.seg) + intel_state.seg = e->X_add_symbol; + else + { + expressionS exp; + + exp.X_op = O_full_ptr; + exp.X_add_symbol = e->X_add_symbol; + exp.X_op_symbol = intel_state.seg; + intel_state.seg = make_expr_symbol (&exp); + } + } i386_intel_fold (e, e->X_op_symbol); break; @@ -956,10 +968,12 @@ i386_intel_operand (char *operand_string, int got_a_float) if (intel_state.seg) { - for (;;) + for (ret = check_none; ; ret = operand_check) { expP = symbol_get_value_expression (intel_state.seg); - if (expP->X_op != O_full_ptr) + if (expP->X_op != O_full_ptr + || symbol_get_value_expression (expP->X_op_symbol)->X_op + != O_register) break; intel_state.seg = expP->X_add_symbol; } @@ -974,6 +988,15 @@ i386_intel_operand (char *operand_string, int got_a_float) as_bad (_("invalid use of register")); return 0; } + switch (ret) + { + case check_error: + as_bad (_("redundant segment overrides")); + return 0; + case check_warning: + as_warn (_("redundant segment overrides")); + break; + } switch (i386_regtab[expP->X_add_number].reg_num) { case 0: i.seg[i.mem_operands] = &es; break; diff --git a/gas/testsuite/gas/i386/intelok.d b/gas/testsuite/gas/i386/intelok.d index bad81e4..41e65b3 100644 --- a/gas/testsuite/gas/i386/intelok.d +++ b/gas/testsuite/gas/i386/intelok.d @@ -1,6 +1,7 @@ #as: -J --divide #objdump: -dwMintel #name: i386 intel-ok +#stderr: intelok.e .*: +file format .* diff --git a/gas/testsuite/gas/i386/intelok.e b/gas/testsuite/gas/i386/intelok.e new file mode 100644 index 0000000..585eaf4 --- /dev/null +++ b/gas/testsuite/gas/i386/intelok.e @@ -0,0 +1,2 @@ +.*: Assembler messages: +.*:153: Warning: redundant segment overrides diff --git a/gas/testsuite/gas/i386/inval-seg.l b/gas/testsuite/gas/i386/inval-seg.l index efe190e..c081b0e 100644 --- a/gas/testsuite/gas/i386/inval-seg.l +++ b/gas/testsuite/gas/i386/inval-seg.l @@ -1,10 +1,22 @@ .*: Assembler messages: .*:3: Error: .* .*:4: Error: .* +.*:7: Error: .* +.*:8: Error: .* +.*:9: Error: .* +.*:10: Error: .* +.*:11: Error: .* GAS LISTING .* - 1 [ ]* .text - 2 [ ]*# All the following should be illegal - 3 [ ]* movl %ds,\(%eax\) - 4 [ ]* movl \(%eax\),%ds +[ ]*[1-9][0-9]*[ ]*\.text +[ ]*[1-9][0-9]*[ ]*# All the following should be illegal +[ ]*[1-9][0-9]*[ ]*movl %ds,\(%eax\) +[ ]*[1-9][0-9]*[ ]*movl \(%eax\),%ds +[ ]*[1-9][0-9]*[ ]* +[ ]*[1-9][0-9]*[ ]*\.intel_syntax noprefix +[ ]*[1-9][0-9]*[ ]*mov eax, es:foo:\[eax\] +[ ]*[1-9][0-9]*[ ]*mov eax, es:fs:foo:\[eax\] +[ ]*[1-9][0-9]*[ ]*mov eax, fs:foo:bar:\[eax\] +[ ]*[1-9][0-9]*[ ]*mov eax, fs:foo:gs:\[eax\] +[ ]*[1-9][0-9]*[ ]*mov eax, bar:gs:\[eax\] diff --git a/gas/testsuite/gas/i386/inval-seg.s b/gas/testsuite/gas/i386/inval-seg.s index 4cc2221..bf09d4d 100644 --- a/gas/testsuite/gas/i386/inval-seg.s +++ b/gas/testsuite/gas/i386/inval-seg.s @@ -2,3 +2,10 @@ # All the following should be illegal movl %ds,(%eax) movl (%eax),%ds + + .intel_syntax noprefix + mov eax, es:foo:[eax] + mov eax, es:fs:foo:[eax] + mov eax, fs:foo:bar:[eax] + mov eax, fs:foo:gs:[eax] + mov eax, bar:gs:[eax]