PR27719, lang_mark_undefineds trashes memory
[binutils-gdb.git] / ld / emultempl / armelf.em
index efdcf5a2aa7b4d231eaede997bac09323746fb33..7aec17e5ede95e488350910875b0b1bf4fb4e3d1 100644 (file)
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright (C) 1991-2020 Free Software Foundation, Inc.
+#   Copyright (C) 1991-2021 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -56,11 +56,17 @@ gld${EMULATION_NAME}_before_parse (void)
 #ifndef TARGET_                        /* I.e., if not generic.  */
   ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
 #endif /* not TARGET_ */
-  input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
-  config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
-  config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
-  link_info.check_relocs_after_open_input = TRUE;
+  input_flags.dynamic = ${DYNAMIC_LINK-true};
+  config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
+  config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
+  link_info.check_relocs_after_open_input = true;
+EOF
+if test -n "$COMMONPAGESIZE"; then
+fragment <<EOF
   link_info.relro = DEFAULT_LD_Z_RELRO;
+EOF
+fi
+fragment <<EOF
 }
 
 static void
@@ -143,11 +149,11 @@ struct hook_stub_info
 
 /* Traverse the linker tree to find the spot where the stub goes.  */
 
-static bfd_boolean
+static bool
 hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
 {
   lang_statement_union_type *l;
-  bfd_boolean ret;
+  bool ret;
 
   for (; (l = *lp) != NULL; lp = &l->header.next)
     {
@@ -185,7 +191,7 @@ hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
                 after its associated input section.  */
              *(info->add.tail) = l->header.next;
              l->header.next = info->add.head;
-             return TRUE;
+             return true;
            }
          break;
 
@@ -206,7 +212,7 @@ hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
          break;
        }
     }
-  return FALSE;
+  return false;
 }
 
 
@@ -227,7 +233,8 @@ elf32_arm_add_stub_section (const char * stub_sec_name,
   struct hook_stub_info info;
 
   flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
-          | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
+          | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP
+          | SEC_LINKER_CREATED);
   stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
                                                 stub_sec_name, flags);
   if (stub_sec == NULL)
@@ -239,7 +246,7 @@ elf32_arm_add_stub_section (const char * stub_sec_name,
 
   info.input_section = after_input_section;
   lang_list_init (&info.add);
-  lang_add_section (&info.add, stub_sec, NULL, os);
+  lang_add_section (&info.add, stub_sec, NULL, NULL, os);
 
   if (info.add.head == NULL)
     goto err_ret;
@@ -277,7 +284,7 @@ gldarm_layout_sections_again (void)
   /* If we have changed sizes of the stub sections, then we need
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
-  ldelf_map_segments (TRUE);
+  ldelf_map_segments (true);
   need_laying_out = -1;
 }
 
@@ -450,17 +457,17 @@ gld${EMULATION_NAME}_finish (void)
   if (params.thumb_entry_symbol)
     {
       h = bfd_link_hash_lookup (link_info.hash, params.thumb_entry_symbol,
-                               FALSE, FALSE, TRUE);
+                               false, false, true);
     }
   else
     {
       struct elf_link_hash_entry * eh;
 
-      if (!entry_symbol.name)
+      if (!entry_symbol.name || !is_elf_hash_table (link_info.hash))
        return;
 
       h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
-                               FALSE, FALSE, TRUE);
+                               false, false, true);
       eh = (struct elf_link_hash_entry *)h;
       if (!h || ARM_GET_SYM_BRANCH_TYPE (eh->target_internal)
                != ST_BRANCH_TO_THUMB)