Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions changelog/dmd.emulate_getrandom.dd
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 7 additions & 2 deletions compiler/src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down
Loading