From 5499b026d218f694a8c9f148466da3259f6cc1fd Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Tue, 21 Mar 2023 11:20:31 -0700 Subject: [PATCH] [lldb][CMake] Enforce not linking against plugin libs in core libs Non-plugin lldb libraries should generally not be linking against lldb plugin libraries. Enforce this in CMake. Differential Revision: https://reviews.llvm.org/D146553 --- lldb/cmake/modules/AddLLDB.cmake | 12 +++++++++++- lldb/source/Breakpoint/CMakeLists.txt | 2 +- lldb/source/Commands/CMakeLists.txt | 2 +- lldb/source/Core/CMakeLists.txt | 1 + lldb/source/DataFormatters/CMakeLists.txt | 2 +- lldb/source/Expression/CMakeLists.txt | 1 + lldb/source/Host/CMakeLists.txt | 2 +- lldb/source/Host/macosx/objcxx/CMakeLists.txt | 2 +- lldb/source/Interpreter/CMakeLists.txt | 2 +- lldb/source/Symbol/CMakeLists.txt | 2 +- lldb/source/Target/CMakeLists.txt | 2 +- lldb/source/Version/CMakeLists.txt | 2 +- 12 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lldb/cmake/modules/AddLLDB.cmake b/lldb/cmake/modules/AddLLDB.cmake index e8fa70a5a684..f2d96dfd68e0 100644 --- a/lldb/cmake/modules/AddLLDB.cmake +++ b/lldb/cmake/modules/AddLLDB.cmake @@ -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() diff --git a/lldb/source/Breakpoint/CMakeLists.txt b/lldb/source/Breakpoint/CMakeLists.txt index 4862c2b36403..5c2802322ed5 100644 --- a/lldb/source/Breakpoint/CMakeLists.txt +++ b/lldb/source/Breakpoint/CMakeLists.txt @@ -1,4 +1,4 @@ -add_lldb_library(lldbBreakpoint +add_lldb_library(lldbBreakpoint NO_PLUGIN_DEPENDENCIES Breakpoint.cpp BreakpointID.cpp BreakpointIDList.cpp diff --git a/lldb/source/Commands/CMakeLists.txt b/lldb/source/Commands/CMakeLists.txt index dc1aebc30de1..6a36c5376d5c 100644 --- a/lldb/source/Commands/CMakeLists.txt +++ b/lldb/source/Commands/CMakeLists.txt @@ -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 diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index b46ed3510e52..f0220beae032 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -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 diff --git a/lldb/source/DataFormatters/CMakeLists.txt b/lldb/source/DataFormatters/CMakeLists.txt index e727432da4f0..7f48a2785c73 100644 --- a/lldb/source/DataFormatters/CMakeLists.txt +++ b/lldb/source/DataFormatters/CMakeLists.txt @@ -1,4 +1,4 @@ -add_lldb_library(lldbDataFormatters +add_lldb_library(lldbDataFormatters NO_PLUGIN_DEPENDENCIES CXXFunctionPointer.cpp DataVisualization.cpp DumpValueObjectOptions.cpp diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt index 54414fb2a7c4..7e4fd81f2afd 100644 --- a/lldb/source/Expression/CMakeLists.txt +++ b/lldb/source/Expression/CMakeLists.txt @@ -1,3 +1,4 @@ +# TODO: Add property `NO_PLUGIN_DEPENDENCIES` to lldbExpression add_lldb_library(lldbExpression DiagnosticManager.cpp DWARFExpression.cpp diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 4a5ceeb60b7b..91f353e50b19 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -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 diff --git a/lldb/source/Host/macosx/objcxx/CMakeLists.txt b/lldb/source/Host/macosx/objcxx/CMakeLists.txt index 9b59273e02ad..273999f24380 100644 --- a/lldb/source/Host/macosx/objcxx/CMakeLists.txt +++ b/lldb/source/Host/macosx/objcxx/CMakeLists.txt @@ -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 diff --git a/lldb/source/Interpreter/CMakeLists.txt b/lldb/source/Interpreter/CMakeLists.txt index c8c7a38904c3..ae79b82d7c3e 100644 --- a/lldb/source/Interpreter/CMakeLists.txt +++ b/lldb/source/Interpreter/CMakeLists.txt @@ -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 diff --git a/lldb/source/Symbol/CMakeLists.txt b/lldb/source/Symbol/CMakeLists.txt index 0b2e6284bd41..cec49b8b2cb4 100644 --- a/lldb/source/Symbol/CMakeLists.txt +++ b/lldb/source/Symbol/CMakeLists.txt @@ -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 diff --git a/lldb/source/Target/CMakeLists.txt b/lldb/source/Target/CMakeLists.txt index 0cb357391642..3823daf370b4 100644 --- a/lldb/source/Target/CMakeLists.txt +++ b/lldb/source/Target/CMakeLists.txt @@ -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 diff --git a/lldb/source/Version/CMakeLists.txt b/lldb/source/Version/CMakeLists.txt index 73367f2775bd..c1393b5dd6e6 100644 --- a/lldb/source/Version/CMakeLists.txt +++ b/lldb/source/Version/CMakeLists.txt @@ -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})