Don't create .eh_frame_hdr on shared lib bfd
[deliverable/binutils-gdb.git] / ld / emultempl / elf32.em
index de460a274f2e262d25970aff8d21420d216a2669..36dee8e66ab702be1234e093377d70f8567ba903 100644 (file)
@@ -38,11 +38,9 @@ fragment <<EOF
 #include "sysdep.h"
 #include "bfd.h"
 #include "libiberty.h"
-#include "filenames.h"
 #include "safe-ctype.h"
+#include "filenames.h"
 #include "getopt.h"
-#include "md5.h"
-#include "sha1.h"
 #include <fcntl.h>
 
 #include "bfdlink.h"
@@ -54,6 +52,7 @@ fragment <<EOF
 #include "ldlang.h"
 #include "ldfile.h"
 #include "ldemul.h"
+#include "ldbuildid.h"
 #include <ldgram.h>
 #include "elf/common.h"
 #include "elf-bfd.h"
@@ -895,53 +894,20 @@ id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
 {
   const char *style = emit_note_gnu_build_id;
   bfd_size_type size;
+  bfd_size_type build_id_size;
 
   size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
   size = (size + 3) & -(bfd_size_type) 4;
 
-  if (!strcmp (style, "md5") || !strcmp (style, "uuid"))
-    size += 128 / 8;
-  else if (!strcmp (style, "sha1"))
-    size += 160 / 8;
-  else if (!strncmp (style, "0x", 2))
-    {
-      /* ID is in string form (hex).  Convert to bits.  */
-      const char *id = style + 2;
-      do
-       {
-         if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
-           {
-             ++size;
-             id += 2;
-           }
-         else if (*id == '-' || *id == ':')
-           ++id;
-         else
-           {
-             size = 0;
-             break;
-           }
-       } while (*id != '\0');
-    }
+  build_id_size = compute_build_id_size (style);
+  if (build_id_size)
+    size += build_id_size;
   else
     size = 0;
 
   return size;
 }
 
-static unsigned char
-read_hex (const char xdigit)
-{
-  if (ISDIGIT (xdigit))
-    return xdigit - '0';
-  if (ISUPPER (xdigit))
-    return xdigit - 'A' + 0xa;
-  if (ISLOWER (xdigit))
-    return xdigit - 'a' + 0xa;
-  abort ();
-  return 0;
-}
-
 static bfd_boolean
 write_build_id (bfd *abfd)
 {
@@ -954,7 +920,6 @@ write_build_id (bfd *abfd)
   bfd_size_type size;
   file_ptr position;
   Elf_External_Note *e_note;
-  typedef void (*sum_fn) (const void *, size_t, void *);
 
   style = t->o->build_id.style;
   asec = t->o->build_id.sec;
@@ -986,55 +951,7 @@ write_build_id (bfd *abfd)
   bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
   memcpy (e_note->name, "GNU", sizeof "GNU");
 
-  if (strcmp (style, "md5") == 0)
-    {
-      struct md5_ctx ctx;
-
-      md5_init_ctx (&ctx);
-      if (!bed->s->checksum_contents (abfd, (sum_fn) &md5_process_bytes, &ctx))
-       return FALSE;
-      md5_finish_ctx (&ctx, id_bits);
-    }
-  else if (strcmp (style, "sha1") == 0)
-    {
-      struct sha1_ctx ctx;
-
-      sha1_init_ctx (&ctx);
-      if (!bed->s->checksum_contents (abfd, (sum_fn) &sha1_process_bytes, &ctx))
-       return FALSE;
-      sha1_finish_ctx (&ctx, id_bits);
-    }
-  else if (strcmp (style, "uuid") == 0)
-    {
-      int n;
-      int fd = open ("/dev/urandom", O_RDONLY);
-      if (fd < 0)
-       return FALSE;
-      n = read (fd, id_bits, size);
-      close (fd);
-      if (n < (int) size)
-       return FALSE;
-    }
-  else if (strncmp (style, "0x", 2) == 0)
-    {
-      /* ID is in string form (hex).  Convert to bits.  */
-      const char *id = style + 2;
-      size_t n = 0;
-      do
-       {
-         if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
-           {
-             id_bits[n] = read_hex (*id++) << 4;
-             id_bits[n++] |= read_hex (*id++);
-           }
-         else if (*id == '-' || *id == ':')
-           ++id;
-         else
-           abort ();           /* Should have been validated earlier.  */
-       } while (*id != '\0');
-    }
-  else
-    abort ();                  /* Should have been validated earlier.  */
+  generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
 
   position = i_shdr->sh_offset + asec->output_offset;
   size = asec->size;
@@ -1097,8 +1014,9 @@ gld${EMULATION_NAME}_after_open (void)
 
       /* Find an ELF input.  */
       for (abfd = link_info.input_bfds;
-          abfd != (bfd *) NULL; abfd = abfd->link_next)
-       if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+          abfd != (bfd *) NULL; abfd = abfd->link.next)
+       if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+           && bfd_count_sections (abfd) != 0)
          break;
 
       /* PR 10555: If there are no ELF input files do not try to
@@ -1134,8 +1052,10 @@ gld${EMULATION_NAME}_after_open (void)
       bfd_boolean warn_eh_frame = FALSE;
       asection *s;
 
-      for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
+      for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
        {
+         if (bfd_count_sections (abfd) == 0)
+           continue;
          if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
            elfbfd = abfd;
          if (!warn_eh_frame)
@@ -1542,7 +1462,7 @@ gld${EMULATION_NAME}_before_allocation (void)
   if (rpath == NULL)
     rpath = (const char *) getenv ("LD_RUN_PATH");
 
-  for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
+  for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
     if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
       {
        const char *audit_libs = elf_dt_audit (abfd);
@@ -2025,9 +1945,12 @@ fragment <<EOF
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
-  bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
-                                                 &link_info);
-  gld${EMULATION_NAME}_map_segments (need_layout);
+  int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+
+  if (need_layout < 0)
+    einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+  else
+    gld${EMULATION_NAME}_map_segments (need_layout);
 }
 EOF
 fi
@@ -2357,6 +2280,14 @@ fragment <<EOF
          link_info.execstack = FALSE;
        }
 EOF
+
+if test x"$BNDPLT" = xyes; then
+fragment <<EOF
+      else if (strcmp (optarg, "bndplt") == 0)
+       link_info.bndplt = TRUE;
+EOF
+fi
+
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 fragment <<EOF
       else if (strcmp (optarg, "global") == 0)
@@ -2536,6 +2467,13 @@ fragment <<EOF
 EOF
 fi
 
+if test x"$BNDPLT" = xyes; then
+fragment <<EOF
+  fprintf (file, _("\
+  -z bndplt                   Always generate BND prefix in PLT entries\n"));
+EOF
+fi
+
 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
 fragment <<EOF
  $PARSE_AND_LIST_OPTIONS
@@ -2581,6 +2519,7 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
   ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
   ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
-  ${LDEMUL_NEW_VERS_PATTERN-NULL}
+  ${LDEMUL_NEW_VERS_PATTERN-NULL},
+  ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}
 };
 EOF
This page took 0.032647 seconds and 4 git commands to generate.