sd-dlopen: introduce _dlopen_loader_ macro to prevent inlining and cloning
When compiler optimization or LTO (Link Time Optimization) is enabled, dlopen helper functions (such as dlopen_libfoo()) can be aggressively inlined into their callers or cloned for specific call sites. While this is beneficial for production builds, it alters or completely removes the original function symbols from the final executable. Consequently, this breaks the test (to be added in this series) that checks whether the dlopen_libfoo() function corresponding to a dlopen ELF note is actually called. To resolve this, introduce the `_dlopen_loader_` macro. Under developer builds, it applies the `_noclone_` and `_noinline_` attributes to guarantee that helper symbols remain intact and discoverable by the test suite. In production builds, the macro evaluates to nothing, allowing full compiler optimization to proceed unimpeded.
This commit is contained in:
@@ -47,7 +47,6 @@
|
||||
#include "bitfield.h"
|
||||
#include "compress.h"
|
||||
#include "dlfcn-util.h"
|
||||
#include "dlopen-note.h"
|
||||
#include "io-util.h"
|
||||
#include "log.h"
|
||||
#include "string-table.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "basic-forward.h"
|
||||
#include "dlopen-note.h"
|
||||
|
||||
typedef enum Compression {
|
||||
COMPRESSION_NONE,
|
||||
@@ -80,11 +81,11 @@ int compress_stream(Compression type, int fdf, int fdt, uint64_t max_bytes, uint
|
||||
int decompress_stream(Compression type, int fdf, int fdt, uint64_t max_bytes);
|
||||
int decompress_stream_by_filename(const char *filename, int fdf, int fdt, uint64_t max_bytes);
|
||||
|
||||
int dlopen_xz(int log_level);
|
||||
int dlopen_lz4(int log_level);
|
||||
int dlopen_zstd(int log_level);
|
||||
int dlopen_zlib(int log_level);
|
||||
int dlopen_bzip2(int log_level);
|
||||
int dlopen_xz(int log_level) _dlopen_loader_;
|
||||
int dlopen_lz4(int log_level) _dlopen_loader_;
|
||||
int dlopen_zstd(int log_level) _dlopen_loader_;
|
||||
int dlopen_zlib(int log_level) _dlopen_loader_;
|
||||
int dlopen_bzip2(int log_level) _dlopen_loader_;
|
||||
|
||||
static inline const char* default_compression_extension(void) {
|
||||
return compression_extension_to_string(DEFAULT_COMPRESSION) ?: "";
|
||||
|
||||
@@ -6,6 +6,16 @@
|
||||
#include "basic-forward.h"
|
||||
#include "strv.h"
|
||||
|
||||
/* Prevent dlopen helper functions (e.g., dlopen_libfoo()) from being inlined or cloned by the compiler/LTO.
|
||||
* This ensures that their specific symbols remain intact in the final executable, allowing the developer
|
||||
* test utility to verify that the functions corresponding to the dlopen ELF notes are actually invoked.
|
||||
* This is restricted to BUILD_MODE_DEVELOPER to avoid degrading production performance. */
|
||||
#if BUILD_MODE_DEVELOPER
|
||||
# define _dlopen_loader_ _noclone_ _noinline_
|
||||
#else
|
||||
# define _dlopen_loader_
|
||||
#endif
|
||||
|
||||
/* Avoid invalid priority. */
|
||||
#define _DLOPEN_CHECK_PRIORITY_required 1
|
||||
#define _DLOPEN_CHECK_PRIORITY_recommended 1
|
||||
|
||||
Reference in New Issue
Block a user