Skip to content

feat(gcc): add libbacktrace-static subpackage - #18458

Draft
Nan Liu (liunan-ms) wants to merge 1 commit into
microsoft:4.0from
liunan-ms:liunan/add-libbacktrace-static
Draft

feat(gcc): add libbacktrace-static subpackage#18458
Nan Liu (liunan-ms) wants to merge 1 commit into
microsoft:4.0from
liunan-ms:liunan/add-libbacktrace-static

Conversation

@liunan-ms

@liunan-ms Nan Liu (liunan-ms) commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Upstream GCC builds libbacktrace for internal use only and deliberately does not install the static archive or header. This PR adds a new libbacktrace-static subpackage to gcc, exposing GCC's internal libbacktrace static library (libbacktrace.a) and its public header(backtrace.h).

Changes

  • New overlay file base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml
    (single file-level [metadata], category = azl-platform-adaptation):
    • Bump the manual gcc_release (7 → 8) so the new subpackage and its
      dependents rebuild.
    • Declare %package -n libbacktrace-static + %description.
    • %install: locate the built libbacktrace.a in the obj tree and install it
      plus backtrace.h into the buildroot.
    • %files -n libbacktrace-static.
    • %changelog entry.
  • Regenerated specs/g/gcc/gcc.spec and refreshed locks/gcc.lock.

The resulting libbacktrace-static RPM ships exactly:

/usr/include/backtrace.h
/usr/lib64/libbacktrace.a

with no runtime dependencies.

Validation

All steps performed against the Azure Linux 4.0 stage2 mock environment
(x86_64).

  1. Render the spec and confirm the overlays applied:

    azldev comp render -p gcc
    # Verified: %global gcc_release 8, %package -n libbacktrace-static,
    # %install find+install of libbacktrace.a/backtrace.h, %files block,
    # and the %changelog entry are all present in specs/g/gcc/gcc.spec.
  2. Build the component:

    azldev comp build -p gcc
    # -> base/out/rpms/rpm-base/libbacktrace-static-15.2.1-8.azl4.x86_64.rpm
  3. Inspect the produced RPM:

    RPM=base/out/rpms/rpm-base/libbacktrace-static-15.2.1-8.azl4.x86_64.rpm
    rpm -qlp "$RPM"        # /usr/include/backtrace.h, /usr/lib64/libbacktrace.a
    rpm -qp --provides "$RPM"   # libbacktrace-static = 15.2.1-8.azl4
    rpm -qp --requires "$RPM"   # only rpmlib(...) deps
  4. Install with tdnf in the 4.0 chroot and verify the files land:

    # copy the built RPM into the persistent mock chroot
    mock -r distro/mock/azl4/stage2/azurelinux-4.0-x86_64.cfg \
         --configdir distro/mock/azl4/stage2 \
         --copyin "$RPM" /tmp/
    
    # install tdnf into the chroot, then tdnf-install the built package
    azldev adv mock shell --enable-network --add-package tdnf <<'EOF'
    tdnf install -y /tmp/libbacktrace-static-15.2.1-8.azl4.x86_64.rpm
    rpm -q libbacktrace-static
    ls -l /usr/lib64/libbacktrace.a /usr/include/backtrace.h
    EOF

    Result:

    Installing:
     libbacktrace-static  x86_64  15.2.1-8.azl4  @commandline  701.6 KiB
    ...
    Complete!
    
    libbacktrace-static-15.2.1-8.azl4.x86_64
    -rw-r--r-- 1 root root   9141 /usr/include/backtrace.h
    -rw-r--r-- 1 root root 709314 /usr/lib64/libbacktrace.a
    
  5. Compile + link + run smoke test (proves the archive is usable and
    correct-arch, not just installable — a wrong-arch or corrupt .a fails at the
    -lbacktrace link or at runtime):

    RPM=base/out/rpms/rpm-base/libbacktrace-static-15.2.1-8.azl4.x86_64.rpm
    azldev adv mock shell --enable-network --add-package gcc --add-package "$RPM" <<'SMOKE'
    cat > /tmp/bt_smoke.c <<'SRC'
    #include <stdio.h>
    #include <stdint.h>
    #include <backtrace.h>
    static void err_cb(void *d, const char *m, int e) {
        fprintf(stderr, "libbacktrace error: %s (%d)\n", m, e);
    }
    static int full_cb(void *d, uintptr_t pc, const char *f, int l, const char *fn) {
        printf("  0x%lx %s:%d %s\n", (unsigned long)pc, f ? f : "?", l, fn ? fn : "?");
        return 0;
    }
    int main(void) {
        struct backtrace_state *s = backtrace_create_state(NULL, 0, err_cb, NULL);
        if (!s) { fprintf(stderr, "backtrace_create_state failed\n"); return 1; }
        backtrace_full(s, 0, full_cb, err_cb, NULL);
        printf("libbacktrace link+run OK\n");
        return 0;
    }
    SRC
    gcc -O2 -Wall -Werror /tmp/bt_smoke.c -o /tmp/bt_smoke -lbacktrace
    readelf -d /tmp/bt_smoke | grep -i backtrace || echo "good: statically linked, no libbacktrace shared dep"
    /tmp/bt_smoke
    SMOKE

    Result:

    -rw-r--r-- 1 root root 709314 /usr/lib64/libbacktrace.a
    (no shared lib; static only)
    # gcc -O2 -Wall -Werror ... -lbacktrace   -> compiled clean
    good: statically linked, no libbacktrace shared dep
      0x40057f ...
      0x7ec2948b95b4 ...
    libbacktrace link+run OK   (exit 0)
    

    Confirms: the header compiles, -lbacktrace links the static archive directly
    into the binary (no DT_NEEDED for libbacktrace), and the resulting program
    runs and exercises the libbacktrace API successfully.

