-
Notifications
You must be signed in to change notification settings - Fork 43
Add plugin activity log file functionality #588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
parth-07
wants to merge
1
commit into
qualcomm:main
Choose a base branch
from
parth-07:PrimitivePluginActLog
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //===- LinkState.h--------------------------------------------------------===// | ||
| // Part of the eld Project, under the BSD License | ||
| // See https://github.com/qualcomm/eld/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef ELD_CORE_LINKSTATE_H | ||
| #define ELD_CORE_LINKSTATE_H | ||
|
|
||
| #include "llvm/ADT/StringRef.h" | ||
| #include "llvm/Support/ErrorHandling.h" | ||
| namespace eld { | ||
| /// Stages of the link process. | ||
| /// What actions a plugin can perform depends on the | ||
| /// link state. For example: | ||
| /// - Plugins can change the output section of an input | ||
| /// section only in BeforeLayout link state. | ||
| /// - Plugins can move chunks from one output section to | ||
| /// another only in CreatingSections link state. | ||
| /// - Plugins can only compute the output image layout checkum using | ||
| /// `LinkerWrapper::getImageLayoutChecksum` only in AfterLayout linker | ||
| /// state. | ||
| /// - Plugins can reassign virtual addresses using | ||
| /// `LinkerWrapper::reassignVirtualAddresses()` only in CreatingSegments | ||
| /// link state. | ||
| /// | ||
| /// Plugin authors should ensure that the action being performed by the | ||
| /// plugin is meaningful in the link state in which it is executed. | ||
| /// Executing invalid actions for a link state can result in undefined | ||
| /// behavior. | ||
| enum LinkState : uint8_t { | ||
| Unknown, | ||
| Initializing, | ||
| BeforeLayout, | ||
| CreatingSections, | ||
| CreatingSegments, | ||
| AfterLayout, | ||
| }; | ||
|
|
||
| static inline llvm::StringRef getLinkStateStrRef(LinkState State) { | ||
| #define ADD_CASE(S) \ | ||
| case LinkState::S: \ | ||
| return #S; | ||
| switch (State) { | ||
| ADD_CASE(Unknown) | ||
| ADD_CASE(Initializing) | ||
| ADD_CASE(BeforeLayout) | ||
| ADD_CASE(CreatingSections) | ||
| ADD_CASE(CreatingSegments) | ||
| ADD_CASE(AfterLayout) | ||
| } | ||
| #undef ADD_CASE | ||
| llvm_unreachable("Invalid LinkState"); | ||
quic-seaswara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } // namespace eld | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ namespace eld { | |
|
|
||
| class DiagnosticEngine; | ||
| class ELFSection; | ||
| class GeneralOptions; | ||
| class LinkerConfig; | ||
| class Module; | ||
| class ResolveInfo; | ||
|
|
@@ -127,6 +128,11 @@ class Fragment { | |
|
|
||
| bool originatesFromPlugin(const Module &Module) const; | ||
|
|
||
| /// Returns a string containing basic fragment information, such as, section | ||
| /// and input file name. It is intended to be used for printing to log files, | ||
| /// diagnostics, or for quick debugging. | ||
| std::string str(const GeneralOptions &Options) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toString ? it might be easy to grep for the occurence and find out in the source code, str makes it very difficult. |
||
|
|
||
| private: | ||
| Fragment(const Fragment &); // DO NOT IMPLEMENT | ||
| Fragment &operator=(const Fragment &); // DO NOT IMPLEMENT | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //===- PluginData.h--------------------------------------------------------===// | ||
| // Part of the eld Project, under the BSD License | ||
| // See https://github.com/qualcomm/eld/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef ELD_PLUGIN_PLUGINACTIVITYLOG_H | ||
| #define ELD_PLUGIN_PLUGINACTIVITYLOG_H | ||
| #include "eld/Plugin/PluginOp.h" | ||
| #include "llvm/Support/FileSystem.h" | ||
| #include "llvm/Support/JSON.h" | ||
| #include <functional> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| namespace eld { | ||
| class GeneralOptions; | ||
| class Plugin; | ||
|
|
||
| /// Records ordered plugin operations. | ||
| class PluginActivityLog { | ||
| public: | ||
| PluginActivityLog(const GeneralOptions &GO, | ||
| const std::vector<Plugin *> &pAllPlugins) | ||
| : Options(GO), AllPlugins(pAllPlugins) {} | ||
|
|
||
| void addPluginOperation(PluginOp &Op) { | ||
| PluginOperations.push_back(std::ref(Op)); | ||
| } | ||
|
|
||
| /// Emit ordered plugin operations to a JSON file for analysis. | ||
| bool print(llvm::StringRef Filename) const; | ||
|
|
||
| void recordPluginLibrary(void *Handle, std::string Path) { | ||
| PluginLibraryHandleToPathMap[Handle] = Path; | ||
| } | ||
|
|
||
| std::string getPluginLibraryPath(void *LibHandle) const { | ||
| auto It = PluginLibraryHandleToPathMap.find(LibHandle); | ||
| if (It != PluginLibraryHandleToPathMap.end()) | ||
| return It->second; | ||
| return ""; | ||
| } | ||
|
|
||
| private: | ||
| // Convert a PluginOp to JSON based on its dynamic type. | ||
| llvm::json::Object toJSON(const PluginOp &Op) const; | ||
|
|
||
| // Overloads for each concrete PluginOp to extract a minimal JSON payload. | ||
| llvm::json::Object toJSON(const ChangeOutputSectionPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const AddChunkPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const RemoveChunkPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const UpdateChunksPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const RemoveSymbolPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const RelocationDataPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const UpdateLinkStatsPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const UpdateRulePluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const ResetOffsetPluginOp &P) const; | ||
|
|
||
| llvm::json::Object toJSON(const UpdateLinkStateOp &P) const; | ||
|
|
||
| llvm::json::Object getBaseActivityJSONObject(const PluginOp &Op) const; | ||
|
|
||
| llvm::json::Array getPluginActivities() const; | ||
|
|
||
| llvm::json::Array getPluginsInfo() const; | ||
|
|
||
| private: | ||
| std::vector<std::reference_wrapper<PluginOp>> PluginOperations; | ||
| const GeneralOptions &Options; | ||
| const std::vector<Plugin *> &AllPlugins; | ||
| std::unordered_map<void *, std::string> PluginLibraryHandleToPathMap; | ||
| }; | ||
| } // namespace eld | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.