]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: copy DT_NEEDED entries from input libraries
authorPatrick Donnelly <pdonnell@ibm.com>
Wed, 16 Apr 2025 20:24:23 +0000 (16:24 -0400)
committerYuri Weinstein <yweinste@redhat.com>
Wed, 16 Jul 2025 22:46:05 +0000 (22:46 +0000)
On Ubuntu 22.04, the linker is not stumbling thinking the libceph-common
library is missing on the command-line. This appears to be a bug and the only
workaround I've found is to copy the DT_NEEDED entries for the input shared
objects (which is traditional linker behavior). I don't have an explanation for
why this occurs only for a few test executables.

Fixes: https://tracker.ceph.com/issues/70498
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
(cherry picked from commit c6ac71d398c16afa4aa888feaf7087bf61038bf0)
(cherry picked from commit b1068d1f751023f39b6453604f6efec9d8851c2f)

src/test/libcephfs/CMakeLists.txt

index 6cbbbe246a5e2f22e64761536afca25a35fafbe7..1eac150bae5f5ec7bf5397439d782844bccbf93d 100644 (file)
@@ -1,3 +1,21 @@
+# Note:
+#
+#    target_link_options(ceph_test_libcephfs PRIVATE -Wl,--copy-dt-needed-entries)
+#
+# This is done due to this linker error:
+#
+#    FAILED: bin/ceph_test_libcephfs_newops
+#    : && /usr/bin/g++-11 -Og -g -rdynamic -pie src/test/libcephfs/CMakeFiles/ceph_test_libcephfs_newops.dir/main.cc.o src/test/libcephfs/CMakeFiles/ceph_test_libcephfs_newops.dir/newops.cc.o -o bin/ceph_test_libcephfs_newops  -Wl,-rpath,/home/ubuntu/ceph/build/lib:  lib/libcephfs.so.2.0.0  lib/libgmock_main.a  lib/libgmock.a  lib/libgtest.a  -ldl  -ldl  /usr/lib/x86_64-linux-gnu/librt.a  -lresolv  -ldl  lib/libceph-common.so.2  lib/libjson_spirit.a  lib/libcommon_utf8.a  lib/liberasure_code.a  lib/libextblkdev.a  -lcap  boost/lib/libboost_thread.a  boost/lib/libboost_chrono.a  boost/lib/libboost_atomic.a  boost/lib/libboost_system.a  boost/lib/libboost_random.a  boost/lib/libboost_program_options.a  boost/lib/libboost_date_time.a  boost/lib/libboost_iostreams.a  boost/lib/libboost_regex.a  lib/libfmtd.a  /usr/lib/x86_64-linux-gnu/libblkid.so  /usr/lib/x86_64-linux-gnu/libcrypto.so  /usr/lib/x86_64-linux-gnu/libudev.so  /usr/lib/x86_64-linux-gnu/libz.so  src/opentelemetry-cpp/sdk/src/trace/libopentelemetry_trace.a  src/opentelemetry-cpp/sdk/src/resource/libopentelemetry_resources.a  src/opentelemetry-cpp/sdk/src/common/libopentelemetry_common.a  src/opentelemetry-cpp/exporters/jaeger/libopentelemetry_exporter_jaeger_trace.a  src/opentelemetry-cpp/ext/src/http/client/curl/libopentelemetry_http_client_curl.a  /usr/lib/x86_64-linux-gnu/libcurl.so  /usr/lib/x86_64-linux-gnu/libthrift.so  -lresolv  -ldl   -Wl,--as-needed -latomic && :
+#    /usr/bin/ld: lib/libcephfs.so.2.0.0: undefined reference to symbol '_ZN4ceph18__ceph_assert_failERKNS_11assert_dataE'
+#    /usr/bin/ld: lib/libceph-common.so.2: error adding symbols: DSO missing from command line
+#    collect2: error: ld returned 1 exit status
+#
+# Despite the presence of libceph-common.so.2 on the linker invocation, this
+# error persists. I (Patrick) have not found a resolution for this except to
+# make the linker behave in traditional manner where library dependencies are
+# assumed to be available. It seems like a linker bug and I have no explanation
+# for why it only affects a few test executables.
+
 if(WITH_LIBCEPHFS)
   add_executable(ceph_test_libcephfs
     test.cc
@@ -18,6 +36,9 @@ if(WITH_LIBCEPHFS)
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
     )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -32,6 +53,9 @@ if(WITH_LIBCEPHFS)
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
     )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_snapdiff PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_snapdiff
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -46,6 +70,9 @@ if(WITH_LIBCEPHFS)
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
     )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_suidsgid PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_suidsgid
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -56,11 +83,13 @@ if(WITH_LIBCEPHFS)
   target_link_libraries(ceph_test_libcephfs_vxattr
     ceph-common
     cephfs
-    librados
     ${UNITTEST_LIBS}
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
     )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_vxattr PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_vxattr
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -75,6 +104,9 @@ if(WITH_LIBCEPHFS)
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
     )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_newops PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_newops
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -83,13 +115,16 @@ if(WITH_LIBCEPHFS)
     add_executable(ceph_test_libcephfs_reclaim
       reclaim.cc
     )
-  target_link_libraries(ceph_test_libcephfs_reclaim
+    target_link_libraries(ceph_test_libcephfs_reclaim
       ceph-common
       cephfs
       ${UNITTEST_LIBS}
       ${EXTRALIBS}
       ${CMAKE_DL_LIBS}
-      )
+    )
+    if(NOT WIN32)
+      target_link_options(ceph_test_libcephfs_reclaim PRIVATE -Wl,--copy-dt-needed-entries)
+    endif()
     install(TARGETS ceph_test_libcephfs_reclaim
       DESTINATION ${CMAKE_INSTALL_BINDIR})
   endif(NOT WIN32)
@@ -97,14 +132,16 @@ if(WITH_LIBCEPHFS)
   add_executable(ceph_test_libcephfs_lazyio
     lazyio.cc
   )
-target_link_libraries(ceph_test_libcephfs_lazyio
-    ceph-common
+  target_link_libraries(ceph_test_libcephfs_lazyio
     cephfs
     librados
     ${UNITTEST_LIBS}
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
-    )   
+  )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_lazyio PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_lazyio
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 
@@ -118,7 +155,10 @@ target_link_libraries(ceph_test_libcephfs_lazyio
     ${UNITTEST_LIBS}
     ${EXTRALIBS}
     ${CMAKE_DL_LIBS}
-    )
+  )
+  if(NOT WIN32)
+    target_link_options(ceph_test_libcephfs_access PRIVATE -Wl,--copy-dt-needed-entries)
+  endif()
   install(TARGETS ceph_test_libcephfs_access
     DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif(WITH_LIBCEPHFS)