-
Notifications
You must be signed in to change notification settings - Fork 8.2k
LLEXT: add discarded symbol groups inspector #99413
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
base: main
Are you sure you want to change the base?
LLEXT: add discarded symbol groups inspector #99413
Conversation
Move ELF-related utilities from the "llext_prepare_exptab" script to a dedicated "llext_elf_toolkit" which can be reused by other LLEXT scripts. While at it, also improve documentation of class SectionDescriptor. Signed-off-by: Mathieu Choplain <[email protected]>
When the LLEXT subsystem detects that a symbol is marked for export from the main image, but the symbol group in which the export belongs is not enabled, add a marker in a special section in addition to not placing the symbol in the final export table. Add a post-build script which consumes the special section as post-build to dump information about all discarded symbols in a build artifact, and also check for common errors (missing Kconfig symbol / improperly named groups). Signed-off-by: Mathieu Choplain <[email protected]>
| def parse_dotconfig(dotconfig_path: Path): | ||
| """ | ||
| Parses symbols from `.config` file at location 'dotconfig_path'. | ||
|
|
||
| Note: tri-state `"m"` is transformed into integer `2`. | ||
| """ | ||
| # Symbols should receive value 'n' if a line | ||
| # containing 'CONFIG_xxx is not set' is present | ||
| CONFIG_NOT_SET_REGEXP = re.compile(r"# (CONFIG_.+) is not set") | ||
|
|
||
| symbols: dict[str, str | int | bool] = {} | ||
|
|
||
| with dotconfig_path.open("r") as fd: | ||
| for line in fd: | ||
| line = line.strip() | ||
| if len(line) <= 1: | ||
| continue | ||
|
|
||
| # Handle comment lines | ||
| if line[0] == '#': | ||
| if match := CONFIG_NOT_SET_REGEXP.match(line): | ||
| symbols[match.group(1)] = False | ||
| continue | ||
|
|
||
| key, value = line.split("=") | ||
|
|
||
| if value == "y": | ||
| value = True | ||
| elif value == "n": | ||
| value = False | ||
| elif value == "m": | ||
| value = 2 | ||
| elif value[0] == value[-1] == '"': | ||
| value = value.strip('"') | ||
| else: | ||
| value = int(value, base=0) | ||
|
|
||
| symbols[key] = value | ||
|
|
||
| return symbols |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I thought about using kconfiglib like a good citizen, but it's much less trivial to use than I hoped... c.f.:
zephyr/cmake/modules/kconfig.cmake
Lines 138 to 163 in 9c1fbc8
| set(COMMON_KCONFIG_ENV_SETTINGS | |
| PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} | |
| srctree=${ZEPHYR_BASE} | |
| ${kconfig_env_dirs} | |
| KERNELVERSION=${KERNELVERSION} | |
| APPVERSION=${APP_VERSION_STRING} | |
| APP_VERSION_EXTENDED_STRING=${APP_VERSION_EXTENDED_STRING} | |
| APP_VERSION_TWEAK_STRING=${APP_VERSION_TWEAK_STRING} | |
| APP_DIR=${APP_DIR} | |
| CONFIG_=${KCONFIG_NAMESPACE}_ | |
| KCONFIG_CONFIG=${DOTCONFIG} | |
| KCONFIG_BOARD_DIR=${KCONFIG_BOARD_DIR} | |
| BOARD=${BOARD} | |
| BOARD_REVISION=${BOARD_REVISION} | |
| BOARD_QUALIFIERS=${BOARD_QUALIFIERS} | |
| HWM_SCHEME=${HWM} | |
| KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR} | |
| APPLICATION_SOURCE_DIR=${APPLICATION_SOURCE_DIR} | |
| ZEPHYR_TOOLCHAIN_VARIANT=${ZEPHYR_TOOLCHAIN_VARIANT} | |
| TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR} | |
| TOOLCHAIN_HAS_NEWLIB=${_local_TOOLCHAIN_HAS_NEWLIB} | |
| TOOLCHAIN_HAS_PICOLIBC=${_local_TOOLCHAIN_HAS_PICOLIBC} | |
| EDT_PICKLE=${EDT_PICKLE} | |
| # Export all Zephyr modules to Kconfig | |
| ${ZEPHYR_KCONFIG_MODULES_DIR} | |
| ) |
|



Follow-up to #98990 (c.f. #98990 (comment))
When the LLEXT subsystem detects that a symbol is marked for export from the main image, but the symbol group in which the export belongs is not enabled, add a marker in a special section in addition to not placing the symbol in the final export table.
Add a post-build script which consumes the special section as post-build to dump information about all discarded symbols in a build artifact, and also check for common errors (missing Kconfig symbol / improperly named groups).
While at it, rework LLEXT scripts organization a little bit - maybe a dedicated
scripts/llextdirectory is starting to make sense though... I also wanted to create a${PROJECT_BINARY_DIR}/llextdirectory for all artifacts, but I'm not super confident about how to ensure CMake will create said directory, so the report is in artifacts root for now (like SLID listings).There's also a bit more clean-up I found along the way (namely: a single
llext_discarded_strtabcould replace the two sectionsllext_discarded_exports_strtab+llext_exports_strtab, andread_strcould possibly be shared between scripts), but that can always come later.Example output on
west build samples/subsys/llext/modules:Example build log + output when a group Kconfig is missing: