The environment of my server is Ubuntu, and the version of the glibc is 2.27
. If I default to compile the code by using cross
, then the binary can successfully run on my server. However, if I set the following configuration
strip = true # Automatically strip symbols from the binary.
opt-level = "z" # Optimize for size.
lto = true
panic = "abort"
Then, if I run the binary executable file, the terminal will report /lib/x86_64-linux-gnu/libc.so.6: version
GLIBC_2.28' not found (required by ./test-file`). What makes the difference here? Why is the binary cannot run on the server if I give it the configuration? Does the default configuration link glibc statically such that the result binary can be run on the server that has a lower version of glibc?
The binary that is fault to run has the following information
// ldd test-file
./test-file: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by ./test-file)
linux-vdso.so.1 (0x00007fff0cbb3000)
libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f7e6a7ea000)
libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f7e6a31e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7e6a106000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7e69ee7000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7e69b49000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7e69945000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7e69554000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7e6b10c000)
// strings ./test-file | grep GLIBC_2.28
GLIBC_2.28
The binary that is successful to run has the following information
root@ubuntu:/home# ldd ./test-file-ok
linux-vdso.so.1 (0x00007ffda2b1f000)
libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f99d6a92000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f99d664e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f99d6436000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f99d622e000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f99d600f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f99d5c71000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f99d5a6d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f99d567c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f99d7a15000)
// strings ./test-file-ok | grep GLIBC_2.28