Enable LTO build (#77)

* fix(Makefile): Don't double up on optimisation flags

This is already provided by BUILD_CFLAGS later on

* feat(common): Mark explicitly-placed things as used

If we put something in a given section, we should be able to expect it to actually turn up in that section!

Doing this will prevent LTO from slurping all the hooks away as "unused".

* feat: Enable LTO

This uses "fat" binaries, so normal builds won't break, but also includes the LTO data for builds that wish to use it
This commit is contained in:
Ash 2024-12-14 21:11:07 +11:00 committed by GitHub
parent 1ac579aebb
commit 276d923569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 15 deletions

View File

@ -23,8 +23,9 @@ INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -g -O2 -Wall -Werror -save-temps \
CFLAGS := -g -Wall -Werror -save-temps \
-ffunction-sections -fdata-sections \
-flto -ffat-lto-objects \
$(MACHDEP) \
$(BUILD_CFLAGS)

View File

@ -38,11 +38,16 @@
extern "C" {
#endif
#define WUPS_SECTION(x) __attribute__((__section__(".wups." x)))
#ifdef __cplusplus
#define WUPS_EXTERN_C extern "C"
#else
#define WUPS_EXTERN_C
#endif
#define WUPS_SECTION(x) WUPS_EXTERN_C __attribute__((__section__(".wups." x), used))
#define WUPS_META(id, value) \
extern const char wups_meta_##id[] WUPS_SECTION("meta"); \
const char wups_meta_##id[] = #id "=" value
WUPS_SECTION("meta") const char wups_meta_##id[] = #id "=" value
#ifdef __cplusplus
}

View File

@ -148,9 +148,7 @@ typedef struct wups_loader_entry_t {
#define WUPS_MUST_REPLACE_FOR_PROCESS(x, lib, function_name, targetProcess) WUPS_MUST_REPLACE_EX(NULL, NULL, real_##x, lib, my_##x, function_name, targetProcess)
#define WUPS_MUST_REPLACE_EX(pAddress, vAddress, original_func, rpl_type, replace_func, replace_function_name, process) \
extern const wups_loader_entry_t wups_load_##replace_func \
WUPS_SECTION("load"); \
const wups_loader_entry_t wups_load_##replace_func = { \
WUPS_SECTION("load") const wups_loader_entry_t wups_load_##replace_func = { \
.type = WUPS_LOADER_ENTRY_FUNCTION_MANDATORY, \
._function = { \
.physical_address = (const void *) pAddress, \

View File

@ -23,8 +23,7 @@ extern "C" {
#endif
#define WUPS_HOOK_EX(type_def, original_func) \
extern const wups_loader_hook_t wups_hooks_##original_func WUPS_SECTION("hooks"); \
const wups_loader_hook_t wups_hooks_##original_func = { \
WUPS_SECTION("hooks") const wups_loader_hook_t wups_hooks_##original_func = { \
.type = type_def, \
.target = (const void *) &(original_func)}

View File

@ -50,14 +50,11 @@ extern "C" {
WUPS___FINI_WRAPPER(); \
WUPS_INIT_CONFIG_FUNCTIONS(); \
WUPS_META(buildtimestamp, __DATE__ " " __TIME__); \
extern const char wups_meta_plugin_name[] WUPS_SECTION("meta"); \
const char wups_meta_plugin_name[] = __plugin_name; \
extern const char wups_meta_info_dump[] WUPS_SECTION("meta"); \
const char wups_meta_info_dump[] = "(plugin: " __plugin_name ";" \
WUPS_SECTION("meta") const char wups_meta_plugin_name[] = __plugin_name; \
WUPS_SECTION("meta") const char wups_meta_info_dump[] = "(plugin: " __plugin_name ";" \
"wups " WUPS_VERSION_STR ";" \
"buildtime: " __DATE__ " " __TIME__ ")"; \
extern const char wups_meta_info_linking_order[] WUPS_SECTION("meta"); \
const char wups_meta_info_linking_order[] = "Loading \"" __plugin_name "\" failed.\n" \
WUPS_SECTION("meta") const char wups_meta_info_linking_order[] = "Loading \"" __plugin_name "\" failed.\n" \
"Function \"wut_get_thread_specific\" returned unexpected value.\n" \
"Please check linking order (expected \"-lwups -lwut\")";