Commit dc78f01
committed
[ABLD-464] Strip debug symbols at packaging time (Plan B)
**what this does**
Adds a packaging-time filter, `dd_pkg_files_stripped` (in
`bazel/rules/dd_packaging/dd_pkg_strip_transform.bzl`), that replaces plain
`pkg_files` calls for shipped binaries. It strips object files as they're
collected into a package and splits the removed debug info into a parallel
`name + "_debug"` sibling target, without requiring any cooperation from the
binary's own build rule -- it works directly against prebuilt-file-backed
targets like `@agent_binary//:agent`, which is this design's main advantage
over the alternative provider/rule-based approach considered in the same
design doc (Plan A, implemented separately).
A single `_dd_strip_split` action runs strip/objcopy/dsymutil once per file
and declares both the "stripped" and "debug" outputs at once; the public
`dd_pkg_strip_transform` rule only projects one half of that shared result,
so building both the normal package and its debug sibling never doubles the
work. File-type detection (ELF/Mach-O/PE) happens at action-execution time in
a new Python driver (`dd_strip_driver.py`), since Starlark can't inspect file
contents during analysis; the Starlark side only applies a cheap
extension/mode-bit heuristic to skip spawning actions for obviously
non-binary files.
Tool paths come from a new `//bazel/toolchains/dd_strip` toolchain: Linux and
Windows source `strip`/`objcopy` off the existing `cc_toolchain`; macOS
hardcodes `/usr/bin/strip` and `/usr/bin/dsymutil` (modeled after
`//bazel/rules/rewrite_rpath`'s hardcoded-path pattern rather than
`//bazel/toolchains/codesign`'s auto-detecting repository_rule, since that
pattern generates a `config_setting` per tool and new config_settings need
separate design review).
Platform semantics match `omnibus-ruby/lib/omnibus/stripper.rb`: Linux does
the 3-step objcopy --only-keep-debug / strip / objcopy --add-gnu-debuglink;
macOS runs `strip -x` plus `dsymutil` into a `.dSYM` bundle; Windows ships a
`strip`'d binary alongside the unstripped original (mingw's toolchain has no
`objcopy`, so there's no split-DWARF story there, matching the existing
`windows_symbol_stripping_file` behavior).
Wired into `packages/agent/product/BUILD.bazel` (the four `dda_built_*_binary`
targets, plus a new `all_files_debug` pkg_filegroup) and
`packages/installer/windows/BUILD.bazel` (`installer_binary` plus a new
`installer_components_debug`). Removed the one-shot
`-Cstrip=symbols` rustc flag from `bazel/configs/system_probe_lite.bazelrc`,
which used to destroy debug info before packaging ever saw it. Updated
`packages/AGENTS.md` and `packages/installer/MIGRATION_PLAN.md` to reflect
that symbol stripping is now migrated.
**testing**
Built and inspected output on macOS (arm64) at each stage:
- A throwaway target wrapping `//cmd/loader:loader` confirmed both the
"stripped" and "debug_only" modes produce sane output: `strip -x` removed
local symbols, `dsymutil` produced a `.dSYM` bundle with a DWARF resource,
and building both mode targets together registered the `DdStripSplit`
action exactly once (verified in the verbose build log).
- `bazel build //packages/agent/product:all_files //packages/agent/product:all_files_debug`
and `//packages/installer/windows:whole_distro_tar //packages/installer/windows:installer_components_debug`
succeed against the real prebuilt targets (`@agent_binary`,
`@trace_agent_binary`, `@process_agent_binary`,
`@privateactionrunner_binary`, `@installer_binary`).
- Along the way, fixed two real bugs surfaced by this: `Args.add()` can't
take a directory (needed `.path` for the `.dSYM` output), and the
passthrough path crashed when the declared debug output was a directory
but the driver couldn't recognize the input's format (hit when packaging a
Linux ELF prebuilt from a macOS host, since the macOS toolchain has no
objcopy -- this is a local-only condition, not a bug in the Linux path
itself).
- `bazel test //bazel/rules/dd_packaging:_dd_packaging_tests` (the existing
suite) still passes -- no regression in the unrelated packaging rules this
shares a package with.
- Could NOT verify on this machine: the actual Linux ELF split (no Linux
sandbox/CI available locally -- the `@trace_agent_binary` prebuilt is a
real Linux ELF, but macOS's `dd_strip` toolchain has no `objcopy`, so it
fell through to passthrough rather than exercising `_strip_elf`), and
whether the produced `.dSYM`/`.debug` artifacts are actually useful to a
debugger (no symbolication round-trip was attempted).
- No unit tests were added for `dd_pkg_strip_transform`/`_dd_strip_split`
themselves (analysistest-style, like `dd_packaging_test.bzl`) -- only
manual `bazel build` + filesystem inspection.
**next steps**
- The Linux objcopy path needs validation in CI or a Linux sandbox before
this can be trusted end-to-end.
- The macOS `dSYM`-splitting approach hasn't been reviewed by the build
team; `strip -x` semantics (keeps global symbols) match omnibus but
deserve a second look.
- Whatever builds `bin/agent/agent` and friends outside Bazel (dda/omnibus)
must also stop pre-stripping, or there will be no debug info left for this
filter to split off -- that's a separate, out-of-scope dependency for this
PR (the Rust/system-probe-lite case is fixed here; the Go/dda case is not).
- Plan A (implemented separately, in parallel) builds its own independent
copy of the same toolchain shape under `//bazel/toolchains/dd_strip` by
design -- deduplicating the two toolchains is a deliberate follow-up, not
done here.1 parent fec92d8 commit dc78f01
12 files changed
Lines changed: 695 additions & 11 deletions
File tree
- bazel
- configs
- rules/dd_packaging
- toolchains/dd_strip
- packages
- agent/product
- installer
- windows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
0 commit comments