]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Add support to annotate tablejump
authorXi Ruoyao <xry111@xry111.site>
Thu, 11 Jul 2024 11:43:48 +0000 (19:43 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Tue, 8 Oct 2024 02:41:25 +0000 (10:41 +0800)
commit0ee028f556401846d27edf0ff67647a1a7a26b6c
tree40fb835273cb08e025a036ef29bd4dd464e808f0
parentc01e3aaae79ecd439ad35063db3dee9775f3aefa
LoongArch: Add support to annotate tablejump

This is per the request from the kernel developers.  For generating the
ORC unwind info, the objtool program needs to analysis the control flow
of a .o file.  If a jump table is used, objtool has to correlate the
jump instruction with the table.

On x86 (where objtool was initially developed) it's simple: a relocation
entry natrually correlates them because one single instruction is used
for table-based jump.  But on an RISC machine objtool would have to
reconstruct the data flow if it must find out the correlation on its
own.

So, 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.  This is very trivial to implement in
GCC.

gcc/ChangeLog:

* config/loongarch/genopts/loongarch.opt.in
(mannotate-tablejump): New option.
* config/loongarch/loongarch.opt: Regenerate.
* config/loongarch/loongarch.md (tablejump<mode>): Emit
additional correlation info between the jump instruction and the
jump table, if -mannotate-tablejump.
* doc/invoke.texi: Document -mannotate-tablejump.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/jump-table-annotate.c: New test.

Suggested-by: Tiezhu Yang <yangtiezhu@loongson.cn>
gcc/config/loongarch/genopts/loongarch.opt.in
gcc/config/loongarch/loongarch.md
gcc/config/loongarch/loongarch.opt
gcc/doc/invoke.texi
gcc/testsuite/gcc.target/loongarch/jump-table-annotate.c [new file with mode: 0644]