diff options
author | Jan Beulich <jbeulich@suse.com> | 2021-06-15 07:59:44 +0200 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2021-06-15 07:59:44 +0200 |
commit | a50187b2c6c28be79a32332e06a572cf08683de3 (patch) | |
tree | 0e7b6cce1e8a7723756955f6d62de2df3f0950c5 /gas/config | |
parent | 86f041462ec31a02efbcecdce8ee52ed2f340a68 (diff) | |
download | gdb-a50187b2c6c28be79a32332e06a572cf08683de3.zip gdb-a50187b2c6c28be79a32332e06a572cf08683de3.tar.gz gdb-a50187b2c6c28be79a32332e06a572cf08683de3.tar.bz2 |
x86: harmonize disp with imm handling
Certain disp values may trigger "... shortened to ..." warnings when
equivalent imm ones don't. In some of the cases there are also
differences (for non-64-bit code) between BFD64 and !BFD64 builds. The
resulting encodings (i.e. use [or not] of the shorter disp8 / imm8
forms) are also different in some cases. Make this handling consistent.
Note that using equivalent 16-bit mode displacements / immediates
continues to expose entirely different behavior (see the disp-imm-16
testcase added by an earlier patch). This may want to be the subject of
further changes, but it'll then quickly become obvious that e.g. keying
use of extend_to_32bit_address() to non-64-bit mode isn't appropriate
either: Once we allow wrapping operands, we would better do so
consistently, in which case all of this would need to become dependent
upon address or operand size instead of mode.
Diffstat (limited to 'gas/config')
-rw-r--r-- | gas/config/tc-i386.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index da4998c..e6276dc 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -5905,26 +5905,24 @@ optimize_disp (void) } #ifdef BFD64 - if (flag_code == CODE_64BIT) + /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */ + if ((i.types[op].bitfield.disp32 + || (flag_code == CODE_64BIT + && want_disp32 (current_templates->start))) + && fits_in_unsigned_long (op_disp)) { - /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */ - if ((i.types[op].bitfield.disp32 - || want_disp32 (current_templates->start)) - && fits_in_unsigned_long (op_disp)) - { - /* If this operand is at most 32 bits, convert - to a signed 32 bit number and don't use 64bit - displacement. */ - op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); - i.types[op].bitfield.disp64 = 0; - i.types[op].bitfield.disp32 = 1; - } + /* If this operand is at most 32 bits, convert + to a signed 32 bit number and don't use 64bit + displacement. */ + op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); + i.types[op].bitfield.disp64 = 0; + i.types[op].bitfield.disp32 = 1; + } - if (fits_in_signed_long (op_disp)) - { - i.types[op].bitfield.disp64 = 0; - i.types[op].bitfield.disp32s = 1; - } + if (flag_code == CODE_64BIT && fits_in_signed_long (op_disp)) + { + i.types[op].bitfield.disp64 = 0; + i.types[op].bitfield.disp32s = 1; } #endif if ((i.types[op].bitfield.disp32 @@ -11019,9 +11017,18 @@ i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp, ret = 0; } + else if (exp->X_op == O_constant) + { + /* Sizing gets taken care of by optimize_disp(). + + If not 64bit, sign/zero extend val, to account for wraparound + when !BFD64. */ + if (flag_code != CODE_64BIT) + exp->X_add_number = extend_to_32bit_address (exp->X_add_number); + } + #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) - else if (exp->X_op != O_constant - && OUTPUT_FLAVOR == bfd_target_aout_flavour + else if (OUTPUT_FLAVOR == bfd_target_aout_flavour && exp_seg != absolute_section && exp_seg != text_section && exp_seg != data_section @@ -11034,9 +11041,7 @@ i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp, } #endif - if (current_templates->start->opcode_modifier.jump == JUMP_BYTE - /* Constants get taken care of by optimize_disp(). */ - && exp->X_op != O_constant) + else if (current_templates->start->opcode_modifier.jump == JUMP_BYTE) i.types[this_operand].bitfield.disp8 = 1; /* Check if this is a displacement only operand. */ |