Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 642924 - =sys-kernel/gentoo-sources-4.14.10-r1 various objtool warnings (-march=native)
Summary: =sys-kernel/gentoo-sources-4.14.10-r1 various objtool warnings (-march=native)
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Kernel Bug Wranglers and Kernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-31 20:12 UTC by Hadrien Lacour
Modified: 2018-03-13 23:22 UTC (History)
8 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge -pqv (gentoo-sources-4.14.10-r1_pqv,89 bytes, text/plain)
2017-12-31 20:12 UTC, Hadrien Lacour
Details
emerge --info (gentoo-sources-4.14.10-r1_info,15.38 KB, text/plain)
2017-12-31 20:13 UTC, Hadrien Lacour
Details
build log (gentoo-sources-4.14.10-r1_build-log,259.03 KB, text/plain)
2017-12-31 20:13 UTC, Hadrien Lacour
Details
kernel config (gentoo-sources-4.14.10-r1_config,108.77 KB, text/plain)
2017-12-31 20:13 UTC, Hadrien Lacour
Details
arch/x86/events/core.o (core.o,50.31 KB, application/x-object)
2018-01-01 00:04 UTC, Hadrien Lacour
Details
gcc opts (gcc_opt,9.06 KB, text/plain; charset=ISO-8859-1)
2018-01-01 12:16 UTC, Hadrien Lacour
Details
gcc target (gcc_help=target,6.97 KB, text/plain; charset=ISO-8859-1)
2018-01-01 12:32 UTC, Hadrien Lacour
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hadrien Lacour 2017-12-31 20:12:22 UTC
Created attachment 512360 [details]
emerge -pqv

