[binutils-gdb] Early expression evaluation

Alan Modra amodra@sourceware.org
Wed Jul 20 02:45:00 GMT 2016


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b751e639fcc69ba6e1d8ccc0fef2be1522802a33

commit b751e639fcc69ba6e1d8ccc0fef2be1522802a33
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jul 20 09:44:46 2016 +0930

    Early expression evaluation
    
    Folding a constant expression early can lead to loss of tokens, eg.
    ABSOLUTE, that are significant in ld's horrible context sensitive
    expression evaluation.  Also, MAXPAGESIZE and other "constants" may
    not have taken values specified on the command line, leading to the
    wrong value being cached.
    
    	* ldexp.c (exp_unop, exp_binop, exp_trinop, exp_nameop): Don't
    	fold expression.
    	* testsuite/ld-elf/maxpage3b.d: Expect correct maxpagesize.

Diff:
---
 ld/ChangeLog                    |  6 +++
 ld/ldexp.c                      | 83 ++++++++++++++---------------------------
 ld/testsuite/ld-elf/maxpage3b.d |  3 +-
 3 files changed, 37 insertions(+), 55 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9dc24b4..b744275 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2016-07-20  Alan Modra  <amodra@gmail.com>
+
+	* ldexp.c (exp_unop, exp_binop, exp_trinop, exp_nameop): Don't
+	fold expression.
+	* testsuite/ld-elf/maxpage3b.d: Expect correct maxpagesize.
+
 2016-07-19  Roland McGrath  <roland@hack.frob.com>
 
 	* emulparams/aarch64elf.sh (GENERATE_PIE_SCRIPT): Set to yes.
diff --git a/ld/ldexp.c b/ld/ldexp.c
index 68c4bc5..a560643 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -1255,80 +1255,55 @@ exp_fold_tree_no_dot (etree_type *tree)
 etree_type *
 exp_binop (int code, etree_type *lhs, etree_type *rhs)
 {
-  etree_type value, *new_e;
-
-  value.type.node_code = code;
-  value.type.filename = lhs->type.filename;
-  value.type.lineno = lhs->type.lineno;
-  value.binary.lhs = lhs;
-  value.binary.rhs = rhs;
-  value.type.node_class = etree_binary;
-  exp_fold_tree_no_dot (&value);
-  if (expld.result.valid_p)
-    return exp_intop (expld.result.value);
-
-  new_e = (etree_type *) stat_alloc (sizeof (new_e->binary));
-  memcpy (new_e, &value, sizeof (new_e->binary));
+  etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->binary));
+
+  new_e->type.node_code = code;
+  new_e->type.filename = lhs->type.filename;
+  new_e->type.lineno = lhs->type.lineno;
+  new_e->binary.lhs = lhs;
+  new_e->binary.rhs = rhs;
+  new_e->type.node_class = etree_binary;
   return new_e;
 }
 
 etree_type *
 exp_trinop (int code, etree_type *cond, etree_type *lhs, etree_type *rhs)
 {
-  etree_type value, *new_e;
-
-  value.type.node_code = code;
-  value.type.filename = cond->type.filename;
-  value.type.lineno = cond->type.lineno;
-  value.trinary.lhs = lhs;
-  value.trinary.cond = cond;
-  value.trinary.rhs = rhs;
-  value.type.node_class = etree_trinary;
-  exp_fold_tree_no_dot (&value);
-  if (expld.result.valid_p)
-    return exp_intop (expld.result.value);
-
-  new_e = (etree_type *) stat_alloc (sizeof (new_e->trinary));
-  memcpy (new_e, &value, sizeof (new_e->trinary));
+  etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->trinary));
+
+  new_e->type.node_code = code;
+  new_e->type.filename = cond->type.filename;
+  new_e->type.lineno = cond->type.lineno;
+  new_e->trinary.lhs = lhs;
+  new_e->trinary.cond = cond;
+  new_e->trinary.rhs = rhs;
+  new_e->type.node_class = etree_trinary;
   return new_e;
 }
 
 etree_type *
 exp_unop (int code, etree_type *child)
 {
-  etree_type value, *new_e;
-
-  value.unary.type.node_code = code;
-  value.unary.type.filename = child->type.filename;
-  value.unary.type.lineno = child->type.lineno;
-  value.unary.child = child;
-  value.unary.type.node_class = etree_unary;
-  exp_fold_tree_no_dot (&value);
-  if (expld.result.valid_p)
-    return exp_intop (expld.result.value);
+  etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->unary));
 
-  new_e = (etree_type *) stat_alloc (sizeof (new_e->unary));
-  memcpy (new_e, &value, sizeof (new_e->unary));
+  new_e->unary.type.node_code = code;
+  new_e->unary.type.filename = child->type.filename;
+  new_e->unary.type.lineno = child->type.lineno;
+  new_e->unary.child = child;
+  new_e->unary.type.node_class = etree_unary;
   return new_e;
 }
 
 etree_type *
 exp_nameop (int code, const char *name)
 {
-  etree_type value, *new_e;
-
-  value.name.type.node_code = code;
-  value.name.type.filename = ldlex_filename ();
-  value.name.type.lineno = lineno;
-  value.name.name = name;
-  value.name.type.node_class = etree_name;
-
-  exp_fold_tree_no_dot (&value);
-  if (expld.result.valid_p)
-    return exp_intop (expld.result.value);
+  etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->name));
 
-  new_e = (etree_type *) stat_alloc (sizeof (new_e->name));
-  memcpy (new_e, &value, sizeof (new_e->name));
+  new_e->name.type.node_code = code;
+  new_e->name.type.filename = ldlex_filename ();
+  new_e->name.type.lineno = lineno;
+  new_e->name.name = name;
+  new_e->name.type.node_class = etree_name;
   return new_e;
 
 }
diff --git a/ld/testsuite/ld-elf/maxpage3b.d b/ld/testsuite/ld-elf/maxpage3b.d
index 4bee0ec..62b50c9 100644
--- a/ld/testsuite/ld-elf/maxpage3b.d
+++ b/ld/testsuite/ld-elf/maxpage3b.d
@@ -4,7 +4,8 @@
 #target: x86_64-*-linux*
 
 #...
-  \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t]+0*200000[ \t]+[ \t0-9a-f]+WA?.*
+  \[[ 0-9]+\] \.data[ \t]+PROGBITS[ \t]+0*10000000[ \t]+[ \t0-9a-f]+WA?.*
 #...
   LOAD+.*0x10000000
+  LOAD+.*0x10000000
 #pass



More information about the Binutils-cvs mailing list