Skip to content

Avoid varargs in socket syscall layer. NFC#27153

Merged
sbc100 merged 2 commits into
emscripten-core:mainfrom
kleisauke:avoid-varargs-socket-syscall
Jun 19, 2026
Merged

Avoid varargs in socket syscall layer. NFC#27153
sbc100 merged 2 commits into
emscripten-core:mainfrom
kleisauke:avoid-varargs-socket-syscall

Conversation

@kleisauke

Copy link
Copy Markdown
Collaborator

Passing a small number of integer arguments may be cheaper than
marshalling varargs on wasm64.

Split out from #19559.

Passing a small number of integer arguments may be cheaper than
marshalling varargs on wasm64.
This is an automatic change generated by tools/maint/rebaseline_tests.py.

The following (1) test expectation files were updated by
running the tests with `--rebaseline`:

```
codesize/test_codesize_hello_dylink_all.json: 855843 => 855818 [-25 bytes / -0.00%]

Average change: -0.00% (-0.00% - -0.00%)
```
@sbc100

sbc100 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

It looks like we still have explicit usage of varargs in 4 syscalls: ioctl fcntl64 fstatfs64 openat.

Presumably removing that is more complex? But if we did then we could remove the whole syscallGetVararg thing?

Comment thread src/lib/libsyscall.js
return 0;
},
__syscall_getpeername__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
__syscall_getpeername: (fd, addr, addrlen, d1, d2, d3) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The man page calls this addrlen. Is there some reason to change it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was trying to sync these syscalls argument names with their corresponding callers:

int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
{
return socketcall(getpeername, fd, addr, len, 0, 0, 0);
}

"$__syscall_munmap",
"$__syscall_prlimit64",
"$__syscall_recvmmsg",
"$__syscall_sendmmsg",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder why this change effects this list?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Probably due to identical code folding (ICF). At least it saves 25 bytes. :)

"$__syscall_munmap",
"$__syscall_prlimit64",
"$__syscall_recvmmsg",
"$__syscall_sendmmsg",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh I think maybe some optimization phase was doing duplicate function merging before on this stub, but its no longer identical maybe.

@sbc100 sbc100 merged commit 8484a7b into emscripten-core:main Jun 19, 2026
39 checks passed
@kleisauke

Copy link
Copy Markdown
Collaborator Author

It looks like we still have explicit usage of varargs in 4 syscalls: ioctl fcntl64 fstatfs64 openat.

Presumably removing that is more complex? But if we did then we could remove the whole syscallGetVararg thing?

Indeed, it's probably too complex. And unlike the socket syscalls, these varargs are actually used and cannot be turned into constants (afaik).

@kleisauke kleisauke deleted the avoid-varargs-socket-syscall branch June 19, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants