From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
Tiezhu Yang <yangtiezhu@loongson.cn>,
Xi Ruoyao <xry111@xry111.site>,
Peter Zijlstra <peterz@infradead.org>,
Huacai Chen <chenhuacai@kernel.org>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-toolchains@vger.kernel.org, Jan Beulich <jbeulich@suse.com>,
"Jose E. Marchesi" <jemarch@gnu.org>, Kees Cook <kees@kernel.org>
Subject: Re: annotating jump tables (Re: [PATCH v2 5/5] LoongArch: Enable jump table with GCC for objtool)
Date: Wed, 27 Nov 2024 16:56:53 -0800 [thread overview]
Message-ID: <20241128005653.st7xwkv2gry2chlc@jpoimboe> (raw)
In-Reply-To: <CAMj1kXF=55+z6udToxO=CZdTK910-jxKdCXpryQGg580J9eXEA@mail.gmail.com>
On Thu, Nov 14, 2024 at 07:13:18PM +0100, Ard Biesheuvel wrote:
> > Looks like this was added to clang in:
> > https://github.com/llvm/llvm-project/pull/102411
> >
> > A comment in llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
> > describes the scheme:
> > + // Emit an additional section to store the correlation info as pairs of
> > + // addresses, each pair contains the address of a jump instruction (jr) and
> > + // the address of the jump table.
> >
> > Ard had a prototype in:
> > https://github.com/llvm/llvm-project/pull/112606
> > which used relocations rather than a discardable section.
>
> Thanks for the cc.
>
> I haven't followed up yet because doing this generically is not
> straight-forward. The main issue is that AArch64 jump tables could be
> emitted into .text with scaled offsets, e.g.,
>
> adr x16, .Ljumptable
> ldrb w17, [x16, xN] // xN is the lookup index
> add x16, x16, w17, sxtw #2 // x16 += 4 * x17
> br x16
>
> .Ljumptable:
> .byte (dest0 - .Ljumptable) >> 2
> .byte (dest1 - .Ljumptable) >> 2
> .byte (dest2 - .Ljumptable) >> 2
> .byte (dest3 - .Ljumptable) >> 2
>
> So just emitting a relocation at the call site and a symbol covering
> the jump table might work for x86, but if we want some that works in
> general, we'll have to come up with some format that describes in more
> detail how to infer the potential destinations of an indirect call it
> is known to be a limited set at compile time.
Loongarch is emitting an array of (insn_ptr, jump_table_ptr) tuples
in .discard.tablejump_annotate. Would that work more generically?
Even better it would also emit the jump table size.
--
Josh
prev parent reply other threads:[~2024-11-28 0:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241105123906.26072-1-yangtiezhu@loongson.cn>
[not found] ` <20241105123906.26072-6-yangtiezhu@loongson.cn>
[not found] ` <20241105141530.GE10375@noisy.programming.kicks-ass.net>
[not found] ` <62df4c24-68ed-fbfc-ed98-2df796697d89@loongson.cn>
[not found] ` <9589c5b673f45f02e2b0fa9d9a96eff0f0df0920.camel@xry111.site>
[not found] ` <7e8adb0b-e681-72ae-40d8-740dc3f9480b@loongson.cn>
2024-11-13 21:11 ` annotating jump tables (Re: [PATCH v2 5/5] LoongArch: Enable jump table with GCC for objtool) Josh Poimboeuf
2024-11-14 17:13 ` Nick Desaulniers
2024-11-14 18:13 ` Ard Biesheuvel
2024-11-28 0:56 ` Josh Poimboeuf [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=20241128005653.st7xwkv2gry2chlc@jpoimboe \
--to=jpoimboe@redhat.com \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=jbeulich@suse.com \
--cc=jemarch@gnu.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=xry111@xry111.site \
--cc=yangtiezhu@loongson.cn \
/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