Do not export USDT function when ENABLE_USDT is OFF
authorShung-Hsi Yu <shung-hsi.yu@suse.com>
Thu, 30 Sep 2021 06:11:46 +0000 (14:11 +0800)
committerShung-Hsi Yu <shung-hsi.yu@suse.com>
Thu, 30 Sep 2021 09:44:31 +0000 (17:44 +0800)
When compiling with CMAKE_USE_LIBBPF_PACKAGE=yes and ENABLE_USDT=OFF, linking
of test_static will fail due to undefined references to
`bcc_usdt_new_frompath', `bcc_usdt_close' and `bcc_usdt_new_frompid'. The
reference comes from link_all.cc which references those functions irrespective
of ENABLE_USDT.

As a fix, introduce EXPORT_USDT and wrap references to USDT functions inside
link_all.cc within #ifdef.

src/cc/CMakeLists.txt
src/cc/link_all.cc

index 974fa49f9b3ef36516ae51de05c0170841086247..bcbbaebecffdb1d8ec6f5cc8f51050a46bb1e6cd 100644 (file)
@@ -89,6 +89,7 @@ set_target_properties(bcc-shared PROPERTIES VERSION ${REVISION_LAST} SOVERSION 0
 set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc)
 
 if(ENABLE_USDT)
+  add_definitions(-DEXPORT_USDT)
   set(bcc_usdt_sources usdt/usdt.cc usdt/usdt_args.cc)
   # else undefined
 endif()
index e03ea76cf6d85d9f8bdd3cca778bea7f4c55aac3..d3dbd9aa1a6d78979250c123574fcf5849952d93 100644 (file)
@@ -13,9 +13,11 @@ namespace {
       if (::getenv("bar") != (char *)-1)
         return;
 
+#ifdef EXPORT_USDT
       (void)bcc_usdt_new_frompid(-1, nullptr);
       (void)bcc_usdt_new_frompath(nullptr);
       (void)bcc_usdt_close(nullptr);
+#endif
     }
   } LinkAll;  // declare one instance to invoke the constructor
 }