init.h: discard exitcall symbols early
PATCH 1/1 init.h: discard exitcall symbols early
From: Arnd Bergmann <[email protected]>
Any __exitcall() and built-in module_exit() handler is marked as __used, which leads to the code being included in the object file and later discarded at link time.
As far as I can tell, this was originally added at the same time as initcalls were marked the same way, to prevent them from getting dropped with gcc-3.4, but it was never actaully necessary to keep exit functions around.
Mark them as __maybe_unused instead, which lets the compiler treat the exitcalls as entirely unused, and make better decisions about dropping specializing static functions called from these.
--- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/init.h +1 -1
@@ -47,7 +47,7 @@#define __initdata __section(".init.data")#define __initconst __section(".init.rodata")#define __exitdata __section(".exit.data") -#define __exit_call __used __section(".exitcall.exit") +#define __exit_call __maybe_unused __section(".exitcall.exit")/* * modpost check for section mismatches during the kernel build.
Signature · 1 line
2.39.5
Adding module loader maintainers into Cc to make them aware of this change.
Quoted 5 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Any
__exitcall()and built-inmodule_exit()handler is marked as__used, which leads to the code being included in the object file and later discarded at link time.
Is this safe for dynamically loaded modules?
Honestly, I am not sure what is the exact efect of this change. The dynamically loadded modules just came to my mind...
Best Regards,
Petr
Quoted 30 lines
As far as I can tell, this was originally added at the same time as initcalls were marked the same way, to prevent them from getting dropped with gcc-3.4, but it was never actaully necessary to keep exit functions around.
Mark them as
__maybe_unusedinstead, which lets the compiler treat the exitcalls as entirely unused, and make better decisions about dropping specializing static functions called from these.Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/init.h +1
-1@@ -47,7 +47,7 @@#define __initdata __section(".init.data")#define __initconst __section(".init.rodata")#define __exitdata __section(".exit.data") -#define __exit_call __used __section(".exitcall.exit") +#define __exit_call __maybe_unused __section(".exitcall.exit")/* * modpost check for section mismatches during the kernel build. Signature · 1 line
2.39.5
Quoted 6 lines · Petr Mladek
Adding module loader maintainers into Cc to make them aware of this change.
Quoted 2 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 3 lines
Any
__exitcall()and built-inmodule_exit()handler is marked as__used, which leads to the code being included in the object file and later discarded at link time.Is this safe for dynamically loaded modules?
Honestly, I am not sure what is the exact efect of this change. The dynamically loadded modules just came to my mind...
In a loadable module, using __exitcall() directly already discards the function at link time, so there is no difference from built-in code. Actually using __exitcall() here is a mistake regardless of my patch.
Using module_exit() in a loadable module still behaves as before, this uses a different macro, which already has __maybe_unused:
#define module_exit(exitfn) \
static inline exitcall_t __maybe_unused __exittest(void) \
{ return exitfn; } \
void cleanup_module(void) __copy(exitfn) \
__attribute__((alias(#exitfn))); \
___ADDRESSABLE(cleanup_module, __exitdata);so this is also unchanged.
Arnd
Quoted 24 lines · Arnd Bergmann
Quoted 6 lines · Petr Mladek
Adding module loader maintainers into Cc to make them aware of this change.
Quoted 2 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Quoted 8 lines
Quoted 3 lines
Any
__exitcall()and built-inmodule_exit()handler is marked as__used, which leads to the code being included in the object file and later discarded at link time.Is this safe for dynamically loaded modules?
Honestly, I am not sure what is the exact efect of this change. The dynamically loadded modules just came to my mind...
In a loadable module, using
__exitcall()directly already discards the function at link time, so there is no difference from built-in code. Actually using__exitcall()here is a mistake regardless of my patch.Using
module_exit()in a loadable module still behaves as before, this uses a different macro, which already has__maybe_unused:
Quoted 8 lines
#define module_exit(exitfn) \ static inline exitcall_t __maybe_unused __exittest(void) \ { return exitfn; } \ void cleanup_module(void) __copy(exitfn) \ __attribute__((alias(#exitfn))); \ ___ADDRESSABLE(cleanup_module, __exitdata);so this is also unchanged.
I see, I was confused because cscope pointed me to:
/**
* module_exit() - driver exit entry point
* @x: function to be run when driver is removed *
* module_exit() will wrap the driver clean-up code
* with cleanup_module() when used with rmmod when
* the driver is a module. If the driver is statically
* compiled into the kernel, module_exit() has no effect.
* There can only be one per module.
*/
#define module_exit(x) __exitcall(x);
and I missed that it was the variant for the built-in modules.
Best Regards,
Petr
Quoted 37 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Any
__exitcall()and built-inmodule_exit()handler is marked as__used, which leads to the code being included in the object file and later discarded at link time.As far as I can tell, this was originally added at the same time as initcalls were marked the same way, to prevent them from getting dropped with gcc-3.4, but it was never actaully necessary to keep exit functions around.
Mark them as
__maybe_unusedinstead, which lets the compiler treat the exitcalls as entirely unused, and make better decisions about dropping specializing static functions called from these.Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/init.h +1
-1@@ -47,7 +47,7 @@#define __initdata __section(".init.data")#define __initconst __section(".init.rodata")#define __exitdata __section(".exit.data") -#define __exit_call __used __section(".exitcall.exit") +#define __exit_call __maybe_unused __section(".exitcall.exit")/* * modpost check for section mismatches during the kernel build. Signature · 1 line
2.39.5
Signature · 1 line
Nicolas