blazesym 0.2.3

blazesym is a library for address symbolization and related tasks.
Documentation
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
name: Test

on:
  push:
  pull_request:
  workflow_call:

env:
  CARGO_TERM_COLOR: always
  # Enable backtraces for panics but not for "regular" errors.
  RUST_BACKTRACE: 1
  RUST_LIB_BACKTRACE: 0
  # Build with only line information enabled to decrease compilation
  # time and binary artifact sizes in CI, while still providing relevant
  # data in backtraces. This option is assumed to only have marginal
  # effects on the generated code, likely only in terms of section
  # arrangement. See
  # https://doc.rust-lang.org/rustc/codegen-options/index.html#debuginfo
  RUSTFLAGS: '-D warnings -C debuginfo=line-tables-only'

jobs:
  build-linux-kernel:
    uses: libbpf/github-actions/.github/workflows/build-linux.yml@bd7fc70260c9ab81801001fcd86ba94070b34e5d
    secrets: inherit
    with:
      # Please keep in sync with vmlinux release version specification
      # below.
      rev: v6.11
      config: 'data/config'
      vmlinux: true
  build:
    name: Build [${{ matrix.runs-on }}, ${{ matrix.rust }}, ${{ matrix.profile }}, ${{ matrix.args }}]
    runs-on: ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        runs-on: [ubuntu-latest]
        rust: [stable]
        profile: [dev, release]
        # gsym-in-apk requires `blazesym-dev/generate-unit-test-files`
        # feature, which requires `llvm-gsymutil` installed. We don't
        # want that dependency in this large OS spanning matrix.
        args: ["--workspace --exclude=blazesym-dev --exclude=gsym-in-apk"]
        include:
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            # Make sure to build *without* `--workspace` or feature
            # unification may mean that `--no-default-features` goes
            # without effect.
            args: "--lib --no-default-features"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=apk"
          - runs-on: windows-latest
            rust: stable
            profile: release
            args: "--lib --no-default-features"
          - runs-on: windows-latest
            rust: stable
            profile: dev
            args: "--tests --features=blazesym-dev/dont-generate-unit-test-files"
          - runs-on: macos-latest
            rust: stable
            profile: release
            args: "--lib --no-default-features"
          - runs-on: macos-latest
            rust: stable
            profile: dev
            args: "--tests --features=blazesym-dev/dont-generate-unit-test-files"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=breakpad"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=bpf"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=gsym"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=zlib"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--lib --no-default-features --features=zstd"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--package=blazecli"
          - runs-on: ubuntu-latest
            rust: stable
            profile: dev
            args: "--package=blazesym-c"
          - runs-on: ubuntu-latest
            rust: stable
            profile: release
            args: "--package=blazesym-c --no-default-features"
    steps:
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
    - uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.runs-on }}-${{ matrix.rust }}-${{ matrix.profile }}
    - name: Build ${{ matrix.profile }}
      run: |
        cargo build --profile=${{ matrix.profile }} ${{ matrix.args }}
  build-cross:
    name: Cross-compile [${{ matrix.target }}]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        # Please update the build-cli workflow cross-compile matrix when
        # adding a new target here.
        target: [
          aarch64-linux-android,
          arm-linux-androideabi,
          armv7-linux-androideabi,
          i686-unknown-linux-gnu,
          x86_64-unknown-linux-musl,
        ]
    steps:
      - uses: actions/checkout@v6
      - uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: ${{ matrix.target }}
      - run: |
          cargo build --lib
          cargo build --lib --features=bpf
          cargo build --package=blazesym-c --lib
  build-minimum:
    name: Build using minimum versions of dependencies
    runs-on: ubuntu-latest
    env:
      RUSTFLAGS: '-A warnings -C debuginfo=line-tables-only'
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo +nightly -Z minimal-versions update
      - uses: dtolnay/rust-toolchain@master
        with:
          # Please adjust README, `rust-version` field in Cargo.toml,
          # and `msrv` in .clippy.toml when bumping version.
          toolchain: 1.75.0
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --features="apk,backtrace,bpf,demangle,dwarf,gsym,tracing"
      - run: cargo build --package=blazesym-c
  nop-rebuilds:
    name: No-op rebuilds
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
    - name: Check incremental rebuilds
      env:
        CARGO_OPTS: --workspace --quiet --tests
      run: |
        cargo check ${CARGO_OPTS}
        # We need another build here to have the reference `output` file
        # present. As long as we converge eventually it's probably good
        # enough...
        cargo check ${CARGO_OPTS}
        output=$(CARGO_LOG=cargo::core::compiler::fingerprint=info cargo check ${CARGO_OPTS} 2>&1)
        [ -z "${output}" ] || (echo "!!!! cargo check --tests rebuild was not a no-op: ${output} !!!!" && false)
  test-coverage:
    name: Test and coverage
    runs-on: ubuntu-24.04
    needs: [build-linux-kernel]
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@nightly
    - uses: Swatinem/rust-cache@v2
    - uses: actions/setup-python@v6
      id: py312
      with:
        python-version: '3.12'
    - name: Install cargo-llvm-cov
      uses: taiki-e/install-action@cargo-llvm-cov
    - name: Install llvm-tools-preview
      # Install llvm-tools-preview, because we don't want this to happen
      # from within our `vmtest` instance.
      run: rustup component add llvm-tools-preview --toolchain nightly-x86_64-unknown-linux-gnu
    - name: Remove .cargo/config.toml
      # We don't want a custom test runner because we run in a VM.
      run: rm .cargo/config.toml
    - name: Build main.sh
      env:
        ARTIFACT_URL: ${{ needs.build-linux-kernel.outputs.kernel-artifact-url }}
        PYTHON: ${{ steps.py312.outputs.python-path }}
        RUSTFLAGS: '--cfg has_large_test_files'
      shell: bash
      run: |
        # cargo-llvm-cov ultimately is just a thin wrapper around cargo
        # commands with certain environment variables set. Because it
        # does not allow us to build binaries and execute them in
        # different steps, we have to roll our own logic for doing just
        # that, because we do not want to build inside a nested VM...
        cargo llvm-cov show-env | sed 's@.*@export \0@' > env.sh
        echo "export PYTHON=${PYTHON}" >> env.sh
        source env.sh

        cargo test --no-run --workspace --all-targets --features=zstd,nightly,blazesym-dev/generate-large-test-files 2>&1 | tee /tmp/cargo-build.log
        tests=$(IFS='' grep Executable /tmp/cargo-build.log |
          awk '{print $NF}' |
          sed 's@[()]@@g' |
          sed 's@.*@\0 --include-ignored@'
        )
        # Yes, there appears to be no way to just retrieve the
        # uploaded artifact. One can't use actions/download-artifact
        # and provide any of the outputs of actions/upload-artifact.
        # Neither does it seem possible to just download the thing
        # directly, because contents are unconditionally zipped. Good.
        # Lord.
        curl --location \
          --fail-with-body \
          --header "Accept: application/vnd.github+json" \
          --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
          --header "X-GitHub-Api-Version: 2022-11-28" \
          --output artifact.zip \
          "${ARTIFACT_URL}"
        # This unzip will produce the kernel bzImage and vmlinux.
        unzip artifact.zip
        # Put vmlinux file into a location amenable to auto-discovery.
        sudo mv vmlinux /boot/vmlinux-6.11.0

        cat <<EOF > main.sh
        #!/bin/sh
        set -e
        . ./env.sh
        $tests
        cargo llvm-cov report --ignore-filename-regex=cli/src/ --lcov --output-path lcov.info
        EOF
        chmod a+x main.sh
    - name: Test and gather coverage
      uses: danobi/vmtest-action@f8c84191b5925c3290595743fc46eaaafd827bf3
      with:
        kernel: bzImage
        command: sh -c 'cd ${{ github.workspace }} && ./main.sh'
    - name: Upload code coverage results
      uses: codecov/codecov-action@v5
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      with:
        files: lcov.info
  build-test-artifacts:
    # Only run tests on other operating systems on the final push. They
    # are very unlikely to break at runtime (we build them anyway), but
    # take quite a bit longer than Linux based ones.
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
    name: Build test artifacts
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
    - run: cargo check --package=blazesym-dev --features=generate-unit-test-files
    - uses: actions/upload-artifact@v6
      with:
        name: test-stable-addrs
        if-no-files-found: error
        path: |
          data/libtest-so*
          data/test-no-debug.bin
          data/test-rs.bin
          data/test-stable-addrs*
  test-partly-supported:
    name: Test on ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        runs-on: [macos-latest, windows-latest]
    runs-on: ${{ matrix.runs-on }}
    needs: [build-test-artifacts]
    steps:
    - uses: actions/checkout@v6
    - uses: actions/download-artifact@v7
      with:
        name: test-stable-addrs
        path: data/
    - uses: dtolnay/rust-toolchain@stable
    - run: cargo test --tests --release --features=blazesym-dev/dont-generate-unit-test-files -- ':other_os:'
  test-sanitizers:
    name: Test with ${{ matrix.sanitizer }} sanitizer
    strategy:
      fail-fast: false
      matrix:
        sanitizer: [address]
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@nightly
    - uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.sanitizer }}
    - name: cargo test -Zsanitizer=${{ matrix.sanitizer }}
      env:
        # TODO: Ideally we'd set CFLAGS and CXXFLAGS as well, but some
        #       of our transitive dependencies don't play nice with
        #       ASAN.
        #CFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
        #CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
        RUSTFLAGS: "-Zsanitizer=${{ matrix.sanitizer }}"
        ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=1"
      # Enable `zstd` feature, which is not yet default in
      # `blazesym-dev` but good to test with in CI.
      run: cargo test --workspace --lib --tests --features=zstd --target x86_64-unknown-linux-gnu
  test-release:
    name: Test with release build
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev liblzma-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
    - uses: Swatinem/rust-cache@v2
    - run: echo "RUSTFLAGS=${RUSTFLAGS} -C debuginfo=limited" >> $GITHUB_ENV
    - env:
        # Support incremental compilation here to not penalize CI compile times too much.
        CARGO_PROFILE_RELEASE_INCREMENTAL: true
        CARGO_PROFILE_RELEASE_LTO: false
      # Enable `zstd` feature, which is not yet default in
      # `blazesym-dev` but good to test with in CI.
      run: cargo test --workspace --features=zstd --release
  test-miri:
    name: Test with Miri
    runs-on: ubuntu-latest
    env:
      # Stack borrows are very experimental. Disable for now.
      MIRIFLAGS: '-Zmiri-disable-stacked-borrows'
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@nightly
      with:
        components: miri
    # Miri would honor our custom test runner, but doesn't work with it. We
    # could conceivably override that by specifying
    # CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER, except it appears as if Miri
    # uses the runner itself. In short, it's a mess. Just remove any
    # such custom configuration when running Miri.
    - name: Remove .cargo/config.toml
      run: rm .cargo/config.toml
    - name: Run tests
      run: cargo miri test --workspace --features=blazesym-dev/dont-generate-unit-test-files -- ":miri:"
  test-32bit:
    name: Test 32bit
    runs-on: ubuntu-latest
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
      with:
        targets: "i686-unknown-linux-gnu"
    - uses: Swatinem/rust-cache@v2
    - run: cargo check --target x86_64-unknown-linux-gnu --package=blazesym-dev --features=generate-unit-test-files
    - name: Install development dependencies
      run: |
        sudo dpkg --add-architecture i386
        sudo apt-get update
        sudo apt-get remove libllvm18
        sudo apt-get install --yes --no-install-recommends libclang-dev:i386
    - run: cargo test --package=blazesym-c --target i686-unknown-linux-gnu
  test-examples:
    name: Test examples
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
    - run: echo "RUSTFLAGS=${RUSTFLAGS} -C debuginfo=limited" >> $GITHUB_ENV
    - run: cargo run --example backtrace
    - run: cargo run --example inspect-mangled
    - run: cargo run --example normalize-virt-offset
    - run: cargo run --package gsym-in-apk
  c-header:
    name: Check generated C header
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@stable
    - run: cargo check --package=blazesym-c --features=generate-c-header
    - name: Check that C header is up-to-date
      run: git diff --exit-code ||
             (echo "!!!! CHECKED IN C HEADER IS OUTDATED !!!!" && false)
  bench:
    # Only run benchmarks on the final push. They are generally only
    # informative because the GitHub Runners do not provide a stable
    # performance baseline anyway.
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
    name: Benchmark
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
    - name: Install development dependencies
      run: |
        sudo apt-get update
        sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
    - uses: actions/checkout@v6
    - uses: dtolnay/rust-toolchain@master
      with:
        # TODO: Remove specification and switch back to @nightly once
        #       `function_casts_as_integer` lint is stable.
        toolchain: 'nightly-2025-11-05'
    - name: Run benchmarks
      shell: bash
      run: |
        echo '```' >> $GITHUB_STEP_SUMMARY
        cargo bench --workspace --features=nightly,blazesym-dev/generate-large-test-files -- bench_ | tee --append $GITHUB_STEP_SUMMARY
        # We use bencher format here for better relation to the above
        # but also because it emits less other crap into our summary.
        # Note that because libtest does not understand the
        # `--output-format` option, we need to specify the benchmark
        # binary (`main`) here and have a different invocation for
        # libtest style benchmarks above. Sigh.
        cargo bench --workspace --bench=main --bench=capi --features=blazesym-dev/dont-generate-unit-test-files -- --output-format=bencher | tee --append $GITHUB_STEP_SUMMARY
        echo '```' >> $GITHUB_STEP_SUMMARY
  clippy:
    name: Lint with clippy
    runs-on: ubuntu-latest
    steps:
      - name: Install development dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --yes --no-install-recommends libelf-dev zlib1g-dev
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo clippy --workspace --no-deps --all-targets --features=blazesym-dev/dont-generate-unit-test-files -- -A unknown_lints -D clippy::todo
  rustfmt:
    name: Check code formatting
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt
      - run: cargo +nightly fmt --all -- --check
  cargo-doc:
    name: Generate documentation
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
      RUSTDOCFLAGS: '--cfg docsrs -D warnings'
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo doc --workspace --exclude=blazesym-dev --exclude=gsym-in-apk --no-deps --document-private-items
  go:
    name: Run Go tests
    runs-on: ubuntu-24.04
    env:
      LLVM_GSYMUTIL: /usr/bin/llvm-gsymutil-18
    steps:
      - name: Install development dependencies
        run: |
          sudo apt-get update
          sudo apt-get install --yes --no-install-recommends gcc-multilib libelf-dev zlib1g-dev
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@nightly
      - run: cargo check --package blazesym-dev --features=generate-unit-test-files
      - run: cargo build --package blazesym-c
      - uses: actions/setup-go@v6
        with:
          go-version: stable
      - uses: golangci/golangci-lint-action@v9
        with:
          version: v2.6
          working-directory: go
        env:
          CGO_CFLAGS: "-I${{ github.workspace }}/capi/include"
      # Tests are compiled first to include debug info, which is skipped in regular `go test`.
      - run: cd go && CGO_CFLAGS="-I$(pwd)/../capi/include" CGO_LDFLAGS="-L$(pwd)/../target/debug" go test -v -c -o /tmp/test . && LD_LIBRARY_PATH=$(pwd)/../target/debug /tmp/test -test.v
  deps:
    name: Check for duplicate dependencies
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - shell: bash
        run: |
          out=$(cargo tree --quiet --duplicates --edges normal 2> /dev/null)
          if [ -n "$out" ]; then
            echo -e "duplicate dependencies found:\n${out}"
            exit 1
          fi

  required-checks:
    needs: [
      build,
      build-cross,
      build-minimum,
      nop-rebuilds,
      test-coverage,
      test-sanitizers,
      test-release,
      test-miri,
      test-examples,
      c-header,
      clippy,
      rustfmt,
      cargo-doc,
      go,
      deps,
    ]
    if: always()
    runs-on: ubuntu-latest
    steps:
      - run: echo '${{ toJSON(needs) }}' | jq -e 'to_entries | all(.value.result == "success")'