using --enable-bundled-python=mtime for __mtime.so generation on NEC
Hi,
The Issue:
Currently, using --enable-bundled-python=mtime with the rcl config results in a linking error:
/usr/bin/ld: /hpc/sw/gnu/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/usr/bin/ld: final link failed: Nonrepresentable section on output
This is due to the -static -add-gcc-rpath flags that are added to LIBS in the rcl config. Through CMAKE these are also included in the link.txt file that is used to create the __mtime.so module library.
A suggested solution:
One way to solve this error is to modify CMAKE_C_STANDARD_LIBRARIES in mtime/python/CMakeLists.txt and remove the static flags that are in conflict with the creation of a shared object.
e.g.
string(REPLACE "-static -add-gcc-rpath" "" CMAKE_C_STANDARD_LIBRARIES ${CMAKE_C_STANDARD_LIBRARIES})
set(CMAKE_C_STANDARD_LIBRARIES ${CMAKE_C_STANDARD_LIBRARIES})
I am not an expert with cmake but as far as I understand it the scope of the set command should only be the python subdirectory of mtime and all other components still get the original CMAKE_C_STANDARD_LIBRARIES.
Also, the the string(REPLACE ... call only replaces the string if it is present. So this should have no effect on systems were the static flags are not present.
The context:
For CMIP7 we want to be able to use mkexp on the NEC and mkexp uses the python mtime to handle time information for restarts etc. For testing and development, the workaround for this issue was to use a virtual environment with a python version were mtime is installed instead of compiling the shared python mtime with the rest of the executables. However, this relies on a hard coded path to a user directory in the mkexp config. So it would be better if --enable-bundled-python=mtime worked on the NEC as well.
Open questions:
- In !59 (merged) it is mentioned that there is no support for the shared libraries with NEC. Is this due to this issue or something else I haven't considered?
- Do you think this solution would be acceptable to enable the creation of
__mtime.soon rcl or do you know of a better solution? - So far, I have tested that this works on rcl and that the added lines don't have an effect on levante. But I haven't done any BuildBot or other CI tests.