* bfd-in.h (BFD_LINKER_CREATED): Define.
[deliverable/binutils-gdb.git] / ld / emultempl / ppc64elf.em
index d24ecf44296860a684cd09cc06a29ae0cf5fab77..de4f02fcd685302e89473656bdbc90a1789fbccf 100644 (file)
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2002, 2003 Free Software Foundation, Inc.
+#   Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
 #
 # This file is part of GLD, the Gnu Linker.
 #
@@ -25,10 +25,12 @@ cat >>e${EMULATION_NAME}.c <<EOF
 
 #include "ldctor.h"
 #include "libbfd.h"
+#include "elf-bfd.h"
 #include "elf64-ppc.h"
 
 /* Fake input file for stubs.  */
 static lang_input_statement_type *stub_file;
+static int stub_added = 0;
 
 /* Whether we need to call ppc_layout_sections_again.  */
 static int need_laying_out = 0;
@@ -42,13 +44,25 @@ static bfd_signed_vma group_size = 1;
 static int dotsyms = 1;
 
 /* Whether to run tls optimization.  */
-static int notlsopt = 0;
+static int no_tls_opt = 0;
+
+/* Whether to run opd optimization.  */
+static int no_opd_opt = 0;
+
+/* Whether to run toc optimization.  */
+static int no_toc_opt = 0;
+
+/* Whether to allow multiple toc sections.  */
+static int no_multi_toc = 0;
 
 /* Whether to emit symbols for stubs.  */
 static int emit_stub_syms = 0;
 
 static asection *toc_section = 0;
 
+/* Whether to canonicalize .opd so that there are no overlapping
+   .opd entries.  */
+static int non_overlapping_opd = 0;
 
 /* This is called before the input files are opened.  We create a new
    fake input file to hold the stub sections.  */
@@ -63,6 +77,8 @@ ppc_create_output_section_statements (void)
       && link_info.hash->creator != &bfd_elf64_powerpcle_vec)
     return;
 
+  link_info.wrap_char = '.';
+
   stub_file = lang_add_input_file ("linker stubs",
                                   lang_input_file_is_fake_enum,
                                   NULL);
@@ -76,19 +92,9 @@ ppc_create_output_section_statements (void)
       return;
     }
 
+  stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
   ldlang_add_file (stub_file);
-}
-
-static void
-ppc_after_open (void)
-{
-  if (!ppc64_elf_mark_entry_syms (&link_info))
-    {
-      einfo ("%X%P: can not mark entry symbols %E\n");
-      return;
-    }
-
-  gld${EMULATION_NAME}_after_open ();
+  ppc64_elf_init_stub_bfd (stub_file->the_bfd, &link_info);
 }
 
 static void
@@ -96,13 +102,14 @@ ppc_before_allocation (void)
 {
   if (stub_file != NULL)
     {
-      if (!ppc64_elf_edit_opd (output_bfd, &link_info))
+      if (!no_opd_opt
+         && !ppc64_elf_edit_opd (output_bfd, &link_info, non_overlapping_opd))
        {
-         einfo ("%X%P: can not edit opd %E\n");
+         einfo ("%X%P: can not edit %s %E\n", "opd");
          return;
        }
 
-      if (ppc64_elf_tls_setup (output_bfd, &link_info) && !notlsopt)
+      if (ppc64_elf_tls_setup (output_bfd, &link_info) && !no_tls_opt)
        {
          /* Size the sections.  This is premature, but we want to know the
             TLS segment layout so that certain optimizations can be done.  */
@@ -115,8 +122,18 @@ ppc_before_allocation (void)
              return;
            }
 
+         /* We must not cache anything from the preliminary sizing.  */
+         elf_tdata (output_bfd)->program_header_size = 0;
          lang_reset_memory_regions ();
        }
+
+      if (!no_toc_opt
+         && !link_info.relocatable
+         && !ppc64_elf_edit_toc (output_bfd, &link_info))
+       {
+         einfo ("%X%P: can not edit %s %E\n", "toc");
+         return;
+       }
     }
 
   gld${EMULATION_NAME}_before_allocation ();
@@ -232,6 +249,7 @@ ppc_add_stub_section (const char *stub_sec_name, asection *input_section)
   if (info.add.head == NULL)
     goto err_ret;
 
+  stub_added = 1;
   if (hook_in_stub (&info, &os->children.head))
     return stub_sec;
 
@@ -270,7 +288,7 @@ ppc_layout_sections_again (void)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
-  if (!link_info.relocateable)
+  if (!link_info.relocatable)
     _bfd_set_gp_value (output_bfd, ppc64_elf_toc (output_bfd));
 }
 
