linux-stable/tools/objtool
Petr Pavlu aadb82bb7c x86/retpoline,kprobes: Fix position of thunk sections with CONFIG_LTO_CLANG
commit 79cd2a1122 upstream.

The linker script arch/x86/kernel/vmlinux.lds.S matches the thunk
sections ".text.__x86.*" from arch/x86/lib/retpoline.S as follows:

  .text {
    [...]
    TEXT_TEXT
    [...]
    __indirect_thunk_start = .;
    *(.text.__x86.*)
    __indirect_thunk_end = .;
    [...]
  }

Macro TEXT_TEXT references TEXT_MAIN which normally expands to only
".text". However, with CONFIG_LTO_CLANG, TEXT_MAIN becomes
".text .text.[0-9a-zA-Z_]*" which wrongly matches also the thunk
sections. The output layout is then different than expected. For
instance, the currently defined range [__indirect_thunk_start,
__indirect_thunk_end] becomes empty.

Prevent the problem by using ".." as the first separator, for example,
".text..__x86.indirect_thunk". This pattern is utilized by other
explicit section names which start with one of the standard prefixes,
such as ".text" or ".data", and that need to be individually selected in
the linker script.

  [ nathan: Fix conflicts with SRSO and fold in fix issue brought up by
    Andrew Cooper in post-review:
    https://lore.kernel.org/20230803230323.1478869-1-andrew.cooper3@citrix.com ]

Fixes: dc5723b02e ("kbuild: add support for Clang LTO")
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230711091952.27944-2-petr.pavlu@suse.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-23 17:32:41 +02:00
..
Documentation docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
arch x86/cpu: Rename original retbleed methods 2023-08-23 17:32:40 +02:00
include/objtool objtool/x86: Fix SRSO mess 2023-08-23 17:32:39 +02:00
.gitignore objtool: Install libsubcmd in build 2023-01-30 16:27:46 -08:00
Build objtool: Install libsubcmd in build 2023-01-30 16:27:46 -08:00
Makefile objtool: Fix HOSTCC flag usage 2023-02-01 09:15:18 -08:00
builtin-check.c objtool: Make struct check_options static 2023-02-01 09:15:23 -08:00
check.c x86/retpoline,kprobes: Fix position of thunk sections with CONFIG_LTO_CLANG 2023-08-23 17:32:41 +02:00
elf.c objtool: Add symbol iteration helpers 2023-04-14 16:08:29 +02:00
objtool.c objtool: Remove instruction::list 2023-02-23 09:21:44 +01:00
orc_dump.c x86,objtool: Split UNWIND_HINT_EMPTY in two 2023-03-23 23:18:58 +01:00
orc_gen.c objtool: Add WARN_INSN() 2023-04-14 16:08:28 +02:00
special.c objtool: Make struct entries[] static and const 2023-02-01 09:15:22 -08:00
sync-check.sh objtool: Add objtool_types.h 2023-03-23 23:18:56 +01:00
weak.c objtool: Ditch subcommands 2022-04-22 12:32:01 +02:00