Skip to content

Comments

getrandom() backwards compatibility shim#10741

Merged
LightBender merged 2 commits intodlang:stablefrom
0xEAB:emulate-getrandom
Apr 10, 2025
Merged

getrandom() backwards compatibility shim#10741
LightBender merged 2 commits intodlang:stablefrom
0xEAB:emulate-getrandom

Conversation

@0xEAB
Copy link
Member

@0xEAB 0xEAB commented Apr 6, 2025

People have been unhappy about the new getrandom() dependency.

Instead of reverting the whole thing, we could supply a compatibility mode to users stuck with legacy systems.

@0xEAB 0xEAB added the OS:Linux Issues specific to Linux label Apr 6, 2025
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @0xEAB!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + phobos#10741"

@0xEAB
Copy link
Member Author

0xEAB commented Apr 6, 2025

Changelog entry?
See https://github.com/dlang/dmd/pull/21158/files.


`getrandom()` was added to the GNU C Library in v2.25.
+/
pragma(msg, "`getrandom()` emulation for legacy Linux targets is enabled.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is obviously a bit spammy. Maybe we should comment it out?

@0xEAB 0xEAB force-pushed the emulate-getrandom branch from 9fddd63 to 4a5098f Compare April 6, 2025 04:08
@LightBender LightBender merged commit 40ffbb3 into dlang:stable Apr 10, 2025
16 of 17 checks passed
version (linux)
{
// `getrandom()` was introduced in Linux 3.17.
version (linux_legacy_emulate_getrandom)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import gcc.config;
static if (Have_Getrandom)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibuclaw Is this something you’d like me to incorporate?
Or was it more like a note to yourself?

Copy link
Member

@ibuclaw ibuclaw Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been nice if this was an enum, as that can survive in the installed sources after the library has been built, and there's already other tests whose results get written to this module at configure time.

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libphobos/libdruntime/gcc/config.d.in;h=e5fcd5073a96a2ffdee25c33348fc73bdddb6bbb;hb=HEAD

version (GNU)
{
    import gcc.config;
}
else version (linux_legacy_emulate_getrandom)
{
    enum Have_Getrandom = false;
}
else
{
    enum Have_Getrandom = true;
}

Have added this, though minor annoyance that it's its own thing rather than using the existing "features" module.

https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=libphobos/m4/druntime/os.m4;h=ef8ca434407149c176e5d93ab4012d53511048e3;hp=15cde3b04b8d47a66f83fa6ae56057359b66adac;hb=b905ce8caf04253e02e153d60d6ea8f99d300af6;hpb=882d3b319dbf50ae64080731a1398031c100b7c7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, this is a function, and not a template. Otherwise this shim would be a non-starter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything urgent here?
Otherwise I’d rather wait to see this getting hopefully replaced by something like #10748 in the near future anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OS:Linux Issues specific to Linux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants