[PATCH] D40623: Correctly set reserved bits for UUID version 4.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 15:01:50 PST 2017


How did you find this?  Was it causing a symptom of something breaking?

On Wed, Nov 29, 2017 at 2:54 PM Rui Ueyama via Phabricator <
reviews at reviews.llvm.org> wrote:

> ruiu created this revision.
> Herald added subscribers: hiraditya, emaste.
>
> Correctly set reserved bits for UUID version 4.
>
>
> https://reviews.llvm.org/D40623
>
> Files:
>   lld/ELF/SyntheticSections.cpp
>   llvm/include/llvm/Support/RandomNumberGenerator.h
>   llvm/lib/Support/RandomNumberGenerator.cpp
>
>
> Index: llvm/lib/Support/RandomNumberGenerator.cpp
> ===================================================================
> --- llvm/lib/Support/RandomNumberGenerator.cpp
> +++ llvm/lib/Support/RandomNumberGenerator.cpp
> @@ -89,3 +89,15 @@
>    return std::error_code(errno, std::system_category());
>  #endif
>  }
> +
> +// UUID v4 is a 122-bit random number in the form of
> +// RRRRRRRR-RRRR-4RRR-xRRR-RRRRRRRRRRRR, where R is a random byte and
> +// x's most siginificant two bits are 0b10.
> +std::error_code llvm::getUuidV4(void *Buffer) {
> +  if (auto EC = getRandomBytes(Buffer, 16))
> +    return EC;
> +  char *Buf = (char *)Buffer;
> +  Buf[7] = 0x40 | (Buf[7] & 0xf);
> +  Buf[9] = 0x80 | (Buf[9] & 0x3f);
> +  return std::error_code();
> +}
> Index: llvm/include/llvm/Support/RandomNumberGenerator.h
> ===================================================================
> --- llvm/include/llvm/Support/RandomNumberGenerator.h
> +++ llvm/include/llvm/Support/RandomNumberGenerator.h
> @@ -65,6 +65,9 @@
>
>  // Get random vector of specified size
>  std::error_code getRandomBytes(void *Buffer, size_t Size);
> +
> +// Get UUID v4.
> +std::error_code getUuidV4(void *Buffer);
>  }
>
>  #endif
> Index: lld/ELF/SyntheticSections.cpp
> ===================================================================
> --- lld/ELF/SyntheticSections.cpp
> +++ lld/ELF/SyntheticSections.cpp
> @@ -368,7 +368,7 @@
>      });
>      break;
>    case BuildIdKind::Uuid:
> -    if (auto EC = getRandomBytes(HashBuf, HashSize))
> +    if (auto EC = getUuidV4(HashBuf))
>        error("entropy source failure: " + EC.message());
>      break;
>    case BuildIdKind::Hexstring:
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171129/ed1953fe/attachment.html>


More information about the llvm-commits mailing list