@@ -280,6 +298,7 @@ build_toc_list (lang_statement_union_type *statement)
 {
   if (statement->header.type == lang_input_section_enum
       && !statement->input_section.ifile->just_syms_flag
+      && (statement->input_section.section->flags & SEC_EXCLUDE) == 0
       && statement->input_section.section->output_section == toc_section)
     ppc64_elf_next_toc_section (&link_info, statement->input_section.section);
 }
@@ -290,6 +309,7 @@ build_section_lists (lang_statement_union_type *statement)
 {
   if (statement->header.type == lang_input_section_enum
       && !statement->input_section.ifile->just_syms_flag
+      && (statement->input_section.section->flags & SEC_EXCLUDE) == 0
       && statement->input_section.section->output_section != NULL
       && statement->input_section.section->output_section->owner == output_bfd)
     {
@@ -310,18 +330,19 @@ gld${EMULATION_NAME}_finish (void)
      descriptor in the .opd section.  */
   entry_section = ".opd";
 
-  /* bfd_elf64_discard_info just plays with debugging sections,
+  /* bfd_elf_discard_info just plays with debugging sections,
      ie. doesn't affect any code, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf${ELFSIZE}_discard_info (output_bfd, &link_info))
+  if (bfd_elf_discard_info (output_bfd, &link_info))
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't have any
      stubs.  */
-  if (stub_file != NULL && !link_info.relocateable)
+  if (stub_file != NULL && !link_info.relocatable)
     {
-      int ret = ppc64_elf_setup_section_lists (output_bfd, &link_info);
+      int ret = ppc64_elf_setup_section_lists (output_bfd, &link_info,
+                                              no_multi_toc);
       if (ret != 0)
        {
          if (ret < 0)
@@ -330,7 +351,7 @@ gld${EMULATION_NAME}_finish (void)
              return;
            }
 
-         toc_section = bfd_get_section_by_name (output_bfd, ".toc");
+         toc_section = bfd_get_section_by_name (output_bfd, ".got");
          if (toc_section != NULL)
            lang_for_each_statement (build_toc_list);
 
@@ -340,7 +361,6 @@ gld${EMULATION_NAME}_finish (void)
 
          /* Call into the BFD backend to do the real work.  */
          if (!ppc64_elf_size_stubs (output_bfd,
-                                    stub_file->the_bfd,
                                     &link_info,
                                     group_size,
                                     &ppc_add_stub_section,
@@ -355,11 +375,20 @@ gld${EMULATION_NAME}_finish (void)
   if (need_laying_out)
     ppc_layout_sections_again ();
 
-  if (stub_file != NULL && stub_file->the_bfd->sections != NULL)
+  if (link_info.relocatable)
+    {
+      asection *toc = bfd_get_section_by_name (output_bfd, ".toc");
+      if (toc != NULL
+         && bfd_section_size (output_bfd, toc) > 0x10000)
+       einfo ("%X%P: TOC section size exceeds 64k\n");
+    }
+
+  if (stub_added)
     {
       char *msg = NULL;
       char *line, *endline;
 
+      emit_stub_syms |= link_info.emitrelocations;
       if (!ppc64_elf_build_stubs (emit_stub_syms, &link_info,
                                  config.stats ? &msg : NULL))
        einfo ("%X%P: can not build stubs: %E\n");
@@ -374,6 +403,8 @@ gld${EMULATION_NAME}_finish (void)
       if (msg != NULL)
        free (msg);
     }
+
+  ppc64_elf_restore_symbols (&link_info);
 }
 
 
@@ -399,50 +430,28 @@ static struct bfd_elf_version_expr *
 gld${EMULATION_NAME}_new_vers_pattern (struct bfd_elf_version_expr *entry)
 {
   struct bfd_elf_version_expr *dot_entry;
-  struct bfd_elf_version_expr *next;
   unsigned int len;
   char *dot_pat;
 
-  if (!dotsyms || entry->pattern[0] == '*')
+  if (!dotsyms || entry->pattern[0] == '*' || entry->pattern[0] == '.')
     return entry;
 
-  /* Is the script adding ".foo" explicitly?  */
-  if (entry->pattern[0] == '.')
-    {
-      /* We may have added this pattern automatically.  Don't add it
-        again.  Quadratic behaviour here is acceptable as the list
-        may be traversed for each input bfd symbol.  */
-      for (next = entry->next; next != NULL; next = next->next)
-       {
-         if (strcmp (next->pattern, entry->pattern) == 0
-             && next->match == entry->match)
-           {
-             next = entry->next;
-             free ((char *) entry->pattern);
-             free (entry);
-             return next;
-           }
-       }
-      return entry;
-    }
-
-  /* Don't add ".foo" if the script has already done so.  */
-  for (next = entry->next; next != NULL; next = next->next)
-    {
-      if (next->pattern[0] == '.'
-         && strcmp (next->pattern + 1, entry->pattern) == 0
-         && next->match == entry->match)
-       return entry;
-    }
-
   dot_entry = xmalloc (sizeof *dot_entry);
+  *dot_entry = *entry;
   dot_entry->next = entry;
   len = strlen (entry->pattern) + 2;
   dot_pat = xmalloc (len);
   dot_pat[0] = '.';
   memcpy (dot_pat + 1, entry->pattern, len - 1);
   dot_entry->pattern = dot_pat;
-  dot_entry->match = entry->match;
+  if (entry->symbol != NULL)
+    {
+      len = strlen (entry->symbol) + 2;
+      dot_pat = xmalloc (len);
+      dot_pat[0] = '.';
+      memcpy (dot_pat + 1, entry->symbol, len - 1);
+      dot_entry->symbol = dot_pat;
+    }
   return dot_entry;
 }
 
@@ -478,6 +487,10 @@ PARSE_AND_LIST_PROLOGUE='
 #define OPTION_DOTSYMS                 (OPTION_STUBSYMS + 1)
 #define OPTION_NO_DOTSYMS              (OPTION_DOTSYMS + 1)
 #define OPTION_NO_TLS_OPT              (OPTION_NO_DOTSYMS + 1)
+#define OPTION_NO_OPD_OPT              (OPTION_NO_TLS_OPT + 1)
+#define OPTION_NO_TOC_OPT              (OPTION_NO_OPD_OPT + 1)
+#define OPTION_NO_MULTI_TOC            (OPTION_NO_TOC_OPT + 1)
+#define OPTION_NON_OVERLAPPING_OPD     (OPTION_NO_MULTI_TOC + 1)
 '
 
 PARSE_AND_LIST_LONGOPTS='
@@ -486,6 +499,10 @@ PARSE_AND_LIST_LONGOPTS='
   { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
   { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
   { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
+  { "no-opd-optimize", no_argument, NULL, OPTION_NO_OPD_OPT },
+  { "no-toc-optimize", no_argument, NULL, OPTION_NO_TOC_OPT },
+  { "no-multi-toc", no_argument, NULL, OPTION_NO_MULTI_TOC },
+  { "non-overlapping-opd", no_argument, NULL, OPTION_NON_OVERLAPPING_OPD },
 '
 
 PARSE_AND_LIST_OPTIONS='
@@ -513,6 +530,19 @@ PARSE_AND_LIST_OPTIONS='
   fprintf (file, _("\
   --no-tls-optimize     Don'\''t try to optimize TLS accesses.\n"
                   ));
+  fprintf (file, _("\
+  --no-opd-optimize     Don'\''t optimize the OPD section.\n"
+                  ));
+  fprintf (file, _("\
+  --no-toc-optimize     Don'\''t optimize the TOC section.\n"
+                  ));
+  fprintf (file, _("\
+  --no-multi-toc        Disallow automatic multiple toc sections.\n"
+                  ));
+  fprintf (file, _("\
+  --non-overlapping-opd Canonicalize .opd, so that there are no overlapping\n\
+                          .opd entries.\n"
+                  ));
 '
 
 PARSE_AND_LIST_ARGS_CASES='
@@ -538,13 +568,28 @@ PARSE_AND_LIST_ARGS_CASES='
       break;
 
     case OPTION_NO_TLS_OPT:
-      notlsopt = 1;
+      no_tls_opt = 1;
+      break;
+
+    case OPTION_NO_OPD_OPT:
+      no_opd_opt = 1;
+      break;
+
+    case OPTION_NO_TOC_OPT:
+      no_toc_opt = 1;
+      break;
+
+    case OPTION_NO_MULTI_TOC:
+      no_multi_toc = 1;
+      break;
+
+    case OPTION_NON_OVERLAPPING_OPD:
+      non_overlapping_opd = 1;
       break;
 '
 
 # Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
 #
-LDEMUL_AFTER_OPEN=ppc_after_open
 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
 LDEMUL_FINISH=gld${EMULATION_NAME}_finish
This page took 0.027781 seconds and 4 git commands to generate.