Skip to contentSkip to conversation

mm, slub: Fix support for clang 10

PATCH In review Hyeonggon Yoo 2 participants 4 messages May 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, slub: Fix support for clang 10

Previously in 'commit ff3daafe3fd3 ("mm, slub: change run-time assertion in kmalloc_index() to compile-time")', changed kmalloc_index's run-time assertion to compile-time assertion.

But clang 10 has a bug misevaluating __builtin_constant_p() as true, making it unable to compile. This bug was fixed in clang 11.

To support clang 10, introduce a macro to do run-time assertion if clang version is less than 11, even if the size is constant. Might revert this commit later if we choose not to support clang 10.

---
 include/linux/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/slab.h +1 -1
index 9d316aac0aba..8d8dd8571261 100644
@@ -413,7 +413,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
 	if (size <=  16 * 1024 * 1024) return 24;
 	if (size <=  32 * 1024 * 1024) return 25;
 
-	if (size_is_constant)
+	if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
 		BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
 	else
 		BUG();
Signature · 1 line
2.25.1
#1 lore raw

Nathan, Thank you for suggesting the idea and allowing me to write the patch.

it compiled and booted without problem when compiled with gcc-10.2.0, clang-10.0.1, clang-11.0.0 with x86_64 default config.

Thanks,
Hyeonggon

#2 lore raw

And Naresh, Thank you for reporting the problem!

If there's any problem with it or I can improve anything, any feedback will be welcomed. and I'll reply soon.

Thanks,
Hyeonggon

Reviewed-by on v1 1/1
#3 lore raw
In reply to Hyeonggon Yoo
Quoted 12 lines · Hyeonggon Yoo

Previously in 'commit ff3daafe3fd3 ("mm, slub: change run-time assertion in kmalloc_index() to compile-time")', changed kmalloc_index's run-time assertion to compile-time assertion.

But clang 10 has a bug misevaluating __builtin_constant_p() as true, making it unable to compile. This bug was fixed in clang 11.

To support clang 10, introduce a macro to do run-time assertion if clang version is less than 11, even if the size is constant. Might revert this commit later if we choose not to support clang 10.

Quoted 6 lines

Thanks for the patch; hopefully this isn't too much burden in order to help us support clang-10 a little bit longer. We will rip it out when dropping clang-10 someday; grepping for CLANG_VERSION should turn this up easily.

Quoted 20 lines
---
 include/linux/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/slab.h +1 -2
index 9d316aac0aba..8d8dd8571261 100644
@@ -413,7 +413,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
        if (size <=  16 * 1024 * 1024) return 24;
        if (size <=  32 * 1024 * 1024) return 25;
 
-       if (size_is_constant)
+       if ((IS_ENABLED(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 110000) && size_is_constant)
                BUILD_BUG_ON_MSG(1, "unexpected size in kmalloc_index()");
        else
                BUG();
--

2.25.1

Signature · 2 lines
Thanks,
~Nick Desaulniers