Copilot AI balanced review requested due to automatic review settings August 14, 2026 22:39
@liunan-ms
Nan Liu (liunan-ms) force-pushed the liunan/add-libbacktrace-static branch from 66d09c5 to f669149 Compare August 14, 2026 22:43
@liunan-ms Nan Liu (liunan-ms) changed the title gcc: add libbacktrace-static subpackage feat(gcc): add libbacktrace-static subpackage Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a GCC libbacktrace-static RPM for downstream build consumers.

Changes:

  • Adds overlays defining and installing the subpackage.
  • Bumps GCC’s release and regenerates its spec.
  • Refreshes the GCC lock fingerprint.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml Defines the GCC customization.
specs/g/gcc/gcc.spec Contains the rendered packaging changes.
locks/gcc.lock Refreshes the component fingerprint.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml
Comment thread base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml Outdated
Copilot AI review requested due to automatic review settings August 14, 2026 22:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml:40

  • The validation only installs the RPM and checks that these files exist; it does not exercise the new package's actual consumer contract. A static-library smoke test should compile, link, and run a minimal backtrace_create_state consumer against -lbacktrace (or rebuild the intended Boost target) in the clean mock chroot so missing link requirements or an unusable archive are caught before merge.
    "install -m 0644 -D \"$_azl_bt\" %{buildroot}%{_libdir}/libbacktrace.a",

Expose GCC's internal libbacktrace static library (libbacktrace.a) and its
header (backtrace.h) as a new libbacktrace-static subpackage
Copilot AI review requested due to automatic review settings August 14, 2026 22:59
@liunan-ms
Nan Liu (liunan-ms) force-pushed the liunan/add-libbacktrace-static branch from f669149 to 6f02a9f Compare August 14, 2026 22:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml:41

  • The exported libbacktrace interface is incomplete. GCC generates backtrace-supported.h, and upstream documents it for users to inspect BACKTRACE_SUPPORTED, thread support, and related capabilities; many consumers include it alongside backtrace.h. Installing only backtrace.h makes those consumers fail to build despite this package being installed. Install the generated header from the libbacktrace object directory as well.
    "install -m 0644 -D %{_builddir}/gcc-%{version}-%{DATE}/libbacktrace/backtrace.h %{buildroot}%{_includedir}/backtrace.h",

base/comps/gcc/overlays/0002-libbacktrace-static.overlay.toml:54

  • The generated backtrace-supported.h must also be owned by libbacktrace-static; otherwise adding it during %install will leave it outside the package manifest (and future stricter unpackaged-file checks would fail).
    "%files -n libbacktrace-static",
    "%{_includedir}/backtrace.h",
    "%{_libdir}/libbacktrace.a",

@@ -0,0 +1,67 @@
# Azure Linux exposes GCC's internal libbacktrace as a standalone

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(blocking):

Did we evaluate the trade-off of building the library from https://github.com/ianlancetaylor/libbacktrace instead?

openSUSE and Debian appear to get it directly from there. (IF you notice the gcc internal copy of the library lists the same author in its copyright notice.)

(openSUSE also has a .spec for this location.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants