mirror of
https://github.com/rui314/mold.git
synced 2024-11-15 14:36:25 +03:00
Emit UUIDv4 if --build-id=uuid is specified
This commit is contained in:
parent
b1ca02b276
commit
34462cf473
@ -1548,6 +1548,22 @@ static void compute_sha256(Context<E> &ctx, i64 offset) {
|
||||
munmap(buf, std::min(bufsize, shard_size));
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
static std::vector<u8> get_uuid_v4(Context<E> &ctx) {
|
||||
std::vector<u8> buf(16);
|
||||
if (!RAND_bytes(buf.data(), buf.size()))
|
||||
Fatal(ctx) << "RAND_bytes failed";
|
||||
|
||||
// Indicate that this is UUIDv4.
|
||||
buf[6] &= 0b00001111;
|
||||
buf[6] |= 0b01000000;
|
||||
|
||||
// Indicates that this is an RFC4122 variant.
|
||||
buf[8] &= 0b00111111;
|
||||
buf[8] |= 0b10000000;
|
||||
return buf;
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void BuildIdSection<E>::write_buildid(Context<E> &ctx, i64 filesize) {
|
||||
switch (ctx.arg.build_id.kind) {
|
||||
@ -1563,9 +1579,8 @@ void BuildIdSection<E>::write_buildid(Context<E> &ctx, i64 filesize) {
|
||||
compute_sha256(ctx, this->shdr.sh_offset + HEADER_SIZE);
|
||||
return;
|
||||
case BuildId::UUID:
|
||||
if (!RAND_bytes(ctx.buf + this->shdr.sh_offset + HEADER_SIZE,
|
||||
ctx.arg.build_id.size(ctx)))
|
||||
Fatal(ctx) << "RAND_bytes failed";
|
||||
write_vector(ctx.buf + this->shdr.sh_offset + HEADER_SIZE,
|
||||
get_uuid_v4(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@ clang -o $t/exe $t/a.c -fuse-ld=`pwd`/../mold -Wl,-build-id
|
||||
readelf -n $t/exe | grep -qv 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
|
||||
|
||||
clang -o $t/exe $t/a.c -fuse-ld=`pwd`/../mold -Wl,-build-id=uuid
|
||||
readelf -n $t/exe | grep -q 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
|
||||
readelf -nW $t/exe |
|
||||
grep -Pq 'GNU.*0x00000010.*NT_GNU_BUILD_ID.*Build ID: ............4...[89abcdef]'
|
||||
|
||||
clang -o $t/exe $t/a.c -fuse-ld=`pwd`/../mold -Wl,-build-id=md5
|
||||
readelf -n $t/exe | grep -q 'GNU.*0x00000010.*NT_GNU_BUILD_ID'
|
||||
|
Loading…
Reference in New Issue
Block a user