Skip to content

docs: document the extern "C" module_register() requirement for dynamically loaded modules - #100

Open
MAN$I VERMA (mansiverma897993) wants to merge 2 commits into
qualcomm:mainfrom
mansiverma897993:docs-dylib-module-register-extern-c
Open

docs: document the extern "C" module_register() requirement for dynamically loaded modules#100
MAN$I VERMA (mansiverma897993) wants to merge 2 commits into
qualcomm:mainfrom
mansiverma897993:docs-dylib-module-register-extern-c

Conversation

@mansiverma897993

Copy link
Copy Markdown

Summary

Fixes #90

The module factory loads out-of-tree components by resolving the unmangled symbol module_register in the shared library named via dylib_path/moduletype (register_module_from_dylib() in module_factory_container.h). The hook must therefore be declared extern "C" -- as every in-tree component does -- but this requirement was not documented, and missing it produces a misleading failure: the library loads, registration is skipped with only a warning, and elaboration aborts with Can't find module type: <X>, which points at the configuration rather than at C++ name mangling.

Changes

Documentation

  • docs/configuration.md: new Loading Components from Shared Libraries section documenting how the library name is resolved (dylib_path, falling back to moduletype, plus the platform extension) and the module_register() contract: the hook must be exported with C linkage and must register the component under the same name used as moduletype (via GSC_MODULE_REGISTER_C), with a minimal header/source example mirroring the in-tree pattern (e.g. keep_alive.h). It also documents the failure mode when extern "C" is missing, and the subtlety that the definition picks up C linkage from the declaration in the included header.
  • docs/backends.md: the Lua example there was the only place dylib_path appeared in the docs -- added a short note next to it cross-referencing the new section.

Diagnostics (module_factory_container.h)

  • The SCP_WARN emitted when module_register is not found in a successfully loaded library now names the likely cause (missing extern "C" linkage, so the exported symbol is mangled).
  • The SC_REPORT_ERROR in construct_module() -- the message users actually see -- now explains, when a library was loaded but the requested type is still unregistered, that the library must export extern "C" void module_register() and that the hook must register the exact requested type name.

On the issue's suggestion to escalate the warning to an error: it is kept as a warning deliberately. A library can legitimately register its types from static initializers at load time (e.g. GSC_MODULE_REGISTER_C at global scope) without exporting a module_register hook, and escalating would break that case. Instead, the fatal-by-default construct_module error now carries the full hint at the point where the failure is certain.

Testing

  • The docs changes are markdown only.
  • The header change only rewords two diagnostic messages; verified clang-format-clean against the repo's .clang-format.

…ister() with extern "C"

The module factory resolves out-of-tree components by looking up the
unmangled symbol module_register in the library named by dylib_path (or
moduletype). This only works when the hook is declared extern "C", as
every in-tree component does, but the requirement was not documented
anywhere: a plain C++ definition exports a mangled symbol, registration
is silently skipped, and elaboration fails with a misleading
"Can't find module type" error.

Add a 'Loading Components from Shared Libraries' section to
docs/configuration.md describing the lookup and the module_register()
contract, and cross-reference it from the dylib_path example in
docs/backends.md.

Fixes qualcomm#90

Signed-off-by: mansiverma897993 <vmansi756@gmail.com>
… contract in dylib diagnostics

When a library loaded via dylib_path exports no module_register symbol
(typically because the hook lacks extern "C" and is mangled), the only
hint was an easy-to-miss warning, and elaboration then aborted with
"Can't find module type" - which suggests a wrong moduletype string
rather than a linkage problem.

Name the likely cause in the warning, and extend the construct_module
error to explain the registration contract when a loaded library did
not register the requested type. The warning stays a warning: a library
may legitimately register its types from static initializers at load
time without exporting module_register.

Fixes qualcomm#90

Signed-off-by: mansiverma897993 <vmansi756@gmail.com>
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.

docs: dynamically loaded modules must export module_register() with extern "C" — requirement is undocumented and the failure mode points elsewhere

1 participant