Skip to content

Commit

Permalink
Merge tag 'objtool-core-2025-03-22' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/tip/tip

Pull objtool updates from Ingo Molnar:

 - The biggest change is the new option to automatically fail the build
   on objtool warnings: CONFIG_OBJTOOL_WERROR.

   While there are no currently known unfixed false positives left, such
   an expansion in the severity of objtool warnings inevitably creates a
   risk of build failures, so it's disabled by default and depends on
   !COMPILE_TEST, so it shouldn't be enabled on
   allyesconfig/allmodconfig builds and won't be forced on people who
   just accept build-time defaults in 'make oldconfig'.

   While the option is strongly recommended, only people who enable it
   explicitly should see it.

   (Josh Poimboeuf)

 - Disable branch profiling in noinstr code with a broad brush that
   includes all of arch/x86/ and kernel/sched/. (Josh Poimboeuf)

 - Create backup object files on objtool errors and print exact objtool
   arguments to make failure analysis easier (Josh Poimboeuf)

 - Improve noreturn handling (Josh Poimboeuf)

 - Improve rodata handling (Tiezhu Yang)

 - Support jump tables, switch tables and goto tables on LoongArch
   (Tiezhu Yang)

 - Misc cleanups and fixes (Josh Poimboeuf, David Engraf, Ingo Molnar)

* tag 'objtool-core-2025-03-22' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (22 commits)
  tracing: Disable branch profiling in noinstr code
  objtool: Use O_CREAT with explicit mode mask
  objtool: Add CONFIG_OBJTOOL_WERROR
  objtool: Create backup on error and print args
  objtool: Change "warning:" to "error:" for --Werror
  objtool: Add --Werror option
  objtool: Add --output option
  objtool: Upgrade "Linked object detected" warning to error
  objtool: Consolidate option validation
  objtool: Remove --unret dependency on --rethunk
  objtool: Increase per-function WARN_FUNC() rate limit
  objtool: Update documentation
  objtool: Improve __noreturn annotation warning
  objtool: Fix error handling inconsistencies in check()
  x86/traps: Make exc_double_fault() consistently noreturn
  LoongArch: Enable jump table for objtool
  objtool/LoongArch: Add support for goto table
  objtool/LoongArch: Add support for switch table
  objtool: Handle PC relative relocation type
  objtool: Handle different entry size of rodata
  ...
  • Loading branch information
Linus Torvalds committed Mar 25, 2025
2 parents 2360899 + 2cbb20b commit 5a658af
Show file tree
Hide file tree
Showing 35 changed files with 571 additions and 252 deletions.
3 changes: 3 additions & 0 deletions arch/loongarch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ config AS_HAS_LBT_EXTENSION
config AS_HAS_LVZ_EXTENSION
def_bool $(as-instr,hvcl 0)

config CC_HAS_ANNOTATE_TABLEJUMP
def_bool $(cc-option,-mannotate-tablejump)

menu "Kernel type and options"

source "kernel/Kconfig.hz"
Expand Down
6 changes: 5 additions & 1 deletion arch/loongarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ KBUILD_AFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)
KBUILD_CFLAGS += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)

ifdef CONFIG_OBJTOOL
KBUILD_CFLAGS += -fno-jump-tables
ifdef CONFIG_CC_HAS_ANNOTATE_TABLEJUMP
KBUILD_CFLAGS += -mannotate-tablejump
else
KBUILD_CFLAGS += -fno-jump-tables # keep compatibility with older compilers
endif
endif

KBUILD_RUSTFLAGS += --target=loongarch64-unknown-none-softfloat -Ccode-model=small
Expand Down
4 changes: 4 additions & 0 deletions arch/x86/Kbuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# SPDX-License-Identifier: GPL-2.0

# Branch profiling isn't noinstr-safe. Disable it for arch/x86/*
subdir-ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING

obj-$(CONFIG_ARCH_HAS_CC_PLATFORM) += coco/

obj-y += entry/
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/coco/sev/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#define pr_fmt(fmt) "SEV: " fmt

#define DISABLE_BRANCH_PROFILING

#include <linux/sched/debug.h> /* For show_regs() */
#include <linux/percpu-defs.h>
#include <linux/cc_platform.h>
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/kernel/head64.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
*/

#define DISABLE_BRANCH_PROFILING

/* cpu_feature_enabled() cannot be used this early */
#define USE_EARLY_PGTABLE_L5

Expand Down
18 changes: 17 additions & 1 deletion arch/x86/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ __visible void __noreturn handle_stack_overflow(struct pt_regs *regs,
}
#endif

/*
* Prevent the compiler and/or objtool from marking the !CONFIG_X86_ESPFIX64
* version of exc_double_fault() as noreturn. Otherwise the noreturn mismatch
* between configs triggers objtool warnings.
*
* This is a temporary hack until we have compiler or plugin support for
* annotating noreturns.
*/
#ifdef CONFIG_X86_ESPFIX64
#define always_true() true
#else
bool always_true(void);
bool __weak always_true(void) { return true; }
#endif

