Skip to content

Commit 354eaa1

Browse files
committed
[llvm][unittests][NFCI] Depend on rpath for loading test plugins
As proven by llvm#159126 it's unnecessary to explicitly construct the path for loading the test plugins. On all supported platforms the rpath is set appropriately for them to be found by the dynamic loader itself. Thus we can just rid ourselves of the extra code. The only exception is `Support/DynamicLibrary` as it also runs on Windows, which lacks the concept of a rpath. This also cleans up some of the CMake code and C++ includes slightly. Surprisingly `intrinsics_gen` isn't necessary for any of them as none of them actually do much. See: llvm#159126
1 parent bb3b020 commit 354eaa1

File tree

10 files changed

+15
-111
lines changed

10 files changed

+15
-111
lines changed
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
# The advisor plugin expects to not link against the Analysis, Support and Core
2-
# libraries, but expects them to exist in the process loading the plugin. This
1+
# The advisor plugin expects to not link against the Analysis, Support and Core
2+
# libraries, but expects them to exist in the process loading the plugin. This
33
# doesn't work with DLLs on Windows (where a shared library can't have undefined
44
# references), so just skip this testcase on Windows.
55
if ((NOT WIN32 AND NOT CYGWIN) OR LLVM_BUILD_LLVM_DYLIB)
66
unset(LLVM_LINK_COMPONENTS)
77
add_llvm_library(InlineAdvisorPlugin MODULE BUILDTREE_ONLY
88
InlineAdvisorPlugin.cpp
99
)
10-
# Put PLUGIN next to the unit test executable.
11-
set_output_directory(InlineAdvisorPlugin
12-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
13-
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
14-
)
1510
set_target_properties(InlineAdvisorPlugin PROPERTIES FOLDER "LLVM/Tests")
16-
17-
# The plugin depends on some of the output files of intrinsics_gen, so make sure
18-
# it is built before the plugin.
19-
add_dependencies(InlineAdvisorPlugin intrinsics_gen)
2011
add_dependencies(AnalysisTests InlineAdvisorPlugin)
2112
endif()

llvm/unittests/Analysis/InlineAdvisorPlugin/InlineAdvisorPlugin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "llvm/Pass.h"
44
#include "llvm/Passes/PassBuilder.h"
55
#include "llvm/Passes/PassPlugin.h"
6-
#include "llvm/Support/CommandLine.h"
7-
#include "llvm/Support/raw_ostream.h"
86

97
#include "llvm/Analysis/InlineAdvisor.h"
108

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
# The order plugin expects to not link against the Analysis, Support and Core
2-
# libraries, but expects them to exist in the process loading the plugin. This
1+
# The order plugin expects to not link against the Analysis, Support and Core
2+
# libraries, but expects them to exist in the process loading the plugin. This
33
# doesn't work with DLLs on Windows (where a shared library can't have undefined
44
# references), so just skip this testcase on Windows.
55
if ((NOT WIN32 AND NOT CYGWIN) OR LLVM_BUILD_LLVM_DYLIB)
66
unset(LLVM_LINK_COMPONENTS)
77
add_llvm_library(InlineOrderPlugin MODULE BUILDTREE_ONLY
88
InlineOrderPlugin.cpp
99
)
10-
# Put PLUGIN next to the unit test executable.
11-
set_output_directory(InlineOrderPlugin
12-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
13-
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
14-
)
1510
set_target_properties(InlineOrderPlugin PROPERTIES FOLDER "Tests")
16-
17-
# The plugin depends on some of the output files of intrinsics_gen, so make sure
18-
# it is built before the plugin.
19-
add_dependencies(InlineOrderPlugin intrinsics_gen)
2011
add_dependencies(AnalysisTests InlineOrderPlugin)
2112
endif()

llvm/unittests/Analysis/InlineOrderPlugin/InlineOrderPlugin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "llvm/Pass.h"
44
#include "llvm/Passes/PassBuilder.h"
55
#include "llvm/Passes/PassPlugin.h"
6-
#include "llvm/Support/CommandLine.h"
7-
#include "llvm/Support/raw_ostream.h"
86

97
#include "llvm/Analysis/InlineOrder.h"
108

