Skip to content
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

Panda load plugin enhancements #1371

Merged
merged 15 commits into from
Oct 31, 2023

Conversation

MarkMankins
Copy link
Collaborator

The major new functionality here is in do_check_export_symbols().

I have a rather large C++ panda plugin that I'm trying to split up into separate plugins. I would like to have a base C++ class in plugin plugin_x. I would like to have plugins plugin_y and plugin_z extend my C++ class defined in plugin_x to implement custom functionality.

This doesn't work with the current logic for loading plugins, as each plugin loaded doesn't provide symbols to subsequently loaded plugins.

do_check_export_symbols changes that behavior, but only for plugins that opt-in to the new behavior.

In plugin_x, by defining a magic symbol:

uint32_t PANDA_EXPORT_SYMBOLS_plugin_x = 1;

panda_plugin_x.so will be opened (via dlopen) with the RTLD_GLOBAL flag. This makes symbols defined in plugin_x available to subsequently loaded plugins.

The majority of the commits in this PR aren't related to this new function. I tried to clean up the various functions that deal with plugin loading and unloading, mostly in callbacks.c. It's possible I broke something here that someone was using - I can rework things if we find I did break something.

Major changes (including potential breaking changes in obscure cases):

  • Consolidated all plugin information in the panda_plugin struct. Removed panda_plugins_to_unload array and panda_plugins_loaded array.
  • Moved pypanda specific logic into their own functions.
  • Removed panda_load_external_plugin. If anyone is using this please let me know and I'll implement a replacement.
  • Replaced most printfs with calls to the appropriate logging api.
  • Plugin help output now always goes to stdout (previously it was a mix of stderr and stdout.)
  • plugin_name is now required in _panda_load_plugin (previously in some cases it was allowed to be null)
  • Previously plugins were prevented from being loaded twice by examining the list of filenames already loaded. This was changed to examine the list of plugin names instead.

@MarkMankins MarkMankins force-pushed the panda_load_plugin_enhancements branch from 4e6dc6c to 6a1c4ff Compare October 11, 2023 19:38
@lacraig2 lacraig2 marked this pull request as ready for review October 11, 2023 19:51
@lacraig2 lacraig2 marked this pull request as draft October 11, 2023 19:52
@MarkMankins MarkMankins marked this pull request as ready for review October 11, 2023 21:24
Moved the logic to dlopen libpanda into seperate utility functions.
This makes it easier to understand what _panda_load_plugin is doing.
Use the existing panda_plugins array to determine if a plugin has already
been loaded.
Added a new boolean field to panda_plugins structure to track
when a request to unload a plugin has been made.
Combine similar functions panda_require_from_library and panda_require into
a new utility.
if magic symbol PANDA_EXPORT_SYMBOLS_plugin_name is present in
the plugin being loaded.
Added an empty check for filename too.
This was probably never going to cause a problem, but the code assumed
a plugin was never greater than 256 bytes, but allowed for that case to
occur, which would cause things to break if it ever happened.
For help output, always print to stdout
Previously, running panda-system-i386 -panda osi_linux:help=y
would output that osi failed to load because PANDA_EXPORT_SYMBOLS_osi_linux
was not defined.  The error message output had nothing to do with
why osi_linux failed to load.  In this case, osi_linux doesn't
panda_require('osi') (which may be a bug) - so when it calls init_osi_api
things go sideways.  The error message was being obtained in init_osi_api
from calling dlerror() - which was reporting the missing symbol, which
isn't an error at all as the symbol is optional and not expected to be
found when loading most plugins.
@MarkMankins MarkMankins force-pushed the panda_load_plugin_enhancements branch from 6a1c4ff to 5f0c31b Compare October 31, 2023 15:34
@MarkMankins
Copy link
Collaborator Author

Rebased to latest dev.

@AndrewFasano AndrewFasano merged commit 9614031 into panda-re:dev Oct 31, 2023
27 checks passed
@AndrewFasano
Copy link
Contributor

Thanks, these seem like some great changes - I had been hoping to get more eyes on the PR before merging, but I'm sure someone will let us know if this breaks anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants