[lldb][CMake] Enforce not linking against plugin libs in core libs
authorAlex Langford <alangford@apple.com>
Tue, 21 Mar 2023 18:20:31 +0000 (11:20 -0700)
committerAlex Langford <alangford@apple.com>
Tue, 21 Mar 2023 23:24:36 +0000 (16:24 -0700)
Non-plugin lldb libraries should generally not be linking against lldb
plugin libraries. Enforce this in CMake.

Differential Revision: https://reviews.llvm.org/D146553

12 files changed:
lldb/cmake/modules/AddLLDB.cmake
lldb/source/Breakpoint/CMakeLists.txt
lldb/source/Commands/CMakeLists.txt
lldb/source/Core/CMakeLists.txt
lldb/source/DataFormatters/CMakeLists.txt
lldb/source/Expression/CMakeLists.txt
lldb/source/Host/CMakeLists.txt
lldb/source/Host/macosx/objcxx/CMakeLists.txt
lldb/source/Interpreter/CMakeLists.txt
lldb/source/Symbol/CMakeLists.txt
lldb/source/Target/CMakeLists.txt
lldb/source/Version/CMakeLists.txt

index e8fa70a..f2d96df 100644 (file)
@@ -37,7 +37,7 @@ function(add_lldb_library name)
   # only supported parameters to this macro are the optional
   # MODULE;SHARED;STATIC library type and source files
   cmake_parse_arguments(PARAM
-    "MODULE;SHARED;STATIC;OBJECT;PLUGIN;FRAMEWORK;NO_INTERNAL_DEPENDENCIES"
+    "MODULE;SHARED;STATIC;OBJECT;PLUGIN;FRAMEWORK;NO_INTERNAL_DEPENDENCIES;NO_PLUGIN_DEPENDENCIES"
     "INSTALL_PREFIX;ENTITLEMENTS"
     "EXTRA_CXXFLAGS;DEPENDS;LINK_LIBS;LINK_COMPONENTS;CLANG_LIBS"
     ${ARGN})
@@ -54,6 +54,16 @@ function(add_lldb_library name)
     endforeach()
   endif()
 
+  if(PARAM_NO_PLUGIN_DEPENDENCIES)
+    foreach(link_lib ${PARAM_LINK_LIBS})
+      if (link_lib MATCHES "^lldbPlugin")
+        message(FATAL_ERROR
+          "Library ${name} cannot depend on a plugin (Found ${link_lib} in "
+          "LINK_LIBS)")
+      endif()
+    endforeach()
+  endif()
+
   if(PARAM_PLUGIN)
     set_property(GLOBAL APPEND PROPERTY LLDB_PLUGINS ${name})
   endif()
index 4862c2b..5c28023 100644 (file)
@@ -1,4 +1,4 @@
-add_lldb_library(lldbBreakpoint
+add_lldb_library(lldbBreakpoint NO_PLUGIN_DEPENDENCIES
   Breakpoint.cpp
   BreakpointID.cpp
   BreakpointIDList.cpp
index dc1aebc..6a36c53 100644 (file)
@@ -2,7 +2,7 @@ lldb_tablegen(CommandOptions.inc -gen-lldb-option-defs
   SOURCE Options.td
   TARGET LLDBOptionsGen)
 
-add_lldb_library(lldbCommands
+add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
   CommandCompletions.cpp
   CommandObjectApropos.cpp
   CommandObjectBreakpoint.cpp
index b46ed35..f0220be 100644 (file)
@@ -19,6 +19,7 @@ if (LLDB_ENABLE_CURSES)
   endif()
 endif()
 
+# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbCore
 add_lldb_library(lldbCore
   Address.cpp
   AddressRange.cpp
index e727432..7f48a27 100644 (file)
@@ -1,4 +1,4 @@
-add_lldb_library(lldbDataFormatters
+add_lldb_library(lldbDataFormatters NO_PLUGIN_DEPENDENCIES
   CXXFunctionPointer.cpp
   DataVisualization.cpp
   DumpValueObjectOptions.cpp
index 54414fb..7e4fd81 100644 (file)
@@ -1,3 +1,4 @@
+# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbExpression
 add_lldb_library(lldbExpression
   DiagnosticManager.cpp
   DWARFExpression.cpp
index 4a5ceeb..91f353e 100644 (file)
@@ -159,7 +159,7 @@ if (LLDB_ENABLE_LIBEDIT)
   endif()
 endif()
 
-add_lldb_library(lldbHost
+add_lldb_library(lldbHost NO_PLUGIN_DEPENDENCIES
   ${HOST_SOURCES}
 
   LINK_LIBS
index 9b59273..273999f 100644 (file)
@@ -2,7 +2,7 @@
 remove_module_flags()
 include_directories(..)
 
-add_lldb_library(lldbHostMacOSXObjCXX
+add_lldb_library(lldbHostMacOSXObjCXX NO_PLUGIN_DEPENDENCIES
   Host.mm
   HostInfoMacOSX.mm
   HostThreadMacOSX.mm
index c8c7a38..ae79b82 100644 (file)
@@ -6,7 +6,7 @@ lldb_tablegen(InterpreterPropertiesEnum.inc -gen-lldb-property-enum-defs
   SOURCE InterpreterProperties.td
   TARGET LLDBInterpreterPropertiesEnumGen)
 
-add_lldb_library(lldbInterpreter
+add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
   CommandAlias.cpp
   CommandHistory.cpp
   CommandInterpreter.cpp
index 0b2e628..cec49b8 100644 (file)
@@ -6,7 +6,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     )
 endif()
 
-add_lldb_library(lldbSymbol
+add_lldb_library(lldbSymbol NO_PLUGIN_DEPENDENCIES
   ArmUnwindInfo.cpp
   Block.cpp
   CompactUnwindInfo.cpp
index 0cb3573..3823daf 100644 (file)
@@ -6,7 +6,7 @@ lldb_tablegen(TargetPropertiesEnum.inc -gen-lldb-property-enum-defs
   SOURCE TargetProperties.td
   TARGET LLDBTargetPropertiesEnumGen)
 
-add_lldb_library(lldbTarget
+add_lldb_library(lldbTarget NO_PLUGIN_DEPENDENCIES
   ABI.cpp
   AssertFrameRecognizer.cpp
   DynamicRegisterInfo.cpp
index 73367f2..c1393b5 100644 (file)
@@ -36,7 +36,7 @@ set_source_files_properties("${version_inc}"
 
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
-add_lldb_library(lldbVersion
+add_lldb_library(lldbVersion NO_PLUGIN_DEPENDENCIES
   Version.cpp
   ${vcs_version_inc}
   ${version_inc})