Bug 208187 - objtool doesn't support some VEX instructions
Summary: objtool doesn't support some VEX instructions
Status: NEW
Alias: None
Product: Tools
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Tools.Other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-15 14:39 UTC by Maxim Britov
Modified: 2021-12-10 15:35 UTC (History)
4 users (show)

See Also:
Kernel Version: 5.7
Subsystem:
Regression: No
Bisected commit-id:


Attachments
5.15.7 build log (490.05 KB, text/plain)
2021-12-10 15:35 UTC, B. Gazotti
Details

Description Maxim Britov 2020-06-15 14:39:13 UTC
Original issue on Gentoo: https://bugs.gentoo.org/726660
May by related on issue for 4.14: https://bugs.gentoo.org/642924

Issue on gcc with detailed comments: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95671


There is patch for build kernel with different march:
https://github.com/graysky2/kernel_gcc_patch/blob/master/enable_additional_cpu_optimizations_for_gcc_v9.1%2B_kernel_v5.7%2B.patch

Gentoo use this patch with USE='experimental'

Since 5.7 kernel builds fails on bdver{2,3,4}.
I can build kernel when add -mno-tbm

From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95671#c11

```
That is clearly a kernel/objtool bug.
Seems it has its own x86_64 instruction decoder and has some VEX decoding code, but either not well tested or not working in this particular case.
Kernel doesn't normally use floating point or SIMD instructions, therefore I'd expect that it only rarely uses VEX encoded instructions, and BEXTR is one of the few general purpose instructions that are VEX encoded.
```


Build error:
HOSTCC  scripts/kconfig/conf.o
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf  --syncconfig Kconfig
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  HOSTCC  arch/x86/tools/relocs_common.o
  HOSTLD  arch/x86/tools/relocs
  HOSTCXX -fPIC scripts/gcc-plugins/structleak_plugin.o
  HOSTLLD -shared scripts/gcc-plugins/structleak_plugin.so
  GENSEED scripts/gcc-plugins/randomize_layout_seed.h
  HOSTCXX -fPIC scripts/gcc-plugins/randomize_layout_plugin.o
  HOSTLLD -shared scripts/gcc-plugins/randomize_layout_plugin.so
  HOSTCXX -fPIC scripts/gcc-plugins/stackleak_plugin.o
  HOSTLLD -shared scripts/gcc-plugins/stackleak_plugin.so
  HOSTCC  scripts/genksyms/genksyms.o
  YACC    scripts/genksyms/parse.tab.[ch]
  HOSTCC  scripts/genksyms/parse.tab.o
  LEX     scripts/genksyms/lex.lex.c
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  HOSTCC  scripts/bin2c
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/sorttable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/extract-cert
  HOSTCC  scripts/mod/mk_elfconfig
  CC      scripts/mod/empty.o
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  CC      kernel/bounds.s
  CC      arch/x86/kernel/asm-offsets.s
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  DESCEND  objtool
  HOSTCC   /usr/src/linux-5.7.1-gentoo-2/tools/objtool/fixdep.o
  HOSTLD   /usr/src/linux-5.7.1-gentoo-2/tools/objtool/fixdep-in.o
  LINK     /usr/src/linux-5.7.1-gentoo-2/tools/objtool/fixdep
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/exec-cmd.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/help.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/pager.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/parse-options.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/run-command.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/sigchain.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/subcmd-config.o
  LD       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/libsubcmd-in.o
  AR       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/libsubcmd.a
  GEN      /usr/src/linux-5.7.1-gentoo-2/tools/objtool/arch/x86/lib/inat-tables.c
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/arch/x86/decode.o
  LD       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/arch/x86/objtool-in.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/builtin-check.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/builtin-orc.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/check.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/orc_gen.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/orc_dump.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/elf.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/special.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/objtool.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/libstring.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/libctype.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/str_error_r.o
  CC       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/librbtree.o
  LD       /usr/src/linux-5.7.1-gentoo-2/tools/objtool/objtool-in.o
  LINK     /usr/src/linux-5.7.1-gentoo-2/tools/objtool/objtool
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/main.o
init/main.o: warning: objtool: initcall_blacklisted()+0xd9: return with modified stack frame
  CC      init/version.o
  CC      init/do_mounts.o
  CC      init/noinitramfs.o
  CC      init/calibrate.o
  CC      init/init_task.o
  AR      init/built-in.a
  AR      usr/built-in.a
  CC      arch/x86/entry/vdso/vma.o
  LDS     arch/x86/entry/vdso/vdso.lds
  AS      arch/x86/entry/vdso/vdso-note.o
  CC      arch/x86/entry/vdso/vclock_gettime.o
  CC      arch/x86/entry/vdso/vgetcpu.o
  VDSO    arch/x86/entry/vdso/vdso64.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso64.so
  HOSTCC  arch/x86/entry/vdso/vdso2c
  VDSO2C  arch/x86/entry/vdso/vdso-image-64.c
  CC      arch/x86/entry/vdso/vdso-image-64.o
  AR      arch/x86/entry/vdso/built-in.a
  CC      arch/x86/entry/vsyscall/vsyscall_64.o
