3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

build: treewide: Set retain attribute

LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
collection of C identifier name sections despite the __start_/__stop_
references. GNU ld before 2015-10 had the behavior as well. Simply set
the retain attribute so that GCC 11 (if configure-time binutils is 2.36
or newer)/Clang 13 will set the SHF_GNU_RETAIN section attribute to
prevent garbage collection.

Without the patch, there are linker errors with -z start-stop-gc
(LLD default) when -Wl,--gc-sections is used:

```
ld.lld: error: undefined symbol: __start___eap
>>> referenced by eap.c
>>>               src/eap.o:(eap_init)
```

The remain attribute will not be needed if the metadata sections are
referenced by code directly.
This commit is contained in:
Fangrui Song 2021-11-10 19:07:58 -08:00 committed by Denis Kenzior
parent 9cd1f8a7df
commit fa1c12453b
4 changed files with 30 additions and 12 deletions

View File

@ -83,10 +83,14 @@ struct command_family_desc {
} __attribute__((aligned(8))); } __attribute__((aligned(8)));
#define COMMAND_FAMILY(name, init, exit) \ #define COMMAND_FAMILY(name, init, exit) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
static struct command_family_desc __command_family_ ## name \ static struct command_family_desc __command_family_ ## name \
__attribute__((used, section("__command"), aligned(8))) = {\ __attribute__((used, retain, \
section("__command"), aligned(8))) = { \
#name, init, exit \ #name, init, exit \
}; \ }; \
_Pragma("GCC diagnostic pop")
bool command_init(char **argv, int argc); bool command_init(char **argv, int argc);
void command_exit(void); void command_exit(void);

View File

@ -118,10 +118,14 @@ struct interface_type_desc {
} __attribute__((aligned(8))); } __attribute__((aligned(8)));
#define INTERFACE_TYPE(interface, init, exit) \ #define INTERFACE_TYPE(interface, init, exit) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
static struct interface_type_desc __interface_type_ ## interface\ static struct interface_type_desc __interface_type_ ## interface\
__attribute__((used, section("__interface"), aligned(8))) = {\ __attribute__((used, retain, section("__interface"), \
aligned(8))) = { \
#interface, init, exit \ #interface, init, exit \
}; \ }; \
_Pragma("GCC diagnostic pop")
bool dbus_proxy_init(void); bool dbus_proxy_init(void);
bool dbus_proxy_exit(void); bool dbus_proxy_exit(void);

View File

@ -94,10 +94,14 @@ struct eap_method_desc {
} __attribute__((aligned(8))); } __attribute__((aligned(8)));
#define EAP_METHOD_BUILTIN(name, init, exit) \ #define EAP_METHOD_BUILTIN(name, init, exit) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
static struct eap_method_desc __eap_builtin_ ## name \ static struct eap_method_desc __eap_builtin_ ## name \
__attribute__((used, section("__eap"), aligned(8))) = { \ __attribute__((used, retain, section("__eap"), \
aligned(8))) = { \
#name, init, exit \ #name, init, exit \
}; \ }; \
_Pragma("GCC diagnostic pop")
int eap_register_method(struct eap_method *method); int eap_register_method(struct eap_method *method);
int eap_unregister_method(struct eap_method *method); int eap_unregister_method(struct eap_method *method);

View File

@ -33,19 +33,25 @@ struct iwd_module_depends {
}; };
#define IWD_MODULE(name, init, exit) \ #define IWD_MODULE(name, init, exit) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wattributes\"") \
static struct iwd_module_desc __iwd_module_ ## name \ static struct iwd_module_desc __iwd_module_ ## name \
__attribute__((used, section("__iwd_module"), aligned(8))) = {\ __attribute__((used, retain, section("__iwd_module"), \
aligned(8))) = { \
#name, init, exit \ #name, init, exit \
}; }; \
_Pragma("GCC diagnostic pop")
#define IWD_MODULE_DEPENDS(name, dep) \ #define IWD_MODULE_DEPENDS(name, dep) \
static struct iwd_module_depends \ _Pragma("GCC diagnostic push") \
__iwd_module__##name##_##dep \ _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
__attribute__((used, section("__iwd_module_dep"), \ static struct iwd_module_depends __iwd_module__##name##_##dep \
aligned(8))) = { \ __attribute__((used, retain, \
.self = #name, \ section("__iwd_module_dep"), aligned(8))) = { \
.target = #dep, \ .self = #name, \
}; .target = #dep, \
}; \
_Pragma("GCC diagnostic pop")
int iwd_modules_init(void); int iwd_modules_init(void);
void iwd_modules_exit(void); void iwd_modules_exit(void);