diff --git a/changelog/dmd.emulate_getrandom.dd b/changelog/dmd.emulate_getrandom.dd new file mode 100644 index 000000000000..453662ced38f --- /dev/null +++ b/changelog/dmd.emulate_getrandom.dd @@ -0,0 +1,19 @@ +`getrandom()` backwards compatibility shim + +To restore compatibility with older Linux platforms where `getrandom()` is +unavailable either due to an outdated kernel or a legacy C library, Phobos now +ships with a shim that emulates a limited subset of `getrandom()` by reading +random bytes from `/dev/urandom`. + +To enable the shim, build DMD and Phobos with the environment variable +`LINUX_LEGACY_EMULATE_GETRANDOM` set to `1`. + +``` +cd phobos +LINUX_LEGACY_EMULATE_GETRANDOM=1 make +``` + +While this is actually Phobos feature, proper enablement requires compiler +support. This has been implemented by appending the version flag to the default +compiler configuration found in `dmd.conf`. Hence the DMD build script has been +made aware of this new option as well. diff --git a/compiler/src/build.d b/compiler/src/build.d index e0169d6ea4cd..59a0da310d46 100755 --- a/compiler/src/build.d +++ b/compiler/src/build.d @@ -305,19 +305,24 @@ DFLAGS=%DFLAGS% -L/OPT:NOICF { enum confFile = "dmd.conf"; enum conf = `[Environment32] -DFLAGS=-I%@P%/../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/32{exportDynamic} -fPIC +DFLAGS=-I%@P%/../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/32{exportDynamic}{extraVersions} -fPIC [Environment64] -DFLAGS=-I%@P%/../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/64{exportDynamic} -fPIC +DFLAGS=-I%@P%/../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/64{exportDynamic}{extraVersions} -fPIC `; } + const extraVersions = (env.getNumberedBool("LINUX_LEGACY_EMULATE_GETRANDOM")) + ? " -version=linux_legacy_emulate_getrandom" + : ""; + builder .name("dmdconf") .target(env["G"].buildPath(confFile)) .msg("(TX) DMD_CONF") .commandFunction(() { const expConf = conf + .replace("{extraVersions}", extraVersions) .replace("{exportDynamic}", exportDynamic) .replace("{BUILD}", env["BUILD"]) .replace("{OS}", env["OS"]);