-
Notifications
You must be signed in to change notification settings - Fork 41
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
Allow to dlopen compression libraries #262
Conversation
88ae20b
to
4f38062
Compare
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.
Nice, thanks for beating me to it.
1087c45
to
3114741
Compare
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.
Left a bunch of minimal - nice to have - comments.
The -D use-dlopen=true
(or equiv) would be amazing to have both so a) we don't need to check for all permutations and b) distributions don't shoot themselves in the foot.
Heavily based on systemd: add similar (but simplified) functions to dlopen() a library and load specific symbols from it. This will be useful to allow to load the compression libraries as needed. A few differences from the systemd implementation: 1) It's allowed to link directly to the library and hence bypass the dlopen() + dlsym() 2) The only entrypoint is dlsym_many() which is already declared with the sentinel: it's expected callers will use an x-macro that doesn't allow forgetting the sentinel 3) No support yet for ELF info annotation yet Signed-off-by: Lucas De Marchi <[email protected]>
Use dlfcn helpers to load liblzma once it's needed. Signed-off-by: Lucas De Marchi <[email protected]>
Use the libkmod-file-xz.c as reference, keeping similar variable names so it's easy to share code. Signed-off-by: Lucas De Marchi <[email protected]>
Use dlfcn helpers to load libz once it's needed. Signed-off-by: Lucas De Marchi <[email protected]>
size_t is unsigned, while the function returns a negative number. Instead of using `ret` for the return from ZSTD_decompress(), re-use dst_size that should be the same as we passed in for that call since it already checks for ZSTD_CONTENTSIZE_UNKNOWN and ZSTD_CONTENTSIZE_ERROR. Even if it's not the same, it's more correct to use that value to assign to file->size to avoid accessing uninitialized memory. Signed-off-by: Lucas De Marchi <[email protected]>
Use dlfcn helpers to load libzstd once it's needed. Signed-off-by: Lucas De Marchi <[email protected]>
Define either to 0 or 1 so codebase is forced to used `#if ENABLE_*` or similar. It's confusing to have some leaving undefined and others defining as 0 or 1. Signed-off-by: Lucas De Marchi <[email protected]>
Move libs to a table, similarly to how other things are handled, so this logic can be more easily expanded in future for all compression types. Signed-off-by: Lucas De Marchi <[email protected]>
Keep the logic similar for all libraries. While at it, add a comment divider for the config output. Signed-off-by: Lucas De Marchi <[email protected]>
Add a dlopen option that allows toggling what libraries libkmod should attempt to dlopen. If -Ddlopen=foo is passed, it means that library is required to build, regardless of -Dfoo=*. However that library will only be linked in if it's not set as dlopen. Signed-off-by: Lucas De Marchi <[email protected]>
Follow the new spec for ELF notes as detailed in https://systemd.io/ELF_PACKAGE_METADATA/. We can copy mostly verbatim the macros from systemd codebase. Example output: $ meson setup --native-file build-dev.ini -Dxz=disabled -Ddlopen=zlib build ... dlopen : zlib features : +ZSTD -XZ +ZLIB +OPENSSL $ dlopen-notes.py build/libkmod.so.2 # build/libkmod.so.2 [ { "feature": "xz", "description": "Support for uncompressing xz-compressed modules", "priority": "recommended", "soname": [ "liblzma.so.5" ] } ] Signed-off-by: Lucas De Marchi <[email protected]>
The second check is a "should fail" check, but it will fail because the build dir already exists rather than for the true reason. Use a different dir for the configure tests and move the `rm` inside the function. Signed-off-by: Lucas De Marchi <[email protected]>
Signed-off-by: Lucas De Marchi <[email protected]>
Test disabling one of the compression libs while dlopen'ing the rest and handling 1 linked and 2 dlopen'ed. Signed-off-by: Lucas De Marchi <[email protected]>
3114741
to
4d875e9
Compare
merged this by mistake while merging #264 |
Heavily based on systemd: add similar (but simplified) functions to dlopen() a library and load specific symbols from it. This will be useful to allow to load the compression libraries as needed. A few differences from the systemd implementation: 1) It's allowed to link directly to the library and hence bypass the dlopen() + dlsym() 2) The only entrypoint is dlsym_many() which is already declared with the sentinel: it's expected callers will use an x-macro that doesn't allow forgetting the sentinel 3) No support yet for ELF info annotation yet Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Use dlfcn helpers to load liblzma once it's needed. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Use the libkmod-file-xz.c as reference, keeping similar variable names so it's easy to share code. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Use dlfcn helpers to load libz once it's needed. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
size_t is unsigned, while the function returns a negative number. Instead of using `ret` for the return from ZSTD_decompress(), re-use dst_size that should be the same as we passed in for that call since it already checks for ZSTD_CONTENTSIZE_UNKNOWN and ZSTD_CONTENTSIZE_ERROR. Even if it's not the same, it's more correct to use that value to assign to file->size to avoid accessing uninitialized memory. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Use dlfcn helpers to load libzstd once it's needed. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Define either to 0 or 1 so codebase is forced to used `#if ENABLE_*` or similar. It's confusing to have some leaving undefined and others defining as 0 or 1. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Move libs to a table, similarly to how other things are handled, so this logic can be more easily expanded in future for all compression types. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Keep the logic similar for all libraries. While at it, add a comment divider for the config output. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Add a dlopen option that allows toggling what libraries libkmod should attempt to dlopen. If -Ddlopen=foo is passed, it means that library is required to build, regardless of -Dfoo=*. However that library will only be linked in if it's not set as dlopen. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Follow the new spec for ELF notes as detailed in https://systemd.io/ELF_PACKAGE_METADATA/. We can copy mostly verbatim the macros from systemd codebase. Example output: $ meson setup --native-file build-dev.ini -Dxz=disabled -Ddlopen=zlib build ... dlopen : zlib features : +ZSTD -XZ +ZLIB +OPENSSL $ dlopen-notes.py build/libkmod.so.2 # build/libkmod.so.2 [ { "feature": "xz", "description": "Support for uncompressing xz-compressed modules", "priority": "recommended", "soname": [ "liblzma.so.5" ] } ] Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
The second check is a "should fail" check, but it will fail because the build dir already exists rather than for the true reason. Use a different dir for the configure tests and move the `rm` inside the function. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Test disabling one of the compression libs while dlopen'ing the rest and handling 1 linked and 2 dlopen'ed. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Add a dlopen option that allows toggling what libraries libkmod should attempt to dlopen. If -Ddlopen=foo is passed, it means that library is required to build, regardless of -Dfoo=*. However that library will only be linked in if it's not set as dlopen. Signed-off-by: Lucas De Marchi <[email protected]> [ with disagreement on the need to toggle each one individually, it'd be better to be all-or-nothing dlopen'ed ] Reviewed-by: Emil Velikov <[email protected]> Link: #262
Follow the new spec for ELF notes as detailed in https://systemd.io/ELF_PACKAGE_METADATA/. We can copy mostly verbatim the macros from systemd codebase. Example output: $ meson setup --native-file build-dev.ini -Dxz=disabled -Ddlopen=zlib build ... dlopen : zlib features : +ZSTD -XZ +ZLIB +OPENSSL $ dlopen-notes.py build/libkmod.so.2 # build/libkmod.so.2 [ { "feature": "xz", "description": "Support for uncompressing xz-compressed modules", "priority": "recommended", "soname": [ "liblzma.so.5" ] } ] Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
The second check is a "should fail" check, but it will fail because the build dir already exists rather than for the true reason. Use a different dir for the configure tests and move the `rm` inside the function. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
Test disabling one of the compression libs while dlopen'ing the rest and handling 1 linked and 2 dlopen'ed. Signed-off-by: Lucas De Marchi <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Link: #262
and now pushed the right version |
Allow to dlopen the compression libraries so distros can choose one to match the MODULE_COMPRESS_* option in the kernel, while still allowing to work with other compressed formats.
I'm not very happy with the meson integration, but I gave up while trying to handle the dependencies between the options.
Still missing here: the ELF note to declare the implicit dependency.Closes: #48