Skip to contentSkip to conversation

meson.build: default to -gsplit-dwarf for debug info

PATCH Applied Alex Bennée 2 participants 2 messages Mar 7, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 meson.build: default to -gsplit-dwarf for debug info

This option is supported by both gcc (since 4.7) and clang (since 7.0). Not only does this make the linkers job easier by reducing the amount of ELF it needs to parse it also reduces the total build size quite considerably. In my case a default build went from 5.8G to 3.9G (vs 1.9G for --disable-debug-info).

The --disable-split-debug option allows distros to keep all the info together for ease of packaging.

---
v1
- add --disable/enable-split-debug
- move to option_cflags
v2
- removed unneeded []'s
- fix stray whitespace
v3
- set qemu_cflags instead of option_cflags
- move up to the rest of the qemu_cflag setting code
- update build size numbers with --disable-debug-info
v4
- we don't need to pass -g, due to meson doing it under the hood
- add comment around option_cflags to make mesons roll clear

---
 meson.build                   | 6 ++++++
 meson_options.txt             | 2 ++
 scripts/meson-buildoptions.sh | 2 ++
 3 files changed, 10 insertions(+)
meson.build +6 -0
index 8d0abe7f12..a8db76fccc 100644
@@ -601,6 +601,10 @@ if get_option('tsan')
   qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
 endif
 
+if get_option('debug') and get_option('split_debug')
+  qemu_cflags += '-gsplit-dwarf'
+endif
+
 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
 # The combination is known as "full relro", because .got.plt is read-only too.
 qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro', '-Wl,-z,now')
@@ -4589,6 +4593,8 @@ if have_rust
   summary_info += {'bindgen':         bindgen.full_path()}
   summary_info += {'bindgen version': bindgen.version()}
 endif
+# option_cflags is purely for the summary display, meson will pass
+# -g/-O options directly
 option_cflags = (get_option('debug') ? ['-g'] : [])
 if get_option('optimization') != 'plain'
   option_cflags += ['-O' + get_option('optimization')]
meson_options.txt +2 -0
index 59d973bca0..3432123fee 100644
@@ -362,6 +362,8 @@ option('debug_mutex', type: 'boolean', value: false,
        description: 'mutex debugging support')
 option('debug_stack_usage', type: 'boolean', value: false,
        description: 'measure coroutine stack usage')
+option('split_debug', type: 'boolean', value: true,
+       description: 'split debug info from object files')
 option('qom_cast_debug', type: 'boolean', value: true,
        description: 'cast debugging support')
 option('slirp_smbd', type : 'feature', value : 'auto',
scripts/meson-buildoptions.sh +2 -0
index 3e8e00852b..aca6e68830 100644
@@ -504,6 +504,8 @@ _meson_option_parse() {
     --disable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=false ;;
     --enable-strip) printf "%s" -Dstrip=true ;;
     --disable-strip) printf "%s" -Dstrip=false ;;
+    --enable-split-debug) printf "%s" -Dsplit_debug=true ;;
+    --disable-split-debug) printf "%s" -Dsplit_debug=false ;;
     --sysconfdir=*) quote_sh "-Dsysconfdir=$2" ;;
     --enable-tcg) printf "%s" -Dtcg=enabled ;;
     --disable-tcg) printf "%s" -Dtcg=disabled ;;
Signature · 1 line
2.39.5
#1 lore raw

Il ven 7 mar 2025, 16:17 Alex Bennée <[email protected]> ha scritto:

Quoted 6 lines

This option is supported by both gcc (since 4.7) and clang (since 7.0). Not only does this make the linkers job easier by reducing the amount of ELF it needs to parse it also reduces the total build size quite considerably. In my case a default build went from 5.8G to 3.9G (vs 1.9G for --disable-debug-info).

Quoted 6 lines

The --disable-split-debug option allows distros to keep all the info together for ease of packaging.

Queued, thanks.

Paolo

Quoted 76 lines

---
v1
- add --disable/enable-split-debug
- move to option_cflags
v2
- removed unneeded []'s
- fix stray whitespace
v3
- set qemu_cflags instead of option_cflags
- move up to the rest of the qemu_cflag setting code
- update build size numbers with --disable-debug-info
v4
- we don't need to pass -g, due to meson doing it under the hood
- add comment around option_cflags to make mesons roll clear

---
 meson.build                   | 6 ++++++
 meson_options.txt             | 2 ++
 scripts/meson-buildoptions.sh | 2 ++
 3 files changed, 10 insertions(+)
meson.build +4 -0
index 8d0abe7f12..a8db76fccc 100644
@@ -601,6 +601,10 @@ if get_option('tsan')
   qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
 endif
 
+if get_option('debug') and get_option('split_debug')
+  qemu_cflags += '-gsplit-dwarf'
+endif
+
 # Detect support for PT_GNU_RELRO + DT_BIND_NOW.
 # The combination is known as "full relro", because .got.plt is read-only

too.
qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro',
'-Wl,-z,now')

meson.build +2 -0
@@ -4589,6 +4593,8 @@ if have_rust
   summary_info += {'bindgen':         bindgen.full_path()}
   summary_info += {'bindgen version': bindgen.version()}
 endif
+# option_cflags is purely for the summary display, meson will pass
+# -g/-O options directly
 option_cflags = (get_option('debug') ? ['-g'] : [])
 if get_option('optimization') != 'plain'
   option_cflags += ['-O' + get_option('optimization')]
meson_options.txt +2 -0
index 59d973bca0..3432123fee 100644
@@ -362,6 +362,8 @@ option('debug_mutex', type: 'boolean', value: false,
        description: 'mutex debugging support')
 option('debug_stack_usage', type: 'boolean', value: false,
        description: 'measure coroutine stack usage')
+option('split_debug', type: 'boolean', value: true,
+       description: 'split debug info from object files')
 option('qom_cast_debug', type: 'boolean', value: true,
        description: 'cast debugging support')
 option('slirp_smbd', type : 'feature', value : 'auto',
scripts/meson-buildoptions.sh +2 -1
index 3e8e00852b..aca6e68830 100644
@@ -504,6 +504,8 @@ _meson_option_parse() {
     --disable-strict-rust-lints) printf "%s" -Dstrict_rust_lints=false ;;
     --enable-strip) printf "%s" -Dstrip=true ;;
     --disable-strip) printf "%s" -Dstrip=false ;;
+    --enable-split-debug) printf "%s" -Dsplit_debug=true ;;
+    --disable-split-debug) printf "%s" -Dsplit_debug=false ;;
     --sysconfdir=*) quote_sh "-Dsysconfdir=$2" ;;
     --enable-tcg) printf "%s" -Dtcg=enabled ;;
     --disable-tcg) printf "%s" -Dtcg=disabled ;;
--

2.39.5