gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gold / expression.cc
index 61a3eaf17e4e5525b210f65c8640d3d5f8407021..b0bd875add2144c2b7eaa9bffc64d8c77521c866 100644 (file)
@@ -1,6 +1,6 @@
 // expression.cc -- expressions in linker scripts for gold
 
-// Copyright (C) 2006-2014 Free Software Foundation, Inc.
+// Copyright (C) 2006-2020 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -74,6 +74,10 @@ struct Expression::Expression_eval_info
   elfcpp::STV* vis_pointer;
   // Pointer to where the rest of the symbol's st_other field should be stored.
   unsigned char* nonvis_pointer;
+  // Whether the value is valid.  In Symbol_assignment::set_if_absolute, we
+  // may be trying to evaluate the address of a section whose address is not
+  // yet finalized, and we need to fail the evaluation gracefully.
+  bool *is_valid_pointer;
 };
 
 // Evaluate an expression.
@@ -83,7 +87,7 @@ Expression::eval(const Symbol_table* symtab, const Layout* layout,
                 bool check_assertions)
 {
   return this->eval_maybe_dot(symtab, layout, check_assertions, false, 0,
-                             NULL, NULL, NULL, NULL, NULL, NULL, false);
+                             NULL, NULL, NULL, NULL, NULL, NULL, false, NULL);
 }
 
 // Evaluate an expression which may refer to the dot symbol.
@@ -99,7 +103,7 @@ Expression::eval_with_dot(const Symbol_table* symtab, const Layout* layout,
   return this->eval_maybe_dot(symtab, layout, check_assertions, true,
                              dot_value, dot_section, result_section_pointer,
                              result_alignment_pointer, NULL, NULL, NULL,
-                             is_section_dot_assignment);
+                             is_section_dot_assignment, NULL);
 }
 
 // Evaluate an expression which may or may not refer to the dot
@@ -114,7 +118,8 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
                           elfcpp::STT* type_pointer,
                           elfcpp::STV* vis_pointer,
                           unsigned char* nonvis_pointer,
-                          bool is_section_dot_assignment)
+                          bool is_section_dot_assignment,
+                          bool* is_valid_pointer)
 {
   Expression_eval_info eei;
   eei.symtab = symtab;
@@ -138,8 +143,18 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
 
   eei.result_alignment_pointer = result_alignment_pointer;
 
+  // Assume the value is valid until we try to evaluate an expression
+  // that can't be evaluated yet.
+  bool is_valid = true;
+  eei.is_valid_pointer = &is_valid;
+
   uint64_t val = this->value(&eei);
 
+  if (is_valid_pointer != NULL)
+    *is_valid_pointer = is_valid;
+  else
+    gold_assert(is_valid);
+
   // If this is an assignment to dot within a section, and the value
   // is absolute, treat it as a section-relative offset.
   if (is_section_dot_assignment && *result_section_pointer == NULL)
@@ -190,6 +205,14 @@ class Symbol_expression : public Expression
   uint64_t
   value(const Expression_eval_info*);
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    Symbol* sym = symtab->lookup(this->name_.c_str());
+    if (sym != NULL)
+      sym->set_in_real_elf();
+  }
+
   void
   print(FILE* f) const
   { fprintf(f, "%s", this->name_.c_str()); }
@@ -295,13 +318,18 @@ class Unary_expression : public Expression
                                      NULL,
                                      NULL,
                                      NULL,
-                                     false);
+                                     false,
+                                     eei->is_valid_pointer);
   }
 
   void
   arg_print(FILE* f) const
   { this->arg_->print(f); }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  { return this->arg_->set_expr_sym_in_real_elf(symtab); }
+
  private:
   Expression* arg_;
 };
@@ -378,7 +406,8 @@ class Binary_expression : public Expression
                                       NULL,
                                       NULL,
                                       NULL,
-                                      false);
+                                      false,
+                                      eei->is_valid_pointer);
   }
 
   uint64_t
@@ -396,7 +425,8 @@ class Binary_expression : public Expression
                                        NULL,
                                        NULL,
                                        NULL,
-                                       false);
+                                       false,
+                                       eei->is_valid_pointer);
   }
 
   void
@@ -419,6 +449,13 @@ class Binary_expression : public Expression
     fprintf(f, ")");
   }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    this->left_->set_expr_sym_in_real_elf(symtab);
+    this->right_->set_expr_sym_in_real_elf(symtab);
+  }
+
  private:
   Expression* left_;
   Expression* right_;
@@ -550,7 +587,8 @@ class Trinary_expression : public Expression
                                       NULL,
                                       NULL,
                                       NULL,
-                                      false);
+                                      false,
+                                      eei->is_valid_pointer);
   }
 
   uint64_t
@@ -558,7 +596,7 @@ class Trinary_expression : public Expression
             Output_section** section_pointer,
             uint64_t* alignment_pointer) const
   {
-    return this->arg1_->eval_maybe_dot(eei->symtab, eei->layout,
+    return this->arg2_->eval_maybe_dot(eei->symtab, eei->layout,
                                       eei->check_assertions,
                                       eei->is_dot_available,
                                       eei->dot_value,
@@ -568,7 +606,8 @@ class Trinary_expression : public Expression
                                       NULL,
                                       NULL,
                                       NULL,
-                                      false);
+                                      false,
+                                      eei->is_valid_pointer);
   }
 
   uint64_t
@@ -576,7 +615,7 @@ class Trinary_expression : public Expression
             Output_section** section_pointer,
             uint64_t* alignment_pointer) const
   {
-    return this->arg1_->eval_maybe_dot(eei->symtab, eei->layout,
+    return this->arg3_->eval_maybe_dot(eei->symtab, eei->layout,
                                       eei->check_assertions,
                                       eei->is_dot_available,
                                       eei->dot_value,
@@ -586,7 +625,8 @@ class Trinary_expression : public Expression
                                       NULL,
                                       NULL,
                                       NULL,
-                                      false);
+                                      false,
+                                      eei->is_valid_pointer);
   }
 
   void
@@ -601,6 +641,14 @@ class Trinary_expression : public Expression
   arg3_print(FILE* f) const
   { this->arg3_->print(f); }
 
+  void
+  set_expr_sym_in_real_elf(Symbol_table* symtab) const
+  {
+    this->arg1_->set_expr_sym_in_real_elf(symtab);
+    this->arg2_->set_expr_sym_in_real_elf(symtab);
+    this->arg3_->set_expr_sym_in_real_elf(symtab);
+  }
+
  private:
   Expression* arg1_;
   Expression* arg2_;
@@ -945,7 +993,10 @@ class Addr_expression : public Section_expression
   {
     if (eei->result_section_pointer != NULL)
       *eei->result_section_pointer = os;
-    return os->address();
+    if (os->is_address_valid())
+      return os->address();
+    *eei->is_valid_pointer = false;
+    return 0;
   }
 
   uint64_t
This page took 0.025751 seconds and 4 git commands to generate.