Improve libc presence detection#6170
Merged
arcanis merged 1 commit intoyarnpkg:masterfrom Mar 27, 2024
Merged
Conversation
Member
|
Thanks! |
Contributor
|
I haven't tested all the distributions you listed, but at least on Arch, Going to open a PR soon. |
3 tasks
arcanis
pushed a commit
that referenced
this pull request
Jul 26, 2025
## What's the problem this PR addresses? Two problems: 1. #6170 broke `libc` detection on at least Alpine Linux and Chimera Linux (and probably on all other `musl`-based distributions as well) by looking for the generic string `libc` in `/usr/bin/ldd`. On both Chimera and Alpine, `ldd --version` prints `musl libc` among the output. 2. `getLibc()` was doing unnecessary work on OSes other than Windows, Mac, and Linux (I originally thought it would have been crashing, but that's incorrect). ~~It strongly appears to me that `getLibc()` would throw an error on any OS other than Windows, Mac, and Linux, as the other OSes supported by node have their own libc implementations that are neither `glibc` nor `musl`.~~ ... ## How did you fix it? 1. The strings `GNU libc` and `GNU C Library` are searched for instead of just `libc`. * By default, `ldd` contains the text `GNU libc` in its `--version` output, but that can be easily customized at build time using a build configuration option (see [here](https://github.com/bminor/glibc/blob/632d895f3e5d98162f77b9c3c1da4ec19968b671/elf/ldd.bash.in#L37) and [here](https://github.com/bminor/glibc/blob/632d895f3e5d98162f77b9c3c1da4ec19968b671/INSTALL#L273-L278)). As a fallback, the text `GNU C Library` is found in the header of the `ldd` script, and it will probably remain there as long as that file remains a script (as opposed to a compiled binary). 2. I made `getLibc()` immediately return `null` on all non-Linux platforms (not just Windows and macOS). ... ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
Saadnajmi
pushed a commit
to Saadnajmi/berry
that referenced
this pull request
Jul 26, 2025
## What's the problem this PR addresses? Two problems: 1. yarnpkg#6170 broke `libc` detection on at least Alpine Linux and Chimera Linux (and probably on all other `musl`-based distributions as well) by looking for the generic string `libc` in `/usr/bin/ldd`. On both Chimera and Alpine, `ldd --version` prints `musl libc` among the output. 2. `getLibc()` was doing unnecessary work on OSes other than Windows, Mac, and Linux (I originally thought it would have been crashing, but that's incorrect). ~~It strongly appears to me that `getLibc()` would throw an error on any OS other than Windows, Mac, and Linux, as the other OSes supported by node have their own libc implementations that are neither `glibc` nor `musl`.~~ ... ## How did you fix it? 1. The strings `GNU libc` and `GNU C Library` are searched for instead of just `libc`. * By default, `ldd` contains the text `GNU libc` in its `--version` output, but that can be easily customized at build time using a build configuration option (see [here](https://github.com/bminor/glibc/blob/632d895f3e5d98162f77b9c3c1da4ec19968b671/elf/ldd.bash.in#L37) and [here](https://github.com/bminor/glibc/blob/632d895f3e5d98162f77b9c3c1da4ec19968b671/INSTALL#L273-L278)). As a fallback, the text `GNU C Library` is found in the header of the `ldd` script, and it will probably remain there as long as that file remains a script (as opposed to a compiled binary). 2. I made `getLibc()` immediately return `null` on all non-Linux platforms (not just Windows and macOS). ... ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem this PR addresses?
On certain Linux distributions,
/usr/bin/ldddoes not contain the string "GLIBC", but "libc". This is the case in popular distros such as openSUSE, Amazon Linux, Fedora, RHEL, Arch, and more. On these distributions, the current version of yarn falls back toprocess.report.getReport(), which is known to have performance issues in some instances.How did you fix it?
Add a check for the presence of the value
libcin addition to the existing check forGLIBC. This allows more Linux users to benefit from the fast-path that does not rely onprocess.report.getReport().Checklist