Skip to content
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

Building 20.12.0 with old GLIBC: sys/random.h: No such file or directory #52223

Open
njzjz opened this issue Mar 26, 2024 · 11 comments
Open

Building 20.12.0 with old GLIBC: sys/random.h: No such file or directory #52223

njzjz opened this issue Mar 26, 2024 · 11 comments
Labels
build Issues and PRs related to build files or the CI.

Comments

@njzjz
Copy link

njzjz commented Mar 26, 2024

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_64 docker 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.

#ifdef HAVE_SYS_RANDOM_H
# include <sys/random.h>
#endif

These three lines were added by #51385 (upstream: c-ares/c-ares@d8edb76), and I believe that HAVE_SYS_RANDOM_H is not correctly set when sys/random.h is missing in the old glibc (<2.25).

What do you see instead?

2024-03-26T19:49:01.0021083Z     cc -o /tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs/out/Release/obj.target/cares/deps/cares/src/lib/ares_rand.o ../deps/cares/src/lib/ares_rand.c '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D_GNU_SOURCE' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DCARES_STATICLIB' '-DHAVE_CONFIG_H' -I../deps/cares/include -I../deps/cares/config/linux  -pthread -Wall -Wextra -Wno-unused-parameter -g -pedantic -Wall -Wextra -Wno-unused-parameter --std=gnu11 -m64 -O3 -fno-omit-frame-pointer  -MMD -MF /tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs/out/Release/.deps//tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs/out/Release/obj.target/cares/deps/cares/src/lib/ares_rand.o.d.raw   -c
2024-03-26T19:49:01.0552754Z   ../deps/cares/src/lib/ares_rand.c:39:12: fatal error: sys/random.h: No such file or directory
2024-03-26T19:49:01.0553982Z      39 | #  include <sys/random.h>
2024-03-26T19:49:01.0554526Z         |            ^~~~~~~~~~~~~~
2024-03-26T19:49:01.0559918Z   compilation terminated.
2024-03-26T19:49:01.0588060Z   make[1]: *** [/tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs/out/Release/obj.target/cares/deps/cares/src/lib/ares_rand.o] Error 1
2024-03-26T19:49:01.0590872Z   make[1]: *** Waiting for unfinished jobs....
2024-03-26T19:49:01.2031508Z   rm 6b3de4dd491ec37fd0646cdb3ef3868d29e0cb21.intermediate
2024-03-26T19:49:01.2232100Z   make[1]: Leaving directory `/tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs/out'
2024-03-26T19:49:01.2253454Z   make: *** [node] Error 2
2024-03-26T19:49:01.2263564Z   FAILED: nodejs-prefix/src/nodejs-stamp/nodejs-build /tmp/tmppjl__aad/build/nodejs-prefix/src/nodejs-stamp/nodejs-build

Additional information

No response

@Ch3nYuY
Copy link
Contributor

Ch3nYuY commented Mar 27, 2024

I reproduced your problem using the same Docker image. By temporarily compiling successfully with #undef HAVE_GETRANDOM #undef HAVE_SYS_RANDOM_H in deps/cares/config/linux/ares_config.h.

At the same time, I found that the HAVE_GETRANDOM macro 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.

@Ch3nYuY
Copy link
Contributor

Ch3nYuY commented Mar 27, 2024

The root cause of this compilation error is that Node.js adopted a static method to directly load config/linux/ares_config.h when incorporating c-ares configurations for different architectures.

node/deps/cares/cares.gyp

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.

node/deps/cares/configure

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.

@richardlau
Copy link
Member

sys/random.h was 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.

@VoltrexKeyva VoltrexKeyva added the build Issues and PRs related to build files or the CI. label Mar 27, 2024
@scosol
Copy link

scosol commented Mar 28, 2024

nodejs/unofficial-builds#127

@njzjz
Copy link
Author

njzjz commented Mar 29, 2024

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_H and HAVE_GETRANDOM.

@zhuzhzh
Copy link

zhuzhzh commented Apr 2, 2024

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_H and HAVE_GETRANDOM.

I agree with this workaround!

@okuryu
Copy link
Contributor

okuryu commented Apr 4, 2024

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.

@Artiom-Morozov-Resilio
Copy link

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_H and HAVE_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
caboom

branch and building on older glibc, should not fail if all macros are set.

@kftang
Copy link

kftang commented Apr 12, 2024

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_H and HAVE_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
caboom

branch and building on older glibc, should not fail if all macros are set.

This worked for me on RHEL 7.5

michalbiesek added a commit to michalbiesek/js2bin that referenced this issue Apr 16, 2024
michalbiesek added a commit to michalbiesek/js2bin that referenced this issue Apr 16, 2024
xhochy added a commit to tsibley/conda-forge-nodejs-feedstock that referenced this issue Apr 25, 2024
xhochy added a commit to xhochy/nodejs-feedstock that referenced this issue Apr 29, 2024
robertsLando added a commit to yao-pkg/pkg-fetch that referenced this issue Jun 13, 2024
@surmish
Copy link

surmish commented Jun 13, 2024

Can you suggest a workaround for this to build on machines with older glibc versions?

> ldd --version
ldd (GNU libc) 2.17

@scosol
Copy link

scosol commented Jun 17, 2024

Can you suggest a workaround for this to build on machines with older glibc versions?

> ldd --version
ldd (GNU libc) 2.17

See the code in here: https://unofficial-builds.nodejs.org/

nodejs/unofficial-builds#129

teaguesterling added a commit to teaguesterling/spack that referenced this issue Jul 7, 2024
…CI failures

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
tldahlgren pushed a commit to spack/spack that referenced this issue Jul 22, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
teaguesterling added a commit to teaguesterling/spack that referenced this issue Jul 28, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
johnwparent pushed a commit to johnwparent/spack that referenced this issue Aug 2, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
diehlpk pushed a commit to diehlpk/spack that referenced this issue Aug 14, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
mvlopri pushed a commit to mvlopri/spack that referenced this issue Aug 23, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
FrederickDeny pushed a commit to FrederickDeny/spack that referenced this issue Aug 26, 2024
* Adding new versions and compilation conflict for nodejs
* Update failed version for gcc14
* Updating conflicts notes for correctness/clarity/format
* Applying spack-ized versions of fix in nodejs/node#52223 to adddress CI failures
* Update fix-old-glibc-random-headers.patch
* Update package.py
* Update fix-old-glibc-random-headers.patch
* Update fix-old-glibc-random-headers.patch
* Adding conflict for older glibc
* Fixing patch for older systems, need to undef
* Removing overly strict conflicts

---------

Signed-off-by: Teague Sterling <teaguesterling@gmail.com>
skupr-anaconda added a commit to AnacondaRecipes/nodejs-feedstock that referenced this issue Sep 6, 2024
skupr-anaconda added a commit to AnacondaRecipes/nodejs-feedstock that referenced this issue Sep 9, 2024
* nodejs_20.17.0

* Add libuv to build as it's a bootstrap dependency in js2c of nodejs >=20.3

* Use libuv 1.48 because of a new uv_pipe_bind2

* Clean up the local cbc.yaml

* Adjust install.py call

* Add workaround for nodejs/node#52223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI.
Projects
None yet
Development

No branches or pull requests

10 participants