Re: [PATCH v2 2/2] compiler-gcc: Remove obsolete RELOC_HIDE() macro
From: Linus Torvalds
Date: Fri Sep 04 2026 - 12:13:17 EST
On Fri, 4 Sept 2026 at 08:30, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> The cast to (unsigned long) should remove all compiler's knowledge
> about the pointer and force the compiler to use integer arithmetic
> instead of pointer arithmetic. This is what the generic version does
> without inline asm.
Yes. The question here is that word "should".
It's not clear that it always does, and historically hasn't.
To clarify: I'm not against this patch. But it is potentially
dangerous and could expose things. See for example:
/* RELOC_HIDE to prevent gcc from warning about short alloc */
ptr1 = RELOC_HIDE(kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL), 0);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1);
where RELOC_HIDE() is used to make sure gcc doesn't do certain optimizations.
Is that code pretty or valid? No. But it's an existing example of
people using RELOC_HIDE to hide things from the compiler.
Linus