ROCm / rocm_smi_lib

ROCm SMI LIB
https://rocm.docs.amd.com/projects/rocm_smi_lib/en/latest/
MIT License
111 stars 48 forks source link

failure to build with link time optimization enabled #111

Closed emollier closed 7 months ago

emollier commented 1 year ago

Greetings,

for information, the Debian project is investigating the use of link time optimization at large scale, and Matthias Klose noticed in Debian Bug #1015653 that the rocm-smi-lib was failing to link with the following error:

[ 87%] Linking CXX shared library librocm_smi64.so
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/rocm_smi && /usr/bin/cmake -E cmake_link_script CMakeFiles/rocm_smi64.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wall -Wextra -fno-rtti -m64 -msse -msse2 -std=c++11  -Wconversion -Wcast-align  -Wformat=2 -fno-common -Wstrict-overflow   -Woverloaded-virtual -Wreorder  -DFORTIFY_SOURCE=2 -fstack-protector-all -Wcast-align -Wl,-z,noexecstack -Wl,-znoexecheap -Wl,-z,relro  -Wtrampolines -Wl,-z,now -fPIE -ggdb -O0 -DDEBUG -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,librocm_smi64.so.1 -o librocm_smi64.so.1.0 CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_device.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_main.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_monitor.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_power_mon.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_utils.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_counters.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_kfd.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_io_link.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi_gpu_metrics.cc.o CMakeFiles/rocm_smi64.dir/__/src/rocm_smi.cc.o CMakeFiles/rocm_smi64.dir/__/third_party/shared_mutex/shared_mutex.cc.o  -lpthread -lrt 
/usr/bin/ld: warning: -z noexecheap ignored
/usr/bin/ld: /tmp/ccSiNzIs.ltrans0.ltrans.o: warning: relocation against `_ZNSt17_Function_handlerIFbcENSt8__detail11_AnyMatcherINSt7__cxx1112regex_traitsIcEELb1ELb0ELb0EEEE10_M_managerERSt9_Any_dataRKS8_St18_Manager_operation' in read-only section `.text'
/usr/bin/ld: /tmp/ccSiNzIs.ltrans0.ltrans.o: relocation R_X86_64_PC32 against symbol `_ZTVSt9exception@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC

You can refer to a more complete log in the Debian bug tracker. Note that the build occurred with -fPIC enabled, so the message is probably a red herring. I'm not sure what to make of this error. It may be nothing, or maybe it could be symptomatic of something else, I don't know. In doubt, I thought you might be interested to be aware of the issue.

In the meantime, I can simply make sure no attempt will be made to build rocm-smi-lib with link time optimization enabled in Debian. This shouldn't be too harmful, I don't believe it's in the rocm-smi-lib that performances are the most critical.

Have a nice day :) Étienne.

emollier commented 10 months ago

I managed to go past this issue with the following change, as it seems the -fPIE option landing late in the compiler command line was erasing the behavior of -fPIC:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -103,7 +103,7 @@ else ()
     set(CMAKE_CXX_FLAGS
       "${CMAKE_CXX_FLAGS} -Wl,-z,noexecstack -Wl,-znoexecheap -Wl,-z,relro ")
     set(CMAKE_CXX_FLAGS
-      "${CMAKE_CXX_FLAGS} -Wtrampolines -Wl,-z,now -fPIE")
+      "${CMAKE_CXX_FLAGS} -Wtrampolines -Wl,-z,now")
 endif ()

 # Use this instead of above for 32 bit

Additionally, this change fixed a build failure on PA-RISC; see Debian bug #1030876. Please don't hesitate to let me know if this change is of interest, so I prepare a proper merge request, or if in the contrary this is causing other problems.

dmitrii-galantsev commented 7 months ago

Fixed as of c4c19e7