+ /* There must always be a ":Main", so we'll add one if there are no
+ symbols. Make sure we have room for it. */
+ table = bfd_alloc (abfd, (count + 1) * sizeof (asymbol *));
+ if (table == NULL)
+ return FALSE;
+
+ memcpy (table, orig_table, count * sizeof (asymbol *));
+
+ /* Move :Main (if there is one) to the first position. This is
+ necessary to get the same layout of the trie-tree when linking as
+ when objcopying the result as in the objcopy.exp test "simple objcopy
+ of executable". It also automatically takes care of assigning serial
+ number 1 to :Main (as is mandatory). */
+ for (i = 0; i < count; i++)
+ if (table[i] != NULL
+ && strcmp (table[i]->name, MMIX_START_SYMBOL_NAME) == 0
+ && (table[i]->flags & (BSF_DEBUGGING|BSF_GLOBAL)) == BSF_GLOBAL)
+ {
+ asymbol *mainsym = table[i];
+ memcpy (table + 1, orig_table, i * sizeof (asymbol *));
+ table[0] = mainsym;
+
+ /* Check that the value assigned to :Main is the same as the entry
+ address. The default linker script asserts this. This is as
+ good a place as any to check this consistency. */
+ if ((mainsym->value
+ + mainsym->section->output_section->vma
+ + mainsym->section->output_offset)
+ != bfd_get_start_address (abfd))
+ {
+ /* Arbitrary buffer to hold the printable representation of a
+ vma. */
+ char vmas_main[40];
+ char vmas_start[40];
+ bfd_vma vma_start = bfd_get_start_address (abfd);
+
+ sprintf_vma (vmas_main, mainsym->value);
+ sprintf_vma (vmas_start, vma_start);
+
+ (*_bfd_error_handler)
+ (_("%s: Bad symbol definition: `Main' set to %s rather\
+ than the start address %s\n"),
+ bfd_get_filename (abfd), vmas_main, vmas_start);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ break;
+ }
+ if (i == count && count != 0)