Skip to content

Commit 6ea94cb

Browse files
committed
fix
1 parent 4aaf28f commit 6ea94cb

File tree

13 files changed

+78
-100
lines changed

13 files changed

+78
-100
lines changed

llvm/lib/Passes/PassPlugin.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,20 @@
1414
using namespace llvm;
1515

1616
Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {
17-
// First, see if the plugin is available in the current executable, with the
18-
// suffix of the symbol being given by the `Filename` otherwise, try loading
19-
// the plugin via the file
2017
std::string Error;
21-
22-
auto Library = sys::DynamicLibrary::getPermanentLibrary(nullptr, &Error);
18+
auto Library =
19+
sys::DynamicLibrary::getPermanentLibrary(Filename.c_str(), &Error);
2320
if (!Library.isValid())
24-
return make_error<StringError>("Could not load current executable",
21+
return make_error<StringError>(Twine("Could not load library '") +
22+
Filename + "': " + Error,
2523
inconvertibleErrorCode());
2624

25+
PassPlugin P{Filename, Library};
26+
2727
// llvmGetPassPluginInfo should be resolved to the definition from the plugin
2828
// we are currently loading.
29-
std::string symbolName = "llvmGetPassPluginInfo" + Filename;
3029
intptr_t getDetailsFn =
31-
(intptr_t)Library.getAddressOfSymbol(symbolName.c_str());
32-
33-
if (!getDetailsFn) {
34-
Library = sys::DynamicLibrary::getPermanentLibrary(
35-
(Filename == "") ? nullptr : Filename.c_str(), &Error);
36-
if (!Library.isValid())
37-
return make_error<StringError>(Twine("Could not load library '") +
38-
Filename + "': " + Error,
39-
inconvertibleErrorCode());
40-
41-
// llvmGetPassPluginInfo should be resolved to the definition from the
42-
// plugin we are currently loading.
43-
getDetailsFn =
44-
(intptr_t)Library.getAddressOfSymbol("llvmGetPassPluginInfo");
45-
}
46-
47-
PassPlugin P{Filename, Library};
30+
(intptr_t)Library.getAddressOfSymbol("llvmGetPassPluginInfo");
4831

4932
if (!getDetailsFn)
5033
// If the symbol isn't found, this is probably a legacy plugin, which is an

llvm/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ set(LLVM_TEST_DEPENDS
138138
not
139139
obj2yaml
140140
opt
141+
opt-printplugin
141142
sancov
142143
sanstats
143144
split-file

llvm/test/Feature/load_staticextension.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; REQUIRES: x86-registered-target
2-
; RUN: opt-printplugin %s -load-pass-plugin="PrintPlugin" -passes="printpass" -disable-output 2>&1 | FileCheck %s
2+
; RUN: opt-printplugin %s -passes="printpass" -disable-output 2>&1 | FileCheck %s
33

44
; REQUIRES: plugins
55

llvm/tools/opt/CMakeLists.txt

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,6 @@ set(LLVM_LINK_COMPONENTS
2929
Passes
3030
)
3131

32-
# We don't want to link this into libLLVM
33-
add_llvm_library(LLVMOptDriver
34-
STATIC
35-
NewPMDriver.cpp
36-
optdriver.cpp
37-
PARTIAL_SOURCES_INTENDED
38-
DEPENDS
39-
intrinsics_gen
40-
)
41-
42-
add_llvm_tool(opt
43-
PARTIAL_SOURCES_INTENDED
44-
opt.cpp
45-
DEPENDS
46-
intrinsics_gen
47-
SUPPORT_PLUGINS
48-
49-
)
50-
target_link_libraries(opt PRIVATE LLVMOptDriver)
51-
52-
export_executable_symbols_for_plugins(opt)
53-
54-
if (LLVM_ENABLE_PLUGINS)
55-
add_llvm_tool(opt-printplugin
56-
NewPMDriver.cpp
57-
opt.cpp
58-
PrintPlugin.cpp
59-
60-
DEPENDS
61-
intrinsics_gen
62-
SUPPORT_PLUGINS
63-
)
64-
target_link_options(opt-printplugin PUBLIC -Wl,--export-dynamic-symbol=llvmGetPassPluginInfoPrintPlugin)
65-
endif()
32+
add_subdirectory(lib)
33+
add_subdirectory(driver)
34+
add_subdirectory(test)

llvm/tools/opt/driver/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_llvm_tool(opt
2+
opt.cpp
3+
DEPENDS
4+
intrinsics_gen
5+
SUPPORT_PLUGINS
6+
)
7+
target_link_libraries(opt PRIVATE LLVMOptDriver)
8+
export_executable_symbols_for_plugins(opt)
File renamed without changes.

llvm/tools/opt/lib/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# We don't want to link this into libLLVM
2+
add_llvm_library(LLVMOptDriver
3+
STATIC
4+
NewPMDriver.cpp
5+
optdriver.cpp
6+
PARTIAL_SOURCES_INTENDED
7+
DEPENDS
8+
intrinsics_gen
9+
)

llvm/tools/opt/NewPMDriver.cpp renamed to llvm/tools/opt/lib/NewPMDriver.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ cl::opt<bool> VerifyEachDebugInfoPreserve(
5757
cl::desc("Start each pass with collecting and end it with checking of "
5858
"debug info preservation."));
5959

60-
cl::opt<std::string>
61-
VerifyDIPreserveExport("verify-di-preserve-export",
62-
cl::desc("Export debug info preservation failures into "
63-
"specified (JSON) file (should be abs path as we use"
64-
" append mode to insert new JSON objects)"),
65-
cl::value_desc("filename"), cl::init(""));
60+
cl::opt<std::string> VerifyDIPreserveExport(
61+
"verify-di-preserve-export",
62+
cl::desc("Export debug info preservation failures into "
63+
"specified (JSON) file (should be abs path as we use"
64+
" append mode to insert new JSON objects)"),
65+
cl::value_desc("filename"), cl::init(""));
6666

6767
} // namespace llvm
6868

@@ -163,7 +163,6 @@ static cl::opt<bool> DisablePipelineVerification(
163163
"-print-pipeline-passes can be used to create a pipeline."),
164164
cl::Hidden);
165165

166-
167166
static cl::opt<PGOKind>
168167
PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
169168
cl::desc("The kind of profile guided optimization"),
@@ -174,8 +173,8 @@ static cl::opt<PGOKind>
174173
"Use instrumented profile to guide PGO."),
175174
clEnumValN(SampleUse, "pgo-sample-use-pipeline",
176175
"Use sampled profile to guide PGO.")));
177-
static cl::opt<std::string> ProfileFile("profile-file",
178-
cl::desc("Path to the profile."), cl::Hidden);
176+
static cl::opt<std::string>
177+
ProfileFile("profile-file", cl::desc("Path to the profile."), cl::Hidden);
179178
static cl::opt<std::string>
180179
MemoryProfileFile("memory-profile-file",
181180
cl::desc("Path to the memory profile."), cl::Hidden);
@@ -411,8 +410,7 @@ bool llvm::runPassPipeline(
411410
} else if (VerifyEachDebugInfoPreserve) {
412411
Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
413412
Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
414-
Debugify.setOrigDIVerifyBugsReportFilePath(
415-
VerifyDIPreserveExport);
413+
Debugify.setOrigDIVerifyBugsReportFilePath(VerifyDIPreserveExport);
416414
Debugify.registerCallbacks(PIC, MAM);
417415
}
418416

llvm/tools/opt/NewPMDriver.h renamed to llvm/tools/opt/lib/NewPMDriver.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ enum OutputKind {
4545
OK_OutputThinLTOBitcode,
4646
};
4747
enum VerifierKind { VK_NoVerifier, VK_VerifyOut, VK_VerifyEachPass };
48-
enum PGOKind {
49-
NoPGO,
50-
InstrGen,
51-
InstrUse,
52-
SampleUse
53-
};
48+
enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse };
5449
enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
55-
}
50+
} // namespace opt_tool
5651

5752
void printPasses(raw_ostream &OS);
5853

File renamed without changes.

0 commit comments

Comments
 (0)