linux-sysprog · intermediate · ~15 min

Resolve a plugin's required symbols

The set-difference primitive that every plugin loader runs.

Challenge

You're writing the contract for a plugin loader. Each plugin must expose a set of named functions; the loader walks them and reports which are missing.

Implement int count_missing_symbols(const char *plugin_symbols[], int n_plug, const char *required[], int n_req).

plugin_symbols[] is the list of symbols the plugin actually exports; required[] is the list the loader needs. Return the count of required symbols not present in plugin_symbols.

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

Two arrays of symbol-name strings.

Output format

Count of missing.

Constraints

O(n_req * n_plug). String compare.

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.