Support AARCH64_TLSLD_ADD_DTPREL_* relocations.
[deliverable/binutils-gdb.git] / gold / expression.cc
index 5441f7e2614606c0f8049a400b7aae2173b4f489..a64fa42302f65d76776e50c59ca49f13425e7c21 100644 (file)
@@ -1,6 +1,6 @@
 // expression.cc -- expressions in linker scripts for gold
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright (C) 2006-2015 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -68,6 +68,12 @@ struct Expression::Expression_eval_info
   Output_section** result_section_pointer;
   // Pointer to where the alignment of the result should be stored.
   uint64_t* result_alignment_pointer;
+  // Pointer to where the type of the symbol on the RHS should be stored.
+  elfcpp::STT* type_pointer;
+  // Pointer to where the visibility of the symbol on the RHS should be stored.
+  elfcpp::STV* vis_pointer;
+  // Pointer to where the rest of the symbol's st_other field should be stored.
+  unsigned char* nonvis_pointer;
 };
 
 // Evaluate an expression.
@@ -76,8 +82,8 @@ uint64_t
 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);
+  return this->eval_maybe_dot(symtab, layout, check_assertions, false, 0,
+                             NULL, NULL, NULL, NULL, NULL, NULL, false);
 }
 
 // Evaluate an expression which may refer to the dot symbol.
@@ -87,11 +93,13 @@ Expression::eval_with_dot(const Symbol_table* symtab, const Layout* layout,
                          bool check_assertions, uint64_t dot_value,
                          Output_section* dot_section,
                          Output_section** result_section_pointer,
-                         uint64_t* result_alignment_pointer)
+                         uint64_t* result_alignment_pointer,
+                         bool is_section_dot_assignment)
 {
   return this->eval_maybe_dot(symtab, layout, check_assertions, true,
                              dot_value, dot_section, result_section_pointer,
-                             result_alignment_pointer);
+                             result_alignment_pointer, NULL, NULL, NULL,
+                             is_section_dot_assignment);
 }
 
 // Evaluate an expression which may or may not refer to the dot
@@ -102,7 +110,11 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
                           bool check_assertions, bool is_dot_available,
                           uint64_t dot_value, Output_section* dot_section,
                           Output_section** result_section_pointer,
-                          uint64_t* result_alignment_pointer)
+                          uint64_t* result_alignment_pointer,
+                          elfcpp::STT* type_pointer,
+                          elfcpp::STV* vis_pointer,
+                          unsigned char* nonvis_pointer,
+                          bool is_section_dot_assignment)
 {
   Expression_eval_info eei;
   eei.symtab = symtab;
@@ -113,14 +125,30 @@ Expression::eval_maybe_dot(const Symbol_table* symtab, const Layout* layout,
   eei.dot_section = dot_section;
 
   // We assume the value is absolute, and only set this to a section
-  // if we find a section relative reference.
+  // if we find a section-relative reference.
   if (result_section_pointer != NULL)
     *result_section_pointer = NULL;
   eei.result_section_pointer = result_section_pointer;
 
+  // For symbol=symbol assignments, we need to track the type, visibility,
+  // and remaining st_other bits.
+  eei.type_pointer = type_pointer;
+  eei.vis_pointer = vis_pointer;
+  eei.nonvis_pointer = nonvis_pointer;
+
   eei.result_alignment_pointer = result_alignment_pointer;
 
-  return this->value(&eei);
+  uint64_t val = this->value(&eei);
+
+  // 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)
+    {
+      gold_assert(dot_section != NULL);
+      val += dot_section->address();
+      *result_section_pointer = dot_section;
+    }
+  return val;
 }
 
 // A number.
@@ -183,6 +211,12 @@ Symbol_expression::value(const Expression_eval_info* eei)
 
   if (eei->result_section_pointer != NULL)
     *eei->result_section_pointer = sym->output_section();
+  if (eei->type_pointer != NULL)
+    *eei->type_pointer = sym->type();
+  if (eei->vis_pointer != NULL)
+    *eei->vis_pointer = sym->visibility();
+  if (eei->nonvis_pointer != NULL)
+    *eei->nonvis_pointer = sym->nonvis();
 
   if (parameters->target().get_size() == 32)
     return eei->symtab->get_sized_symbol<32>(sym)->value();
@@ -257,7 +291,11 @@ class Unary_expression : public Expression
                                      eei->dot_value,
                                      eei->dot_section,
                                      arg_section_pointer,
-                                     eei->result_alignment_pointer);
+                                     eei->result_alignment_pointer,
+                                     NULL,
+                                     NULL,
+                                     NULL,
+                                     false);
   }
 
   void
