Fix libc
detection on various platforms
#6840
Open
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?
Two problems:
Improve libc presence detection #6170 broke
libc
detection on at least Alpine Linux and Chimera Linux (and probably on all othermusl
-based distributions as well) by looking for the generic stringlibc
in/usr/bin/ldd
. On both Chimera and Alpine,ldd --version
printsmusl libc
among 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 neitherglibc
normusl
....
How did you fix it?
The strings
GNU libc
andGNU C Library
are searched for instead of justlibc
.ldd
contains the textGNU libc
in its--version
output, but that can be easily customized at build time using a build configuration option (see here and here). As a fallback, the textGNU C Library
is found in the header of theldd
script, and it will probably remain there as long as that file remains a script (as opposed to a compiled binary).I made
getLibc()
immediately returnnull
on all non-Linux platforms (not just Windows and macOS)....
Checklist