This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] RE: ill effect of <register>+<constant>
>>> "Dave Korn" <dave.korn@artimi.com> 21.09.07 20:12 >>>
>On 21 September 2007 18:31, Andreas Schwab wrote:
>
>> "Dave Korn" <dave.korn@artimi.com> writes:
>>
>>> I don't see how removing an unused and non-useful feature would really
>>> count as "crippling". I'm not suggesting it should be disabled for ppc,
>>> but for x86, really .... what could conceivably be the use?
>>
>> There are many more architectures besides ppc and x86. Almost all of
>> them have numbered registers.
>
> Are you deliberately missing the point on purpose for rhetorical purposes?
>I'm not suggesting it makes no sense for any architecture *except* x86. I
>hope that is clearer. It certainly does make sense for anything with a big
>set of idempotent numbered registers.
>
> But really, please: what's the use of being able to turn (for example) cx
>into edi by adding a number to it?
Here's a patch that disables such for x86 and ia64. Perhaps a few other
architecture may want to follow.
Built and tested on x86_64-unknown-linux-gnu and ia64-unknown-linux-gnu.
gas/
2007-09-25 Jan Beulich <jbeulich@novell.com>
* config/tc-i386.h (md_register_arithmetic): Define.
* config/tc-ia64.h (md_register_arithmetic): Likewise.
* expr.c (make_expr_symbol): Force O_register expressions into
reg_section.
(expr): Provide default for md_register_arithmetic. Don't resolve
adding/subtracting constants to/from registers if
md_register_arithmetic is zero.
--- 2007-09-25/gas/config/tc-i386.h 2007-09-25 16:27:43.000000000 +0200
+++ 2007-09-25/gas/config/tc-i386.h 2007-09-24 13:44:49.000000000 +0200
@@ -272,6 +272,8 @@ extern int tc_i386_fix_adjustable (struc
extern int i386_parse_name (char *, expressionS *, char *);
#define md_parse_name(s, e, m, c) i386_parse_name (s, e, c)
+#define md_register_arithmetic 0
+
extern const struct relax_type md_relax_table[];
#define TC_GENERIC_RELAX_TABLE md_relax_table
--- 2007-09-25/gas/config/tc-ia64.h 2007-08-22 11:01:53.000000000 +0200
+++ 2007-09-25/gas/config/tc-ia64.h 2007-09-24 11:23:34.000000000 +0200
@@ -130,6 +130,7 @@ extern void ia64_convert_frag (fragS *);
#endif /* TE_HPUX */
#define md_flush_pending_output() ia64_flush_pending_output ()
#define md_parse_name(s,e,m,c) ia64_parse_name (s, e, c)
+#define md_register_arithmetic 0
#define tc_canonicalize_symbol_name(s) ia64_canonicalize_symbol_name (s)
#define tc_canonicalize_section_name(s) ia64_canonicalize_symbol_name (s)
#define md_optimize_expr(l,o,r) ia64_optimize_expr (l, o, r)
--- 2007-09-25/gas/expr.c 2007-08-22 11:01:50.000000000 +0200
+++ 2007-09-25/gas/expr.c 2007-09-24 11:21:31.000000000 +0200
@@ -95,7 +95,9 @@ make_expr_symbol (expressionS *expressio
symbolP = symbol_create (FAKE_LABEL_NAME,
(expressionP->X_op == O_constant
? absolute_section
- : expr_section),
+ : expressionP->X_op == O_register
+ ? reg_section
+ : expr_section),
0, &zero_address_frag);
symbol_set_value_expression (symbolP, expressionP);
@@ -1722,7 +1724,11 @@ expr (int rankarg, /* Larger # is highe
}
else
#endif
- if (op_left == O_add && right.X_op == O_constant)
+#ifndef md_register_arithmetic
+# define md_register_arithmetic 1
+#endif
+ if (op_left == O_add && right.X_op == O_constant
+ && (md_register_arithmetic || resultP->X_op != O_register))
{
/* X + constant. */
resultP->X_add_number += right.X_add_number;
@@ -1745,12 +1751,14 @@ expr (int rankarg, /* Larger # is highe
resultP->X_op = O_constant;
resultP->X_add_symbol = 0;
}
- else if (op_left == O_subtract && right.X_op == O_constant)
+ else if (op_left == O_subtract && right.X_op == O_constant
+ && (md_register_arithmetic || resultP->X_op != O_register))
{
/* X - constant. */
resultP->X_add_number -= right.X_add_number;
}
- else if (op_left == O_add && resultP->X_op == O_constant)
+ else if (op_left == O_add && resultP->X_op == O_constant
+ && (md_register_arithmetic || right.X_op != O_register))
{
/* Constant + X. */
resultP->X_op = right.X_op;