Skip to content

Define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS in compiler-rt #15411

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

Merged
merged 1 commit into from
Mar 12, 2022

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 2, 2021

In defining this I noticed that musl will also choose to use
these canonical syscalls when the alternative is not defined.

This allows us to remove a bunch of duplicate syscalls and
their implementation.

@sbc100 sbc100 requested review from kripken and dschuff November 2, 2021 18:44
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch from 4acbd74 to cce72bf Compare November 2, 2021 18:45
Base automatically changed from remove_unused_syscalls to main November 2, 2021 18:53
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch 2 times, most recently from 77f3ebf to 1f6d26a Compare November 2, 2021 19:38
@sbc100 sbc100 requested a review from ethanalee November 2, 2021 19:38
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch from 1f6d26a to c4ad261 Compare November 2, 2021 19:42
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Can you elaborate on the benefits here more? I'm unclear on the purpose of this.

@@ -1054,7 +1054,7 @@ static long open(const char* pathname, int flags, int mode) {
return (long)desc;
}

long __syscall_open(long path, long flags, ...)
Copy link
Member

@kripken kripken Nov 2, 2021

Choose a reason for hiding this comment

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

These changes to use at() variants increase code size slightly. Very little, but still, is it worth the benefits here?

Copy link
Collaborator Author

@sbc100 sbc100 Nov 2, 2021

Choose a reason for hiding this comment

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

Yes, indeed. I think its worth it for the reduced complexity and maintenance.

It also a code size win for programs that call both flavors of these functions and fewer JS imports.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it reduces complexity somewhat. I also agree it's a code size win for programs that use both. But I worry that maybe the common case is a program that uses just one, and it used to use the simple one, which is the case we'd be regressing. That might be worth measuring at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I don't think it will be a regression even for simple such programs, at least no more than the single line which is the call to SYSCALLS.calculateAt. SYSCALLS.calculateAt is part of the SYSCALLS objects which IIRC clusure is not able to remove anyway.. so I think the calculateAt method gets included in any case. But I can/will measure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Given that we just landed af4a408 is seems a reasonable extension to land this too.

@sbc100 sbc100 force-pushed the use_canonical_syscalls branch 2 times, most recently from c2dbfa9 to fef8f84 Compare November 2, 2021 20:15
@sbc100 sbc100 requested a review from kripken November 2, 2021 20:17
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Sounds good. Basically lgtm % comments and also assuming you don't measure more than a few bytes of change in size in simple programs using files (and not using files, just to be sure, but there should be 0 change there).

@@ -14,7 +14,7 @@ int dup2(int old, int new)
#else
if (old==new) {
#ifdef __EMSCRIPTEN__
r = __wasi_fd_is_valid(old) ? 0 : -1;
r = __wasi_fd_is_valid(old) ? 0 : -EBADF;
Copy link
Member

Choose a reason for hiding this comment

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

Is this a separate bugfix from this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes indeed, let me see if I can split that out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually this is bugfix, but it doesn't make sense to land separately really since this is basically in dead code. Prior to this PR SYS_dup2 is defined so this entire block of code is ifdef'd out. By removing SYS_dup2 in this PR we are forced to fix this existing bug.

I guess I could split out the removal of dup2.... that could work.

sbc100 added a commit that referenced this pull request Nov 3, 2021
The musl implemenation of dup2 works fine without this syscall as it can
be implemented in terms of dup3.

As part of this change I was forced to implement __wasi_fd_fdstat_get
for wasmfs since dup2 not depends on this wasi syscall.

Split out from #15411
sbc100 added a commit that referenced this pull request Nov 3, 2021
The musl implemenation of dup2 works fine without this syscall as it can
be implemented in terms of dup3.

As part of this change I was forced to implement __wasi_fd_fdstat_get
for wasmfs since dup2 not depends on this wasi syscall.

Split out from #15411
sbc100 added a commit that referenced this pull request Nov 3, 2021
The musl implemenation of dup2 works fine without this syscall as it can
be implemented in terms of dup3.

As part of this change I was forced to implement __wasi_fd_fdstat_get
for wasmfs since dup2 not depends on this wasi syscall.

Split out from #15411
sbc100 added a commit that referenced this pull request Nov 3, 2021
The musl implemenation of dup2 works fine without this syscall as it can
be implemented in terms of dup3.

As part of this change I was forced to implement __wasi_fd_fdstat_get
for wasmfs since dup2 not depends on this wasi syscall.

Split out from #15411
sbc100 added a commit that referenced this pull request Nov 3, 2021
The musl implemenation of dup2 works fine without this syscall as it can
be implemented in terms of dup3.

As part of this change I was forced to implement __wasi_fd_fdstat_get
for wasmfs since dup2 not depends on this wasi syscall.

Split out from #15411
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch from fef8f84 to 5fa5a32 Compare November 4, 2021 00:21
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch from 5fa5a32 to 617b4d8 Compare February 19, 2022 00:07
@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 19, 2022

No change in side for non-file using code (I ran ./tests/runner other.*code_size* other.*metadce* --rebase and it registered no changes).

For an example that uses fopen I see 3 bytes increase in wasm size and 18 byte increase in (non-closure) output (out of 65041 bytes!).

$ /bin/ls -la after.* before.*
-rw-r----- 1 sbc primarygroup 65041 Feb 18 16:25 before.js
-rwxr-x--- 1 sbc primarygroup  8198 Feb 18 16:25 before.wasm
-rw-r----- 1 sbc primarygroup 65058 Feb 18 16:25 after.js
-rwxr-x--- 1 sbc primarygroup  8201 Feb 18 16:25 after.wasm

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm, however, is it possible to delay landing this? The changes to library_syscall.js here will require updates to the external PThreadFS codebase, which is temporary and not heavily tested. I would prefer to wait on landing this until WasmFS replaces PThreadFS to avoid disruption to our partners.

@sbc100
Copy link
Collaborator Author

sbc100 commented Feb 22, 2022

Sure, no hurry.

@sbc100 sbc100 force-pushed the use_canonical_syscalls branch 3 times, most recently from f167bd5 to 4c318cf Compare March 4, 2022 20:28
In defining this I noticed that musl will also choose to use
these canonical syscalls when the alternative is not defined.

This allows us to remove a bunch of duplicate syscalls and
their implementation.
@sbc100 sbc100 force-pushed the use_canonical_syscalls branch from 4c318cf to 25c18cb Compare March 11, 2022 14:57
@sbc100 sbc100 merged commit 1a0b77c into main Mar 12, 2022
@sbc100 sbc100 deleted the use_canonical_syscalls branch March 12, 2022 00:26
sbc100 added a commit that referenced this pull request Mar 16, 2023
sbc100 added a commit that referenced this pull request Mar 17, 2023
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
impact-maker pushed a commit to impact-maker/emscripten that referenced this pull request Mar 17, 2023
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