@@ -336,7 +374,11 @@ class Binary_expression : public Expression
                                       eei->dot_value,
                                       eei->dot_section,
                                       section_pointer,
-                                      alignment_pointer);
+                                      alignment_pointer,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      false);
   }
 
   uint64_t
@@ -350,7 +392,11 @@ class Binary_expression : public Expression
                                        eei->dot_value,
                                        eei->dot_section,
                                        section_pointer,
-                                       alignment_pointer);
+                                       alignment_pointer,
+                                       NULL,
+                                       NULL,
+                                       NULL,
+                                       false);
   }
 
   void
@@ -399,18 +445,19 @@ class Binary_expression : public Expression
     value(const Expression_eval_info* eei)                             \
     {                                                                  \
       Output_section* left_section;                                    \
-      uint64_t left_alignment;                                         \
+      uint64_t left_alignment = 0;                                     \
       uint64_t left = this->left_value(eei, &left_section,             \
                                       &left_alignment);                \
       Output_section* right_section;                                   \
-      uint64_t right_alignment;                                                \
+      uint64_t right_alignment = 0;                                    \
       uint64_t right = this->right_value(eei, &right_section,          \
                                         &right_alignment);             \
       if (KEEP_RIGHT && left_section == NULL && right_section != NULL) \
        {                                                               \
          if (eei->result_section_pointer != NULL)                      \
            *eei->result_section_pointer = right_section;               \
-         if (eei->result_alignment_pointer != NULL)                    \
+         if (eei->result_alignment_pointer != NULL                     \
+             && right_alignment > *eei->result_alignment_pointer)      \
            *eei->result_alignment_pointer = right_alignment;           \
        }                                                               \
       else if (KEEP_LEFT                                               \
@@ -419,8 +466,9 @@ class Binary_expression : public Expression
        {                                                               \
          if (eei->result_section_pointer != NULL)                      \
            *eei->result_section_pointer = left_section;                \
-         if (eei->result_alignment_pointer != NULL)                    \
-           *eei->result_alignment_pointer = right_alignment;           \
+         if (eei->result_alignment_pointer != NULL                     \
+             && left_alignment > *eei->result_alignment_pointer)       \
+           *eei->result_alignment_pointer = left_alignment;            \
        }                                                               \
       else if ((WARN || left_section != right_section)                 \
               && (left_section != NULL || right_section != NULL)       \
@@ -498,7 +546,11 @@ class Trinary_expression : public Expression
                                       eei->dot_value,
                                       eei->dot_section,
                                       section_pointer,
-                                      NULL);
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      false);
   }
 
   uint64_t
@@ -512,7 +564,11 @@ class Trinary_expression : public Expression
                                       eei->dot_value,
                                       eei->dot_section,
                                       section_pointer,
-                                      alignment_pointer);
+                                      alignment_pointer,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      false);
   }
 
   uint64_t
@@ -526,7 +582,11 @@ class Trinary_expression : public Expression
                                       eei->dot_value,
                                       eei->dot_section,
                                       section_pointer,
-                                      alignment_pointer);
+                                      alignment_pointer,
+                                      NULL,
+                                      NULL,
+                                      NULL,
+                                      false);
   }
 
   void
This page took 0.030898 seconds and 4 git commands to generate.