RPATH_CHANGE fails for ELF files with more than 65536 sections
CMake project to reproduce the issue
- CMakeLists.txt (trivial C++ project that installs an executable)
-
main.cc
: Trivialmain
function + the output of
for i in `seq 1 70000`; do
echo "int var_$i __attribute__((section(\"section_$i\"))) = $i;"
done
The shell script is from https://sourceware.org/bugzilla/show_bug.cgi?id=5900
Steps to reproduce:
- Configure project with
-DCMAKE_INSTALL_RPATH=/usr/lib
- Build and install the project
Installation fails with:
Install the project...
-- Install configuration: ""
-- Installing: [...]/elftest
CMake Error at cmake_install.cmake:55 (file):
file RPATH_CHANGE could not write new RPATH:
/usr/lib
to the file:
[...]/elftest
No valid ELF RPATH or RUNPATH entry exists in the file;
The cause of this bug seems to be that cmELF
doesn't support ELF files with more than 65536 sections as then the real section count is in the header of section 0, not in the ELF header. I.e., cmELF
doesn't find any sections and thus, doesn't find the RPATH
or RUNPATH
entries even though they exist.
I've encountered this issue with a real world project that statically links to gRPC (and indirectly to abseil-cpp).