[PATCH] D113991: Support using sha256 as --build-id kind

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 05:48:22 PST 2021


serge-sans-paille created this revision.
serge-sans-paille added a reviewer: MaskRay.
Herald added subscribers: arichardson, emaste.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Both sha1 and md5 are considered deprecated, it would be great to support a more recent/secure hashing algorithm to compute build id


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113991

Files:
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/SyntheticSections.cpp
  lld/ELF/Writer.cpp


Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -28,6 +28,7 @@
 #include "llvm/Support/Parallel.h"
 #include "llvm/Support/RandomNumberGenerator.h"
 #include "llvm/Support/SHA1.h"
+#include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/xxhash.h"
 #include <climits>
@@ -3036,6 +3037,11 @@
       memcpy(dest, SHA1::hash(arr).data(), hashSize);
     });
     break;
+  case BuildIdKind::Sha256:
+    computeHash(buildId, buf, [&](uint8_t *dest, ArrayRef<uint8_t> arr) {
+      memcpy(dest, SHA256::hash(arr).data(), hashSize);
+    });
+    break;
   case BuildIdKind::Uuid:
     if (auto ec = llvm::getRandomBytes(buildId.data(), hashSize))
       error("entropy source failure: " + ec.message());
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -280,6 +280,8 @@
     return 16;
   case BuildIdKind::Sha1:
     return 20;
+  case BuildIdKind::Sha256:
+    return 32;
   case BuildIdKind::Hexstring:
     return config->buildIdVector.size();
   default:
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -783,6 +783,8 @@
     return {BuildIdKind::Md5, {}};
   if (s == "sha1" || s == "tree")
     return {BuildIdKind::Sha1, {}};
+  if (s == "sha256")
+    return {BuildIdKind::Sha256, {}};
   if (s == "uuid")
     return {BuildIdKind::Uuid, {}};
   if (s.startswith("0x"))
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -43,7 +43,7 @@
 enum class BsymbolicKind { None, NonWeakFunctions, Functions, All };
 
 // For --build-id.
-enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
+enum class BuildIdKind { None, Fast, Md5, Sha1, Sha256, Hexstring, Uuid };
 
 // For --discard-{all,locals,none}.
 enum class DiscardPolicy { Default, All, Locals, None };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113991.387590.patch
Type: text/x-patch
Size: 2116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211116/bad6a7ad/attachment.bin>


More information about the llvm-commits mailing list