TIC6X __c6xabi_DSBT_BASE
[deliverable/binutils-gdb.git] / ld / ldexp.c
index 33ca289682cd0dc0fe15f2d9b3143f4417546ea7..6fa251e79e4b500141d5e851e3c55a6a73629d84 100644 (file)
@@ -1,5 +1,5 @@
 /* This module handles expression trees.
-   Copyright (C) 1991-2017 Free Software Foundation, Inc.
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
 
    This file is part of the GNU Binutils.
@@ -60,15 +60,12 @@ struct definedness_hash_entry
      section statement, the section we'd like it relative to.  */
   asection *final_sec;
 
+  /* Low bits of iteration count.  Symbols with matching iteration have
+     been defined in this pass over the script.  */
+  unsigned int iteration : 8;
+
   /* Symbol was defined by an object file.  */
   unsigned int by_object : 1;
-
-  /* Symbols was defined by a script.  */
-  unsigned int by_script : 1;
-
-  /* Low bit of iteration count.  Symbols with matching iteration have
-     been defined in this pass over the script.  */
-  unsigned int iteration : 1;
 };
 
 static struct bfd_hash_table definedness_table;
@@ -283,10 +280,9 @@ definedness_newfunc (struct bfd_hash_entry *entry,
       bfd_hash_allocate (table, sizeof (struct definedness_hash_entry));
 
   if (ret == NULL)
-    einfo (_("%P%F: bfd_hash_allocate failed creating symbol %s\n"), name);
+    einfo (_("%F%P: bfd_hash_allocate failed creating symbol %s\n"), name);
 
   ret->by_object = 0;
-  ret->by_script = 0;
   ret->iteration = 0;
   return &ret->root;
 }
@@ -315,12 +311,12 @@ update_definedness (const char *name, struct bfd_link_hash_entry *h)
     bfd_hash_lookup (&definedness_table, name, TRUE, FALSE);
 
   if (defentry == NULL)
-    einfo (_("%P%F: bfd_hash_lookup failed creating symbol %s\n"), name);
+    einfo (_("%F%P: bfd_hash_lookup failed creating symbol %s\n"), name);
 
   /* If the symbol was already defined, and not by a script, then it
      must be defined by an object file or by the linker target code.  */
   ret = TRUE;
-  if (!defentry->by_script
+  if (!h->ldscript_def
       && (h->type == bfd_link_hash_defined
          || h->type == bfd_link_hash_defweak
          || h->type == bfd_link_hash_common))
@@ -332,7 +328,6 @@ update_definedness (const char *name, struct bfd_link_hash_entry *h)
        ret = FALSE;
     }
 
-  defentry->by_script = 1;
   defentry->iteration = lang_statement_iteration;
   defentry->final_sec = bfd_abs_section_ptr;
   if (expld.phase == lang_final_phase_enum
@@ -629,7 +624,7 @@ fold_binary (etree_type *tree)
            expld.result.value = ((bfd_signed_vma) lhs.value
                                  % (bfd_signed_vma) expld.result.value);
          else if (expld.phase != lang_mark_phase_enum)
-           einfo (_("%F%S %% by zero\n"), tree->binary.rhs);
+           einfo (_("%F%P:%pS %% by zero\n"), tree->binary.rhs);
          arith_result_section (&lhs);
          break;
 
@@ -638,7 +633,7 @@ fold_binary (etree_type *tree)
            expld.result.value = ((bfd_signed_vma) lhs.value
                                  / (bfd_signed_vma) expld.result.value);
          else if (expld.phase != lang_mark_phase_enum)
-           einfo (_("%F%S / by zero\n"), tree->binary.rhs);
+           einfo (_("%F%P:%pS / by zero\n"), tree->binary.rhs);
          arith_result_section (&lhs);
          break;
 
@@ -686,6 +681,9 @@ fold_trinary (etree_type *tree)
 static void
 fold_name (etree_type *tree)
 {
+  struct bfd_link_hash_entry *h;
+  struct definedness_hash_entry *def;
+
   memset (&expld.result, 0, sizeof (expld.result));
 
   switch (tree->type.node_code)
@@ -703,23 +701,18 @@ fold_name (etree_type *tree)
       break;
 
     case DEFINED:
-      if (expld.phase != lang_first_phase_enum)
-       {
-         struct bfd_link_hash_entry *h;
-         struct definedness_hash_entry *def;
-
-         h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
-                                           &link_info,
-                                           tree->name.name,
-                                           FALSE, FALSE, TRUE);
-         new_number (h != NULL
-                     && (h->type == bfd_link_hash_defined
-                         || h->type == bfd_link_hash_defweak
-                         || h->type == bfd_link_hash_common)
-                     && ((def = symbol_defined (tree->name.name)) == NULL
-                         || def->by_object
-                         || def->iteration == (lang_statement_iteration & 1)));
-       }
+      h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
+                                       &link_info,
+                                       tree->name.name,
+                                       FALSE, FALSE, TRUE);
+      new_number (h != NULL
+                 && (h->type == bfd_link_hash_defined
+                     || h->type == bfd_link_hash_defweak
+                     || h->type == bfd_link_hash_common)
+                 && (!h->ldscript_def
+                     || (def = symbol_defined (tree->name.name)) == NULL
+                     || def->by_object
+                     || def->iteration == (lang_statement_iteration & 255)));
       break;
 
     case NAME:
