1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-10 10:57:55 +03:00

Remove dependency to OpenSSL's RAND_bytes

This commit is contained in:
Rui Ueyama 2021-09-05 17:02:08 +09:00
parent b4953951f0
commit 76018da068
2 changed files with 18 additions and 4 deletions

View File

@ -22,6 +22,16 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
EOF
LDFLAGS='-fuse-ld=lld -static'
# libstdc++'s `std::__glibcxx_rwlock_rdlock` refers these symbols
# as weak symbols, although they need to be defined. Otherwise,
# the program crashes after juping to address 0.
# So, we force loading symbols as a workaround.
LDFLAGS="$LDFLAGS -Wl,-u,pthread_rwlock_rdlock"
LDFLAGS="$LDFLAGS -Wl,-u,pthread_rwlock_unlock"
LDFLAGS="$LDFLAGS -Wl,-u,pthread_rwlock_wrlock"
docker run -it --rm -v `pwd`:/mold -u $(id -u):$(id -g) \
mold-build-ubuntu20 \
make -C /mold -j$(nproc) EXTRA_LDFLAGS='-fuse-ld=lld -static'
make -C /mold -j$(nproc) EXTRA_LDFLAGS="$LDFLAGS"

View File

@ -1,6 +1,5 @@
#include "mold.h"
#include <openssl/rand.h>
#include <shared_mutex>
#include <sys/mman.h>
#include <tbb/parallel_for_each.h>
@ -1665,8 +1664,13 @@ static void compute_sha256(Context<E> &ctx, i64 offset) {
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";
FILE *fp = fopen("/dev/urandom", "r");
if (!fp)
Fatal(ctx) << "cannot open /dev/urandom: " << strerror(errno);
if (fread(buf.data(), buf.size(), 1, fp) != 1)
Fatal(ctx) << "fread on /dev/urandom: short read";
fclose(fp);
// Indicate that this is UUIDv4.
buf[6] &= 0b00001111;