Skip to content

Remove remaining uses of setErrNo and deprecate SUPPORT_ERRNO setting #21074

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
Jan 17, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 12, 2024

Aside from the setErrNo library function SUPPORT_ERRNO also controlled the building the malloc and sbrk. However, just setting errno to ENOMEM didn't seem to have any effect on the code size for any of our micro benchmarks. This may be because LTO can completely eliminate the write to errno when there are no readers, or it could be that errno usage exists in in even the smallest program already so removing from malloc alone makes no difference.

@sbc100 sbc100 requested review from kripken, dschuff and juj January 12, 2024 19:35
@sbc100 sbc100 force-pushed the errno_support branch 2 times, most recently from 2d81085 to e7f5566 Compare January 12, 2024 22:34
@dschuff
Copy link
Member

dschuff commented Jan 12, 2024

so IIUC what's really happening here is that C runtime functions are all still setting errno where appropriate but errno is basically not exposed to JS and there are no JS functions that need to set it, and therefore we don't need to have the function for setting it from JS. So the setting was always a bit of a misnomer?
If that's right, the documentation should probably mention that (in case users actually use errno in their C code, they'll understand that they won't be broken).

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 12, 2024

so IIUC what's really happening here is that C runtime functions are all still setting errno where appropriate but errno is basically not exposed to JS and there are no JS functions that need to set it, and therefore we don't need to have the function for setting it from JS. So the setting was always a bit of a misnomer? If that's right, the documentation should probably mention that (in case users actually use errno in their C code, they'll understand that they won't be broken).

Yes, IIUC traditionally C function always set errno internally and ERRNO_SUPPORT was only about exposing errno setting to JS code.

The ERRNO_SUPPORT setting only started to effect native in d98572b, but it was/is strictly limited to malloc and sbrk. Errno support for all other C library function is (and always way) unconditional.

As far as I can tell there is no code size regression from making malloc/sbrk just like the rest of libc.

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 12, 2024

I think the reason we don't see any code size regressions from having malloc/sbrk reference errno is that its almost impossible to build a native program without any errno references. Even strdup references errno.

The cost of supporting errno on the native side is tiny and likely very hard to avoid.

@sbc100 sbc100 force-pushed the errno_support branch 2 times, most recently from a7cc04b to 97e3b0d Compare January 12, 2024 23:54
@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 13, 2024

I'll wait for @kripken and @juj to weight in in case there is some code size benefit that I'm not seen (and we are not testing for)

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 % comments/questions

ChangeLog.md Outdated
@@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

3.1.52 (in development)
-----------------------
- The `ERRNO_SUPPORT` setting is now deprecated since the `setErrNo` function
that it controls is no longer used by emscripten. Use of `errno` from in C
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
that it controls is no longer used by emscripten. Use of `errno` from in C
that it controls is no longer used by emscripten. Use of `errno` from C

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.

Makes sense, thanks for checking that.

Seems reasonable given emmalloc is our compact allocator, so as long as we don't regress that sgtm.

@sbc100 sbc100 force-pushed the errno_support branch 2 times, most recently from e1f3e30 to 3a0a73d Compare January 17, 2024 18:43
@sbc100 sbc100 changed the title Remove remaining uses of setErrNo and deprecate ERRNO_SUPPORT setting Remove remaining uses of setErrNo and deprecate SUPPORT_ERRNO setting Jan 17, 2024
Aside from the `setErrNo` library function `SUPPORT_ERRNO` also
controlled the building the malloc and sbrk.  However, just setting
errno to ENOMEM didn't seem to have any effect on the code size for any
of our micro benchmarks.  This may be because LTO can completely
eliminate the write to `errno` when there are no readers, or it could be
that errno usage exists in in even the smallest program already so
removing from malloc alone makes no difference.
@sbc100 sbc100 merged commit 946c850 into emscripten-core:main Jan 17, 2024
@sbc100 sbc100 deleted the errno_support branch January 17, 2024 23: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.

3 participants