@@ -728,9 +721,6 @@ fold_name (etree_type *tree)
        {
          /* Self-assignment is only allowed for absolute symbols
             defined in a linker script.  */
-         struct bfd_link_hash_entry *h;
-         struct definedness_hash_entry *def;
-
          h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
                                            &link_info,
                                            tree->name.name,
@@ -740,23 +730,19 @@ fold_name (etree_type *tree)
                    || h->type == bfd_link_hash_defweak)
                && h->u.def.section == bfd_abs_section_ptr
                && (def = symbol_defined (tree->name.name)) != NULL
-               && def->iteration == (lang_statement_iteration & 1)))
+               && def->iteration == (lang_statement_iteration & 255)))
            expld.assign_name = NULL;
        }
-      if (expld.phase == lang_first_phase_enum)
-       ;
-      else if (tree->name.name[0] == '.' && tree->name.name[1] == 0)
+      if (tree->name.name[0] == '.' && tree->name.name[1] == 0)
        new_rel_from_abs (expld.dot);
       else
        {
-         struct bfd_link_hash_entry *h;
-
          h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
                                            &link_info,
                                            tree->name.name,
                                            TRUE, FALSE, TRUE);
          if (!h)
-           einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
+           einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
          else if (h->type == bfd_link_hash_defined
                   || h->type == bfd_link_hash_defweak)
            {
@@ -765,10 +751,10 @@ fold_name (etree_type *tree)
              output_section = h->u.def.section->output_section;
              if (output_section == NULL)
                {
-                 if (expld.phase == lang_mark_phase_enum)
+                 if (expld.phase <= lang_mark_phase_enum)
                    new_rel (h->u.def.value, h->u.def.section);
                  else
-                   einfo (_("%X%S: unresolvable symbol `%s'"
+                   einfo (_("%X%P:%pS: unresolvable symbol `%s'"
                             " referenced in expression\n"),
                           tree, tree->name.name);
                }
@@ -783,7 +769,7 @@ fold_name (etree_type *tree)
          else if (expld.phase == lang_final_phase_enum
                   || (expld.phase != lang_mark_phase_enum
                       && expld.assigning_to_dot))
-           einfo (_("%F%S: undefined symbol `%s'"
+           einfo (_("%F%P:%pS: undefined symbol `%s'"
                     " referenced in expression\n"),
                   tree, tree->name.name);
          else if (h->type == bfd_link_hash_new)
@@ -796,7 +782,7 @@ fold_name (etree_type *tree)
          if (expld.assign_src == NULL)
            expld.assign_src = h;
          else
-           expld.assign_src = (struct bfd_link_hash_entry *) - 1;
+           expld.assign_src = (struct bfd_link_hash_entry *) - 1;
        }
       break;
 
@@ -809,7 +795,7 @@ fold_name (etree_type *tree)
          if (os == NULL)
            {
              if (expld.phase == lang_final_phase_enum)
-               einfo (_("%F%S: undefined section `%s'"
+               einfo (_("%F%P:%pS: undefined section `%s'"
                         " referenced in expression\n"),
                       tree, tree->name.name);
            }
@@ -827,7 +813,7 @@ fold_name (etree_type *tree)
          if (os == NULL)
            {
              if (expld.phase == lang_final_phase_enum)
-               einfo (_("%F%S: undefined section `%s'"
+               einfo (_("%F%P:%pS: undefined section `%s'"
                         " referenced in expression\n"),
                       tree, tree->name.name);
            }
@@ -855,7 +841,7 @@ fold_name (etree_type *tree)
          if (os == NULL)
            {
              if (expld.phase == lang_final_phase_enum)
-               einfo (_("%F%S: undefined section `%s'"
+               einfo (_("%F%P:%pS: undefined section `%s'"
                         " referenced in expression\n"),
                       tree, tree->name.name);
              new_number (0);
@@ -887,7 +873,7 @@ fold_name (etree_type *tree)
          if (mem != NULL)
            new_number (mem->length);
          else
-           einfo (_("%F%S: undefined MEMORY region `%s'"
+           einfo (_("%F%P:%pS: undefined MEMORY region `%s'"
                     " referenced in expression\n"),
                   tree, tree->name.name);
        }
@@ -903,7 +889,7 @@ fold_name (etree_type *tree)
          if (mem != NULL)
            new_rel_from_abs (mem->origin);
          else
-           einfo (_("%F%S: undefined MEMORY region `%s'"
+           einfo (_("%F%P:%pS: undefined MEMORY region `%s'"
                     " referenced in expression\n"),
                   tree, tree->name.name);
        }
@@ -915,7 +901,7 @@ fold_name (etree_type *tree)
       else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
        new_number (config.commonpagesize);
       else
-       einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
+       einfo (_("%F%P:%pS: unknown constant `%s' referenced in expression\n"),
               tree, tree->name.name);
       break;
 
@@ -957,12 +943,12 @@ is_sym_value (const etree_type *tree, bfd_vma val)
   return (tree->type.node_class == etree_name
          && tree->type.node_code == NAME
          && (def = symbol_defined (tree->name.name)) != NULL
-         && def->by_script
-         && def->iteration == (lang_statement_iteration & 1)
+         && def->iteration == (lang_statement_iteration & 255)
          && (h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
                                                &link_info,
                                                tree->name.name,
                                                FALSE, FALSE, TRUE)) != NULL
+         && h->ldscript_def
          && h->type == bfd_link_hash_defined
          && h->u.def.section == bfd_abs_section_ptr
          && h->u.def.value == val);
@@ -1063,7 +1049,7 @@ exp_fold_tree_1 (etree_type *tree)
       if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0)
        {
          if (tree->type.node_class != etree_assign)
-           einfo (_("%F%S can not PROVIDE assignment to"
+           einfo (_("%F%P:%pS can not PROVIDE assignment to"
                     " location counter\n"), tree);
          if (expld.phase != lang_first_phase_enum)
            {
@@ -1096,11 +1082,11 @@ exp_fold_tree_1 (etree_type *tree)
                  || expld.section == bfd_und_section_ptr)
                {
                  if (expld.phase != lang_mark_phase_enum)
-                   einfo (_("%F%S invalid assignment to"
+                   einfo (_("%F%P:%pS invalid assignment to"
                             " location counter\n"), tree);
                }
              else if (expld.dotp == NULL)
-               einfo (_("%F%S assignment to location counter"
+               einfo (_("%F%P:%pS assignment to location counter"
                         " invalid outside of SECTIONS\n"), tree);
 
              /* After allocation, assignment to dot should not be
@@ -1119,7 +1105,7 @@ exp_fold_tree_1 (etree_type *tree)
                    nextdot += expld.section->vma;
                  if (nextdot < expld.dot
                      && expld.section != bfd_abs_section_ptr)
-                   einfo (_("%F%S cannot move location counter backwards"
+                   einfo (_("%F%P:%pS cannot move location counter backwards"
                             " (from %V to %V)\n"),
                           tree, expld.dot, nextdot);
                  else
@@ -1167,60 +1153,67 @@ exp_fold_tree_1 (etree_type *tree)
             2) Section relative symbol values cannot be correctly
             converted to absolute values, as is required by many
             expressions, until final section sizing is complete.  */
-         if ((expld.result.valid_p
-              && (expld.phase == lang_final_phase_enum
-                  || expld.assign_name != NULL))
-             || (expld.phase <= lang_mark_phase_enum
-                 && tree->type.node_class == etree_assign
-                 && tree->assign.defsym))
+         if (expld.phase == lang_final_phase_enum
+              || expld.assign_name != NULL)
            {
+             if (tree->type.node_class == etree_provide)
+               tree->type.node_class = etree_provided;
+
              if (h == NULL)
                {
                  h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
                                            TRUE, FALSE, TRUE);
                  if (h == NULL)
-                   einfo (_("%P%F:%s: hash creation failed\n"),
+                   einfo (_("%F%P:%s: hash creation failed\n"),
                           tree->assign.dst);
                }
 
-             if (expld.result.section == NULL)
-               expld.result.section = expld.section;
-             if (!update_definedness (tree->assign.dst, h) && 0)
+              /* If the expression is not valid then fake a zero value.  In
+                 the final phase any errors will already have been raised,
+                 in earlier phases we want to create this definition so
+                 that it can be seen by other expressions.  */
+              if (!expld.result.valid_p
+                  && h->type == bfd_link_hash_new)
+                {
+                  expld.result.value = 0;
+                  expld.result.section = NULL;
+                  expld.result.valid_p = TRUE;
+                }
+
+             if (expld.result.valid_p)
                {
-                 /* Symbol was already defined.  For now this error
-                    is disabled because it causes failures in the ld
-                    testsuite: ld-elf/var1, ld-scripts/defined5, and
-                    ld-scripts/pr14962.  Some of these no doubt
-                    reflect scripts used in the wild.  */
-                 (*link_info.callbacks->multiple_definition)
-                   (&link_info, h, link_info.output_bfd,
-                    expld.result.section, expld.result.value);
+                 if (expld.result.section == NULL)
+                   expld.result.section = expld.section;
+                 if (!update_definedness (tree->assign.dst, h) && 0)
+                   {
+                     /* Symbol was already defined.  For now this error
+                        is disabled because it causes failures in the ld
+                        testsuite: ld-elf/var1, ld-scripts/defined5, and
+                        ld-scripts/pr14962.  Some of these no doubt
+                        reflect scripts used in the wild.  */
+                     (*link_info.callbacks->multiple_definition)
+                       (&link_info, h, link_info.output_bfd,
+                        expld.result.section, expld.result.value);
+                   }
+                 h->type = bfd_link_hash_defined;
+                 h->u.def.value = expld.result.value;
+                 h->u.def.section = expld.result.section;
+                 h->linker_def = ! tree->assign.type.lineno;
+                 h->ldscript_def = 1;
+                 if (tree->assign.hidden)
+                   bfd_link_hide_symbol (link_info.output_bfd,
+                                         &link_info, h);
+
+                 /* Copy the symbol type if this is an expression only
+                    referencing a single symbol.  (If the expression
+                    contains ternary conditions, ignoring symbols on
+                    false branches.)  */
+                 if (expld.assign_src != NULL
+                     && (expld.assign_src
+                         != (struct bfd_link_hash_entry *) -1))
+                   bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
+                                                   expld.assign_src);
                }
-             h->type = bfd_link_hash_defined;
-             h->u.def.value = expld.result.value;
-             h->u.def.section = expld.result.section;
-             h->linker_def = ! tree->assign.type.lineno;
-             h->ldscript_def = 1;
-             if (tree->type.node_class == etree_provide)
-               tree->type.node_class = etree_provided;
-
-             /* Copy the symbol type if this is an expression only
-                referencing a single symbol.  (If the expression
-                contains ternary conditions, ignoring symbols on
-                false branches.)  */
-             if (expld.result.valid_p
-                 && expld.assign_src != NULL
-                 && expld.assign_src != (struct bfd_link_hash_entry *) 0 - 1)
-               bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
-                                               expld.assign_src);
-           }
-         else if (expld.phase == lang_final_phase_enum)
-           {
-             h = bfd_link_hash_lookup (link_info.hash, tree->assign.dst,
-                                       FALSE, FALSE, TRUE);
-             if (h != NULL
-                 && h->type == bfd_link_hash_new)
-               h->type = bfd_link_hash_undefined;
            }
          expld.assign_name = NULL;
        }
@@ -1348,7 +1341,6 @@ static etree_type *
 exp_assop (const char *dst,
           etree_type *src,
           enum node_tree_enum class,
-          bfd_boolean defsym,
           bfd_boolean hidden)
 {
   etree_type *n;
@@ -1360,7 +1352,6 @@ exp_assop (const char *dst,
   n->assign.type.node_class = class;
   n->assign.src = src;
   n->assign.dst = dst;
-  n->assign.defsym = defsym;
   n->assign.hidden = hidden;
   return n;
 }
@@ -1370,7 +1361,7 @@ exp_assop (const char *dst,
 etree_type *
 exp_assign (const char *dst, etree_type *src, bfd_boolean hidden)
 {
-  return exp_assop (dst, src, etree_assign, FALSE, hidden);
+  return exp_assop (dst, src, etree_assign, hidden);
 }
 
 /* Handle --defsym command-line option.  */
@@ -1378,7 +1369,7 @@ exp_assign (const char *dst, etree_type *src, bfd_boolean hidden)
 etree_type *
 exp_defsym (const char *dst, etree_type *src)
 {
-  return exp_assop (dst, src, etree_assign, TRUE, FALSE);
+  return exp_assop (dst, src, etree_assign, FALSE);
 }
 
 /* Handle PROVIDE.  */
@@ -1386,7 +1377,7 @@ exp_defsym (const char *dst, etree_type *src)
 etree_type *
 exp_provide (const char *dst, etree_type *src, bfd_boolean hidden)
 {
-  return exp_assop (dst, src, etree_provide, FALSE, hidden);
+  return exp_assop (dst, src, etree_provide, hidden);
 }
 
 /* Handle ASSERT.  */
@@ -1427,7 +1418,7 @@ exp_print_tree (etree_type *tree)
       return;
     case etree_rel:
       if (tree->rel.section->owner != NULL)
-       minfo ("%B:", tree->rel.section->owner);
+       minfo ("%pB:", tree->rel.section->owner);
       minfo ("%s+0x%v", tree->rel.section->name, tree->rel.value);
       return;
     case etree_assign:
@@ -1437,7 +1428,7 @@ exp_print_tree (etree_type *tree)
       break;
     case etree_provide:
     case etree_provided:
-      fprintf (config.map_file, "PROVIDE (%s, ", tree->assign.dst);
+      fprintf (config.map_file, "PROVIDE (%s = ", tree->assign.dst);
       exp_print_tree (tree->assign.src);
       fputc (')', config.map_file);
       break;
@@ -1525,7 +1516,7 @@ exp_get_vma (etree_type *tree, bfd_vma def, char *name)
       if (expld.result.valid_p)
        return expld.result.value;
       else if (name != NULL && expld.phase != lang_mark_phase_enum)
-       einfo (_("%F%S: nonconstant expression for %s\n"),
+       einfo (_("%F%P:%pS: nonconstant expression for %s\n"),
               tree, name);
     }
   return def;
@@ -1551,7 +1542,7 @@ exp_get_fill (etree_type *tree, fill_type *def, char *name)
   if (!expld.result.valid_p)
     {
       if (name != NULL && expld.phase != lang_mark_phase_enum)
-       einfo (_("%F%S: nonconstant expression for %s\n"),
+       einfo (_("%F%P:%pS: nonconstant expression for %s\n"),
               tree, name);
       return def;
     }
@@ -1611,7 +1602,7 @@ exp_get_abs_int (etree_type *tree, int def, char *name)
        }
       else if (name != NULL && expld.phase != lang_mark_phase_enum)
        {
-         einfo (_("%F%S: nonconstant expression for %s\n"),
+         einfo (_("%F%P:%pS: nonconstant expression for %s\n"),
                 tree, name);
        }
     }
@@ -1637,7 +1628,7 @@ ldexp_init (void)
                              definedness_newfunc,
                              sizeof (struct definedness_hash_entry),
                              13))
-    einfo (_("%P%F: can not create hash table: %E\n"));
+    einfo (_("%F%P: can not create hash table: %E\n"));
 }
 
 /* Convert absolute symbols defined by a script from "dot" (also
This page took 0.031689 seconds and 4 git commands to generate.