Skip to content

Implement ppoll and pselect in terms of poll and select#26482

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:ppoll_pselect
Mar 20, 2026
Merged

Implement ppoll and pselect in terms of poll and select#26482
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:ppoll_pselect

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 18, 2026

Because we don't support true async signals this is safe to do in userspace.

Followup to #26084

@sbc100 sbc100 force-pushed the ppoll_pselect branch 2 times, most recently from bdead93 to 6ece7ce Compare March 18, 2026 16:22
@sbc100 sbc100 enabled auto-merge (squash) March 18, 2026 17:24
Because we don't support true async signals this is safe to do in
userspace.

Followup to emscripten-core#26084
Copy link
Collaborator

@kleisauke kleisauke left a comment

Choose a reason for hiding this comment

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

LGTM % a question regarding the code size test.

"$__syscall_ppoll",
"$__syscall_prlimit64",
"$__syscall_pselect6",
"$__syscall_recvmmsg",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you perhaps know why this symbol (and $__syscall_shutdown below) is included now? I noticed a similar thing in PR #19559, but haven't investigated this further.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm.. I actually have no idea. Asking gemini if it can figure that out now..

Copy link
Collaborator Author

@sbc100 sbc100 Mar 20, 2026

Choose a reason for hiding this comment

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

Wow, AI figured it out pretty quick:

"""
The investigation reveals that the appearance of __syscall_recvmmsg and __syscall_shutdown in the funcs list of test_codesize_hello_dylink_all.json is a side effect of Identical Code Folding (ICF) in the linker, combined with the removal of ppoll and pselect6 from the UNIMPLEMENTED syscall stubs.
"""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Key Findings:

  1. ICF Merging: In system/lib/libc/emscripten_syscall_stubs.c, many syscalls are implemented using the UNIMPLEMENTED macro. When NDEBUG is
    defined (as it is in this test), these functions all have an identical body (return -ENOSYS;). The linker (Wasm-LD) merges functions with
    identical bodies and the same signatures into a single WASM function to save space.
  2. Canonical Names: When multiple functions are merged, the linker chooses one name to be the internal name of the function in the WASM.
    This is usually the alphabetically first name among the merged symbols.
  3. The Change:
    • Group 1 (5 arguments): Previously contained __syscall_ppoll, __syscall_recvmmsg, and __syscall_sendmmsg. Since ppoll was
      alphabetically first, it was chosen as the canonical name ($__syscall_ppoll).
    • Group 2 (6 arguments): Previously contained __syscall_pselect6, __syscall_shutdown, and __syscall_socketpair. Since pselect6 was
      alphabetically first, it was chosen as the canonical name ($__syscall_pselect6).
  4. Effect of the Commit: The commit removed ppoll and pselect6 from the UNIMPLEMENTED list in emscripten_syscall_stubs.c (as they now have
    real implementations).
    • In the 5-arg group, __syscall_recvmmsg is now the alphabetically first member, so it became the new canonical name.
    • In the 6-arg group, __syscall_shutdown is now the alphabetically first member, so it became the new canonical name. Key Findings:
  5. ICF Merging: In system/lib/libc/emscripten_syscall_stubs.c, many syscalls are implemented using the UNIMPLEMENTED macro. When NDEBUG is
    defined (as it is in this test), these functions all have an identical body (return -ENOSYS;). The linker (Wasm-LD) merges functions with
    identical bodies and the same signatures into a single WASM function to save space.
  6. Canonical Names: When multiple functions are merged, the linker chooses one name to be the internal name of the function in the WASM.
    This is usually the alphabetically first name among the merged symbols.
  7. The Change:
    • Group 1 (5 arguments): Previously contained __syscall_ppoll, __syscall_recvmmsg, and __syscall_sendmmsg. Since ppoll was
      alphabetically first, it was chosen as the canonical name ($__syscall_ppoll).
    • Group 2 (6 arguments): Previously contained __syscall_pselect6, __syscall_shutdown, and __syscall_socketpair. Since pselect6 was
      alphabetically first, it was chosen as the canonical name ($__syscall_pselect6).
  8. Effect of the Commit: The commit removed ppoll and pselect6 from the UNIMPLEMENTED list in emscripten_syscall_stubs.c (as they now have
    real implementations).
    • In the 5-arg group, __syscall_recvmmsg is now the alphabetically first member, so it became the new canonical name.
    • In the 6-arg group, __syscall_shutdown is now the alphabetically first member, so it became the new canonical name.
  9. Validation: The total number of functions in the funcs list remained exactly the same (1689 entries). Only the names changed because the
    previous "representatives" of these merged groups were removed from the codebase.

The symbols were already present as exports before the change; they only "appeared" as new internal function names because they were promoted
to being the representatives for their respective merged groups.

  1. Validation: The total number of functions in the funcs list remained exactly the same (1689 entries). Only the names changed because the
    previous "representatives" of these merged groups were removed from the codebase.

The symbols were already present as exports before the change; they only "appeared" as new internal function names because they were promoted
to being the representatives for their respective merged groups.

@sbc100 sbc100 disabled auto-merge March 20, 2026 16:29
@sbc100 sbc100 merged commit 43be3a1 into emscripten-core:main Mar 20, 2026
38 checks passed
@sbc100 sbc100 deleted the ppoll_pselect branch March 20, 2026 16:29
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