These started with 4.14.9 (so I'm staying on 4.14.8-r1). Here are the first ones:

arch/x86/events/amd/uncore.o: warning: objtool: amd_uncore_cpu_starting()+0x9b: can't find jump dest instruction at .text+0x125
arch/x86/events/core.o: warning: objtool: x86_pmu_hw_config()+0x13: can't find jump dest instruction at .text+0x1495
kernel/fork.o: warning: objtool: account_kernel_stack()+0xd4: sibling call from callable instruction with modified stack frame
kernel/fork.o: warning: objtool: sysctl_max_threads()+0xee: stack state mismatch: cfa1=7+104 cfa2=7+96
arch/x86/entry/vdso/vma.o: warning: objtool: vgetcpu_cpu_init()+0x9e: return with modified stack frame
arch/x86/events/amd/ibs.o: warning: objtool: perf_ibs_init()+0x6a: stack state mismatch: cfa1=7+8 cfa2=7+0
...


What I tried:
- At first, I thought this was caused by ORC replacing frame_unwinder (I use olddefconfig) but reverting it didn't solve anything.
- I also tried with CFLAGS="-O2 -march=native -pipe" (I use -O3, usually).

So the only thing remaining I can think of is the 17.0 profile.
Comment 1 Hadrien Lacour 2017-12-31 20:13:05 UTC
Created attachment 512362 [details]
emerge --info
Comment 2 Hadrien Lacour 2017-12-31 20:13:36 UTC
Created attachment 512364 [details]
build log
Comment 3 Hadrien Lacour 2017-12-31 20:13:57 UTC
Created attachment 512366 [details]
kernel config
Comment 4 Hadrien Lacour 2017-12-31 20:15:00 UTC
I also tried using ld.bfd instead of ld.gold.
Comment 5 Sergei Trofimovich gentoo-dev 2017-12-31 23:56:43 UTC
These are likely caused by 17.0 profile, namely gcc[pie].
Perhaps, objtool needs to be tweaked to understand new code pattern for control flow change. Given that it reports so tiny values, like '.text+0x125' I would guess objtool does not understand some PIE-induced relocations.

Can you upload single .o file and a post reported warning for it?
Comment 6 Hadrien Lacour 2018-01-01 00:04:46 UTC
Created attachment 512368 [details]
arch/x86/events/core.o

Sure:

arch/x86/events/core.o: warning: objtool: x86_pmu_hw_config()+0x13: can't find jump dest instruction at .text+0x15cd
Comment 7 Sergei Trofimovich gentoo-dev 2018-01-01 00:38:03 UTC
(In reply to Hadrien Lacour from comment #6)
> Created attachment 512368 [details]
> arch/x86/events/core.o
> 
> Sure:
> 
> arch/x86/events/core.o: warning: objtool: x86_pmu_hw_config()+0x13: can't
> find jump dest instruction at .text+0x15cd

$ objdump -d -r core.o

00000000000015a8 <x86_pmu_hw_config>:
    15a8:       8b 87 f8 00 00 00       mov    0xf8(%rdi),%eax
    15ae:       a9 00 80 01 00          test   $0x18000,%eax
    15b3:       0f 85 ad 00 00 00       jne    1666 <x86_pmu_hw_config+0xbe>
    15b9:       8f ea 78 10 c0 0f 02    bextr  $0x20f,%eax,%eax
    15c0:       00 00 
    15c2:       83 f8 01                cmp    $0x1,%eax
    15c5:       7e 13                   jle    15da <x86_pmu_hw_config+0x32>
    15c7:       0f b6 05 00 00 00 00    movzbl 0x0(%rip),%eax        # 15ce <x86_pmu_hw_config+0x26>
                        15ca: R_X86_64_PC32     x86_pmu+0x165
    15ce:       83 e0 0f                and    $0xf,%eax
...
    1666:       0f b6 0d 00 00 00 00    movzbl 0x0(%rip),%ecx        # 166d <x86_pmu_hw_config+0xc5>
                        1669: R_X86_64_PC32     x86_pmu+0x16c
    166d:       31 d2                   xor    %edx,%edx
...

At least control flow instructions are not special. It looks like objtool believes instruction starts at x86_pmu_hw_config()+0x13 (0x15bb, looks wrong).

(Decoded test incorrectly?)
Comment 8 Sergei Trofimovich gentoo-dev 2018-01-01 11:33:31 UTC
Local reproducer:
    $ make allyesconfig
    $ make arch/x86/events/core.o
    $ tools/objtool/objtool check arch/x86/events/core.o
Comment 9 Sergei Trofimovich gentoo-dev 2018-01-01 12:06:04 UTC
(In reply to Hadrien Lacour from comment #6)
> Created attachment 512368 [details]
> arch/x86/events/core.o
> 
> Sure:
> 
> arch/x86/events/core.o: warning: objtool: x86_pmu_hw_config()+0x13: can't
> find jump dest instruction at .text+0x15cd

Can you also dump your output of:
    $ LANG=C gcc -Q -O2 -march=native --help=optimizers
I'd like to replicate generated instructions by compiler locally.
Comment 10 Hadrien Lacour 2018-01-01 12:16:47 UTC
Created attachment 512486 [details]
gcc opts

Here, I'm on piledriver.
Comment 11 Sergei Trofimovich gentoo-dev 2018-01-01 12:24:36 UTC
(In reply to Hadrien Lacour from comment #10)
> Created attachment 512486 [details]
> gcc opts
> 
> Here, I'm on piledriver.

Thanks! Can you also add target ones?
    $ LANG=C gcc -Q -O2 -march=native --help=target
Comment 12 Hadrien Lacour 2018-01-01 12:32:52 UTC
Created attachment 512488 [details]
gcc target
Comment 13 Sergei Trofimovich gentoo-dev 2018-01-01 14:31:01 UTC
I've added tiny debug entry to get the idea which instruction length is decoded incorrectly:

--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -266,6 +266,7 @@ static int decode_instructions(struct objtool_file *file)
                                                      &insn->len, &insn->type,
                                                      &insn->immediate,
                                                      &insn->stack_op);
+                       fprintf (stderr, "offset: 0x%lx; len=%u; ret=%i\n", offset, insn->len, ret);
                        if (ret)
                                goto err;

'bextr' instruction length is incorrect (reported 2, actual 9):

    15b9:       8f ea 78 10 c0 0f 02    bextr  $0x20f,%eax,%eax
    15c0:       00 00 

    offset: 0x15b9; len=2; ret=0

'bextr' is likely coming from -march=native expansion: -march=bdver2 -mbmi (but I failed to reproduce it locally on gcc-7.2.0).

How exactly you are specifying -march=native when building kernel?
Do you run genkernel or cr to /usr/src and run 'make CFLAGS="-O2 -march=native -pipe"' there?
Comment 14 Hadrien Lacour 2018-01-01 14:53:32 UTC
Now that you say it, maybe I don't build it with march=native. I only do `sudo make -j8` inside /usr/src/linux; the CFLAGS I mentionned are in my make.conf.
Comment 15 Sergei Trofimovich gentoo-dev 2018-01-01 15:37:57 UTC
(In reply to Hadrien Lacour from comment #14)
> Now that you say it, maybe I don't build it with march=native. I only do
> `sudo make -j8` inside /usr/src/linux; the CFLAGS I mentionned are in my
> make.conf.

I think something leaks out to your environment to propagate -march=native to kernel. Let's check what arguments are passed to the compiler in your case:

    $ sudo rm arch/x86/events/core.o
    $ sudo make arch/x86/events/core.o V=1

That should force core.o rebuild and will dump raw gcc command.

[ I've finally reproduced 'bextr' generation locally. It requires CFLAGS="-march=bdver2 -mtbm".

fun fact: "bextr $number,..." is not a BMI encoding (as I initially thought) but TBM encoding. BMI only defines "register,register,register" form of VEX encoding, TBM is "immediate,register,register" form, only AMD implements it currently. Somewhat explains why kernel disassembler misses it as disassembler is based on intel manual. ]
Comment 16 Sergei Trofimovich gentoo-dev 2018-01-01 15:53:39 UTC
Oh, I think I've found it:

https://dev.gentoo.org/~mpagano/genpatches/trunk/4.14/5010_enable-additional-cpu-optimizations-for-gcc.patch

It's enabled with USE=experimental and enables -march=native for CONFIG_MNATIVE
+        cflags-$(CONFIG_MNATIVE) += $(call cc-option,-march=native)

You have it set, right?
Comment 17 Hadrien Lacour 2018-01-01 16:05:30 UTC
Yeah, I should have mentioned it.
Comment 18 Viktor Yu. Kovalskii 2018-01-24 09:24:17 UTC
(In reply to Sergei Trofimovich from comment #16)
> Oh, I think I've found it:
> 
> https://dev.gentoo.org/~mpagano/genpatches/trunk/4.14/5010_enable-additional-
> cpu-optimizations-for-gcc.patch
> 
> It's enabled with USE=experimental and enables -march=native for
> CONFIG_MNATIVE
> +        cflags-$(CONFIG_MNATIVE) += $(call cc-option,-march=native)
> 
> You have it set, right?

I confirm this bug for sys-kernel/gentoo-sources:4.14.15.

with "Native optimizations autodetected by GCC" I have same errors.

with "Generic-x86-64" I have successfully built kernel.

emerge -pv1 sys-kernel/gentoo-sources 

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] sys-kernel/gentoo-sources-4.14.15:4.14.15::gentoo  USE="experimental symlink -build" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB
Comment 19 alpir 2018-01-24 10:11:37 UTC
I confirm this bug for sys-kernel/gentoo-sources-4.14.15 and 4.14.14 with segfault (CONFIG_MPILEDRIVER=y, AMD FX-8320E):
mm/.tmp_memory.o: warning: objtool: print_bad_pte()+0x9c: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: wp_page_copy()+0x3a6: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: __follow_pte_pmd.isra.10()+0x296: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: _vm_normal_page()+0x2a: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: unmap_page_range()+0xf8: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: finish_mkwrite_fault()+0xc7: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: do_wp_page()+0xd2: return with modified stack frame
mm/.tmp_memory.o: warning: objtool: alloc_set_pte()+0x38e: return with modified stack frame
/bin/sh: строка 1: 23359 Ошибка сегментирования                   ./tools/objtool/objtool check "mm/.tmp_memory.o"
make[1]: *** [scripts/Makefile.build:321: mm/memory.o] Ошибка 139
make: *** [Makefile:1028: mm] Ошибка 2

With "Generic-x86-64" I have successfully built kernel.
Comment 20 Adam Carter 2018-01-31 22:41:09 UTC
FYI, on gentoo-sources 4.15.0, changing from CONFIG_MPILEDRIVER to CONFIG_MBULLDOZER was enough to make the kernel build.
Comment 21 Wendy 2018-02-04 14:22:18 UTC
Selecting CONFIG_MBULLDOZER instead of CONFIG_PILEDRIVER solves this bug for me and also bug #645774 starting with kernel 4.14.14
Comment 22 Alice Ferrazzi Gentoo Infrastructure gentoo-dev 2018-03-12 11:27:50 UTC
solved upstream as comment
Comment 23 Hadrien Lacour 2018-03-12 14:06:21 UTC
Can you tell what's the first fixed version? I tried with 4.14.25 and 4.15.9 with CONFIG_MPILEDRIVER to no avail.
Comment 24 Sergei Trofimovich gentoo-dev 2018-03-13 23:22:57 UTC
Reopening until we confirm the issue was fixed/reported upstream.

It's a bit tricky as upstream kernel has no mechanism to build kernel with -march=native today.