This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch 2/2] support --build-id=sha1


This changes the new --build-id switch to handle sha1 as well as md5, and
to default to sha1.  I left this out of the original patch so that it could
be reviewed without worrying about any libiberty issue.

Ok to commit (after 1/2)?


Thanks,
Roland


bfd/
	* elf.c (_bfd_id_note_section_size): Support "sha1" style.
	(_bfd_elf_write_build_id_section): Likewise.

ld/
	* emultempl/elf32.em (DEFAULT_BUILD_ID_STYLE): Change to "sha1".

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.397
diff -B -b -p -u -r1.397 elf.c
--- bfd/elf.c	9 Jul 2007 21:23:43 -0000	1.397
+++ bfd/elf.c	9 Jul 2007 22:52:27 -0000
@@ -44,6 +44,7 @@ SECTION
 #include "libiberty.h"
 #include "safe-ctype.h"
 #include "md5.h"
+#include "sha1.h"
 
 static int elf_sort_sections (const void *, const void *);
 static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
@@ -5088,10 +5089,8 @@ _bfd_id_note_section_size (bfd *abfd, st
 
   if (!strcmp (style, "md5") || !strcmp (style, "uuid"))
     size += 128 / 8;
-#if 0				/* libiberty has md5 but not sha1 */
   else if (!strcmp (style, "sha1"))
     size += 160 / 8;
-#endif
   else if (!strncmp (style, "0x", 2))
     {
       /* ID is in string form (hex).  Convert to bits.  */
@@ -5181,6 +5180,18 @@ _bfd_elf_write_build_id_section (bfd *ab
       else
 	return FALSE;
     }
+  else if (!strcmp (style, "sha1"))
+    {
+      struct sha1_ctx ctx;
+      sha1_init_ctx (&ctx);
+      if (bed->s->checksum_contents (abfd,
+				     (void (*) (const void *, size_t, void *))
+				     &sha1_process_bytes,
+				     &ctx))
+	sha1_finish_ctx (&ctx, id_bits);
+      else
+	return FALSE;
+    }
   else if (!strcmp (style, "uuid"))
     {
       int n;
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.180
diff -B -b -p -u -r1.180 elf32.em
--- ld/emultempl/elf32.em	9 Jul 2007 21:25:34 -0000	1.180
+++ ld/emultempl/elf32.em	9 Jul 2007 22:52:27 -0000
@@ -1839,7 +1839,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
   memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
 }
 
-#define DEFAULT_BUILD_ID_STYLE	"md5"
+#define DEFAULT_BUILD_ID_STYLE	"sha1"
 
 static bfd_boolean
 gld${EMULATION_NAME}_handle_option (int optc)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]