From: Uros Bizjak <ubizjak@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v2 2/2] compiler-gcc: Remove obsolete RELOC_HIDE() macro
Date: Sat, 5 Sep 2026 11:42:09 +0200 [thread overview]
Message-ID: <CAFULd4aHBevLgA-fJXx+Uh-JHZSnDRsgU6k+XO2+T8HS5QEpfg@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=whYAZQXQ4X2kDjigwhE5W7qwYWR3pHnP-67ceYChqJzvw@mail.gmail.com>
On Fri, Sep 4, 2026 at 5:40 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Fri, 4 Sept 2026 at 08:30, Uros Bizjak <ubizjak@gmail.com> 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.
Yes, this one requires inline asm. The testcase:
--cut here--
void *baz (void)
{
struct {
unsigned long words[2];
} *ptr1;
/* RELOC_HIDE to prevent gcc from warning about short alloc */
ptr1 = RELOC_HIDE(malloc(sizeof(*ptr1) - 3), 0);
return ptr1;
}
--cut here--
compiles without warning with the old definition of RELOC_HIDE() and reports:
<source>: In function 'baz':
<source>:33:14: warning: allocation of insufficient size '13' for type
'struct <anonymous>' with size '16' [-Walloc-size]
33 | ptr1 = RELOC_HIDE(malloc(sizeof(*ptr1) - 3), 0);
| ^
Also, GCC > 4.9 has its share of problems with "=rm" output (e.g.
[1]), so the output asm operand constraint should stay "=r".
So, RELOC_HIDE() should stay as it is, and the patch should simply
remove the obsolete third paragraph from the comment.
[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124209
Thanks,
Uros.
prev parent reply other threads:[~2026-09-05 9:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:25 [PATCH v2 0/2] Remove obsolete RELOC_HIDE() macro from compiler-gcc.h Uros Bizjak
2026-09-04 8:25 ` [PATCH v2 1/2] x86/boot: Disable GCC min-pagesize assumption in boot code Uros Bizjak
2026-09-04 13:17 ` H. Peter Anvin
2026-09-06 20:44 ` Uros Bizjak
2026-09-04 8:25 ` [PATCH v2 2/2] compiler-gcc: Remove obsolete RELOC_HIDE() macro Uros Bizjak
2026-09-04 15:16 ` Linus Torvalds
2026-09-04 15:29 ` Uros Bizjak
2026-09-04 15:39 ` Linus Torvalds
2026-09-05 9:42 ` Uros Bizjak [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFULd4aHBevLgA-fJXx+Uh-JHZSnDRsgU6k+XO2+T8HS5QEpfg@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®