llvm/unittests/Analysis/PluginInlineAdvisorAnalysisTest.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,13 @@
44
#include "llvm/IR/Module.h"
55
#include "llvm/Passes/PassBuilder.h"
66
#include "llvm/Passes/PassPlugin.h"
7-
#include "llvm/Support/CommandLine.h"
87
#include "llvm/Support/raw_ostream.h"
9-
#include "llvm/Testing/Support/Error.h"
108
#include "gtest/gtest.h"
119

1210
namespace llvm {
1311

1412
namespace {
1513

16-
void anchor() {}
17-
18-
static std::string libPath(const std::string Name = "InlineAdvisorPlugin") {
19-
const auto &Argvs = testing::internal::GetArgvs();
20-
const char *Argv0 =
21-
Argvs.size() > 0 ? Argvs[0].c_str() : "PluginInlineAdvisorAnalysisTest";
22-
void *Ptr = (void *)(intptr_t)anchor;
23-
std::string Path = sys::fs::getMainExecutable(Argv0, Ptr);
24-
llvm::SmallString<256> Buf{sys::path::parent_path(Path)};
25-
sys::path::append(Buf, (Name + LLVM_PLUGIN_EXT).c_str());
26-
return std::string(Buf.str());
27-
}
28-
2914
// Example of a custom InlineAdvisor that only inlines calls to functions called
3015
// "foo".
3116
class FooOnlyInlineAdvisor : public InlineAdvisor {
@@ -61,8 +46,7 @@ struct CompilerInstance {
6146

6247
// connect the plugin to our compiler instance
6348
void setupPlugin() {
64-
auto PluginPath = libPath();
65-
ASSERT_NE("", PluginPath);
49+
auto PluginPath{std::string{"InlineAdvisorPlugin"} + LLVM_PLUGIN_EXT};
6650
Expected<PassPlugin> Plugin = PassPlugin::Load(PluginPath);
6751
ASSERT_TRUE(!!Plugin) << "Plugin path: " << PluginPath;
6852
Plugin->registerPassBuilderCallbacks(PB);

llvm/unittests/Analysis/PluginInlineOrderAnalysisTest.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,13 @@
44
#include "llvm/IR/Module.h"
55
#include "llvm/Passes/PassBuilder.h"
66
#include "llvm/Passes/PassPlugin.h"
7-
#include "llvm/Support/CommandLine.h"
87
#include "llvm/Support/raw_ostream.h"
9-
#include "llvm/Testing/Support/Error.h"
108
#include "gtest/gtest.h"
119

12-
#include "llvm/Analysis/InlineOrder.h"
13-
1410
namespace llvm {
1511

1612
namespace {
1713

18-
void anchor() {}
19-
20-
std::string libPath(const std::string Name = "InlineOrderPlugin") {
21-
const auto &Argvs = testing::internal::GetArgvs();
22-
const char *Argv0 =
23-
Argvs.size() > 0 ? Argvs[0].c_str() : "PluginInlineOrderAnalysisTest";
24-
void *Ptr = (void *)(intptr_t)anchor;
25-
std::string Path = sys::fs::getMainExecutable(Argv0, Ptr);
26-
llvm::SmallString<256> Buf{sys::path::parent_path(Path)};
27-
sys::path::append(Buf, (Name + LLVM_PLUGIN_EXT).c_str());
28-
return std::string(Buf.str());
29-
}
30-
3114
struct CompilerInstance {
3215
LLVMContext Ctx;
3316
ModulePassManager MPM;
@@ -43,8 +26,7 @@ struct CompilerInstance {
4326

4427
// Connect the plugin to our compiler instance.
4528
void setupPlugin() {
46-
auto PluginPath = libPath();
47-
ASSERT_NE("", PluginPath);
29+
auto PluginPath{std::string{"InlineOrderPlugin"} + LLVM_PLUGIN_EXT};
4830
Expected<PassPlugin> Plugin = PassPlugin::Load(PluginPath);
4931
ASSERT_TRUE(!!Plugin) << "Plugin path: " << PluginPath;
5032
Plugin->registerPassBuilderCallbacks(PB);
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
add_llvm_library(DoublerPlugin MODULE BUILDTREE_ONLY
2-
DoublerPlugin.cpp
3-
)
4-
5-
# Put PLUGIN next to the unit test executable.
6-
set_output_directory(DoublerPlugin
7-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
8-
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
9-
)
2+
DoublerPlugin.cpp
3+
)
104
set_target_properties(DoublerPlugin PROPERTIES FOLDER "Tests")
11-
12-
# The plugin depends on some of the output files of intrinsics_gen, so make sure
13-
# it is built before the plugin.
14-
add_dependencies(DoublerPlugin intrinsics_gen)
155
add_dependencies(PluginsTests DoublerPlugin)

llvm/unittests/Passes/Plugins/PluginsTest.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,13 @@
2727

2828
using namespace llvm;
2929

30-
void anchor() {}
31-
32-
static std::string LibPath(const std::string Name = "TestPlugin") {
33-
const auto &Argvs = testing::internal::GetArgvs();
34-
const char *Argv0 = Argvs.size() > 0 ? Argvs[0].c_str() : "PluginsTests";
35-
void *Ptr = (void *)(intptr_t)anchor;
36-
std::string Path = sys::fs::getMainExecutable(Argv0, Ptr);
37-
llvm::SmallString<256> Buf{sys::path::parent_path(Path)};
38-
sys::path::append(Buf, (Name + LLVM_PLUGIN_EXT).c_str());
39-
return std::string(Buf.str());
40-
}
41-
4230
TEST(PluginsTests, LoadPlugin) {
4331
#if !defined(LLVM_ENABLE_PLUGINS)
4432
// Skip the test if plugins are disabled.
4533
GTEST_SKIP();
4634
#endif
4735

48-
auto PluginPath = LibPath();
49-
ASSERT_NE("", PluginPath);
50-
36+
auto PluginPath{std::string{"TestPlugin"} + LLVM_PLUGIN_EXT};
5137
Expected<PassPlugin> Plugin = PassPlugin::Load(PluginPath);
5238
ASSERT_TRUE(!!Plugin) << "Plugin path: " << PluginPath;
5339

@@ -71,10 +57,8 @@ TEST(PluginsTests, LoadMultiplePlugins) {
7157
GTEST_SKIP();
7258
#endif
7359

74-
auto DoublerPluginPath = LibPath("DoublerPlugin");
75-
auto TestPluginPath = LibPath("TestPlugin");
76-
ASSERT_NE("", DoublerPluginPath);
77-
ASSERT_NE("", TestPluginPath);
60+
auto DoublerPluginPath{std::string{"DoublerPlugin"} + LLVM_PLUGIN_EXT};
61+
auto TestPluginPath{std::string{"TestPlugin"} + LLVM_PLUGIN_EXT};
7862

7963
Expected<PassPlugin> DoublerPlugin1 = PassPlugin::Load(DoublerPluginPath);
8064
ASSERT_TRUE(!!DoublerPlugin1)
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
add_llvm_library(TestPlugin MODULE BUILDTREE_ONLY
2-
TestPlugin.cpp
3-
)
4-
5-
# Put PLUGIN next to the unit test executable.
6-
set_output_directory(TestPlugin
7-
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
8-
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/../
9-
)
2+
TestPlugin.cpp
3+
)
104
set_target_properties(TestPlugin PROPERTIES FOLDER "Tests")
115

12-
# The plugin depends on some of the output files of intrinsics_gen, so make sure
13-
# it is built before the plugin.
14-
add_dependencies(TestPlugin intrinsics_gen)
156
add_dependencies(PluginsTests TestPlugin)

llvm/unittests/Support/DynamicLibrary/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,16 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
3333
endif()
3434

3535
function(dynlib_add_module NAME)
36-
add_library(${NAME} MODULE
36+
add_llvm_library(${NAME} MODULE BUILDTREE_ONLY
3737
PipSqueak.cpp
38-
)
38+
)
3939
set_target_properties(${NAME} PROPERTIES FOLDER "LLVM/Tests/Support")
4040

4141
set_output_directory(${NAME}
4242
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
4343
LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
4444
)
4545

46-
set_target_properties(${NAME}
47-
PROPERTIES PREFIX ""
48-
SUFFIX ${LLVM_PLUGIN_EXT}
49-
)
50-
5146
add_dependencies(DynamicLibraryTests ${NAME})
5247

5348
if(LLVM_INTEGRATED_CRT_ALLOC)

0 commit comments

Comments
 (0)