[x86] Resolve non-PIC undefweak symbols in executable
[deliverable/binutils-gdb.git] / ld / emultempl / mipself.em
index 65cb0731a2b3a9f48a592dd821e3ee88ab43a254..dbff36bb8d18264bdba1d29c2127a1804ec9e896 100644 (file)
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
+#   Copyright (C) 2004-2016 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -27,12 +27,14 @@ fragment <<EOF
 #define is_mips_elf(bfd)                               \
   (bfd_get_flavour (bfd) == bfd_target_elf_flavour     \
    && elf_tdata (bfd) != NULL                          \
-   && elf_object_id (bfd) == MIPS_ELF_TDATA)
+   && elf_object_id (bfd) == MIPS_ELF_DATA)
 
 /* Fake input file for stubs.  */
 static lang_input_statement_type *stub_file;
 static bfd *stub_bfd;
 
+static bfd_boolean insn32;
+
 static void
 mips_after_parse (void)
 {
@@ -45,7 +47,7 @@ mips_after_parse (void)
       link_info.emit_hash = TRUE;
       link_info.emit_gnu_hash = FALSE;
     }
-  after_parse_default ();
+  gld${EMULATION_NAME}_after_parse ();
 }
 
 struct hook_stub_info
@@ -134,10 +136,14 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section,
 {
   asection *stub_sec;
   flagword flags;
-  const char *secname;
   lang_output_section_statement_type *os;
   struct hook_stub_info info;
 
+  /* PR 12845: If the input section has been garbage collected it will
+     not have its output section set to *ABS*.  */
+  if (bfd_is_abs_section (output_section))
+    return NULL;
+
   /* Create the stub file, if we haven't already.  */
   if (stub_file == NULL)
     {
@@ -169,13 +175,11 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section,
   if (!bfd_set_section_flags (stub_bfd, stub_sec, flags))
     goto err_ret;
 
-  /* Create an output section statement.  */
-  secname = bfd_get_section_name (output_section->owner, output_section);
-  os = lang_output_section_find (secname);
+  os = lang_output_section_get (output_section);
 
   /* Initialize a statement list that contains only the new statement.  */
   lang_list_init (&info.add);
-  lang_add_section (&info.add, stub_sec, os);
+  lang_add_section (&info.add, stub_sec, NULL, os);
   if (info.add.head == NULL)
     goto err_ret;
 
@@ -194,6 +198,12 @@ mips_add_stub_section (const char *stub_sec_name, asection *input_section,
 static void
 mips_create_output_section_statements (void)
 {
+  struct elf_link_hash_table *htab;
+
+  htab = elf_hash_table (&link_info);
+  if (is_elf_hash_table (htab) && is_mips_elf (link_info.output_bfd))
+    _bfd_mips_elf_insn32 (&link_info, insn32);
+
   if (is_mips_elf (link_info.output_bfd))
     _bfd_mips_elf_init_stubs (&link_info, mips_add_stub_section);
 }
@@ -206,7 +216,7 @@ mips_before_allocation (void)
   flagword flags;
 
   flags = elf_elfheader (link_info.output_bfd)->e_flags;
-  if (!link_info.shared
+  if (!bfd_link_pic (&link_info)
       && !link_info.nocopyreloc
       && (flags & (EF_MIPS_PIC | EF_MIPS_CPIC)) == EF_MIPS_CPIC)
     _bfd_mips_elf_use_plts_and_copy_relocs (&link_info);
@@ -236,6 +246,41 @@ mips_lang_for_each_input_file (void (*func) (lang_input_statement_type *))
 
 EOF
 
+# Define some shell vars to insert bits of code into the standard elf
+# parse_args and list_options functions.
+#
+PARSE_AND_LIST_PROLOGUE='
+enum
+  {
+    OPTION_INSN32 = 301,
+    OPTION_NO_INSN32
+  };
+'
+
+PARSE_AND_LIST_LONGOPTS='
+  { "insn32", no_argument, NULL, OPTION_INSN32 },
+  { "no-insn32", no_argument, NULL, OPTION_NO_INSN32 },
+'
+
+PARSE_AND_LIST_OPTIONS='
+  fprintf (file, _("\
+  --insn32                    Only generate 32-bit microMIPS instructions\n"
+                  ));
+  fprintf (file, _("\
+  --no-insn32                 Generate all microMIPS instructions\n"
+                  ));
+'
+
+PARSE_AND_LIST_ARGS_CASES='
+    case OPTION_INSN32:
+      insn32 = TRUE;
+      break;
+
+    case OPTION_NO_INSN32:
+      insn32 = FALSE;
+      break;
+'
+
 LDEMUL_AFTER_PARSE=mips_after_parse
 LDEMUL_BEFORE_ALLOCATION=mips_before_allocation
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=mips_create_output_section_statements
This page took 0.024668 seconds and 4 git commands to generate.