Optimize dlopen ELF notes via anchoring and explicitly embed them into executables (#42908)
This PR optimizes the handling of `dlopen` ELF notes and reduces binary footprints across the tree. By enabling compiler section-splitting (`-ffunction-sections`/`-fdata-sections`), the linker can now accurately garbage-collect unused code and data. To align with this, `SD_ELF_NOTE_DLOPEN_ANCHORED()` macro is introduced, which ties `dlopen` notes to their calling functions so that unused notes are automatically removed by `--gc-sections`. Additionally, this explicitly embeds required `dlopen` notes into individual executables to fix a visibility issue where package managers missed runtime dependencies invoked indirectly through `libsystemd-shared.so`.
This commit is contained in:
@@ -47,7 +47,11 @@ executables += [
|
||||
executable_template['include_directories'],
|
||||
],
|
||||
'dependencies' : [
|
||||
libacl_cflags,
|
||||
libblkid_cflags,
|
||||
libcryptsetup_cflags,
|
||||
libmount_cflags,
|
||||
libopenssl_cflags,
|
||||
libseccomp_cflags,
|
||||
libselinux_cflags,
|
||||
],
|
||||
|
||||
@@ -1826,7 +1826,7 @@ static int oci_seccomp(const char *name, sd_json_variant *v, sd_json_dispatch_fl
|
||||
if (r < 0)
|
||||
return json_log(def, flags, r, "Unknown default action: %s", sd_json_variant_string(def));
|
||||
|
||||
r = DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
|
||||
r = DLOPEN_LIBSECCOMP(LOG_DEBUG, recommended);
|
||||
if (r < 0)
|
||||
return json_log(def, flags, r, "No support for libseccomp: %m");
|
||||
|
||||
|
||||
+11
-4
@@ -20,9 +20,11 @@
|
||||
#include "sd-path.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "acl-util.h"
|
||||
#include "alloc-util.h"
|
||||
#include "barrier.h"
|
||||
#include "base-filesystem.h"
|
||||
#include "blkid-util.h"
|
||||
#include "btrfs-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-error.h"
|
||||
@@ -36,12 +38,13 @@
|
||||
#include "constants.h"
|
||||
#include "copy.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "crypto-util.h"
|
||||
#include "cryptsetup-util.h"
|
||||
#include "daemon-util.h"
|
||||
#include "dev-setup.h"
|
||||
#include "devnum-util.h"
|
||||
#include "discover-image.h"
|
||||
#include "dissect-image.h"
|
||||
#include "dlfcn-util.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "ether-addr-util.h"
|
||||
@@ -6141,9 +6144,13 @@ static int run(int argc, char *argv[]) {
|
||||
if (arg_cleanup)
|
||||
return do_cleanup();
|
||||
|
||||
(void) DLOPEN_LIBMOUNT(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
|
||||
(void) DLOPEN_LIBSECCOMP(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
|
||||
(void) DLOPEN_LIBSELINUX(LOG_DEBUG, SD_ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED);
|
||||
(void) DLOPEN_CRYPTSETUP(LOG_DEBUG, suggested);
|
||||
(void) DLOPEN_LIBACL(LOG_DEBUG, recommended);
|
||||
(void) DLOPEN_LIBBLKID(LOG_DEBUG, recommended);
|
||||
(void) DLOPEN_LIBCRYPTO(LOG_WARNING, recommended);
|
||||
(void) DLOPEN_LIBMOUNT(LOG_DEBUG, recommended);
|
||||
(void) DLOPEN_LIBSECCOMP(LOG_DEBUG, recommended);
|
||||
(void) DLOPEN_LIBSELINUX(LOG_DEBUG, recommended);
|
||||
|
||||
r = cg_has_legacy();
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user