linux-sysprog · intermediate · ~15 min

Resolve a plugin's required symbols

The set-difference primitive that every plugin loader runs.

Challenge

Check a plugin against the symbols a loader requires, and count how many required symbols the plugin does not export — the validation a dlopen-based loader runs before calling into a module.

Task

Implement int count_missing_symbols(const char *plugin_symbols[], int n_plug, const char *required[], int n_req) that returns how many required symbols are absent.

Input

  • plugin_symbols, n_plug: the names of symbols the plugin actually exports.
  • required, n_req: the names the loader needs.

Output

Returns the number of entries in required that do not appear in plugin_symbols (compared by string value).

Example

plug = {"init","tick","shutdown"}, req = {"init","tick","shutdown"}
count_missing_symbols(plug, 3, req, 3)   ->   0
plug = {"init"}, req = {"init","tick","shutdown"}
count_missing_symbols(plug, 1, req, 3)   ->   2
count_missing_symbols(NULL, 0, req, 3)   ->   3   (nothing exported)
count_missing_symbols(plug, 3, NULL, 0)  ->   0   (nothing required)

Edge cases

  • An empty required list returns 0.
  • An empty plugin returns n_req (all required symbols missing).

Why this matters

dlopen lets a program load a shared library at runtime and resolve named symbols. A defensive plugin loader checks every required symbol BEFORE running any code from the module.

Input format

plugin_symbols[n_plug] (symbols the plugin exports) and required[n_req] (symbols the loader needs).

Output format

The count of required symbols not present in plugin_symbols.

Constraints

Compare symbol names with strcmp. Empty required -> 0; empty plugin -> n_req.

Starter code

#include <stddef.h>
int count_missing_symbols(const char *plugin_symbols[], int n_plug, const char *required[], int n_req) { /* TODO */ (void)plugin_symbols; (void)n_plug; (void)required; (void)n_req; return 0; }

Common mistakes

Returning the count present instead of missing.

Edge cases to handle

Empty required (return 0). Empty plugin (return n_req).

Complexity

O(n_req * n_plug).

Background lessons

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.