[PATCH 1/3] compiler.h: add ASSERT_STATIC_STORAGE()

Andrew Morton akpm at linux-foundation.org
Fri Sep 11 22:57:49 PDT 2026


On Fri, 11 Sep 2026 18:14:41 -0400 Yury Norov <yury.norov at gmail.com> wrote:

> Static lock initializers rely on a persistent object address when lockdep
> assigns a lock-class key. Using such an initializer for an automatic local
> object can compile successfully but disable lockdep on the first lock
> acquisition.
> 
> Add ASSERT_STATIC_STORAGE() for declaration macros that require
> static storage duration. It declares an unused static pointer initialized
> with the object's address. An automatic local object's address is not a
> valid static initializer, so the compiler rejects it.
> 
> Mirror the helper in tools/include/linux/compiler.h because the userspace
> radix-tree tests include the kernel IDA and Maple Tree headers with the
> tools compiler definitions.
> 
> For example:
> 
>   void example(void)
>   {
>           int object;
>           ASSERT_STATIC_STORAGE(object);
>   }
> 
> GCC reports:
> 
>   error: initializer element is not constant
>     name##_storage_check = &(name)
>                            ^
>   note: in expansion of macro 'ASSERT_STATIC_STORAGE'
>     ASSERT_STATIC_STORAGE(object);
> 
> File-scope objects and static local objects remain valid. The helper takes
> an object identifier and must be used as a declaration after that object
> has been declared.
> 

Thanks, I'll queue it.

Sashiko wants the same treatment for a few other macros:
	https://sashiko.dev/#/patchset/20260911221444.1523311-1-ynorov@nvidia.com



More information about the maple-tree mailing list