Repository navigation
Building 20.12.0 with old GLIBC: sys/random.h: No such file or directory #52223
Description
Activity
I reproduced your problem using the same Docker image. By temporarily compiling successfully with
#undef HAVE_GETRANDOM#undef HAVE_SYS_RANDOM_Hindeps/cares/config/linux/ares_config.h.At the same time, I found that the
HAVE_GETRANDOMmacro encountered the same problem. They seem to have been introduced during the automated update of c-ares (#51385, #51582). I'm looking into how to fix them.The root cause of this compilation error is that Node.js adopted a static method to directly load
config/linux/ares_config.hwhen incorporating c-ares configurations for different architectures.
Lines 197 to 200 in 6d2d3f1
[ 'OS=="linux"', { 'include_dirs': [ 'config/linux' ], 'sources': [ 'config/linux/ares_config.h' ] }], As a result, the original mechanism of c-ares for generating macros, as demonstrated below, was not executed.
Lines 21505 to 21509 in 6d2d3f1
if test "x$ac_cv_header_sys_random_h" = xyes then : printf "%s\n" "#define HAVE_SYS_RANDOM_H 1" >>confdefs.h fi However, I currently do not know how to dynamically detect header files and set macros in GYP.
sys/random.hwas added in glibc 2.25. glibc 2.28 has been the minimum supported version since Node.js 18, so this isn't an issue for Node.js.If you are building Node.js for an older glibc you'll need to make adjustments accordingly.
Reacted by Chenyu Yang- addedbuildIssues and PRs related to Node.js builds or CI infrastructure.Issues and PRs related to Node.js builds or CI infrastructure.
on Mar 27, 2024 - Reacted by Vanilla and lasorda
However, I currently do not know how to dynamically detect header files and set macros in GYP.
Could we append the following codes to
deps/cares/config/linux/ares_config.h:#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)) #undef HAVE_SYS_RANDOM_H #undef HAVE_GETRANDOM #endif
When GLIBC version <2.25, undefine
HAVE_SYS_RANDOM_HandHAVE_GETRANDOM.Reacted by Boyang Du, Mikhail Ryzhov and Aman KarmaniHowever, I currently do not know how to dynamically detect header files and set macros in GYP.
Could we append the following codes to
deps/cares/config/linux/ares_config.h:#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)) #undef HAVE_SYS_RANDOM_H #undef HAVE_GETRANDOM #endif
When GLIBC version <2.25, undefine
HAVE_SYS_RANDOM_HandHAVE_GETRANDOM.I agree with this workaround!
I have solved this problem by applying Anna's patch.
nodejs/unofficial-builds#127 (review)
so I have successfully built v18 and v20 on CentOS 7 (glibc 2.17) and they pass tests with citgm.However, I currently do not know how to dynamically detect header files and set macros in GYP.
Could we append the following codes to
deps/cares/config/linux/ares_config.h:#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)) #undef HAVE_SYS_RANDOM_H #undef HAVE_GETRANDOM #endif
When GLIBC version <2.25, undefine
HAVE_SYS_RANDOM_HandHAVE_GETRANDOM.That may need
#include <sys/types.h>above check as well, because GLIBC comes from features.h and it's not included on all pathes where ares_config.h is included. I see it on glibc 2.17.You can check your setup it by adding
#else caboombranch and building on older glibc, should not fail if all macros are set.
However, I currently do not know how to dynamically detect header files and set macros in GYP.
Could we append the following codes to
deps/cares/config/linux/ares_config.h:#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 25)) #undef HAVE_SYS_RANDOM_H #undef HAVE_GETRANDOM #endif
When GLIBC version <2.25, undefine
HAVE_SYS_RANDOM_HandHAVE_GETRANDOM.That may need
#include <sys/types.h>above check as well, because GLIBC comes from features.h and it's not included on all pathes where ares_config.h is included. I see it on glibc 2.17.You can check your setup it by adding
#else caboombranch and building on older glibc, should not fail if all macros are set.
This worked for me on RHEL 7.5
Reacted by Boyang Du and i3v- added 2 commits that reference this issue
on Apr 16, 2024 - added a commit that references this issue
on Jun 13, 2024 Can you suggest a workaround for this to build on machines with older
glibcversions?> ldd --version ldd (GNU libc) 2.17Can you suggest a workaround for this to build on machines with older
glibcversions?> ldd --version ldd (GNU libc) 2.17See the code in here: https://unofficial-builds.nodejs.org/
- added a commit that references this issue
on Jul 22, 2024 - added a commit that references this issue
on Jul 28, 2024 - added a commit that references this issue
on Aug 2, 2024 - added a commit that references this issue
on Aug 14, 2024 - added a commit that references this issue
on Aug 26, 2024 - added a commit that references this issue
on Apr 20, 2026
Version
20.12.0
Platform
Linux 42c14383a17c 6.7.3-100.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Feb 1 03:33:32 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
CentOS 7
What steps will reproduce the bug?
Use the
quay.io/pypa/manylinux2014_x86_64docker image (CentOS 7 based) to build nodejs (./configure).How often does it reproduce? Is there a required condition?
It can be consistently reproduced.
What is the expected behavior? Why is that the expected behavior?
It can be successfully built, like 20.11.1.
node/deps/cares/src/lib/ares_rand.c
Lines 38 to 40 in 94fb854
These three lines were added by #51385 (upstream: c-ares/c-ares@d8edb76), and I believe that
HAVE_SYS_RANDOM_His not correctly set whensys/random.his missing in the old glibc (<2.25).What do you see instead?
Additional information
No response