From ffe33e8a007dad1489d0c070adda48c50af59cd8 Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Sun, 6 Apr 2025 05:09:32 +0200 Subject: [PATCH 1/3] Implement `version (linux_legacy_emulate_getrandom)` --- compiler/src/build.d | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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"]); From 18e2340e181d6f78efd794ef9e63f7c2e5674000 Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Sun, 6 Apr 2025 05:17:56 +0200 Subject: [PATCH 2/3] Add changelog entry --- changelog/dmd.emulate_getrandom.dd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 changelog/dmd.emulate_getrandom.dd diff --git a/changelog/dmd.emulate_getrandom.dd b/changelog/dmd.emulate_getrandom.dd new file mode 100644 index 000000000000..d112185dd3cf --- /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. From 5cf44a36ee8eb4929ae71e98c8530c03007241bd Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Sun, 6 Apr 2025 05:28:55 +0200 Subject: [PATCH 3/3] Fix typo --- changelog/dmd.emulate_getrandom.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/dmd.emulate_getrandom.dd b/changelog/dmd.emulate_getrandom.dd index d112185dd3cf..453662ced38f 100644 --- a/changelog/dmd.emulate_getrandom.dd +++ b/changelog/dmd.emulate_getrandom.dd @@ -15,5 +15,5 @@ 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 +compiler configuration found in `dmd.conf`. Hence the DMD build script has been made aware of this new option as well.