Running code-server on Old glibc Platforms
Problem Background
Due to work requirements, I needed to run code-server on CentOS 7. The simplest approach would be to download the pre-compiled package from coder/code-server. Unfortunately, running it directly resulted in errors like these:
| |
Clearly, this is caused by the outdated glibc version in CentOS 7 (see issue). Using ldd --version, we can find that CentOS 7’s glibc version is 2.17. To solve this problem, the simplest approach would be to compile and install code-server in a glibc 2.17 environment.
Compiling code-server in a glibc 2.17 environment is overly complex. You would need:
- A node compiled for glibc 2.17, see Node.js Unofficial Builds Project
- A container environment with gcc >= 12 and glibc = 2.17. This environment is extremely demanding! Compiling gcc takes considerable time!
- Follow code-server’s documentation to compile it
And there are known issues:
- File Watcher crashes unexpectedly due to SIGSEGV
- Dependencies on newer versions of C++ standard library
After trying this approach, I don’t recommend it.
A Moment of Inspiration
After an afternoon of contemplation, I recalled someone mentioning they had tried upgrading their system’s glibc but ended up breaking the system. I wondered: is there a way to make code-server link to a higher version of glibc without affecting the system? Yes, there is.
I found a tool called patchelf. As the name suggests, it’s used to patch ELF files (the binary format used in Linux), allowing modification of binary file links, interpreters, and dependencies.
Since code-server is entirely based on node.js, we only need to patch the node interpreter that comes with code-server to link it to a higher version of glibc. The node interpreter can be found after extracting code-server at lib/node.
Let’s examine it with ldd ./node, which gives output similar to:
| |
We can see that node links to the system’s glibc (/lib/x86_64-linux-gnu/libc.so.6, /lib64/ld-linux-x86-64.so.2).
Implementing the Solution
Compiling glibc
| |
Note that compiling glibc has minimum version requirements for tools like make, gcc, and binutils. Please refer to the INSTALL file in the extracted glibc source code.
Patching the Node Interpreter
- Add the higher version of glibc to rpath:
| |
- Modify the interpreter:
| |
Testing
Run ./lib/node to check if it works:
| |
Looks good!
Now running ./bin/code-server should work smoothly!