/*
* Runs on an IST stack for x86_64 and on a special task stack for x86_32.
*
Expand Down Expand Up @@ -514,7 +529,8 @@ DEFINE_IDTENTRY_DF(exc_double_fault)

pr_emerg("PANIC: double fault, error_code: 0x%lx\n", error_code);
die("double fault", regs, error_code);
panic("Machine halted.");
if (always_true())
panic("Machine halted.");
instrumentation_end();
}

Expand Down
1 change: 0 additions & 1 deletion arch/x86/mm/kasan_init_64.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-2.0
#define DISABLE_BRANCH_PROFILING
#define pr_fmt(fmt) "kasan: " fmt

/* cpu_feature_enabled() cannot be used this early */
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/mm/mem_encrypt_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Author: Tom Lendacky <thomas.lendacky@amd.com>
*/

#define DISABLE_BRANCH_PROFILING

#include <linux/linkage.h>
#include <linux/init.h>
#include <linux/mm.h>
Expand Down
2 changes: 0 additions & 2 deletions arch/x86/mm/mem_encrypt_identity.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Author: Tom Lendacky <thomas.lendacky@amd.com>
*/

#define DISABLE_BRANCH_PROFILING

/*
* Since we're dealing with identity mappings, physical and virtual
* addresses are the same, so override these defines which are ultimately
Expand Down
4 changes: 4 additions & 0 deletions drivers/acpi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT

ifdef CONFIG_TRACE_BRANCH_PROFILING
CFLAGS_processor_idle.o += -DDISABLE_BRANCH_PROFILING
endif

#
# ACPI Boot-Time Table Parsing
#
Expand Down
3 changes: 3 additions & 0 deletions drivers/cpuidle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Makefile for cpuidle.
#

# Branch profiling isn't noinstr-safe
ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING

obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o
obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o
Expand Down
5 changes: 4 additions & 1 deletion drivers/idle/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_INTEL_IDLE) += intel_idle.o

# Branch profiling isn't noinstr-safe
ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING

obj-$(CONFIG_INTEL_IDLE) += intel_idle.o
5 changes: 5 additions & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_irq_work.o = $(CC_FLAGS_FTRACE)
endif

# Branch profiling isn't noinstr-safe
ifdef CONFIG_TRACE_BRANCH_PROFILING
CFLAGS_context_tracking.o += -DDISABLE_BRANCH_PROFILING
endif

# Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip()
# in coverage traces.
KCOV_INSTRUMENT_softirq.o := n
Expand Down
3 changes: 3 additions & 0 deletions kernel/entry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ KASAN_SANITIZE := n
UBSAN_SANITIZE := n
KCOV_INSTRUMENT := n

# Branch profiling isn't noinstr-safe
ccflags-$(CONFIG_TRACE_BRANCH_PROFILING) += -DDISABLE_BRANCH_PROFILING

CFLAGS_REMOVE_common.o = -fstack-protector -fstack-protector-strong
CFLAGS_common.o += -fno-stack-protector

Expand Down
5 changes: 5 additions & 0 deletions kernel/sched/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
endif

# Branch profiling isn't noinstr-safe
ifdef CONFIG_TRACE_BRANCH_PROFILING
CFLAGS_build_policy.o += -DDISABLE_BRANCH_PROFILING
CFLAGS_build_utility.o += -DDISABLE_BRANCH_PROFILING
endif
#
# Build efficiency:
#
Expand Down
6 changes: 6 additions & 0 deletions kernel/time/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# SPDX-License-Identifier: GPL-2.0

# Branch profiling isn't noinstr-safe
ifdef CONFIG_TRACE_BRANCH_PROFILING
CFLAGS_sched_clock.o += -DDISABLE_BRANCH_PROFILING
endif

obj-y += time.o timer.o hrtimer.o sleep_timeout.o
obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
obj-y += timeconv.o timecounter.o alarmtimer.o
Expand Down
11 changes: 11 additions & 0 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ config FRAME_POINTER
config OBJTOOL
bool

config OBJTOOL_WERROR
bool "Upgrade objtool warnings to errors"
depends on OBJTOOL && !COMPILE_TEST
help
Fail the build on objtool warnings.

Objtool warnings can indicate kernel instability, including boot
failures. This option is highly recommended.

If unsure, say Y.

config STACK_VALIDATION
bool "Compile-time stack metadata validation"
depends on HAVE_STACK_VALIDATION && UNWINDER_FRAME_POINTER
Expand Down
5 changes: 5 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE)

# Branch profiling isn't noinstr-safe
ifdef CONFIG_TRACE_BRANCH_PROFILING
CFLAGS_smp_processor_id.o += -DDISABLE_BRANCH_PROFILING
endif

# These files are disabled because they produce lots of non-interesting and/or
# flaky coverage that is not a function of syscall inputs. For example,
# rbtree can be global and individual rotations don't correlate with inputs.
Expand Down
1 change: 1 addition & 0 deletions scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call
objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess
objtool-args-$(CONFIG_GCOV_KERNEL) += --no-unreachable
objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
objtool-args-$(CONFIG_OBJTOOL_WERROR) += --Werror --backtrace

objtool-args = $(objtool-args-y) \
$(if $(delay-objtool), --link) \
Expand Down
Loading

0 comments on commit 5a658af

Please sign in to comment.