arch/x86/entry/vsyscall/vsyscall_64.o: warning: objtool: emulate_vsyscall()+0x287: stack state mismatch: cfa1=7+64 cfa2=7+56
  AS      arch/x86/entry/vsyscall/vsyscall_emu_64.o
  AR      arch/x86/entry/vsyscall/built-in.a
  AS      arch/x86/entry/entry_64.o
  AS      arch/x86/entry/thunk_64.o
  CC      arch/x86/entry/syscall_64.o
  CC      arch/x86/entry/common.o
  AR      arch/x86/entry/built-in.a
  CC      arch/x86/events/amd/core.o
arch/x86/events/amd/core.o: warning: objtool: amd_pmu_handle_irq()+0x30: stack state mismatch: cfa1=7+16 cfa2=7+0
  CC      arch/x86/events/amd/uncore.o
  CC      arch/x86/events/amd/power.o
  CC      arch/x86/events/amd/ibs.o
arch/x86/events/amd/ibs.o: warning: objtool: perf_ibs_init()+0x23: can't find jump dest instruction at .text+0xe5
make[3]: *** [scripts/Makefile.build:267: arch/x86/events/amd/ibs.o] Error 255
make[3]: *** Deleting file 'arch/x86/events/amd/ibs.o'
make[2]: *** [scripts/Makefile.build:488: arch/x86/events/amd] Error 2
make[1]: *** [scripts/Makefile.build:488: arch/x86/events] Error 2
make: *** [Makefile:1729: arch/x86] Error 2
Comment 1 Martin Liška 2020-06-15 17:40:52 UTC
Reduced test-case:

$ cat lbr.i
int a, c, d;
long b;

void
fn1() {
  for (; c; c++) {
    int e, f = 0;
    if (a) {
      e = !(d & 1ULL << 63);
      f = e;
    }
    d = fn1;
    b = f;
  }
}

$ gcc lbr.i -c -O2 -march=bdver2 -c && ~/Programming/linux/tools/objtool/objtool check --uaccess lbr.o
lbr.i: In function ‘fn1’:
lbr.i:12:7: warning: assignment to ‘int’ from ‘void (*)()’ makes integer from pointer without a cast [-Wint-conversion]
   12 |     d = fn1;
      |       ^
lbr.o: warning: objtool: fn1()+0x26: can't find jump dest instruction at .text+0x36

disassembly:
  26:	74 0e                	je     36 <fn1+0x36>
  28:	48 0f ba fa 1f       	btc    $0x1f,%rdx
  2d:	8f ea f8 10 ca 1f 01 	bextr  $0x11f,%rdx,%rcx
  34:	00 00 
  36:	ff c0                	inc    %eax
Comment 2 B. Gazotti 2021-12-10 15:35:43 UTC
Created attachment 299985 [details]
5.15.7 build log

This issue has come back with a vengeance on 5.15. Compiling the kernel with -march/-mtune=native or bdver2 on my FX-6300 causes objtool to print out several warnings of that kind. The build doesn't fail, but the resulting kernel is unbootable and panics with a "Fatal Exception" after decompressing (if you guys need a full stack trace, how do I get a log from before the kernel takes over?). Using -march/-mtune=bdver1 works fine, though. 5.14 used to work, so I guess we have a regression?

Full build log attached. CFLAGS were appended with KCFLAGS, no external patches applied.

Note You need to log in before you can comment on or make changes to this bug.