]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
distro/include: rework debug friendly optimization
authorHongxu Jia <hongxu.jia@windriver.com>
Mon, 22 Dec 2025 14:53:58 +0000 (22:53 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 22 Jan 2026 16:50:56 +0000 (16:50 +0000)
The problem with DEBUG_BUILD is that we have a lot of debug information
in builds anyway and this is now unclear what it means. The
documentation.conf entry mentions packages which is now incorrect too.
The variable is a very old one and the interface is poorly designed
compared to other areas now.

This commit drop DEBUG_BUILD, use DEBUG_OPTIMIZE to instead, add
debug-optimize.bbclass and debug-optimize.inc. Use variable DEBUG_OPTIMIZE
to defer inherit debug-optimize.bbclass conditionally.

Make a config fragment core/yocto/debug-optimize to set DEBUG_OPTIMIZE ?= 1
to enable debug friendly optimize. For the recipe (such as qemu) which doesn't
work with debug optimization, set DEBUG_OPTIMIZE = "0" to disable it for a
given recipe even though config fragment core/yocto/debug-optimize is enabled

In bitbake.conf, use ??= to set *_OPTIMIZATION, in debug-optimize.inc
to use ?= to override *_OPTIMIZATION

In debug-optimize.bbclass, include_all debug-optimize.inc to allow other
layers to add their own debug optimization configurations.

User should use the following ways to enable debug optimize

  $ bitbake-config-build enable-fragment core/yocto/debug-optimize

Or

  $ echo 'OE_FRAGMENTS += "core/yocto/debug-optimize"' >> conf/local.conf

NOTE: we do not encourage user to enable debug friendly optimization by setting
DEBUG_OPTIMIZE = '1' directly, because the variable override is not certainty,
which is affected by the order of configuration parsing

Suggested-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Suggested-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-global/base.bbclass
meta/classes/debug-optimize.bbclass [new file with mode: 0644]
meta/conf/bitbake.conf
meta/conf/distro/include/debug-optimize.inc [new file with mode: 0644]
meta/conf/documentation.conf
meta/conf/fragments/yocto/debug-optimize.conf [new file with mode: 0644]
meta/conf/templates/default/local.conf.sample.extended
meta/recipes-devtools/qemu/qemu.inc

index cf303c237a5a93a607c9b20dd85c36c3fc1006ed..3c9488cd45e7493cf3115721cd5d2a40bbb5cbdc 100644 (file)
@@ -35,6 +35,9 @@ TOOLCHAIN_NATIVE ??= "${PREFERRED_TOOLCHAIN_NATIVE}"
 inherit_defer toolchain/${TOOLCHAIN_NATIVE}-native
 inherit_defer toolchain/${TOOLCHAIN}
 
+DEBUG_OPTIMIZE ??= "0"
+inherit_defer ${@oe.utils.vartrue('DEBUG_OPTIMIZE', 'debug-optimize', '',d)}
+
 def lsb_distro_identifier(d):
     adjust = d.getVar('LSB_DISTRO_ADJUST')
     adjust_func = None
diff --git a/meta/classes/debug-optimize.bbclass b/meta/classes/debug-optimize.bbclass
new file mode 100644 (file)
index 0000000..8d26d03
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+# Allow other layers to add their own debug build configurations
+include_all conf/distro/include/debug-optimize.inc
index 88f4d0df6919ddef636cfcc8d2828fae78a8e8b8..653d396c79596639690ff2e6de2cd9c1e12ec847 100644 (file)
@@ -659,13 +659,10 @@ DEBUG_PREFIX_MAP ?= "${DEBUG_PREFIX_MAP_EXTRA} \
 "
 DEBUG_LEVELFLAG ?= "-g"
 
-FULL_OPTIMIZATION = "-O2 ${DEBUG_LEVELFLAG}"
-DEBUG_OPTIMIZATION = "-Og ${DEBUG_LEVELFLAG}"
-SELECTED_OPTIMIZATION = "${@d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
-SELECTED_OPTIMIZATION[vardeps] += "FULL_OPTIMIZATION DEBUG_OPTIMIZATION DEBUG_BUILD"
+FULL_OPTIMIZATION ??= "-O2 ${DEBUG_LEVELFLAG}"
+SELECTED_OPTIMIZATION ??= "${FULL_OPTIMIZATION}"
 # compiler flags for native/nativesdk
-BUILD_OPTIMIZATION = "${@oe.utils.vartrue('DEBUG_BUILD', '-Og -g', '-O2', d)}"
-BUILD_OPTIMIZATION[vardeps] += "DEBUG_BUILD"
+BUILD_OPTIMIZATION ??= "-O2"
 
 ##################################################################
 # Reproducibility
diff --git a/meta/conf/distro/include/debug-optimize.inc b/meta/conf/distro/include/debug-optimize.inc
new file mode 100644 (file)
index 0000000..b5fb3bb
--- /dev/null
@@ -0,0 +1,5 @@
+# Override SELECTED_OPTIMIZATION and BUILD_OPTIMIZATION when fragment 'core/yocto/debug-optimize' is enabled.
+DEBUG_OPTIMIZATION ?= "-Og ${DEBUG_LEVELFLAG}"
+SELECTED_OPTIMIZATION ?= "${DEBUG_OPTIMIZATION}"
+# compiler flags for native/nativesdk
+BUILD_OPTIMIZATION ?= "-Og -g"
index 741130a3921eb578874d05b7e1663578b4fae4fb..956d4a79a683a5232f7d6101e837092c2ecadf75 100644 (file)
@@ -129,8 +129,8 @@ CVE_CHECK_LAYER_INCLUDELIST[doc] = "Defines which layers to include during cve-c
 D[doc] = "The destination directory."
 DATE[doc] = "The date the build was started using YMD format."
 DATETIME[doc] = "The date and time the build was started."
-DEBUG_BUILD[doc] = "Specifies to build packages with debugging information. This influences the value of the SELECTED_OPTIMIZATION variable."
 DEBUG_OPTIMIZATION[doc] = "The options to pass in TARGET_CFLAGS and CFLAGS when compiling a system for debugging. This variable defaults to '-Og ${DEBUG_LEVELFLAG}'."
+DEBUG_OPTIMIZE[doc] = "Specifies to build recipe with debugging friendly optimization. This influences the value of the SELECTED_OPTIMIZATION variable."
 DEFAULT_PREFERENCE[doc] = "Specifies a weak bias for recipe selection priority."
 DEPENDS[doc] = "Lists a recipe's build-time dependencies (i.e. other recipe files)."
 DEPLOY_DIR[doc] = "Points to the general area that the OpenEmbedded build system uses to place images, packages, SDKs and other output files that are ready to be used outside of the build system."
@@ -370,7 +370,7 @@ SDK_OUTPUT[doc] = "The location used by the OpenEmbedded build system when creat
 SDKIMAGE_FEATURES[doc] = "Equivalent to IMAGE_FEATURES. However, this variable applies to the SDK generated from an image using the command 'bitbake -c populate_sdk imagename'."
 SDKMACHINE[doc] = "Specifies the architecture (i.e. i686 or x86_64) for which to build SDK and ADT items."
 SECTION[doc] = "The section in which packages should be categorized. Package management utilities can make use of this variable."
-SELECTED_OPTIMIZATION[doc] = "The variable takes the value of FULL_OPTIMIZATION unless DEBUG_BUILD = '1'. In this case, the value of DEBUG_OPTIMIZATION is used."
+SELECTED_OPTIMIZATION[doc] = "The variable takes the value of FULL_OPTIMIZATION unless fragment 'core/yocto/debug-optimize' is enabled. In this case, the value of DEBUG_OPTIMIZATION is used."
 SERIAL_CONSOLES[doc] = "Defines the serial consoles (TTYs) to enable using getty."
 SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS[doc] = "A list of recipe dependencies that should not be used to determine signatures of tasks from one recipe when they depend on tasks from another recipe."
 SIGGEN_EXCLUDERECIPES_ABISAFE[doc] = "A list of recipes that are completely stable and will never change."
diff --git a/meta/conf/fragments/yocto/debug-optimize.conf b/meta/conf/fragments/yocto/debug-optimize.conf
new file mode 100644 (file)
index 0000000..000b5a5
--- /dev/null
@@ -0,0 +1,7 @@
+BB_CONF_FRAGMENT_SUMMARY = "Specifies to build recipes with debugging friendly optimization. \
+This influences the value of the SELECTED_OPTIMIZATION variable."
+BB_CONF_FRAGMENT_DESCRIPTION = "Enables full debug and backtrace capabilities for all programs \
+and libraries in the image, by modifying the SELECTED_OPTIMIZATION variable, \
+setting it to "DEBUG_OPTIMIZATION"."
+
+DEBUG_OPTIMIZE ?= "1"
index a898b18d59fa9baad024480bc47765f276b249fd..ecf1855d2a05a02dcbe0184f7f56a7bf285f926d 100644 (file)
@@ -67,7 +67,7 @@
 #
 # Uncomment this to change the optimization to make debugging easer, at the
 # possible cost of performance.
-# DEBUG_BUILD = "1"
+# OE_FRAGMENTS += "core/yocto/debug-optimize"
 #
 # Uncomment this to disable the stripping of the installed binaries
 # INHIBIT_PACKAGE_STRIP = "1"
index d320b13ba782a1da73ff658a08760725bc2ce26f..b4fbee6752d792230ac32aa950f2071ef3802d47 100644 (file)
@@ -60,8 +60,8 @@ COMPATIBLE_HOST:mipsarchn64 = "null"
 COMPATIBLE_HOST:riscv32 = "null"
 
 # Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
-# upstream states qemu doesn't work without optimization
-DEBUG_BUILD = "0"
+# upstream states qemu doesn't work with debug friendly optimization
+DEBUG_OPTIMIZE = "0"
 
 do_install:append() {
     # Prevent QA warnings about installed ${localstatedir}/run