Skip to content

Commit 2c26d57

Browse files
jpoimboegregkh
authored andcommitted
objtool: Support GCC 8 switch tables
commit fd35c88 upstream. With GCC 8, some issues were found with the objtool switch table detection. 1) In the .rodata section, immediately after the switch table, there can be another object which contains a pointer to the function which had the switch statement. In this case objtool wrongly considers the function pointer to be part of the switch table. Fix it by: a) making sure there are no pointers to the beginning of the function; and b) making sure there are no gaps in the switch table. Only the former was needed, the latter adds additional protection for future optimizations. 2) In find_switch_table(), case 1 and case 2 are missing the check to ensure that the .rodata switch table data is anonymous, i.e. that it isn't already associated with an ELF symbol. Fix it by adding the same find_symbol_containing() check which is used for case 3. This fixes the following warnings with GCC 8: drivers/block/virtio_blk.o: warning: objtool: virtio_queue_rq()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+72 net/ipv6/icmp.o: warning: objtool: icmpv6_rcv()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+64 drivers/usb/core/quirks.o: warning: objtool: quirks_param_set()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+48 drivers/mtd/nand/raw/nand_hynix.o: warning: objtool: hynix_nand_decode_id()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+24 drivers/mtd/nand/raw/nand_samsung.o: warning: objtool: samsung_nand_decode_id()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+32 drivers/gpu/drm/nouveau/nvkm/subdev/top/gk104.o: warning: objtool: gk104_top_oneinit()+0x0: stack state mismatch: cfa1=7+8 cfa2=7+64 Reported-by: Arnd Bergmann <arnd@arndb.de> Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: David Laight <David.Laight@ACULAB.COM> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: damian <damian.tometzki@icloud.com> Link: http://lkml.kernel.org/r/20180510224849.xwi34d6tzheb5wgw@treble Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1bea53d commit 2c26d57

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎tools/objtool/check.c‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,17 +805,28 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
805805
struct rela *rela = table;
806806
struct instruction *alt_insn;
807807
struct alternative *alt;
808+
struct symbol *pfunc = insn->func->pfunc;
809+
unsigned int prev_offset = 0;
808810

809811
list_for_each_entry_from(rela, &file->rodata->rela->rela_list, list) {
810812
if (rela == next_table)
811813
break;
812814

815+
/* Make sure the switch table entries are consecutive: */
816+
if (prev_offset && rela->offset != prev_offset + 8)
817+
break;
818+
819+
/* Detect function pointers from contiguous objects: */
820+
if (rela->sym->sec == pfunc->sec &&
821+
rela->addend == pfunc->offset)
822+
break;
823+
813824
alt_insn = find_insn(file, rela->sym->sec, rela->addend);
814825
if (!alt_insn)
815826
break;
816827

817828
/* Make sure the jmp dest is in the function or subfunction: */
818-
if (alt_insn->func->pfunc != insn->func->pfunc)
829+
if (alt_insn->func->pfunc != pfunc)
819830
break;
820831

821832
alt = malloc(sizeof(*alt));
@@ -826,6 +837,13 @@ static int add_switch_table(struct objtool_file *file, struct instruction *insn,
826837

827838
alt->insn = alt_insn;
828839
list_add_tail(&alt->list, &insn->alts);
840+
prev_offset = rela->offset;
841+
}
842+
843+
if (!prev_offset) {
844+
WARN_FUNC("can't find switch jump table",
845+
insn->sec, insn->offset);
846+
return -1;
829847
}
830848

831849
return 0;
@@ -882,7 +900,9 @@ static struct rela *find_switch_table(struct objtool_file *file,
882900
struct instruction *orig_insn = insn;
883901

884902
text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
885-
if (text_rela && text_rela->sym == file->rodata->sym) {
903+
if (text_rela && text_rela->sym == file->rodata->sym &&
904+
!find_symbol_containing(file->rodata, text_rela->addend)) {
905+
886906
/* case 1 */
887907
rodata_rela = find_rela_by_dest(file->rodata,
888908
text_rela->addend);

0 commit comments

Comments
 (0)