Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SO_REUSEPORT is not defined for some linux targets #20688

Closed
pinskia opened this issue Jan 12, 2025 · 14 comments
Closed

SO_REUSEPORT is not defined for some linux targets #20688

pinskia opened this issue Jan 12, 2025 · 14 comments
Labels
Druntime Specific to druntime Review:Has PR This Issue has a PR

Comments

@pinskia
Copy link

pinskia commented Jan 12, 2025

Forwarded from https://gcc.gnu.org/PR118438.

The following targets seems to be missing a definition of SO_REUSEPORT from core/sys/posix/sys/socket.d :
s390*-linux-gnu loongarch64-linux-gnu hppa*-linux-gnu mips*-linux-gnu sparc*-*-linux-gnu

This definition is now needed to compile libphobos/src/std/socket.d too.

@pinskia
Copy link
Author

pinskia commented Jan 12, 2025

Note libphobos change which introduced this depedency is dlang/phobos@9aa794c

pinskia referenced this issue in dlang/phobos Jan 12, 2025
The issue also mentions the Druntime bindings, which have been added a few years ago,
however this was missing from std.socket. This implementation provides SO_REUSEPORT on
Windows as well, despite it being equivalent to SO_REUSEADDR, to simplify client code.

Co-authored-by: Elias Batek <[email protected]>
@thewilsonator thewilsonator added the Druntime Specific to druntime label Jan 12, 2025
@thewilsonator
Copy link
Contributor

There are existing version branches for HPPA, LoongArch64, MIPS and SPARC in https://github.com/dlang/dmd/blob/caf0e12e0c220be042b73d12a8843d2d5e66f661/druntime/src/core/sys/posix/sys/socket.d that do indeed lack a definition of SO_REUSEPORT.

I'm guessing that s390 is SystemZ and also has a branch that lacks that definition.

If you could point me to where those values are defined in the system's headers I can put a PR together, or if you would like to do that yourself, a PR to the stable branch of this repository would be appreciated.

@thewilsonator
Copy link
Contributor

also cc @ibuclaw for forwarding this to GDC/GCC

@pinskia
Copy link
Author

pinskia commented Jan 12, 2025

also cc @ibuclaw for forwarding this to GDC/GCC

This bug report was originally forwarded from GCC/GDC in the first place :)

@ibuclaw
Copy link
Member

ibuclaw commented Jan 13, 2025

If you could point me to where those values are defined in the system's headers I can put a PR together, or if you would like to do that yourself, a PR to the stable branch of this repository would be appreciated.

You'd have to look in the Linux source code.

https://github.com/search?q=repo%3Atorvalds%2Flinux+SO_REUSEPORT+language%3AC+path%3A**%2Fsocket.h

@thewilsonator
Copy link
Contributor

This bug report was originally forwarded from GCC/GDC in the first place :)

Bad wording on my part, I meant the resultant PR to fix the issue.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 13, 2025

If you could point me to where those values are defined in the system's headers I can put a PR together, or if you would like to do that yourself, a PR to the stable branch of this repository would be appreciated.

You'd have to look in the Linux source code.

https://github.com/search?q=repo%3Atorvalds%2Flinux+SO_REUSEPORT+language%3AC+path%3A**%2Fsocket.h

tl;dr

Alpha => 0x0200 (though, no D compiler support code for that target)
HPPA_Any => 0x200
MIPS_Any => 0x200
SPARC_Any => 0x200
Everything else => 15

There are existing version branches for HPPA, LoongArch64, MIPS and SPARC in https://github.com/dlang/dmd/blob/caf0e12e0c220be042b73d12a8843d2d5e66f661/druntime/src/core/sys/posix/sys/socket.d that do indeed lack a definition of SO_REUSEPORT.

It's also missing at the top:

version (HPPA64)  version = HPPA_Any;

@ibuclaw
Copy link
Member

ibuclaw commented Jan 13, 2025

a PR to the stable branch of this repository would be appreciated.

FWIW, this only affects master.

@thewilsonator
Copy link
Contributor

SPARC_Any => 0x200

It seems that all of the current SPARC ones are wrong. Druntime seems to assume that SPARC uses[uapi/asm-generic/socket.h](https://github.com/torvalds/linux/blob/5bc55a333a2f7316b58edc7573e8e893f7acb532/include/uapi/asm-generic/socket.h#L27) (with SO_REUSEPORT = 15;) Could you please verify that.

thewilsonator added a commit to thewilsonator/dmd that referenced this issue Jan 13, 2025
@thewilsonator thewilsonator added the Review:Has PR This Issue has a PR label Jan 13, 2025
@thewilsonator
Copy link
Contributor

#20689

@ibuclaw
Copy link
Member

ibuclaw commented Jan 13, 2025

SPARC_Any => 0x200

It seems that all of the current SPARC ones are wrong. Druntime seems to assume that SPARC uses[uapi/asm-generic/socket.h](https://github.com/torvalds/linux/blob/5bc55a333a2f7316b58edc7573e8e893f7acb532/include/uapi/asm-generic/socket.h#L27) (with SO_REUSEPORT = 15;) Could you please verify that.

Maybe you're mixing up SPARC and PPC?

@thewilsonator
Copy link
Contributor

Yes and no. I think I put it in the wrong place in the PR but
arch/sparc/include/uapi/asm/socket.h

#define SO_PEERCRED	0x0040
#define SO_LINGER	0x0080
#define SO_OOBINLINE	0x0100
#define SO_REUSEPORT	0x0200
#define SO_BSDCOMPAT    0x0400
#define SO_RCVLOWAT     0x0800
#define SO_SNDLOWAT     0x1000

https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/posix/sys/socket.d#L463-L496

@ibuclaw
Copy link
Member

ibuclaw commented Jan 13, 2025

Right, those are indeed all wrong. I was tempted to know who wrote this, but of course it's me. :-)

dlang/druntime@0e1ee40

@thewilsonator
Copy link
Contributor

Right, those are indeed all wrong.

#20690

I was tempted to know who wrote this, but of course it's me. :-)

Its always the person you suspect most ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Druntime Specific to druntime Review:Has PR This Issue has a PR
Projects
None yet
Development

No branches or pull requests

3 participants