-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix libc detection on various platforms
#6840
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
Conversation
libc detection on some musl-based distributionslibc detection on musl-based Linux distributions
By default, glib's version of ldd uses the text "GNU libc", but that text is provided by the build system, so it's not guaranteed to be there
libc detection on musl-based Linux distributionslibc detection on various platforms
|
As a side note, while it took a year for anyone to notice that
Disregard, that last part, I misunderstood how that |
## 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.
What's the problem this PR addresses?
Two problems:
Improve libc presence detection #6170 broke
libcdetection on at least Alpine Linux and Chimera Linux (and probably on all othermusl-based distributions as well) by looking for the generic stringlibcin/usr/bin/ldd. On both Chimera and Alpine,ldd --versionprintsmusl libcamong the output.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 thatgetLibc()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 neitherglibcnormusl....
How did you fix it?
The strings
GNU libcandGNU C Libraryare searched for instead of justlibc.lddcontains the textGNU libcin its--versionoutput, but that can be easily customized at build time using a build configuration option (see here and here). As a fallback, the textGNU C Libraryis found in the header of thelddscript, and it will probably remain there as long as that file remains a script (as opposed to a compiled binary).I made
getLibc()immediately returnnullon all non-Linux platforms (not just Windows and macOS)....
Checklist