Skip to content

Commit afb5e5c

Browse files
jpoimboegregkh
authored andcommitted
objtool: Detect RIP-relative switch table references
commit 6f5ec29 upstream. Typically a switch table can be found by detecting a .rodata access followed an indirect jump: 1969: 4a 8b 0c e5 00 00 00 mov 0x0(,%r12,8),%rcx 1970: 00 196d: R_X86_64_32S .rodata+0x438 1971: e9 00 00 00 00 jmpq 1976 <dispc_runtime_suspend+0xb6a> 1972: R_X86_64_PC32 __x86_indirect_thunk_rcx-0x4 Randy Dunlap reported a case (seen with GCC 4.8) where the .rodata access uses RIP-relative addressing: 19bd: 48 8b 3d 00 00 00 00 mov 0x0(%rip),%rdi # 19c4 <dispc_runtime_suspend+0xbb8> 19c0: R_X86_64_PC32 .rodata+0x45c 19c4: e9 00 00 00 00 jmpq 19c9 <dispc_runtime_suspend+0xbbd> 19c5: R_X86_64_PC32 __x86_indirect_thunk_rdi-0x4 In this case the relocation addend needs to be adjusted accordingly in order to find the location of the switch table. The fix is for case 3 (as described in the comments), but also make the existing case 1 & 2 checks more precise by only adjusting the addend for R_X86_64_PC32 relocations. This fixes the following warnings: drivers/video/fbdev/omap2/omapfb/dss/dispc.o: warning: objtool: dispc_runtime_suspend()+0xbb8: sibling call from callable instruction with modified stack frame drivers/video/fbdev/omap2/omapfb/dss/dispc.o: warning: objtool: dispc_runtime_resume()+0xcc5: sibling call from callable instruction with modified stack frame Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/b6098294fd67afb69af8c47c9883d7a68bf0f8ea.1526305958.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2c26d57 commit afb5e5c

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

‎tools/objtool/check.c‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -898,24 +898,24 @@ static struct rela *find_switch_table(struct objtool_file *file,
898898
{
899899
struct rela *text_rela, *rodata_rela;
900900
struct instruction *orig_insn = insn;
901+
unsigned long table_offset;
901902

903+
/* case 1 & 2 */
902904
text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
903905
if (text_rela && text_rela->sym == file->rodata->sym &&
904906
!find_symbol_containing(file->rodata, text_rela->addend)) {
905907

906-
/* case 1 */
907-
rodata_rela = find_rela_by_dest(file->rodata,
908-
text_rela->addend);
909-
if (rodata_rela)
910-
return rodata_rela;
908+
table_offset = text_rela->addend;
909+
if (text_rela->type == R_X86_64_PC32) {
910+
/* case 2 */
911+
table_offset += 4;
912+
file->ignore_unreachables = true;
913+
}
911914

912-
/* case 2 */
913-
rodata_rela = find_rela_by_dest(file->rodata,
914-
text_rela->addend + 4);
915+
rodata_rela = find_rela_by_dest(file->rodata, table_offset);
915916
if (!rodata_rela)
916917
return NULL;
917918

918-
file->ignore_unreachables = true;
919919
return rodata_rela;
920920
}
921921

@@ -949,18 +949,21 @@ static struct rela *find_switch_table(struct objtool_file *file,
949949
if (!text_rela || text_rela->sym != file->rodata->sym)
950950
continue;
951951

952+
table_offset = text_rela->addend;
953+
if (text_rela->type == R_X86_64_PC32)
954+
table_offset += 4;
955+
952956
/*
953957
* Make sure the .rodata address isn't associated with a
954958
* symbol. gcc jump tables are anonymous data.
955959
*/
956-
if (find_symbol_containing(file->rodata, text_rela->addend))
957-
continue;
958-
959-
rodata_rela = find_rela_by_dest(file->rodata, text_rela->addend);
960-
if (!rodata_rela)
960+
if (find_symbol_containing(file->rodata, table_offset))
961961
continue;
962962

963-
return rodata_rela;
963+
/* mov [rodata addr], %reg */
964+
rodata_rela = find_rela_by_dest(file->rodata, table_offset);
965+
if (rodata_rela)
966+
return rodata_rela;
964967
}
965968

966969
return NULL;

0 commit comments

Comments
 (0)